Example #1
0
 def _run_beam(self):
     from mcvine import resources as res
     moddat = os.path.join(
         res.instrument('CNCS'),
         'mcstas',
         'source_sct21a_td_05_1.dat',
     )
     guide11dat = os.path.join(
         res.instrument('CNCS'),
         'mcstas',
         'guide11-focus.txt',
     )
     cmd = ['mcvine instruments cncs mod2sample']
     from mcni.pyre_support.MpiApplication \
         import mpi_launcher_choice as launcher
     data = {
         "ncount": self.inventory.ncount,
         "buffer_size":
         int(self.inventory.ncount / 5 / self.inventory.nodes),
         ("%s.nodes" % launcher): self.inventory.nodes,
         "output-dir": self.m2sout,
         'moderator.S_filename': moddat,
         'Guide11.option': 'file={}'.format(guide11dat),
     }
     cmd += self._buildCmdOptions(data)
     cmd = ' '.join(cmd)
     open('run-m2s.sh', 'wt').write(cmd)  # save the running command
     bpp._exec(cmd)
     return
Example #2
0
 def test1(self):
     source_file = os.path.join(instrument('ARCS'), "moderator/source_sct521_bu_17_1.dat")
     from mcni.pyre_support.MpiApplication \
         import mpi_launcher_choice as launcher
     cmd = "mcvine instruments arcs mod2sample --moderator.S_filename=%s --ncount=1e5 --buffer_size=10000 --%s.nodes=2" % (source_file, launcher)
     sp.check_call(shlex.split(cmd), shell=False, cwd=cwd)
     return
Example #3
0
 def _run_beam(self):
     cmd = ['mcvine instruments arcs mod2sample']
     keys = ['ncount']
     cmd += self._buildCmdFromInventory(keys)
     # buffer_size
     buffer_size = self.inventory.buffer_size
     if not buffer_size:
         buffer_size = int(self.inventory.ncount/10)
     cmd += ['--buffer_size=%s' % buffer_size]
     # output-dir
     cmd.append( '--output-dir=%s' % self.m2sout)
     # moderator file
     from mcvine import resources
     moddat = os.path.join(
         resources.instrument('ARCS'), 'moderator',
         'source_sct521_bu_17_1.dat',
         )
     cmd += ['--moderator.S_filename=%s' % moddat]
     # mpi nodes
     from mcni.pyre_support.MpiApplication import mpi_launcher_choice
     if self.inventory.nodes:
         cmd += ['--%s.nodes=%s' % (
             mpi_launcher_choice, self.inventory.nodes)]
     cmd = ' '.join(cmd)
     open('run-m2s.sh', 'wt').write(cmd) # save the running command
     bpp._exec(cmd)
     return
Example #4
0
def readPixelPosition(pixelID):
    ppfile = 'pixelID2position.bin'
    ppfile = os.path.join(resources.instrument('ARCS'), 'reduction', ppfile)
    import numpy
    positions = numpy.fromfile(ppfile, 'double')
    positions.shape = -1, 3
    return positions[pixelID]
Example #5
0
def run(neutrons,
        workdir,
        nodes,
        ncount=None,
        tofbinsize=0.1,
        tofmax=0.2,
        instrument=None,
        detsys=None,
        z_rotation=0.):
    neutrons = os.path.abspath(neutrons)
    workdir = os.path.abspath(workdir)
    if os.path.exists(workdir):
        raise IOError("%s already exists" % workdir)
    os.makedirs(workdir)
    if not detsys:
        if not instrument:
            raise RuntimeError(
                "Please specify instrument name or path to <instrument>.xml.fornxs"
            )
        from mcvine import resources
        detsys = os.path.join(resources.instrument(instrument.upper()),
                              'detsys', '%s.xml.fornxs' % instrument)
    eventdat = sendneutronstodetsys(
        neutronfile=neutrons,
        workdir=workdir,
        nodes=nodes,
        ncount=ncount,
        tofbinsize=tofbinsize,
        tofmax=tofmax,
        detsys=detsys,
        z_rotation=z_rotation,
    )
    return
Example #6
0
 def main(self):
     neutrons = self.inventory.neutrons; neutrons = os.path.abspath(neutrons)
     workdir = self.inventory.workdir; workdir = os.path.abspath(workdir)
     if os.path.exists(workdir):
         raise IOError("%s already exists" % workdir)
     os.makedirs(workdir)
     
     nodes = self.inventory.nodes
     tofbinsize = self.inventory.tofbinsize
     tofmax = self.inventory.tofmax
     z_rotation = self.inventory.z_rotation
     detsys = self.inventory.detsys
     if not detsys:
         instrument = self.inventory.instrument
         if not instrument:
             raise RuntimeError("Please specify instrument name or path to <instrument>.xml.fornxs")
         from mcvine import resources
         detsys = os.path.join(
             resources.instrument(instrument.upper()), 
             'detsys',
             '%s.xml.fornxs' % instrument)
     run(neutrons, workdir, 
         nodes=nodes, tofbinsize=tofbinsize, tofmax=tofmax, 
         detsys=detsys, z_rotation=z_rotation)
     return
Example #7
0
def runsim(vi, ei, ncount):
    xml = os.path.join(resources.instrument('ARCS'), 'reduction', 'ARCS.xml.reduction.standard')
    # run main sim
    cmd = './sd --source.velocity="%s" --source.energy=%s --detector.instrumentxml=%s --ncount=%s' % (
        tuple(vi), ei, xml, ncount)
    execute(cmd)
    return
Example #8
0
def readPixelPosition(pixelID):
    ppfile = 'pixelID2position.bin'
    ppfile = os.path.join(resources.instrument('ARCS'), 'reduction', ppfile)
    import numpy
    positions = numpy.fromfile(ppfile, 'double')
    positions.shape = -1,3
    return positions[pixelID]
Example #9
0
def runsim(vi, ei, ncount):
    xml = os.path.join(resources.instrument('ARCS'), 'reduction',
                       'ARCS.xml.reduction.standard')
    # run main sim
    cmd = './sd --source.velocity="%s" --source.energy=%s --detector.instrumentxml=%s --ncount=%s' % (
        tuple(vi), ei, xml, ncount)
    execute(cmd)
    return
Example #10
0
 def test1(self):
     source_file = os.path.join(instrument('ARCS'),
                                "moderator/source_sct521_bu_17_1.dat")
     from mcni.pyre_support.MpiApplication \
         import mpi_launcher_choice as launcher
     cmd = "mcvine instruments arcs mod2sample --moderator.S_filename=%s --ncount=1e5 --buffer_size=10000 --%s.nodes=2" % (
         source_file, launcher)
     sp.check_call(shlex.split(cmd), shell=False, cwd=cwd)
     return
Example #11
0
def run(
    ncount=100, 
    vi=(0,0,1),
    ei = 700,
    ):
    # convert to mcstas coordinates
    vx,vy,vz = vi
    vi = vy, vz, vx
    xml = os.path.join(resources.instrument('ARCS'), 'reduction', 'ARCS.xml.reduction.standard')
    # run main sim
    cmd = './sd --source.velocity="%s" --source.energy=%s --detector.instrumentxml=%s --ncount=%s' % (
        tuple(vi), ei, xml, ncount)
    print ("running", cmd)
    execute(cmd)
    
    # reduce events to S(Q,E)
    eventsdat = 'out/events.dat'
    return
def run(
        ncount=100,
        vi=(0, 0, 1),
        ei=700,
):
    # convert to mcstas coordinates
    vx, vy, vz = vi
    vi = vy, vz, vx
    xml = os.path.join(resources.instrument('ARCS'), 'reduction',
                       'ARCS.xml.reduction.standard')
    # run main sim
    cmd = './sd --source.velocity="%s" --source.energy=%s --detector.instrumentxml=%s --ncount=%s' % (
        tuple(vi), ei, xml, ncount)
    print(("running", cmd))
    execute(cmd)

    # reduce events to S(Q,E)
    eventsdat = 'out/events.dat'
    return
Example #13
0
    def _run_beam(self):
        cmd = ["mcvine instruments sequoia mod2sample"]
        keys = ["ncount"]
        cmd += self._buildCmdFromInventory(keys)
        cmd += ["-buffer_size=%s" % int(self.inventory.ncount / 10)]
        cmd.append("--output-dir=%s" % self.m2sout)
        from mcvine import resources as res

        moddat = os.path.join(res.instrument("SEQUOIA"), "moderator", "source_sct521_bu_17_1.dat")
        cmd += ["-mod.S_filename=%s" % moddat]
        # mpi nodes
        from mcni.pyre_support.MpiApplication import mpi_launcher_choice

        if self.inventory.nodes:
            cmd += ["--%s.nodes=%s" % (mpi_launcher_choice, self.inventory.nodes)]
        cmd = " ".join(cmd)
        open("run-m2s.sh", "wt").write(cmd)  # save the running command
        bpp._exec(cmd)
        return
Example #14
0
 def _run_beam(self):
     cmd = ['mcvine instruments arcs mod2sample']
     keys = ['ncount']
     cmd += self._buildCmdFromInventory(keys)
     cmd += ['--buffer_size=%s' % int(self.inventory.ncount/10)]
     cmd.append( '--output-dir=%s' % self.m2sout)
     from mcvine import resources
     moddat = os.path.join(
         resources.instrument('ARCS'), 'moderator',
         'source_sct521_bu_17_1.dat',
         )
     cmd += ['--moderator.S_filename=%s' % moddat]
     # mpi nodes
     from mcni.pyre_support.MpiApplication import mpi_launcher_choice
     if self.inventory.nodes:
         cmd += ['--%s.nodes=%s' % (
             mpi_launcher_choice, self.inventory.nodes)]
     cmd = ' '.join(cmd)
     open('run-m2s.sh', 'wt').write(cmd) # save the running command
     bpp._exec(cmd)
     return
Example #15
0
 def _run_beam(self):
     from mcvine import resources as res
     moddat = os.path.join(
         res.instrument('HYSPEC'),
         'mcstas',
         'SNS_TD_30o70p_fit_fit.dat',
     )
     cmd = ['mcvine instruments hyspec mod2sample']
     from mcni.pyre_support.MpiApplication \
         import mpi_launcher_choice as launcher
     data = {
         "ncount": self.inventory.ncount,
         "buffer_size":
         int(self.inventory.ncount / 5 / self.inventory.nodes),
         ("%s.nodes" % launcher): self.inventory.nodes,
         "output-dir": self.m2sout,
         'moderator.S_filename': moddat,
     }
     cmd += self._buildCmdOptions(data)
     cmd = ' '.join(cmd)
     open('run-m2s.sh', 'wt').write(cmd)  # save the running command
     bpp._exec(cmd)
     return
Example #16
0
 def test1(self):
     source_file = os.path.join(instrument('ARCS'), "moderator/source_sct521_bu_17_1.dat")
     cmd = "mcvine instruments arcs m2s -E=100 --- --moderator.S_filename=%s --ncount=1e5 --buffer_size=10000 --overwrite-datafiles" % source_file
     execute(cmd)
     return
Example #17
0
    cmd += ['--%s=%s' % (k,v) for k,v in args.iteritems()]
    cmd = ' '.join(cmd)
    run_sh = os.path.join(workdir, 'run.sh')
    open(run_sh, 'w').write(cmd+'\n')
    from .utils import execute
    execute(cmd, workdir)

    # events.dat
    outfile = os.path.join(workdir, 'out', 'events.dat')
    return outfile

sd_txt = """
import mcvine
from mcvine.applications.InstrumentBuilder import build
components = ['source', 'detsys']
App = build(components)
app = App('sd')
app.run()
"""


import numpy as np
from mcvine import resources
import os

#
arcsxml = os.path.join(
    resources.instrument('ARCS'), 'detsys', 'ARCS.xml.fornxs')


Example #18
0
            import mpi_launcher_choice as launcher
        args['%s.nodes' % launcher] = nodes
    cmd += ['--%s=%s' % (k, v) for k, v in args.items()]
    cmd = ' '.join(cmd)
    run_sh = os.path.join(workdir, 'run.sh')
    open(run_sh, 'w').write(cmd + '\n')
    from .utils import execute
    execute(cmd, workdir)

    # events.dat
    outfile = os.path.join(workdir, 'out', 'events.dat')
    return outfile


sd_txt = """
import mcvine
from mcvine.applications.InstrumentBuilder import build
components = ['source', 'detsys']
App = build(components)
app = App('sd')
app.run()
"""

import numpy as np
from mcvine import resources
import os

#
cncsxml = os.path.join(resources.instrument('CNCS'), 'detsys',
                       'CNCS.xml.fornxs')
Example #19
0
 def test1(self):
     source_file = os.path.join(instrument('ARCS'),
                                "moderator/source_sct521_bu_17_1.dat")
     cmd = "mcvine instruments arcs m2s -E=100 --- --moderator.S_filename=%s --ncount=1e5 --buffer_size=10000 --overwrite-datafiles" % source_file
     execute(cmd)
     return
Example #20
0
File: raw.py Project: mcvine/mcvine
    return


def setEnergyRequest(entry, Ei):
    """set energy request value into an ARCS nexus file
    
    entry: nexus "entry"
    Ei: unit meV
    
    caveat: the nexus template file should already have /entry/DASlogs/EnergyRequest which contains the appropriate sub-datasets with correct attributes.
    """
    setDASlogsEntryValue(entry, 'EnergyRequest', Ei)
    return


bank_id_offset = 1
pixelsperbank = 8 * 128
pixel_id_offset = (bank_id_offset-1)*pixelsperbank
nbanks = 20
npixels = nbanks * pixelsperbank
import os
from mcvine import resources as res
nxs_template = os.path.join(
    res.instrument('HYSPEC'), 'resources',
    'hyspec-raw-events-template.nxs',
    )
import numpy as np


# End of file 
Example #21
0
    return


def setEnergyRequest(entry, Ei):
    """set energy request value into an ARCS nexus file
    
    entry: nexus "entry"
    Ei: unit meV
    
    caveat: the nexus template file should already have /entry/DASlogs/EnergyRequest which contains the appropriate sub-datasets with correct attributes.
    """
    setDASlogsEntryValue(entry, 'EnergyRequest', Ei)
    return


bank_id_offset = 1
pixelsperbank = 8 * 128
pixel_id_offset = (bank_id_offset - 1) * pixelsperbank
nbanks = 20
npixels = nbanks * pixelsperbank
import os
from mcvine import resources as res
nxs_template = os.path.join(
    res.instrument('HYSPEC'),
    'nxs',
    'hyspec-raw-events-template.nxs',
)
import numpy as np

# End of file
Example #22
0
File: raw.py Project: mcvine/mcvine
        # h.shape = 8, 128
        # b['data_x_y'][:] = np.array(h, dtype='uint32')
        
        continue

    # XXX: should it be a float?
    # entry['total_counts'][0] = len(events)

    #
    f.close()
    #
    sys.stdout.write('\n')
    return


bank_id_offset = 1
pixelsperbank = 8 * 128
pixel_id_offset = (bank_id_offset-1)*pixelsperbank
nbanks = 50
npixels = nbanks * pixelsperbank
import os
from mcvine import resources as res
nxs_template = os.path.join(
    res.instrument('CNCS'), 'nxs',
    'cncs-raw-events-template.nxs',
    )
import numpy as np


# End of file 
Example #23
0
        # data
        hist = hh.load(itofpath)
        tofaxis = hist.axisFromName('tof'); tofaxis.changeUnit('microsecond')
        bb = tofaxis.binBoundaries().asNumarray()
        tofmin = bb[0]; tofmax = bb[-1]
        # XXX Michael Reuter said that float array is OK.
        # change array to double
        N = len(mon_entry['data'])
        del mon_entry['data']
        mon_entry['data'] = np.zeros(N, dtype="double")
        # set attributes
        mon_entry['data'].attrs['signal'] = 1
        mon_entry['data'].attrs['axes'] = 'time_of_flight'
        # set data
        mon_entry['data'][int(tofmin): int(tofmax)] = hist.I
        continue
    return


nbanks = 38+39+38
pixelsperbank = 8 * 128
npixels = nbanks * pixelsperbank
import os
from mcvine import resources
nxs_template = os.path.join(
    resources.instrument('ARCS'), 'nxs', 'arcs-raw-events-template.nxs')
import numpy as np


# End of file 
Example #24
0
def config(Edes=20., E_min=10., E_max=30., Ortho30=False, toffset_us=-1.0, freq=180, LMS=1.8, iv=-1.0, Heusler=False, LM3S=0.72):
     
  
     
     
     
  
  from math import sqrt, pi as PI, asin
  from mcni.utils.conversion import SE2V
  import os
  
  # 
  
  M4=3.0; # 
  Mi=2.0; # 
  LG4M=0.3; #
  ih=0.0; # 
  W0=0.04;# 
  WS=0.0; #
  H0=0.15; # 
  HS=0.0; #
  
  x_mono = 0.16 ;
  L1 = 9.93 ;
  L2 = 48. * 0.501 ;
  L3 = 5.0 ;
  Rc = (0.5*L2 + L3)*L2/x_mono ;
  LMM = L1 + L2 + L3 ;
  
  GAP_T0 = 0.23 + 0.07 ;        HALF_GAP_T0 = 0.5 * GAP_T0 ;
  GAP_T1A = 0.06 ;              HALF_GAP_T1A = 0.5 * GAP_T1A ;
  GAP_T1B = 0.06 ;              HALF_GAP_T1B = 0.5 * GAP_T1B ;
  GAP_T2 = 0.24 ;               HALF_GAP_T2 = 0.5 * GAP_T2 ;
  GAP_MON = 0.0456 ;            HALF_GAP_MON = 0.5 * GAP_MON ;
  GAP_VALV = 0.08 ;             HALF_GAP_VALV = 0.5 * GAP_VALV ;
  
  L_T2_M = 2.0098 ;
  L_T1B_M = 2.7854 ;
  L_MON1_M = 3.5664 ;
  L_MON2_M = 1.4774 ;
  L_VALV_M = 3.9106 ;
  L_SHUT2_M = 4.7370 ;
  
  POS_T0 = 8.50 ;
  POS_T1A = 9.40 ;
  
  POS_G1A = 2.3203 ;      LEN_G1A = 1.8686 ;
  POS_G1B = 4.2328 ;      LEN_G1B = 2.0875 ;
  POS_G1C = 6.3203 ;      LEN_G1C = POS_T0 - HALF_GAP_T0 - POS_G1C ;
  POS_T0_T1A = POS_T0 + HALF_GAP_T0 ;
  LEN_T0_T1A = POS_T1A - POS_T0 - HALF_GAP_T1A - HALF_GAP_T0 ;
  POS_T1A_G2 = POS_T1A + HALF_GAP_T1A ;
  LEN_T1A_G2 = L1 - POS_T1A_G2 ;
  
  POS_G3 = LMM - L3 + 0.001 ;       POS_SHUT2 = LMM - L_SHUT2_M ;
  LEN_G3 = POS_SHUT2 - POS_G3 ;     LEN_SHUT2 = 0.5 ; 
  POS_VALV = LMM - L_VALV_M ;
  LEN_SHUT2_VALV = POS_VALV - POS_SHUT2 - HALF_GAP_VALV - LEN_SHUT2 ;
  POS_MON1 = LMM - L_MON1_M ;
  LEN_VALV_MON1 = POS_MON1 - POS_VALV - HALF_GAP_VALV - HALF_GAP_MON ;
  POS_T1B = LMM - L_T1B_M ;
  LEN_MON1_T1B = POS_T1B - POS_MON1 - HALF_GAP_MON - HALF_GAP_T1B ;
  POS_T2 = LMM - L_T2_M ;
  LEN_T1B_T2 = POS_T2 - POS_T1B - HALF_GAP_T1B - HALF_GAP_T2 ;
  POS_MON2 = LMM - L_MON2_M ;
  LEN_T2_MON2 = POS_MON2 - POS_T2 - HALF_GAP_T2 - HALF_GAP_MON ;
  POS_G4 = POS_MON2 + HALF_GAP_MON ;
  LEN_G4 = LMM - POS_G4 - LG4M ; 
  if (LEN_G4 <= 0.0) : LEN_G4 = 0.001 
  WA = W0 + WS * POS_G3 / (LMM + LMS - POS_G3) ; WB = WS / (LMM + LMS - POS_G3) ;
  HA = H0 + HS * POS_G3 / (LMM + LMS - POS_G3) ; HB = HS / (LMM + LMS - POS_G3) ;
  
  W1_G3 = WA ; W2_G3 = WA - WB * (POS_G3 + LEN_G3) ;
  H1_G3 = HA ; H2_G3 = HA - HB * (POS_G3 + LEN_G3) ;
  W1_SHUT2 = WA - WB * POS_SHUT2 ; W2_SHUT2 = WA - WB * (POS_SHUT2 + LEN_SHUT2) ;
  H1_SHUT2 = HA - HB * POS_SHUT2 ; H2_SHUT2 = HA - HB * (POS_SHUT2 + LEN_SHUT2) ;
  W1_SHUT2_VALV = WA - WB * (POS_SHUT2 + LEN_SHUT2) ; 
  W2_SHUT2_VALV = WA - WB * (POS_SHUT2 + LEN_SHUT2 + LEN_SHUT2_VALV) ;
  H1_SHUT2_VALV = HA - HB * (POS_SHUT2 + LEN_SHUT2) ; 
  H2_SHUT2_VALV = HA - HB * (POS_SHUT2 + LEN_SHUT2 + LEN_SHUT2_VALV) ;
  W1_VALV_MON1 = WA - WB * (POS_VALV + HALF_GAP_VALV) ; 
  W2_VALV_MON1 = WA - WB * (POS_VALV + HALF_GAP_VALV + LEN_VALV_MON1) ;
  H1_VALV_MON1 = HA - HB * (POS_VALV + HALF_GAP_VALV) ; 
  H2_VALV_MON1 = HA - HB * (POS_VALV + HALF_GAP_VALV + LEN_VALV_MON1) ;
  W1_MON1_T1B = WA - WB * (POS_MON1 + HALF_GAP_MON) ; 
  W2_MON1_T1B = WA - WB * (POS_MON1 + HALF_GAP_MON + LEN_MON1_T1B) ;
  H1_MON1_T1B = HA - HB * (POS_MON1 + HALF_GAP_MON) ; 
  H2_MON1_T1B = HA - HB * (POS_MON1 + HALF_GAP_MON + LEN_MON1_T1B) ;
  W1_T1B_T2 = WA - WB * (POS_T1B + HALF_GAP_T1B) ; 
  W2_T1B_T2 = WA - WB * (POS_T1B + HALF_GAP_T1B + LEN_T1B_T2) ;
  H1_T1B_T2 = HA - HB * (POS_T1B + HALF_GAP_T1B) ; 
  H2_T1B_T2 = HA - HB * (POS_T1B + HALF_GAP_T1B + LEN_T1B_T2) ;
  W1_T2_MON2 = WA - WB * (POS_T2 + HALF_GAP_T2) ; 
  W2_T2_MON2 = WA - WB * (POS_T2 + HALF_GAP_T2 + LEN_T2_MON2) ;
  H1_T2_MON2 = HA - HB * (POS_T2 + HALF_GAP_T2) ; 
  H2_T2_MON2 = HA - HB * (POS_T2 + HALF_GAP_T2 + LEN_T2_MON2) ;
  W1_G4 = WA - WB * POS_G4 ; W2_G4 = WA - WB * (POS_G4 + LEN_G4) ;
  H1_G4 = HA - HB * POS_G4 ; H2_G4 = HA - HB * (POS_G4 + LEN_G4) ;
  
  LSD = 4.5 ;
  
  from mcvine import resources as res
  moddatadir = os.path.join(
      res.instrument('HYSPEC'),
      'mcstas',
      )
  if Ortho30:
      sourcename= os.path.join(moddatadir, "SNS_TD_30o70p_fit_fit.dat")
  else:
      sourcename= os.path.join(moddatadir, "SNS_TD_0o100p_fit_fit.dat")
      pass
  # 
  
  if (toffset_us > -1.1 and toffset_us < -0.9):
      toffset_s = 0.3 * pow(( 1.0 + Edes ),(-0.9)) / 1000.0 
  else:
      toffset_s = toffset_us / 1000000.0 
      pass
  
  # not necessarily true
  if (Edes < 60.0) :
      freq_T0 = 30.0; 
  else:
      freq_T0 = 60.0;
      pass
  
  # 
  # 
  nos_eng = E_max - E_min ;
  if( nos_eng < 6 ): nos_eng = 100 
  nos_eng = int(nos_eng)
  
  # 
  phase_0 = POS_T0/(sqrt(Edes)*SE2V)+toffset_s;
  
  # 
  phase_1A = POS_T1A/(sqrt(Edes)*SE2V)+toffset_s;
  t_T1A_min = POS_T1A/(sqrt(E_max)*SE2V) - 0.0020 + toffset_s;
  t_T1A_max = POS_T1A/(sqrt(E_min)*SE2V) + 0.0020 + toffset_s;
  ang_freq_1A = 2.0*PI*60.0 ;
  radius_1A = 0.250 ;
  wid_1A = 0.0946 ;
  nos_t1a = int(100000. * (t_T1A_max - t_T1A_min))
  
  # 
  phase_1B = POS_T1B/(sqrt(Edes)*SE2V)+toffset_s;
  t_T1B_min = POS_T1B/(sqrt(E_max)*SE2V) - 0.0020 + toffset_s;
  t_T1B_max = POS_T1B/(sqrt(E_min)*SE2V) + 0.0020 + toffset_s;
  ang_freq_1B = 2.0*PI*60.0 ;
  radius_1B = 0.250 ;
  wid_1B = 0.0946 ;
  nos_t1b = int(100000. * (t_T1B_max - t_T1B_min))
  
  """ The T2 FermiChopper parameters:
  dist_eff - The routine uses distance & nominal velocity to set the phase angle
  vi_eff   - and we therefore have to calculate an effective distance to account
           - for the offset time. 
  """
  len = 0.01 ;   #   
  wid = 0.0006  ; #      
  nos = 77 ;     #  
  trn = 1.0  ;    #  
  barrel = 0.12 ;       
  height = 0.155 ;
  vi_eff = sqrt(Edes) * SE2V ;
  dist_eff = POS_T2 + vi_eff * toffset_s ;
  t_T2_min = (POS_T2 + HALF_GAP_T2 - 0.0004)/(sqrt(Edes)*SE2V) - 0.000125 + toffset_s;    
  t_T2_max = (POS_T2 + HALF_GAP_T2 - 0.0004)/(sqrt(Edes)*SE2V) + 0.000125 + toffset_s;
  b_radius = barrel / 2.0 ;
  b_height_min = -height / 2.0 ;
  b_height_max =  height / 2.0 ;
  nos_t2 = int(100000. * (t_T2_max - t_T2_min))
  
  # 
  t2_min = (L1 + L2)/(sqrt(E_max)*SE2V) - 0.0020 + toffset_s;    
  t2_max = (L1 + L2)/(sqrt(E_min)*SE2V) + 0.0020 + toffset_s;    
  nos_g2 = int(100000. * (t2_max - t2_min))
  
  # 
  t_mon0_min = POS_G1A /(sqrt(E_max)*SE2V) - 0.0020 + toffset_s ;    
  t_mon0_max = POS_G1A /(sqrt(E_min)*SE2V) + 0.0020 + toffset_s ;    
  nos_mon0 = int(100000. * (t_mon0_max - t_mon0_min))
  
  # 
  t_mon1_min = POS_MON1/(sqrt(E_max)*SE2V) - 0.0020 + toffset_s;    
  t_mon1_max = POS_MON1/(sqrt(E_min)*SE2V) + 0.0020 + toffset_s;    
  nos_mon1 = int(100000. * (t_mon1_max - t_mon1_min))
  
  # 
  t_mon2_min = POS_MON2/(sqrt(Edes)*SE2V) - 0.000125 + toffset_s;    
  t_mon2_max = POS_MON2/(sqrt(Edes)*SE2V) + 0.000125 + toffset_s;    
  nos_mon2 = int(100000. * (t_mon2_max - t_mon2_min))
  
  # 
  t4_min = (POS_G4 + LEN_G4)/(sqrt(Edes)*SE2V) - 0.000125 + toffset_s;    
  t4_max = (POS_G4 + LEN_G4)/(sqrt(Edes)*SE2V) + 0.000125 + toffset_s;
  nos_g4 = int(100000. * (t4_max - t4_min))
  
  # 
  t_mon3_min =(LMM + LMS - LM3S) /(sqrt(Edes)*SE2V) - 0.000125 + toffset_s;    
  t_mon3_max =(LMM + LMS -LM3S)/(sqrt(Edes)*SE2V) + 0.000125 + toffset_s;    
  nos_mon3 = int(100000. * (t_mon3_max - t_mon3_min))
  
  # 
  phasefs_min = (LMM + LMS)/(sqrt(Edes)*SE2V) - 0.0002 + toffset_s ;
  phasefs_max = (LMM + LMS)/(sqrt(Edes)*SE2V) + 0.0002 + toffset_s ;
  nos_samp = int(100000. * (phasefs_max - phasefs_min) )
  phaseff_min = (LMM + LMS + LSD)/(sqrt(Edes)*SE2V) - 0.0002 + toffset_s ;
  phaseff_max = (LMM + LMS + LSD)/(sqrt(Edes)*SE2V) + 0.0002 + toffset_s ;
  nos_det = int(100000. * (phaseff_max - phaseff_min))
  
  # 
  
  if not Heusler:
      dPG = 3.3539 ;
      m_gap = 0.0014 ;# 
      eta_h = 72.0 ; #  
      eta_v = 72.0 ; # 
      wid_h = 0.3 ;
      wid_v = 0.012 ;
      nos_h = 1 ;
      nos_v = 13 ;
  else :
      dPG = 3.43 ;
      m_gap = 0.00125 # 
      eta_h = 48.0 * 0.45 / 0.8 ;
      eta_v = 48.0 * 0.45 / 0.8 ; 
      wid_h = 0.15 ;
      wid_v = 0.015 ;
      nos_h = 1 ;
      nos_v = 9 ;
      pass
  
  # 
  WL_mean = sqrt(81.81/Edes);
  Q_m = 2.0*PI/dPG ;
  k_m = 2.0*PI/WL_mean ;
  sin_tm = Q_m / (2.0 * k_m) ;
  Cl_ang = asin(sin_tm) * 180.0/PI ;
  Al_ang = 2.0 * Cl_ang ;
  if(iv < -0.1) :
      L1V = LMM ; L2V = LMS ;
      if(iv > -1.5 and iv < -0.5): L2V = LMS ;
      if(iv > -2.5 and iv < -1.5): L2V = LMS + LSD ;
      R_vert = 2.0 * L1V * L2V * sin_tm / (L1V + L2V) ; 
      pass
  if(iv > -0.1 and iv < 0.1): R_vert = 10000.0
  if(iv > 0.1) : R_vert = iv 
  R_horz = 10000.0 ; 
  components = [arm1, source_00, Mon0_toF, Mon0_total, G1A_guide, G1B_guide, G1C_guide, T0_T1A_guide, T1A_chopper, G2_curved_guide, G3_guide, Shutter2_guide, Shutter2_valve_guide, Valve_mon1_guide, Mon1_toF, Mon1_total, Mon1_t1b_guide, T1B_chopper, T1B_T2_guide, T2_Fermi, T2_MON2_guide, Mon2_toF, Mon2_total, G4_guide, arm2, monochromator, Exit_tube, Mon3_ToF, Mon3_total, Aperture1, Soeller20, Aperture2, sample_10x10, sample_1x1, recorder()]
  from mcvine.pyre_support.pml import set_instrument_parameters, PmlRenderer
  class instrument: pass
  instrument.name='hyspec_moderator2sample'
  instrument.components=components
  set_instrument_parameters(instrument, locals())
  from mcvine.pyre_support.pml import PmlRenderer
  renderer = PmlRenderer()
  text = '\n'.join(renderer.render(instrument))
  pml = 'hyspec_moderator2sample.pml'
  open(pml, 'wt').write(text)
  return
Example #25
0
        del mon_entry['data']
        mon_entry['data'] = np.zeros(N, dtype="double")
        # set attributes
        mon_entry['data'].attrs['signal'] = 1
        mon_entry['data'].attrs['axes'] = 'time_of_flight'
        # set data
        mon_entry['data'][int(tofmin): int(tofmax)] = hist.I
        continue
    return

recorder = 19.9
sample = recorder + 0.1254
m1 = 18.26
m2 = 29.0032


bank_id_offset = 38
pixelsperbank = 8 * 128
pixel_id_offset = (bank_id_offset-1)*pixelsperbank
nbanks = 37+39+37
npixels = nbanks * pixelsperbank
import os
from mcvine import resources as res
nxs_template = os.path.join(
    res.instrument('SEQUOIA'), 'nxs',
    'sequoia-raw-events-template.nxs')
import numpy as np


# End of file 
Example #26
0
    run_sh = os.path.join(workdir, 'run.sh')
    open(run_sh, 'w').write(cmd+'\n')
    execute(cmd, workdir)
    
    # events.dat
    outfile = os.path.join(workdir, 'out', 'events.dat')
    return outfile

sd_txt = """
import mcvine
from mcvine.applications.InstrumentBuilder import build
components = ['source', 'detsys']
App = build(components)
app = App('sd')
app.run()
"""


# utils
from ...ARCS.applications.utils import execute


import numpy as np
from mcvine import resources as res
import os, subprocess as sp

#
sequoiaxml = os.path.join(
    res.instrument('SEQUOIA'), 'detsys', 'sequoia.xml.fornxs')

Example #27
0
    pulse_time = np.zeros(nevents)

    tof = events['tofChannelNo']  # XXX: tof unit?
    weights = events['p']

    return {
        'indices': indices,
        'pulse_time': pulse_time,
        'tof': tof,
        'weights': weights,
    }


import os
from mcvine import resources
nxs_template = os.path.join(resources.instrument('ARCS'), 'nxs',
                            'arcs-events-template.nxs')


def _write(path,
           indices=None,
           pulse_time=None,
           tof=None,
           tofbinsize=None,
           weights=None):
    """write "processed" ARCS nexus file given relevant data
    """
    import shutil
    shutil.copyfile(nxs_template, path)
    import time
    time.sleep(0.5)