Skip to content

Overview of Functionality

tincotema edited this page Dec 6, 2023 · 2 revisions

Overview of Functionality

This Package offers several functions to improve your workflow with Mcstas Simuations and Processing the simulation results.

The Functionality is build around the two Dictionary's variables and mcvariables.

Dict variables

Parameters of the dict variables are global variables that apply to any simulation and contains the location of the main working directory. It is automatically generated with the 'mcpw_setup' command and is saved in local_var.py It belongs to a single host

The typical name vor this dict is 'var'.

The dict entry's you will find the most useful will be:

  • var['p_local'] The Local Working directory (Absolute Path; a Path object)
  • var['sim_res'] The simulation result folder in your p_local dir.

All other variables should not be necessary to use in your code.

Dict mcvariables

Parameters of the dict mcvariables contain all important values to run a simulation. The mcpw_setup command will create it from the given instrument file and put it into instrument_name.py file.

The typical name vor the dict is 'mcvar'.

The dict entry you will find the most usefull will be:

  • mcvar['sim'] The directory(name) of a particular simulation

All other entry's should be self explanatory

If one of the variables is an object of the Scan class, the program will run as many simulation steps as defined in the scan variable (see Scan Class below). You can only scan one variable at a time with this method. To scan multiple variables at once see 'Scanning with csv file'.

The instrument.py file

The instrument.py file will be the main file you will work in. Apart from the mcvariables class it will contain all your custom functions for analyzing and data treatment. Here you import all necessary packages and all your functions you want to get executed and call them in the analyse(), pre_simulation() or post_simulation() function. These three functions will be called by mcpw_manager and executed at the correct time

pre_simulation(var,mcvar,var_list)

This function can change var, mcvar, and var_list at runtime before the simulation is called. You can use it to reformat your var_list, create a new one or have fancy interconnecting of your mcstas variables. The changed variables will later be saved together with the simulation results. This function is not called if you only analyse a old results.

post_simulation(var,mcvar, var_list)

This function is called directly after the simulation and is meant to be a part of post processing that permanently change the data from the simulation. You can for example compress the detector output of several detector to single file to save disk space.

analyse(var,mcvar,var_list)

This function should contains everything to analyse and visualize the results in a non destructive way. If you use the "full" mode of mcpw_manager it is called at the very end of the simulation also after post_simulation.

You can call it also separately for an older simulation you did with the "analyse" mode. Here the -d option of mcpw_manager indicates witch old simulation you want to analyse. The corresponding mcvariables potentially used var_list is automatically loaded. If no -d option is specified the latest available simulation is analysed.

Use of Scan class and var_lists

Scan Class

The Scan class is used to simplify the process of running a number of simulations over a range of one variable. If you want to change more than one variable per step, use the csv file function.

Scan(start,stop,unit,step)

The first two arguments are the start and stop range for the Scan, the 3th value is a string which represents the unit of the scan variable. the 4th value is the number of steps. The scan points are evenly distributed between the start and stop points, which are included.

Property's of the Scan class are:

-scan.start start value -scan.stop stop value -scan.range stop - start -scan.unit normally a string that can be used in the automatic labelling of graphs -scan.N number of steps to scan the range with -scan.step size of one step -scan.absolute_value(n) absolute value of the n-th step

Scanning with csv file

Witch the -l, --list argument you can provide a csv file with data points. The first row has to be a header row containing the names of the variables below them. The names have to match with the once in you instrument and mcvar dict. Each row represents one simulation and has to be fully filled with values that can be cast to a python float. Variable that don't change at all don't need to be part of the list and will be taken from the mcvariable class.

Mini example csv:

  x,    y,   z
  1,    4,   7
1.4,    6,   9
  2, 4e-4, 9e5

The content of the csv is loaded into the variable var_list.

If you want to ignore a column you can do this by adding a '#' at the beginning of the variable name. i.e: x, #y, z; in this case the y column would be ignored.

If you want to load a csv with a different format than described above, you have to reformat it accordingly inside the scope of the pre_simulation function.