Plotting and analysis¶
Defining a new plot¶
It is possible to initialize and create PLOTs directly from your command line. For this you have to be in a PROJECT directory.
The following command
apy --init-plot PLOT
will create:
A new plot directory: ./python/scripy/PROJECT/plots/PLOT
Default plot class: ./python/scripy/PROJECT/plots/PLOT/__init__.py
The class implements three basic methods:
import arepy as apy import numpy as np class PLOT(apy.scripy.plot): def settings(self): # Some general settings go here... def init(self): # Plot initialization goes here... def plot(self): # Plotting routine goes here...
Additionally, it is possible to split the PLOT class into several SUBPLOT classes and store them in separate files.
One parent class that contains general plot settings
./python/scripy/PROJECT/plots/PLOT/__init__.py
import arepy as apy import numpy as np class PLOT(apy.scripy.plot): def settings(self): # Some general settings go here...
One or several subplot classes that inherit the parent class
./python/scripy/PROJECT/plots/PLOT/SUBPLOT.py
import arepy as apy import numpy as np from scripy.PROJECT.plots.PLOT import PLOT class SUBPLOT(PLOT): def init(self): # Plot initialization goes here... def plot(self): # Plotting routine goes here...
Plot class¶
-
class
arepy.scripy.
plot
(action, proj, dirName, fileName=None, *args)¶ General class of a plot
- Variables
grps (arepy.files.collection) – Groups object
fig (arepy.plot.figure) – Figure object
tab (arepy.data.table) – Table object
Note
Note that class variables ‘grps’, ‘fig’ and ‘tab’ are accessible only in the ‘plot()’ function
-
settings
()¶ Plot settings
This is the place for general settings of the simulation. In principle, data set in this functions should be available for all subplots. For example the plotting units can be set here:
self.opt['simOpt'] = { 'initUnitsNew': {'length':apy.const.pc}, 'initImages':True, 'initSinks':True, 'initSnap': True, }
-
init
()¶ Initialization of a plot
This is the place for particular settings of the plot. A basic figure setup could be:
# allocate processors self.setProcessors( fig=6 ) # setup snapshot groups self.setGroups(['names','sim','snaps'],[ ('nrpm3',4, [100,33]), ('nrp0', 5, [65,23]), ]) # setup figure self.setFigure(2,1,2)
-
plot
()¶ Main plotting routine
This method prepares the figure for plotting. A simple plotting routine could look like:
# loop through all groups for grp in self.grps: # setup a simulation sim = self.getSimulation(grp.opt['sim'],**self.opt['simOpt']) # add snapshot to the group grp.addSnapshot(sim,grp.opt['snaps']) # select a subplot where we plot data sp = self.fig.getSubplot(grp.index,0, xlabel='x',ylabel='y' ) # plot an image grp.setImage(sp,'density','slice')
-
getSimulation
(sim, **opt)¶ Get a project simulation
- Parameters
sim (int) – Simulation ID
opt (dict) – Additional simulation settings
-
setProcessors
(fig=1, kdt=1, snap=1)¶ Distribute number of processors
- Parameters
fig (int) – Number of processors used for figure plotting
kdt (int) – Number of processors used by a KDTree algorithm
snap (int) – Number of processors used to read a multi-file snapshot
Example:
self.setProcessors( fig=apy.numCpu )
-
setGroups
(names, options, **opt)¶ Set simulation groups
- Parameters
names (list[str]) – Table column names
options (list[tuple]) – Table rows
opt (dict) – Additional group options
This function sets to the class a variable
self.grps
that contains all the group information.
Example:
self.setGroups(['names','sim','snaps'],[ ( 'hydroHelium', 18, 30 ), ( 'hydroOnly', 21, 30 ), ])
-
setFigure
(ncol, nrow, nfig, movie=False, show=False, debug=False, plot=True, **opt)¶ Set a new figure
- Parameters
ncol (int) – Number of collumns
nrow (int) – Number of rows
nfig (int) – Number of figures
srow (float) – Size of the subplot rows on the figure (figsize)
scol (float) – Size of the subplot cols on the figure (figsize)
movie (bool) – Create a movie from all figures
show (bool) – Display figures at the end of the plotting
debug (bool) – Save figures into a debug folder
plot (bool) – Plot figures
gridspec (dict) – Gridspec options
tickparam (dict) – Parameters of the axis ticks and their labels
group (list[str]) – List of grouped axis elements in case of several subplots
Example:
self.setFigure(2,1,1,show=True,scol=4,srow=2, gridspec={'hspace':0.1}, group=['xlabel'], tickparam={'axis':'both','direction':'in','top':True,'right':True})
-
setTable
(show=False, debug=False, **opt)¶ Set a new table
- Parameters
show (bool) – Display table at the end of the calculation
debug (bool) – Save table into a debug folder
opt (dict) – Additional table options
Plotting the data¶
Plots can be subsequently called from the command line in three ways:
Using the following command
apy --plot PLOT [SUBPLOT]
figures will be saved as
./results/PROJECT/PLOT/PLOT/000000_0000/PLOT000.png
or
./results/PROJECT/PLOT/SUBPLOT/000000_0000/SUBPLOT000.png
where 000000_0000 is a current time-stamp and 000 is a figure number.
In order to avoid many subfolders while debugging one can use also the following command:
apy --debug PLOT [SUBPLOT]
In this case the figure are stored as
./results/PROJECT/PLOT/SUBPLOT/debug/SUBPLOT000.png
Finally, it is also possible to display the last created plot without recalculating the values:
apy --show PLOT [SUBPLOT]