Functions
Contents
Functions¶
McStasScritpt includes some freestanding functions located in the functions module.
import mcstasscript as ms
import laue_example
data = laue_example.create_data("data_for_loading")
---- Found 1 places in McStas output with keyword 'error'.
(negative time, miss next components, rounding errors, Nan, Inf).
Opening input file '/Applications/McStas-2.7.1.app/Contents/Resources/mcstas/2.7.1//data/YBaCuO.lau' (Table_Read_Offset)
Single_crystal: YBaCuO.lau structure a=3.8186 b=3.886 c=11.6777 aa=90 bb=90 cc=90 V0=173.286
Single_crystal: sample: Read 62 reflections from file 'YBaCuO.lau'
Single_crystal: sample: Vc=173.286 [Angs] sigma_abs=14.82 [barn] sigma_inc=2.105 [barn] reflections=YBaCuO.lau
Detector: PSD_I=1.649e-05 PSD_ERR=2.2246e-07 PSD_N=2.6104e+06 "psd.dat"
Detector: div_lambda_h_I=1.649e-05 div_lambda_h_ERR=2.2246e-07 div_lambda_h_N=2.6104e+06 "div_lambda_h.dat"
Detector: div_lambda_v_I=1.649e-05 div_lambda_v_ERR=2.2246e-07 div_lambda_v_N=2.6104e+06 "div_lambda_v.dat"
Detector: lambda_I=1.48475e-05 lambda_ERR=2.20229e-07 lambda_N=261775 "lambda_transmission.dat"
INFO: Placing instr file copy laue_example.instr in dataset /Users/madsbertelsen/PaNOSC/McStasScript/github/McStasScript/docs/source/user_guide/data_for_loading_14
----------------------------------------------------------------------
INFO: Using directory: "/Users/madsbertelsen/PaNOSC/McStasScript/github/McStasScript/docs/source/user_guide/data_for_loading_14"
INFO: Regenerating c-file: laue_example.c
CFLAGS=
INFO: Recompiling: ./laue_example.out
mccode-r.c:2837:3: warning: expression result unused [-Wunused-value]
*t0;
^~~
1 warning generated.
INFO: ===
Warning: 1.9722e+06 events were removed in Component[3] PSD=PSD_monitor()
(negative time, miss next components, rounding errors, Nan, Inf).
Opening input file '/Applications/McStas-2.7.1.app/Contents/Resources/mcstas/2.7.1//data/YBaCuO.lau' (Table_Read_Offset)
Single_crystal: YBaCuO.lau structure a=3.8186 b=3.886 c=11.6777 aa=90 bb=90 cc=90 V0=173.286
Single_crystal: sample: Read 62 reflections from file 'YBaCuO.lau'
Single_crystal: sample: Vc=173.286 [Angs] sigma_abs=14.82 [barn] sigma_inc=2.105 [barn] reflections=YBaCuO.lau
Detector: PSD_I=1.649e-05 PSD_ERR=2.2246e-07 PSD_N=2.6104e+06 "psd.dat"
Detector: div_lambda_h_I=1.649e-05 div_lambda_h_ERR=2.2246e-07 div_lambda_h_N=2.6104e+06 "div_lambda_h.dat"
Detector: div_lambda_v_I=1.649e-05 div_lambda_v_ERR=2.2246e-07 div_lambda_v_N=2.6104e+06 "div_lambda_v.dat"
Detector: lambda_I=1.48475e-05 lambda_ERR=2.20229e-07 lambda_N=261775 "lambda_transmission.dat"
INFO: Placing instr file copy laue_example.instr in dataset /Users/madsbertelsen/PaNOSC/McStasScript/github/McStasScript/docs/source/user_guide/data_for_loading_14
loading system configuration
data_path = data[0].get_data_location()
load_data function¶
The load_data function reads a McStas dataset from disk and returns it in the form of McStasData and McStasDataEvent objects in a list. The input is the path to the folder containing the McStas data. The path can be absolute or relative. Here the path from the generated example data is used.
loaded_data = ms.load_data(data_path)
print(loaded_data)
[
McStasData: PSD type: 2D I:1.649e-05 E:2.2246e-07 N:2610400.0,
McStasData: div_lambda_h type: 2D I:1.649e-05 E:2.2246e-07 N:2610400.0,
McStasData: div_lambda_v type: 2D I:1.649e-05 E:2.2246e-07 N:2610400.0,
McStasData: lambda type: 1D I:1.48475e-05 E:2.20229e-07 N:261775.0]
The load_data function provides a way to work with data not created in the current session or created without McStasScript.
name_search¶
The name_search function searches a list of data for instances that match a monitor name or a filename. If a monitor creates more than one dataset, name_search may return multiple data objects.
Here a search for the component name is performed.
div_lambda_h = ms.name_search("div_lambda_h", data)
print(div_lambda_h)
McStasData: div_lambda_h type: 2D I:1.649e-05 E:2.2246e-07 N:2610400.0
ms.make_plot(div_lambda_h, fontsize=14, figsize=(10, 6))
It is also possible to search for the name of the datafile.
transmission = ms.name_search("lambda_transmission.dat", data)
ms.make_plot(transmission, fontsize=14, figsize=(10, 6))
name_plot_options¶
The name_plot_options function combines a search with name_search and a call to its set_plot_options. Setting plot options changes how the data will be plotted, and this provides a nice way to control one plot per line in a neat manner.
ms.name_plot_options("PSD", data, log=True, orders_of_mag=7)
ms.name_plot_options("div_lambda_h", data, log=True, orders_of_mag=5)
ms.name_plot_options("div_lambda_v", data, log=False, colormap="hot")
ms.name_plot_options("lambda", data, log=True)
ms.make_plot(data, figsize=(8, 6))