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/ccNu0bY3.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+0xbb3): 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.64535e-05 PSD_ERR=2.20527e-07 PSD_N=2.61047e+06 "psd.dat"
Detector: div_lambda_h_I=1.64535e-05 div_lambda_h_ERR=2.20527e-07 div_lambda_h_N=2.61047e+06 "div_lambda_h.dat"
Detector: div_lambda_v_I=1.64535e-05 div_lambda_v_ERR=2.20527e-07 div_lambda_v_N=2.61047e+06 "div_lambda_v.dat"
Detector: lambda_I=1.48432e-05 lambda_ERR=2.20422e-07 lambda_N=260081 "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.64535e-05 E:2.20527e-07 N:2610470.0, 
McStasData: div_lambda_h type: 2D  I:1.64535e-05 E:2.20527e-07 N:2610470.0, 
McStasData: div_lambda_v type: 2D  I:1.64535e-05 E:2.20527e-07 N:2610470.0, 
McStasData: lambda type: 1D  I:1.48432e-05 E:2.20422e-07 N:260081.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/1d59832a46b11fca0a0d8afc582f8f410b41835cf1e865df9ddbe7258522bf8f.png ../_images/db8b773891b1e616092cae2dc09e54ea04b43c374f3380530e2ffb415414a183.png ../_images/56da082060a759e62da105765cc7a8c78c7db38c0a109195d2db8284a7fbd565.png ../_images/f42359692b63e286fe9ec92a2e3f41ad17596eaaec160376d432bb7418f618c1.png