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")

Hide code cell output

INFO: Using directory: "/home/runner/work/McStasScript/McStasScript/docs/source/user_guide/data_for_loading"
INFO: Regenerating c-file: laue_example.c
CFLAGS= @NCRYSTALFLAGS@

-----------------------------------------------------------

Generating single GPU kernel or single CPU section layout: 

-----------------------------------------------------------

Generating GPU/CPU -DFUNNEL layout:

-----------------------------------------------------------
INFO: Recompiling: ./laue_example.out
lto-wrapper: warning: using serial compilation of 2 LTRANS jobs
lto-wrapper: note: see the '-flto' option documentation for more information
/home/runner/micromamba/envs/mcstasscript-docs/bin/x86_64-conda-linux-gnu-ld: /tmp/ccOFbpKR.ltrans0.ltrans.o: in function `read_hkl_data.constprop.0':
/home/runner/work/McStasScript/McStasScript/docs/source/user_guide/./laue_example.c:12539:(.text.read_hkl_data.constprop.0+0x36a8): warning: the use of `tmpnam' is dangerous, better use `mkstemp'
INFO: ===
Opening input file '/home/runner/micromamba/envs/mcstasscript-docs/share/mcstas/resources/data/YBaCuO.lau' (Table_Read_Offset)
Mode: lengths and angles
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
Direct space lattice orientation:
  a = [0 3.8186 2.33822e-16]
  b = [0 0 3.886]
  c = [11.6777 7.15053e-16 7.15053e-16]
Reciprocal space lattice orientation:
  a* = [-1.00753e-16 1.64542 0]
  b* = [-9.90052e-17 -9.90052e-17 1.61688]
  c* = [0.53805 0 0]
*** TRACE end *** 
Detector: PSD_I=1.61166e-05 PSD_ERR=2.17909e-07 PSD_N=2.61165e+06 "psd.dat"
Detector: div_lambda_h_I=1.61166e-05 div_lambda_h_ERR=2.17909e-07 div_lambda_h_N=2.61165e+06 "div_lambda_h.dat"
Detector: div_lambda_v_I=1.61166e-05 div_lambda_v_ERR=2.17909e-07 div_lambda_v_N=2.61165e+06 "div_lambda_v.dat"
Detector: lambda_I=1.45238e-05 lambda_ERR=2.17838e-07 lambda_N=274600 "lambda_transmission.dat"
INFO: Placing instr file copy laue_example.instr in dataset /home/runner/work/McStasScript/McStasScript/docs/source/user_guide/data_for_loading
INFO: Placing generated c-code copy laue_example.c in dataset /home/runner/work/McStasScript/McStasScript/docs/source/user_guide/data_for_loading
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.61166e-05 E:2.17909e-07 N:2611650.0, 
McStasData: div_lambda_h type: 2D  I:1.61166e-05 E:2.17909e-07 N:2611650.0, 
McStasData: div_lambda_v type: 2D  I:1.61166e-05 E:2.17909e-07 N:2611650.0, 
McStasData: lambda type: 1D  I:1.45238e-05 E:2.17838e-07 N:274600.0]

The load_data function provides a way to work with data not created in the current session or created without McStasScript.

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))
../_images/23b4e7d7b481e4ed068ae58f57f353cd894fbd7443758301fb391d706bdb7874.png ../_images/6ad80e5c69594788521c001b5bd2467462a24a148b6ed32bcef42ea45839b502.png ../_images/8b4de271d009ba6e2ee9ce2ff9b4482ac912424348539cda65a9f4a06075dd8a.png ../_images/00be6c34580f47618fc3e9630f9e31c4fded2f021fe4a9031a8eb2ec20ba4493.png