From ca448f9c0e9e1b4cfd925671e74eda3121e5de09 Mon Sep 17 00:00:00 2001 From: noordhee Date: Mon, 13 Jan 2025 09:12:44 +0100 Subject: [PATCH 1/6] data and plot separation on peak select --- ImageD11/peakselect.py | 99 ++++++++++++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 27 deletions(-) diff --git a/ImageD11/peakselect.py b/ImageD11/peakselect.py index fc85084e..bfc1b009 100755 --- a/ImageD11/peakselect.py +++ b/ImageD11/peakselect.py @@ -73,17 +73,31 @@ def rings_mask(cf, dstol, dsmax, cell=None): m |= (abs(cf.ds - v) < dstol) return m +# separated plot logic, call from ''select_ring_peaks_by_intensity'' (only place the following function was called) +# will return the same result as before +# additional arugment will be used by DAU ewoks team! +def sorted_peak_intensity_mask(colf, uself=True, frac=0.995, B=0.2, doplot=None, return_plot_data=False): + """ + Create a boolean mask for a columnfile based on peaks sorted by fractional intensity. -def sorted_peak_intensity_mask(colf, uself=True, frac=0.995, B=0.2, doplot=None): - """Create a boolean mask for a columnfile - Based on peaks sorted by fractional intensity - Keeps peaks[:frac] where peaks are sorted by intensity""" - # correct intensities for structure factor (decreases with 2theta) + Args: + colf: Input column file object. + uself: Apply Lorentz factor correction (default: True). + frac: Fraction of peaks to keep based on intensity. + B: Thermal factor for intensity correction. + doplot: Optional plotting argument. + return_plot_data: Whether to return data used for plotting. + + Returns: + mask: Boolean mask for selected peaks. + plot_data (optional): Data used for plotting (if return_plot_data is True). + """ + # Correct intensities for structure factor (decreases with 2theta) cor_intensity = colf.sum_intensity * (np.exp(colf.ds * colf.ds * B)) if uself: lf = ImageD11.refinegrains.lf(colf.tth, colf.eta) cor_intensity *= lf - order = np.argsort(cor_intensity)[::-1] # sort the peaks by intensity + order = np.argsort(cor_intensity)[::-1] # Sort peaks by intensity sortedpks = cor_intensity[order] cums = np.cumsum(sortedpks) cums /= cums[-1] @@ -97,37 +111,68 @@ def sorted_peak_intensity_mask(colf, uself=True, frac=0.995, B=0.2, doplot=None) # Aim is to select the strongest peaks for indexing. cutoff = sortedpks[enough] mask = cor_intensity > cutoff + if doplot is not None: - from matplotlib import pyplot as plt - fig, axs = plt.subplots(1, 2, figsize=(10, 5)) - axs[0].plot(cums / cums[-1], ',') - axs[0].set(xlabel='npks', ylabel='fractional intensity') - axs[0].plot([mask.sum(), ], [frac, ], "o") - axs[1].plot(cums / cums[-1], ',') - axs[1].set(xlabel='npks logscale', ylabel='fractional intensity', xscale='log', ylim=(doplot, 1.), - xlim=(np.searchsorted(cums, doplot), len(cums))) - axs[1].plot([mask.sum(), ], [frac, ], "o") - plt.show() + plot_sorted_peak_intensity(cums, mask, frac, doplot) + + if return_plot_data: + # Return data for further use (no plotting) + plot_data = { + "cums": cums, + "masksum": mask.sum(), + "frac": frac, + } + return mask, plot_data + return mask +def plot_sorted_peak_intensity(cums, mask, frac, doplot): + """ + Helper function to plot sorted peak intensity data. + + Args: + cums: Cumulative sums of sorted intensities. + mask: Boolean mask for selected peaks. + frac: Fraction of peaks to keep. + doplot: Plot zooming range. + """ + from matplotlib import pyplot as plt + + fig, axs = plt.subplots(1, 2, figsize=(10, 5)) + axs[0].plot(cums / cums[-1], ',') + axs[0].set(xlabel='npks', ylabel='fractional intensity') + axs[0].plot([mask.sum(), ], [frac, ], "o") + + axs[1].plot(cums / cums[-1], ',') + axs[1].set(xlabel='npks logscale', ylabel='fractional intensity', + xscale='log', ylim=(doplot, 1.), + xlim=(np.searchsorted(cums, doplot), len(cums))) + axs[1].plot([mask.sum(), ], [frac, ], "o") -def select_ring_peaks_by_intensity(cf, dstol=0.005, dsmax=None, frac=0.99, B=0.2, doplot=None): + plt.show() + +# no edit on the logic, and legacy code will continue as before +def select_ring_peaks_by_intensity(cf, dstol=0.005, dsmax=None, frac=0.99, B=0.2, doplot=None,): """ - cf = input columnfile + unit cell in parameters - dstol = difference in d* (=1/d) for assigning peaks to rings - dsmax = high angle cutoff to remove peaks - frac = the fractional normalised intensity to keep (removes weak peaks) - B = thermal factor to downweight low angle vs high angle peaks for normalised intensity - doplot = whether to draw a plot (float number, range for zoomed plot) - - returns: a columnfile with peaks removed + Select peaks based on ring intensity. + + Args: + cf: Input columnfile + unit cell parameters. + dstol: Difference in d* for assigning peaks to rings. + dsmax: High angle cutoff for removing peaks. + frac: Fractional normalised intensity to keep (removes weak peaks) + B: Thermal factor to downweight low angle vs high angle peaks for normalised intensity + doplot: Whether to draw a plot. + + Returns: + cfc: Columnfile with selected peaks. """ if dsmax is None: dsmax = cf.ds.max() cfd = cf else: - cfd = cf.copyrows( cf.ds <= dsmax ) - m = rings_mask( cfd, dstol=dstol, dsmax=dsmax) + cfd = cf.copyrows(cf.ds <= dsmax) + m = rings_mask(cfd, dstol=dstol, dsmax=dsmax) cfc = cfd.copyrows(m) ms = sorted_peak_intensity_mask(cfc, frac=frac, B=B, doplot=doplot) cfc.filter(ms) From fd9bfd59efa7b03d0dbe09a0dd86f2370e82c100 Mon Sep 17 00:00:00 2001 From: noordhee Date: Mon, 13 Jan 2025 14:50:46 +0100 Subject: [PATCH 2/6] intesity_filtered_ring_peaks_and_plot_data function in peakselect file --- ImageD11/peakselect.py | 82 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 67 insertions(+), 15 deletions(-) diff --git a/ImageD11/peakselect.py b/ImageD11/peakselect.py index bfc1b009..05519921 100755 --- a/ImageD11/peakselect.py +++ b/ImageD11/peakselect.py @@ -73,10 +73,8 @@ def rings_mask(cf, dstol, dsmax, cell=None): m |= (abs(cf.ds - v) < dstol) return m -# separated plot logic, call from ''select_ring_peaks_by_intensity'' (only place the following function was called) -# will return the same result as before -# additional arugment will be used by DAU ewoks team! -def sorted_peak_intensity_mask(colf, uself=True, frac=0.995, B=0.2, doplot=None, return_plot_data=False): +# separated plot logic, call from ''select_ring_peaks_by_intensity'' +def sorted_peak_intensity_mask(colf, uself=True, frac=0.995, B=0.2, doplot=None): """ Create a boolean mask for a columnfile based on peaks sorted by fractional intensity. @@ -86,11 +84,9 @@ def sorted_peak_intensity_mask(colf, uself=True, frac=0.995, B=0.2, doplot=None, frac: Fraction of peaks to keep based on intensity. B: Thermal factor for intensity correction. doplot: Optional plotting argument. - return_plot_data: Whether to return data used for plotting. Returns: mask: Boolean mask for selected peaks. - plot_data (optional): Data used for plotting (if return_plot_data is True). """ # Correct intensities for structure factor (decreases with 2theta) cor_intensity = colf.sum_intensity * (np.exp(colf.ds * colf.ds * B)) @@ -115,15 +111,6 @@ def sorted_peak_intensity_mask(colf, uself=True, frac=0.995, B=0.2, doplot=None, if doplot is not None: plot_sorted_peak_intensity(cums, mask, frac, doplot) - if return_plot_data: - # Return data for further use (no plotting) - plot_data = { - "cums": cums, - "masksum": mask.sum(), - "frac": frac, - } - return mask, plot_data - return mask def plot_sorted_peak_intensity(cums, mask, frac, doplot): @@ -177,3 +164,68 @@ def select_ring_peaks_by_intensity(cf, dstol=0.005, dsmax=None, frac=0.99, B=0.2 ms = sorted_peak_intensity_mask(cfc, frac=frac, B=B, doplot=doplot) cfc.filter(ms) return cfc + + +def sorted_peak_intensity_mask_cum_data(colf, uself=True, frac=0.995, B=0.2,): + """ + Create a boolean mask for a columnfile based on peaks sorted by fractional intensity. + + Args: + colf: Input column file object. + uself: Apply Lorentz factor correction (default: True). + frac: Fraction of peaks to keep based on intensity. + B: Thermal factor for intensity correction. + + Returns: + mask: Boolean mask for selected peaks. + plot_data (optional): Data used for plotting. + """ + # Correct intensities for structure factor (decreases with 2theta) + cor_intensity = colf.sum_intensity * (np.exp(colf.ds * colf.ds * B)) + if uself: + lf = ImageD11.refinegrains.lf(colf.tth, colf.eta) + cor_intensity *= lf + order = np.argsort(cor_intensity)[::-1] # Sort peaks by intensity + sortedpks = cor_intensity[order] + cums = np.cumsum(sortedpks) + cums /= cums[-1] + + # TODO + # anything above this should be calculated once and added to the CF + # check if the column exists before calculating + # slider for frac? + # all above only needs calculating once + enough = np.searchsorted(cums, frac) + # Aim is to select the strongest peaks for indexing. + cutoff = sortedpks[enough] + mask = cor_intensity > cutoff + + return mask, cums, [mask.sum(), frac] # last two arguments are the data for plotting + + +# For the ewoks task, we would like to have this +def intensity_filtered_ring_peaks_and_plot_data(cf, uself = True, dstol=0.005, dsmax=None, frac=0.99, B=0.2,): + """ + Select peaks based on ring intensity. + + Args: + cf: Input columnfile + unit cell parameters. + dstol: Difference in d* for assigning peaks to rings. + dsmax: High angle cutoff for removing peaks. + frac: Fractional normalised intensity to keep (removes weak peaks) + B: Thermal factor to downweight low angle vs high angle peaks for normalised intensity + doplot: Whether to draw a plot. + + Returns: + cfc: Columnfile with selected peaks. + """ + if dsmax is None: + dsmax = cf.ds.max() + cfd = cf + else: + cfd = cf.copyrows( cf.ds <= dsmax ) + m = rings_mask( cfd, dstol=dstol, dsmax=dsmax ) + cfc = cfd.copyrows(m) + ms, cums, single_point = sorted_peak_intensity_mask_cum_data(cfc, frac=frac, B=B,) + cfc.filter(ms) + return cfc, cums, single_point \ No newline at end of file From 9dfc1281f90e06768a1a6aca72121ab333cb1d15 Mon Sep 17 00:00:00 2001 From: noordhee Date: Mon, 13 Jan 2025 15:12:39 +0100 Subject: [PATCH 3/6] intesity_filtered_ring_peaks_and_plot_data function in peakselect file --- ImageD11/peakselect.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/ImageD11/peakselect.py b/ImageD11/peakselect.py index 05519921..25c2e382 100755 --- a/ImageD11/peakselect.py +++ b/ImageD11/peakselect.py @@ -73,7 +73,7 @@ def rings_mask(cf, dstol, dsmax, cell=None): m |= (abs(cf.ds - v) < dstol) return m -# separated plot logic, call from ''select_ring_peaks_by_intensity'' +# separated plot logic, def sorted_peak_intensity_mask(colf, uself=True, frac=0.995, B=0.2, doplot=None): """ Create a boolean mask for a columnfile based on peaks sorted by fractional intensity. @@ -138,7 +138,7 @@ def plot_sorted_peak_intensity(cums, mask, frac, doplot): plt.show() -# no edit on the logic, and legacy code will continue as before +# no edit on the logic, def select_ring_peaks_by_intensity(cf, dstol=0.005, dsmax=None, frac=0.99, B=0.2, doplot=None,): """ Select peaks based on ring intensity. @@ -158,7 +158,7 @@ def select_ring_peaks_by_intensity(cf, dstol=0.005, dsmax=None, frac=0.99, B=0.2 dsmax = cf.ds.max() cfd = cf else: - cfd = cf.copyrows(cf.ds <= dsmax) + cfd = cf.copyrows( cf.ds <= dsmax ) m = rings_mask(cfd, dstol=dstol, dsmax=dsmax) cfc = cfd.copyrows(m) ms = sorted_peak_intensity_mask(cfc, frac=frac, B=B, doplot=doplot) @@ -166,7 +166,7 @@ def select_ring_peaks_by_intensity(cf, dstol=0.005, dsmax=None, frac=0.99, B=0.2 return cfc -def sorted_peak_intensity_mask_cum_data(colf, uself=True, frac=0.995, B=0.2,): +def sorted_peak_intensity_mask_plot_data(colf, uself=True, frac=0.995, B=0.2,): """ Create a boolean mask for a columnfile based on peaks sorted by fractional intensity. @@ -178,7 +178,7 @@ def sorted_peak_intensity_mask_cum_data(colf, uself=True, frac=0.995, B=0.2,): Returns: mask: Boolean mask for selected peaks. - plot_data (optional): Data used for plotting. + plot_data: Data used for plotting. """ # Correct intensities for structure factor (decreases with 2theta) cor_intensity = colf.sum_intensity * (np.exp(colf.ds * colf.ds * B)) @@ -200,11 +200,15 @@ def sorted_peak_intensity_mask_cum_data(colf, uself=True, frac=0.995, B=0.2,): cutoff = sortedpks[enough] mask = cor_intensity > cutoff - return mask, cums, [mask.sum(), frac] # last two arguments are the data for plotting + plot_data = { + "cums": cums, + "pt": [mask.sum(), frac] + } + return mask, plot_data # For the ewoks task, we would like to have this -def intensity_filtered_ring_peaks_and_plot_data(cf, uself = True, dstol=0.005, dsmax=None, frac=0.99, B=0.2,): +def intensity_filtered_ring_peaks_and_plot_data(cf, dstol=0.005, dsmax=None, frac=0.99, B=0.2,): """ Select peaks based on ring intensity. @@ -214,10 +218,10 @@ def intensity_filtered_ring_peaks_and_plot_data(cf, uself = True, dstol=0.005, d dsmax: High angle cutoff for removing peaks. frac: Fractional normalised intensity to keep (removes weak peaks) B: Thermal factor to downweight low angle vs high angle peaks for normalised intensity - doplot: Whether to draw a plot. Returns: cfc: Columnfile with selected peaks. + plot_data: for plotting """ if dsmax is None: dsmax = cf.ds.max() @@ -226,6 +230,6 @@ def intensity_filtered_ring_peaks_and_plot_data(cf, uself = True, dstol=0.005, d cfd = cf.copyrows( cf.ds <= dsmax ) m = rings_mask( cfd, dstol=dstol, dsmax=dsmax ) cfc = cfd.copyrows(m) - ms, cums, single_point = sorted_peak_intensity_mask_cum_data(cfc, frac=frac, B=B,) + ms, plot_data = sorted_peak_intensity_mask_plot_data( cfc, frac=frac, B=B, ) cfc.filter(ms) - return cfc, cums, single_point \ No newline at end of file + return cfc, plot_data \ No newline at end of file From 51daec6fa2cf3594d73d7402ecea0cde5e2f22fa Mon Sep 17 00:00:00 2001 From: noordhee Date: Mon, 13 Jan 2025 15:47:45 +0100 Subject: [PATCH 4/6] intesity_filtered_ring_peaks_and_plot_data function in peakselect file --- ImageD11/peakselect.py | 94 +++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 56 deletions(-) diff --git a/ImageD11/peakselect.py b/ImageD11/peakselect.py index 25c2e382..2fa11223 100755 --- a/ImageD11/peakselect.py +++ b/ImageD11/peakselect.py @@ -73,7 +73,7 @@ def rings_mask(cf, dstol, dsmax, cell=None): m |= (abs(cf.ds - v) < dstol) return m -# separated plot logic, +# separated plot logic and core computation logic, def sorted_peak_intensity_mask(colf, uself=True, frac=0.995, B=0.2, doplot=None): """ Create a boolean mask for a columnfile based on peaks sorted by fractional intensity. @@ -88,26 +88,7 @@ def sorted_peak_intensity_mask(colf, uself=True, frac=0.995, B=0.2, doplot=None) Returns: mask: Boolean mask for selected peaks. """ - # Correct intensities for structure factor (decreases with 2theta) - cor_intensity = colf.sum_intensity * (np.exp(colf.ds * colf.ds * B)) - if uself: - lf = ImageD11.refinegrains.lf(colf.tth, colf.eta) - cor_intensity *= lf - order = np.argsort(cor_intensity)[::-1] # Sort peaks by intensity - sortedpks = cor_intensity[order] - cums = np.cumsum(sortedpks) - cums /= cums[-1] - - # TODO - # anything above this should be calculated once and added to the CF - # check if the column exists before calculating - # slider for frac? - # all above only needs calculating once - enough = np.searchsorted(cums, frac) - # Aim is to select the strongest peaks for indexing. - cutoff = sortedpks[enough] - mask = cor_intensity > cutoff - + mask, cums = sorted_peak_intensity_mask_plot_data(colf = colf, uself=uself, frac=frac, B=B,) if doplot is not None: plot_sorted_peak_intensity(cums, mask, frac, doplot) @@ -138,33 +119,6 @@ def plot_sorted_peak_intensity(cums, mask, frac, doplot): plt.show() -# no edit on the logic, -def select_ring_peaks_by_intensity(cf, dstol=0.005, dsmax=None, frac=0.99, B=0.2, doplot=None,): - """ - Select peaks based on ring intensity. - - Args: - cf: Input columnfile + unit cell parameters. - dstol: Difference in d* for assigning peaks to rings. - dsmax: High angle cutoff for removing peaks. - frac: Fractional normalised intensity to keep (removes weak peaks) - B: Thermal factor to downweight low angle vs high angle peaks for normalised intensity - doplot: Whether to draw a plot. - - Returns: - cfc: Columnfile with selected peaks. - """ - if dsmax is None: - dsmax = cf.ds.max() - cfd = cf - else: - cfd = cf.copyrows( cf.ds <= dsmax ) - m = rings_mask(cfd, dstol=dstol, dsmax=dsmax) - cfc = cfd.copyrows(m) - ms = sorted_peak_intensity_mask(cfc, frac=frac, B=B, doplot=doplot) - cfc.filter(ms) - return cfc - def sorted_peak_intensity_mask_plot_data(colf, uself=True, frac=0.995, B=0.2,): """ @@ -178,7 +132,7 @@ def sorted_peak_intensity_mask_plot_data(colf, uself=True, frac=0.995, B=0.2,): Returns: mask: Boolean mask for selected peaks. - plot_data: Data used for plotting. + cums: Data used for plotting. """ # Correct intensities for structure factor (decreases with 2theta) cor_intensity = colf.sum_intensity * (np.exp(colf.ds * colf.ds * B)) @@ -200,11 +154,34 @@ def sorted_peak_intensity_mask_plot_data(colf, uself=True, frac=0.995, B=0.2,): cutoff = sortedpks[enough] mask = cor_intensity > cutoff - plot_data = { - "cums": cums, - "pt": [mask.sum(), frac] - } - return mask, plot_data + return mask, cums + +# no edit on the logic, +def select_ring_peaks_by_intensity(cf, dstol=0.005, dsmax=None, frac=0.99, B=0.2, doplot=None,): + """ + Select peaks based on ring intensity. + + Args: + cf: Input columnfile + unit cell parameters. + dstol: Difference in d* for assigning peaks to rings. + dsmax: High angle cutoff for removing peaks. + frac: Fractional normalised intensity to keep (removes weak peaks) + B: Thermal factor to downweight low angle vs high angle peaks for normalised intensity + doplot: Whether to draw a plot. + + Returns: + cfc: Columnfile with selected peaks. + """ + if dsmax is None: + dsmax = cf.ds.max() + cfd = cf + else: + cfd = cf.copyrows( cf.ds <= dsmax ) + m = rings_mask(cfd, dstol=dstol, dsmax=dsmax) + cfc = cfd.copyrows(m) + ms = sorted_peak_intensity_mask(cfc, frac=frac, B=B, doplot=doplot) + cfc.filter(ms) + return cfc # For the ewoks task, we would like to have this @@ -230,6 +207,11 @@ def intensity_filtered_ring_peaks_and_plot_data(cf, dstol=0.005, dsmax=None, fra cfd = cf.copyrows( cf.ds <= dsmax ) m = rings_mask( cfd, dstol=dstol, dsmax=dsmax ) cfc = cfd.copyrows(m) - ms, plot_data = sorted_peak_intensity_mask_plot_data( cfc, frac=frac, B=B, ) - cfc.filter(ms) + ms, cums = sorted_peak_intensity_mask_plot_data( cfc, frac=frac, B=B, ) + cfc.filter(ms) + + plot_data = { + "cums": cums, + "pt": [ms.sum(), frac] + } return cfc, plot_data \ No newline at end of file From 2041346f9a2f7d1e5c14db1f2a583062e75d5e38 Mon Sep 17 00:00:00 2001 From: noordhee Date: Mon, 13 Jan 2025 16:59:27 +0100 Subject: [PATCH 5/6] intesity_filtered_ring_peaks_and_plot_data function in peakselect file --- ImageD11/peakselect.py | 36 ++---------------------------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/ImageD11/peakselect.py b/ImageD11/peakselect.py index 2fa11223..b695525d 100755 --- a/ImageD11/peakselect.py +++ b/ImageD11/peakselect.py @@ -88,7 +88,7 @@ def sorted_peak_intensity_mask(colf, uself=True, frac=0.995, B=0.2, doplot=None) Returns: mask: Boolean mask for selected peaks. """ - mask, cums = sorted_peak_intensity_mask_plot_data(colf = colf, uself=uself, frac=frac, B=B,) + mask, cums = sorted_peak_intensity_mask_and_cumsum(colf = colf, uself=uself, frac=frac, B=B,) if doplot is not None: plot_sorted_peak_intensity(cums, mask, frac, doplot) @@ -120,7 +120,7 @@ def plot_sorted_peak_intensity(cums, mask, frac, doplot): plt.show() -def sorted_peak_intensity_mask_plot_data(colf, uself=True, frac=0.995, B=0.2,): +def sorted_peak_intensity_mask_and_cumsum(colf, uself=True, frac=0.995, B=0.2,): """ Create a boolean mask for a columnfile based on peaks sorted by fractional intensity. @@ -183,35 +183,3 @@ def select_ring_peaks_by_intensity(cf, dstol=0.005, dsmax=None, frac=0.99, B=0.2 cfc.filter(ms) return cfc - -# For the ewoks task, we would like to have this -def intensity_filtered_ring_peaks_and_plot_data(cf, dstol=0.005, dsmax=None, frac=0.99, B=0.2,): - """ - Select peaks based on ring intensity. - - Args: - cf: Input columnfile + unit cell parameters. - dstol: Difference in d* for assigning peaks to rings. - dsmax: High angle cutoff for removing peaks. - frac: Fractional normalised intensity to keep (removes weak peaks) - B: Thermal factor to downweight low angle vs high angle peaks for normalised intensity - - Returns: - cfc: Columnfile with selected peaks. - plot_data: for plotting - """ - if dsmax is None: - dsmax = cf.ds.max() - cfd = cf - else: - cfd = cf.copyrows( cf.ds <= dsmax ) - m = rings_mask( cfd, dstol=dstol, dsmax=dsmax ) - cfc = cfd.copyrows(m) - ms, cums = sorted_peak_intensity_mask_plot_data( cfc, frac=frac, B=B, ) - cfc.filter(ms) - - plot_data = { - "cums": cums, - "pt": [ms.sum(), frac] - } - return cfc, plot_data \ No newline at end of file From e608b4e53aac0f5744ce36846793ce48def2b3b3 Mon Sep 17 00:00:00 2001 From: noordhee Date: Thu, 16 Jan 2025 09:55:03 +0100 Subject: [PATCH 6/6] loic comments update on peakselect functions --- ImageD11/peakselect.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ImageD11/peakselect.py b/ImageD11/peakselect.py index b695525d..21583ade 100755 --- a/ImageD11/peakselect.py +++ b/ImageD11/peakselect.py @@ -73,7 +73,6 @@ def rings_mask(cf, dstol, dsmax, cell=None): m |= (abs(cf.ds - v) < dstol) return m -# separated plot logic and core computation logic, def sorted_peak_intensity_mask(colf, uself=True, frac=0.995, B=0.2, doplot=None): """ Create a boolean mask for a columnfile based on peaks sorted by fractional intensity. @@ -132,7 +131,7 @@ def sorted_peak_intensity_mask_and_cumsum(colf, uself=True, frac=0.995, B=0.2,): Returns: mask: Boolean mask for selected peaks. - cums: Data used for plotting. + cums: Cumulative sums of the (sorted) peak intensities """ # Correct intensities for structure factor (decreases with 2theta) cor_intensity = colf.sum_intensity * (np.exp(colf.ds * colf.ds * B)) @@ -156,7 +155,7 @@ def sorted_peak_intensity_mask_and_cumsum(colf, uself=True, frac=0.995, B=0.2,): return mask, cums -# no edit on the logic, + def select_ring_peaks_by_intensity(cf, dstol=0.005, dsmax=None, frac=0.99, B=0.2, doplot=None,): """ Select peaks based on ring intensity. @@ -167,8 +166,7 @@ def select_ring_peaks_by_intensity(cf, dstol=0.005, dsmax=None, frac=0.99, B=0.2 dsmax: High angle cutoff for removing peaks. frac: Fractional normalised intensity to keep (removes weak peaks) B: Thermal factor to downweight low angle vs high angle peaks for normalised intensity - doplot: Whether to draw a plot. - + doplot: Whether to draw a plot. (float number, range for zoomed plot) Returns: cfc: Columnfile with selected peaks. """