Пример #1
0
def test_peak_finding(h5_main):
    row_ind, col_ind = 110, 25
    pixel_ind = col_ind + row_ind * num_cols
    spectra = h5_main[pixel_ind]

    peak_inds = find_all_peaks(spectra, [20, 60], num_steps=30)

    fig, axis = plt.subplots()
    axis.scatter(np.arange(len(spectra)), np.abs(spectra), c='black')
    axis.axvline(peak_inds[0], color='r', linewidth=2)
    axis.set_ylim([0, 1.1 * np.max(np.abs(spectra))])
    axis.set_title('find_all_peaks found peaks at index: {}'.format(peak_inds),
                   fontsize=16)
Пример #2
0
    def _map_function(spectra, *args, **kwargs):
        """
        This is the function that will be applied to each pixel in the dataset.
        It's job is to demonstrate what needs to be done for each pixel in the dataset.
        pyUSID.Process will handle the parallel computation and memory management

        As in typical scientific problems, the results from find_all_peaks() need to be
        post-processed

        In this case, the find_all_peaks() function can sometimes return 0 or more than one peak
        for spectra that are very noisy

        Knowing that the peak is typically at the center of the spectra,
        we return the central index when no peaks were found
        Or the index closest to the center when multiple peaks are found

        Finally once we have a single index, we need to index the spectra by that index
        in order to get the amplitude at that frequency.
        """

        peak_inds = find_all_peaks(spectra, [20, 60], num_steps=30)

        central_ind = len(spectra) // 2
        if len(peak_inds) == 0:
            # too few peaks
            # set peak to center of spectra
            val = central_ind
        elif len(peak_inds) > 1:
            # too many peaks
            # set to peak closest to center of spectra
            dist = np.abs(peak_inds - central_ind)
            val = peak_inds[np.argmin(dist)]
        else:
            # normal situation
            val = peak_inds[0]
        # Finally take the amplitude of the spectra at this index
        return np.abs(spectra[val])
Пример #3
0
def run_serial_compute(h5_main):
    raw_data = h5_main[()]
    serial_results = list()
    for vector in raw_data:
        serial_results.append(find_all_peaks(vector, [20, 60], num_steps=30))
    return serial_results
Пример #4
0
#        # The below numpy array is used to configure the returned function wpeaks
#        wavelet_widths = np.linspace(width_bounds[0], width_bounds[1], num_steps)
#
#        peak_indices = find_peaks_cwt(np.abs(vector), wavelet_widths, **kwargs)
#
#        return peak_indices
#
# Testing the function
# ----------------------
# Let’s see what the operation on an example spectra returns.

row_ind, col_ind = 103, 19
pixel_ind = col_ind + row_ind * num_cols
spectra = h5_main[pixel_ind]

peak_inds = find_all_peaks(spectra, [20, 60], num_steps=30)

fig, axis = plt.subplots()
axis.scatter(np.arange(len(spectra)), np.abs(spectra), c='black')
axis.axvline(peak_inds[0], color='r', linewidth=2)
axis.set_ylim([0, 1.1 * np.max(np.abs(spectra))])
axis.set_title('find_all_peaks found peaks at index: {}'.format(peak_inds),
               fontsize=16)

########################################################################################################################
# Before we apply the function to the entire dataset, lets load the dataset to memory so that file-loading time is not a
# factor when comparing the times for serial and parallel computing times:

raw_data = h5_main[()]

########################################################################################################################