Пример #1
0
def test_calibconst():

    DETNAME = 'tmo_quadanode'

    ds = DataSource(
        files=
        '/reg/g/psdm/detector/data2_test/xtc/data-amox27716-r0100-acqiris-e000100.xtc2'
    )
    orun = next(ds.runs())
    print('\nruninfo expt: %s  runnum: %d' % (orun.expt, orun.runnum))

    cc0 = wu.calib_constants_all_types(
        DETNAME, exp=orun.expt,
        run=orun.runnum)  # , time_sec=None, vers=None, url=cc.URL)
    print(' >>>> calib constants direct access:\n', cc0)

    det = orun.Detector(DETNAME)

    cc = det.calibconst
    print(' >>>> det.calibconst:\n', cc)

    for nev, evt in enumerate(orun.events()):
        if nev > 2: break
        print('Event %d' % nev)
        print_ndarr(det.raw.times(evt), '  times : ', last=4)
        print_ndarr(det.raw.waveforms(evt), '  wforms: ', last=4)
Пример #2
0
def issue_2020_12_19():
    """First version of det.raw.calib"""
    from psana.pyalgos.generic.NDArrUtils import print_ndarr, info_ndarr
    from psana import DataSource

    ds = DataSource(exp='ueddaq02',run=28)

    for run in ds.runs():
        print('====== run.runnum: ', run.runnum) 

        det = run.Detector('epixquad')

        print('det._det_name      : ', det._det_name) # epixquad
        print('det._dettype       : ', det._dettype)  # epix
        print('det.raw._det_name  : ', det.raw._det_name) # epixquad
        print('det.raw._dettype   : ', det.raw._dettype)  # epix
        print('det.raw._uniqueid  : ', det.raw._uniqueid)  # epix_3926196238-017....
        print('_sorted_segment_ids: ', det.raw._sorted_segment_ids) # [0, 1, 2, 3]

        for stepnum,step in enumerate(run.steps()):

          print('%s\n==== Step %1d ====' % (50*'_',stepnum))

          for evnum,evt in enumerate(step.events()):
            if evnum>2 and evnum%500!=0: continue
            print('%s\nStep %1d Event %04d' % (50*'_',stepnum, evnum))

            calib  = det.raw.calib(evt)
            ###########################
            print(info_ndarr(det.raw._pedestals(), 'peds  '))
            print(info_ndarr(det.raw.raw(evt),    'raw   '))
            print(info_ndarr(calib,               'calib '))
Пример #3
0
def issue_2020_12_10():
    """
    O'Grady, Paul Christopher <*****@*****.**>
    Thu 12/10/2020 9:37 PM
    On Dec 10, 2020, at 10:47 AM, Dubrovin, Mikhail <*****@*****.**> wrote:

    >> Detector scan_raw_2_0_0 is implemented in detector/envstore.py
    >>but I can't get anything useful from this detector. Something is still missing.

    The script below works for me for the ued epix-scan.
    At the moment I?ve forgotten why we did it with two Detectors 
    instead of putting the information into one detector 
    or the Step object (like we do with the runinfo).
    Perhaps Mona/ChrisF/Matt (cc?d) can remind me post tag-up.
    We?ve had several long discussions about this and changed it a few times ...
    my apologies for forgetting.   This time I will capture what we say here:
    https://confluence.slac.stanford.edu/pages/viewpage.action?pageId=247694685
    chris
    """
    #print('DATA FILE IS AVAILABLE ON drp-ued-cmp001 ONLY')
    #fname = '/u2/pcds/pds/ued/ueddaq02/xtc/ueddaq02-r0027-s000-c000.xtc2'

    from psana import DataSource
    ds = DataSource(exp='ueddaq02',run=28)
    #ds = DataSource(files='/reg/d/psdm/ued/ueddaq02/xtc/ueddaq02-r0027-s000-c000.xtc2')
    #detname='epixquad'
    myrun = next(ds.runs())
    step_value = myrun.Detector('step_value')
    step_docstring = myrun.Detector('step_docstring')
    for nstep,step in enumerate(myrun.steps()):
        print('step:',nstep,step_value(step),step_docstring(step))
        for nevt,evt in enumerate(step.events()):
            if nevt==3: print('evt3:',nstep,step_value(evt),step_docstring(evt))
Пример #4
0
def run_fakestep():
    # Set SMD0 and EB batch size
    os.environ['PS_SMD_N_EVENTS'] = '5'
    os.environ['PS_FAKESTEP_FLAG'] = '1'
    PS_EB_NODES = 2
    os.environ['PS_EB_NODES'] = str(PS_EB_NODES)
    batch_size = 4

    xtc_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                           'test_data', 'fakesteps')
    ds = DataSource(exp='xpptut13', run=1, dir=xtc_dir, batch_size=batch_size)
    cn_steps = 0
    cn_events = 0
    result = {'evt_per_step': [], 'n_steps': 0, 'n_events': 0}
    for r, run in enumerate(ds.runs()):
        sdet = run.Detector('motor1')
        hsd = run.Detector('hsd')
        andor = run.Detector('andor')
        for i, step in enumerate(run.steps()):
            cn_evt_per_step = 0
            for j, evt in enumerate(step.events()):
                hsd_calib = hsd.raw.calib(evt)
                andor_calib = andor.raw.calib(evt)
                cn_evt_per_step += 1
                cn_events += 1
            cn_steps += 1
            result['evt_per_step'].append(cn_evt_per_step)

    result['n_steps'] = cn_steps
    result['n_events'] = cn_events
    if rank > PS_EB_NODES or size == 1:
        print(
            f'rank:{rank} #steps:{cn_steps} #events:{cn_events} #event_per_step:{result}'
        )
    return result
Пример #5
0
def run_serial_read(n_events, batch_size=1, filter_fn=0):
    exp_xtc_dir = os.path.join(xtc_dir, '.tmp')
    os.environ['PS_SMD_N_EVENTS'] = str(n_events)
    ds = DataSource(exp='xpptut13',
                    run=1,
                    dir=exp_xtc_dir,
                    batch_size=batch_size,
                    filter=filter_fn,
                    monitor=True)
    cn_steps = 0
    cn_events = 0
    result = {'evt_per_step': [0, 0, 0], 'n_steps': 0, 'n_events': 0}
    for r, run in enumerate(ds.runs()):
        edet = run.Detector('HX2:DVD:GCC:01:PMON')
        sdet = run.Detector('motor2')
        for i, step in enumerate(run.steps()):
            cn_evt_per_step = 0
            for j, evt in enumerate(step.events()):
                cn_evt_per_step += 1
                cn_events += 1
            cn_steps += 1
            result['evt_per_step'][i] = cn_evt_per_step

    result['n_steps'] = cn_steps
    result['n_events'] = cn_events
    print(f'rank={rank} result={result}')
    return result
Пример #6
0
 def test_step_det(self):
     xtc_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                             'data-w-step.xtc2')
     ds = DataSource(files=xtc_file)
     myrun = next(ds.runs())
     det = myrun.scaninfo
     expected_det = {
         ('step_value', 'raw'): 'raw',
         ('step_docstring', 'raw'): 'raw'
     }
     assert det == expected_det
     step_v = myrun.Detector('step_value')
     step_s = myrun.Detector('step_docstring')
     for nstep, step in enumerate(myrun.steps()):
         if nstep == 0:
             assert step_v(step) == 0
             assert step_s(
                 step
             ) == '{"detname": "epixquad_0", "scantype": "pedestal", "step": 0}'
         elif nstep == 1:
             assert step_v(step) == 1
             assert step_s(
                 step
             ) == '{"detname": "epixquad_0", "scantype": "pedestal", "step": 1}'
         for nevt, evt in enumerate(step.events()):
             pass
Пример #7
0
def det_container(xtc_file):
    ds = DataSource(files=xtc_file)
    myrun = next(ds.runs())
    det = myrun.Detector('bogusdet', accept_missing=True)
    for config in det.raw._configs:
        for e in config.__dict__['bogusdet'].items():
            pass
def test_xtcav_lasing_on(args=Arguments()):

    from psana import DataSource
    from psana.xtcav.LasingOnCharacterization import LasingOnCharacterization, setDetectors
    from psana.pyalgos.generic.NDArrUtils import info_ndarr, np

    ds = DataSource(files=args.fname)
    run = next(ds.runs())

    dets = setDetectors(run)
    lon = LasingOnCharacterization(args, run, dets)

    nimgs = 0
    for nev, evt in enumerate(run.events()):

        img = dets._camraw(evt)
        print('Event %03d raw data: %s' % (nev, info_ndarr(img)))

        if img is None: continue
        if not lon.processEvent(evt): continue

        t, power, agr, pulse = lon.resultsProcessImage()
        print('%sAgreement:%7.3f%%  Max power: %g  GW Pulse Delay: %.3f ' %
              (10 * ' ', agr * 100, np.amax(power), pulse[0]))

        nimgs += 1
        if nimgs >= args.events: break
Пример #9
0
def launch_client(pid):
    dg_count = 0
    ds = DataSource(shmem='shmem_test_' + pid)
    run = next(ds.runs())
    cspad = run.Detector('xppcspad')
    hsd = run.Detector('xpphsd')
    for evt in run.events():
        if not evt:
            break
        if not evt._dgrams:
            break
        if not len(evt._dgrams):
            break
        # check for L1 accept transition ID 12
        assert (hsd.raw.calib(evt).shape == (5, ))
        assert (hsd.fex.calib(evt).shape == (6, ))
        padarray = vals.padarray
        assert (np.array_equal(cspad.raw.calib(evt),
                               np.stack((padarray, padarray))))
        assert (np.array_equal(cspad.raw.image(evt),
                               np.vstack((padarray, padarray))))
        if evt._dgrams[0].service() == 12:
            # immediately release datagram to server
            # if this "del" isn't done then the client receives fewer
            # datagrams, perhaps because the shmem buffer doesn't
            # guarantee delivery of all dgrams, but I'm not certain - cpo
            del evt._dgrams[0]
            dg_count += 1
    return dg_count
Пример #10
0
def test_standard():
    # Usecase 1a : two iterators with filter function
    ds = DataSource(exp='xpptut13',
                    run=1,
                    dir=xtc_dir,
                    filter=filter_fn,
                    batch_size=1)

    sendbuf = np.zeros(1, dtype='i')
    recvbuf = None
    if rank == 0:
        recvbuf = np.empty([size, 1], dtype='i')

    for run in ds.runs():
        det = run.Detector('xppcspad')
        edet = run.Detector('HX2:DVD:GCC:01:PMON')
        infodet = run.Detector('epicsinfo')
        for evt in run.events():
            sendbuf += 1
            padarray = vals.padarray
            assert (np.array_equal(
                det.raw.calib(evt),
                np.stack((padarray, padarray, padarray, padarray))))
            assert evt._size == 2  # check that two dgrams are in there
            assert edet(evt) is None or edet(evt) == 41.0

    comm.Gather(sendbuf, recvbuf, root=0)
    if rank == 0:
        assert np.sum(
            recvbuf) == 10  # need this to make sure that events loop is active
Пример #11
0
def test_py2xtc(tmp_path):

    config = {}
    detname = 'spi_cspad'
    dettype = 'cspad'
    serial_number = '1234'
    namesid = 0

    nameinfo = dc.nameinfo(detname, dettype, serial_number, namesid)
    alg = dc.alg('raw', [1, 2, 3])

    cydgram = dc.CyDgram()

    image_array = np.array([[1, 2, 3, 4], [9, 8, 7, 6]])
    orientations_array = np.array([4, 3, 2, 1])

    runinfo_detname = 'runinfo'
    runinfo_dettype = 'runinfo'
    runinfo_detid = ''
    runinfo_namesid = 1
    runinfo_nameinfo = dc.nameinfo(runinfo_detname, runinfo_dettype,
                                   runinfo_detid, runinfo_namesid)
    runinfo_alg = dc.alg('runinfo', [0, 0, 1])
    runinfo_data = {'expt': 'xpptut15', 'runnum': 14}

    fname = os.path.join(tmp_path, 'junk.xtc2')

    f = open(fname, 'wb')
    for i in range(4):
        my_data = {
            'image': image_array + i,
            'orientations': orientations_array + i
        }

        cydgram.addDet(nameinfo, alg, my_data)
        # only do this for the first two dgrams: name info for config, and
        # the runinfo data for beginrun
        if i < 2: cydgram.addDet(runinfo_nameinfo, runinfo_alg, runinfo_data)
        timestamp = i
        if (i == 0):
            transitionid = 2  # Configure
        elif (i == 1):
            transitionid = 4  # BeginRun
        else:
            transitionid = 12  # L1Accept
        xtc_bytes = cydgram.get(timestamp, transitionid)
        f.write(xtc_bytes)
    f.close()

    from psana import DataSource
    ds = DataSource(files=fname)
    myrun = next(ds.runs())
    assert myrun.expt == runinfo_data['expt']
    assert myrun.runnum == runinfo_data['runnum']
    for nevt, evt in enumerate(myrun.events()):
        assert np.array_equal(evt._dgrams[0].spi_cspad[0].raw.image,
                              image_array + nevt + 2)
        assert np.array_equal(evt._dgrams[0].spi_cspad[0].raw.orientations,
                              orientations_array + nevt + 2)
    assert nevt > 0  #make sure we get events
Пример #12
0
def test_callback(batch_size):
    ds = DataSource(exp='xpptut13',
                    run=1,
                    dir=xtc_dir,
                    filter=filter_fn,
                    destination=destination,
                    batch_size=batch_size)

    sendbuf = np.zeros(1, dtype='i')
    recvbuf = None
    if rank == 0:
        recvbuf = np.empty([size, 1], dtype='i')

    for run in ds.runs():
        det = run.Detector('xppcspad')
        edet = run.Detector('HX2:DVD:GCC:01:PMON')
        for step in run.steps():
            for evt in step.events():
                sendbuf += 1
                padarray = vals.padarray
                assert (np.array_equal(
                    det.raw.calib(evt),
                    np.stack((padarray, padarray, padarray, padarray))))
                assert evt._size == 2  # check that two dgrams are in there

    comm.Gather(sendbuf, recvbuf, root=0)
    if rank == 0:
        assert np.sum(
            recvbuf) == 10  # need this to make sure that events loop is active
Пример #13
0
def getLasingOffShot(lon, fname_loff):
    results=lon._pulse_characterization
    loff = lon._lasingoffreference
    ibunch = 0

    group = results.groupnum[ibunch]
    profs = loff.averaged_profiles

    ds = DataSource(files=fname_loff)
    run = next(ds.runs())

    print('XXXX dir(run)', dir(run))
    print('XXXX max_events', run.max_events)
    print('XXXX esm', run.esm)
    print('XXXX timestamp', run.timestamp)
    print('XXXX dm', run.dm)
    print('XXXX smd_dm', run.smd_dm)
    #====================
    sys.exit('TEST EXIT')
    #====================

    camera = run.Detector(cons.DETNAME)
    camraw = xtup.get_attribute(camera,'raw')

    #LCLS1 stuff does not work here
    #times = run.times()
    #time = profs.eventTime[ibunch][group]
    #fid = profs.eventFid[ibunch][group]
    #et = EventTime(int(time),int(fid))
    #evt_loff = run.event(et)

    if camraw is None:
        print('No lasing off image found for unixtime',time,'and fiducials',fid)
    print('Found lasing off shot in run',loff.parameters.run)
    return camraw(evt_loff)
Пример #14
0
def test_opal_data_access() :
    tname = sys.argv[1] if len(sys.argv) > 1 else '0'

    print('DIRECT ACCESS CALIBRATION CONSTANTS')

    from psana.pscalib.calib.MDBWebUtils import calib_constants
    data, doc = calib_constants('ele_opal_1234', exp='amox27716', ctype='pop_rbfs', run=85)
    print('direct consatnts access meta:\n', doc)
    print('\ndirect consatnts access data:')
    for k,v in data.items() : print_ndarr(v, '%03d : '%k)

    print('DETECTOR INTERFACE ACCESS CALIBRATION CONSTANTS')

    ds = DataSource(files='/reg/g/psdm/detector/data2_test/xtc/data-amox27716-r0085-opal1k.xtc2')
    orun = next(ds.runs())
    camera = orun.Detector('opal')

    print('test_xtcav_data    expt: %s runnum: %d\n' % (orun.expt, orun.runnum))

    for nev,evt in enumerate(orun.events()):
        if nev>10 : break
        print('Event %03d'%nev, end='')
        ####print_ndarr(camera.raw.array(evt), '  camera.raw.array(evt):')
        #print_ndarr(camera.img(evt), '  camera.img(evt):')
        #print('XXXXX', evt._dgrams[0].xtcav[0].raw.raw)
        #print('XXXXX', dir(evt._dgrams[0].opal[0].raw.img))

        print('***',camera.raw.image(evt))
        break

    calib_data, calib_meta = camera.calibconst.get('pop_rbfs')
    print('camera.calibconst.get   calib_meta', calib_meta)
Пример #15
0
def issue_2022_01_26():
    """The same as issue_2022_01_21 but for run 10, print ndarray, access constants.
    """
    from psana.detector.NDArrUtils import info_ndarr
    from psana import DataSource
    ds = DataSource(exp='tmoc00318',run=10)
    orun = next(ds.runs())
    det = orun.Detector('epix100')

    print('dir(det.raw):', dir(det.raw))
    print()
    print(info_ndarr(det.raw._pedestals(),   'det.raw._pedestals()  '))
    print(info_ndarr(det.raw._gain(),        'det.raw._gain()'))
    print(info_ndarr(det.raw._rms(),         'det.raw._rms()'))
    print(info_ndarr(det.raw._status(),      'det.raw._status()'))
    print(info_ndarr(det.raw._mask_calib(),  'det.raw._mask_calib()'))
    print(info_ndarr(det.raw._mask_from_status(),  'det.raw._mask_from_status()'))
    print(info_ndarr(det.raw._mask_edges(),  'det.raw._mask_edges()'))
    print(info_ndarr(det.raw._common_mode(), 'det.raw._common_mode()'))
    #print(info_ndarr(det.raw.,   'det.raw.'))
    print(info_ndarr(det.raw._pixel_coords(do_tilt=True, cframe=0), 'det.raw._pixel_coords(...)'))

    print()

    for nevt,evt in enumerate(orun.events()):
        if nevt>10:
            print('event loop is terminated by maximal number of events')
            break
        print(info_ndarr(det.raw.raw(evt),   'det.raw.raw(evt)  '))
        print(info_ndarr(det.raw.calib(evt), 'det.raw.calib(evt)'))
Пример #16
0
def run_serial_read(n_events, batch_size=1, filter_fn=0):
    exp_xtc_dir = os.path.join(xtc_dir, '.tmp')
    os.environ['PS_SMD_N_EVENTS'] = str(n_events)
    timestamps = np.array([4294967300, 4294967303, 4294967305, 4294967311, \
            4294967317, 4294967318, 4294967319, 4294967321, 4294967322, \
            4294967337, 4294967338, 4294967339, 4294967340, 4294967342, 4294967343], dtype=np.uint64)
    ds = DataSource(exp='xpptut13',
                    run=1,
                    dir=exp_xtc_dir,
                    batch_size=batch_size,
                    filter=filter_fn,
                    monitor=True,
                    timestamps=timestamps)
    cn_steps = 0
    cn_events = 0
    result = {'evt_per_step': [0, 0, 0], 'n_steps': 0, 'n_events': 0}
    for r, run in enumerate(ds.runs()):
        edet = run.Detector('HX2:DVD:GCC:01:PMON')
        sdet = run.Detector('motor2')
        for i, step in enumerate(run.steps()):
            cn_evt_per_step = 0
            for j, evt in enumerate(step.events()):
                cn_evt_per_step += 1
                cn_events += 1
            cn_steps += 1
            result['evt_per_step'][i] = cn_evt_per_step

    result['n_steps'] = cn_steps
    result['n_events'] = cn_events
    return result
Пример #17
0
def main():
    limit = int(os.environ['LIMIT']) if 'LIMIT' in os.environ else None

    data_dir = os.environ['DATA_DIR']
    ds = DataSource(exp='junk',
                    run=1,
                    dir=data_dir,
                    max_events=limit,
                    det_name='spi_cspad')
    # Note: DataSource doesn't seem to care about max_events when given
    # a filename.

    n_runs = 0
    runs = []
    for run in ds.runs():
        # FIXME: must epoch launch
        data_collector.load_run_data(run)
        # Right now, we assume one run or a serie of runs with the same
        # experimental configuration.

        n_runs += 1

        runs.append(
            run)  # Keep run around to avoid having it be garbage collected.

    solver.solve(n_runs)

    legion.execution_fence(
        block=True)  # Block to keep runs in scope until solve completes.
Пример #18
0
 def find_event(self, exp_run_event):
     """exp_run_event: contain experiment number, run number and event
     number
     'exp=xppj1216:run=17:event=0' or 'exp=xppj1216:run=17:event=rayonix,0'
     """
     fields = []
     event_number = nan
     detector_name = ""
     for f in exp_run_event.split(':'):
         if f.startswith("event="):
             detector_event = f.replace("event=", "")
             if "," in detector_event:
                 detector_name = ",".join(detector_event.split(",")[0:-1])
                 event_number = int(detector_event.split(",")[-1])
             else:
                 event_number = int(detector_event)
         else:
             fields += [f]
     exp_run = ":".join(fields)
     if exp_run != self.exp_run or detector_name != self.detector_name \
         or event_number < self.event_number:
         start = time()
         try:
             from psana import DataSource
             self.ds = DataSource(exp_run)
             self.es = self.ds.env().epicsStore()
         except Exception, msg:
             error('Failed to open datasource: %s: %s' % (exp_run, msg))
             return None
         self.exp_run = exp_run
         self.event_number = -1
         self.serial_number = -1
         self.detector_name = detector_name
         debug('Opened %r in %g seconds' % (exp_run, time() - start))
Пример #19
0
def detnames(xtc_file):
    ds = DataSource(files=xtc_file)
    myrun = next(ds.runs())

    assert ('xppcspad', 'cspad', 'raw', '2_3_42') in myrun.xtcinfo
    assert myrun.epicsinfo[('HX2:DVD:GCC:01:PMON', 'raw')] == 'raw'
    assert myrun.scaninfo[('motor1', 'raw')] == 'raw'
Пример #20
0
    def starting_time(self, exp_run):
        """exp_run: contains experiment number, run number, e.g.
        'exp=xppj1216:run=17'"""
        from tempfile import gettempdir
        from pickle import load, dump

        if self.starting_times == {}:
            try:
                self.starting_times = load(
                    file(gettempdir() + "/datastream.starting_times.pkl"))
            except:
                pass

        if exp_run in self.starting_times:
            return self.starting_times[exp_run]
        from psana import DataSource, EventId
        try:
            ds = DataSource(exp_run)
            for event in ds.events():
                s, ns = event.get(EventId).time()
                t = s + ns * 1e-9
                debug("%s: %s" % (exp_run, date_time(t)))
                break
        except Exception, msg:
            debug("%s: %s" % (exp_run, msg))
            t = nan
Пример #21
0
def mixedrate(batch_size=1):
    # Test mixed rate detectors
    xtc_mixedrate_dir = os.path.join(
        os.path.dirname(os.path.realpath(__file__)), 'test_data', 'mixed_rate')
    ds = DataSource(exp='xpptut15', run=1, dir=xtc_mixedrate_dir, batch_size=1)
    sendbuf = np.zeros(1, dtype='i')
    recvbuf = None
    if rank == 0:
        recvbuf = np.empty([size, 1], dtype='i')

    for run in ds.runs():
        det = run.Detector('xppcspad')
        edet = run.Detector('HX2:DVD:GCC:01:PMON')
        for evt in run.events():
            sendbuf += 1
            assert evt._size == 2  # both test files have xppcspad
            if evt._nanoseconds < 30:  # first SlowUpdate is ts 30
                assert edet(evt) is None
            else:
                assert edet(evt) == 41.0

    comm.Gather(sendbuf, recvbuf, root=0)
    if rank == 0:
        assert np.sum(
            recvbuf
        ) == 100  # need this to make sure that events loop is active
Пример #22
0
def test_hsd():
    dir_path = os.path.dirname(os.path.realpath(__file__))
    ds = DataSource(files=os.path.join(dir_path, 'test_hsd.xtc2'))

    myrun = next(ds.runs())
    det = myrun.Detector('xpphsd')

    for nevt, evt in enumerate(myrun.events()):
        wfs = det.hsd.waveforms(evt)
        fex = det.hsd.peaks(evt)
        nwf = 0
        for digitizer, wf in wfs.items():
            times = wfs[digitizer]['times']
            assert np.array_equal(times, np.arange(1600))
            for channel, waveform in wf.items():
                if type(channel) is int:  # skip over the 'times'
                    assert len(waveform) == len(times)
                    nwf += 1
        assert nwf == 1
        nfex = 0
        for digitizer, fexdata in fex.items():
            for channel, fexchan in fexdata.items():
                starttimes, peaks = fexchan
                # for this test-pattern data there is only one peak found: the
                # entire waveform starting at time 0.
                assert np.array_equal(peaks[0], waveform)
                assert len(starttimes) == 1
                assert starttimes[0] == 0
                nfex += 1
        assert nfex == 1
    assert (nevt == 3)
Пример #23
0
def procEvents(args):

    fname = getattr(
        args, 'fname',
        '/reg/g/psdm/detector/data2_test/xtc/data-amox23616-r0137-e000100-xtcav-v2.xtc2'
    )
    max_shots = getattr(args, 'max_shots', 200)
    mode = getattr(args, 'mode', 'smd')

    ds = DataSource(files=fname)
    run = next(ds.runs())

    dets = setDetectors(
        run)  # NEEDS IN camera, ebeam, gasdetecto, eventid, xtcavpars
    lon = LasingOnCharacterization(args, run, dets)

    nimgs = 0
    for nev, evt in enumerate(run.events()):

        img = dets._camraw(evt)
        logger.info('Event %03d' % nev)
        logger.debug(info_ndarr(img, 'camera raw:'))
        if img is None: continue

        if not lon.processEvent(evt): continue

        t, power, agr, pulse = lon.resultsProcessImage()
        print('%sAgreement:%7.3f%%  Max power: %g  GW Pulse Delay: %.3f ' %
              (12 * ' ', agr * 100, np.amax(power), pulse[0]))

        nimgs += 1
        if nimgs >= max_shots:
            break
Пример #24
0
def test_hsd_padonly():
    dir_path = os.path.dirname(os.path.realpath(__file__))
    ds = DataSource(files=os.path.join(dir_path, 'test_hsd.xtc2'))

    myrun = next(ds.runs())
    det = myrun.Detector('xpphsd')

    for nevt, evt in enumerate(myrun.events()):
        pad = det.hsd.padded(evt)

        # make sure we return None if there are no entries
        if not pad: assert pad is None

        if pad:
            for ndigi, (digitizer, wfsdata) in enumerate(pad.items()):
                times = wfsdata['times']
                nwf = 0
                for channel, waveform in wfsdata.items():
                    if type(channel) is int:  # skip over the 'times'
                        nwf += 1
                        assert len(waveform) == len(times)
                assert nwf == 1, nwf  # counting from one
            assert ndigi == 1, ndigi  # enumerate counting from zero
        if nevt == 20:
            break  # stop early since this xtc file has incomplete dg
    assert (nevt > 0)  # make sure we received events
Пример #25
0
def test_timetool_psana(plot=False):
    dir_path = os.path.dirname(os.path.realpath(__file__))
    ds = DataSource(files=os.path.join(dir_path, 'test_timetool_psana.xtc2'))

    myrun = next(ds.runs())
    det = myrun.Detector('tmott')
    edge_finder = EdgeFinder(det.calibconst)
    edet = myrun.Detector('IIR')

    # TODO: Add first pass get all the backgrounds

    # Second pass - finding edges from given backgrounds and good image
    for nevt, evt in enumerate(myrun.events()):
        image = det.ttalg.image(evt)

        if image is None: continue
        result = edge_finder(image, edet(evt))

        if plot:
            plt.plot(image / np.max(image), label="signal")
            plt.plot(result.convolved, label="convolution result")
            plt.plot(result.edge, result.amplitude, "x")
            plt.hlines(*result.results_half[1:], color="C2")
            plt.title(
                f'edge_pos={result.edge:d} fwhm={result.fwhm:.2f} ampl={result.amplitude:.2f} ampl_next={result.amplitude_next:.2f} ref_ampl={result.ref_amplitude:.2f}'
            )
            plt.legend()
            plt.xlabel('pixel number')
            plt.ylabel('normalized signal')
            plt.show()

    assert nevt == 1324
Пример #26
0
def test_output(h5data):
    """Compares known data (saved to hdf5 by the push process) with read data."""
    pixel_position_reciprocal = h5data['pixel_position_reciprocal']
    pixel_index_map = h5data['pixel_index_map']
    intensities = h5data['intensities']

    n_test_events = 3
    ds = DataSource(files='out.xtc2')
    run = next(ds.runs())
    det = run.Detector('amopnccd')
    xtc2_pixel_position_reciprocal = run.beginruns[0].scan[
        0].raw.pixel_position_reciprocal
    xtc2_pixel_index_map = run.beginruns[0].scan[0].raw.pixel_index_map
    data_array = np.zeros([n_test_events, 1, 128, 128], dtype=np.float32)

    for i, evt in enumerate(run.events()):
        if i == n_test_events: break
        data_array[i, :, :, :] = det.raw.calib(evt)

    assert np.array_equal(intensities[:n_test_events][:], data_array)
    assert np.array_equal(pixel_position_reciprocal,
                          xtc2_pixel_position_reciprocal)
    assert np.array_equal(pixel_index_map, xtc2_pixel_index_map)

    print('TEST SUCCESS')
Пример #27
0
def issue_2020_11_24():
    from psana import DataSource
    import numpy as np
    ds = DataSource(exp='tmolw0618',run=52)
    myrun = next(ds.runs())
    det = myrun.Detector('tmoopal')
    print(det.calibconst)
Пример #28
0
def issue_2022_03_16():
    """Uervirojnangkoorn, Monarin <*****@*****.**> Wed 3/16/2022 12:25 PM
    Hi Mikhail, I mentioned that I tried to use calibcfg and calibtab for amox27716 run 85.
    I can see the contents of both variables from det.calibconst but they are (I believe)
    not compatible for DLDProcess.
    Here?s the script that works (this script uses calibcfg and calibtab from txt files)
    /cds/home/m/monarin/psana-nersc/psana2/dgrampy/ex-01-conv-raw-to-fex-wf.py
    If you uncomment line 144 (kwargs.update(cc)), you will see the error that I showed earlier.
    The cc has calibcfg and calibtab contents.
    My question is Is there a way to pass calibcfg and calibtab contents instead of the file paths.
    Thank you in advance!
    Mona
    """
    from psana import DataSource

    ds    = DataSource(files='/reg/g/psdm/detector/data2_test/xtc/data-amox27716-r0100-acqiris-e001000.xtc2')
    orun  = next(ds.runs())
    det   = orun.Detector('tmo_quadanode')
    cc    = det.calibconst

    print('cc.keys():', cc.keys())
    for k in cc.keys():
        data, meta = cc[k]
        print(k, 'meta:\n', meta)
        print(k, 'type(data):\n', type(data))
        print(k, 'data[:500]:\n', data[:500])
Пример #29
0
def issue_2020_12_16():
    """Chriss access to config does not work, Matts' works """
    from psana.pyalgos.generic.NDArrUtils import print_ndarr
    from psana import DataSource
    ds = DataSource(files='/cds/data/psdm/ued/ueddaq02/xtc/ueddaq02-r0027-s000-c000.xtc2')
    detname = 'epixquad'

    for orun in ds.runs():
      print('run.runnum: %d detnames: %s expt: %s' % (orun.runnum, str(orun.detnames), orun.expt))

      det = orun.Detector(detname)
      print('det.raw._det_name: %s' % det.raw._det_name) # epixquad
      print('det.raw._dettype : %s' % det.raw._dettype)  # epix

      scfg = None
      for config in det._configs:
          if not detname in config.__dict__:
              print('Skipping config {:}'.format(config.__dict__))
              continue
          scfg = getattr(config,detname)

      for nstep, step in enumerate(orun.steps()):
          print('\n==== step:%02d' %nstep)

          print('DOES NOT WORK')
          for k,v in det.raw._seg_configs().items():
              cob = v.config
              print_ndarr(cob.asicPixelConfig, 'seg:%02d trbits: %s asicPixelConfig:'%(k, str(cob.trbit)))

          print('WORKS')
          for k,v in scfg.items():
              cob = v.config
              print_ndarr(cob.asicPixelConfig, 'seg:%02d trbits: %s asicPixelConfig:'%(k, str(cob.trbit)))
Пример #30
0
def test_mask(tname):
    """
    """
    from psana import DataSource
    ds = DataSource(exp='uedcom103',
                    run=7,
                    dir='/cds/data/psdm/prj/public01/xtc')
    orun = next(ds.runs())
    det = orun.Detector('epixquad')  # epixquad is replaced by epix10ka_000002
    peds, meta = det.calibconst['pedestals']
    logger.info('\nmetadata\n', meta)
    logger.info(info_ndarr(peds, '\npedestals'))

    mask = test_mask_select(tname, det)  # [0,:]

    #sys.exit('TEST EXIT')

    evt = next(orun.events())

    arr = mask + 1

    logger.info(info_ndarr(arr, '\ntest_mask arr for image'))

    img = det.raw.image(evt, nda=arr)
    logger.info(info_ndarr(img, '\nimg'))

    flimg = ug.fleximagespec(img, arr=arr, amin=0, amax=2)
    #   else: flimg.update(img)#, arr=arr)
    flimg.axtitle(title='test_mask %s' % tname)
    #   ug.gr.show(mode='NO HOLD')
    ug.gr.show()