Comments (3)
I believe this would do the trick:
instr.settings(NeXus=True, custom_flags="--IDF")
Unless the --IDF flags needs to be immediately after the --format=NeXus?
from mcstasscript.
Thanks, I will try that out. The order should be unimportant.
from mcstasscript.
I can confirm this works, the below script runs and generates a .h5 file (obviously I should't have used data=
, there are no data that McStasScript can currently load)
The generated .h5 can be downloaded here: https://tmp.mcstas.org/pygen-mcstasscript-mccode.h5
#!/usr/bin/env python3
# Automatically generated file.
# Format: Python script code
# McStas <http://www.mcstas.org>
# Instrument: templateSANS2_Mantid.instr (templateSANS2_Mantid)
# Date: Tue May 2 09:34:21 2023
# File: templateSANS2_Mantid_generated.py
import mcstasscript as ms
# Python McStas instrument description
instr = ms.McStas_instr("templateSANS2_Mantid_generated", author = "McPygen", origin = "ESS DMSC")
# Add collected DEPENDENCY strings
instr.set_dependency(' @NEXUSFLAGS@ ')
# *****************************************************************************
# * Start of instrument 'templateSANS2_Mantid' generated code
# *****************************************************************************
# MCSTAS system dir is "/home/nexmap/pkwi/McStas/mcstas/3.x-dev/"
# *****************************************************************************
# * instrument 'templateSANS2_Mantid' and components DECLARE
# *****************************************************************************
# Instrument parameters:
Lambda = instr.add_parameter('double', 'lambda', value='6', comment='Input parameter added by mcpygen')
dlambda = instr.add_parameter('double', 'dlambda', value='0.05', comment='Input parameter added by mcpygen')
r = instr.add_parameter('double', 'r', value='150', comment='Input parameter added by mcpygen')
PHI = instr.add_parameter('double', 'PHI', value='1e-3', comment='Input parameter added by mcpygen')
Delta_Rho = instr.add_parameter('double', 'Delta_Rho', value='6e10', comment='Input parameter added by mcpygen')
frac_dir = instr.add_parameter('double', 'frac_dir', value='0.03', comment='Input parameter added by mcpygen')
frac_inc = instr.add_parameter('double', 'frac_inc', value='0.01', comment='Input parameter added by mcpygen')
instr.append_declare(r'''
''')
instr.append_initialize(r'''
''')
uv_was_scattered = instr.add_user_var("int ", "was_scattered", comment="USERVAR added by mcpygen")
# *****************************************************************************
# * instrument 'templateSANS2_Mantid' TRACE
# *****************************************************************************
# Comp instance a1, placement and parameters
a1 = instr.add_component('a1','Progress_bar', AT=['0', '0', '0'], ROTATED=['0.0', '0.0', '0.0'])
a1.profile = '"NULL"'
a1.percent = '10'
a1.flag_save = '0'
a1.minutes = '0'
# Comp instance arm, placement and parameters
arm = instr.add_component('arm','Arm', AT=['0', '0', '0'], ROTATED=['0.0', '0.0', '0.0'])
# Comp instance sourceMantid, placement and parameters
sourceMantid = instr.add_component('sourceMantid','Source_simple', AT=['0', '0', '0'], AT_RELATIVE='arm', ROTATED=['0.0', '0.0', '0.0'], ROTATED_RELATIVE='arm')
sourceMantid.radius = '0.02'
sourceMantid.yheight = '0'
sourceMantid.xwidth = '0'
sourceMantid.dist = '6'
sourceMantid.focus_xw = '0.01'
sourceMantid.focus_yh = '0.01'
sourceMantid.E0 = '0'
sourceMantid.dE = '0'
sourceMantid.lambda0 = 'lambda'
sourceMantid.dlambda = 'dlambda'
sourceMantid.flux = '1e8'
sourceMantid.gauss = '0'
sourceMantid.target_index = '+ 1'
# Comp instance coll1, placement and parameters
coll1 = instr.add_component('coll1','Slit', AT=['0', '0', '3'], AT_RELATIVE='arm', ROTATED=['0.0', '0.0', '0.0'], ROTATED_RELATIVE='arm')
coll1.xmin = 'UNSET'
coll1.xmax = 'UNSET'
coll1.ymin = 'UNSET'
coll1.ymax = 'UNSET'
coll1.radius = '0.005'
coll1.xwidth = 'UNSET'
coll1.yheight = 'UNSET'
# Comp instance coll2, placement and parameters
coll2 = instr.add_component('coll2','Slit', AT=['0', '0', '6'], AT_RELATIVE='arm', ROTATED=['0.0', '0.0', '0.0'], ROTATED_RELATIVE='arm')
coll2.xmin = 'UNSET'
coll2.xmax = 'UNSET'
coll2.ymin = 'UNSET'
coll2.ymax = 'UNSET'
coll2.radius = '0.005'
coll2.xwidth = 'UNSET'
coll2.yheight = 'UNSET'
# Comp instance sample_position, placement and parameters
sample_position = instr.add_component('sample_position','Arm', AT=['0', '0', '0.2'], AT_RELATIVE='coll2', ROTATED=['0.0', '0.0', '0.0'], ROTATED_RELATIVE='coll2')
# Comp instance Sample_in, placement and parameters
Sample_in = instr.add_component('Sample_in','PSD_monitor', AT=['0', '0', '0'], AT_RELATIVE='sample_position', ROTATED=['0.0', '0.0', '0.0'], ROTATED_RELATIVE='sample_position')
Sample_in.nx = '90'
Sample_in.ny = '90'
Sample_in.filename = '"SamplePos"'
Sample_in.xmin = '-0.05'
Sample_in.xmax = '0.05'
Sample_in.ymin = '-0.05'
Sample_in.ymax = '0.05'
Sample_in.xwidth = '0.02'
Sample_in.yheight = '0.02'
Sample_in.restore_neutron = '1'
Sample_in.nowritefile = '0'
# Comp instance sampleMantid, placement and parameters
sampleMantid = instr.add_component('sampleMantid','SANS_spheres2', AT=['0', '0', '0.2'], AT_RELATIVE='coll2', ROTATED=['0.0', '0.0', '0.0'], ROTATED_RELATIVE='coll2')
# SPLIT 10 times at sampleMantid
sampleMantid.set_SPLIT('10')
# EXTEND at sampleMantid
sampleMantid.append_EXTEND(r'''
was_scattered=SCATTERED;
''')
sampleMantid.xwidth = '0.02'
sampleMantid.yheight = '0.02'
sampleMantid.zthick = '0.001'
sampleMantid.dsdw_inc = '0.02'
sampleMantid.sc_aim = '( 1 - frac_dir )'
sampleMantid.sans_aim = '( 1 - frac_inc )'
sampleMantid.R = 'r'
sampleMantid.phi = '1e-3'
sampleMantid.drho = '6e10'
sampleMantid.singlesp = '1'
sampleMantid.Qmind = '0.0001'
sampleMantid.Qmaxd = '2.1544346900319'
# Comp instance detector, placement and parameters
detector = instr.add_component('detector','PSD_monitor', AT=['0', '0', '3'], AT_RELATIVE='sample_position', ROTATED=['0.0', '0.0', '0.0'], ROTATED_RELATIVE='sample_position')
detector.nx = '128'
detector.ny = '128'
detector.filename = '"PSD.dat"'
detector.xmin = '-0.3'
detector.xmax = '0.3'
detector.ymin = '-0.3'
detector.ymax = '0.3'
detector.xwidth = '0'
detector.yheight = '0'
detector.restore_neutron = '0'
detector.nowritefile = '0'
# Comp instance detectorSANS, placement and parameters
detectorSANS = instr.add_component('detectorSANS','PSD_monitor', AT=['0', '0', '3'], AT_RELATIVE='sample_position', ROTATED=['0.0', '0.0', '0.0'], ROTATED_RELATIVE='sample_position')
# WHEN ( was_scattered ) at detectorSANS
detectorSANS.set_WHEN('( was_scattered )')
detectorSANS.nx = '128'
detectorSANS.ny = '128'
detectorSANS.filename = '"SANS.dat"'
detectorSANS.xmin = '-0.3'
detectorSANS.xmax = '0.3'
detectorSANS.ymin = '-0.3'
detectorSANS.ymax = '0.3'
detectorSANS.xwidth = '0'
detectorSANS.yheight = '0'
detectorSANS.restore_neutron = '0'
detectorSANS.nowritefile = '0'
# Comp instance detectorDB, placement and parameters
detectorDB = instr.add_component('detectorDB','PSD_monitor', AT=['0', '0', '3'], AT_RELATIVE='sample_position', ROTATED=['0.0', '0.0', '0.0'], ROTATED_RELATIVE='sample_position')
# WHEN ( ! was_scattered ) at detectorDB
detectorDB.set_WHEN('( ! was_scattered )')
detectorDB.nx = '128'
detectorDB.ny = '128'
detectorDB.filename = '"Direct.dat"'
detectorDB.xmin = '-0.3'
detectorDB.xmax = '0.3'
detectorDB.ymin = '-0.3'
detectorDB.ymax = '0.3'
detectorDB.xwidth = '0'
detectorDB.yheight = '0'
detectorDB.restore_neutron = '0'
detectorDB.nowritefile = '0'
# Comp instance Ldetector, placement and parameters
Ldetector = instr.add_component('Ldetector','L_monitor', AT=['0', '0', '3.01'], AT_RELATIVE='sample_position', ROTATED=['0.0', '0.0', '0.0'], ROTATED_RELATIVE='sample_position')
Ldetector.nL = '1000'
Ldetector.filename = '"Edet.dat"'
Ldetector.nowritefile = '0'
Ldetector.xmin = '-0.3'
Ldetector.xmax = '0.3'
Ldetector.ymin = '-0.3'
Ldetector.ymax = '0.3'
Ldetector.xwidth = '0'
Ldetector.yheight = '0'
Ldetector.Lmin = '5.5'
Ldetector.Lmax = '6.5'
Ldetector.restore_neutron = '0'
# Comp instance PSDrad, placement and parameters
PSDrad = instr.add_component('PSDrad','PSD_monitor_rad', AT=['0', '0', '3.02'], AT_RELATIVE='sample_position', ROTATED=['0.0', '0.0', '0.0'], ROTATED_RELATIVE='sample_position')
# WHEN ( was_scattered ) at PSDrad
PSDrad.set_WHEN('( was_scattered )')
PSDrad.nr = '100'
PSDrad.filename = '"psd2.dat"'
PSDrad.filename_av = '"psd2_av.dat"'
PSDrad.rmax = '0.3'
# Comp instance PSDrad_full, placement and parameters
PSDrad_full = instr.add_component('PSDrad_full','PSD_monitor_rad', AT=['0', '0', '3.02'], AT_RELATIVE='sample_position', ROTATED=['0.0', '0.0', '0.0'], ROTATED_RELATIVE='sample_position')
PSDrad_full.nr = '100'
PSDrad_full.filename = '"psd2_full.dat"'
PSDrad_full.filename_av = '"psd2_av_full.dat"'
PSDrad_full.rmax = '0.3'
# Comp instance nD_Mantid_1, placement and parameters
nD_Mantid_1 = instr.add_component('nD_Mantid_1','Monitor_nD', AT=['0', '0', '3.2'], AT_RELATIVE='sampleMantid', ROTATED=['0.0', '0.0', '0.0'], ROTATED_RELATIVE='sampleMantid')
nD_Mantid_1.user1 = '""'
nD_Mantid_1.user2 = '""'
nD_Mantid_1.user3 = '""'
nD_Mantid_1.xwidth = '0'
nD_Mantid_1.yheight = '0'
nD_Mantid_1.zdepth = '0'
nD_Mantid_1.xmin = '-0.3'
nD_Mantid_1.xmax = '0.3'
nD_Mantid_1.ymin = '-0.3'
nD_Mantid_1.ymax = '0.3'
nD_Mantid_1.zmin = '0'
nD_Mantid_1.zmax = '0'
nD_Mantid_1.bins = '0'
nD_Mantid_1.min = '-1e40'
nD_Mantid_1.max = '1e40'
nD_Mantid_1.restore_neutron = '1'
nD_Mantid_1.radius = '0'
nD_Mantid_1.options = '"mantid square x limits=[-0.3 0.3] bins=128 y limits=[-0.3 0.3] bins=128, neutron pixel min=0 t, list all neutrons"'
nD_Mantid_1.filename = '"bank01_events.dat"'
nD_Mantid_1.geometry = '"NULL"'
nD_Mantid_1.nowritefile = '0'
nD_Mantid_1.username1 = '"NULL"'
nD_Mantid_1.username2 = '"NULL"'
nD_Mantid_1.username3 = '"NULL"'
instr.settings(checks=False,NeXus=True, custom_flags="--IDF",ncount=1e7)
data = instr.backengine()
# end of generated Python code templateSANS2_Mantid_generated.py
from mcstasscript.
Related Issues (20)
- Find data both from component name and data file name HOT 1
- Set plot options when defining monitor
- Provide filenames and strigns
- Relative vector length not checked HOT 1
- InputError exception used but not defined
- Group skipped in reader HOT 2
- Reader raise a error when reading COPY components.
- Dumping error with pint quantities HOT 1
- No instrument file generated if force_compile=False HOT 1
- Integer values read from component files *must* be expressed in base 10.
- Multiple MCPL_output Components
- show_instrument() problems HOT 1
- Feature request: instr.add_DEPENDENCY HOT 1
- Feature request: Add openacc (GPU) acceleration option alongside MPI HOT 2
- Feature request: Add 'astrox' comp-search folder when generating McXtrace-code HOT 2
- Naming issue with COPY() components
- Missing support for "diagnostics" option when using McXtrace? HOT 1
- show_instrument not working in documentation nor locally
- McStas 3.5 - McStasScript integration: Instrument visualisation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mcstasscript.