Exemple #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)
Exemple #2
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)))
Exemple #3
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)
Exemple #4
0
def test_entropy():

    print('In %s' % sys._getframe().f_code.co_name)

    from psana.pyalgos.generic.NDArrGenerators import random_standard
    from psana.pyalgos.generic.NDArrUtils import print_ndarr
    from time import time

    arr_float = random_standard(shape=(100000, ),
                                mu=200,
                                sigma=25,
                                dtype=np.float)
    arr_int16 = arr_float.astype(np.int16)

    print_ndarr(arr_int16, name='arr_int16', first=0, last=10)

    t0_sec = time()
    ent1 = entropy(arr_int16)
    t1_sec = time()
    ent2 = entropy_v1(arr_int16)
    t2_sec = time()
    ent3 = entropy_cpo(arr_int16)
    t3_sec = time()

    print('entropy(arr_int16)     = %.6f, time=%.6f sec' %
          (ent1, t1_sec - t0_sec))
    print('entropy_v1(arr_int16)  = %.6f, time=%.6f sec' %
          (ent2, t2_sec - t1_sec))
    print('entropy_cpo(arr_int16) = %.6f, time=%.6f sec' %
          (ent3, t3_sec - t2_sec))
Exemple #5
0
 def test_serialize_numpy_array():
   nda = random_standard(shape=(4,6), mu=100, sigma=10, dtype=np.float32)
   #nda = aranged_array(shape=(2,3), dtype=np.float) # uint32)
   print_ndarr(nda, 'nda', first=0, last=12)
   d = serialize_numpy_array(nda)
   print('serialize_numpy_array: %s' % d)
   nda2 = deserialize_numpy_array(d)
   print_ndarr(nda, 'de-serialized nda', first=0, last=12)
Exemple #6
0
 def test_calib_constants():
     det = 'cspad_0001'
     data, doc = calib_constants('cspad_0001',
                                 exp='cxic0415',
                                 ctype='pedestals',
                                 run=50,
                                 time_sec=None,
                                 vers=None)  #, url=cc.URL)
     print_ndarr(data, '==== test_calib_constants', first=0, last=5)
     print('==== doc: %s' % str(doc))
def test_02():
    from ndarray import test_nda_fused_v2
    print(50 * '_', '\nTest of templated function test_nda_fused_v2')
    nda = np.arange(0, 10, 1, dtype=np.int32)
    nda.shape = (2, 5)
    #print('XXXXXXX type(nda.shape[0]) :', type(nda.shape[0]))

    print('dir(nda):', dir(nda))
    print('nda.strides:', nda.strides)

    print_ndarr(nda, '  nda in : ', first=0, last=10)
    test_nda_fused_v2(nda)
    print_ndarr(nda, '  nda out: ', first=0, last=10)
def proc_data(**kwargs):

    logger.info(str_kwargs(kwargs, title='Input parameters:'))

    IFNAME = kwargs.get(
        'ifname',
        '/reg/g/psdm/detector/data_test/hdf5/amox27716-r0100-e060000-single-node.h5'
    )
    EVSKIP = kwargs.get('evskip', 0)
    EVENTS = kwargs.get('events', 10) + EVSKIP
    OFPREFIX = kwargs.get('ofprefix', './')
    VERBOSE = kwargs.get('verbose', False)

    proc = DLDProcessor(**kwargs)
    stats = DLDStatistics(proc, **kwargs)

    f = open_input_h5file(IFNAME, **kwargs)
    print('  file: %s\n  number of events in file %d' %
          (IFNAME, f.events_in_h5file()))

    t0_sec = time()
    nev = 0
    while f.next_event():
        nev = f.event_number()

        if nev < EVSKIP: continue
        if nev > EVENTS: break

        if do_print(nev): logger.info('Event %3d' % nev)

        nhits, pktsec = f.peak_arrays()

        if VERBOSE:
            print_ndarr(nhits, '  number_of_hits: ')
            print_ndarr(pktsec, '  peak_times_sec: ', last=4)

        proc.event_proc(nev, nhits, pktsec)

        stats.fill_data(nhits, pktsec)

        if VERBOSE:
            for i, (x, y, r,
                    t) in enumerate(proc.xyrt_list(nev, nhits, pktsec)):
                print('    hit:%2d x:%7.3f y:%7.3f t:%10.5g r:%7.3f' %
                      (i, x, y, t, r))

    dt = time() - t0_sec
    print('%d events processing time = %.3f sec or %.6f sec/event or %.3f Hz' %
          (nev, dt, dt / nev, nev / dt))

    draw_plots(stats, prefix=OFPREFIX, do_save=True, hwin_x0y0=(0, 10))
Exemple #9
0
def test02():
    import psalg_ext
    import numpy as np
    from psana.pyalgos.generic.NDArrUtils import print_ndarr
    print('test numpy.array')

    af8 = np.ones((5, 5), dtype=np.float64)
    print_ndarr(af8, 'input array ')
    #psalg_ext.test_nda_f8(af8)
    #psalg_ext.test_nda_v1(af8)
    #print_ndarr(af8, 'output array')

    ai2 = np.ones((6, 3), dtype=np.int16)
    print_ndarr(ai2, 'input array ')
def test_06():
    print(50 * '_', '\nTest of wfpkfinder_cfd')
    from ndarray import wfpkfinder_cfd
    from ex_wf import WF  # local import
    #print(WF)
    #wf  = np.arange(0, 20, 1, dtype=np.double)
    wf = np.array(WF, dtype=np.double)
    pkvals = np.zeros((10, ), dtype=np.double)
    pkinds = np.zeros((10, ), dtype=np.uint32)
    baseline, threshold, fraction, deadtime, leading_edges = 0, -5, 0.5, 0, True
    npks = wfpkfinder_cfd(wf, baseline, threshold, fraction, deadtime,
                          leading_edges, pkvals, pkinds)
    print('  npks: %d' % npks)
    print_ndarr(pkvals, '  values : ')
    print_ndarr(pkinds, '  times  : ')
Exemple #11
0
def image_with_random_peaks(shape=(500, 500)):
    from psana.pyalgos.generic.NDArrUtils import print_ndarr

    print('XXX1 shape:', shape)
    img = ag.random_standard(shape, mu=0, sigma=10)
    print_ndarr(img, 'XXX ag.random_standard')

    peaks = ag.add_random_peaks(img,
                                npeaks=50,
                                amean=100,
                                arms=50,
                                wmean=1.5,
                                wrms=0.3)
    ag.add_ring(img, amp=20, row=500, col=500, rad=300, sigma=50)
    return img
Exemple #12
0
def test_xtcav_data_access():
    tname = sys.argv[1] if len(sys.argv) > 1 else '0'

    ds = DataSource(files=data_file(tname))
    orun = next(ds.runs())
    det = orun.Detector('xtcav')

    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(det.raw.array(evt), '  det.raw.array(evt):')
        print_ndarr(det.raw(evt), '  det.raw(evt):')
Exemple #13
0
def draw_waveforms(wfs, wts, nev):
    """Draws all waveforms on figure axes, one waveform per axis.
       Parameters:
       - wfs [np.array] shape=(NUM_CHANNELS, NUM_SAMPLES) - waveform intensities
       - wts [np.array] shape=(NUM_CHANNELS, NUM_SAMPLES) - waveform times
    """
    t0_sec = time()

    #======== peak-finding algorithm ============
    #wfs, wts = array_of_selected_channels(wfs), array_of_selected_channels(wts)
    nhits, pkinds, pkvals, pktsec = peaks(wfs, wts)
    pkinds, pkvals = peaks.peak_indexes_values(wfs, wts)  # massaging for V4

    dt_sec = time() - t0_sec
    wfssel, wtssel = peaks.waveforms_preprocessed(
        wfs, wts)  # selected time range and subtracted offset
    thr = peaks.THR

    #============================================

    print_ndarr(wtssel, '  wtssel: ', last=4)
    print('  wf processing time(sec) = %8.6f' % dt_sec)
    print_ndarr(nhits, '  nhits : ', last=10)
    print_ndarr(pkinds, '  pkinds: ', last=4)
    print_ndarr(pktsec, '  pktsec: ', last=4)
    print_ndarr(pkvals, '  pkvals: ', last=4)

    for ch in range(naxes):
        ax[ch].clear()
        ax[ch].set_xlim(time_range_sec)
        ax[ch].set_ylabel(ylab[ch], fontsize=14)

        # draw waveform
        ax[ch].plot(wtssel[ch], wfssel[ch], gfmt[ch], linewidth=lw)

        # draw line for threshold level
        gr.drawLine(ax[ch],
                    ax[ch].get_xlim(), (thr, thr),
                    s=10,
                    linewidth=1,
                    color='k')

        # draw lines for peak times
        draw_times(ax[ch], pkvals[ch], pkinds[ch], wtssel[ch])

    gr.set_win_title(fig, 'Event: %d' % nev)
    gr.draw_fig(fig)
    gr.show(mode='non-hold')
def proc_data(**kwargs):

    DSNAME       = kwargs.get('dsname', '/reg/g/psdm/detector/data2_test/xtc/data-amox27716-r0100-acqiris-e000100.xtc2')
    DETNAME      = kwargs.get('detname','tmo_hexanode')
    NUM_CHANNELS = kwargs.get('numchs', 5)
    NUM_HITS     = kwargs.get('numhits', 16)
    EVSKIP       = kwargs.get('evskip', 0)
    EVENTS       = kwargs.get('events', 10) + EVSKIP
    EXP          = kwargs.get('exp', 'amox27716')
    RUN          = kwargs.get('run', 100)
    OFPREFIX     = kwargs.get('ofprefix','./')
    ofname       = '%s%s-r%04d-e%06d-single-node.h5' % (OFPREFIX, EXP, int(RUN), EVENTS)

    tname = sys.argv[1] if len(sys.argv) > 1 else '1'
    print('TEST %s' % tname)

    logger.info(str_kwargs(kwargs, title='Input parameters:'))

    peaks = WFPeaks(**kwargs)
    ofile = open_output_h5file(ofname, peaks, **kwargs)

    ds = DataSource(files=DSNAME)
    orun = next(ds.runs())
    det = orun.Detector(DETNAME)

    for nevt,evt in enumerate(orun.events()):
        if nevt<EVSKIP : continue
        if nevt>EVENTS : break
        print('Event %3d'%nevt)
        wts = det.raw.times(evt)
        wfs = det.raw.waveforms(evt)

        t0_sec = time()

        # ACCESS FOR TEST 1:
        if tname == '1' :
            nhits, pkinds, pkvals, pktns = peaks(wfs,wts)

        # ALTERNATIVE ACCESS:
        else :
            peaks.proc_waveforms(wfs, wts) 
            nhits  = peaks.number_of_hits(wfs, wts)
            pktns  = peaks.peak_times_ns(wfs, wts)
            pkvals = peaks.peak_values(wfs, wts)
            pkinds = peaks.peak_indexes(wfs, wts)

        print("  waveforms processing time = %.6f sec" % (time() - t0_sec))
        print_ndarr(wfs,   '  waveforms      : ', last=4)
        print_ndarr(nhits, '  number_of_hits : ')
        print_ndarr(wts,   '  times          : ', last=4)
        print_ndarr(pktns, '  peak_times_ns  : ', last=4)

        ofile.add_event_to_h5file()

    print('\n',usage())
    sys.exit('TEST %s EXIT' % tname)
def save_constants_in_file(tname, fname='0-end.txt'):
    if tname == '0':
        nda, ctype = delayed_denom()
        print_ndarr(nda, 'nda for ctype: %s' % ctype)
        save_txt(fname, nda, cmts=(), fmt='%d', verbos=True, addmetad=True)
        cmd = 'cdb add -e tmo -d tmott -c %s -r 1 -f %s -u dubrovin' % (ctype,
                                                                        fname)

    elif tname == '1':
        d, ctype = fir_coefficients()
        print('dict:', d)
        save_textfile(str(d), fname, mode='w', verb=True)
        cmd = 'cdb add -e tmo -d tmott -c %s -r 1 -f %s -i txt -u dubrovin' % (
            ctype, fname)

    msg = 'DO NOT FORGET ADD CONSTS TO DB: %s' % cmd
    print(msg)
def test_xtcav_data_access():
    tname = sys.argv[1] if len(sys.argv) > 1 else '0'

    #fig, axim = fig_axis()
    fig, axim, axcb = gr.fig_img_cbar_axes(fig=None,\
             win_axim=(0.05,  0.05, 0.87, 0.93),\
             win_axcb=(0.923, 0.05, 0.02, 0.93)) #, **kwargs)

    ds = DataSource(files=data_file(tname))
    orun = next(ds.runs())
    det = orun.Detector('xtcav')

    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='')

        nda = det.raw(evt)
        print_ndarr(nda, '  det.raw(evt):')

        mean, std = nda.mean(), nda.std()
        aran = (mean - 3 * std, mean + 5 * std)

        axim.clear()
        axcb.clear()

        imsh = gr.imshow(axim, nda, amp_range=aran, extent=None, interpolation='nearest',\
                         aspect='auto', origin='upper', orientation='horizontal', cmap='inferno')
        cbar = gr.colorbar(fig,
                           imsh,
                           axcb,
                           orientation='vertical',
                           amp_range=aran)

        gr.set_win_title(fig, 'Event: %d' % nev)
        gr.draw_fig(fig)
        gr.show(mode='non-hold')

    gr.save_fig(
        fig,
        prefix='./img-%s-r%04d-e%06d-' % (orun.expt, orun.runnum, nev),
        suffix='.png',
    )
    gr.show()
def test_xtc2_runinfo():
    from psana.pyalgos.generic.NDArrUtils import print_ndarr

    from psana import DataSource
    ds = DataSource(files=FNAME_XTC2)
    orun = next(ds.runs())

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

    det = orun.Detector(DETNAME)
    #print('dir(det)', dir(det))

    for nev, evt in enumerate(orun.events()):
        if nev > 10: break
        print('Event %d' % nev, end='')
        print_ndarr(det.raw.array(evt), '  raw:')
Exemple #18
0
def proc_data(**kwargs):

    logger.info(str_kwargs(kwargs, title='Input parameters:'))

    DSNAME = kwargs.get(
        'dsname',
        '/reg/g/psdm/detector/data2_test/xtc/data-amox27716-r0100-acqiris-e000100.xtc2'
    )
    DETNAME = kwargs.get('detname', 'tmo_quadanode')
    EVSKIP = kwargs.get('evskip', 0)
    EVENTS = kwargs.get('events', 100) + EVSKIP
    OFPREFIX = kwargs.get('ofprefix', './')
    VERBOSE = kwargs.get('verbose', False)

    ds = DataSource(files=DSNAME)
    orun = next(ds.runs())
    det = orun.Detector(DETNAME)

    kwargs['consts'] = det.calibconst

    peaks = WFPeaks(**kwargs)
    proc = DLDProcessor(**kwargs)
    stats = DLDStatistics(proc, **kwargs)

    for nev, evt in enumerate(orun.events()):
        if nev < EVSKIP: continue
        if nev > EVENTS: break

        if do_print(nev): logger.info('Event %3d' % nev)
        t0_sec = time()

        wts = det.raw.times(evt)
        wfs = det.raw.waveforms(evt)

        nhits, pkinds, pkvals, pktsec = peaks(wfs, wts)

        if VERBOSE:
            print("  waveforms processing time = %.6f sec" % (time() - t0_sec))
            print_ndarr(wfs, '  waveforms     : ', last=4)
            print_ndarr(wts, '  times         : ', last=4)
            print_ndarr(nhits, '  number_of_hits: ')
            print_ndarr(pktsec, '  peak_times_sec: ', last=4)

        proc.event_proc(nev, nhits, pktsec)

        stats.fill_data(nhits, pktsec)

        if VERBOSE:
            for i, (x, y, r,
                    t) in enumerate(proc.xyrt_list(nev, nhits, pktsec)):
                print('    hit:%2d x:%7.3f y:%7.3f t:%10.5g r:%7.3f' %
                      (i, x, y, t, r))

    draw_plots(stats, prefix=OFPREFIX, do_save=True, hwin_x0y0=(0, 10))
Exemple #19
0
def test_data_from_hdf5(**kwargs):

    IFNAME = kwargs['ifname']
    EVSKIP = kwargs['evskip']
    EVENTS = kwargs['events'] + EVSKIP

    f = open_input_h5file(IFNAME, **kwargs)

    print('  file: %s\n  number of events in file %d' %
          (IFNAME, f.events_in_h5file()))

    while f.next_event():
        evnum = f.event_number()

        if evnum < EVSKIP: continue
        if evnum > EVENTS: break
        print('Event %3d' % evnum)
        print_ndarr(f.number_of_hits(), '  number_of_hits:')
        print_ndarr(f.tdc_ns(), '  peak_times_ns: ', last=4)
def test_xtc2_runinfo():
    from psana.pyalgos.generic.NDArrUtils import print_ndarr

    from psana import DataSource
    ds = DataSource(files=FNAME_XTC2)
    orun = next(ds.runs())

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

    det = orun.Detector(DETNAME)

    for nev, evt in enumerate(orun.events()):
        if nev > 100: break
        print('Event %d' % nev)
        if getattr(det, 'raw', None) is None:
            print('    --- ev:%d det has no attribute raw...' % nev)
            continue
        print_ndarr(det.raw.times(evt), '  times : ', last=4)
        print_ndarr(det.raw.waveforms(evt), '  wforms: ', last=4)
def test_pfv4r3(tname):

    print('test_pfv4r3: %s' % {
        '4': '2-d np.array',
        '5': '3-d np.array',
        '6': 'list of 2-d np.array'
    }[tname])

    data = None
    mask = None

    sh = (1000, 1000) if tname == '4' else (32, 185, 388)  # (4,512,512)

    mu, sigma = 0, 25
    data = np.array(mu + sigma * np.random.standard_normal(sh),
                    dtype=np.double)
    mask = np.ones(sh, dtype=np.uint16)

    if tname == '6':
        data = [data[i, :, :] for i in range(sh[0])]
        mask = [mask[i, :, :] for i in range(sh[0])]

    #print 'data object', str(data)
    #print 'mask object', str(mask)
    #print 'data[0].shape', data[0].shape
    print_ndarr(data, 'input data')
    print_ndarr(mask, 'input mask')

    t0_sec = time()
    peaks = peaks_droplet(data, mask, thr_low=50, thr_high=80, rank=5, r0=7.0, dr=2.0,\
                          npix_min=1, npix_max=None, amax_thr=0, atot_thr=0, son_min=5.5)

    print('peaks_droplet: img.shape=%s consumed time = %.6f(sec)' %
          (str(sh), time() - t0_sec))

    for p in peaks:
        #print dir(p)
        print('  seg:%4d, row:%4d, col:%4d, npix:%4d, son:%4.1f' %
              (p.seg, p.row, p.col, p.npix, p.son))
Exemple #22
0
def proc_data(**kwargs):

    logger.info(str_kwargs(kwargs, title='Input parameters:'))

    DSNAME = kwargs.get(
        'dsname',
        '/reg/g/psdm/detector/data2_test/xtc/data-amox27716-r0100-acqiris-e001000.xtc2'
    )
    DETNAME = kwargs.get('detname', 'tmo_quadanode')
    EVSKIP = kwargs.get('evskip', 0)
    EVENTS = kwargs.get('events', 10) + EVSKIP
    EXP = kwargs.get('exp', 'amox27716')
    RUN = kwargs.get('run', 100)
    VERBOSE = kwargs.get('verbose', False)
    OFPREFIX = kwargs.get('ofprefix', './')
    ofname = '%s%s-r%04d-e%06d-ex-22_lowerthresh.h5' % (OFPREFIX, EXP,
                                                        int(RUN), EVENTS)

    peaks = WFPeaks(**kwargs)
    ofile = open_output_h5file(ofname, peaks, **kwargs)

    ds = DataSource(files=DSNAME)
    orun = next(ds.runs())
    det = orun.Detector(DETNAME)

    for nev, evt in enumerate(orun.events()):

        if nev < EVSKIP: continue
        if nev > EVENTS: break

        if do_print(nev): logger.info('Event %4d' % nev)
        t0_sec = time()

        wts = det.raw.times(evt)
        wfs = det.raw.waveforms(evt)

        nhits, pkinds, pkvals, pktsec = peaks(wfs, wts)  # ACCESS TO PEAK INFO

        if VERBOSE:
            print("  ev:%4d waveforms processing time = %.6f sec" %
                  (nev, time() - t0_sec))
            print_ndarr(wfs, '    waveforms      : ', last=4)
            print_ndarr(wts, '    times          : ', last=4)
            print_ndarr(nhits, '    number_of_hits : ')
            print_ndarr(pktsec, '    peak_times_sec : ', last=4)

        ofile.add_event_to_h5file()
Exemple #23
0
def proc_data(**kwargs):

    logger.info(str_kwargs(kwargs, title='Input parameters:'))

    DSNAME = kwargs.get(
        'dsname',
        '/reg/g/psdm/detector/data2_test/xtc/data-amox27716-r0100-acqiris-e000100.xtc2'
    )
    DETNAME = kwargs.get('detname', 'tmo_quadanode')
    EVSKIP = kwargs.get('evskip', 0)
    EVENTS = kwargs.get('events', 10) + EVSKIP
    VERBOSE = kwargs.get('verbose', False)

    ds = DataSource(files=DSNAME)
    orun = next(ds.runs())

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

    det = orun.Detector(DETNAME)
    #kwargs['detobj'] = det
    kwargs['consts'] = det.calibconst

    peaks = WFPeaks(**kwargs)
    proc = DLDProcessor(**kwargs)  #detobj=det to get cfg/calib constants

    for nev, evt in enumerate(orun.events()):
        if nev < EVSKIP: continue
        if nev > EVENTS: break

        if do_print(nev): logger.info('Event %3d' % nev)
        t0_sec = time()

        wts = det.raw.times(evt)
        wfs = det.raw.waveforms(evt)

        nhits, pkinds, pkvals, pktsec = peaks(wfs, wts)  # ACCESS TO PEAK INFO

        if VERBOSE:
            print("  waveforms processing time = %.6f sec" % (time() - t0_sec))
            print_ndarr(wfs, '  waveforms      : ', last=4)
            print_ndarr(wts, '  times          : ', last=4)
            print_ndarr(nhits, '  number_of_hits : ')
            print_ndarr(pktsec, '  peak_times_sec : ', last=4)

        for i, (x, y, r, t) in enumerate(proc.xyrt_list(nev, nhits, pktsec)):
            print('    hit:%2d x:%7.3f y:%7.3f t:%10.5g r:%7.3f' %
                  (i, x, y, t, r))
Exemple #24
0
    def test_insert_many(tname):
        """Insert many documents in loop
    """
        client, expname, detname, db_exp, db_det, fs_exp, fs_det, col_exp, col_det =\
            connect(host=cc.HOST, port=cc.PORT, experiment='cxi12345', detector='camera-0-cxids1-0', verbose=True)

        t_data = 0
        nloops = 10

        for i in range(nloops):
            logger.info('%s\nEntry: %4d' % (50 * '_', i))
            data = get_test_nda()
            print_ndarr(data, 'data nda')

            t0_sec = time()
            id_data_exp, id_data_det, id_exp, id_det = insert_data_and_two_docs(data, fs_exp, fs_det, col_exp, col_det,\
                 experiment=expname, detector=detname, ctype='pedestals', time_sec=str(int(time())), run='10', verbose=True)

            #id_data = insert_data(nda, fs)
            dt_sec = time() - t0_sec
            t_data += dt_sec
            logger.info('Insert data in %s id_data: %s time %.6f sec ' %
                        (fs, id_data, dt_sec))

            #doc = docdic(nda, id_data, experiment=expname, detector=detname, run='10', ctype='pedestals')
            #print_doc_keys(doc)

            #t0_sec = time()
            #idd_exp = insert_document(doc, col_exp)
            #idd_det = insert_document(doc, col_det)
            #dt_sec = time() - t0_sec
            #t_doc += dt_sec
            #logger.info('Insert 2 docs %s, %s time %.6f sec' % (idd_exp, idd_det, dt_sec))

        logger.info('Average time to insert data and two docs: %.6f sec' %
                    (t_data / nloops))
def test_03():
    print(50 * '_', '\nTest of py_ctest_vector')
    from ndarray import py_ctest_vector

    nda1 = np.arange(0, 10, 1, dtype=np.double)
    nda2 = np.arange(1, 10, 1, dtype=np.float32)
    nda3 = np.arange(10, 1, -1, dtype=np.int32)
    nda4 = np.ones((5, ), dtype=np.double)

    py_ctest_vector(nda1)
    py_ctest_vector(nda2)
    py_ctest_vector(nda3)
    py_ctest_vector(nda4)

    print_ndarr(nda1, '  nda1: ')
    print_ndarr(nda2, '  nda2: ')
    print_ndarr(nda3, '  nda3: ')
    print_ndarr(nda4, '  nda4: ')
Exemple #26
0
def do_work():

    prefix = './%s-figs-ti_vs_tj' % gu.str_tstamp(
        fmt='%Y-%m-%d', time_sec=None)  # '%Y-%m-%dT%H:%M:%S%z'
    gu.create_directory(prefix, mode=0o775)

    path = os.path.abspath(os.path.dirname(__file__))
    print('path to npy flies dir:', path)

    ti_vs_tj = np.load('%s/ti_vs_tj.npy' % path)
    t_all = np.load('%s/t_all.npy' % path)

    trange = (1400., 2900.)

    print_ndarr(ti_vs_tj, 'ti_vs_tj:\n')
    print_ndarr(t_all, 't_all:\n')

    sum_bkg = t_all.sum()
    sum_cor = ti_vs_tj.sum()

    print('sum_bkg:', sum_bkg)
    print('sum_cor:', sum_cor)

    imrange = trange + trange  # (1400., 2900., 1400., 2900.)
    axim = gr.plotImageLarge(ti_vs_tj, img_range=imrange, amp_range=(0,500), figsize=(11,10),\
                             title='ti_vs_tj', origin='lower', window=(0.10, 0.08, 0.88, 0.88), cmap='inferno')
    gr.save('%s/fig-ti_vs_tj.png' % prefix)

    bkg = np.outer(t_all, t_all) / sum_bkg
    print_ndarr(bkg, 'bkg:\n')
    axim = gr.plotImageLarge(bkg, img_range=imrange, amp_range=(0,500), figsize=(11,10),\
                             title='bkg', origin='lower', window=(0.10, 0.08, 0.88, 0.88), cmap='inferno')
    gr.save('%s/fig-ti_vs_tj-bkg.png' % prefix)

    harr = t_all
    nbins = harr.size
    ht = HBins(trange, nbins, vtype=np.float32)  # ht.binedges()
    fig, axhi, hi = gr.hist1d(ht.bincenters(), bins=nbins, amp_range=ht.limits(), weights=harr, color='b', show_stat=True,\
                              log=True, figsize=(7,6), axwin=(0.10, 0.10, 0.88, 0.85), title='1-d bkg',\
                              xlabel='time of all hits (ns)', ylabel='number of hits', titwin='1-d bkg')
    gr.save('%s/fig-time-hits.png' % prefix)
    gr.show()
Exemple #27
0
         bins=nbins,
         weights=sig_wfg * 0.005,
         color='g',
         histtype='step',
         **kwargs)

cond_wfg_sb = np.absolute(wfg) < THRD
sb_wfg = np.select([
    cond_wfg_sb,
], [
    ones_wf,
], default=0)
#ax2.hist(t, bins=nbins, weights=sb_wfg*0.01, color='r', histtype='step', **kwargs)

inds = np.nonzero(sig_wfg)[0]  # index selects 1st dimension in tuple
print_ndarr(inds, "ZZZZ inds")

grinds = split_consecutive(inds)
print_ndarr(grinds, "ZZZZ argwhere")

for i, group in enumerate(grinds):
    print('gr:%02d range:%04d-%04d size:%04d' %
          (i, group[0], group[-1], len(group)))
    pt = group[-1] + binmin
    gr.drawLine(ax2, (pt, pt), (0, -THRD), s=10, linewidth=3, color='r')
    #gr.drawLine(ax2, (pt,pt), (0,wff[p]), s=10, linewidth=1, color='r')

#----------

ax3.set_ylabel('cumsum')
#sig_wfg_only = np.select([cond_wfg_sb,], [zeros_wf,], default=1)
Exemple #28
0
#!/usr/bin/env python
#----------
"""- loop over events of psana dataset (xtc2 file) and 
   - print raw acqiris waveforms and associated sample times
"""

from psana import DataSource
from psana.pyalgos.generic.NDArrUtils import print_ndarr

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

for nev, evt in enumerate(orun.events()):
    if nev > 10: break
    print('Event %d' % nev)
    print_ndarr(det.raw.times(evt), '  times : ', last=4)
    print_ndarr(det.raw.waveforms(evt), '  wforms: ', last=4)

#----------
Exemple #29
0
def proc_data(**kwargs):

    DSNAME = kwargs.get(
        'dsname',
        '/reg/g/psdm/detector/data2_test/xtc/data-amox27716-r0100-acqiris-e000100.xtc2'
    )
    DETNAME = kwargs.get('detname', 'tmo_quadanode')
    EVSKIP = kwargs.get('evskip', 0)
    EVENTS = kwargs.get('events', 10) + EVSKIP
    VERBOSE = kwargs.get('verbose', False)

    ds = DataSource(files=DSNAME)
    orun = next(ds.runs())

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

    det = orun.Detector(DETNAME)
    kwargs['consts'] = det.calibconst

    peaks = WFPeaks(**kwargs)
    HF = HitFinder(kwargs)

    xs = np.empty([
        0,
    ])
    ys = np.empty([
        0,
    ])
    ts = np.empty([
        0,
    ])
    sm = {
        'u': np.empty([
            0,
        ]),
        'v': np.empty([
            0,
        ])
    }
    sb = {
        'u': np.empty([
            0,
        ]),
        'v': np.empty([
            0,
        ])
    }

    for nev, evt in enumerate(orun.events()):

        if nev < EVSKIP: continue
        if nev > EVENTS: break

        t0_sec = time()

        wts = det.raw.times(evt)
        wfs = det.raw.waveforms(evt)

        nhits, pkinds, pkvals, pktsec = peaks(wfs, wts)  # ACCESS TO PEAK INFO
        pktsec = pktsec * 1e9
        if VERBOSE:
            print("  waveforms processing time = %.6f sec" % (time() - t0_sec))
            print_ndarr(wfs, '  waveforms      : ', last=4)
            print_ndarr(wts, '  times          : ', last=4)
            print_ndarr(nhits, '  number_of_hits : ')
            print_ndarr(pktsec, '  peak_times_sec : ', last=4)

        HF.FindHits(pktsec[4, :nhits[4]], pktsec[0, :nhits[0]],
                    pktsec[1, :nhits[1]], pktsec[2, :nhits[2]],
                    pktsec[3, :nhits[3]])
        xs1, ys1, ts1 = HF.GetXYT()
        xs = np.concatenate([xs, xs1], axis=0)
        ys = np.concatenate([ys, ys1], axis=0)
        ts = np.concatenate([ts, ts1], axis=0)

        print(str(nev) + 'th event in 950 total events')

    xbins = np.linspace(-50, 50, 200)
    tbins = np.linspace(1500, 4000, 1250)
    plt.figure()

    plt.subplot(121)
    xy, _, _ = np.histogram2d(xs, ys, bins=[xbins, xbins])
    im = plt.imshow(xy + 1,
                    extent=[xbins[0], xbins[-1], xbins[0], xbins[-1]],
                    norm=LogNorm(vmin=1, vmax=xy.max() + 1))
    ax = plt.gca()
    divider = make_axes_locatable(ax)
    cax = divider.append_axes("right", size="5%", pad=0.05)
    plt.colorbar(im, cax=cax)
    ax.set_title('X - Y')
    ax.set_xlabel('X (mm)')
    ax.set_ylabel('Y (mm)')

    plt.subplot(122)
    ht, _ = np.histogram(ts, bins=tbins)
    plt.plot(tbins[:-1], ht)
    plt.title('Time of Flight')
    plt.xlabel('T (ns)')
    plt.ylabel('Yield (arb. units)')

    plt.tight_layout()
    plt.show()
Exemple #30
0
 def test_get_data_for_docid():
     id_doc, id_data, dbname, colname = test_get_random_doc_and_data_ids(
         det='cspad_0001')
     o = get_data_for_docid(dbname, colname, id_doc)
     #o = get_data_for_docid('cdb_cxid9114', 'cspad_0001', '5b6cdde71ead144f115319be')
     print_ndarr(o, 'test_get_data_for_docid o:', first=0, last=10)