Role of spinal sensorimotor circuits in triphasic muscle command: a simulation approach using goal exploration process.
The 5 matches
- [1] § Methods › Brief overview of rGEP ↔ makeGraphs.py, lines 4243–4296 · score 0.70 · behavior space, closest behavior, valid behaviors, behavior domain, inside, chosen
- [2] § Results › Analysis of triphasic patterns in the various models › Elaboration of triphasic commands in spinal sensorimotor networks ↔ DialogChoose_in_List.py, lines 448–504 · score 0.67 · Ext PN, ExtAlpha, FlxPN, FlxAlpha, sensory neurons
- [3] § Results › Analysis of triphasic patterns in the various models › Elaboration of triphasic commands in spinal sensorimotor networks ↔ DialogChoose_in_List.py, lines 448–504 · score 0.66 · ExtAlpha, ExtPN, FlxPN, FlxAlpha, gamma, sensory
- [4] § Methods › Software’s used in simulations ↔ class_animatLabModel.py, lines 1–34 · score 0.52 · python3.8, AnimatLab, synapses, models
- [5] § Methods › Musculoskeletal system ↔ makeGraphs.py, lines 4243–4296 · score 0.52 · behavior space, closest behavior, behavior domain, parent, durations, speed
Paper
Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
Python · 4,749 lines · 195 KB · no license · 2 matches
- # -*- coding: utf-8 -*-
- """
- Created on Mon Feb 19 2018
- This script select a file in a chosen directory
- @author: Solene Lambert & Daniel Cattaert
- When a folder is selected (in the saved directory) - > model_dir
- (1) Plot separately Deb, Max, Fin values for each selected chart column
- Each plot represents the values for each const parameter and all trials
- Thee results are plotted in different colors for different mvt durations
- Results for the different angles are on separate sheeet graph
- these graphs are saved in the model_dir
- (2) Plots of the elbow movementfor each template
- Each plot represents the template and all movements obtained with the
- different constant values (for example Ia->MN sunapse strength)
- these graphs are saved in each folder specific to a movement template
- (i.e. angles and mvt duration)
- (3) Plot of superimposed movements of same angles and different durations
- Possibility to choose the constant values to plot results
- Plot relationship between parameters
- (1) Builds graphs of chosen parameter values. Each graph represents
- the adaptation of the parameter value for each value of the constant
- parameter (and for all selected trials). Different mvt durations are
- ploted with different lines. The different angles are plotted on different
- files.
- (2) Draws and saves correlation graphs for each angle_duration condition
- (3) Draws and saves a matrix of correlation graphs with color codes
- New series of procedures added for metrics of optimization methods.
- class GEPGraphsMetrics containing a "grid" method (grid_method) that builts
- a grid on behaviour space (40x40) in order to calculate the number of
- elements of the grid in which a behavior (at least one) was found.
- Then this methods builds the function nbboxes=f(nbRuns) with a step=100
- runs (i.e. for 7500 runs we get 75 points).
- Builts the corresponding graph (and saves it), with the indication of the
- value of span for each run series (numbers on the curve), and the type of
- run (reparam, GEPrand, CMAE) with a color code.
- 1) "metrics" has been modified to allow re-use of the present df_parremai
- and df_bhvremain dataframes. A message box is used to ask the user what to
- do either keep these dataframes, or load a new one.
- 2)When calling "metrics" the previously present BhvWindow is erased
- 3)If the newly selected directory contains only one GepData folder then if
- this directory is the same as the one present in memory, the asim file is
- not red again
- 4) When selecting a single directory in which GEPdata folder contains a
- series of runs (GEPdata00.par,GEPdata01.par,... GEPdataii.par) it
- is proposed to choose a given run (in a table, select check button case)
- 1) windows are now disposed and ordered on right-up screen corner
- 2) the bhv_window is erased and recreated each time a new type of analyze
- is performed.
- 3) a new procedure "makes_bhvpar_windows" was created to recreate the
- bhv_window that also actualizes two files used in GEP_GUI procedures:
- self.mafen.source_df_bhvremain = df_bhv.iloc[self.df_glob.index]
- self.mafen.source_df_parremain = df_par.iloc[self.df_glob.index]
- In param_in_blue(self, df_par): all par graphs are built from
- listDicGraphs. This dictionary can be modified from makeGEPMetrics.py
- to choose the params plotted in each graph
- namex = self.listDicGraphs[pargr+1]["abscissa"]
- namey = self.listDicGraphs[pargr+1]["ordinate"]
- parx = self.xparNameDict[namex[0]]
- pary = self.xparNameDict[namey[0]]
- In class GUI_Graph:
- new methods added:
- plot_2D_stability_map(self, df_bhvremain, df_parremain)
- Prepares a dataframe in which for each behavior (duration,
- amplitude) a mean distance is calculated from the distance to
- all behaviors produced by parameters in the vicinyty (dist<0.2)
- of this behavior. When several distances are obtained, the mean
- value is retained. Then call the do_plot_2D_stability_map()
- method to plot the stability map.
- do_plot_2D_stability_map(self, df_cues_dist)
- plot_densitymap_metrics(self): it asks to choos a folder with GEPdata
- and builds the corresponding df_bhvremain and df_parremain dataframes
- (if already present in memor, asks if a new folder is to be analysed)
- Then calls the new function do_plot_2D_density_map_metrics
- do_plot_2D_density_map_metrics(df_bhvremain, behav_col,
- pathGEP, GEPdataName,
- nbruns, col_scale_range):
- Plots and saves a density map that uses the same grid as the grid
- used in metrics to evaluate how the GEP explores the behavior
- space. THe score in metrics is simply the number of cases in the
- grid that contain at least one behavior.
- Here, this gid is used to count the number of behaviors in each
- case, which gives an idea of the density of the behaviors in the
- different regions.
- a new general procedure added:
- plot_2D_graph_from_array(x, pathGEP, baseName, nameX, nameY, extent)
- x is an array of arrays containing values (typically the number of
- behaviours in each case of the grid defined by the array of arrays, but
- it may be any value that defines a feature of the grid).
- pathGEP is the path to save the graphs (.esp and .pdf)
- baseName is the name of the graph
- nameX and nameY are the X and Y axes legends
- extent is an array [x_min, x_max, y_min, y_max] used to define the
- ranges of x and y axes.
- GEPGraphsMetrics class Contains various methods to build graphs for GEP analysis
- - plot and save behavior and parameter maps
- - plot and save behavior map
- - plot and save behavior map (with chosen number of valid behaviors)
- - plot and save density map of GEP behavior domain
- - plot and save stability map of GEP behavior domain
- - plot and save progression of GEP process with two metric methods
- - plot_densitymaps_contour
- - plot_save_2D_densitymap_contour
- These two methods use contour to draw the density map (continuous way)
- Translated in Python 3.8 Jan 2023 (D. Cattaert)
- Modified January 27, 2023 (D. Cattaert):
- Saving to xls has beenreplaced by saving in csv format.
- Modified January 29, 2023 (D. Cattaert):
- New methods added in Graph_Setting class :
- chartgraph_selected_bhv()
- run_selected_bhv()
- These methods used selected Bhv to build graph from charts. To do this
- the corresponding paramsets are run and results saved in graphs/run-0
- or run-1 etc... in incremental manner.
- ModifiedFebruary 1, 2023 (D. Cattaert):
- Modification of run_selected_bhv() method that use now the saves_seeds()
- method of GEP_GUI to complete the new directory.
- Modified February 3, 2023 (D. Cattaert):
- Modifications of build_newdf() method:
- After selectiion of several folders, the index of df_bhvremain and
- df_parremain are no more set to range(len(self.df_parremain)) but to
- self.lst_valid, the list of valid elements (varmse<1) adapted to take
- into account the origin of elements (i.e. the folder of origin)
- self.df_bhvremain.index = self.lst_valid
- self.df_parremain.index = self.lst_valid
- Accordingly, in run_selected_bhv() method, the concatenated pairs numbers
- (optSet.pairs) are now directly compatible with seeds_selected
- (= list(df_glob.index)). So lst_valid is no more used.
- The call to GEP-GUI.py saves_seeds() is made with the param
- seedDirCreate=False in order not to create a 0_IDXXX_seeds00 foder.
- Modified February 14, 2023 (D. Cattaert):
- In the procedure graphfromchart(), "path" replaced by "chart_path"
- In the class GUI_Graph, a bug in the method build_newdf() was fixed: when
- only one folder (one experiment) was chosen, the variable "tab_bhv" was not
- defined. It is now defined if one_expe:
- if self.prevListGEPFiles == []:
- tab_bhv = readTablo(self.listGEPFolders[0], "GEPdata00bhv.txt")
- tab_bhv = np.array(tab_bhv)
- Modified February 28, 2023 (D. Cattaert):
- in GEPGraphsMetrics class, bug fixed in make_graph_score_evol(method):
- "span = int(tabnewspan[idx])" not accepted for a list. Now replaced
- by series of tests to define span.
- Modified Mars 01, 2023 (D. Cattaert):
- graphfromchart() procedure improved. Neuron voltage are no more expressed
- in V but in mV.
- Modified April 23, 2023 (D. Cattaert):
- New method plot_abaque_duration() allows to draw abaques of duration values
- in the MaxSpeed vs Amplitude graph. It calls a new prodecure from
- optimization: plot_series_curves_maxspeed_ampl_duration()
- Modified April 28, 2023 (D. Cattaert):
- Method chooseChartFromPar() : bug fixed to take into account the new format
- in datastructure. This method builds bhv Plots from the charts of
- datastructure the varme of which is <1.
- New method analyze_triphasic():
- Builds a new df_bhv and df_par from a datastructure
- Runs the method chooseChartFromPar() to select charts from the
- datastructure
- From datastructure, builds a new self.df_chart containint:
- chartName, varmse, startangle, ampl, max_speed, dur_mvt2, run_rg
- plus three other columns characterizing triphasic pattern:
- TwoPicks, FlxTo0BetwPicks, ExtOnePick
- Aks if plot is required for each selected chartName (the plot contains
- the movement and EMGs (1FlxPotMuscle, 1ExtPotMuscle)
- The self.df_chart is saved in csv format.
- Modified May 10, 2023 (D. Cattaert):
- Bug fixed in chooseChartFromPar() method. The <Max replaced by <=Max
- Modified May 16, 2023 (D. cattaert):
- Scalses for bhv plots corrected and set to 0-120 for x , and 0-500 for
- MaxSpeed
- New method: plot_save_density_map_metrics() used when called from
- controlScriptGEP.py to build gaphs with autoscale=True
- Modified July 29, 2023 (D. Cattaert):
- Method saveplot_bhvparam() in GEPGraphMetrics class modified so that
- when called from a multipleExpeGraph the complete dataframe is plotted.
- Modified September 17, 2023 (D. Cattaert):
- Method make_graph_score_evol() Bug fixed to take into account the type of
- tabnewspan[idx] when red from datastructure and is ['DicSpanVal.txt'],
- Which means that for this series, span values was red from DicSpanVal.txt:
- if type(tabnewspan[idx][0]) is str: ...
- Modified Ostober 06, 2023 (D. Cattaert):
- Method saveplot_bhvparam(): bug fixed for multiple expe graph. Start and
- End values missed. Now provided.
- Method plot_densitymap_metrics(): same bug fixed
- Modified October 10, 2023 (d. Cattaert):
- Method analyze_triphasic() improved so that multiple experiments are
- allowed. Method build_df_chart() modified accordingly. Nw the df_chart
- contains a new column "origine". A number (0 to nbExpe) indicates the
- origin folder of the chart name. Method chooseChartFromPar() modified
- accordingly. It does not asks anymore for a GEPdata00.par, but gets it
- directly from the self.listGEPFolders list elaborated in build_newdf()
- method called by make_bhvpardf() method.
- Modoified October 10, 2023 (D. Cattaert):
- Bug fixed in chooseChartFromPar(). Now the chart directory is obtained from
- self.listGEPFolders, and the chart is red in the good GEPChartFiles,
- according to the experiment folder in the list self.listGEPFolders.
- Modified October 17, 2023 (D. Cattaert):
- Method makegr_chart_tcourse() modified to allow two types of graph when the
- names extension is ".txt":
- either an 'EMG'
- or a 'bhvMvt'
- Modified February 03, 2024 (D. Cattaert):
- In grid_method() method, derecated writing fixed:
- state_table = np.zeros(dtype=int, shape=(nbcol, nbrow))
- ('dtype=np.int' replaced by 'dtype=int')
- Modified April 12, 2024 (D. Cattaert):
- makeGraphs.py Bug fixed in the selection of behaviors when data
- are from several folders. The behaviors are now selected
- using "orig_rg" and "origine". The index of chart_global_df
- is now compatible with indexes of df_parremain and
- df_bhvremain
- Modified April 24, 2024 (D. Cattaert):
- Old methods (used for the old format "experiments series")
- have been suppressed.
- New procedures introduced to Analyze neuron activities and par
- vs bhv. Now it is possible to opena previously saved
- "df_chart_bhv_neur_param.csv" to make graphs. The new method
- ("read_csv_for_df_bhv_neur_par()") relies on a part of the old
- "build_newdf()" method to reconstruct the df_parremain and
- df_bhvremain dataframes.
- To do this, "build_newdf()" has been splitted into four sub methods
- Modified May 1st, 2024 (D; Cattaert):
- Bug fixed in method "run_selected_bhv". Selected_seeds are obtained from
- the index of the dataframe "df_glob". This is OK but the corresponding
- parameters were not at those rows, becaus correct rows are indicated in
- rgserie column NOT AT INDEX!!! This is why the correct row of each
- parameter (in optSet.pairs) is calculated :
- rg_pair = int(df_bhvremain.loc[select]["rgserie"])
- The script was chaned accordingly:
- seeds_selected = list(df_glob.index))
- selected_pairs = []
- for select in seeds_selected:
- print(df_parremain.loc[select][:5])
- rg_pair = int(df_bhvremain.loc[select]["rgserie"])
- print(optSet.pairs[rg_pair][:5])
- selected_pairs.append(optSet.pairs[rg_pair])
- Modified May 02, 2024 (D. Cattaert):
- Bug in method "run-selected-bhv()' fixed. Now, df-parremain and
- df-bhvremain indexes correspond to seeds-selected = df_glob.rgserie
- Modified May 15, 2024 (D. Cattaert):
- Bug in construct_df_par_bhv_remains() and read_csv_for_df_bhv_neur_par()
- methods have been fixedc:
- "sum_precedingTab" variable was added to sum preceeding tables in order
- to get a correct final index
- Modified May 17, 2024 (D. Cattaert):
- Suppression of two lines on read_csv_for_df_bhv_neur_par() method:
- self.df_bhvremain.loc[:, "orig_rg"] = self.df_bhvremain["rgserie"]
- self.df_parremain.loc[:, "orig_rg"] = self.df_parremain["rgserie"]
- because self.df_bhvremain and self.df_parremain already got the column
- entitled "orgi-rg" (in construct_df_par_bhv_remains() method)
- in and self.df_parremain already got the column
- In order to allow analysis from a different computer, with path
- different from the one used to build the multipleExpeGraph-x folders, the
- method "construct_df_par_bhv_remains()" has been modified so that it works
- with relative folder addresses established from self.ensembleRunDir
- annimatsimdir is rebuilt to make it compatible with the computer paths
- Modified June 05, 2024 (D. Cattaert):
- new_run_dir is now created in chartgraph_selected_bhv() method
- This allows the par and bhv csv files of selected behaviors to be saved in
- new_run_dir (run-0, run-1 etc.)
- Modified July 5, 2024 (D. Cattaert):
- create_df_for_bhv_neur_par() method modified to allow second peak detection
- at user's demand.
- get_peaks_and_troughs() procedure modified accordingly. Asks the user
- Which neurone to search for a second peak.
- Modified July 15, 2024 (D. Cattaert):
- read_csv_for_df_bhv_neur_par() method modified to accept lines containing a
- NaN element
- buildStpDiscretCol() procedure modified to get a single color scale (<50),
- because plotting to legends(plt.legend()) is no more accepted.
- Modified July 17, 2024 (D. Cattaert):
- Bug fixed in "save (par+bhv) dataframe to csv". The problem came from the
- variable "self.new_run_dir" that was not defined in the method
- "construct_df_par_bhv_remains" but only in neuron analysis. Therfor, any
- call to "save "par+bhv dataframes to csv" directely after running
- "make/analyze (par+bhv) dataframe" failed. This is now fixed in the method
- "construct_df_par_bhv_remains":
- new line added after the folders have been selected:
- self.new_run_dir = self.graph_path
- Modified December 20, 2024 (D. Cattaert):
- Bug fixed in method "build_df_chart()" (self.mydir was not known):
- if self.mydir == '':
- self.mydir = self.graph_path
- df_chart.to_csv(self.mydir + '/charts_infos.csv')
- Modified January 25, 2025 (D.Cattaert):
- graphfromchart() procedure modified to include in the title the 3 last
- parts of the pathway to the chartFile.
- Previously, the graph title was:
- "GEP_chart00.txt; randParam bestfit:0.5787...;
- mse bestfit:0.5787022423750172; coactBestFit:0.0
- Now it is:
- GEP_chart05.txt; NS33B2NG(sim)/NS33B2NGB_52_..._100/workDir_animatlab
- mse:36.1529 coactP:0.0
- max_endangleP:18.33 End_1FlxAlpha_P:2.22 End_1ExtAlpha_P:0.00 ...
- mvt duration: 1.08
- The algorithm used to get mseVal and coactVal from the chart's firts line
- have been modified to work with new charts and old charts accordings to
- changes made in savechartfile() (in optimization.py).
- This procedure is called by makeGraphFromChart() called by various
- methods of GUI_graph class.
- Modified February 20, 2025 (D. Cattaert):
- build_df_chart() modified so that is self.graph_path does not exist; it
- is created. This occured when new charts are created from selected
- behaviors limits (or all behaviors).The file charts_infos.csv can then be
- saved in this new "graphs" directory.
- Modified June 24, 2025 ( D. Cattaert):
- Bug fixed in "Analyze Neurons_activity/bhv from charts"
- Now after creating the dataframe and saving it (self.fname), the dataframe
- is recreated by launching read_csv_for_df_bhv_neur_par_from_file(self),
- To do this, read_csv_for_df_bhv_neur_par(self) has been splitted into Two
- methods: one to chosse the csv file and the other to read it:
- def read_csv_for_df_bhv_neur_par(self):
- res = (QtWidgets.QFileDialog.
- getOpenFileName(self, "Choose bhv_df_csv file to analyse",
- self.mydir, "Files (*csv)"))
- if type(res) == tuple:
- self.fname, __tmp = res
- else:
- self.fname = res
- print(self.fname)
- self.read_csv_for_df_bhv_neur_par_from_file()
- def read_csv_for_df_bhv_neur_par_from_file(self):
- if self.fname is not None:
- ...
- modified September 04, 2025 (D. Cattaert):
- errThr and coactThr values is now red from win.errThr and win.coactThr
- All methods and functions have been modified accordingly in optimization.py
- The value of win.errThr (that was 1.0 in previous version) is now given in
- a method from GUI ("setErrThr()").
- The value of win.coactThr (that was 0.01 in previous version) is now given in
- a method from GUI ("setErrThr()"). Using this method plus two new buttons,
- win.errThr and win.coactThr can be changed in the GUI.
- These two values are incorporated in datastructure (conditons' last list')
- and saved in GEPdata00.par at each extend and fill.
- The graphs use now these two new settings (red from datastructure) and they
- can be changed (via a dialog). This dialog can be call from the first
- button of the GEPgraphMetric menu. Thes two values are saved in the graphs'
- titles
- Suppression of nan elements in selected dataframe for single plot (eiher
- with a color factor of not)
- Modified October 22, 2025 (D. Cattaert):
- Method "create_df_for_bhv_neur_par()" modified self.fname (name of of the
- self.chart_glob_df), that includes now the length of df_chart.
- Method "plot_bhvmap_nbBhvOK" reduces the number of points of the graph plot
- Modified May 24 2026 (D. Cattaert):
- New predecure ("Analyse perturbation effects on bhv") allows to add
- perturbation to the arm during movement. A new stimulus is added in the
- FinalModel files (.asim and .aproj) of the original directory.
- New subdirectory of "graph" directory is created to store the rusults of
- running each perturbed model.The perturbation parameters are givent by the
- user. It is also possible to run a limited ârt of the original behavior
- domain.Once finished the original FinalModel files are restored.
- Modified June 09, 2026 (D. Cattaert):
- Perturbation procedurehas been rewrittent to work in parallel mode.
- GEP_GUI.py and optimization.py have been modified accordingly.
- modified June 10, 2026 (D.Cattaert):
- method "saves_newGEPdata()" (from GEP_GUI.py) modified to include a new
- parameter in the call (saveGrFromChart=False). This new parametr allows to
- choose to build graphs or not in the class "Perturbation_Setting0" in the
- method used to run selected behaviors (run_selected_bhv).
- Modified June19, 2026 (D. Cattaert):
- It is now possible to choose not to save .aproj and/or .asim files.
- New dialog boxes have been added for the user to choose what to save.
- """
- import os
- from os import listdir
- from os.path import isfile, join
- import pickle
- import copy
- import random
- import ctypes # used to create message box
- from ctypes import wintypes as w
- import matplotlib.pyplot as plt
- # import matplotlib.colors as pltcolors
- import matplotlib.pylab as pylab
- import matplotlib as mpl
- # from matplotlib import colors as mcolors
- # from matplotlib import cm
- import json
- from itertools import product
- import numpy as np
- import pandas as pd
- # from openpyxl import Workbook
- import seaborn as sns
- from scipy.stats import pearsonr
- from scipy.stats import linregress
- from scipy.signal import find_peaks_cwt
- from scipy.signal import find_peaks
- from scipy.signal import lfilter
- from itertools import groupby
- # from mpl_toolkits.mplot3d import axes3d
- from mpl_toolkits.mplot3d import Axes3D
- from math import log as ln
- from math import sqrt as sqrt
- from math import isnan
- from math import pi
- import pyqtgraph as pg
- from pyqtgraph.Qt import QtCore
- from pyqtgraph.Qt import QtWidgets
- # from PyQt5 import QtWidgets
- from optimization import showdialog
- from optimization import load_datastructure
- from optimization import readTabloTxt
- from optimization import readTablo
- from optimization import chartToDataFrame
- from optimization import getInfoComputer
- from optimization import SaveIncrementNb
- from optimization import saveListToDir
- from optimization import calculate_minjerk_duration
- from optimization import copyRenameFilewithExt
- from optimization import copyFileDir_ext
- from optimization import copyFileDir
- from optimization import copyFileWithExt
- from optimization import copyFile
- from optimization import readGravityfromAsim
- from optimization import readCoacPenality
- from optimization import testVarMsePlot
- from optimization import plot_series_curves_maxspeed_ampl_duration
- # import mvt_GUI
- from DialogChoose_in_List import ChooseInList
- from DialogChoose_in_List import GetText
- from DialogChoose_in_List import choose_one_element_in_list
- from DialogChoose_in_List import choose_elements_in_list
- from DialogChoose_in_List import set_values_in_list
- from DialogChoose_in_List import Enter_Values
- from DialogChoose_in_List import InfoWindow
- from optimization import loadParams
- from animatlabOptimSetting import OptimizeSimSettings
- from FoldersArm import FolderOrg
- import class_animatLabModel as AnimatLabModel
- import class_projectManager as ProjectManager
- from class_animatLabSimulationRunner import AnimatLabSimulationRunner as SimRun
- import class_animatLabSimulationRunner as AnimatLabSimRunner
- import xml.etree.ElementTree as elementTree
- import uuid
- """
- from matplotlib.backends.qt_compat import is_pyqt5
- if is_pyqt5():
- from matplotlib.backends.backend_qt5agg import (
- FigureCanvas, NavigationToolbar2QT as NavigationToolbar)
- else:
- from matplotlib.backends.backend_qt4agg import (
- FigureCanvas, NavigationToolbar2QT as NavigationToolbar)
- """
- from matplotlib.backends.backend_qt5agg import (
- FigureCanvas, NavigationToolbar2QT as NavigationToolbar)
- global verbose
- verbose = 2
- # ======= Format a new "MessageBox" function to be used in Python 2.7 =======
- # The four folling lines are for python2.7 because Python 2's strings are byte
- # strings and marshaled as byte strings (char*). Python 3's strings are Unicode
- # strings and marshaled as wide strings (wchar_t*). Without defining .argtypes,
- # ctypes won't error check and happily pass the wrong type.
- user32 = ctypes.WinDLL('user32')
- MessageBox = user32.MessageBoxW
- MessageBox.argtypes = w.HWND, w.LPCWSTR, w.LPCWSTR, w.UINT
- MessageBox.restype = ctypes.c_int
- """
- # to use "MessageBox just type
- # MessageBox(None, u'message', u'title', 0)
- # it will return the code of answer
- # several options (styles) are possible:
- ## Styles:
- ## 0 : OK
- ## 1 : OK | Cancel
- ## 2 : Abort | Retry | Ignore
- ## 3 : Yes | No | Cancel
- ## 4 : Yes | No
- ## 5 : Retry | No
- ## 6 : Cancel | Try Again | Continue
- """
- # -----------------------------------------------------------------------------
- def dialogWindow(titre, info, details=""):
- rep = showdialog(titre, info, details)
- # print(rep)
- if rep == 1024:
- OK = True
- else:
- OK = False
- return OK
- class Form(QtWidgets.QWidget):
- def __init__(self, parent=None):
- super(Form, self).__init__(parent)
- nameLabel = QtWidgets.QLabel("Name:")
- self.nameLine = QtWidgets.QLineEdit()
- self.submitButton = QtWidgets.QPushButton("&Submit")
- self.quitButton = QtWidgets.QPushButton("&Quit")
- buttonLayout1 = QtWidgets.QVBoxLayout()
- buttonLayout1.addWidget(nameLabel)
- buttonLayout1.addWidget(self.nameLine)
- buttonLayout1.addWidget(self.submitButton)
- buttonLayout1.addWidget(self.quitButton)
- self.submitButton.clicked.connect(self.submitContact)
- self.quitButton.clicked.connect(self.closeIt)
- mainLayout = QtWidgets.QGridLayout()
- # mainLayout.addWidget(nameLabel, 0, 0)
- mainLayout.addLayout(buttonLayout1, 0, 1)
- self.setLayout(mainLayout)
- self.setWindowTitle("Hello Qt")
- def submitContact(self):
- name = self.nameLine.text()
- if name == "":
- QtWidgets.QMessageBox.information(self, "Empty Field",
- "Please enter a name and address.")
- return
- else:
- QtWidgets.QMessageBox.information(self, "Success!",
- "Hello %s!" % name)
- def closeIt(self):
- """
- doc string
- """
- self.close()
- def change_key_str_to_int(dic_folder_st):
- rep = {}
- for key in list(dic_folder_st.keys()):
- rep[int(key)] = dic_folder_st[key].replace("\\", "/")
- return rep
- def lighten_color(color, amount=0.5):
- """
- Lightens the given color by multiplying (1-luminosity) by the given amount.
- Input can be matplotlib color string, hex string, or RGB tuple.
- Examples:
- >> lighten_color('g', 0.3)
- >> lighten_color('#F034A3', 0.6)
- >> lighten_color((.3,.55,.1), 0.5)
- """
- import matplotlib.colors as mc
- import colorsys
- try:
- c = mc.cnames[color]
- except Exception as e:
- c = color
- print(e)
- c = colorsys.rgb_to_hls(*mc.to_rgb(c))
- return colorsys.hls_to_rgb(c[0], 1 - amount * (1 - c[1]), c[2])
- def getListOfFiles(dirName):
- '''
- For the given path, get the List of all files in the directory tree
- '''
- # create a list of file and sub directories
- # names in the given directory
- listOfFile = os.listdir(dirName)
- allFiles = list()
- # Iterate over all the entries
- for entry in listOfFile:
- # Create full path
- fullPath = os.path.join(dirName, entry)
- # If entry is a directory then get the list of files in this directory
- if os.path.isdir(fullPath):
- allFiles = allFiles + getListOfFiles(fullPath)
- else:
- allFiles.append(fullPath)
- return allFiles
- def find_a_file(rootdir=None, fileName=None):
- if rootdir is None:
- from mainOpt import readAnimatLabDir
- animatsimdir = readAnimatLabDir()
- rootdir = animatsimdir
- if fileName is None:
- fileName = "GEPdata00.par"
- # Get the list of all files in directory tree at given path
- # listOfFiles = getListOfFiles(rootdir)
- # Print the files
- # for elem in listOfFiles:
- # print(elem)
- # print ("****************")
- # Get the list of all files in directory tree at given path
- listOfFiles = list()
- listOfDir = list()
- for (dirpath, dirnames, filenames) in os.walk(rootdir):
- listOfFiles += [os.path.join(dirpath, file) for file in filenames]
- listOfDir += [os.path.join(dirpath, file) for file in dirnames]
- listOfSearchedFiles = list()
- listOfSearchedDir = list()
- # Print the files
- for elem in listOfFiles:
- if elem[-len(fileName):] == fileName:
- print(elem)
- listOfSearchedFiles.append(elem)
- listOfSearchedDir.append(os.path.split(elem)[0])
- return listOfSearchedDir
- def save_eps_pdf(graph_path, tit, sstit):
- nomfic_eps = r'{0}\{1}{2}.eps'.format(graph_path, tit, sstit)
- nomfic_pdf = r'{0}\{1}{2}.pdf'.format(graph_path, tit, sstit)
- if len(nomfic_eps) > 250:
- nomfic_eps = r'{0}\{1}.eps'.format(graph_path, tit)
- nomfic_pdf = r'{0}\{1}.pdf'.format(graph_path, tit)
- if not os.path.exists(nomfic_eps):
- plt.savefig(nomfic_eps, bbox_inches='tight')
- plt.savefig(nomfic_pdf, bbox_inches='tight')
- else:
- root = nomfic_eps[:nomfic_eps.find(".eps")]
- print(len(root))
- k = 0
- while os.path.exists("{0}({1}){2}".format(root, k, ".eps")):
- k += 1
- nomfic_eps = "{0}({1}){2}".format(root, k, ".eps")
- nomfic_pdf = "{0}({1}){2}".format(root, k, ".pdf")
- plt.savefig(nomfic_eps, bbox_inches='tight')
- plt.savefig(nomfic_pdf, bbox_inches='tight')
- print("files saved under {0}".format(nomfic_eps))
- """
- def create_workbook(path):
- workbook = Workbook()
- sheet = workbook.active
- sheet['A1'] = 'Hello'
- sheet['A2'] = 'from'
- sheet['A3'] = 'OpenPyXL'
- workbook.save(path)
- """
- def dataframe_to_rows(df, index=False):
- rows = []
- if index == True:
- row = [""]
- for col in list(df.columns):
- row.append(col)
- else:
- row = list(df.columns)
- rows.append(row)
- indexes = list(df.index)
- for id_row, row in enumerate(df.index):
- # print("row=", id_row, "index=", indexes[id_row])
- if index:
- rowVals = [indexes[id_row]]
- else:
- rowVals = []
- for idx, col in enumerate(df.columns):
- # print("\t {:2.2f}".format(df.loc[row, col]), end=" " )
- rowVals.append(df.loc[row, col])
- # print()
- rows.append(rowVals)
- return rows
- """
- def save_df_to_xls(df, pathGEP, file_name, typ=None):
- # Although this procedure has been fixed for Python 3.8, we do not use it
- # anymore because dataframe conversion is not straight forward and more
- # over importing xlsx file to built a dataframe is not satisfying. We use
- # csv file instead.
- workbook = Workbook()
- sheet = workbook.active
- rows = dataframe_to_rows(df, index=False)
- for r_idx, row in enumerate(rows, 1):
- for c_idx, value in enumerate(row, 1):
- sheet.cell(row=r_idx, column=c_idx, value=value)
- completeName = os.path.join(pathGEP, file_name + '.xlsx')
- workbook.save(completeName)
- print('DataFrame is written successfully to Excel Sheet.')
- """
- def save_df_to_csv(df, pathGEP, file_name, typ=None):
- completeName = os.path.join(pathGEP, file_name + '.csv')
- df.to_csv(completeName, sep=",")
- def calculate_dist_par(df_parremain, par_names, idx, rg, dist):
- d2 = 0
- for par in par_names:
- x = df_parremain[par][idx] - df_parremain[par][rg]
- if x > dist:
- d = None
- return None
- d2 += x*x
- d = sqrt(d2)
- if d < dist:
- return d
- # print(idx, d)
- return d
- def find_close_param(df_parremain, par_names, rg, dist):
- """
- Gets all parameter sets in df_parremain that are close to a given parameter
- set (at distance < dist).
- Returns the list of ranks of such parameters and list of distances¨2
- """
- lst_closepar_rg = []
- lst_closepar_d = []
- for idx in df_parremain.index:
- if idx != rg:
- """
- d2 = 0
- for par in par_names:
- x = df_parremain[par][idx] - df_parremain[par][rg]
- if x > dist:
- d2 += x*x
- d = sqrt(d2)
- """
- d = calculate_dist_par(df_parremain, par_names, idx, rg, dist)
- if d is not None:
- # print idx, d
- lst_closepar_rg.append(idx)
- lst_closepar_d.append(d)
- return lst_closepar_rg, lst_closepar_d
- def Calc_disp(df_bhvremain, source_rg, lst_closepar_rg, behav_col):
- """
- """
- behavs_cues = df_bhvremain[df_bhvremain.columns[behav_col]]
- # =========== normalization of endangle => division by 100 ===========
- behav_normalized = copy.deepcopy(behavs_cues)
- behav_normalized[df_bhvremain.columns[behav_col][0]] *= 0.01
- lst_bhv_dist = []
- for idx in lst_closepar_rg:
- if idx != source_rg:
- bhv_d2 = 0
- for bhv in df_bhvremain.columns[behav_col]:
- x = behav_normalized[bhv][idx] -\
- behav_normalized[bhv][source_rg]
- bhv_d2 += x*x
- bhv_d = sqrt(bhv_d2)
- lst_bhv_dist.append(bhv_d)
- return lst_bhv_dist
- def getValuesFromText(txt):
- t2 = txt
- xtab = []
- while t2.find('\t') != -1:
- t1 = t2[:t2.find('\t')]
- t2 = t2[t2.find('\t')+1:]
- xtab.append(t1)
- t1 = t2[:t2.find('\n')]
- xtab.append(t1)
- return xtab
- def read_dist_list(pathGEP, baseName):
- """
- Reads a table containing as columns: idx, run, score, nBhvOK, density
- This table was saved as a text file in a previous run of grid_method()
- """
- tabFinal = []
- # idx = 0
- completeName = os.path.join(pathGEP, baseName + '.txt')
- with open(completeName, 'r') as fich:
- columns_txt = fich.readline()
- columns = getValuesFromText(columns_txt)
- while 1:
- # while idx < 9:
- tab1 = []
- tab2 = []
- valid_line = True
- txt = fich.readline()
- if txt == '':
- break
- else:
- tab1 = getValuesFromText(txt)
- # print(tab1)
- try:
- x = int(tab1[0])
- except Exception as e:
- x = tab1
- print(e, "alpha-numeric line", x)
- valid_line = False
- if valid_line:
- for k in range(len(columns)):
- try:
- if tab1[k].find('.') == -1: # not a float
- tab2.append(int(tab1[k]))
- else:
- tab2.append(float(tab1[k]))
- # tab2.append(tab1[k])
- except Exception as e:
- if len(tab1) < len(columns):
- tab2.append(0)
- else:
- tab2.append(np.NaN)
- k = 0
- if (verbose > 2):
- print(e)
- tabFinal.append(tab2)
- # idx += 1
- tab_dist = tabFinal
- fich.close()
- df_dist = pd.DataFrame(tab_dist[:],
- columns=columns,
- index=np.arange(len(tab_dist[:])))
- return df_dist
- def read_tab_scores(pathGEP, baseName):
- tabFinal = []
- # idx = 0
- completeName = os.path.join(pathGEP, baseName + '.txt')
- with open(completeName, 'r') as fich:
- columns_txt = fich.readline()
- columns = getValuesFromText(columns_txt)
- while 1:
- # while idx < 9:
- tab1 = []
- tab2 = []
- valid_line = True
- txt = fich.readline()
- if txt == '':
- break
- else:
- tab1 = getValuesFromText(txt)
- # print(tab1)
- try:
- x = int(tab1[0])
- except Exception as e:
- x = tab1
- print(e, "alpha-numeric line", x)
- valid_line = False
- if valid_line:
- for k in range(len(columns)):
- try:
- if tab1[k].find('.') == -1: # not a float
- tab2.append(int(tab1[k]))
- else:
- tab2.append(float(tab1[k]))
- # tab2.append(tab1[k])
- except Exception as e:
- if len(tab1) < len(columns):
- tab2.append(0)
- else:
- tab2.append(np.NaN)
- k = 0
- if (verbose > 2):
- print(e)
- tabFinal.append(tab2)
- # idx += 1
- tab_scores = tabFinal
- fich.close()
- return tab_scores
- def get_titre(path, baseName):
- titre = "{}/{}".format(path, baseName)
- titre = titre.replace("\\", "/")
- slashPositions = [pos for pos, char in enumerate(titre) if char == "/"]
- end1 = max([x for x in slashPositions[:-1] if x < 100])
- tit1 = titre[: end1+1]
- if end1 < max(slashPositions):
- end2 = max([x for x in slashPositions if x < 160])
- tit2 = titre[end1+1:end2+1]
- if end2 < max(slashPositions):
- end3 = max([x for x in slashPositions if x < 240])
- tit3 = titre[end2+1:end3+1]
- if end3 < max(slashPositions):
- tit4 = titre[end3+1:]
- titr = tit1 + "\n" + tit2 + "\n" + tit3 + "\n" + tit4
- else:
- tit3 = titre[end2+1:]
- titr = tit1 + "\n" + tit2 + "\n" + tit3
- else:
- tit3 = titre[end2+1:]
- titr = tit1 + "\n" + tit2 + "\n" + tit3
- else:
- titr = titre
- return titr
- def includePerturbationInAsim(pertStart, pertDur, pertForce,
- asimFileName, new_run_dir):
- """
- """
- def indent(elem, level=0):
- i = "\n" + level * " "
- if len(elem):
- if not elem.text or not elem.text.strip():
- elem.text = i + " "
- for child in elem:
- indent(child, level + 1)
- if not child.tail or not child.tail.strip():
- child.tail = i
- if level and (not elem.tail or not elem.tail.strip()):
- elem.tail = i
- pertStartTxt = '%s' % pertStart
- pertEnd = pertStart + pertDur
- pertEndTxt = '%s' % pertEnd
- pertForceTxt = '%s' % pertForce
- lookupType = []
- lookupID = []
- lookupName = []
- lookupElement = []
- def lookupAppend(el, elType):
- lookupType.append(elType)
- lookupID.append(el.find("ID").text)
- lookupName.append(el.find("Name").text)
- lookupElement.append(el)
- asimFile = os.path.join(new_run_dir, asimFileName)
- tree = elementTree.parse(asimFile)
- root = tree.getroot()
- path = "Environment/Organisms"
- for el in list(root.find("ExternalStimuli")):
- if el.find("Type").text == "MotorPosition":
- lookupAppend(el, "MotorPosition")
- for el in list(root.find("ExternalStimuli")):
- if el.find("Type").text == "MotorVelocity":
- lookupAppend(el, "MotorVelocity")
- for el in list(root.find("ExternalStimuli")):
- if el.find("Type").text == "Current":
- lookupAppend(el, "ExternalStimuli")
- for el in list(root.find("ExternalStimuli")):
- if el.find("Type").text == "ForceInput":
- lookupAppend(el, "ForceInput")
- external = root.find("ExternalStimuli")
- stim = elementTree.Element("Stimulus")
- def add(tag, text):
- e = elementTree.SubElement(stim, tag)
- e.text = text
- if "perturbation" not in lookupName:
- add("ID", str(uuid.uuid4()))
- add("Name", "perturbation")
- add("AlwaysActive", "False")
- add("Enabled", "True")
- add("ModuleName", "")
- add("Type", "ForceInput")
- add("StructureID", "e6b0c0e2-b87c-4391-8637-55925b1b6ca4")
- add("BodyID", "49172659-54fc-42dd-8d4c-cb5b5e921576")
- add("StartTime", pertStartTxt)
- add("EndTime", pertEndTxt)
- rel = elementTree.SubElement(stim, "RelativePosition")
- rel.set("x", "0")
- rel.set("y", "0")
- rel.set("z", "0")
- add("ForceX", "0")
- add("ForceY", "0")
- add("ForceZ", pertForceTxt)
- for tag in ["TorqueX", "TorqueY", "TorqueZ"]:
- add(tag, "0")
- children = list(external)
- insert_at = next(
- (i for i, el in enumerate(children)
- if el.find("Type") is not None and el.find("Type").text == "MotorVelocity"),
- len(children)
- )
- external.insert(insert_at, stim)
- indent(root)
- tree.write(asimFile, encoding="utf-8", xml_declaration=True)
- # ================ Modification of the perturbation parameters ============
- else:
- for stim in external.findall("Stimulus"):
- t = stim.find("Type")
- if t is not None and t.text == "ForceInput":
- stim.find("Name").text = "perturbation"
- stim.find("StartTime").text = pertStartTxt
- stim.find("EndTime").text = pertEndTxt
- stim.find("ForceX").text = "0"
- stim.find("ForceY").text = "0"
- stim.find("ForceZ").text = pertForceTxt
- stim.find("TorqueX").text = "0"
- stim.find("TorqueY").text = "0"
- stim.find("TorqueZ").text = "0"
- break
- tree.write(asimFile, encoding="utf-8", xml_declaration=True)
- def includePerturbationinAproj(pertStart, pertDur, pertForce,
- aprojFileName, new_run_dir):
- def indent(elem, level=0):
- i = "\n" + level * " "
- if len(elem):
- if not elem.text or not elem.text.strip():
- elem.text = i + " "
- for child in elem:
- indent(child, level + 1)
- if not child.tail or not child.tail.strip():
- child.tail = i
- if level and (not elem.tail or not elem.tail.strip()):
- elem.tail = i
- pertStartTxt = '%s' % pertStart
- pertEnd = pertStart + pertDur
- pertEndTxt = '%s' % pertEnd
- pertForceTxt = '%s' % pertForce
- aprojlookupType = []
- aprojlookupID = []
- aprojlookupName = []
- aprojlookupElement = []
- def aprojlookupAppend(el, elType):
- aprojlookupType.append(elType)
- aprojlookupID.append(el.find("ID").text)
- aprojlookupName.append(el.find("Name").text)
- aprojlookupElement.append(el)
- aprojFile = os.path.join(new_run_dir, aprojFileName)
- aprojtree = elementTree.parse(aprojFile)
- aprojroot = aprojtree.getroot()
- print("\nREADING .aproj elements...")
- # print "Stimuli"
- path = "Simulation/Stimuli"
- for el in list(aprojroot.find(path)):
- # print el.find("Name").text,
- aprojlookupAppend(el, "Stimulus")
- stimuli = aprojroot.find("Simulation/Stimuli")
- stim = elementTree.Element("Stimulus")
- def add_text(tag, text):
- e = elementTree.SubElement(stim, tag)
- e.text = text
- return e
- def add_attrib(tag, attrs):
- return elementTree.SubElement(stim, tag, attrs)
- if "perturbation" not in aprojlookupName:
- add_text("AssemblyFile", "AnimatGUI.dll")
- add_text("ClassName", "AnimatGUI.DataObjects.ExternalStimuli.Force")
- add_text("Name", "perturbation")
- add_text("ID", str(uuid.uuid4()))
- add_attrib("StartTime", {"Value": pertStartTxt, "Scale": "None", "Actual": pertStartTxt})
- add_attrib("EndTime", {"Value": pertEndTxt, "Scale": "None", "Actual": pertEndTxt})
- add_attrib("StepInterval", {"Value": "0", "Scale": "milli", "Actual": "0"})
- add_text("AlwaysActive", "False")
- add_text("Enabled", "True")
- add_text("ValueType", "Constant")
- add_text("Equation", "0")
- add_text("StructureID", "e6b0c0e2-b87c-4391-8637-55925b1b6ca4")
- add_text("PartID", "49172659-54fc-42dd-8d4c-cb5b5e921576")
- add_attrib("PositionX", {"Value": "0", "Scale": "None", "Actual": "0"})
- add_attrib("PositionY", {"Value": "0", "Scale": "None", "Actual": "0"})
- add_attrib("PositionZ", {"Value": "0", "Scale": "None", "Actual": "0"})
- add_attrib("ForceX", {"Value": "0", "Scale": "None", "Actual": "0"})
- add_attrib("ForceY", {"Value": "0", "Scale": "None", "Actual": "0"})
- add_attrib("ForceZ", {"Value": pertForceTxt, "Scale": "None", "Actual": pertForceTxt})
- add_attrib("TorqueX", {"Value": "0", "Scale": "None", "Actual": "0"})
- add_attrib("TorqueY", {"Value": "0", "Scale": "None", "Actual": "0"})
- add_attrib("TorqueZ", {"Value": "0", "Scale": "None", "Actual": "0"})
- children = list(stimuli)
- insert_at = next(
- (i for i, el in enumerate(children)
- if el.find("ClassName") is not None and el.find("ClassName").text == "AnimatGUI.DataObjects.ExternalStimuli.MotorVelocity"),
- len(children)
- )
- stimuli.insert(insert_at, stim)
- indent(aprojroot)
- aprojtree.write(aprojFile, encoding="utf-8", xml_declaration=True)
- else:
- for stim in stimuli.findall("Stimulus"):
- cls = stim.find("ClassName")
- if cls is not None and cls.text == "AnimatGUI.DataObjects.ExternalStimuli.Force":
- stim.find("Name").text = "perturbation"
- stim.find("StartTime").set("Value", pertStartTxt)
- stim.find("StartTime").set("Actual", pertStartTxt)
- stim.find("EndTime").set("Value", pertEndTxt)
- stim.find("EndTime").set("Actual", pertEndTxt)
- stim.find("ForceX").set("Value", "0")
- stim.find("ForceX").set("Actual", "0")
- stim.find("ForceY").set("Value", "0")
- stim.find("ForceY").set("Actual", "0")
- stim.find("ForceZ").set("Value", pertForceTxt)
- stim.find("ForceZ").set("Actual", pertForceTxt)
- break
- aprojtree.write(aprojFile, encoding="utf-8", xml_declaration=True)
- def plot_2D_graph_from_array(x, graph_path, baseName,
- nameX, nameY, extent, col_scale_range):
- """
- plot_2D_graph_from_array(x, graph_path, baseName, nameX, nameY, extent)
- x is an array of arrays containing values (typically the number of
- behaviours in each case of the grid defined by the array of arrays, but
- it may be any value that defines a feature of the grid).
- => graph_path is the path to save the graphs (.esp and .pdf)
- => baseName is the name of the graph
- => nameX and nameY are the X and Y axes legends
- => extent is an array [x_min, x_max, y_min, y_max] used to define the
- ranges of x and y axes.
- """
- path = os.path.split(graph_path)[0]
- titre = get_titre(path, baseName)
- # nameX = df_cues_dist.columns[0]
- # nameY = df_cues_dist.columns[1]
- w = 10
- h = 9
- d = 80
- vmin = col_scale_range[0]
- vmax = col_scale_range[1]
- plt.figure(figsize=(w, h), dpi=d)
- color_map = plt.imshow(x, origin='lower',
- extent=extent,
- aspect='auto',
- vmin=vmin, vmax=vmax)
- # color_map = plt.imshow(x, origin='lower')
- # color_map = plt.imshow(x)
- color_map.set_cmap("nipy_spectral")
- # plt.colorbar()
- cbar = plt.colorbar()
- cbar.ax.tick_params(labelsize=18)
- plt.xlabel(nameX, fontsize=18)
- plt.ylabel(nameY, fontsize=18)
- plt.xticks(fontsize=18)
- plt.yticks(fontsize=18)
- plt.suptitle(titre, fontsize=12, y=0.97)
- plt.savefig(os.path.join(graph_path, baseName + '.pdf'))
- plt.savefig(os.path.join(graph_path, baseName + '.eps'))
- plt.show()
- def do_plot_2D_density_map_metrics(df_bhvremain, behav_col, bhv_names,
- graph_path, GEPdataName, nbruns,
- min_x=0, max_x=120,
- min_y=0, max_y=5,
- autoscale=True):
- """
- from df_bhvremain, builds a table 40x40 of number of bhvs contained in each
- frame case.
- """
- nbcol = 40
- nbrow = 40
- """
- min_x = 0
- max_x = 120
- min_y = 0
- max_y = 1.4
- """
- intervalx = (max_x - min_x)/nbcol
- intervaly = round((max_y - min_y)*1000/nbrow)/1000
- extent = [min_x, max_x, min_y, max_y]
- # ================= find rank ond nbruns in orig_rg ===================
- end_rank = df_bhvremain[df_bhvremain["orig_rg"] >= nbruns-1].index[0]
- behav_cues = df_bhvremain[df_bhvremain.columns[behav_col]]
- df_cues = copy.deepcopy(behav_cues)
- df_cues_sel = df_cues.loc[:][:end_rank]
- tab_nb_bhv = []
- x_name = bhv_names[behav_col[0]]
- y_name = bhv_names[behav_col[1]]
- for i in range(nbrow):
- yi = i*intervaly + min_y
- ys = (i+1)*intervaly + min_y
- row_df = df_cues_sel.loc[(df_cues_sel[y_name] >= yi) &
- (df_cues_sel[y_name] < ys)]
- nb_bhv_row = []
- for j in range(nbcol):
- xi = j*intervalx + min_x
- xs = (j+1)*intervalx + min_x
- temp_col_df = row_df.loc[(row_df[x_name] >= xi) &
- (row_df[x_name] < xs)]
- # print yi, ys, xi, xs, temp_col_df
- nb_bhv_row.append(len(temp_col_df[x_name]))
- # print nb_bhv_row
- tab_nb_bhv.append(nb_bhv_row)
- tab_nb_bhv = np.array(tab_nb_bhv)
- nameX = df_cues.columns[0]
- nameY = df_cues.columns[1]
- # nb_runs = len(df_cues_sel)
- color_min = 0
- color_max = tab_nb_bhv.max() + 1
- if not autoscale:
- # --------------------------------------------------------------------
- listChoix = ['colorScale_range']
- listDicColScalRange = [{'colorScale_range': ["inf", "sup"]}]
- listDic_Color_range = [{"inf": color_min, "sup": color_max}]
- factorLimits_keys = ["inf", "sup"]
- titleText = "set limits for factor"
- rep = ChooseInList.listTransmit(parent=None,
- graphNo=0,
- listChoix=listChoix,
- items=factorLimits_keys,
- listDicItems=listDicColScalRange,
- onePerCol=[0],
- colNames=["colorScale_range", 'value'],
- dicValues=listDic_Color_range[0],
- typ="val",
- titleText=titleText)
- listDicColScalRange = rep[0]
- if len(rep[1]) > 0: # No values entered, ESC button was used
- color_min = float(rep[1]['inf'])
- color_max = float(rep[1]['sup'])
- # --------------------------------------------------------------------
- col_scale_range = (color_min, color_max)
- if behav_col[1] == 8:
- ordTyp = "duration"
- elif behav_col[1] == 6:
- ordTyp = "maxSpeed"
- baseName = "{}_{}_{}_{}{}".format(GEPdataName, ordTyp, "densityMap",
- nbruns, "_runs")
- plot_2D_graph_from_array(tab_nb_bhv, graph_path, baseName,
- nameX, nameY, extent, col_scale_range)
- def build_stability_dataframe(df_bhvremain, df_parremain, graph_path,
- GEPdataName, behav_col, par_names,
- search_dist):
- """
- Prepares a dataframe in which, for each behavior (duration,
- amplitude) a mean distance is calculated from
- all behaviors produced by parameters in the vicinyty (dist<search_dist)
- of the parameters of this behavior. When several distances are
- obtained, the mean value is retained.
- """
- if behav_col[1] == 8:
- ordTyp = "duration"
- elif behav_col[1] == 6:
- ordTyp = "maxSpeed"
- baseName = "{}_{}_{}{}".format(GEPdataName[:], ordTyp, "List_stab",
- search_dist)
- completeName = os.path.join(graph_path, baseName + '.txt')
- if not os.path.exists(completeName):
- df_dist = []
- lst_dist = []
- print("please wait... building unstability map")
- for source_rg in df_bhvremain.index:
- res = find_close_param(df_parremain, par_names,
- source_rg, search_dist)
- lst_closepar_rg = res[0]
- # lst_closepar_d = res[1]
- bhv_dist = Calc_disp(df_bhvremain, source_rg,
- lst_closepar_rg, behav_col)
- mean_dist = np.array(bhv_dist).mean()
- # print source_rg, mean_dist
- if source_rg % 10 == 0:
- print("*", end=" ")
- lst_dist.append(mean_dist)
- """"
- df_dist.append(pd.DataFrame({'rg': lst_closepar_rg,
- 'par_d': lst_closepar_d,
- 'bhv_d': bhv_dist},
- index = range(len(lst_closepar_rg))))
- """
- print()
- # ================= saves lst_dist ====================
- # baseName = "{}{}{}_{}".format(GEPdataName[:], ordTyp, "_List_stab",
- # search_dist)
- # completeName = os.path.join(graph_path, baseName + '.txt')
- with open(completeName, 'w') as fich:
- s = "index\tmeandist\n"
- fich.write(s)
- for idx, dist in enumerate(lst_dist):
- s = "{}\t{:2.3f}\n".format(idx, dist)
- fich.write(s)
- fich.close()
- # ================= reads lst_dist ====================
- df_dist = read_dist_list(graph_path, baseName)
- print(df_dist)
- behavs_cues = df_bhvremain[df_bhvremain.columns[behav_col]]
- df_cues_dist = copy.deepcopy(behavs_cues)
- df_cues_dist['dist_bhv'] = df_dist["meandist"]
- df_cues_dist['rg'] = df_cues_dist.index
- else:
- # ================= reads lst_dist ====================
- df_dist = read_dist_list(graph_path, baseName)
- print(df_dist)
- behavs_cues = df_bhvremain[df_bhvremain.columns[behav_col]]
- df_cues_dist = copy.deepcopy(behavs_cues)
- df_cues_dist['dist_bhv'] = df_dist["meandist"]
- df_cues_dist['rg'] = df_cues_dist.index
- return df_cues_dist
- def do_plot_2D_stability_map(MyWin, df_cues_dist, search_dist, graph_path,
- GEPdataName):
- """
- plots the stability map
- """
- nbcol = 40
- nbrow = 40
- """
- min_x = 0
- max_x = 120
- min_y = 0.2
- max_y = 1.4
- """
- behav_col = MyWin.behav_col
- bhv_names = MyWin.bhv_names
- name_x = bhv_names[behav_col[0]]
- name_y = bhv_names[behav_col[1]]
- max_x_bhv = df_cues_dist[name_x].max()
- max_y_bhv = df_cues_dist[name_y].max()
- max_x = float(int(max_x_bhv*10)+1)/10
- max_y = float(int(max_y_bhv*10)+1)/10
- min_x = 0
- min_y = 0
- intervalx = (max_x - min_x)/nbcol
- intervaly = round((max_y - min_y)*1000/nbrow)/1000
- tab_nb_bhv = []
- map_bhv = []
- tab_dist_bhv = []
- name_x = MyWin.bhv_names[MyWin.behav_col[0]]
- name_y = MyWin.bhv_names[MyWin.behav_col[1]]
- for i in range(nbrow):
- yi = i*intervaly + min_y
- ys = (i+1)*intervaly + min_y
- row_df = df_cues_dist.loc[(df_cues_dist[name_y] >= yi) &
- (df_cues_dist[name_y] < ys)]
- map_bhv_row = []
- nb_bhv_row = []
- dist_bhv_row = []
- for j in range(nbcol):
- xi = j*intervalx + min_x
- xs = (j+1)*intervalx + min_x
- temp_col_df = row_df.loc[(row_df[name_x] >= xi) &
- (row_df[name_x] < xs)]
- # print yi, ys, xi, xs, temp_col_df
- map_bhv_row.append([yi, ys, xi, xs,
- len(temp_col_df[name_x])])
- nb_bhv_row.append(len(temp_col_df[name_x]))
- try:
- # we cannot use mean() because this will give NaN in
- # temp_col_df["dist_bhv"].mean()
- # ===== elimination of cases without distance (NaN) ======
- tmp_df = copy.deepcopy(temp_col_df["dist_bhv"])
- tmp_ser = pd.Series(tmp_df)
- nan_elems = tmp_ser.isnull()
- remove_nan = tmp_ser[~nan_elems]
- tmpdist = np.array(remove_nan)
- if len(tmpdist) > 0:
- dist_bhv_row.append(tmpdist.mean())
- else:
- dist_bhv_row.append(np.NaN)
- except Exception as e:
- if (verbose > 2):
- print(e)
- # if in the process a case is empty (NaN) -> a negative value
- # is given: -0.01 is small enough for the case to appear in black
- # but not too larg to modify the color scale
- stab_bhv_row = [-0.01 if isnan(x) else x for x in dist_bhv_row]
- # print nb_bhv_row
- tab_nb_bhv.append(nb_bhv_row)
- map_bhv.append(map_bhv_row)
- tab_dist_bhv.append(stab_bhv_row)
- tab_nb_bhv = np.array(tab_nb_bhv)
- map_bhv = np.array(map_bhv)
- tab_dist_bhv = np.array(tab_dist_bhv)
- extent = [min_x, max_x, min_y, max_y]
- nameX = df_cues_dist.columns[0]
- nameY = df_cues_dist.columns[1]
- nb_runs = len(df_cues_dist)
- if behav_col[1] == 8:
- ordTyp = "duration"
- elif behav_col[1] == 6:
- ordTyp = "maxSpeed"
- col_scale_range = (-0.01, tab_nb_bhv.max())
- baseName = "{}_{}_{}_{}".format(GEPdataName, ordTyp, nb_runs, "densityMap")
- plot_2D_graph_from_array(tab_nb_bhv, graph_path, baseName,
- nameX, nameY, extent, col_scale_range)
- baseName = "{}_{}_{}_{}_{}".format(GEPdataName, ordTyp, nb_runs,
- "stabilityMap", search_dist)
- col_scale_range = (-0.01, tab_dist_bhv.max())
- plot_2D_graph_from_array(tab_dist_bhv, graph_path, baseName,
- nameX, nameY, extent, col_scale_range)
- def makeDensityMap_contour(rel_behavs_cues, step=0.05,
- xmin=None, xmax=None, ymin=None, ymax=None):
- """
- builds a matrix containing the number of elements in each unit surface
- (squarre step x step) covering the X and the Y range of behavs_cues
- """
- # xmin = None
- df = copy.deepcopy(rel_behavs_cues)
- if xmin is None:
- xmin = min(df[df.columns[0]]) - step
- xmax = max(df[df.columns[0]])
- ymin = min(df[df.columns[1]]) - step
- ymax = max(df[df.columns[1]])
- else:
- xmin = xmin - step
- ymin = ymin - step
- xmin_gr = int(xmin/step) * step
- xmax_gr = (int(xmax/step) + 1) * step
- print(xmin, xmax)
- ymin_gr = int(ymin/step) * step
- ymax_gr = (int(ymax/step) + 1) * step
- print(ymin, ymax)
- listx = np.linspace(xmin_gr, xmax_gr, int((xmax_gr-xmin_gr)/step)+1)
- listy = np.linspace(ymin_gr, ymax_gr, int((ymax_gr-ymin_gr)/step)+2)
- density_map = []
- # xmin = min(df[df.columns[0]])
- # xmax = max(df[df.columns[0]])
- # print xmin, xmax
- # ymin = min(df[df.columns[1]])
- # ymax = max(df[df.columns[1]])
- # print ymin, ymax
- for yval in listy:
- res = []
- for xval in listx:
- # print x*step, y*step
- tmp_df = copy.deepcopy(df)
- onTheSpotx1 = (tmp_df[tmp_df.columns[0]] > xval)
- tmp_df = tmp_df[onTheSpotx1]
- onTheSpotx2 = (tmp_df[tmp_df.columns[0]] < xval+step)
- tmp_df = tmp_df[onTheSpotx2]
- onTheSpoty1 = (tmp_df[tmp_df.columns[1]] > yval)
- tmp_df = tmp_df[onTheSpoty1]
- onTheSpoty2 = (tmp_df[tmp_df.columns[1]] < yval+step)
- tmp_df = tmp_df[onTheSpoty2]
- # print len(tmp_df)
- res.append(len(tmp_df))
- density_map.append(res)
- return density_map, listx, listy
- def plot_3D_density_map_contour(df_bhvremain, behav_col, step=0.02,
- incline=60, rot=-90,
- xmin=None, xmax=None, ymin=None, ymax=None):
- """
- Plots a 3D-Graph using the density_map and the listx, listy to build
- a X, Y grid
- """
- behavs_cues = df_bhvremain[df_bhvremain.columns[behav_col]]
- rel_behavs_cues = behavs_cues/[MyWin.scale_x, MyWin.scale_y]
- res = makeDensityMap_contour(rel_behavs_cues, step=step,
- xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax)
- (density_map, listx, listy) = res
- nameX = rel_behavs_cues.columns[0]
- nameY = rel_behavs_cues.columns[1]
- X, Y = np.meshgrid(listx, listy)
- Z = np.array(density_map)
- fig = plt.figure(figsize=(7, 7), dpi=100)
- ax = plt.axes(projection='3d')
- ax.contour3D(X, Y, Z, 50, cmap='cool')
- # ax.contour3D(X, Y, Z, 50, cmap='binary')
- # ax.contour3D(X, Y, Z, 50, cmap='viridis')
- ax.set_xlabel(nameX)
- ax.set_ylabel(nameY)
- ax.set_zlabel("Nb evts")
- ax.view_init(incline, rot)
- fig.show()
- def plot_2D_density_map_contour(MyWin, df_bhvremain, behav_col, graph_path,
- strGEPdataName, nbruns=None,
- step=0.02, aimbhv=[],
- xmin=0, xmax=1.2, ymin=0, ymax=1.5,
- saveDM=False):
- """
- Plots a 2D-Graph using the density_map (contour) and the listx, listy to
- build a X, Y grid. Density_map, listx and listy are obtained from the
- function makeDensityMap_contour()
- """
- behav_cues = df_bhvremain[df_bhvremain.columns[behav_col]]
- if nbruns is None:
- nbruns = df_bhvremain["orig_rg"].max()
- # ================= find rank ond nbruns in orig_rg ===================
- end_rank = df_bhvremain[df_bhvremain["orig_rg"] >= nbruns].index[0]
- df_cues = copy.deepcopy(behav_cues)
- df_cues_sel = df_cues.loc[:][:end_rank]
- rel_behavs_cues = df_cues_sel/[MyWin.scale_x, MyWin.scale_y]
- res = makeDensityMap_contour(rel_behavs_cues, step=step,
- xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax)
- (density_map, listx, listy) = res
- nameX = rel_behavs_cues.columns[0]
- nameY = rel_behavs_cues.columns[1]
- if behav_col[1] == 8: # if ordonate is duration...
- labelnameX = nameX + "(x 0.01)"
- labelnameY = nameY
- elif behav_col[1] == 6:
- labelnameX = nameX + "(x 0.01)"
- labelnameY = nameY + "(x 0.01)"
- X, Y = np.meshgrid(listx, listy)
- Z = np.array(density_map)
- Z[Z == 1] = 4 # replace all 1 by 4
- Z[Z == 2] = 4 # replace all 1 by 4
- Z[Z == 3] = 4 # replace all 1 by 4
- nbniv = int(np.amax(Z))
- plt.figure(figsize=(10, 9), dpi=80)
- plt.contourf(X, Y, Z, nbniv, cmap='nipy_spectral', vmin=0, vmax=130)
- cbar = plt.colorbar()
- cbar.ax.tick_params(labelsize=18)
- plt.xlabel(labelnameX, fontsize=18)
- plt.ylabel(labelnameY, fontsize=18)
- plt.xticks(fontsize=18)
- plt.yticks(fontsize=18)
- for point in aimbhv:
- x = point[0]-MyWin.scale_x*step/2
- y = point[1]-MyWin.scale_y*step/2
- relx, rely = x/MyWin.scale_x, y/MyWin.scale_y
- plt.plot(relx, rely, '-p', color='gray',
- markersize=5, linewidth=4,
- markerfacecolor='white',
- markeredgecolor='gray',
- markeredgewidth=2)
- if saveDM:
- path = os.path.split(graph_path)[0]
- strGEPdataName = os.path.splitext(strGEPdataName)[0]
- if behav_col[1] == 8:
- ordTyp = "duration"
- elif behav_col[1] == 6:
- ordTyp = "maxSpeed"
- baseName = "{}_{}_{}{}{}{}".format(strGEPdataName, ordTyp,
- len(df_cues_sel),
- "bhv_DensityContour_",
- nbruns, "runs")
- titre = get_titre(path, baseName)
- plt.suptitle(titre, fontsize=12, y=0.97)
- plt.savefig(os.path.join(graph_path, baseName + '.pdf'))
- plt.savefig(os.path.join(graph_path, baseName + '.eps'))
- plt.show()
- def read_metric_table(graph_path, baseName):
- """
- Reads a table containing as columns: idx, run, score, nBhvOK, density
- This table was saved as a text file in a previous run of grid_method()
- """
- tabFinal = []
- # idx = 0
- completeName = os.path.join(graph_path, baseName + '.txt')
- with open(completeName, 'r') as fich:
- columns_txt = fich.readline()
- colums = getValuesFromText(columns_txt)
- while 1:
- # while idx < 11:
- tab1 = []
- tab2 = []
- valid_line = True
- txt = fich.readline()
- if txt == '':
- break
- else:
- tab1 = getValuesFromText(txt)
- # print(tab1)
- try:
- x = int(tab1[0])
- except Exception as e:
- x = tab1
- print(e, "alpha-numeric line", x)
- valid_line = False
- if valid_line:
- for k in range(len(colums)):
- try:
- if tab1[k].find('.') == -1: # not a float
- tab2.append(int(tab1[k]))
- else:
- tab2.append(float(tab1[k]))
- # tab2.append(tab1[k])
- except Exception as e:
- if len(tab1) < len(colums):
- tab2.append(0)
- else:
- tab2.append(1)
- k = 0
- if (verbose > 2):
- print(e)
- tabFinal.append(tab2)
- # idx += 1
- tab_scores = tabFinal
- fich.close()
- df_score = pd.DataFrame(tab_scores[:],
- columns=colums,
- index=np.arange(len(tab_scores[:])))
- return df_score
- def FitCourseToDataFrame(completeName):
- """
- Reads a text file (FitCourse.txt). The first line is measured param
- names. There may be several successive sessions (CMAeData-00,
- CMAeData-01...). They are grouped in a single dataframe. Returns the
- nparray of data, the dataframe and the list of parameter names.
- """
- tabFinal = []
- tabnewstart = []
- # idx = 0
- # prevline = ""
- # prevtrial = 0
- with open(completeName, 'r') as fich:
- params = fich.readline()
- params = params[:-2] + "\tsaved\n"
- tabparams = getValuesFromText(params)
- while 1:
- # while idx < 11:
- tab1 = []
- tab2 = []
- valid_line = True
- txt = fich.readline()
- if txt == '':
- break
- else:
- tab1 = getValuesFromText(txt)
- # print(tab1)
- if tab1[0] == "1":
- # tabnewstart.append(int(prevtrial))
- # print(prevline)
- tabnewstart.append(len(tabFinal)+1)
- else:
- try:
- x = float(tab1[0])
- except Exception as e:
- x = tab1
- print(e, "alpha-numeric line", x)
- valid_line = False
- if valid_line:
- for k in range(len(tabparams)):
- try:
- tab2.append(float(tab1[k]))
- # tab2.append(tab1[k])
- except Exception as e:
- if len(tab1) < len(tabparams):
- tab2.append(0)
- else:
- tab2.append(1)
- k = 0
- if (verbose > 2):
- print(e)
- nptab2 = np.array(tab2)
- tabFinal.append(nptab2)
- # idx += 1
- print(tabnewstart)
- tabFinal = np.array(tabFinal)
- # tabFinal = np.transpose(tabFinal)
- dataframe = pd.DataFrame(tabFinal, columns=tabparams)
- dataframe.index = np.arange(1, len(dataframe)+1, 1)
- return (tabFinal, dataframe, tabparams, tabnewstart)
- def plotdataframe(dataframe, par, Deb, Fin, tabnewstart,
- unitx="xaxis", unity="yaxis", color="b", ylim=(-5, 50)):
- plt.legend(fontsize=30)
- if Fin-Deb < 20:
- dataframe[Deb:Fin][par].plot(color=color, marker="o")
- else:
- dataframe[Deb:Fin][par].plot(color=color, ylim=ylim)
- for idx, newstart in enumerate(tabnewstart):
- if newstart in range(Deb, Fin):
- plt.axvline(tabnewstart[idx])
- plt.xlabel(unitx, fontsize=20)
- plt.ylabel(unity, fontsize=20)
- plt.legend(loc=0, fontsize=18)
- plt.xticks(fontsize=18)
- plt.yticks(fontsize=18)
- # plt.rcParams.update({'font.size': 28})
- def plotdf_improve(dataframe, par, Deb, Fin, tabnewstart,
- unitx="xaxis", unity="yaxis", color="b", ylim=(-5, 50)):
- """
- Plots one parameter (par) against time from Deb to Fin. Each time a new
- start is present in tabnewstart, a vertical line is traced.
- """
- if (par == "eval") or (par == "mse"):
- par2 = "bestfit"
- if par == "coactpenality":
- par2 = "bestcoact"
- new_df = copy.deepcopy(dataframe)
- # ====== creates one new column =================
- lst_bestfit = []
- lst_bestcoact = []
- # bestfit = new_df["eval"][1]
- bestfit = new_df[par][1]
- bestcoact = new_df["coactpenality"][1]
- for idx in range(1, len(new_df)):
- lst_bestfit.append(bestfit)
- lst_bestcoact.append(bestcoact)
- if idx in tabnewstart:
- bestfit = new_df["eval"][idx]
- bestcoact = new_df["coactpenality"][idx]
- """
- # if idx in range(len(new_df)-10, len(new_df)):
- if idx in range(1169, 1200):
- print idx, new_df["eval"][idx], "=>", bestfit,
- print " \t", new_df["coactpenality"][idx], "=>", bestcoact
- """
- if new_df["eval"][idx+1] < bestfit:
- bestfit = new_df["eval"][idx+1]
- if new_df["coactpenality"][idx+1] < bestcoact:
- bestcoact = new_df["coactpenality"][idx+1]
- lst_bestfit.append(bestfit)
- lst_bestcoact.append(bestcoact)
- new_df.loc[:, 'bestfit'] = lst_bestfit
- new_df.loc[:, 'bestcoact'] = lst_bestcoact
- """
- saved_OK = dataframe['saved'] == 1
- df = dataframe[saved_OK]
- if len(df) > 0:
- print df
- """
- ylimMax = new_df[Deb:Fin][par2].max()*1.2
- ylimMin = -ylimMax/20
- ylim=(ylimMin, ylimMax)
- # plt.legend(fontsize=30)
- if Fin-Deb < 20:
- new_df[Deb:Fin][par2].plot(color=color, marker="o")
- else:
- new_df[Deb:Fin][par2].plot(color=color, ylim=ylim)
- for idx, newstart in enumerate(tabnewstart):
- # if newstart in range(Deb, Fin):
- if newstart in range(new_df.index[Deb], new_df.index[Fin-1]):
- plt.axvline(tabnewstart[idx])
- plt.xlabel(unitx, fontsize=20)
- plt.ylabel(unity, fontsize=20)
- # plt.legend(loc=0, fontsize=18)
- plt.xticks(fontsize=18)
- plt.yticks(fontsize=18)
- # plt.rcParams.update({'font.size': 28})
- def adaptScale(max_valY):
- y = max_valY * 10000
- while (y > 10):
- y = y/10
- # BarreY = int(round((max_valY / y)))
- BarreY = max_valY / y
- if y < 1.1:
- scaleYMax = 1.1 * BarreY
- elif y < 1.2:
- scaleYMax = 1.2 * BarreY
- elif y < 1.5:
- scaleYMax = 1.5 * BarreY
- elif y < 2:
- scaleYMax = 2 * BarreY
- elif y < 5:
- scaleYMax = int(y + 1) * BarreY
- else:
- scaleYMax = int(y + 1) * BarreY
- return scaleYMax
- def graphfromFitCourse(path, FitCourseFileName):
- """
- Uses the path to FitCourse to built a plot of the corresponding
- dataframe
- """
- completeName = os.path.join(path, FitCourseFileName)
- baseName = os.path.splitext(FitCourseFileName)[0]
- (tabFinal, dataframe,
- tabparams, tabnewstart) = FitCourseToDataFrame(completeName)
- df = copy.deepcopy(dataframe)
- plt.figure(figsize=(20, 20), dpi=50)
- plt.subplot(331)
- Deb = 0
- Fin = len(df)
- par = "mse"
- max_valY = df[Deb:Fin][par].max()
- min_valY = df[Deb:Fin][par][Fin]
- ylimMax = adaptScale(max_valY)
- if (max_valY - min_valY) < (0.5 * ylimMax):
- ylimMax *= 2
- ylimMin = -ylimMax/20
- plotdataframe(df, "mse", Deb, Fin, tabnewstart,
- unitx="Trial", unity=par, color="b",
- ylim=(ylimMin, ylimMax))
- plt.subplot(332)
- Deb = int(len(df)/2)
- Fin = len(df)
- max_valY = df[Deb:Fin][par].max()
- ylimMax = adaptScale(max_valY)
- if (max_valY - min_valY) < (0.5 * ylimMax):
- ylimMax *= 2
- ylimMin = -ylimMax/20
- plotdataframe(df, "mse", Deb, Fin, tabnewstart,
- unitx="Trial", unity=par, color="b",
- ylim=(ylimMin, ylimMax))
- plt.subplot(333)
- Deb = int(len(df)*3/4)
- Fin = len(df)
- max_valY = df[Deb:Fin][par].max()
- ylimMax = adaptScale(max_valY)
- # if (max_valY - min_valY) < (0.5 * ylimMax):
- # ylimMax *= 2
- ylimMin = -ylimMax/20
- plotdataframe(df, "mse", Deb, Fin, tabnewstart,
- unitx="Trial", unity=par, color="b",
- ylim=(ylimMin, ylimMax))
- plt.subplot(334)
- Deb = 0
- Fin = len(df)
- par = "coactpenality"
- plotdataframe(df, "coactpenality", Deb, Fin, tabnewstart,
- unitx="Trial", unity=par, color="orange")
- plt.subplot(335)
- Deb = int(len(df)/2)
- Fin = len(df)
- plotdataframe(df, "coactpenality", Deb, Fin, tabnewstart,
- unitx="Trial", unity=par, color="orange")
- plt.subplot(336)
- Deb = int(len(df)*3/4)
- Fin = len(df)
- plotdataframe(df, "coactpenality", Deb, Fin, tabnewstart,
- unitx="Trial", unity=par, color="orange")
- plt.subplot(337)
- Deb = 0
- Fin = len(df)
- par = "mse"
- max_valY = df[Deb:Fin][par][Deb + 1]
- min_valY = df[Deb:Fin][par][Fin]
- ylimMax = adaptScale(max_valY)
- if (max_valY - min_valY) < (0.5 * ylimMax):
- ylimMax *= 2
- ylimMin = -ylimMax/20
- plotdf_improve(df, "mse", Deb, Fin, tabnewstart,
- unitx="Trial", unity=par, color="b",
- ylim=(ylimMin, ylimMax))
- plt.subplot(338)
- Deb = int(len(df)/2)
- Fin = len(df)
- max_valY = df[Deb:Fin][par][Deb + 1]
- ylimMax = adaptScale(max_valY)
- if (max_valY - min_valY) < (0.5 * ylimMax):
- ylimMax *= 2
- ylimMin = -ylimMax/20
- plotdf_improve(df, "mse", Deb, Fin, tabnewstart,
- unitx="Trial", unity=par, color="b",
- ylim=(ylimMin, ylimMax))
- plt.subplot(339)
- Deb = int(len(df)*3/4)
- Fin = len(df)
- max_valY = df[Deb:Fin][par][Deb + 1]
- ylimMax = adaptScale(max_valY)
- # if (max_valY - min_valY) < (0.5 * ylimMax):
- # ylimMax *= 2
- ylimMin = -ylimMax/20
- plotdf_improve(df, "mse", Deb, Fin, tabnewstart,
- unitx="Trial", unity=par, color="b",
- ylim=(ylimMin, ylimMax))
- plt.gcf().subplots_adjust(left=0.09, right=0.95, top=0.9, bottom=0.1,
- wspace=0.2, hspace=0.25)
- bestfit = df["mse"].min()
- bestfitline = df.index[df['mse'] == bestfit].values
- if len(bestfitline) > 1:
- bestfitlineVal = bestfitline[0]
- else:
- bestfitlineVal = bestfitline
- titre = get_titre(path, FitCourseFileName)
- # titre = completeName
- titre = titre + "\n" + "bestfit= %3.3f at line %3d" % (bestfit,
- bestfitlineVal)
- plt.suptitle(titre, fontsize=20)
- plt.savefig(os.path.join(path, baseName + '.pdf'))
- plt.savefig(os.path.join(path, baseName + '.eps'))
- plt.show()
- def select_chartcol(optSet, colnames):
- list_elem = colnames
- typ = "chart_col"
- print("Select sensory neurons to plot (validate the selection window)")
- selected = optSet.sensColChartNames
- text = "select sensory neurons to plot"
- list_sensory_neur = choose_elements_in_list(list_elem, typ, selected, text)
- print("Select alpha MNs to plot (validate the selection window)")
- selected = optSet.mnColChartNames
- text = "select alpha MNs to plot"
- list_alpha_neur = choose_elements_in_list(list_elem, typ, selected, text)
- print("Select gamma MNs to plot (check and validate selection window)")
- selected = []
- text = "select gamma MN to plot"
- list_gamma_neur = choose_elements_in_list(list_elem, typ, selected, text)
- return list_sensory_neur, list_alpha_neur, list_gamma_neur
- def graph_chart_elements(optSet, chart_path, chartName,
- lstChartColNam=["1FlxPotMuscle", "1ExtPotMuscle"],
- y_label="EMG (mV)",
- title="_EMG_Mvt"):
- """
- Uses the path, chartname to built a plot of a dataframe of chart data.
- """
- # EMGsNames = ['1FlxPotMuscle', '1ExtPotMuscle']
- colnames = optSet.chartColNames
- # completeName = os.path.join(chart_path, chartName)
- completeName = chart_path + "/" + chartName
- baseName = os.path.splitext(chartName)[0]
- my_palette = sns.color_palette("tab10")
- # Tdf[:0.6]
- (L, df, titre, tabparams) = chartToDataFrame(completeName,
- colnames=colnames)
- df.index = df.Time
- df[:0.6]
- plt.figure(figsize=(20, 8), dpi=50)
- plt.subplot(121)
- plt.rc('xtick', labelsize=14) # fontsize of the x tick labels
- plt.rc('ytick', labelsize=14) # fontsize of the x tick labels
- for col in range(len(lstChartColNam)):
- print()
- df_EMG = df[:][lstChartColNam[col]] * 1000
- df_EMG.loc[4:7].plot(color=my_palette[col])
- unitx = "Time (s)"
- # unity = "EMG (mV)"
- unity = y_label
- plt.xlabel(unitx, fontsize=18)
- plt.ylabel(unity, fontsize=18)
- plt.legend(fontsize=12)
- plt.subplot(122)
- df.loc[4:7]["Elbow"].plot(color="c")
- unitx = "Time (s)"
- unity = "Elbow Mvt (degres)"
- plt.xlabel(unitx, fontsize=18)
- plt.ylabel(unity, fontsize=18)
- plt.legend(fontsize=12)
- plt.suptitle(titre, fontsize=20)
- plt.savefig(os.path.join(chart_path, baseName + title + '.pdf'))
- #plt.savefig(os.path.join(chart_path, baseName + title + '.eps'))
- plt.show()
- def graph_triphasic(optSet, chart_path, chartName, EMGsNames):
- """
- Uses the path, chartname to built a plot of a dataframe of chart data.
- """
- # EMGsNames = ['1FlxPotMuscle', '1ExtPotMuscle']
- colnames = optSet.chartColNames
- # completeName = os.path.join(chart_path, chartName)
- completeName = chart_path + "/" + chartName
- baseName = os.path.splitext(chartName)[0]
- my_palette = sns.color_palette("tab10")
- # Tdf[:0.6]
- (L, df, titre, tabparams) = chartToDataFrame(completeName,
- colnames=colnames)
- df.index = df.Time
- df[:0.6]
- plt.figure(figsize=(20, 8), dpi=50)
- plt.subplot(121)
- plt.rc('xtick', labelsize=14) # fontsize of the x tick labels
- plt.rc('ytick', labelsize=14) # fontsize of the x tick labels
- for col in range(2):
- df_EMG = df[:][EMGsNames[col]] * 1000
- df_EMG[4:7].plot(color=my_palette[col])
- unitx = "Time (s)"
- unity = "EMG (mV)"
- plt.xlabel(unitx, fontsize=18)
- plt.ylabel(unity, fontsize=18)
- plt.legend(fontsize=12)
- plt.subplot(122)
- df[4:7]["Elbow"].plot(color="c")
- unitx = "Time (s)"
- unity = "Elbow Mvt (degres)"
- plt.xlabel(unitx, fontsize=18)
- plt.ylabel(unity, fontsize=18)
- plt.legend(fontsize=12)
- plt.suptitle(titre, fontsize=20)
- plt.savefig(os.path.join(chart_path, baseName + '_EMG_Mvt.pdf'))
- plt.savefig(os.path.join(chart_path, baseName + '_EMG_Mvt.eps'))
- plt.show()
- def graphfromchart(optSet, chart_path, chartName, templateFileName,
- comment=""):
- """
- Uses the path, chartname and corresponding mvt template to
- built a plot of a dataframe of chart data.
- """
- colnames = optSet.chartColNames
- completeName = os.path.join(chart_path, chartName)
- baseName = os.path.splitext(chartName)[0]
- rootname = os.path.split(chart_path)[0]
- result_path = rootname + "/ResultFiles"
- expename2 = os.path.split(rootname)[1]
- split2 = os.path.split(rootname)[0]
- expename1 = os.path.split(split2)[1]
- split1 = os.path.split(split2)[0]
- expename0 = os.path.split(split1)[1]
- experoot = expename0 + "/" + expename1 + "/" + expename2
- chart_plot_pickle_name = result_path + "/chart_plot.pkl"
- if os.path.exists(chart_plot_pickle_name):
- with open(chart_plot_pickle_name, 'rb') as f1:
- optSet.chart_column_to_plot = pickle.load(f1)
- list_sensory_neur = optSet.chart_column_to_plot[0]
- list_alpha_neur = optSet.chart_column_to_plot[1]
- list_gamma_neur = optSet.chart_column_to_plot[2]
- else:
- rep = select_chartcol(optSet, colnames)
- list_sensory_neur, list_alpha_neur, list_gamma_neur = rep
- if rep is not None:
- optSet.chart_column_to_plot = list(rep)
- with open(chart_plot_pickle_name, 'wb') as f1:
- pickle.dump(list(rep), f1)
- T = np.loadtxt(templateFileName)
- Tdf = pd.DataFrame(T)
- Tdf.index = Tdf[1]
- my_palette = sns.color_palette("tab10")
- # Tdf[:0.6]
- (L, df, tit, tabparams) = chartToDataFrame(completeName,
- colnames=colnames)
- split_tit = tit.split(";")
- if split_tit[2][:5] == " mse:":
- msetxt = split_tit[2].split(":")[1]
- mseVal = float(msetxt)
- coacttxt = split_tit[3].split(":")[1].split("\n")[0]
- coactVal = float(coacttxt)
- elif split_tit[2][:5] == ' best':
- msetxt = split_tit[2].split(":")[1]
- mseVal = float(msetxt)
- coactVal = None
- else:
- msetxt = split_tit[1].split(":")[1]
- mseVal = float(msetxt)
- coacttxt = split_tit[3].split(":")[1]
- coactVal = float(coacttxt)
- titre = chartName + "; " + experoot
- if coactVal is None:
- titre += "\n mse:{:.4f}".format(mseVal)
- else:
- titre += "\n mse:{:.4f} coactP:{:.4}".format(mseVal, coactVal)
- dfsrtTime = df.Time[0]
- # dfendTime = df.Time[len(df)-1]
- dfendTime = 9.99
- df.index = df.Time
- df[:0.6]
- # add two columns to df : TemplateTime and Template
- df.loc[:, 'TemplateTime'] = Tdf[dfsrtTime:dfendTime][1]
- df.loc[:, 'Template'] = Tdf[dfsrtTime:dfendTime][2]
- if verbose > 3:
- print("15 first rows...")
- print(df[dfsrtTime:dfsrtTime+0.15])
- print("15 last rows")
- print(df[dfendTime-0.15:dfendTime])
- plt.figure(figsize=(20, 15), dpi=50)
- plt.subplot(321)
- muscle = ["Triceps1", "Biceps1"]
- plt.rc('xtick', labelsize=14) # fontsize of the x tick labels
- plt.rc('ytick', labelsize=14) # fontsize of the x tick labels
- for col in range(2):
- df[:dfendTime][muscle[col]].plot(color=my_palette[col])
- unitx = "Time (s)"
- unity = "Force (N)"
- plt.xlabel(unitx, fontsize=18)
- plt.ylabel(unity, fontsize=18)
- plt.legend(fontsize=12)
- list_alpha_neur.sort()
- plt.subplot(322)
- for col, mn in enumerate(list_alpha_neur):
- df_mn = df[:dfendTime][mn] * 1000
- df_mn.plot(color=my_palette[col])
- # df[:]["1ExtAlpha"].plot(color="b")
- # df[:]['1FlxAlpha'].plot(color="r")
- unitx = "Time (s)"
- unity = "Membrane potentoial (mV)"
- plt.xlabel(unitx, fontsize=18)
- plt.ylabel(unity, fontsize=18)
- plt.legend(fontsize=12)
- list_sensory_neur.sort()
- plt.subplot(323)
- for col, sens in enumerate(list_sensory_neur):
- df_sens = df[:dfendTime][sens] * 1000
- df_sens.plot(color=my_palette[col])
- # df[:]["1ExtIa"].plot(color="b")
- # df[:]["1FlxIa"].plot(color="r")
- unitx = "Time (s)"
- unity = "Membrane potentoial (mV)"
- plt.xlabel(unitx, fontsize=18)
- plt.ylabel(unity, fontsize=18)
- plt.legend(fontsize=12)
- list_gamma_neur.sort()
- plt.subplot(324)
- for col, gamma in enumerate(list_gamma_neur):
- df_gamma = df[:dfendTime][gamma] *1000
- df_gamma.plot(color=my_palette[col])
- # df[:]["1ExtGamma"].plot(color="b")
- # df[:]["1FlxGamma"].plot(color="r")
- unitx = "Time (s)"
- unity = "Membrane potentoial (mV)"
- plt.xlabel(unitx, fontsize=18)
- plt.ylabel(unity, fontsize=18)
- plt.legend(fontsize=12)
- plt.subplot(325)
- df[:dfendTime]["Elbow"].plot(color="c")
- df[:dfendTime]["Template"].plot(color="grey")
- unitx = "Time (s)"
- unity = "Elbow Mvt (degres)"
- plt.xlabel(unitx, fontsize=18)
- plt.ylabel(unity, fontsize=18)
- plt.legend(fontsize=12)
- plt.subplot(326)
- df[4.5:6]["Elbow"].plot(color="c")
- df[4.5:6]["Template"].plot(color="grey")
- unitx = "Time (s)"
- unity = "Elbow Mvt (degres)"
- plt.xlabel(unitx, fontsize=18)
- plt.ylabel(unity, fontsize=18)
- plt.legend(fontsize=12)
- plt.gcf().subplots_adjust(left=0.09, right=0.95, top=0.9, bottom=0.1,
- wspace=0.2, hspace=0.25)
- if comment != "":
- titre += "\n " + comment
- plt.suptitle(titre, fontsize=20)
- completename = os.path.join(chart_path, baseName + '_bhvMvt.pdf')
- if os.path.isfile(completename):
- os.remove(completename)
- plt.savefig(os.path.join(chart_path, baseName + '_bhvMvt.pdf'))
- completename = os.path.join(chart_path, baseName + '_bhvMvt.eps')
- if os.path.isfile(completename):
- os.remove(completename)
- plt.savefig(os.path.join(chart_path, baseName + '_bhvMvt.eps'))
- plt.show()
- def choose_title_col(df):
- """
- """
- lst_col_name = list(df.columns)
- listDic_columns = [{'title': lst_col_name[0]}]
- listChoix = list(listDic_columns[0].keys())
- titleText = "select a column for titles"
- rep = ChooseInList.listTransmit(parent=None,
- graphNo=0,
- listChoix=listChoix,
- items=lst_col_name,
- listDicItems=listDic_columns,
- onePerCol=[1],
- colNames=["title"],
- typ="chk",
- titleText=titleText)
- # Create a series from dic_params_order
- listDic_columns = rep[0]
- title_col = listDic_columns[0]['title'][0]
- return title_col
- def choose_lines(lst_ligns):
- """
- """
- lst_items = [str(title) for title in lst_ligns]
- listDic_limits = [{'first': lst_items[0], 'last': lst_items[1]}]
- """
- listChoix = []
- for key in listDic_limits[0].keys():
- listChoix.append(key)
- """
- listChoix = ["first", "last"]
- titleText = "select start and end of rows for radar"
- rep = ChooseInList.listTransmit(parent=None,
- graphNo=0,
- listChoix=listChoix,
- items=lst_items,
- listDicItems=listDic_limits,
- onePerCol=[1, 1],
- colNames=listChoix,
- typ="chk",
- titleText=titleText)
- # Create a series from dic_params_order
- listDic_limits = rep[0]
- first = listDic_limits[0]['first'][0]
- last = listDic_limits[0]['last'][0]
- return (first, last)
- def reorder_df(df, prev_column_order=None):
- """
- """
- if prev_column_order is None:
- col_name = list(df.columns)
- listChoix = ['params']
- listDic_params = [{'params': col_name}]
- params_order = list(zip(col_name, list(range(1, len(col_name)+1, 1))))
- dic_params_order = dict(params_order)
- listDic_params_order = [dic_params_order]
- titleText = "set order of parameters"
- rep = ChooseInList.listTransmit(parent=None,
- graphNo=0,
- listChoix=listChoix,
- items=col_name,
- listDicItems=listDic_params,
- onePerCol=[0],
- colNames=["order"],
- dicValues=listDic_params_order[0],
- typ="val",
- titleText=titleText)
- # Create a series from dic_params_order
- listDic_params = rep[0]
- dic_params_order = rep[1]
- for par in list(dic_params_order.keys()):
- val = dic_params_order[par]
- if int(float(val)) < 10:
- val = "0" + val
- dic_params_order[par] = int(float(val))
- else:
- dic_params_order[par] = int(float(val))
- # print "rep[1]", rep[1]
- s = pd.Series(dic_params_order, name='order')
- s.index.name = 'par_names'
- s = s.reset_index()
- # Create a dataframe from dic_params_order series
- ordered_df = pd.DataFrame(s)
- ordered_df = ordered_df.sort_values(by='order')
- ordered_df.to_pickle(MyWin.graph_path + "/order_param.pkl")
- # get the ordered paramNames
- ordered_names = list(ordered_df["par_names"])
- else:
- ordered_names = prev_column_order
- # Re-order the original df folloing the new column order
- df_new = df.reindex(columns=ordered_names)
- return df_new
- def prepare_spider(df_radar, row, title, overdraw, color, ylim=(-0.2, 1)):
- """
- Procedure used to prepare a radar graph (set position in sheet, polar axes,
- names around the radar)
- """
- (ymin, ymax) = ylim
- # number of variable
- categories = list(df_radar)[0:]
- N = len(categories)
- red_categories = [cat[:cat.find(".")] for cat in categories]
- null_categories = ["" for cat in categories]
- # prepares ticks and labels
- # nbstep = (ymax - ymin) * 10
- # ticks = np.arange(ymin, ymax+float(ymax-ymin)/nbstep,
- # float(ymax-ymin)/nbstep)
- # strticks = ["{:2.2f}".format(tick) for tick in ticks]
- # calculate the angle of each axis in the plot
- # pi = np.pi
- angles = [n / float(N) * 2 * pi for n in range(N)]
- angles += angles[:1]
- # Initialise the spider plot
- if not overdraw:
- ax = plt.subplot(3, 2, row+1, polar=True, )
- plt.subplots_adjust(wspace=0.9, hspace=None)
- labelsize = 9
- offset = (1.08)
- letterscale = 0.036
- else:
- ax = plt.subplot(2, 1, 1, polar=True, )
- plt.gcf().subplots_adjust(left=0.2, bottom=0.2,
- right=0.7, top=0.9,
- wspace=0, hspace=0.2)
- labelsize = 13
- offset = (1.09)
- letterscale = 0.020
- # In order the first axis to be on top:
- ax.set_theta_offset(pi / 2)
- ax.set_theta_direction(-1)
- # Draw one axe per variable + add labels labels yet
- # plt.xticks(angles[:-1], red_categories, color='grey', size=12)
- plt.xticks(angles[:-1], null_categories, color='grey', size=12)
- # Draw ylabels
- ax.set_rlabel_position(0)
- # plt.yticks(ticks, strticks, color="grey", size=10)
- plt.ylim(ymin, ymax)
- # add oriented xlabels
- theta = np.arange(pi/2, -2*pi + pi/2, -2*pi/N)
- rotations = np.rad2deg(theta)
- for x, rotation, label in zip(angles[:-1], rotations, red_categories):
- # offset = (1.1)
- h = offset + (len(label)/2.) * letterscale
- lab = ax.text(x, h, label,
- transform=ax.get_xaxis_transform(),
- ha='center', va='center', fontsize=labelsize)
- lab.set_rotation(rotation)
- # Add a title
- plt.title(title, size=16, color=color, y=1.4)
- return ax, angles
- def add_spider_values(df_radar, row, color, title, filled, ax, angles):
- # get the values to plot
- values = df_radar.loc[row].values.flatten().tolist()
- values += values[:1]
- ax.plot(angles, values, color=color, linewidth=2, linestyle='solid',
- label=title)
- if filled:
- ax.fill(angles, values, color=color, alpha=0.3)
- return ax
- def makeRadarFromExcelPar_csv(df_radar, lst_title, sup_title, sub_title,
- graph_path, name, ylim):
- """
- Builds the global graph of a series of radars (from df_radar), with a
- global name (sup_title), a sub-title, and the path and name of the figure
- to be saved.
- """
- lst_df_rad = []
- # builts a new index for df_radar
- df_radar.index = np.arange(len(df_radar))
- nb_rad = len(df_radar)
- if len(df_radar.index) < 7:
- lst_df_rad.append(df_radar)
- else:
- k = 0
- last_rad = (k+1) * 6
- while last_rad < nb_rad:
- lst_df_rad.append(df_radar[k*6:last_rad])
- k += 1
- last_rad = (k+1) * 6
- lst_df_rad.append(df_radar[k*6:nb_rad])
- # Create a color palette:
- # my_palette = plt.cm.get_cmap("Set2", len(df_radar.index))
- # my_palette = plt.cm.get_cmap("tab20", len(df_radar.index))
- # my_palette = plt.cm.get_cmap("gist_ncar", len(df_radar.index)+2)
- my_palette = mpl.colormaps["gist_ncar"](len(df_radar.index)+2)
- # my_palette = plt.cm.get_cmap("nipy_spectral", len(df_radar.index)+1)
- filled = True
- overdraw = False
- # Loop to plot
- for idx, df_rad in enumerate(lst_df_rad):
- # initialize the figure
- my_dpi = 60
- plt.figure(figsize=(900/my_dpi, 1800/my_dpi), dpi=my_dpi)
- df_rad.index = list(range(len(df_rad)))
- for row in list(df_rad.index):
- rad = row + idx*6
- print(rad)
- color = my_palette(rad)
- title = lst_title[rad]
- # ylim = (0, 1/float(scale_up))
- ax, angles = prepare_spider(df_radar, row, title, overdraw,
- color, ylim)
- add_spider_values(df_radar, row, color, title, filled, ax, angles)
- plt.suptitle(sup_title, fontsize=16)
- plt.figtext(.5, .9, sub_title + str(idx), fontsize=14, ha='center')
- # model_dir = graph_path
- tit = os.path.split(sup_title)[-1]
- sstit = sub_title + str(idx)
- save_eps_pdf(graph_path, tit, sstit)
- # plt.savefig(os.path.join(path, name + sub_title + str(idx) + '.pdf'))
- # plt.savefig(os.path.join(path, name + sub_title + str(idx) + '.eps'))
- plt.show()
- def overdrawRadarFromExcelPar_csv(df_radar, lst_title, sup_title, sub_title,
- graph_path, name, ylim):
- """
- Builds the global graph of overdran selected params (from df_radar), with a
- global name (sup_title), a sub-title, and the path and name of the figure
- to be saved.
- """
- # builts a new index for df_radar
- df_radar.index = np.arange(len(df_radar))
- # Create a color palette:
- # my_palette = plt.cm.get_cmap("Set2", len(df_radar.index))
- # my_palette = plt.cm.get_cmap("tab20", len(df_radar.index))
- my_palette = mpl.colormaps["gist_ncar"](len(df_radar.index)+2)
- # my_palette = plt.cm.get_cmap("nipy_spectral", len(df_radar.index)+1)
- filled = False
- # initialize the figure
- my_dpi = 60
- plt.figure(figsize=(900/my_dpi, 1800/my_dpi), dpi=my_dpi)
- row = 0
- title = ""
- color = "b"
- overdraw = True
- # ax, angles = prepare_spider(df_radar, row, title,
- # overdraw, color, ylim=(-0.2, 1))
- ax, angles = prepare_spider(df_radar, row, title,
- overdraw, color, ylim=ylim)
- for rad in list(df_radar.index):
- print(rad, color)
- color = my_palette(rad)
- title = lst_title[rad]
- ax = add_spider_values(df_radar, rad, color, title, filled, ax, angles)
- # ax.legend(loc='upper right', bbox_to_anchor=(1.9, 1.1))
- # ax.legend(prop=dict(size=18))
- ax.legend(bbox_to_anchor=(1.55, 1.2), prop=dict(size=14))
- plt.suptitle(sup_title, fontsize=16, y=1.02)
- plt.figtext(.5, 0.98, sub_title, fontsize=14, ha='center')
- # model_dir = graph_path
- tit = os.path.split(sup_title)[-1]
- sstit = sub_title + "_overdraw"
- save_eps_pdf(graph_path, tit, sstit)
- # plt.savefig(os.path.join(path, name + sub_title + str(idx) + '.pdf'))
- # plt.savefig(os.path.join(path, name + sub_title + str(idx) + '.eps'))
- plt.show()
- def adaptPaletteTodf(df_glob_sel, factor, step_palette, codeCoul_df_sel):
- """
- From step_palette, creates a set of colors, one for each element in the df.
- """
- colour = [step_palette[i] for i in codeCoul_df_sel['color']]
- if verbose > 2:
- print("... color scale achieved")
- print("len(colour) =", len(colour))
- print("len(df_glob_sel) =", len(df_glob_sel))
- return colour
- def buildStpFilledCol(df, factor):
- """
- Creates a palette of colors one for each element in the df. This is not the
- same as "buildStpDiscretCol()" that get only the colors of levels (missing
- steps in codeCoul_df being removed).
- """
- # ============= creates new "color" & factor df ==============
- codeCoul_df = copy.deepcopy(df[[factor]])
- rg = codeCoul_df.index
- codeCoul_df.loc[:, 'rg'] = rg # index is now in a new column 'rg'
- codeCoul_df.sort_values(factor, axis=0, ascending=True,
- inplace=True, na_position='last')
- sort_factor = np.array(codeCoul_df[factor])
- # ----- creates a quantal progressing array for factor values
- mult = 0.1
- nb_levels = 1
- newsortf = copy.deepcopy(sort_factor)
- newsortf = newsortf * mult
- newsortf = newsortf.astype(int)
- mini = newsortf.min()
- maxi = newsortf.max()
- while nb_levels <= 100:
- mult *= 10
- newsortf = copy.deepcopy(sort_factor)
- # newsortf = (newsortf * 10)
- newsortf = newsortf * mult
- newsortf = newsortf.astype(int)
- mini = newsortf.min()
- maxi = newsortf.max()
- nb_levels = maxi-mini + 1
- if verbose > 2:
- print(nb_levels)
- if nb_levels > 100:
- mult = mult/10
- newsortf = copy.deepcopy(sort_factor)
- # newsortf = (newsortf * 10)
- newsortf = newsortf * mult
- newsortf = newsortf.astype(int)
- mini = newsortf.min()
- maxi = newsortf.max()
- nb_levels = maxi-mini + 1
- if verbose > 2:
- print(nb_levels)
- # ==== creates the color palette associated to nb levels
- step_palette = []
- cmap = plt.get_cmap('gist_rainbow')
- for i in range(nb_levels):
- # print cmap(float(i)/nb_levels, float(10)/10)
- step_palette.append(cmap(float(i)/nb_levels, float(10)/10))
- # ==== crates a list of the colors of each data in factor
- color_sort = []
- for idx, val in enumerate(newsortf):
- color_sort.append(step_palette[val-mini])
- # ------ rescale 'seq_factor' to original scale
- newsortf_scale = newsortf/mult
- # ------ adds the new "quantal progressing factor" column
- seq_factor = "seq_{}".format(factor)
- codeCoul_df.loc[:, seq_factor] = newsortf_scale
- # ------ adds the new "quantal progressing factor" column
- coul = newsortf - newsortf.min()
- coul = coul.astype(int)
- codeCoul_df.loc[:, "color"] = coul
- # ------ re-arrange df according to original rg
- codeCoul_df.sort_values("rg", axis=0, ascending=True,
- inplace=True, na_position='last')
- color = [step_palette[i] for i in codeCoul_df['color']]
- if verbose > 2:
- print("... color scale achieved")
- print("len(color) =", len(color))
- print("len(df) =", len(df))
- return color, codeCoul_df, step_palette
- def buildStpDiscretCol(df_glob, factor):
- """
- Creates a palette of colors corresponding to the number of leves in the
- factor column. This column is first copied and transformed in a series of
- level values. Each level corresponds to a color
- """
- # *********** creates a new rainbow palette n = 20 levels ********
- cmap = plt.get_cmap('gist_rainbow')
- # ============= creates new "color" & factor df ==============
- codeCoul_df = copy.deepcopy(df_glob[[factor]])
- codeCoul_df.dropna(inplace=True)
- rg = codeCoul_df.index
- codeCoul_df.loc[:, 'rg'] = rg # index is now in a new column 'rg'
- codeCoul_df.sort_values(factor, axis=0, ascending=True,
- inplace=True, na_position='last')
- # type(codeCoul_df)
- codeCoul_df.describe()
- sort_factor = codeCoul_df[factor].values
- # sort_factor = codeCoul_df[factor].values.T[0]
- # ----- creates a sequential array for factor values
- mult = 0.1
- nb_levels = 1
- newsortf = copy.deepcopy(sort_factor)
- newsortf = newsortf * mult
- newsortf = newsortf.astype(int)
- mini = newsortf.min()
- maxi = newsortf.max()
- while nb_levels <= 50:
- mult *= 2
- newsortf = copy.deepcopy(sort_factor)
- # newsortf = (newsortf * 10)
- newsortf = newsortf * mult
- newsortf = newsortf.astype(int)
- mini = newsortf.min()
- maxi = newsortf.max()
- nb_levels = maxi-mini + 1
- # print nb_levels
- if nb_levels > 50:
- mult = mult/2
- newsortf = copy.deepcopy(sort_factor)
- # newsortf = (newsortf * 10)
- newsortf = newsortf * mult
- newsortf = newsortf.astype(int)
- mini = newsortf.min()
- maxi = newsortf.max()
- nb_levels = maxi-mini + 1
- # print nb_levels
- print("nb_levels:", nb_levels)
- # ========= build the palettte for factor df ==========
- step_palette = []
- for i in range(nb_levels):
- # print cmap(float(i)/nb_levels, float(10)/10)
- step_palette.append(cmap(float(i)/nb_levels, float(10)/10))
- palette = step_palette
- # the sequential array (newsortf) may contain up to 100 steps
- # So now we limit the superior values of the array
- limsup = mini + len(palette) - 1
- for idx, val in enumerate(newsortf):
- if val > limsup:
- newsortf[idx] = limsup
- mini = newsortf.min()
- maxi = newsortf.max()
- nb_levels = maxi-mini + 1
- # ==== modifies palette for missing levels in 'seq_factor' =====
- step_color = len(palette) // nb_levels
- nbstep_color = 0
- list_colors = [] # list of index of valid colors in palette
- list_colors.append(0) # starts with the first color in palette
- prev_val = newsortf[0] # first value of ordered seq_factor
- for idx, val in enumerate(newsortf):
- if (val - prev_val) < 1: # same value in successive vals
- None
- # print "-",
- else: # increment >= 1
- # print '+{}'.format(val - prev_val),
- nbstep_color = nbstep_color + (val - prev_val)
- list_colors.append(nbstep_color * step_color)
- prev_val = val
- adapt_palette = []
- for col in list_colors:
- adapt_palette.append(palette[col])
- step_pal_misRem = adapt_palette
- # ===============================================================
- # ------ rescale 'seq_factor' to original scale
- newsortf = newsortf/mult
- # ------ adds the new "color" column
- seq_factor = "seq_{}".format(factor)
- codeCoul_df.loc[:, seq_factor] = newsortf
- # ------ reagange df according to original rg
- codeCoul_df.sort_values("rg", axis=0, ascending=True,
- inplace=True, na_position='last')
- print("len(palette) =", len(step_pal_misRem))
- return [step_pal_misRem, codeCoul_df]
- def make_3d_plot_subPlots(df_glob, dataSet, selected_dataSets,
- list_items, faceColItems,
- xlim, ylim, zlim,
- factor, select_3_col, titre, ss_titre, graph_path,
- azim=60, elev=30):
- """
- Draws a 3D scatter plot with a fourth parameter as color scale
- """
- # ======= The following lines are used to debug the plot =======
- """
- self=MyWin
- df_glob = self.df_glob
- factor = self.factor
- select_3_col = self.select_3_col
- ss_titre = self.ss_titre
- titre = "Fig5_3D_Dots_{}__{}__{}".format(select_3_col[0][:13],
- select_3_col[1][:13],
- select_3_col[2][:13])
- dataSet = self.visu_3d.dataSet
- selected_dataSets = self.visu_3d.selected_dataSets
- list_items = self.visu_3d.setnames
- self.graph_settings.choose_factor()
- factor = self.factor
- print("factor =", factor)
- color, codeCoul_df, step_palette = buildStpFilledCol(df_glob, factor)
- # Gets the first set of dots to apply color scale on it
- gl3d_item = self.visu_3d.listgl3dItems[0]
- self.visu_3d.apply_colors(color, gl3d_item)
- azim = self.visu_3d.axis.azim
- elev = self.visu_3d.axis.elev
- xlim = self.visu_3d.axis.get_xlim()
- ylim = self.visu_3d.axis.get_ylim()
- zlim = self.visu_3d.axis.get_zlim()
- model_dir = self.ensembleRunDir
- color, codeCoul_df, step_palette = buildStpFilledCol(df_glob, factor)
- gl3d_item = self.visu_3d.listgl3dItems[0]
- self.visu_3d.apply_colors(color, gl3d_item)
- faceColItems = self.visu_3d.faceColItems
- """
- [step_pal_misRem, codeCoul_df] = buildStpDiscretCol(df_glob, factor)
- seq_factor = "seq_{}".format(factor)
- # seq_factor_col = codeCoul_df[seq_factor]
- classes = list(set(codeCoul_df[seq_factor]))
- classes.sort(reverse=False)
- color_map = dict(list(zip(classes, step_pal_misRem)))
- # colors = seq_factor_col.apply(lambda group: color_map[group])
- # print(colors[0:10])
- # print()
- # =============== Creating plot ==================
- fig = plt.figure(figsize=(8, 8), dpi=100)
- # ax = fig.gca(projection='3d')
- ax = fig.add_axes([0.0, 0.0, 0.8, 0.8], projection='3d')
- ax.view_init(azim=azim, elev=elev)
- ax.set_xlabel(select_3_col[0])
- ax.set_ylabel(select_3_col[1])
- ax.set_zlabel(select_3_col[2])
- ax.set_xlim(xlim)
- ax.set_ylim(ylim)
- ax.set_zlim(zlim)
- subset_txt = ""
- for idx, subset in enumerate(list_items):
- colors = faceColItems[idx]
- # print(colors[0:10])
- if subset in selected_dataSets:
- pos = dataSet[idx]
- (x, y, z) = pos
- ax.scatter(x, y, z, alpha=0.8,
- facecolors=colors,
- edgecolors=colors,
- s=10,
- # label=classes,
- )
- if subset == "main":
- None
- else:
- subset_txt = "{}_{}".format(subset_txt, subset[7:])
- tit = "{}__color={}".format(titre, factor[:13])
- # tit = "{}({})".format(tit, subset_txt[:10])
- orient = "azim({}) elev({})".format(azim, elev)
- titre_2lines = "{}\n{} {}".format(tit, ss_titre, orient)
- titre_3lines = "{}\n{}{}".format(titre_2lines, factor[:13], subset_txt)
- plt.suptitle(titre_3lines, fontsize=14, y=0.90)
- # ================= building legend for color scale ===============
- labels = copy.deepcopy(classes)
- labels.sort(reverse=True)
- nbcolors = len(classes)
- if nbcolors < 50:
- handles = [plt.plot([], [], color=color_map[labels[i]],
- ls="", marker='o',
- markersize=6)[0] for i in range(nbcolors)]
- # In legend order is that of classes (revert order)
- plt.legend(handles, labels, loc=(1.08, 0.00))
- plt.setp(plt.gca().get_legend().get_texts(), fontsize='6')
- else:
- # ------------ 1st set of legend elements ----------------
- labels1 = labels[:nbcolors/2]
- handles1 = [plt.plot([], [], color=color_map[labels[i]],
- ls="", marker='o',
- markersize=6)[0] for i in range(nbcolors/2)]
- # In legend order is that of classes (revert order)
- first_legend = plt.legend(handles1, labels1,
- loc=(1.04, 0.00))
- plt.gca().add_artist(first_legend)
- plt.setp(plt.gca().get_legend().get_texts(), fontsize='6')
- # ------------ 2nd set of legend elements ----------------
- labels2 = labels[nbcolors/2:]
- handles2 = [plt.plot([], [], color=color_map[labels[i]],
- ls="", marker='o',
- markersize=6)[0] for i in range(nbcolors/2,
- nbcolors)]
- # In legend order is that of classes (revert order)
- second_legend = plt.legend(handles2, labels2,
- loc=(1.12, 0.00))
- plt.gca().add_artist(second_legend)
- plt.setp(plt.gca().get_legend().get_texts(), fontsize='6')
- sstit = ss_titre_to_txt(ss_titre)
- sstit = "{}__az({})_el({})".format(sstit, azim, elev)
- ficname = r'{0}\{1}{2}'.format(graph_path, tit, sstit)
- directory = graph_path
- ext = ".pdf"
- complete_name = SaveIncrementNb(directory, ficname, ext)
- file_name = os.path.splitext(complete_name)[0]
- plt.savefig(r'{}.eps'.format(file_name), bbox_inches='tight')
- plt.savefig(r'{}.pdf'.format(file_name), bbox_inches='tight')
- plt.show()
- def saveCSVStructure(self):
- """
- Saves the CSV files sturcture (Angle & Duration, Constants ...)
- """
- structCSVFileName = "CSV_Struct.par"
- complete_structCSVFName = os.path.join(self.graph_path, structCSVFileName)
- csv_structure = [self.graph_path, self.rootdir,
- self.prevListAngles, self.prevListConsts,
- self.prevListTrials, self.prevListColNames,
- self.prevListParams,
- [self.strtTime, self.endTime]]
- f = open(complete_structCSVFName, 'w')
- for idx in range(len(csv_structure)):
- # s = str(idx) + '\t'
- s = ""
- if idx < 2:
- s = csv_structure[idx] + '\n'
- else:
- for idy in range(len(csv_structure[idx])-1):
- tmpval = csv_structure[idx][idy]
- s += "{}".format(tmpval) + '\t'
- s += "{}".format(csv_structure[idx][idy+1]) + '\n'
- # print(s)
- f.write(s)
- f.close()
- print("data saved to:", complete_structCSVFName)
- def getBestParamSet(graph_path, ang, const, trial):
- pathGEP = os.path.join(graph_path, ang, const, trial, "GEPdata")
- fileGEP = os.path.join(pathGEP, "GEPdata00.par")
- datastructure = load_datastructure(fileGEP)
- nbMvtSet = len(datastructure)
- bestChartName = ""
- bestparamset = []
- # print pathGEP,
- if verbose > 2:
- print("NbSets:", nbMvtSet, end=" ")
- if nbMvtSet > 0:
- mvtSet = nbMvtSet - 1
- typ = datastructure[mvtSet][0]
- start = datastructure[mvtSet][1]
- end = datastructure[mvtSet][2]
- # packetsize = datastructure[mvtSet][3]
- if verbose > 2:
- print("{} start={} end={}".format(typ, start, end), end=" ")
- conditions = datastructure[mvtSet][4]
- nbObj = len(conditions)
- chartList = conditions[nbObj-2]
- rangList = conditions[nbObj-1]
- bestChartName = chartList[len(chartList)-1]
- bestParamRg = rangList[len(rangList)-1]
- if verbose > 2:
- print("---> best param set: {}".format(bestParamRg))
- tab = readTablo(pathGEP, "GEPdata00.txt")
- tab = np.array(tab)
- if tab[0][-1] != 0.0:
- # nbparfromtab = len(tab[0]) - 2
- pairs = np.array(tab[:, :])
- else:
- # nbparfromtab = len(tab[0]) - 2 - 1
- pairs = np.array(tab[:, 0:-1])
- bestparamset = pairs[bestParamRg]
- else:
- print("no data to plot")
- return (bestChartName, bestparamset)
- def read_pklfile(self, paramFicName):
- try:
- print()
- print("looking paramOpt file:", paramFicName)
- with open(paramFicName, 'rb') as input:
- self.paramVSCDName = pickle.load(input)
- self.paramVSCDValue = pickle.load(input)
- self.paramVSCDType = pickle.load(input)
- self.paramVSCDCoul = pickle.load(input)
- self.paramMarquezName = pickle.load(input)
- self.paramMarquezValue = pickle.load(input)
- self.paramMarquezType = pickle.load(input)
- self.paramMarquezCoul = pickle.load(input)
- print("nb loaded param :", len(self.paramVSCDName))
- # print "nb nb actual param param:", len(listparNameOpt)
- print("nb expected param:", 42)
- # There are 42 VSCD parameters in this version
- nbloadedpar = len(self.paramVSCDName)
- if nbloadedpar == 42:
- if self.paramVSCDName[16] == 'disabledSynNbs':
- # This is the last version that includes "seriesSynNSParam"
- if verbose > 3:
- print("paramOpt :")
- for idx, val in enumerate(self.paramVSCDName):
- print("{0}:\t{1}".format(val,
- self.paramVSCDValue[idx]))
- elif self.paramVSCDName[16] == 'allsyn':
- # This is not the last version that includes "seriesSynNSParam"
- print("this version does not indicate seriesSynNSParam")
- if verbose > 3:
- print("paramMarquez :")
- for idx, val in enumerate(self.paramMarquezName):
- print("{0}:\t{1}".format(val,
- self.paramMarquezValue[idx]))
- print('=================== Param loaded ====================')
- response = True
- elif nbloadedpar == 41:
- print("paramOpt with only 41 params:")
- pln = ['selectedChart'] + self.paramVSCDName
- self.paramVSCDName = pln
- plv = [0] + self.paramVSCDValue
- paramVSCDValue = plv
- plt = [int] + self.paramVSCDType
- self.paramVSCDType = plt
- plc = ["Magenta"] + self.paramVSCDCoul
- self.paramVSCDCoul = plc
- if verbose > 3:
- print("paramOpt :")
- for idx, val in enumerate(self.paramVSCDName):
- print("{0}:\t{1}".format(val, paramVSCDValue[idx]))
- print("paramMarquez :")
- for idx, val in enumerate(self.paramMarquezName):
- print("{0}:\t{1}".format(val, self.paramMarquezValue[idx]))
- print('=================== Param loaded ====================')
- response = True
- else:
- print("Mismatch between existing and actual parameter files")
- response = False
- except Exception as e:
- if (verbose > 2):
- print(e)
- # print("No parameter file with this name in the directory", end=" ")
- # print("NEEDs to create a new parameter file")
- response = False
- return response
- def getOptSetFromAsim(self, animatsimdir):
- rootdir = os.path.dirname(animatsimdir)
- subdir = os.path.split(animatsimdir)[-1]
- animatLabV2ProgDir, nb_procs = getInfoComputer()
- folders = FolderOrg(animatlab_root=rootdir,
- python27_source_dir=animatLabV2ProgDir,
- subdir=subdir)
- sims = SimRun("Test Sims",
- rootFolder=folders.animatlab_rootFolder,
- commonFiles=folders.animatlab_commonFiles_dir,
- sourceFiles=folders.python27_source_dir,
- simFiles=folders.animatlab_simFiles_dir,
- resultFiles=folders.animatlab_result_dir)
- model = AnimatLabModel.AnimatLabModel(folders.animatlab_commonFiles_dir)
- projMan = ProjectManager.ProjectManager('Test Project')
- # aprojFicName = os.path.split(model.aprojFile)[-1]
- if self.optSet is None:
- optSet = OptimizeSimSettings(folders=folders, model=model,
- projMan=projMan, sims=sims)
- fileName = 'paramOpt.pkl'
- if loadParams(os.path.join(folders.animatlab_result_dir, fileName),
- optSet):
- # optSet was updated from "paramOpt.pkl"
- # we use then optSet to implement the needed variables
- optSet.actualizeparamVSCD()
- optSet.actualizeparamMarquez()
- optSet.ideal_behav = [0, 0]
- else:
- print("paramOpt.pkl MISSING !!, run 'GUI_animatlabOptimization.py'")
- self.stimParName = optSet.stimParName
- self.synParName = optSet.synParName
- self.synNSParName = optSet.synNSParName
- self.synFRParName = optSet.synFRParName
- self.par_names = optSet.xparName
- self.optSet = optSet
- return self.optSet, model
- def get_angle_dur(select_angledur_dir):
- mvt_by_angle = []
- angles = []
- durees = []
- for cond in select_angledur_dir:
- if cond[:cond.find("_")] not in angles:
- angles.append(cond[:cond.find("_")])
- if cond[cond.find("_")+1:] not in durees:
- durees.append(cond[cond.find("_")+1:])
- for ang in angles:
- ang_set = []
- for cond in select_angledur_dir:
- if cond[:cond.find("_")] in ang:
- ang_set.append(cond)
- mvt_by_angle.append(ang_set)
- return (mvt_by_angle, angles, durees)
- def make_graph_var(graph_path, list_VSCDParam, strtTime, endTime,
- prevListConsts, prevListTrials,
- selectLst_const_trial, select_angledur_dir,
- select_var_names_plt):
- """
- Builds graphs of chosen chart names variables for Deb, Max and Fin
- Each graph represents the values of these variables for each constant
- parameter value (for all selected trials). Different mvt durations are
- ploted with different lines. The different angles are plotted on different
- files.
- """
- list_constVal = ['Time']
- for const in prevListConsts:
- lastConstPar = const
- while lastConstPar.find("=") != -1:
- lastConstPar = lastConstPar[lastConstPar.find("=")+1:]
- # print(lastConstPar)
- for idx, trial in enumerate(prevListTrials):
- list_constVal.append("{0}-{1}".format(lastConstPar, idx+1))
- (mvt_by_angle, angles, durees) = get_angle_dur(select_angledur_dir)
- for ang_idx, ang in enumerate(angles):
- dic_VSCDparam = list_VSCDParam[ang_idx]
- # endMvt1 = dic_VSCDparam["endMvt1"]
- endPos1 = dic_VSCDparam["endPos1"]
- endMvt2 = dic_VSCDparam["endMvt2"]
- endPos2 = dic_VSCDparam["endPos2"]
- titre = "fig_var_{0}".format(ang)
- angle_class = mvt_by_angle[ang_idx]
- ysize = len(select_var_names_plt) * 2
- fig, ax = plt.subplots(nrows=len(select_var_names_plt), ncols=3,
- figsize=(7, ysize), dpi=150,
- # subplot_kw={'xticks': [], 'yticks': []},
- sharex='col', sharey='row')
- for idx, var in enumerate(select_var_names_plt):
- for mvt in angle_class:
- output_path = os.path.join(graph_path, mvt, "output")
- df1 = pd.read_csv(r'{0}\{1}.csv'.format(output_path, var),
- delimiter='\t',
- index_col='Time',
- header=1,
- names=list_constVal)
- selectdf1 = df1.loc[:, selectLst_const_trial]
- "Deb_steady part"
- Deb = selectdf1.loc[0.5:endPos1]
- Deb_moy = Deb.mean(axis=0)
- # Deb.describe()
- "Max part"
- MaxVal = selectdf1.max(axis=0)
- "Fin_steady part"
- Fin = selectdf1.loc[endMvt2:endPos2]
- # Fin.describe()
- Fin_moy = Fin.mean(axis=0)
- ax[idx, 0].plot(Deb_moy)
- ax[idx, 0].set_title('Deb_' + var, fontsize=10) # set title
- ax[idx, 1].plot(MaxVal)
- ax[idx, 1].set_title('Max_' + var, fontsize=10)
- ax[idx, 2].plot(Fin_moy)
- ax[idx, 2].set_title("Fin_" + var, fontsize=10)
- if idx == 0:
- # plt.legend(angle_class,
- # bbox_to_anchor=(0., 1.02, 1., .102), loc=3,
- # ncol=1, mode="expand", borderaxespad=0.)
- ax[idx, 2].legend(angle_class,
- bbox_to_anchor=(0.05, 1.2),
- loc=3, borderaxespad=0.)
- if idx == len(select_var_names_plt) - 1:
- ax[idx, 0].tick_params(axis='x', rotation=70)
- ax[idx, 1].tick_params(axis='x', rotation=70)
- ax[idx, 2].tick_params(axis='x', rotation=70)
- plt.suptitle(titre, fontsize=14, y=1-ysize*0.005)
- plt.savefig(r'{0}\fig_var_{1}.eps'.format(graph_path, ang))
- plt.show()
- def make_graph_mvt(graph_path, list_VSCDParam, strtTime, endTime,
- prevListConsts, prevListTrials,
- selectLst_const_trial, select_angledur_dir,
- select_var_names_plt, fname='fig_Elbow.eps'):
- """
- Builds the elbow movement for each angle on a separates files
- (and for all mvt durations).
- """
- list_constVal = ['Time']
- for const in prevListConsts:
- lastConstPar = const
- while lastConstPar.find("=") != -1:
- lastConstPar = lastConstPar[lastConstPar.find("=")+1:]
- # print(lastConstPar)
- for idx, trial in enumerate(prevListTrials):
- list_constVal.append("{0}-{1}".format(lastConstPar, idx+1))
- # movement together
- figmvt, axes = plt.subplots(nrows=len(select_angledur_dir), ncols=2,
- figsize=(7, 14), dpi=150,
- sharex='col',
- sharey='row')
- for idx, angdur in enumerate(select_angledur_dir):
- const = prevListConsts[0]
- trial = prevListTrials[0]
- templateFileName = os.path.join(graph_path, angdur, const, trial,
- "ResultFiles", "template.txt")
- T = np.loadtxt(templateFileName)
- Tdf = pd.DataFrame(T)
- Tdf.index = Tdf[1]
- output_path = os.path.join(graph_path, angdur, "output")
- df_move = pd.read_csv(r'{0}\Elbow.csv'.format(output_path),
- delimiter='\t',
- index_col='Time',
- header=1,
- names=list_constVal)
- select_df_move = df_move.loc[:, selectLst_const_trial]
- # add two columns to df_move : TemplateTime and Template
- select_df_move.loc[:, 'TemplateTime'] = Tdf[strtTime:endTime][1]
- select_df_move.loc[:, 'Template'] = Tdf[strtTime:endTime][2]
- # select_df_move.plot()
- # titre = "{0}".format(angdur)
- for col in selectLst_const_trial:
- data = select_df_move[:][col]
- # data.plot(ax=axes[0])
- axes[idx, 0].plot(data, linewidth=0.2)
- dataT = select_df_move[:]["Template"]
- # dataT.plot(ax=axes[0], color="grey")
- axes[idx, 0].plot(dataT, color="grey")
- unitx = "Time (s)"
- unity = "Elbow Mvt (degres)"
- axes[idx, 0].legend(loc='upper left', fontsize=4)
- axes[idx, 0].set_ylabel(unity, fontsize=10)
- if idx == len(select_angledur_dir) - 1:
- axes[idx, 0].set_xlabel(unitx, fontsize=10)
- for col in selectLst_const_trial:
- data = select_df_move[4.9:6][col]
- # data.plot(ax=axes[1])
- axes[idx, 1].plot(data, linewidth=0.2)
- dataT = select_df_move[4.9:6]["Template"]
- # dataT.plot(ax=axes[1], color="grey")
- axes[idx, 1].plot(dataT, color="grey")
- unitx = "Time (s)"
- unity = "Elbow Mvt (degres)"
- # axes[idx, 1].text(4.25, 35, angdur)
- axes[idx, 1].set_title(angdur)
- axes[idx, 1].legend(loc='upper left', fontsize=4)
- # axes[idx, 1].set_ylabel(unity, fontsize=10)
- if idx == len(select_angledur_dir) - 1:
- axes[idx, 1].set_xlabel(unitx, fontsize=10)
- plt.suptitle("Angles and Durations series", fontsize=14, y=0.91)
- plt.savefig(r'{0}\{1}'.format(graph_path, fname))
- plt.show()
- def make_graph_supmvt(graph_path, list_VSCDParam, strtTime, endTime,
- prevListConsts, prevListTrials,
- selectLst_const_trial, select_angledur_dir,
- select_var_names_plt, fname="fig_Elbow2.eps"):
- """
- Builds superimposed movements of same angles and different durations
- """
- list_constVal = ['Time']
- for const in prevListConsts:
- lastConstPar = const
- while lastConstPar.find("=") != -1:
- lastConstPar = lastConstPar[lastConstPar.find("=")+1:]
- # print(lastConstPar)
- for idx, trial in enumerate(prevListTrials):
- list_constVal.append("{0}-{1}".format(lastConstPar, idx+1))
- (mvt_by_angle, angles, durees) = get_angle_dur(select_angledur_dir)
- # superimposed movements
- nbrows = len(angles)
- fig2mvt, axes2 = plt.subplots(nrows=nbrows, ncols=1,
- figsize=(7, 7*nbrows), dpi=150)
- for ang_idx, ang in enumerate(angles):
- colors = []
- newHandles = []
- newLabels = []
- # dic_VSCDparam = list_VSCDParam[ang_idx]
- # titre = "{0}".format(ang)
- angle_class = mvt_by_angle[ang_idx]
- for mvt_idx, mvt in enumerate(angle_class):
- const = prevListConsts[0]
- trial = prevListTrials[0]
- templateFileName = os.path.join(graph_path, mvt, const, trial,
- "ResultFiles", "template.txt")
- T = np.loadtxt(templateFileName)
- Tdf = pd.DataFrame(T)
- Tdf.index = Tdf[1]
- output_path = os.path.join(graph_path, mvt, "output")
- df_move = pd.read_csv(r'{0}\Elbow.csv'.format(output_path),
- delimiter='\t',
- index_col='Time',
- header=1,
- names=list_constVal)
- select_df_move = df_move.loc[:, selectLst_const_trial]
- # add two columns to df_move : TemplateTime and Template
- select_df_move.loc[:, 'TemplateTime'] = Tdf[strtTime:endTime][1]
- select_df_move.loc[:, 'Template'] = Tdf[strtTime:endTime][2]
- # df_move.plot()
- color = "C{}".format(mvt_idx)
- colors.append(color)
- for col in selectLst_const_trial:
- data = select_df_move[4.9:6][col]
- if nbrows > 1:
- axes2[ang_idx].plot(data, linewidth=0.5,
- color=color, label=mvt)
- else:
- axes2.plot(data, linewidth=0.5, color=color, label=mvt)
- dataT = select_df_move[4.9:6]["Template"]
- unitx = "Time (s)"
- unity = "Elbow Mvt (degres)"
- if nbrows > 1:
- axes2[ang_idx].plot(dataT, color="grey")
- axes2[ang_idx].set_title(ang)
- axes2[ang_idx].legend(angle_class,
- loc='upper left', fontsize=18)
- axes2[ang_idx].set_ylabel(unity, fontsize=10)
- if ang_idx == nbrows - 1:
- axes2[ang_idx].set_xlabel(unitx, fontsize=10)
- # gets the handles and labels of legend for current mvt
- handles, labels = axes2[ang_idx].get_legend_handles_labels()
- else:
- axes2.plot(dataT, color="grey")
- axes2.set_title(ang)
- axes2.legend(angle_class, loc='upper left', fontsize=18)
- axes2.set_ylabel(unity, fontsize=10)
- if ang_idx == nbrows - 1:
- axes2.set_xlabel(unitx, fontsize=10)
- # gets the handles and labels of legend for current mvt
- handles, labels = axes2.get_legend_handles_labels()
- # gets the first handle & label of each constant list
- # and add it in new Handles & newLabels, respectively
- nbConstTrial = len(selectLst_const_trial)
- newHandles.append(handles[mvt_idx*(nbConstTrial)])
- newLabels.append(labels[mvt_idx*(nbConstTrial)])
- # and now adds the "template" in legend handles and labels
- newHandles.append(handles[(mvt_idx+1)*(nbConstTrial)-1])
- newLabels.append(labels[(mvt_idx+1)*(nbConstTrial)-1])
- # at the end of each angle_class, rewrites the legend using newHandles
- # and newLabels
- if nbrows > 1:
- axes2[ang_idx].legend(newHandles, newLabels)
- else:
- axes2.legend(newHandles, newLabels)
- plt.suptitle("Angles and Superimposed Durations", fontsize=14, y=0.94)
- plt.savefig(r'{0}\{1}'.format(graph_path, fname))
- plt.show()
- def make_graph_param(graph_path, select_constVal_dir, select_angledur_dir,
- selectLst_const_trial, prevLstPltParams):
- """
- Builds graphs of chosen parameter values. Each graph represents
- the adaptation of the parameter value for each value of the constant
- parameter (and for all selected trials). Different mvt durations are
- ploted with different lines. The different angles are plotted on different
- files.
- """
- df1 = pd.read_csv(r'{0}\{1}.csv'.format(graph_path, "output_param"),
- delimiter='\t',
- # index_col="param",
- index_col=0,
- # header=2,
- header=[0, 1, 2],
- # names=column_labels,
- )
- parnames = df1.index
- nbcol = 3
- nbrow = int(len(parnames)/nbcol)
- if len(parnames) > nbrow*nbcol:
- nbrow += 1
- ysize = nbrow * 2
- (mvt_by_angle, angles, durees) = get_angle_dur(select_angledur_dir)
- for ang_idx, ang in enumerate(angles):
- titre = "fig_par_{0}".format(ang)
- angle_class = mvt_by_angle[ang_idx]
- dfang = df1[angle_class]
- fig, ax = plt.subplots(nrows=nbrow, ncols=nbcol,
- figsize=(7, ysize), dpi=150,
- # subplot_kw={'xticks': [], 'yticks': []},
- sharex='col', sharey='row')
- lastrow = (len(parnames) - len(parnames) % 3) // 3
- for par_idx, par in enumerate(parnames):
- col = par_idx % 3 # modulo function -> 0 1 2 0 1 2 etc.
- row = (par_idx - col) / 3
- # print row, col
- for dur_idx, dur in enumerate(angle_class):
- dfdur = dfang[dur]
- dfconst = dfdur[select_constVal_dir]
- dfconst.columns = selectLst_const_trial
- ax[row, col].plot(dfconst.loc[par])
- ax[row, col].set_title(par, fontsize=9)
- if row == 0 and col == 2:
- # plt.legend(angle_class,
- # bbox_to_anchor=(0., 1.02, 1., .102), loc=3,
- # ncol=1, mode="expand", borderaxespad=0.)
- ax[0, 2].legend(angle_class,
- bbox_to_anchor=(0.05, 1.2),
- loc=3, borderaxespad=0.)
- if row == lastrow:
- ax[row, col].tick_params(axis='x', rotation=70)
- plt.suptitle(titre, fontsize=14, y=1-ysize*0.005)
- plt.savefig(r'{0}\fig_par_{1}.eps'.format(graph_path, ang))
- plt.show()
- def analyse_const_dir(const):
- list_cstes = []
- fini = False
- while not fini:
- res = const.find("_")
- if res != -1:
- prevconst = const[:const.find("_")]
- # print prevconst
- if prevconst != "const":
- list_cstes.append(prevconst)
- const = const[const.find("_")+1:]
- else:
- # print const
- list_cstes.append(const)
- fini = True
- return list_cstes
- def factor_scatter_matrix(df, factor, graph_name,
- plt_factor=False, palette=None):
- '''
- Create a scatter matrix of the variables in df, with differently colored
- points depending on the value of df[factor].
- inputs:
- df: pandas.DataFrame containing the columns to be plotted, as well
- as factor.
- factor: string or pandas.Series. The column indicating which group
- each row belongs to.
- palette: A list of hex codes, at least as long as the number of groups.
- If omitted, a predefined palette will be used, but it only includes
- 9 groups.
- '''
- from pandas.plotting import scatter_matrix
- from scipy.stats import gaussian_kde
- import seaborn as sns
- if isinstance(factor, str):
- factor_name = factor # save off the name
- factor_col = df.loc[:, factor] # extract column
- if plt_factor is False:
- df = df.drop(factor_name, axis=1) # remove from df, so it
- # doesn't get a row and col in the plot.
- classes = list(set(factor_col))
- classes.sort(reverse=False)
- nbcolors = len(classes)
- if palette is None:
- palette = colors = sns.color_palette()
- """
- palette = ['#e41a1c', '#377eb8', '#4eae4b',
- '#994fa1', '#ff8101', '#fdfc33',
- '#a8572c', '#f482be', '#999999']
- """
- color_map = dict(list(zip(classes, palette)))
- if len(classes) > len(palette):
- message1 = 'Too many groups for the number of colors provided.'
- message2 = ' We only have {} colors in the palette, for {} groups.'
- message = message1 + message2
- raise ValueError(message.format(len(palette), len(classes)))
- plt.rcParams['axes.labelsize'] = 8
- plt.rcParams['ytick.labelsize'] = 6
- colors = factor_col.apply(lambda group: color_map[group])
- axarr = scatter_matrix(df, figsize=(15, 15),
- alpha=1,
- marker='.',
- c=colors,
- diagonal=None)
- for rc in range(len(df.columns)):
- for group in classes:
- try:
- y = df[factor_col == group].iloc[:, rc].values
- gkde = gaussian_kde(y)
- ind = np.linspace(y.min(), y.max(), 1000)
- axarr[rc][rc].plot(ind, gkde.evaluate(ind),
- c=color_map[group])
- # in the color process colors are associated to values in
- # value order (i.e. 1st value 0.01 -> first color)
- except Exception as e:
- None
- if verbose > 2:
- print(e)
- title = "{0} colors by {1}".format(graph_name, factor)
- plt.suptitle(title, fontsize=14, y=0.90)
- labels = copy.deepcopy(classes)
- labels.sort(reverse=True)
- if nbcolors < 50:
- handles = [plt.plot([], [], color=color_map[labels[i]],
- ls="", marker='o',
- markersize=8)[0] for i in range(nbcolors)]
- # In legend the order is that of classes (revert order) so all is OK
- plt.legend(handles, labels, loc=(1.02, 0))
- plt.setp(plt.gca().get_legend().get_texts(), fontsize='10')
- else:
- labels1 = labels[:nbcolors/2]
- handles1 = [plt.plot([], [], color=color_map[labels[i]],
- ls="", marker='o',
- markersize=8)[0] for i in range(nbcolors/2)]
- # In legend the order is that of classes (revert order) so all is OK
- first_legend = plt.legend(handles1, labels1, loc=(1.02, 0))
- plt.gca().add_artist(first_legend)
- plt.setp(plt.gca().get_legend().get_texts(), fontsize='10')
- labels2 = labels[nbcolors/2:]
- handles2 = [plt.plot([], [], color=color_map[labels[i]],
- ls="", marker='o',
- markersize=8)[0] for i in range(nbcolors/2,
- nbcolors)]
- # In legend the order is that of classes (revert order) so all is OK
- second_legend = plt.legend(handles2, labels2, loc=(1.25, 0))
- plt.gca().add_artist(second_legend)
- plt.setp(plt.gca().get_legend().get_texts(), fontsize='10')
- return axarr, color_map
- # ======================================================================
- # functions to plot GEP graphs
- # ======================================================================
- def do_plot_bhv_param(MyWin, df_bhvremain, df_parremain, behav_col, graph_path,
- baseName, listDicGraphs, xparNameDict, xparName,
- max_x_bhv=1.2, max_y_bhv=5):
- nbpargraphs = len(listDicGraphs)
- nbgraphs = nbpargraphs + 1 # the bhvGraph is added on 1st line
- nblines = int(float(nbgraphs+1)/3)
- reste = nbgraphs % 3
- if reste > 0:
- nblines += 1
- if nblines % 5 != 0:
- nbpages = int(nblines / 5) + 1
- # nbLinesLastPage = nblines % 5
- else:
- nbpages = int(nblines / 5)
- # nbLinesLastPage = 5
- # nbLinesPerPage = []
- nbparGr1stPage = min(14, nbpargraphs)
- grlist = [list(range(0, nbparGr1stPage))] # list of pargraphs of 1st page
- rg1stGrNextPage = nbparGr1stPage
- if nbpages > 1:
- for pag in range(1, nbpages-1):
- # nbLinesPerPage.append(5)
- grlist.append(list(range(rg1stGrNextPage, rg1stGrNextPage+14)))
- rg1stGrNextPage = rg1stGrNextPage+14
- # nbLinesPerPage.append(nbLinesLastPage)
- grlist.append(list(range(rg1stGrNextPage, nbpargraphs)))
- for page in range(nbpages):
- plotGrOnPage(MyWin, df_bhvremain, df_parremain, behav_col, graph_path,
- baseName, listDicGraphs, xparNameDict, xparName, page,
- grlist, max_x_bhv=max_x_bhv, max_y_bhv=max_y_bhv)
- def plotGrOnPage(MyWin, df_bhvremain, df_parremain, behav_col, graph_path,
- baseName, listDicGraphs, xparNameDict, xparName, page,
- grlist, max_x_bhv=1.2, max_y_bhv=1.4):
- listcolors = ['blue', 'orange', 'green', 'red', 'purple',
- 'brown', 'pink', 'gray', 'olive', 'cyan']
- fig = plt.figure(figsize=(10, 18), dpi=90)
- # plt.subplots_adjust(bottom=0, left=0.1, top=0.9, right=0.9)
- grid = plt.GridSpec(5, 3, wspace=0.4, hspace=0.3)
- path = os.path.split(graph_path)[0]
- # baseName = strGEPdataName[:] + "/ bhv_par_graphs"
- baseNamePage = baseName + "_p" + str(page+1)
- titre = get_titre(path, baseNamePage)
- # titre = titre + "_p" + str(page+1)
- plt.suptitle(titre, fontsize=12, y=0.95)
- row = -1
- if page == 0:
- # ===================== plots the behavior map =======================
- behavs_cues = df_bhvremain[df_bhvremain.columns[behav_col]]
- rel_behavs_cues = behavs_cues/[MyWin.scale_x, MyWin.scale_y]
- nameX = rel_behavs_cues.columns[0]
- nameY = rel_behavs_cues.columns[1]
- valX = rel_behavs_cues[nameX]
- valY = rel_behavs_cues[nameY]
- # figure, ax = plt.subplots(figsize=(7, 7))
- # figure, ax = plt.subplots()
- # ax3 = fig.add_subplot(337)
- ax3 = fig.add_subplot(grid[0, 0])
- selectedROI = MyWin.mafen.selectedROI
- if selectedROI == []:
- # ===========================================================
- ax3.scatter(valX, valY, marker='o', s=4, c="r")
- # ===========================================================
- else:
- for idxROI, listdata in enumerate(selectedROI):
- valX_s = valX[listdata]
- valY_s = valY[listdata]
- color = listcolors[idxROI]
- # ---------------------------------------------------
- ax3.scatter(valX_s, valY_s, marker='o', s=4, c=color)
- # ---------------------------------------------------
- if behav_col[1] == 8: # if ordonate is duration...
- labelnameX = nameX + " (x 0.01)"
- labelnameY = nameY
- elif behav_col[1] == 6:
- labelnameX = nameX + " (x 0.01)"
- labelnameY = nameY + " (x 0.01)"
- ax3.set_xlabel(labelnameX, fontsize=11)
- ax3.set_ylabel(labelnameY, fontsize=11)
- plt.xticks(fontsize=10)
- plt.yticks(fontsize=10)
- ax3.set_axisbelow(True)
- ax3.set_xlim(0, max_x_bhv)
- ax3.set_ylim(0, max_y_bhv)
- ax3.grid(linestyle='-', linewidth='0.5', color='green')
- row = 0
- # =====================================================================
- # =================== plots the parameter maps =======================
- axpar = []
- # row = 0
- line = 0
- for idx, pargr in enumerate(grlist[page]):
- abscissName = listDicGraphs[pargr]['abscissa'][0]
- ordinateName = listDicGraphs[pargr]['ordinate'][0]
- if abscissName[abscissName.find(".")+1:] == "SynAmp":
- xmin = 0
- xmax = 0.05
- if ordinateName[ordinateName.find(".")+1:] == "SynAmp":
- ymin = 0
- ymax = 0.05
- if abscissName[abscissName.find(".")+1:] == "CurrentOn":
- xmin = 0
- xmax = 1
- if ordinateName[ordinateName.find(".")+1:] == "CurrentOn":
- ymin = 0
- ymax = 1
- row = row + 1
- if row > 2:
- row = 0
- line = line + 1
- # axpar.append(fig.add_subplot(3, nblines+1, 8+pargr))
- axpar.append(fig.add_subplot(grid[line, row]))
- namex = listDicGraphs[pargr]["abscissa"]
- namey = listDicGraphs[pargr]["ordinate"]
- parx = xparNameDict[namex[0]]
- pary = xparNameDict[namey[0]]
- dflist_x = df_parremain[xparName[parx]]
- dflist_y = df_parremain[xparName[pary]]
- if dflist_x.max() > xmax:
- xmax = dflist_x.max()
- if dflist_x.min() < xmin:
- xmin = dflist_x.min()
- """
- if (dflist_y.max() > ymax) or dflist_y.min() < ymin:
- if dflist_y.max() - dflist_y.min() < 2:
- ymax = (dflist_y.max() + dflist_y.min())/2 + 1
- ymin = (dflist_y.max() + dflist_y.min())/2 - 1
- """
- if dflist_y.max() > ymax:
- ymax = dflist_y.max()
- if dflist_y.min() < ymin:
- ymin = dflist_y.min()
- print(namex[0], parx, namey[0], pary)
- selectedROI = MyWin.mafen.selectedROI
- if selectedROI == []:
- # ===========================================================
- axpar[idx].scatter(list(dflist_x), list(dflist_y),
- marker='o', s=4, c="b")
- # ===========================================================
- else:
- for idxROI, listdata in enumerate(selectedROI):
- dflist_x_s = dflist_x[listdata]
- dflist_y_s = dflist_y[listdata]
- color = listcolors[idxROI]
- # ---------------------------------------------------
- axpar[idx].scatter(list(dflist_x_s), list(dflist_y_s),
- marker='o', s=4, c=color)
- # ---------------------------------------------------
- axpar[idx].set_xlabel(namex[0], fontsize=11)
- axpar[idx].set_ylabel(namey[0], fontsize=11)
- plt.xticks(fontsize=10)
- plt.yticks(fontsize=10)
- axpar[idx].set_axisbelow(True)
- """
- xmin = -4
- xmax = 2
- ymin = -3
- ymax = 3
- """
- axpar[idx].set_xlim(xmin, xmax)
- axpar[idx].set_ylim(ymin, ymax)
- axpar[idx].grid(linestyle='-', linewidth='0.5', color='gray')
- # =====================================================================
- plt.savefig(os.path.join(graph_path, baseNamePage + '.pdf'))
- plt.savefig(os.path.join(graph_path, baseNamePage + '.eps'))
- plt.show()
- def ss_titre_to_txt(ss_titre):
- txt = "{}".format(ss_titre)
- txt = txt.replace(" ", "")
- txt = txt.replace("[", "(")
- txt = txt.replace("]", ")")
- txt = txt.replace("_", "")
- return "_{}".format(txt)
- def look_for_peaks(data):
- start = 0
- sequence = []
- for key, group in groupby(data):
- sequence.append((key, start))
- start += sum(1 for _ in group)
- for (b, bi), (m, mi), (a, ai) in zip(sequence, sequence[1:], sequence[2:]):
- if b < m and a < m:
- yield m, mi
- class Ui_Visu3D(object):
- def setupUi(self, Visu3D):
- self.Visu3D = Visu3D
- self.Visu3D.setObjectName("Visu3D")
- self.Visu3D.resize(400, 400)
- btn_color_per_set = QtWidgets.QPushButton('Color Points per set')
- btn_color_per_set.clicked.connect(self.colors_per_set)
- btn_create_subset = QtWidgets.QPushButton('create subset')
- btn_create_subset.clicked.connect(self.restrain_visible_factor)
- btn_choose_subset = QtWidgets.QPushButton('choose subset')
- btn_choose_subset.clicked.connect(self.choose_subset)
- btn_remove_subset = QtWidgets.QPushButton('remove subset')
- btn_remove_subset.clicked.connect(self.remove_subset)
- btn_chge_colorPar = QtWidgets.QPushButton('Change Colored param')
- btn_chge_colorPar.clicked.connect(self.chge_colorPar)
- btn_set_orient = QtWidgets.QPushButton('set orientation')
- btn_set_orient.clicked.connect(self.set_orient)
- btn_clear = QtWidgets.QPushButton('clear graph')
- btn_clear.clicked.connect(self.clearData)
- btn_save = QtWidgets.QPushButton('save graph')
- btn_save.clicked.connect(self.saveGraph)
- btn_quit = QtWidgets.QPushButton('QUIT')
- btn_quit.clicked.connect(self.closeWindows)
- # ==============================================
- # Add QHBoxlayout to place the buttons
- self.buttonHLayout1 = QtWidgets.QHBoxLayout()
- self.buttonHLayout1.setObjectName("ButtonHLayout")
- # self.buttonHLayout1.addWidget(btn_color_per_set)
- self.buttonHLayout1.addWidget(btn_create_subset)
- self.buttonHLayout1.addWidget(btn_choose_subset)
- self.buttonHLayout1.addWidget(btn_remove_subset)
- self.buttonHLayout1.addWidget(btn_chge_colorPar)
- self.buttonHLayout1.addWidget(btn_set_orient)
- self.buttonHLayout1.addWidget(btn_save)
- # self.buttonHLayout1.addWidget(btn_clear)
- self.buttonHLayout1.addWidget(btn_quit)
- self.horizontalLayout = QtWidgets.QHBoxLayout()
- self.horizontalLayout.setObjectName("horizontalLayout")
- self.verticalLayout = QtWidgets.QVBoxLayout()
- self.verticalLayout.setObjectName("verticalLayout")
- # Add widgets to the layout in their proper positions
- # self.verticalLayout.addWidget(self.gl3d)
- self.verticalLayout.addLayout(self.buttonHLayout1)
- self.horizontalLayout.addLayout(self.verticalLayout)
- self.Visu3D.setLayout(self.horizontalLayout)
- # self.centralwidget.setLayout(self.horizontalLayout)
- self.setWindowTitle("Make 3d graph")
- QtCore.QMetaObject.connectSlotsByName(self.Visu3D)
- # TODO ...
- class Visualizer3D(QtWidgets.QDialog, Ui_Visu3D):
- def __init__(self, graph_path, GUI_Gr_obj):
- super(Visualizer3D, self).__init__()
- self.setupUi(self) # le 2eme self est pour l'argument Visualizer3D
- self.graph_path = graph_path
- self.GUI_Gr_obj = GUI_Gr_obj
- self.rootdir = ""
- self.ficname = ""
- self.dataSet = []
- self.listgl3dItems = []
- self.faceColItems = []
- self.setnames = []
- self.listDic_dataSet = [{'data_sets': ["main"]}]
- self.selected_dataSets = ['main']
- plt.ion()
- # self.figure, self.axis = plt.subplots(figsize=(10, 10), dpi=100)
- self.figure = plt.figure(figsize=(10, 10), dpi=100)
- self.canvas = FigureCanvas(self.figure)
- # self.canvas.mpl_connect('pick_event', self.onpick)
- self.verticalLayout.addWidget(self.canvas)
- # self.visu_3d.gridLayout.addWidget(self.canvas)
- self.axis = self.figure.add_subplot(1, 1, 1, projection='3d')
- # self.axis = self.figure.gca(projection='3d')
- # self.figure.set_size_inches(18.5, 10.5)
- self.axis.set_xlabel("xlabel")
- self.axis.set_ylabel("ylabel")
- self.axis.set_zlabel("zlabel")
- self.axis.view_init(60, 30)
- print(" ========== execution in Vizualizer ON ==========")
- # self.show()
- """
- def newData(self):
- pos = np.random.randint(-10, 10, size=(100, 3))
- pos[:, 2] = np.abs(pos[:, 2])
- color = np.zeros((pos.shape[0], 4), dtype=np.float32)
- color[:, 0] = 0.5
- color[:, 1] = 0.2
- color[:, 2] = 0.5
- color[:, 3] = 1
- x = pos[:, 0]
- y = pos[:, 1]
- z = pos[:, 2]
- self.addData(pos=(x, y, z), size=10, pxMode=True, color=color)
- # color = np.roll(color, 1, axis=0)
- def origin_colors(self):
- for idx, gl3d_item in enumerate(self.listgl3dItems):
- color = self.faceColItems[idx]
- gl3d_item._facecolor3d = color
- gl3d_item._edgecolor3d = color
- plt._auto_draw_if_interactive(self.figure, 1)
- """
- """
- def plot_curves(self, indexes):
- for idx, gl3d_item in enumerate(self.listgl3dItems):
- for i in indexes: # might be more than 1 point if ambiguous click
- new_fc = self.fc.copy()
- new_fc[i,:] = (1, 0, 0, 1)
- gl3d_item._facecolor3d = new_fc
- gl3d_item._edgecolor3d = new_fc
- self.figure.canvas.draw_idle()
- def onpick(self, event):
- ind = event.ind
- print ind
- self.plot_curves(list(ind))
- """
- def addData(self, pos=None, names=["xlabel", "ylabel", "zlabel"],
- fourth="fourthlabel", size=10, pxMode=True, color=None,
- setname="", ficname=""):
- factor = fourth
- self.ficname = ficname
- (x, y, z) = pos
- self.axis.set_xlabel(names[0])
- self.axis.set_ylabel(names[1])
- self.axis.set_zlabel(names[2])
- # ======== tests if bvh name (bhv_names[behav_col[i]]) is in names
- # (if so, sets the limits to original (before restraining bhv)
- x_bhvname = self.GUI_Gr_obj.bhv_names[self.GUI_Gr_obj.behav_col[0]]
- y_bhvname = self.GUI_Gr_obj.bhv_names[self.GUI_Gr_obj.behav_col[1]]
- rank_x = list
- rank_y = list
- if x_bhvname in names:
- # print x_bhvname,
- rank_x = [i for i in range(len(names)) if names[i] == x_bhvname]
- # print rank_x
- if rank_x[0] == 0:
- self.axis.set_xlim(self.GUI_Gr_obj.bhv_xmin,
- self.GUI_Gr_obj.bhv_xmax)
- elif rank_x[0] == 1:
- self.axis.set_ylim(self.GUI_Gr_obj.bhv_xmin,
- self.GUI_Gr_obj.bhv_xmax)
- elif rank_x[0] == 2:
- self.axis.set_zlim(self.GUI_Gr_obj.bhv_xmin,
- self.GUI_Gr_obj.bhv_xmax)
- if y_bhvname in names:
- # print(y_bhvname, end=" ")
- rank_y = [i for i in range(len(names)) if names[i] == y_bhvname]
- # print(rank_y)
- if rank_y[0] == 0:
- self.axis.set_xlim(self.GUI_Gr_obj.bhv_ymin,
- self.GUI_Gr_obj.bhv_ymax)
- elif rank_y[0] == 1:
- self.axis.set_ylim(self.GUI_Gr_obj.bhv_ymin,
- self.GUI_Gr_obj.bhv_ymax)
- elif rank_y[0] == 2:
- self.axis.set_zlim(self.GUI_Gr_obj.bhv_ymin,
- self.GUI_Gr_obj.bhv_ymax)
- if color is None:
- print("no color scale")
- gl3d_item = self.axis.scatter(x, y, z, s=size,
- facecolors=["C5"]*len(x),
- edgecolors=["C5"]*len(x),
- picker=True)
- else:
- # print("apllying color scale")
- gl3d_item = self.axis.scatter(x, y, z, s=size,
- facecolors=color,
- edgecolors=color,
- picker=True)
- fc = gl3d_item.get_facecolors()
- self.faceColItems.append(fc)
- self.dataSet.append(pos)
- self.setnames.append(setname)
- self.listgl3dItems.append(gl3d_item)
- plt._auto_draw_if_interactive(self.figure, 1)
- self.setWindowTitle("color={}".format(factor))
- print("new data {} added to 3d_graph".format(gl3d_item))
- return gl3d_item
- def chge_colorPar(self):
- self.GUI_Gr_obj.graph_settings.choose_factor()
- factor = self.GUI_Gr_obj.factor
- print("factor =", factor)
- df_glob = self.GUI_Gr_obj.df_glob
- # print(df_glob)
- color, codeCoul_df, step_palette = buildStpFilledCol(df_glob, factor)
- # Gets the first set of dots to apply color scale on it
- gl3d_item = self.listgl3dItems[0]
- self.apply_colors(color, gl3d_item)
- # =====================================================================
- # TODO Part not Finished...
- fc = gl3d_item.get_facecolors()
- self.faceColItems[0] = fc
- # =====================================================================
- self.setWindowTitle("color={}".format(factor))
- def apply_colors(self, color, gl3d_item):
- # for idx, gl3d_item in enumerate(self.listgl3dItems):
- gl3d_item._facecolor3d = color
- gl3d_item._edgecolor3d = color
- plt._auto_draw_if_interactive(self.figure, 1)
- # print("new_color for gl3d_item")
- # print("len(color) =", len(color))
- def restrain_visible_factor(self):
- factor = self.GUI_Gr_obj.factor
- df_glob = self.GUI_Gr_obj.df_glob
- color, codeCoul_df, step_palette = buildStpFilledCol(df_glob, factor)
- seq_factor = "seq_{}".format(factor)
- # seq_factor_col = copy.deepcopy(codeCoul_df[seq_factor])
- list_sort_seq_factor = np.array(codeCoul_df[seq_factor])
- list_sort_seq_factor.sort()
- if verbose > 2:
- print("seq_factor:", list_sort_seq_factor)
- print("sorted seq_factor:", list_sort_seq_factor)
- step = list_sort_seq_factor[1] - list_sort_seq_factor[0]
- i = 0
- while step == 0:
- step = list_sort_seq_factor[i+1] - list_sort_seq_factor[0]
- i += 1
- # print(step)
- step = step / 100
- # print(step)
- k = 0
- while step < 1:
- step *= 10
- k += 1
- # print(step)
- # print round(step)
- step = round(step) / (10**k)
- # print(step)
- step *= 100
- print("step in color scale: {}".format(step))
- factor_min = min(codeCoul_df[seq_factor])
- factor_max = max(codeCoul_df[seq_factor])
- listChoix = ['factor_limits']
- listDicFactorLimNam = [{'factor_limits': ["inf", "sup"]}]
- listDic_factorLimVal = [{"inf": factor_min, "sup": factor_max}]
- factorLimits_keys = ["inf", "sup"]
- titleText = "set limits for factor"
- rep = ChooseInList.listTransmit(parent=None,
- graphNo=0,
- listChoix=listChoix,
- items=factorLimits_keys,
- listDicItems=listDicFactorLimNam,
- onePerCol=[0],
- colNames=["Factor_limits", 'value'],
- dicValues=listDic_factorLimVal[0],
- typ="val",
- titleText=titleText)
- listDicFactorLimNam = rep[0]
- if len(rep[1]) == 0: # No values entered, ESC button was used
- return
- factLim_names = []
- # print("rep[1]", rep[1])
- for i in range(len(listDicFactorLimNam[0][listChoix[0]])):
- itemName = listDicFactorLimNam[0][listChoix[0]][i]
- factLim_names.append(itemName)
- listDic_factorLimVal[0][itemName] = float(rep[1][itemName])
- # print itemName, rep[1][itemName]
- factor_inf = listDic_factorLimVal[0]['inf']
- factor_sup = listDic_factorLimVal[0]['sup']
- # print('factor_inf={} ; factor_sup={}'.format(factor_inf, factor_sup))
- # get the ranks of factor_inf and factor_sup in codeCoul_df
- idx_inf = codeCoul_df.loc[codeCoul_df[seq_factor] == factor_inf]
- if len(idx_inf) > 0:
- rg_inf = idx_inf.index[0]
- else: # this means that factor_inf does not exist in seq_factor
- while len(idx_inf) < 1: # then lokk for the immediately larger
- if factor_inf - step > factor_min:
- factor_inf -= step
- factor_inf = round(factor_inf/step)*step
- else:
- factor_inf = factor_min
- idx_inf = codeCoul_df.loc[codeCoul_df[seq_factor] ==
- factor_inf]
- if len(idx_inf) > 0:
- rg_inf = idx_inf.index[0]
- # rg = np.searchsorted(list_sort_seq_factor, factor_inf)
- idx_sup = codeCoul_df.loc[codeCoul_df[seq_factor] == factor_sup]
- if len(idx_sup) > 0:
- rg_sup = idx_sup.index[0]
- else: # this means that factor_inf does not exist in seq_factor
- while len(idx_sup) < 1: # then lokk for the immediately larger
- if factor_sup + step < factor_max:
- factor_sup += step
- factor_sup = round(factor_sup/step)*step
- else:
- factor_sup = factor_max
- idx_sup = codeCoul_df.loc[codeCoul_df[seq_factor] ==
- factor_sup]
- if len(idx_sup) > 0:
- print(factor_sup, idx_sup)
- if len(idx_sup) > 0:
- rg_sup = idx_sup.index[0]
- print('factor_inf={} ; factor_sup={}'.format(factor_inf, factor_sup))
- # and gets the corresponding color ranks in "color"
- color_inf = int(codeCoul_df.loc[rg_inf]["color"])
- color_sup = int(codeCoul_df.loc[rg_sup]["color"])
- if verbose > 2:
- print('color_inf={} ; color_sup={}'.format(color_inf, color_sup))
- setname = "factor_{}-{}".format(factor_inf, factor_sup)
- # ========== defines transparent colors for df_glob dots =============
- col_trans = copy.deepcopy(color)
- color_tr = [[col_trans[i][j] for j in range(4)]
- for i in range(len(col_trans))]
- color_t = [tuple([color_tr[i][j] if j < 3 else 0.02 for j in range(4)])
- for i in range(len(col_trans))]
- # and applies it to the main 3D scatter graph
- gl3d_item = self.listgl3dItems[0]
- self.apply_colors(color_t, gl3d_item)
- # prepares a new df for plot data corresponding to selected factor
- df_glob_sel = copy.deepcopy(df_glob)
- factor_OK = df_glob_sel[factor] > factor_inf
- df_glob_sel = df_glob_sel[factor_OK]
- factor_OK = df_glob_sel[factor] < factor_sup
- df_glob_sel = df_glob_sel[factor_OK]
- codeCoul_df_sel = codeCoul_df.loc[df_glob_sel.index][:]
- # colour = step_palette[color_inf]
- # sel_pal = step_palette[color_inf:color_sup]
- colour = adaptPaletteTodf(df_glob_sel, factor,
- step_palette, codeCoul_df_sel)
- x = np.array(df_glob_sel[self.GUI_Gr_obj.select_3_col[0]])
- y = np.array(df_glob_sel[self.GUI_Gr_obj.select_3_col[1]])
- z = np.array(df_glob_sel[self.GUI_Gr_obj.select_3_col[2]])
- self.addData(pos=(x, y, z),
- names=self.GUI_Gr_obj.select_3_col, fourth=factor,
- size=4, pxMode=True, color=colour,
- setname=setname, ficname=self.ficname)
- # nb ficname is not used so far
- self.setWindowTitle("color={} -> restricted to {} - {}".format(factor,
- factor_inf, factor_sup))
- # plt._auto_draw_if_interactive(self.figure, 1)
- def choose_subset(self):
- listChoix = ['data_sets']
- # self.listDic_dataSet = [{'data_sets': ["main"]}]
- titleText = "choose set to plot"
- list_items = self.setnames
- listDic_dataSet = self.listDic_dataSet
- rep = ChooseInList.listTransmit(parent=None,
- graphNo=0,
- listChoix=listChoix,
- items=list_items,
- listDicItems=listDic_dataSet,
- onePerCol=[0],
- colNames=["data sets"],
- typ="chk",
- titleText=titleText)
- self.listDic_dataSet = rep[0]
- self.selected_dataSets = self.listDic_dataSet[0][listChoix[0]]
- unselected_dataSets = []
- for idx, gl3d_item in enumerate(self.listgl3dItems):
- color = self.faceColItems[idx]
- sub_set = list_items[idx]
- if sub_set in self.selected_dataSets:
- gl3d_item._facecolor3d = color
- gl3d_item._edgecolor3d = color
- else:
- unselected_dataSets.append(sub_set)
- gl3d_item._facecolor3d = (0, 0, 0, 0)
- gl3d_item._edgecolor3d = (0, 0, 0, 0)
- plt._auto_draw_if_interactive(self.figure, 1)
- def remove_subset(self):
- listChoix = ['data_sets']
- titleText = "choose set to remove from list"
- list_remove = []
- list_items = self.setnames
- listDic_remSet = [{'data_sets': []}]
- rep = ChooseInList.listTransmit(parent=None,
- graphNo=0,
- listChoix=listChoix,
- items=list_items,
- listDicItems=listDic_remSet,
- onePerCol=[0],
- colNames=["data sets"],
- typ="chk",
- titleText=titleText)
- listDic_remSet = rep[0]
- dataSetsToRemove = listDic_remSet[0][listChoix[0]]
- print("dataSets To Remove:", dataSetsToRemove)
- # for idx, subset in enumerate(list_items):
- for idx, gl3d_item in enumerate(self.listgl3dItems):
- sub_set = list_items[idx]
- if sub_set in dataSetsToRemove:
- list_remove.append(idx)
- if sub_set in self.selected_dataSets:
- gl3d_item._facecolor3d = (0, 0, 0, 0)
- gl3d_item._edgecolor3d = (0, 0, 0, 0)
- plt._auto_draw_if_interactive(self.figure, 1)
- unwanted = set(list_remove)
- faceColItems = self.faceColItems
- listgl3dItems = self.listgl3dItems
- dataSet = self.dataSet
- list_items = [list_items[idx] for idx in range(len(list_items))
- if idx not in unwanted]
- faceColItems = [faceColItems[idx] for idx in range(len(list_items))
- if idx not in unwanted]
- listgl3dItems = [listgl3dItems[idx] for idx in range(len(list_items))
- if idx not in unwanted]
- dataSet = [dataSet[idx] for idx in range(len(list_items))
- if idx not in unwanted]
- self.setnames = list_items
- self.faceColItems = faceColItems
- self.listgl3dItems = listgl3dItems
- self.dataSet = dataSet
- def colors_per_set(self):
- for idx, gl3d_item in enumerate(self.listgl3dItems):
- # -------- One color for all dots --------
- color = [random.uniform(0, 1), random.uniform(0, 1),
- random.uniform(0, 1), 1]
- gl3d_item._facecolor3d = color
- gl3d_item._edgecolor3d = color
- plt._auto_draw_if_interactive(self.figure, 1)
- print("one color per gl3d_item")
- def set_orient(self):
- azim = self.axis.azim
- elev = self.axis.elev
- azim = float("{0:.2f}".format(round(azim, 2)))
- elev = float("{0:.2f}".format(round(elev, 2)))
- print("azim={} elev={}".format(azim, elev))
- listChoix = ['orientation']
- listDicOrientNames = [{'orientation': ["azim", "elev"]}]
- listDic_orient_val = [{"azim": azim, "elev": elev}]
- self.orient_keys = ["azim", "elev"]
- titleText = "set orientation 3D graph"
- rep = ChooseInList.listTransmit(parent=None,
- graphNo=0,
- listChoix=listChoix,
- items=self.orient_keys,
- listDicItems=listDicOrientNames,
- onePerCol=[0],
- colNames=["orientation", 'value'],
- dicValues=listDic_orient_val[0],
- typ="val",
- titleText=titleText)
- listDicOrientNames = rep[0]
- self.orient_names = []
- self.dic_orient_val = rep[1]
- # print "rep[1]", rep[1]
- for i in range(len(listDicOrientNames[0][listChoix[0]])):
- itemName = listDicOrientNames[0][listChoix[0]][i]
- self.orient_names.append(itemName)
- listDic_orient_val[0][itemName] = float(rep[1][itemName])
- # print itemName, rep[1][itemName]
- azim = listDic_orient_val[0]['azim']
- elev = listDic_orient_val[0]['elev']
- print('azim={} ; elev={}'.format(azim, elev))
- self.axis.view_init(azim=azim, elev=elev)
- plt._auto_draw_if_interactive(self.figure, 1)
- def clearData(self):
- for idx, gl3d_item in enumerate(self.listgl3dItems):
- print(gl3d_item)
- gl3d_item.remove()
- self.dataSet = []
- self.listgl3dItems = []
- plt._auto_draw_if_interactive(self.figure, 1)
- print("all gl3d_item supressed")
- def saveGraph(self):
- azim = self.axis.azim
- elev = self.axis.elev
- """
- xlim = self.axis.get_xlim()
- ylim = self.axis.get_ylim()
- zlim = self.axis.get_zlim()
- """
- azim = float("{0:.2f}".format(round(azim, 2)))
- elev = float("{0:.2f}".format(round(elev, 2)))
- print("azim={} elev={}".format(azim, elev))
- self.graph_path = QtWidgets.QFileDialog.\
- getExistingDirectory(self, "folder in which to save figure",
- self.rootdir)
- self.rootdir = os.path.split(self.graph_path)[0]
- print(r'{0}\{1}.pdf'.format(self.graph_path, self.ficname))
- df_glob = self.GUI_Gr_obj.df_glob
- select_3_col = self.GUI_Gr_obj.select_3_col
- factor = self.GUI_Gr_obj.factor
- ss_titre = self.GUI_Gr_obj.ss_titre
- titre = "Fig5_3D_Dots_{}__{}__{}".format(select_3_col[0][:13],
- select_3_col[1][:13],
- select_3_col[2][:13])
- # self.GUI_Gr_obj.make_3d_plot(df_glob, select_3_col,
- # titre, ss_titre, factor,
- # azim=azim, elev=elev)
- """
- dataSet = self.dataSet
- selected_dataSets = self.selected_dataSets
- list_items = self.setnames
- faceColItems = self.faceColItems
- graph_path = self.graph_path
- make_3d_plot_subPlots(df_glob, dataSet, selected_dataSets,
- list_items, faceColItems,
- xlim, ylim, zlim,
- factor, select_3_col, titre, ss_titre,
- graph_path,
- azim=azim, elev=elev)
- """
- self.GUI_Gr_obj.make_3d_plot(df_glob, select_3_col, titre, ss_titre,
- factor, azim=azim, elev=elev)
- def closeWindows(self):
- # self.gl3d.removeItem(self.sp2)
- self.close()
- def closeEvent(self, event):
- """
- code exécuté quand l'interface est fermée
- """
- # ajoute une boite de dialogue pour confirmation de fermeture
- result = QtWidgets.QMessageBox.question(self,
- "Confirm Exit...",
- "Do you want to exit ?",
- (QtWidgets.QMessageBox.Yes |
- QtWidgets.QMessageBox.No))
- if result == QtWidgets.QMessageBox.Yes:
- # permet d'ajouter du code pour fermer proprement
- print(" ========== execution in Vizualizer OFF ==========")
- event.accept()
- else:
- event.ignore()
- class InputDialogWin(QtWidgets.QWidget):
- def __init__(self, parent=None):
- super(InputDialogWin, self).__init__(parent)
- layout = QtWidgets.QFormLayout()
- self.btn2 = QtWidgets.QPushButton("Enter an integer")
- self.btn2.clicked.connect(self.getint)
- self.le2 = QtWidgets.QLineEdit()
- layout.addRow(self.btn2, self.le2)
- self.setLayout(layout)
- def getint(self, dialog_title, question, val):
- num, ok = QtWidgets.QInputDialog.getInt(self, dialog_title, question, val)
- if ok:
- self.le2.setText(str(num))
- return num
- # TODO to be Finished..
- class GEPGraphsMetrics(QtWidgets.QDialog): # top-level widget to hold everything
- """
- class containing various methods to build graphs for GEP analysis
- - plot and save behavior and parameter maps
- - plot and save behavior map
- - plot and save behavior map (with chosen number of valid behaviors)
- - plot and save density map of GEP behavior domain
- - plot and save stability map of GEP behavior domain
- - plot and save progression of GEP process with two metric methods
- Two procedures can be used to estimate the "efficacy" of an
- optimisation process:
- 1) Build an array that covers the behavior space with a given
- step and count the number of behaviours that are present in
- each box.
- Then give the number of boxes with at least one behaviour.
- 2) Generate random targets inb the behaviour space and find for
- each target the closest behaviour. Then calculate the mean of
- distances from targets to closest behaviours.
- """
- def __init__(self, GUI_Gr_obj, parent=None):
- super(GEPGraphsMetrics, self).__init__(parent)
- self.resize(300, 150)
- self.GUI_Gr_obj = GUI_Gr_obj
- # self.scale_x = self.GUI_Gr_obj.scale_x
- # Create some widgets to be placed inside
- self.setErrThr_btn = QtWidgets.QPushButton('set errThr & coactThr')
- self.setErrThr_btn.clicked.connect(self.setErrThr)
- self.saveplotbhv_btn = QtWidgets.QPushButton('saveplot bhv map')
- self.saveplotbhv_btn.clicked.connect(self.saveplot_bhv)
- self.saveplobhvtparam_btn = QtWidgets.QPushButton('saveplot bhvparam maps')
- self.saveplobhvtparam_btn.clicked.connect(self.saveplot_bhvparam)
- self.behavior_map_btn = QtWidgets.QPushButton("&Behavior Map GEP")
- self.behavior_map_btn.clicked.connect(self.plot_bhvmap_nbBhvOK)
- self.MSp_ampl_Abaque_btn = QtWidgets.QPushButton("Abaque MaxSpeed/dur")
- self.MSp_ampl_Abaque_btn.clicked.connect(self.plot_abaque_duration)
- self.plot_density_btn = QtWidgets.QPushButton('plot bhv DensityMapContour')
- self.plot_density_btn.clicked.connect(self.plot_densitymaps_contour)
- self.density_map_btn = QtWidgets.QPushButton("&Density Map GEP")
- self.density_map_btn.clicked.connect(self.plot_densitymap_metrics)
- self.stability_map_btn = QtWidgets.QPushButton("&stability Map GEP")
- self.stability_map_btn.clicked.connect(self.plot_save_2D_stabilitymap)
- self.grid_method_btn = QtWidgets.QPushButton('metrics with grid method')
- self.grid_method_btn.clicked.connect(self.grid_method)
- self.dist_to_rand_goal_btn = QtWidgets.QPushButton('random goal method')
- self.dist_to_rand_goal_btn.clicked.connect(self.rand_goal_method)
- self.btn_quit = QtWidgets.QPushButton('QUIT')
- self.btn_quit.clicked.connect(self.closeIt)
- self.behavs = self.GUI_Gr_obj.optSet.behavs
- self.pairs = self.GUI_Gr_obj.optSet.pairs
- # text = QtWidgets.QLineEdit('enter text')
- self.listw = QtWidgets.QListWidget()
- # self.plot = pg.PlotWidget()
- # self.gl3d = gl.GLViewWidget()
- # Create a grid layout to manage the widgets size and position
- layout = QtWidgets.QGridLayout()
- self.setLayout(layout)
- # layout = QtWidgets..QVBoxLayout()
- # Add widgets to the layout in their proper positions
- layout.addWidget(self.setErrThr_btn, 0, 0)
- layout.addWidget(self.saveplotbhv_btn, 1, 0) # goes 1st row-left
- layout.addWidget(self.saveplobhvtparam_btn, 2, 0) # goes 2nd row-left
- layout.addWidget(self.behavior_map_btn, 3, 0) # goes 3d row-left
- layout.addWidget(self.MSp_ampl_Abaque_btn, 4, 0) # goes 4th row-left
- layout.addWidget(self.plot_density_btn, 5, 0) # goes 5th row-left
- layout.addWidget(self.density_map_btn, 6, 0)
- layout.addWidget(self.stability_map_btn, 7, 0)
- layout.addWidget(self.grid_method_btn, 8, 0)
- layout.addWidget(self.dist_to_rand_goal_btn, 9, 0)
- layout.addWidget(self.btn_quit, 10, 0) # goes in bottom-left
- # layout.addWidget(self.plot, 0, 1, 3, 1) # plot goes on right side,
- # # spanning 3 rows
- self.setWindowTitle("GEP Metrics and Graphs")
- self.to_init()
- def screen_loc(self, xshift=0, yshift=0):
- ag = QtWidgets.QDesktopWidget().availableGeometry()
- # sg = QtWidgets.QDesktopWidget().screenGeometry()
- widget = self.geometry()
- x = ag.width() - widget.width() - xshift
- # y = 2 * ag.height() - sg.height() - widget.height()
- y = ag.height() - widget.height() - yshift
- self.move(x, y)
- def to_init(self):
- """
- doc string
- """
- self.autoscale = False
- self.scale_x = self.GUI_Gr_obj.scale_x
- self.scale_y = self.GUI_Gr_obj.scale_y
- self.behav_col = self.GUI_Gr_obj.behav_col
- self.bhv_names = self.GUI_Gr_obj.bhv_names
- self.errThr = self.GUI_Gr_obj.errThr
- self.coactThr = self.GUI_Gr_obj.coactThr
- def setErrThr(self):
- list_entry_name = ["errThr", "coactThr"]
- list_entry_value = [self.errThr, self.coactThr]
- #list_value_max = [0.2, 5, 5]
- window_name = "Enter errThr and coactThr"
- dicValues = {}
- for idx, nam in enumerate(list_entry_name):
- dicValues[nam] = list_entry_value[idx]
- selected = list(dicValues.keys())
- typ, text = "sel", "typ"
- dicValues = set_values_in_list(dicValues, selected, typ, text)
- self.errThr = float(dicValues["errThr"])
- self.coactThr = float(dicValues["coactThr"])
- self.GUI_Gr_obj.errThr = self.errThr
- self.GUI_Gr_obj.coactThr = self.coactThr
- self.GUI_Gr_obj.mafen.errThr = self.errThr
- self.GUI_Gr_obj.mafen.coactThr = self.coactThr
- self.GUI_Gr_obj.mafen.clearBhv()
- self.GUI_Gr_obj.mafen.plotBhvSet(self.behavs, self.pairs,
- 0, len(self.behavs)-1)
- df_bhvremain = copy.deepcopy(self.GUI_Gr_obj.df_bhvremain)
- # ======== selection of data by coactP level =========
- # print(df_behav)
- coact_OK = df_bhvremain['coactpen'] < self.coactThr
- df_behav = df_bhvremain[coact_OK]
- def saveplot_bhv(self):
- """
- Saves a plot of behavior domain using a method of the class MaFenetre
- """
- df_bhv = self.GUI_Gr_obj.df_bhvremain
- # pathGEP = self.GUI_Gr_obj.listGEPFolders[0]
- # root_path = os.path.split(pathGEP)[0]
- # graph_path = os.path.join(root_path, "graphs")
- # graph_path = root_path + "/graphs"
- graph_path = self.GUI_Gr_obj.graph_path
- if not os.path.exists(graph_path):
- os.makedirs(graph_path)
- behav_col = self.behav_col
- if behav_col[1] == 8:
- ordTyp = "duration"
- elif behav_col[1] == 6:
- ordTyp = "maxSpeed"
- name = "{}_{}".format("GEPdata00", ordTyp)
- behav_col = self.behav_col
- max_x_bhv = df_bhv[df_bhv.columns[behav_col[0]]].max()/self.scale_x
- max_y_bhv = df_bhv[df_bhv.columns[behav_col[1]]].max()/self.scale_y
- self.GUI_Gr_obj.mafen.save_map_behav(df_bhv, graph_path, name,
- max_x=max_x_bhv, max_y=max_y_bhv)
- print("bvh plot saved to: " + graph_path)
- def saveplot_bhvparam(self):
- """
- Plots and saves in pdf and eps format, a series of x-y scatter graphs
- representing the behaviors (from df_bhvremain) and the corresponding
- parameter sets presented by pairs of parameters (from df_parremain).
- It s possible to restraindf_bhvremain and df_parremain to lines that
- are between start and end
- """
- optSet = self.GUI_Gr_obj.optSet
- xparName = optSet.xparName
- graph_path = self.GUI_Gr_obj.graph_path
- graph_name = os.path.split(graph_path)[-1]
- df_bhv = copy.deepcopy(self.GUI_Gr_obj.df_bhvremain)
- df_par = copy.deepcopy(self.GUI_Gr_obj.df_parremain)
- if graph_name[:15] == 'mltpleExpeGraph':
- print("This is a multipleExpeGraph ==> plot totality of _bhv")
- start = 0
- end = df_bhv["rgserie"].max()
- else:
- if self.autoscale is not True:
- self.dialog = InputDialogWin()
- start = 0
- end = len(self.GUI_Gr_obj.df_bhvremain)
- dialog_title = "plot range"
- start = self.dialog.getint(dialog_title, "start row", start)
- end = self.dialog.getint(dialog_title, "end row", end)
- else:
- start = 0
- end = df_bhv["rgserie"].max()
- df_bhv = df_bhv.loc[start:end]
- df_par = df_par.loc[start:end]
- behav_col = self.GUI_Gr_obj.behav_col
- listDicGraphs = self.GUI_Gr_obj.mafen.listDicGraphs
- xparNameDict = self.GUI_Gr_obj.mafen.xparNameDict
- # pathGEP = self.GUI_Gr_obj.listGEPFolders[0]
- # root_path = os.path.split(pathGEP)[0]
- # graph_path = os.path.join(root_path, "graphs")
- # graph_path = root_path + "/graphs"
- graph_path = self.GUI_Gr_obj.graph_path
- if not os.path.exists(graph_path):
- os.makedirs(graph_path)
- strGEPdataName = self.GUI_Gr_obj.prevListGEPFiles[0]
- strGEPdataName = os.path.splitext(strGEPdataName)[0]
- if behav_col[1] == 8:
- ordTyp = "duration"
- max_x_bhv = 1.2
- max_y_bhv = 2.0
- elif behav_col[1] == 6:
- ordTyp = "maxSpeed"
- max_x_bhv = 1.2
- max_y_bhv = 5.0
- baseName = "{}_{}_{}_{}_{}".format(strGEPdataName[:], ordTyp,
- "bhv_par_graphs", start, end)
- """
- max_x_bhv = df_bhv[df_bhv.columns[behav_col[0]]].max()/self.scale_x
- max_y_bhv = df_bhv[df_bhv.columns[behav_col[1]]].max()/self.scale_y
- max_x = float(int(max_x_bhv*10)+1)/10
- max_y = float(int(max_y_bhv*10)+1)/10
- """
- do_plot_bhv_param(self.GUI_Gr_obj, df_bhv, df_par, behav_col,
- graph_path, baseName, listDicGraphs, xparNameDict,
- xparName, max_x_bhv=max_x_bhv, max_y_bhv=max_y_bhv)
- print("bvh & parameter plot saved to: " + graph_path)
- def plot_bhvmap_nbBhvOK(self):
- """
- plots and saves the df_bhvremain dataframe for index < nbBhvOK
- """
- # self.GUI_Gr_obj.close_otherwin()
- """
- df_bhvremain = self.GUI_Gr_obj.df_bhvremain
- ret = 7
- if df_bhvremain is not None:
- msg = "A previous dataframe is present \n Use Same dataframe?"
- ret = MessageBox(None, msg, 'Previous dataframe detected', 3)
- print ret
- if ret == 2:
- print "ESC"
- elif ret == 6:
- print "YES --> Keep the previous dataframe"
- print "df_bhvremain size : {}\n".format(len(df_bhvremain))
- elif ret == 7:
- print "NO: --> Look for another dierctory"
- if ret == 7:
- self.GUI_Gr_obj.make_bhvpardf_bhvparwins()
- """
- optSet = self.GUI_Gr_obj.optSet
- listcolors = ['blue', 'orange', 'green', 'red', 'purple',
- 'brown', 'pink', 'gray', 'olive', 'cyan']
- # self.GUI_Gr_obj.make_bhvpardf_bhvparwins()
- df_bhvremain = self.GUI_Gr_obj.df_bhvremain
- selectedROI = self.GUI_Gr_obj.mafen.selectedROI
- # pathGEP = self.GUI_Gr_obj.listGEPFolders[0]
- # root_path = os.path.split(pathGEP)[0]
- # graph_path = os.path.join(root_path, "graphs")
- # graph_path = root_path + "/graphs"
- graph_path = self.GUI_Gr_obj.graph_path
- if not os.path.exists(graph_path):
- os.makedirs(graph_path)
- strGEPdataName = self.GUI_Gr_obj.prevListGEPFiles[0]
- GEPdataName = os.path.splitext(strGEPdataName)[0]
- df = copy.deepcopy(df_bhvremain)
- # ==============================================================
- coact_OK = df['coactpen'] < self.coactThr
- df = df[coact_OK]
- # ==============================================================
- err_OK = df['varmse'] < self.errThr
- df = df[err_OK]
- # ==============================================================
- list_entry_name = ["nbBhvOKs", "X_min", "X_max", "Y_min", "Y_max"]
- nbBhvOKs = len(df)
- behav_col = self.GUI_Gr_obj.behav_col
- # max_x = df_bhvremain[df_bhvremain.columns[behav_col[0]]].max()/100
- # max_y_bhv = df_bhvremain[df_bhvremain.columns[behav_col[1]]].max()
- list_entry_value = [str(nbBhvOKs), str(0), str(1.2), str(0), str(1.4)]
- list_value_max = [nbBhvOKs, 1.5, 1.5, 5, 5]
- window_name = "Enter nbBhvOK to Plot"
- self.list_bhvmap_value = list_entry_value
- self.get_nbBhvOKs = Enter_Values(self,
- list_entry_name,
- list_entry_value,
- list_value_max,
- window_name)
- self.get_nbBhvOKs.show()
- self.get_nbBhvOKs.exec_() # Stops further processes
- # until executed
- self.list_bhvmap_value = self.list_value
- # QtWidgets.QApplication.processEvents()
- # ==============================================================
- nbBhvOK = int(self.list_bhvmap_value[0])
- x_min = float(self.list_bhvmap_value[1])
- x_max = float(self.list_bhvmap_value[2])
- y_min = float(self.list_bhvmap_value[3])
- y_max = float(self.list_bhvmap_value[4])
- df = df[:nbBhvOK]
- rate = 100
- lstdurMvt2T = []
- behav_col = self.GUI_Gr_obj.behav_col
- if behav_col[1] == 8:
- ordTyp = "duration"
- # ======== add a new column with durMvt2T from template ===========
- for idx in df.index:
- amplitude = df.endangle[idx]
- max_speed = df.max_speed[idx]
- rep = calculate_minjerk_duration(amplitude, max_speed, rate)
- durMvt2T = rep[0]
- lstdurMvt2T.append(durMvt2T)
- df.loc[:, 'durMvt2T'] = lstdurMvt2T
- # =================================================================
- name = "{}_{}_bhvPlot_{}".format(GEPdataName, "durationT", nbBhvOK)
- elif behav_col[1] == 6:
- ordTyp = "maxSpeed"
- name = "{}_{}_bhvPlot_{}".format(GEPdataName, ordTyp, nbBhvOK)
- # name = GEPdataName + "bhvPlot_{}".format(nbBhvOK)
- # path = os.path.split(pathGEP)[0]
- if os.path.split(graph_path)[1] == "graphs":
- path = os.path.split(graph_path)[0]
- else:
- path = graph_path
- # titre = "{}/{}".format(path, name)
- baseName = name
- titre = get_titre(path, baseName) + " errThr: {} coactThr: {}"
- titre = titre.format(self.errThr, self.coactThr)
- if ordTyp == "duration":
- bhv_col = [3, 13]
- else:
- bhv_col = [3, 6]
- # ===========================================================
- # Reduction of the number of points
- # ===========================================================
- x = df[df.columns[bhv_col[0]]].to_numpy()
- y = df[df.columns[bhv_col[1]]].to_numpy()
- points = np.column_stack((x,y))
- nb_cases = 200
- resolution_x = (x.max() - x.min())/ nb_cases
- resolution_y = (y.max() - y.min())/ nb_cases
- resolution = np.array([resolution_x, resolution_y])
- # approximation of each point (several points have the samee coordinates)
- quantized = np.round(points / resolution) * resolution
- # keep only one occurence for each point (doublon suppress)
- _, unique_indices = np.unique(quantized, axis=0, return_index=True)
- df2 = df.iloc[unique_indices].copy()
- a=len(df)
- b=len(df2)
- print(f"reduction from {a} to {b} points")
- behavs_cues = df2[df2.columns[bhv_col]]
- rel_behavs_cues = behavs_cues/[self.scale_x, self.scale_y]
- nameX = rel_behavs_cues.columns[0]
- nameY = rel_behavs_cues.columns[1]
- valX = rel_behavs_cues[nameX]
- valY = rel_behavs_cues[nameY]
- if self.behav_col[1] == 8: # if ordonate is duration...
- labelnameX = nameX + "(x 0.01)"
- labelnameY = nameY
- elif self.behav_col[1] == 6:
- labelnameX = nameX + "(x 0.01)"
- labelnameY = nameY + "(x 0.01)"
- # ===========================================================
- fig = plt.figure(figsize=(10, 10), dpi=90)
- # plt.subplots_adjust(bottom=0, left=0.1, top=0.9, right=0.9)
- grid = plt.GridSpec(1, 1, wspace=0.4, hspace=0.3)
- ax1 = fig.add_subplot(grid[0, 0])
- # selectedROI = []
- if selectedROI == []:
- # ---------------------------------------------------
- ax1.scatter(valX, valY, marker='o', s=4, c="r")
- # ---------------------------------------------------
- else:
- for idxROI, listdata in enumerate(selectedROI):
- dflist_x = rel_behavs_cues[nameX][listdata]
- dflist_y = rel_behavs_cues[nameY][listdata]
- color = listcolors[idxROI]
- # ---------------------------------------------------
- ax1.scatter(dflist_x, dflist_y, marker='o', s=4, c=color)
- # ---------------------------------------------------
- ax1.set_xlabel(labelnameX, fontsize=11)
- ax1.set_ylabel(labelnameY, fontsize=11)
- plt.xticks(fontsize=10)
- plt.yticks(fontsize=10)
- ax1.set_axisbelow(True)
- ax1.set_xlim(x_min, x_max)
- ax1.set_ylim(y_min, y_max)
- ax1.grid(linestyle='-', linewidth='0.5', color='green')
- plt.suptitle(titre, fontsize=12, y=0.95)
- plt.savefig(os.path.join(graph_path, name + "_reduced" + '.pdf'))
- plt.savefig(os.path.join(graph_path, name + "_reduced" + '.eps'))
- plt.show()
- # ===========================================================
- # Plot all points
- # ===========================================================
- behavs_cues = df[df.columns[bhv_col]]
- rel_behavs_cues = behavs_cues/[self.scale_x, self.scale_y]
- nameX = rel_behavs_cues.columns[0]
- nameY = rel_behavs_cues.columns[1]
- valX = rel_behavs_cues[nameX]
- valY = rel_behavs_cues[nameY]
- if self.behav_col[1] == 8: # if ordonate is duration...
- labelnameX = nameX + "(x 0.01)"
- labelnameY = nameY
- elif self.behav_col[1] == 6:
- labelnameX = nameX + "(x 0.01)"
- labelnameY = nameY + "(x 0.01)"
- # ===========================================================
- fig = plt.figure(figsize=(10, 10), dpi=90)
- # plt.subplots_adjust(bottom=0, left=0.1, top=0.9, right=0.9)
- grid = plt.GridSpec(1, 1, wspace=0.4, hspace=0.3)
- ax1 = fig.add_subplot(grid[0, 0])
- # selectedROI = []
- if selectedROI == []:
- # ---------------------------------------------------
- ax1.scatter(valX, valY, marker='o', s=4, c="r")
- # ---------------------------------------------------
- else:
- for idxROI, listdata in enumerate(selectedROI):
- dflist_x = rel_behavs_cues[nameX][listdata]
- dflist_y = rel_behavs_cues[nameY][listdata]
- color = listcolors[idxROI]
- # ---------------------------------------------------
- ax1.scatter(dflist_x, dflist_y, marker='o', s=4, c=color)
- # ---------------------------------------------------
- ax1.set_xlabel(labelnameX, fontsize=11)
- ax1.set_ylabel(labelnameY, fontsize=11)
- plt.xticks(fontsize=10)
- plt.yticks(fontsize=10)
- ax1.set_axisbelow(True)
- ax1.set_xlim(x_min, x_max)
- ax1.set_ylim(y_min, y_max)
- ax1.grid(linestyle='-', linewidth='0.5', color='green')
- plt.suptitle(titre, fontsize=12, y=0.95)
- plt.savefig(os.path.join(graph_path, name + '.pdf'))
- plt.savefig(os.path.join(graph_path, name + '.eps'))
- plt.show()
- # self.mafen.save_map_behav(df, pathGEP, name)
- def plot_abaque_duration(self):
- """
- Plots a series of curves Maxspeed=f(amplitude) for a series of
- duration values
- INPUT: graph_path, graph_name, mindur, maxdur, stepdur
- in which mindur and max dur are the minimum and maximum values of
- duration, and stepdur is the step used to define the varius values
- of duration between mindur and maxdur
- OUTPUT: a plot that will be saved in the graph folder (graph_path)
- under the names : graph_name + '.pdf' and graph_name + '.eps'
- """
- graph_path = self.GUI_Gr_obj.graph_path
- graph_name = "abaques_duration"
- nomfic_eps = graph_path + '/' + graph_name + '.eps'
- nomfic_pdf = graph_path + '/' + graph_name + '.pdf'
- if not os.path.exists(nomfic_eps):
- plt.savefig(nomfic_eps, bbox_inches='tight')
- plt.savefig(nomfic_pdf, bbox_inches='tight')
- else:
- root = nomfic_eps[:nomfic_eps.find(".eps")]
- print(len(root))
- k = 0
- while os.path.exists("{0}({1}){2}".format(root, k, ".eps")):
- k += 1
- nomfic_eps = "{0}({1}){2}".format(root, k, ".eps")
- nomfic_pdf = "{0}({1}){2}".format(root, k, ".pdf")
- graph_name_with_ext = os.path.split(nomfic_eps)[-1]
- graph_name = os.path.splitext(graph_name_with_ext)[0]
- # ==============================================================
- list_entry_name = ["mindur", "maxdur", "stepdur"]
- list_entry_value = [0.2, 5, 0.25]
- #list_value_max = [0.2, 5, 5]
- window_name = "Enter min, max, step for durations"
- dicValues = {}
- for idx, nam in enumerate(list_entry_name):
- dicValues[nam] = list_entry_value[idx]
- selected, typ, text = "sel", "typ", window_name
- dicValues = set_values_in_list(dicValues, selected, typ, text)
- # QtWidgets.QApplication.processEvents()
- # ==============================================================
- mindur = float(dicValues["mindur"])
- maxdur = float(dicValues["maxdur"])
- stepdur = float(dicValues["stepdur"])
- plot_series_curves_maxspeed_ampl_duration(graph_path, graph_name,
- mindur, maxdur, stepdur)
- def plot_densitymap_metrics(self):
makeGraphs.py at commit 04b2210, no license · at the source
Overview
- Institut de Neurosciences Cognitives et Intégratives d’Aquitaine, UMR 5287, CNRS, Université de Bordeaux, Bordeaux, France
- Neuroscience Institute, Georgia State University, Atlanta, GA, United States
- Inria Bordeaux Sud-Ouest, Talence, France
Abstract
During rapid voluntary elbow movement on horizontal plane, a stereotyped triphasic pattern is typically observed in the electromyograms (EMGs) of antagonistic muscles acting at this joint. To explain the origin of such triphasic commands, two types of theories have been proposed. Peripheral theories consider that triphasic commands result from sensorimotor spinal networks, either through a combination of reflexes or through a spinal central pattern generator. Central theories consider that the triphasic command is elaborated in the brain. Although both theories were partially supported by physiological data, there is still no consensus about how exactly triphasic commands are elaborated. Moreover, capacities of simple spinal sensorimotor circuits to elaborate triphasic commands on their own have not been tested yet. In order to test this, we modelled arm musculoskeletal system operating in the absence of gravity, muscle activation dynamics, proprioceptive spindle and Golgi afferent activities and spinal sensorimotor circuits. Step commands were designed to modify the activity of spinal neurons and the strength of their synapses, either to prepare (SET) the network before movement onset, or to launch the movement (GO). Since these step commands do not contain any dynamics, changes in muscle activities responsible for arm movement rest entirely upon interactions between the spinal network and the musculoskeletal system. Critically, we selected step commands using a Goal Exploration Process inspired from baby babbling during development. In this task, the Goal Exploration Process proved very efficient at discovering step commands that enabled spinal circuits to handle a broad spectrum of functional behaviors, displayed in a behavioral space characterized by movement amplitude and maximal speed. All over the behavioral space, specific SET and GO commands elicited natural triphasic commands, thereby substantiating the inherent capacity of the spinal network in generating them.
Reproduced under the paper's license (CC BY), from the paper cited above.
Repository
Its files are read in the Code ↔ Paper reader above, with 5 matches between paragraphs and lines of code.
cattaert/rgep
04b2210fb8ce22193e9a2339340909d294d63bdc, 27 July 2026Availability: 1 check, the latest on 30 September 2026: the link answers
- 30 September 2026: the link answers
42 files
- BurstDetect.py, Python, 188 lines
- DialogChoose_in_List.py, Python, 1,125 lines, 2 matches
- FoldersArm.py, Python, 101 lines
- Functions/
GetRatio.py , Python, 35 lines - Functions/
border.py , Python, 33 lines - Functions/
dcm.py , Python, 89 lines - Functions/
getACC.py , Python, 35 lines - Functions/
ldiv.py , Python, 45 lines - Functions/
lodd.py , Python, 44 lines - Functions/
nc.py , Python, 44 lines - Functions/
robp.py , Python, 40 lines - GEP_GUI.py, Python, 4,297 lines
- GUI_AnimatPar.py, Python, 2,031 lines
- SaveInfoComputer.py, Python, 124 lines
- SeekValidParams.py, Python, 1,575 lines
- VSCD_tool_box.py, Python, 582 lines
- animatlabOptimSetting.py
, Python, 1,076 lines - bhv_GUI.py, Python, 277 lines
- buildControlScript.py, Python, 803 lines
- buildControlScriptGetSee
ds.py , Python, 945 lines - change_mesh_new.py, Python, 641 lines
- class_UiMainWindow.py, Python, 757 lines
- class_animatLabModel.py, Python, 1,431 lines, 1 match
- class_animatLabSimulatio
nRunner.py , Python, 331 lines - class_chartData.py, Python, 266 lines
- class_chartViz.py, Python, 141 lines
- class_projectManager.py, Python, 254 lines
- class_search_algorithm.p
y , Python, 317 lines - class_simulationSet.py, Python, 127 lines
- cmaes_tool_box.py, Python, 338 lines
- controlScriptGEP.py, Python, 2,066 lines
- dfFromFile.py, Python, 43 lines
- gep_tool_box.py, Python, 624 lines
- mainOpt.py, Python, 1,287 lines
- makeGraphs.py, Python, 4,749 lines, 2 matches
- mvt_GUI.py, Python, 170 lines
- optimization.py, Python, 5,055 lines
- param_GUI.py, Python, 101 lines
- param_model_migrate.py, Python, 1,167 lines
- seed_clusters.py, Python, 498 lines
- testAnimatLab.py, Python, 190 lines
- README.md, Text, 2 lines
The paper's code and data availability statement is in the Data section.
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 41 scripts, each with its path and the digest of its content;
- 5 matches between paragraphs of the paper and lines of the code (method lexical-v1);
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
No dataset and no data link were found in the paper.
Data availability statement
Python scripts for GEP and all simulations included in this study can be downloaded from GitHub, with an installation procedure for all software package involved: (https://
Reproduced under the paper's license (CC BY), from the paper cited above.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 1, 30 September 2026: the first record
Recorded: type, language, journal, volume, pages, dates, 7 authors, 5 keywords, 68 references.
Cite
This paper
Cattaert, D., Guemann, M., Paclet, F., Lemarchand, L., Chung, B., Oudeyer, P.-Y., & de Rugy, A. (2026). Role of spinal sensorimotor circuits in triphasic muscle command: a simulation approach using goal exploration process. Frontiers in computational neuroscience, 20, 1745836. https://
BibTeX
@article{cattaert2026rol
author = {Cattaert, Daniel and Guemann, Matthieu and Paclet, Florent and Lemarchand, Luca and Chung, Bryce and Oudeyer, Pierre-Yves and de Rugy, Aymar},
title = {{Role of spinal sensorimotor circuits in triphasic muscle command: a simulation approach using goal exploration process}},
journal = {Frontiers in computational neuroscience},
year = {2026},
month = mar,
volume = {20},
pages = {1745836},
publisher = {Frontiers Media SA},
issn = {1662-5188},
doi = {10.3389/
url = {https://
pmid = {41889600},
pmcid = {PMC13015193}
}
RIS
TY - JOUR
AU - Cattaert, Daniel
AU - Guemann, Matthieu
AU - Paclet, Florent
AU - Lemarchand, Luca
AU - Chung, Bryce
AU - Oudeyer, Pierre-Yves
AU - de Rugy, Aymar
TI - Role of spinal sensorimotor circuits in triphasic muscle command: a simulation approach using goal exploration process
T2 - Frontiers in computational neuroscience
J2 - Front Comput Neurosci
PY - 2026
DA - 2026/
VL - 20
SP - 1745836
SN - 1662-5188
PB - Frontiers Media SA
DO - 10.3389/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.3389/
"type": "article-journal",
"title": "Role of spinal sensorimotor circuits in triphasic muscle command: a simulation approach using goal exploration process",
"container-title": "Frontiers in computational neuroscience",
"author": [
{
"family": "Cattaert",
"given": "Daniel"
},
{
"family": "Guemann",
"given": "Matthieu"
},
{
"family": "Paclet",
"given": "Florent"
},
{
"family": "Lemarchand",
"given": "Luca"
},
{
"family": "Chung",
"given": "Bryce"
},
{
"family": "Oudeyer",
"given": "Pierre-Yves"
},
{
"family": "de Rugy",
"given": "Aymar"
}
],
"container-title-short":
"volume": "20",
"page": "1745836",
"DOI": "10.3389/
"PMID": "41889600",
"PMCID": "PMC13015193",
"ISSN": "1662-5188",
"publisher": "Frontiers Media SA",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
3,
11
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.1016/j.celrep.2026.117793 [code]
- Clustered inputs engage dendritic nonlinearities and calcium signaling to support efficient place-field formation in CA1 pyramidal neurons.Journal: Cell reportsIn common: seaborn, scikit-learn, pandas, 3 other tools, none (in silico), computational modeling (no new data)
- [2] doi:10.1038/s41586-026-10670-w [code]
- Zero-shot design of drug-binding proteins via neural iterative selection-expansion.Journal: NatureIn common: seaborn, scikit-learn, pandas, 3 other tools, none (in silico), computational modeling (no new data)
- [3] doi:10.7554/elife.107423 [code]
- A context-free model of savings in motor learning.Journal: eLifeIn common: seaborn, scikit-learn, pandas, 3 other tools, 1 reference
- [4] doi:10.1126/sciadv.aeg6797 [code]
- Dorsoventral gradient of theta sweeps in the medial entorhinal cortex.Journal: Science advancesIn common: seaborn, scikit-learn, pandas, 3 other tools, none (in silico), systems
- [5] doi:10.1038/s41467-026-76104-3 [code]
- Sensorimotor remapping drives task specialization in prefrontal cortex.Journal: Nature communicationsIn common: seaborn, scikit-learn, pandas, 3 other tools, computational modeling (no new data), systems
- [6] doi:10.1038/s41467-026-72152-x [code]
- Centralized brain networks controlling antennal grooming coordination.Journal: Nature communicationsIn common: seaborn, scikit-learn, pandas, 3 other tools, computational modeling (no new data), systems
- [7] doi:10.1093/nc/niag029 [code]
- A data-driven approach to identifying and evaluating connectivity-based neural correlates of conscious visual perception.Journal: Neuroscience of consciousnessIn common: seaborn, scikit-learn, pandas, 3 other tools, none (in silico)
- [8] doi:10.1371/journal.pcbi.1014391 [code]
- Multi-stable oscillations in cortical networks with two classes of inhibition.Journal: PLoS computational biologyIn common: seaborn, scikit-learn, pandas, 3 other tools, none (in silico)
- [9] doi:10.3389/fncom.2026.1753444 [code]
- NMDA receptor kinetics drive distinct routes to chaotic firing in pyramidal neurons.Journal: Frontiers in computational neuroscienceIn common: seaborn, scikit-learn, pandas, 3 other tools, none (in silico)
- [10] doi:10.1093/bioinformatics/btag328 [code]
- eFEL: electrophysiology feature extraction library.Journal: Bioinformatics (Oxford, England)In common: seaborn, scikit-learn, pandas, 3 other tools, none (in silico)
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 1 repository of the authors' code, each at its verified commit and with its license, 41 scripts, and 5 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:24f23abdb6809698…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.
Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
