예제 #1
0
    def test_01():
        from psana.pyalgos.generic.NDArrGenerators import random_standard

        print('%s\n%s\n' % (80 * '_', 'Test method subtract_bkgd(...):'))
        shape1 = (32, 185, 388)
        winds = [(s, 10, 155, 20, 358) for s in (0, 1)]
        data = random_standard(shape=shape1, mu=300, sigma=50)
        bkgd = random_standard(shape=shape1, mu=100, sigma=10)
        cdata = subtract_bkgd(data, bkgd, mask=None, winds=winds, pbits=0o377)
예제 #2
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))
예제 #3
0
def test01():
    """imshow"""
    img = random_standard(shape=(40, 60), mu=200, sigma=25)
    fig, axim = fig_img_axes()
    move_fig(fig, x0=50, y0=20)
    imsh = imshow(axim, img, amp_range=None, extent=None,\
           interpolation='nearest', aspect='auto', origin='upper',\
           orientation='horizontal', cmap='jet')
예제 #4
0
파일: Utils.py 프로젝트: slac-lcls/lcls2
    def test_10():
        from psana.pyalgos.generic.NDArrGenerators import random_standard

        image = random_standard()
        verbosity = True
        save_image_tiff(image, fname='image.tiff', verb=verbosity)
        save_image_file(image, fname='image.png', verb=verbosity)
        save_image_file(image, fname='image.xyz', verb=verbosity)
예제 #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)
예제 #6
0
def unitest_entropy():
    import sys
    from psana.pyalgos.generic.NDArrGenerators import random_standard
    print('In %s' % sys._getframe().f_code.co_name)
    np.random.seed(42)
    arr_int16 = random_standard(shape=(100000,), mu=200, sigma=25, dtype=np.int16)
    ent1 = entropy(arr_int16);
    print('entropy(arr_int16) = %.6f' % ent1)
    assert('%.6f'%ent1 == '6.690948')
예제 #7
0
파일: Graphics.py 프로젝트: monarin/lcls2
def test02() :
    """ hist
    """
    mu, sigma = 200, 25
    arr = random_standard((500,), mu, sigma)
    #fig = figure(figsize=(6,5), title='Test hist', dpi=80, facecolor='w', edgecolor='w', frameon=True, move=(100,10))    
    #axhi = add_axes(fig, axwin=(0.10, 0.08, 0.85, 0.88))
    fig, axhi = fig_img_axes()
    his = hist(axhi, arr, bins=100, amp_range=(mu-6*sigma,mu+6*sigma), weights=None, color=None, log=False)
예제 #8
0
def test01():
    """ imshow
    """
    img = random_standard(shape=(40, 60), mu=200, sigma=25)
    #fig = figure(figsize=(6,5), title='Test imshow', dpi=80, facecolor='w', edgecolor='w', frameon=True, move=(100,10))
    #axim = add_axes(fig, axwin=(0.10, 0.08, 0.85, 0.88))
    fig, axim = fig_img_axes()
    move_fig(fig, x0=200, y0=100)
    imsh = imshow(axim, img, amp_range=None, extent=None,\
           interpolation='nearest', aspect='auto', origin='upper',\
           orientation='horizontal', cmap='jet')
예제 #9
0
 def test_serialize_dict():
     d = {'val':123,
          'nda1': aranged_array(shape=(3,4), dtype=np.int),
          'nda2': random_standard(shape=(2,3), mu=100, sigma=10, dtype=np.float)
         }
     print('initial dict:')
     print_dict(d)
     serialize_dict(d)
     print(80*'_')
     print('serialized dict:')
     print_dict(d)
     print(80*'_')
     deserialize_dict(d)
     print('deserialized dict:')
     print_dict(d)
     print(80*'_')
예제 #10
0
파일: Graphics.py 프로젝트: monarin/lcls2
def test04() :
    """ Update histogram in the event loop
    """
    mu, sigma = 200, 25
    #fig = figure(figsize=(6,5), title='Test hist', dpi=80, facecolor='w', edgecolor='w', frameon=True, move=(100,10))
    #axhi = add_axes(fig, axwin=(0.10, 0.08, 0.85, 0.88))
    fig, axhi = fig_img_axes()

    for i in range(10) :
       print('Event %3d' % i)
       arr = random_standard((500,), mu, sigma, dtype=np.float)
       axhi.cla()
       set_win_title(fig, 'Event %d' % i)
       his = hist(axhi, arr, bins=100, amp_range=(mu-6*sigma,mu+6*sigma), weights=None, color=None, log=False)

       show(mode=1) # !!!!!!!!!!
예제 #11
0
def image_with_random_peaks(shape=(500, 500), add_water_ring=True):
    img = random_standard(shape, mu=0, sigma=10)
    if add_water_ring:
        rad = 0.3 * shape[0]
        sigm = rad / 4
        add_ring(img,
                 amp=20,
                 row=shape[0] / 2,
                 col=shape[1] / 2,
                 rad=rad,
                 sigma=sigm)
    peaks = add_random_peaks(img,
                             npeaks=10,
                             amean=100,
                             arms=50,
                             wmean=1.5,
                             wrms=0.3)
    return img, peaks
예제 #12
0
def test05():
    """ Update image with color bar in the event loop
    """
    fig, axim, axcb = fig_img_cbar_axes()
    move_fig(fig, x0=200, y0=0)
    imsh = None
    for i in range(20):
        print('Event %3d' % i)
        img = random_standard((1000, 1000), mu=i, sigma=10)
        #axim.cla()
        set_win_title(fig, 'Event %d' % i)
        if imsh is None:
            imsh, cbar = imshow_cbar(fig, axim, axcb, img, amin=None, amax=None, extent=None,\
                                     interpolation='nearest', aspect='auto', origin='upper',\
                                     orientation='vertical', cmap='inferno')
        else:
            imsh.set_data(img)
            ave, rms = img.mean(), img.std()
            imsh.set_clim(ave - 1 * rms, ave + 3 * rms)
        show(mode=1)  # !!!!!!!!!!
예제 #13
0
def test03():
    """ Update image in the event loop
    """
    #fig = figure(figsize=(6,5), title='Test hist', dpi=80, facecolor='w', edgecolor='w', frameon=True, move=(100,10))
    #axim = add_axes(fig, axwin=(0.10, 0.08, 0.85, 0.88))
    fig, axim = fig_img_axes()
    imsh = None
    for i in range(10):
        print('Event %3d' % i)
        img = random_standard((1000, 1000), mu=200, sigma=25)
        #axim.cla()
        set_win_title(fig, 'Event %d' % i)

        if imsh is None:
            imsh = imshow(axim, img, amp_range=None, extent=None,\
                   interpolation='nearest', aspect='auto', origin='upper',\
                   orientation='horizontal', cmap='jet')
        else:
            imsh.set_data(img)
        show(mode=1)  # !!!!!!!!!!
예제 #14
0
    def test_08():
        import psana.pyalgos.generic.Graphics as gg
        from psana.pyalgos.generic.NDArrGenerators import random_standard
        from psana.pyalgos.generic.NDArrUtils import reshape_to_2d

        print('%s\n%s\n' %
              (80 * '_', 'Test method locxymax(nda, order, mode):'))
        #data = random_standard(shape=(32,185,388), mu=0, sigma=10)
        data = random_standard(shape=(2, 185, 388), mu=0, sigma=10)
        t0_sec = time()
        mask = locxymax(data, order=1, mode='clip')
        print('Consumed t = %10.6f sec' % (time() - t0_sec))

        if True:
            img = data if len(data.shape) == 2 else reshape_to_2d(data)
            msk = mask if len(mask.shape) == 2 else reshape_to_2d(mask)

            ave, rms = img.mean(), img.std()
            amin, amax = ave - 2 * rms, ave + 2 * rms
            gg.plotImageLarge(img, amp_range=(amin, amax), title='random')
            gg.plotImageLarge(msk, amp_range=(0, 1), title='mask loc max')
            gg.show()
예제 #15
0
def test06():
    """ fig_img_cbar
    """
    img = random_standard((1000, 1000), mu=100, sigma=10)
    fig, axim, axcb, imsh, cbar = fig_img_cbar(img)  #, **kwa)
    move_fig(fig, x0=200, y0=0)
예제 #16
0
 def test_02():
     from psana.pyalgos.generic.NDArrGenerators import random_standard
     shape1 = (32, 185, 388)
     data = random_standard(shape=shape1, mu=300, sigma=50)
     print(info_ndarr(data, 'test_02: info_ndarr', first=0, last=3))
     print(info_ndarr(shape1, 'test_02: info_ndarr'))
예제 #17
0
def test07():
    """ r-phi fig_img_proj_cbar
    """
    img = random_standard((200, 200), mu=100, sigma=10)
    fig, axim, axcb, imsh, cbar = fig_img_proj_cbar(img)
    move_fig(fig, x0=200, y0=0)