Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using libpyvinyl input and output for transferring MCPL from one instrument to another #53

Merged
merged 3 commits into from
Nov 4, 2022

Conversation

shervin86
Copy link

  • A new MCPLDataFormat is defined to keep the path of an MCPL file.
  • A corresponding pyvinylMCPLData data class is defined
  • When calling the backengine, before writing the instrument file to disk, if an entry in the input DataCollection with key "mcpl" is found, the mcpl filename is replacing the filename value in any MCPL_input component found
  • If MCPL_output components are defined, the absolute path of the files is added to the output DataCollection with key "mcpl", "mcpl2", etc. starting from the last MCPL_output component defined.

@shervin86
Copy link
Author

A corresponding test is missing...

@shervin86
Copy link
Author

My test script:

import sys
from mcstasscript.interface import functions
from mcstasscript.interface import instr as mcinstr

# this is needed to get the location of McStas executables and libraries
# my_configurator = functions.Configurator()


calc1 = mcinstr.McStas_instr(
    "OriginTest",
    executable_path="/usr/local/mcstas/2.7.1/bin",
    package_path="/usr/local/mcstas/2.7.1/",
)

instr = calc1

Origin = instr.add_component("Origin", "Progress_bar")
Origin.set_AT(["0", "0", "0"], RELATIVE="ABSOLUTE")


src = instr.add_component("Source_simple", "Source_simple")
src.set_parameters(xwidth=0.1, yheight=0.1, dist=2, E0=5, dE=4)

guide_start = instr.add_component("Source_end", "Arm")
guide_start.set_AT([0, 0, 2], RELATIVE=src)

guide_1 = instr.add_component("guide_1", "Guide_gravity")
guide_1.set_parameters(w1=0.03, h1=0.03, m=3, l=10)
guide_1.set_RELATIVE(guide_start)

guide_end = instr.add_component("Guide_end", "Arm")
guide_end.set_AT(guide_1.l, RELATIVE=guide_1)

sample_position = instr.add_component(
    "Sample_position",
    "Arm",
)
sample_position.set_AT(0.5, RELATIVE=guide_end)

vout = instr.add_component("vout", "MCPL_output", AT=[0, 0, 0], RELATIVE="PREVIOUS")
vout.filename = '"vout"'


output = instr.backengine()
# print(mycalculator.output["mcpl"])


calc2 = mcinstr.McStas_instr(
    "MCPLTest",
    #    input_path="/dev/shm/mcstasscript",
    executable_path="/usr/local/mcstas/2.7.1/bin",
    package_path="/usr/local/mcstas/2.7.1/",
)


calc2.input = calc1.output

instr = calc2

Origin = instr.add_component("Origin", "Progress_bar")
Origin.set_AT(["0", "0", "0"], RELATIVE="ABSOLUTE")

src = instr.add_component("mcpl", "MCPL_input")
src.filename = '"none"'

guide_start = instr.add_component("Source_end", "Arm")
guide_start.set_AT([0, 0, 2], RELATIVE=src)

guide_1 = instr.add_component("guide_1", "Guide_gravity")
guide_1.set_parameters(w1=0.03, h1=0.03, m=3, l=10)
guide_1.set_RELATIVE(guide_start)


guide_end = instr.add_component("Guide_end", "Arm")
guide_end.set_AT(guide_1.l, RELATIVE=guide_1)

sample_position = instr.add_component(
    "Sample_position",
    "Arm",
)
sample_position.set_AT(0.5, RELATIVE=guide_end)

banana = instr.add_component("banana", "Monitor_nD", RELATIVE=sample_position)
banana.xwidth = 2.0
banana.yheight = 0.3
banana.restore_neutron = 1
banana.filename = '"banana.dat"'
banana.options = '"theta limits=[5 175] bins=150, banana"'

calc2.backengine()

sys.exit(0)

from libpyvinyl.Instrument import Instrument
libpyvinylINSTR = Instrument("testInstr")
libpyvinylINSTR.add_calculator(calc1)
libpyvinylINSTR.add_calculator(calc2)
libpyvinylINSTR.run()

Copy link
Collaborator

@mads-bertelsen mads-bertelsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Nice functionality, lets have an example included so we can convey it to users.

mcstasscript/data/MCPLDataFormat.py Outdated Show resolved Hide resolved
mcstasscript/interface/instr.py Outdated Show resolved Hide resolved
mcstasscript/interface/instr.py Outdated Show resolved Hide resolved
@shervin86
Copy link
Author

My testing script should be a simple but valid example. Would you like something different?

Shervin Nourbakhsh added 3 commits November 4, 2022 09:55
@shervin86
Copy link
Author

I rebased w.r.t. to the master. The tests are failing because of libpyvinyl. I fixed that in PaNOSC-ViNYL/libpyvinyl#74

@mads-bertelsen mads-bertelsen merged commit a0f9977 into master Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants