예제 #1
0
def remove_etaloning(bkfree, psfree, etalon):
    if type(psfree) is None.__class__:
        psfree = bkfree

    if type(etalon) is not None.__class__:
        etmn1 = np.squeeze(np.mean(np.mean(etalon.s1[:, :, :, :], 1), 0))
        etmn2 = np.squeeze(np.mean(np.mean(etalon.s2[:, :, :, :], 1), 0))

        [a, b, c, d] = bkfree.s1.shape

        bkfrees1 = bkfree.s1
        bkfrees2 = bkfree.s2
        psfrees1 = psfree.s1
        psfrees2 = psfree.s2

        etalonfree1 = np.full((a, b, c, d), 0, dtype='float')
        etalonfree2 = np.full((a, b, c, d), 0, dtype='float')
        etalonSumfree1 = np.full((a, b, c, d), 0, dtype='float')
        etalonSumfree2 = np.full((a, b, c, d), 0, dtype='float')

        sgetmn1 = sg_filt(etmn1, window_length=7, polyorder=3)
        sgetmn2 = sg_filt(etmn2, window_length=7, polyorder=3)

        for ai in range(0, a):
            for bi in range(0, b):
                for ci in range(0, c):
                    etalonfree1[ai, bi, ci, :] = (np.squeeze(
                        bkfrees1[ai, bi, ci, :])) / sgetmn1
                    etalonfree2[ai, bi, ci, :] = (np.squeeze(
                        bkfrees2[ai, bi, ci, :])) / sgetmn2

                    etalonSumfree1[ai, bi, ci, :] = (np.squeeze(
                        psfrees1[ai, bi, ci, :])) / sgetmn1
                    etalonSumfree2[ai, bi, ci, :] = (np.squeeze(
                        psfrees2[ai, bi, ci, :])) / sgetmn2

        etfree = EmptyClass()
        etfree.s1 = etalonfree1
        etfree.s2 = etalonfree2

        etSumfree = EmptyClass()
        etSumfree.s1 = etalonSumfree1
        etSumfree.s2 = etalonSumfree2

        return etfree, etSumfree

    else:
        return bkfree, psfree
예제 #2
0
def remove_stokespump(cars, stokes, pump):
    if not (type(cars) is None.__class__ or type(stokes) is None.__class__
            or type(pump) is None.__class__):
        pumpstokes1 = np.squeeze(np.mean(np.mean(
            stokes.s1[:, :, :, :], 1), 0)) + np.squeeze(
                np.mean(np.mean(pump.s1[:, :, :, :], 1), 0))
        pumpstokes2 = np.squeeze(np.mean(np.mean(
            stokes.s2[:, :, :, :], 1), 0)) + np.squeeze(
                np.mean(np.mean(pump.s2[:, :, :, :], 1), 0))

        [a, b, c, d] = cars.s1.shape

        psfree1 = np.full((a, b, c, d), 0, dtype='float')
        psfree2 = np.full((a, b, c, d), 0, dtype='float')

        pumpstokes1 = sg_filt(pumpstokes1, window_length=5, polyorder=3)
        pumpstokes2 = sg_filt(pumpstokes2, window_length=5, polyorder=3)

        max1 = max(pumpstokes1)
        max2 = max(pumpstokes2)

        for ai in range(0, a):
            for bi in range(0, b):
                for ci in range(0, c):
                    psfree1[ai, bi,
                            ci, :] = np.squeeze(cars.s1[ai, bi, ci, :]) - (
                                max(np.squeeze(cars.s1[ai, bi, ci, :])) /
                                max1) * pumpstokes1
                    psfree2[ai, bi,
                            ci, :] = np.squeeze(cars.s2[ai, bi, ci, :]) - (
                                max(np.squeeze(cars.s2[ai, bi, ci, :])) /
                                max2) * pumpstokes2

        psfree = EmptyClass()
        psfree.s1 = psfree1
        psfree.s2 = psfree2

        return psfree

    else:
        return cars
예제 #3
0
def ellipse(data_epl, pos, cm_px, peak_width=20, rel_height=0.8,
            plot=False):
    """
    Function that takes in the EPL image and finds the best elliptical fit
    EPL diameter. Optionally plots the result against the 'optical diameter'
    as well for quick diagnostic of single image.
    =============
    --VARIABLES--
    data_epl:           EPL converted image of spray from convert2EPL
                        function (array).
    pos:                Vertical pixel location for the elliptical fitting
                        plot (integer).
    peak_width:         Width in pixels to be used for the find_peaks
                        function. Defaulted to 20 px (integer).
    rel_height:         Relative height to be used for the peak_widths
                        function. Defaulted to 0.8 for the 'fifth_maximum'
                        (scalar).
    cm_px:             Pixel to cm conversion, dependent on experimental
                        setup (scalar).
    plot:               Check to see if plots are wanted. Defaulted to
                        False (boolean).
    """

    peaks, _ = find_peaks(
                          sg_filt(data_epl[pos, :], 105, 7),
                          width=peak_width,
                          prominence=0.1
                          )
    [rel_width, rel_max, lpos, rpos] = peak_widths(
                                                   sg_filt(
                                                           data_epl[pos, :],
                                                           105,
                                                           7
                                                           ),
                                                   peaks,
                                                   rel_height=rel_height
                                                   )
    rel_width = rel_width[0]
    rel_max = rel_max[0]
    lft = int(round(lpos[0]))
    rgt = int(round(rpos[0]))
    model_epl, fitted_graph, epl_graph = ideal_ellipse(
                                                       data_epl[pos, :]
                                                               [lft:rgt],
                                                       rel_width,
                                                       rel_max,
                                                       cm_px
                                                       )

    if plot:
        plot_ellipse(epl_graph, fitted_graph)

        plt.figure()
        plt.imshow(data_epl, vmin=0, vmax=1)
        plt.plot([pos]*len(data_epl[pos, :]), color='r', linestyle='--')
        plt.colorbar()
        plt.title('EPL [cm] Mapping of Spray')

        plt.figure()
        plt.plot(data_epl[pos, :])
        plt.title('Line Scan at ' + str(pos))
        plt.xlabel('Horizontal Location [px]')
        plt.ylabel('EPL [cm]')
예제 #4
0
def convert2EPL(test_path, offset, model_pckl, cm_pix,
                dark_path, flat_path, cropped_view=None, plot=False):
    """
    Function that takes in the designated raw test and converts to EPL.
    Optionally plots the result as well.
    =============
    --VARIABLES--
    test_path:          Path to an individual raw test image (.tif)
    offset:             Background EPL value correction. Given as either a
                        tuple of slices that designate a region outside the
                        spray, or as a float if the offset value is known
                        beforehand.
    model_pckl:         White beam model to be used. Generated by the
                        specific whitebeam_*.py script (.pckl).
    cm_pix:             Pixel to cm conversion, dependent on experimental
                        setup (scalar).
    dark_path:          Path to the image to be used for dark current
                        subtraction (.tif).
    flat_path:          Path to the image to be used for flat field
                        normalization (.tif).
    cropped_view:       Optional integer array parameter to crop down the
                        image before conversion. Defaulted to None (int).
    plot:               Check to see if plots are wanted. Defaulted to
                        False (boolean).
    """

    f = open(model_pckl, 'rb')
    model = pickle.load(f)
    f.close()

    dark = np.array(Image.open(dark_path))
    flatfield = np.array(Image.open(flat_path))
    flatfield_darksub = flatfield - dark

    beam_middle = np.zeros((flatfield_darksub.shape[1]))
    for i in range(flatfield_darksub.shape[1]):
        beam_middle[i] = np.argmax(
                                   sg_filt(
                                           flatfield_darksub[:, i],
                                           55,
                                           3
                                           )
                                   )

    beam_middle_avg = int(np.mean(beam_middle).round())

    angles = model[0]
    angle_to_px = [
                   beam_middle_avg+3500*np.tan(x*10**-3)/cm_pix
                   for x in angles
                   ]

    data = np.array(Image.open(test_path))
    data_norm = (data-dark) / flatfield_darksub

    data_epl = np.empty(np.shape(data_norm), dtype=float)

    if isinstance(cropped_view, None):
        cropped_view = np.linspace(1, data_norm.shape[0])

    for z, _ in enumerate(cropped_view):
        j = np.argmin(abs(z-np.array(angle_to_px)))
        data_epl[z, :] = model[1][j](data_norm[z, :])

    if type(offset) == tuple:
        offset_epl = data_epl[offset[0], offset[1]]
        data_epl -= offset_epl
    else:
        data_epl -= offset

    if plot:
        plt.imshow(data_epl, vmin=0, vmax=1)
        plt.colorbar
        plt.title('EPL [cm] Mapping of Spray')

    return data_epl