예제 #1
0
def process_all_globs(glob_patterns,
                      show=False,
                      individual=False,
                      subArray=None,
                      normalization="peak",
                      normalizationArray=None,
                      labelList=None,
                      filterList=None,
                      recompute=False,
                      scale='angle',
                      ncores=None):
    """
    Return scaled, background-subtracted, and normalized powder patterns for data
    corresponding to each pattern in glob_patterns
    """
    if subArray is None:
        subArray = [None] * len(glob_patterns)
    if labelList is None:
        labelList = [None] * len(glob_patterns)
    if filterList is None:
        filterList = [None] * len(glob_patterns)
    if normalizationArray is None:
        normalizationArray = [None] * len(glob_patterns)

    def run_and_plot(glob,
                     bgsub=None,
                     label=None,
                     data_filter=None,
                     normalization=None):
        return process_radial_distribution(sum_radial_densities(glob,
                                                                False,
                                                                True,
                                                                ncores=ncores),
                                           normalization=normalization,
                                           bgsub=bgsub,
                                           label=glob,
                                           scale=scale,
                                           plot=show)

    outputs = []
    for patt, subtraction, label, one_filter, norm in zip(
            glob_patterns, subArray, labelList, filterList,
            normalizationArray):
        outputs = outputs + [
            run_and_plot(patt,
                         bgsub=subtraction,
                         label=label,
                         data_filter=one_filter,
                         normalization=norm)
        ]
    if show:
        plt.legend()
        plt.show(block=False)
    #output format: angles, intensities, angles, intensities, etc.
    return np.vstack((_ for _ in outputs))
예제 #2
0
def process_all_globs(
    glob_patterns,
    show=False,
    individual=False,
    subArray=None,
    normalization="peak",
    normalizationArray=None,
    labelList=None,
    filterList=None,
    recompute=False,
    scale="angle",
    ncores=None,
):
    """
    Return scaled, background-subtracted, and normalized powder patterns for data
    corresponding to each pattern in glob_patterns
    """
    if subArray is None:
        subArray = [None] * len(glob_patterns)
    if labelList is None:
        labelList = [None] * len(glob_patterns)
    if filterList is None:
        filterList = [None] * len(glob_patterns)
    if normalizationArray is None:
        normalizationArray = [None] * len(glob_patterns)

    def run_and_plot(glob, bgsub=None, label=None, data_filter=None, normalization=None):
        return process_radial_distribution(
            sum_radial_densities(glob, False, True, ncores=ncores),
            normalization=normalization,
            bgsub=bgsub,
            label=glob,
            scale=scale,
            plot=show,
        )

    outputs = []
    for patt, subtraction, label, one_filter, norm in zip(
        glob_patterns, subArray, labelList, filterList, normalizationArray
    ):
        outputs = outputs + [
            run_and_plot(patt, bgsub=subtraction, label=label, data_filter=one_filter, normalization=norm)
        ]
    if show:
        plt.legend()
        plt.show(block=False)
    # output format: angles, intensities, angles, intensities, etc.
    return np.vstack((_ for _ in outputs))
예제 #3
0
def process_and_plot(pattern_list,
                     deconvolution_iterations=100,
                     plot_powder=True,
                     show=True,
                     dtheta=5e-4,
                     filtsize=2,
                     center=CENTER,
                     airfactor=1.0,
                     kaptonfactor=0.0,
                     smooth_size=0.0,
                     normalize='',
                     peak_ranges=None):
    # TODO update docstring
    """
    Process data specified by glob patterns in pattern_list, using the
    parameters extracted from the filepath prefix

    Inputs:
        normalize: if == height, normalizes spectra by peak value; if == a tuple
            (assumed to contain two ints), normalizes by the integral of the
            specified range; if bool(height) == False, no normalization is done.
        peak_ranges: a list of tuples storing min and max angles of powder peaks
            (necessary for generating a plot of integrated Bragg peak intensities)
    """
    def one_spectrum(pattern):
        npulses = glob_npulses(pattern)
        x, y = full_process(pattern,
                            glob_attenuator(pattern),
                            dtheta=dtheta,
                            filtsize=filtsize,
                            npulses=npulses,
                            center=center,
                            airfactor=airfactor,
                            kaptonfactor=kaptonfactor,
                            smooth_size=smooth_size,
                            deconvolution_iterations=deconvolution_iterations)
        #x, y = estimator(deconvolution_iterations)
        # normalize by peak height
        if normalize == 'height':
            return [x, y / np.max(y)]
        # normalize by integral of the specified range
        elif isinstance(normalize, tuple):
            integral = peak_sizes(x, y, [normalize], bg_subtract=False)
            return [x, y / integral]
        elif normalize:
            raise ValueError("invalid value for normalize: " + str(normalize))
        else:
            return x, y

    spectra = [one_spectrum(pattern) for pattern in pattern_list]

    def plot_curves(cmap_start=0., cmap_max=1.0):
        # TODO: implement this
        #cmap = plt.get_cmap('coolwarm')
        ncurves = len(spectra)
        for i, pattern, curve in zip(range(len(spectra)), pattern_list,
                                     spectra):
            #plt.plot(*curve, label = pattern, color = cmap(cmap_start + i * (cmap_max - cmap_start)/ncurves))
            plt.plot(*curve, label=pattern)
        plt.legend()
        #        ax.set_xlabel('Angle (rad)')
        #        ax.set_ylabel('Intensity (arb)')
        plt.xlabel('Angle (rad)')
        plt.ylabel('Intensity (arb)')

    if plot_powder:
        plot_curves()
    if show:
        plt.show()
    return spectra
예제 #4
0
 def show():
     plt.xlabel("angle (degrees)")
     plt.ylabel("inensity (arb)")
     plt.legend()
     plt.show()
예제 #5
0
def process_and_plot(
    pattern_list,
    deconvolution_iterations=100,
    plot_powder=True,
    show=True,
    dtheta=5e-4,
    filtsize=2,
    center=CENTER,
    airfactor=1.0,
    kaptonfactor=0.0,
    smooth_size=0.0,
    normalize="",
    peak_ranges=None,
):
    # TODO update docstring
    """
    Process data specified by glob patterns in pattern_list, using the
    parameters extracted from the filepath prefix

    Inputs:
        normalize: if == height, normalizes spectra by peak value; if == a tuple
            (assumed to contain two ints), normalizes by the integral of the
            specified range; if bool(height) == False, no normalization is done.
        peak_ranges: a list of tuples storing min and max angles of powder peaks
            (necessary for generating a plot of integrated Bragg peak intensities)
    """

    def one_spectrum(pattern):
        npulses = glob_npulses(pattern)
        x, y = full_process(
            pattern,
            glob_attenuator(pattern),
            dtheta=dtheta,
            filtsize=filtsize,
            npulses=npulses,
            center=center,
            airfactor=airfactor,
            kaptonfactor=kaptonfactor,
            smooth_size=smooth_size,
            deconvolution_iterations=deconvolution_iterations,
        )
        # x, y = estimator(deconvolution_iterations)
        # normalize by peak height
        if normalize == "height":
            return [x, y / np.max(y)]
        # normalize by integral of the specified range
        elif isinstance(normalize, tuple):
            integral = peak_sizes(x, y, [normalize], bg_subtract=False)
            return [x, y / integral]
        elif normalize:
            raise ValueError("invalid value for normalize: " + str(normalize))
        else:
            return x, y

    spectra = [one_spectrum(pattern) for pattern in pattern_list]

    def plot_curves(cmap_start=0.0, cmap_max=1.0):
        # TODO: implement this
        # cmap = plt.get_cmap('coolwarm')
        ncurves = len(spectra)
        for i, pattern, curve in zip(range(len(spectra)), pattern_list, spectra):
            # plt.plot(*curve, label = pattern, color = cmap(cmap_start + i * (cmap_max - cmap_start)/ncurves))
            plt.plot(*curve, label=pattern)
        plt.legend()
        #        ax.set_xlabel('Angle (rad)')
        #        ax.set_ylabel('Intensity (arb)')
        plt.xlabel("Angle (rad)")
        plt.ylabel("Intensity (arb)")

    if plot_powder:
        plot_curves()
    if show:
        plt.show()
    return spectra
예제 #6
0
 def show():
     plt.xlabel("angle (degrees)")
     plt.ylabel("inensity (arb)")
     plt.legend()
     plt.show()