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=
      
WARNING:
 The parameter mosaic_AB of sample is initialized 
 using a static {,,,} vector.
  -> Such static vectors support literal numbers ONLY.
  -> Any vector use of variables or defines must happen via a 
     DECLARE/INITIALIZE pointer.


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

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/ccwnvQaj.ltrans0.ltrans.o: in function `read_hkl_data.constprop.0':
/home/runner/work/McStasScript/McStasScript/docs/source/user_guide/./laue_example.c:10798:(.text.read_hkl_data.constprop.0+0xbf7): 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.886 2.37949e-16]
  b = [0 0 3.8186]
  c = [11.6777 7.15053e-16 7.15053e-16]
Reciprocal space lattice orientation:
  a* = [-9.90052e-17 1.61688 0]
  b* = [-1.00753e-16 -1.00753e-16 1.64542]
  c* = [0.53805 0 0]
*** TRACE end *** 
Detector: PSD_I=1.66158e-05 PSD_ERR=2.21924e-07 PSD_N=2.61181e+06 "psd.dat"
Detector: div_lambda_h_I=1.66158e-05 div_lambda_h_ERR=2.21924e-07 div_lambda_h_N=2.61181e+06 "div_lambda_h.dat"
Detector: div_lambda_v_I=1.66158e-05 div_lambda_v_ERR=2.21924e-07 div_lambda_v_N=2.61181e+06 "div_lambda_v.dat"
Detector: lambda_I=1.49654e-05 lambda_ERR=2.21147e-07 lambda_N=261647 "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.66158e-05 E:2.21924e-07 N:2611810.0, 
McStasData: div_lambda_h type: 2D  I:1.66158e-05 E:2.21924e-07 N:2611810.0, 
McStasData: div_lambda_v type: 2D  I:1.66158e-05 E:2.21924e-07 N:2611810.0, 
McStasData: lambda type: 1D  I:1.49654e-05 E:2.21147e-07 N:261647.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/a944a76b6e54af410e9af47f4cea8962d6403af258b07ada036138c7a08ba474.png ../_images/0dbd2d0864d68f043a67a02184df6a74b57b9690b9533680e9e5f75174ab29ab.png ../_images/fd9050183a66f5347245933fd6cfe97ac124953e02864927acc5f51a37d5bd99.png ../_images/7bd281c25b7a878189f438930d8e00b8bc2b36e8c3a48e49f96527abddb9a568.png