Ejemplo n.º 1
0
    def test01(ntest, prefix='fig-v01'):
        """Test for radial 1-d binning of entire image.
    """
        from time import time
        import psana.pyalgos.generic.Graphics as gg
        from psana.pscalib.geometry.GeometryAccess import img_from_pixel_arrays

        arr, geo = data_geo(ntest)

        t0_sec = time()
        iX, iY = geo.get_pixel_coord_indexes()
        X, Y, Z = geo.get_pixel_coords()
        mask = geo.get_pixel_mask(mbits=0o377).flatten()
        print('Time to retrieve geometry %.3f sec' % (time() - t0_sec))

        t0_sec = time()
        hp = HPolar(X, Y, mask, nradbins=500, nphibins=1)  # v1
        print('HPolar initialization time %.3f sec' % (time() - t0_sec))

        t0_sec = time()
        nda, title = arr, None
        if ntest == 1: nda, title = arr, 'averaged data'
        elif ntest == 2: nda, title = hp.pixel_rad(), 'pixel radius value'
        elif ntest == 3: nda, title = hp.pixel_phi(), 'pixel phi value'
        elif ntest == 4:
            nda, title = hp.pixel_irad() + 2, 'pixel radial bin index'
        elif ntest == 5:
            nda, title = hp.pixel_iphi() + 1, 'pixel phi bin index'
        elif ntest == 6:
            nda, title = hp.pixel_iseq(
            ) + 2, 'pixel sequential (rad and phi) bin index'
        elif ntest == 7:
            nda, title = mask, 'mask'
        elif ntest == 8:
            nda, title = hp.pixel_avrg(nda), 'averaged radial intensity'
        elif ntest == 9:
            nda, title = hp.pixel_avrg_interpol(
                arr) * mask, 'interpolated radial intensity'
        else:
            print('Test %d is not implemented' % ntest)
            return

        print('Get %s n-d array time %.3f sec' % (title, time() - t0_sec))

        img = img_from_pixel_arrays(
            iX, iY, nda) if not ntest in (21, ) else nda[100:300, :]

        da, ds = None, None
        colmap = 'jet'  # 'cubehelix' 'cool' 'summer' 'jet' 'winter'
        if ntest in (2, 3, 4, 5, 6, 7):
            da = ds = (nda.min() - 1., nda.max() + 1.)

        else:
            ave, rms = nda.mean(), nda.std()
            da = ds = (ave - 2 * rms, ave + 3 * rms)

        gg.plotImageLarge(img,
                          amp_range=da,
                          figsize=(14, 12),
                          title=title,
                          cmap=colmap)
        gg.save('%s-%02d-img.png' % (prefix, ntest))

        gg.hist1d(nda, bins=None, amp_range=ds, weights=None, color=None, show_stat=True, log=False, \
               figsize=(6,5), axwin=(0.18, 0.12, 0.78, 0.80), \
               title=None, xlabel='Pixel value', ylabel='Number of pixels', titwin=title)
        gg.save('%s-%02d-his.png' % (prefix, ntest))

        gg.show()

        print('End of test for %s' % title)
Ejemplo n.º 2
0
    def test03(ntest, prefix='fig-v01'):
        """Test for 2-d binning of the restricted rad-phi range of entire image
    """
        from time import time
        import psana.pyalgos.generic.Graphics as gg
        from psana.pscalib.geometry.GeometryAccess import img_from_pixel_arrays

        arr, geo = data_geo(ntest)

        iX, iY = geo.get_pixel_coord_indexes()
        X, Y, Z = geo.get_pixel_coords()
        mask = geo.get_pixel_mask(mbits=0o377).flatten()

        t0_sec = time()

        #hp = HPolar(X, Y, mask, nradbins=5, nphibins=8, phiedges=(-20, 240), radedges=(10000,80000))
        hp = HPolar(X,
                    Y,
                    mask,
                    nradbins=3,
                    nphibins=8,
                    phiedges=(240, -20),
                    radedges=(80000, 10000))  # v3

        print('HPolar initialization time %.3f sec' % (time() - t0_sec))

        #print('bin_number_of_pixels:',   hp.bin_number_of_pixels())
        #print('bin_intensity:', hp.bin_intensity(arr))
        #print('bin_avrg:',   hp.bin_avrg(arr))

        t0_sec = time()
        nda, title = arr, None
        if ntest == 41: nda, title = arr, 'averaged data'
        elif ntest == 44:
            nda, title = hp.pixel_irad() + 2, 'pixel radial bin index'
        elif ntest == 45:
            nda, title = hp.pixel_iphi() + 2, 'pixel phi bin index'
        elif ntest == 46:
            nda, title = hp.pixel_iseq(
            ) + 2, 'pixel sequential (rad and phi) bin index'
            #elif ntest == 47: nda, title = mask,                  'mask'
        elif ntest == 48:
            nda, title = hp.pixel_avrg(
                nda, subs_value=180), 'averaged radial intensity'
        elif ntest == 49:
            nda, title = hp.pixel_avrg_interpol(
                nda,
                verb=True) * mask, 'averaged radial interpolated intensity'
        elif ntest == 50:
            nda, title = hp.bin_avrg_rad_phi(nda), 'r-phi'
        else:
            print('Test %d is not implemented' % ntest)
            return

        print('Get %s n-d array time %.3f sec' % (title, time() - t0_sec))

        img = img_from_pixel_arrays(
            iX, iY, nda) if not ntest in (50, ) else nda  # [100:300,:]

        colmap = 'jet'  # 'cubehelix' 'cool' 'summer' 'jet' 'winter' 'gray'

        da = (nda.min() - 1, nda.max() + 1)
        ds = da

        if ntest in (41, 48, 49, 50):
            ave, rms = nda.mean(), nda.std()
            da = ds = (ave - 2 * rms, ave + 3 * rms)

        gg.plotImageLarge(img,
                          amp_range=da,
                          figsize=(14, 12),
                          title=title,
                          cmap=colmap)
        gg.save('%s-%02d-img.png' % (prefix, ntest))

        gg.hist1d(nda, bins=None, amp_range=ds, weights=None, color=None, show_stat=True, log=False, \
               figsize=(6,5), axwin=(0.18, 0.12, 0.78, 0.80), \
               title=None, xlabel='Pixel value', ylabel='Number of pixels', titwin=title)
        gg.save('%s-%02d-his.png' % (prefix, ntest))

        gg.show()

        print('End of test for %s' % title)