-
Notifications
You must be signed in to change notification settings - Fork 26
FRC and FSC cutoff=None option
#1060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| This module contains code for estimating resolution achieved by reconstructions. | ||
| """ | ||
| import logging | ||
| import warnings | ||
|
|
||
| import matplotlib.pyplot as plt | ||
| import numpy as np | ||
|
|
@@ -44,7 +45,7 @@ def __init__(self, a, b, pixel_size=None, method="fft"): | |
| Default `None` implies "pixel" units. | ||
| :param method: Selects either 'fft' (on Cartesian grid), | ||
| or 'nufft' (on polar grid). Defaults to 'fft'. | ||
| 7""" | ||
| """ | ||
|
|
||
| # Sanity checks | ||
| if not hasattr(self, "dim"): | ||
|
|
@@ -250,7 +251,11 @@ def analyze_correlations(self, cutoff): | |
| Convert from the Fourier correlations to frequencies and resolution. | ||
|
|
||
| :param cutoff: Cutoff value, traditionally `.143`. | ||
| Note `cutoff=None` evaluates as `cutoff=1`. | ||
| """ | ||
| # Handle optional cutoff plotting. | ||
| if cutoff is None: | ||
| cutoff = 1 | ||
|
Comment on lines
+257
to
+258
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This causes a |
||
|
|
||
| cutoff = float(cutoff) | ||
| if not (0 <= cutoff <= 1): | ||
|
|
@@ -271,8 +276,12 @@ def analyze_correlations(self, cutoff): | |
| # Convert indices to frequency (as 1/angstrom) | ||
| frequencies = self._freq(c_ind) | ||
|
|
||
| # Convert to resolution in angstrom, smaller is higher frequency. | ||
| self._resolutions = 1 / frequencies | ||
| with warnings.catch_warnings(): | ||
| # When using high cutoff (eg. 1) it is possible `frequencies` | ||
| # contains 0; capture and ignore that division warning. | ||
| warnings.filterwarnings("ignore", r".*divide by zero.*") | ||
| # Convert to resolution in angstrom, smaller is higher frequency. | ||
| self._resolutions = 1 / frequencies | ||
|
|
||
| return self._resolutions | ||
|
|
||
|
|
@@ -289,17 +298,25 @@ def _freq(self, k): | |
| # Similar to wavenumbers. Larger is higher frequency. | ||
| return k / (self.L * self.pixel_size) | ||
|
|
||
| def plot(self, cutoff, save_to_file=False, labels=None): | ||
| def plot(self, cutoff=None, save_to_file=False, labels=None): | ||
| """ | ||
| Generates a Fourier correlation plot. | ||
|
|
||
| :param cutoff: Cutoff value, traditionally `.143`. | ||
| Default `None` implies `cutoff=1` and excludes | ||
| plotting cutoff line. | ||
| :param save_to_file: Optionally, save plot to file. | ||
| Defaults False, enabled by providing a string filename. | ||
| User is responsible for providing reasonable filename. | ||
| See `https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.savefig.html`. | ||
| """ | ||
| cutoff = float(cutoff) | ||
|
|
||
| # Handle optional cutoff plotting. | ||
| _plot_cutoff = True | ||
| if cutoff is None: | ||
| cutoff = 1 | ||
| _plot_cutoff = False | ||
|
|
||
| if not (0 <= cutoff <= 1): | ||
| raise ValueError("Supplied correlation `cutoff` not in [0,1], {cutoff}") | ||
|
|
||
|
|
@@ -344,17 +361,20 @@ def plot(self, cutoff, save_to_file=False, labels=None): | |
| _label = labels[i] | ||
| plt.plot(freqs_units, line, label=_label) | ||
|
|
||
| # Display cutoff | ||
| plt.axhline(y=cutoff, color="r", linestyle="--", label=f"cutoff={cutoff}") | ||
| estimated_resolution = self.analyze_correlations(cutoff)[0] | ||
|
|
||
| # Display resolution | ||
| plt.axvline( | ||
| x=estimated_resolution, | ||
| color="b", | ||
| linestyle=":", | ||
| label=f"Resolution={estimated_resolution:.3f}", | ||
| ) | ||
| # Display cutoff | ||
| if _plot_cutoff: | ||
| plt.axhline(y=cutoff, color="r", linestyle="--", label=f"cutoff={cutoff}") | ||
|
|
||
| # Display resolution | ||
| plt.axvline( | ||
| x=estimated_resolution, | ||
| color="b", | ||
| linestyle=":", | ||
| label=f"Resolution={estimated_resolution:.3f}", | ||
| ) | ||
|
|
||
| # x-axis decreasing | ||
| plt.gca().invert_xaxis() | ||
| plt.legend(title=f"Method: {self.method}") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.