opal.datasets package¶
Notebooks¶
opal.datasets.AmrDataset module¶
-
class
opal.datasets.AmrDataset.
AmrDataset
(directory)[source]¶ Bases:
opal.datasets.DatasetBase.DatasetBase
,opal.visualization.AmrPlotter.AmrPlotter
Dataset of AMR output. It uses (https://yt-project.org/) to parse the data. An OPAL-AMR fork is found in https://gitlab.psi.ch/frey_m/yt.
-
__init__
(directory)[source]¶ - Parameters
directory (list) – Directory name that contains a Header file and Level_x (x = 0, 1, 2, …) directories.
-
get_ray_along
(axis, field, **kwargs)[source]¶ - Parameters
axis (str) – Take a line cut along this axis (‘x’, ‘y’, ‘z’)
field (str) – y-axis parameter
center ((float, float), optional) – Center through which line should go
- Returns
array
array
tuple – center
Notes
27. May 2018 http://yt-project.org/doc/visualizing/manual_plotting.html
-
property
real_ds
¶
-
opal.datasets.DatasetBase module¶
-
class
opal.datasets.DatasetBase.
DatasetBase
(directory, fname)[source]¶ Bases:
object
Class with member functions common to all datasets.
-
_directory
¶ Directory of file
- Type
str
-
_fname
¶ Name of file
- Type
str
-
property
ds
¶ returns: :rtype: reference to dataset. Used in plotting classes.
-
property
filename
¶
-
property
filetype
¶
-
property
size
¶ To be implemented by derived class.
-
opal.datasets.FieldDataset module¶
-
class
opal.datasets.FieldDataset.
FieldDataset
(directory, fname)[source]¶ Bases:
opal.datasets.DatasetBase.DatasetBase
,opal.analysis.FieldAnalysis.FieldAnalysis
,opal.visualization.FieldPlotter.FieldPlotter
-
_basename
¶ leading name all files have in common
- Type
str
-
_directory
¶ the directory of all files
- Type
str
-
_df
¶ the data of a single step (vector and scalar fields)
- Type
pandas.core.frame.DataFrame
-
_dim
¶ list of number of grid points per dimension
- Type
list
-
_fields
¶ the keys are the different fields and the values denotes ‘scalar’ or ‘field’
- Type
dict
-
_loaded_step
¶ the number of the loaded file (if -1, no file is loaded)
- Type
int
-
_label_mapper
¶ map variable names to nice plotting labels
- Type
dict
-
_npadding
¶ the number of digits in the number (used for zero padding)
- Type
int
-
_parser
¶ class to parse field data
- Type
-
_stride
¶ list of stride per dimension
- Type
list
-
_units
¶ the keys are the variable names and the values their units
- Type
dict
-
_count_files
(directory, fname)[source]¶ Count the number of field files (scalar and vector fields). Store the names and the number of files in the dictionary self._fields.
-
_find_nearest
(array, value, dim)[source]¶ Find nearest value in an array.
- Parameters
array (numpy.array) – the array where to find value
value (float) – the value to check
dim (int) – the dimension to check
Reference –
--------- –
https (//stackoverflow.com/questions/2566412/find-nearest-value-in-numpy-array (5. June 2020)) –
- Returns
array index
- Return type
int
-
_get_combined_filename
(step, field)[source]¶ - Parameters
step (int) – the time step
field (str) – the field
- Returns
the full file name
- Return type
str
-
_load_step
(step)[source]¶ Load all fields of a single step. It merges the dataframes of the individual field files of a step.
-
_zero_padding
(step)[source]¶ Get zero padded number as string in order to load a file.
- Parameters
step (int) – the time step
- Returns
zero padded number as string
- Return type
str
-
property
dataframe
¶ returns: all the data :rtype: pandas.core.frame.DataFrame
-
getData
(var, step=0)[source]¶ Get the data of a variable.
- Parameters
var (str) – variable name
step (int, optional) – time step
- Returns
data of a column
- Return type
numpy.ndarray
-
getLabel
(var)[source]¶ Obtain label for plotting.
- Parameters
var (str) – variable name
- Returns
Plotting label
- Return type
str
-
getSlice
(field, normal, pos=0.0, index=0, step=0)[source]¶ Get a 2d slice through the data.
- Parameters
field (str) – name of scalar field or vector field component
normal (str) – normal direction. Either ‘x’, ‘y’, or ‘z’
pos (float, optional) – coordinate position of slice
step (int, optional) – time step
index (int, optional) – optional to ‘pos’. If index > 0, pos is ignored.
- Returns
numpy.ndarray – coordinate values in the first direction
numpy.ndarray – coordinate values in the second direction
numpy.ndarray – field values
-
get_mesh_spacing
(step=0)[source]¶ Get the mesh spacings.
- Parameters
step (int, optional) – time step
- Returns
the mesh spacing per dimension
- Return type
list
-
property
indices
¶ Get indices of grid points.
- Returns
grid points
- Return type
numpy.ndarray
-
property
names
¶ returns: the variable names :rtype: list
-
property
positions
¶ Get coordinates at the grid points.
- Returns
coordinates
- Return type
numpy.ndarray
-
property
stride
¶ returns: stride per dimension :rtype: list
-
opal.datasets.GridDataset module¶
-
class
opal.datasets.GridDataset.
GridDataset
(directory, fname)[source]¶ Bases:
opal.datasets.SDDSDatasetBase.SDDSDatasetBase
,opal.visualization.GridPlotter.GridPlotter
opal.datasets.H5Dataset module¶
-
class
opal.datasets.H5Dataset.
H5Dataset
(directory, fname)[source]¶ Bases:
opal.datasets.DatasetBase.DatasetBase
,opal.visualization.H5Plotter.H5Plotter
,opal.analysis.H5Statistics.H5Statistics
-
__variable_mapper
¶ Map user input variable name to file variable name
- Type
dict
-
__label_mapper
¶ Map user input variable
- Type
dict
-
__unit_label_mapper
¶ Units of variables to plotting style name to plot label name
- Type
list
-
__direction
¶ Used to find out the direction in case of vector type data
- Type
dict
-
getData
(var, **kwargs)[source]¶ Obtain data of a variable
- Parameters
var (str) – Variable name
- Returns
Data (n, dim)
- Return type
array
-
getH5DataFrame
(step=0)[source]¶ Get a dataframe with the following columns:
‘id’ particle id
‘px’ momentum in x
‘py’ momentum in y
‘pz’ momentum in z
‘ptype’ particle type
‘x’ position in x
‘y’ position in x
‘z’ position in x
‘q’ particle charge
- Parameters
step (int, optional) – the output step
- Returns
a dataframe with the columns [‘id’ ,’px’, ‘py’, ‘pz’, ‘ptype’, ‘x’, ‘y’, ‘z’, ‘q’]
- Return type
pandas.core.frame.DataFrame
-
getLabel
(var)[source]¶ Obtain label for plotting.
- Parameters
var (str) – Variable name
- Returns
Appropriate name plotting ready
- Return type
str
-
getMonitorDataFrame
()[source]¶ Monitor H5 files only. Get a dataframe with the following columns:
‘id’ particle id
‘px’ momentum in x
‘py’ momentum in y
‘pz’ momentum in z
‘time’ time
‘turn’ turn number
‘x’ position in x
‘y’ position in x
‘z’ position in x
‘q’ particle charge
- Returns
a dataframe with the columns [‘id’ ,’px’, ‘py’, ‘pz’, ‘time’, ‘turn’, ‘x’, ‘y’, ‘z’]
- Return type
pandas.core.frame.DataFrame
-
getUnit
(var)[source]¶ Obtain unit for plotting.
- Parameters
var (str) – Variable name
- Returns
Appropriate unit in math mode for plotting
- Return type
str
-
property
size
¶ To be implemented by derived class.
-
opal.datasets.LBalDataset module¶
-
class
opal.datasets.LBalDataset.
LBalDataset
(directory, fname)[source]¶ Bases:
opal.datasets.SDDSDatasetBase.SDDSDatasetBase
,opal.visualization.ProfilingPlotter.ProfilingPlotter
opal.datasets.LossDataset module¶
-
class
opal.datasets.LossDataset.
LossDataset
(directory, fname)[source]¶ Bases:
opal.datasets.DatasetBase.DatasetBase
-
__parser
¶ Actual data holder
- Type
-
__unit_label_mapper
¶ Units of variables to plotting style
- Type
list
-
getData
(var, **kwargs)[source]¶ Obtain the data of a variable
- Parameters
var (str) – Variable name
- Returns
an array of the data
- Return type
array
-
getLabel
(var)[source]¶ Obtain label for plotting.
- Parameters
var (str) – Variable name
- Returns
Appropriate name plotting ready
- Return type
str
-
getUnit
(var)[source]¶ Obtain unit for plotting.
- Parameters
var (str) – Variable name
- Returns
Appropriate unit in math mode for plotting
- Return type
str
-
property
size
¶ To be implemented by derived class.
-
opal.datasets.MemoryDataset module¶
-
class
opal.datasets.MemoryDataset.
MemoryDataset
(directory, fname)[source]¶ Bases:
opal.datasets.SDDSDatasetBase.SDDSDatasetBase
,opal.visualization.MemoryPlotter.MemoryPlotter
opal.datasets.OptimizerDataset module¶
-
class
opal.datasets.OptimizerDataset.
OptimizerDataset
(directory, fname)[source]¶ Bases:
opal.datasets.DatasetBase.DatasetBase
,opal.visualization.OptimizerPlotter.OptimizerPlotter
,opal.analysis.OptimizerAnalysis.OptimizerAnalysis
-
__parser
¶ Actual data holder
- Type
-
__postfix
¶ Substring of generation filenames that is identical to all files
- Type
str
-
_loaded_generation
¶ Currently loaded generation
- Type
int
-
_loaded_optimizer
¶ Currently loaded optimizer
- Type
int
-
_loadedGeneration
¶ Load a generation file
- Type
function
-
__init__
(directory, fname)[source]¶ Constructor.
- Parameters
directory (str) – Directory name
fname (str) – Generation file name
-
_loadGeneration
(gen, opt=0, pareto=False)[source]¶ Load data of generation into memory.
- Parameters
gen (int) – Generation
opt (int, optional) – Optimizer (default: 0)
pareto (bool, optional) – Load pareto file (default: False)
-
property
bounds
¶ Obtain design variable upper and lower bounds
-
property
design_variables
¶ Obtain design variable names
-
getData
(var, **kwargs)[source]¶ Obtain the data of a variable or all data of an individual.
An individual is returned when setting ‘ind’ > 0. In that case the ‘var’ parameter is not considered.
- Parameters
var (str) – A design variable or objective
ind (int, optional) – Individual identity number, default: -1, which means all
gen (int, optional) – Generation, default: 1
opt (int, optional) – Optimizer, default: 0
all (bool, optional) – Get all info of an individual (i.e. objectives, design variables) default : True
pareto (bool, optional) – Load pareto file (default: False)
- Returns
Array of the data
- Return type
array
-
getGenerationBasename
(gen, opt=0)[source]¶ Obtain the basename of a specific generation.
- Parameters
gen (int) – Generation
opt (int, optional) – Optimizer number (default: 0)
- Returns
A basename of the selected generation
- Return type
str
-
getLabel
(var)[source]¶ Obtain label for plotting.
- Parameters
var (str) – Variable name
- Returns
Appropriate name plotting ready
- Return type
str
-
getUnit
(var)[source]¶ Obtain unit for plotting.
- Parameters
var (str) – Variable name
Notes
The optimizer does not yet write the units of each variable to the files. This function raises an error.
-
individuals
(gen, opt=0, pareto=False)[source]¶ Obtain the ID of every individual of the currently loaded generation file
- Parameters
gen (int) – Generation
opt (int, optional) – Optimizer (default: 0)
pareto (bool, optional) – Load pareto file (default: False)
-
property
num_generations
¶ Obtain the number of generations
-
property
num_optimizers
¶
-
property
objectives
¶ Obtain objective names
-
property
size
¶ Returns the number of individuals
-
opal.datasets.PeakDataset module¶
-
class
opal.datasets.PeakDataset.
PeakDataset
(directory, fname)[source]¶ Bases:
opal.datasets.DatasetBase.DatasetBase
,opal.visualization.PeakPlotter.PeakPlotter
-
__parser
¶ Actual data holder
- Type
-
__variable_mapper
¶ Map user input variable
- Type
dict
-
getData
(var, **kwargs)[source]¶ Obtain the data of a variable
- Parameters
var (str) – Variable name
- Returns
Array of the data
- Return type
array
-
getLabel
(var)[source]¶ Obtain label for plotting.
- Parameters
var (str) – Variable name
- Returns
appropriate name plotting ready
- Return type
str
-
getUnit
(var)[source]¶ Obtain unit for plotting.
- Parameters
var (str) – Variable name
- Returns
Appropriate unit in math mode for plotting
- Return type
str
-
property
size
¶ To be implemented by derived class.
-
opal.datasets.ProbeHistDataset module¶
-
class
opal.datasets.ProbeHistDataset.
ProbeHistDataset
(directory, fname)[source]¶ Bases:
opal.datasets.DatasetBase.DatasetBase
,opal.visualization.ProbePlotter.ProbePlotter
-
__parser
¶ Actual data holder
- Type
-
__variable_mapper
¶ Map user input variable
- Type
dict
-
__label_mapper
¶ Map user input variable
- Type
dict
-
getData
(var, **kwargs)[source]¶ Obtain the data of a variable
- Parameters
var (str) – Variable name
- Returns
Array of the data
- Return type
array
-
getLabel
(var)[source]¶ Obtain label for plotting.
- Parameters
var (str) – Variable name
- Returns
Appropriate name plotting ready
- Return type
str
-
getUnit
(var)[source]¶ Obtain unit for plotting.
- Parameters
var (str) – Variable name
- Returns
Appropriate unit in math mode for plotting
- Return type
str
-
property
size
¶ To be implemented by derived class.
-
opal.datasets.SDDSDatasetBase module¶
-
class
opal.datasets.SDDSDatasetBase.
SDDSDatasetBase
(directory, fname, **kwargs)[source]¶ Bases:
opal.datasets.DatasetBase.DatasetBase
-
_parser
¶ Actual data holder
- Type
-
_variable_mapper
¶ Map user input variable name to file variable name
- Type
dict
-
_label_mapper
¶ Map user input variable name to plot label name
- Type
dict
-
_unit_label_mapper
¶ Units of variables to plotting style
- Type
list
-
property
dataframe
¶
-
getData
(var, **kwargs)[source]¶ Obtain data of a variable
- Parameters
var (str) – Variable name
- Returns
List of the data
- Return type
list
-
getLabel
(var)[source]¶ Obtain label for plotting.
- Parameters
var (str) – Variable name
- Returns
Appropriate name plotting ready
- Return type
str
-
getRow
(var, val)[source]¶ Obtain a row of a dataset
- Parameters
var (str) – Variable name
val (float) – Value of given variable
-
getUnit
(var)[source]¶ Obtain unit for plotting.
- Parameters
var (str) – Variable name
- Returns
Appropriate unit in math mode for plotting
- Return type
str
-
property
size
¶ To be implemented by derived class.
-
opal.datasets.SamplerDataset module¶
-
class
opal.datasets.SamplerDataset.
SamplerDataset
(directory, fname)[source]¶ Bases:
opal.datasets.DatasetBase.DatasetBase
,opal.visualization.SamplerPlotter.SamplerPlotter
,opal.analysis.SamplerStatistics.SamplerStatistics
-
__parser
¶ Actual data holder
- Type
-
__nFiles
¶ Number of sampler output files found
- Type
int
-
__actual_file_load
(i)¶
-
__init__
(directory, fname)[source]¶ Constructor.
- Parameters
directory (str) – Directory name
fname (str) – Generation file name
-
__load_file
(ind)¶ Load file
A sampler output might be split into several files. This function first checks if new data needs to be loaded and then reads the data if necessary.
- indint
Individual identity number
-
property
bounds
¶ Obtain design variable upper and lower bounds
-
property
design_variables
¶ Obtain design variable names
-
getData
(var, **kwargs)[source]¶ Get input data
Obtain the input data of a design variable of an individual. In order to select a specific individual set parameter ‘ind’ >= 0. If ‘ind’ is not given, the function takes the default value 0.
- Parameters
var (str) – A design variable or objective if
var == ''
the full dvar (dvar==True
) or objective data is returnedind (int, optional) – Individual identity number (default: 0)
dvar (bool) – Return DVAR data in case of var==’’ (default: True)
- Returns
Design variable simulation input value.
- Return type
float
-
getLabel
(var)[source]¶ Obtain label for plotting.
- varstr
Variable name
- Returns
Appropriate name plotting ready
- Return type
str
-
getUnit
(var)[source]¶ Obtain unit for plotting.
- Parameters
var (str) – Variable name
Notes
The sampler does not yet write the units of each variable to the files. This function raises an error.
-
property
loaded_file
¶
-
property
objectives
¶ Obtain objectives names
-
property
size
¶ Returns the number of individuals
-
opal.datasets.SolverDataset module¶
-
class
opal.datasets.SolverDataset.
SolverDataset
(directory, fname)[source]¶ Bases:
opal.datasets.SDDSDatasetBase.SDDSDatasetBase
,opal.visualization.SolverPlotter.SolverPlotter
opal.datasets.StatDataset module¶
-
class
opal.datasets.StatDataset.
StatDataset
(directory, fname)[source]¶ Bases:
opal.datasets.SDDSDatasetBase.SDDSDatasetBase
,opal.visualization.StatPlotter.StatPlotter
opal.datasets.StdOpalOutputDataset module¶
-
class
opal.datasets.StdOpalOutputDataset.
StdOpalOutputDataset
(directory, fname)[source]¶ Bases:
opal.datasets.DatasetBase.DatasetBase
,opal.visualization.StdOpalOutputPlotter.StdOpalOutputPlotter
,opal.analysis.StdOpalOutputAnalysis.StdOpalOutputAnalysis
-
getData
(var, **kwargs)[source]¶ Obtain filename
- Parameters
var (str) – Unused
- Returns
Filename
- Return type
str
-
getLabel
(var)[source]¶ Obtain label for plotting.
- Parameters
var (str) – Unused
- Returns
Empty string
- Return type
str
-
getUnit
(var)[source]¶ Obtain unit for plotting.
- Parameters
var (str) – Unused
- Returns
Empty string
- Return type
str
-
property
size
¶ To be implemented by derived class.
-
opal.datasets.TimeDataset module¶
-
class
opal.datasets.TimeDataset.
TimeDataset
(directory, fname, ttype='ippl')[source]¶ Bases:
opal.datasets.DatasetBase.DatasetBase
,opal.visualization.TimingPlotter.TimingPlotter
-
__parser
¶ Actual data holder
- Type
-
__init__
(directory, fname, ttype='ippl')[source]¶ Constructor.
- Parameters
directory (str) – Directory of file
fname (str) – Basename
ttype (str) – Time file type (‘ippl’ timing or OPAL ‘output’)
-
getData
(var, **kwargs)[source]¶ Obtain the timing data
- Parameters
var (str or int) – Timing name or index of timing
prop (str, optional) – Property, i.e. ‘cpu avg’, ‘cpu max’, ‘cpu min’, ‘wall avg’, ‘wall max’, ‘wall min’ or ‘cpu tot’ and ‘wall tot’ (only for main timing)
- Returns
The timing data
- Return type
float
-
getLabel
(var)[source]¶ Obtain label for plotting.
- Parameters
var (str) – String that is returned
- Returns
var – Input variable var
- Return type
str
-
getUnit
(var)[source]¶ Obtain unit for plotting.
- Parameters
var (str) – Unused
- Returns
The string ‘s’ for seconds
- Return type
str
-
property
size
¶ To be implemented by derived class.
-
opal.datasets.TrackOrbitDataset module¶
-
class
opal.datasets.TrackOrbitDataset.
TrackOrbitDataset
(directory, fname)[source]¶ Bases:
opal.datasets.DatasetBase.DatasetBase
,opal.visualization.TrackOrbitPlotter.TrackOrbitPlotter
,opal.analysis.TrackOrbitAnalysis.TrackOrbitAnalysis
-
__parser
¶ Actual data holder
- Type
-
__unit_label_mapper
¶ Units of variables to plotting style
- Type
list
-
getData
(var, **kwargs)[source]¶ Obtain the data of a variable
- Parameters
var (str) – Variable name
- Returns
Array of the data
- Return type
array
-
getLabel
(var)[source]¶ Obtain label for plotting.
- Parameters
var (str) – Variable name
- Returns
Appropriate name plotting ready
- Return type
str
-
getUnit
(var)[source]¶ Obtain unit for plotting.
- Parameters
var (str) – Variable name
- Returns
Appropriate unit in math mode for plotting
- Return type
str
-
property
size
¶ To be implemented by derived class.
-