-
Notifications
You must be signed in to change notification settings - Fork 8
Issue 1119 changing spectral axis #1136
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
Open
astrofle
wants to merge
3
commits into
release-1.1
Choose a base branch
from
issue-1119-changing-spectral_axis
base: release-1.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
|---|---|---|
|
|
@@ -1097,6 +1097,73 @@ def rest_value(self, value: Quantity): | |
| self.meta["RESTFREQ"] = value.to("Hz").value | ||
| self.meta["RESTFRQ"] = value.to("Hz").value | ||
|
|
||
| def with_spectral_axis_unit(self, *args, **kwargs): | ||
| """ | ||
| Returns a new spectrum with a different spectral axis unit. Note that this creates a new | ||
| object using the converted spectral axis and thus drops the original WCS, if it existed, | ||
| replacing it with a lookup-table :class:`~gwcs.wcs.WCS` based on the new spectral axis. The | ||
| original WCS will be stored in the ``original_wcs`` entry of the new object's ``meta`` | ||
| dictionary. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| unit : :class:`~astropy.units.Unit` | ||
| Any valid spectral unit: velocity, (wave)length, or frequency. | ||
| Only vacuum units are supported. | ||
| doppler_convention : {None, 'relativistic', 'radio', 'optical'} | ||
| The Doppler convention to use for the output velocity axis. | ||
| Required if the output type is velocity. This can be either one | ||
| of the above strings, or an `astropy.units` equivalency. | ||
| rest_value : :class:`~astropy.units.Quantity` | ||
| A rest wavelength or frequency with appropriate units. Required if | ||
| output type is velocity. The spectrum's WCS should include this | ||
| already if the *input* type is velocity, but the WCS's rest | ||
| wavelength/frequency can be overridden with this parameter. | ||
|
|
||
| .. note: This must be the rest frequency/wavelength *in vacuum*, | ||
| even if your spectrum has air wavelength units | ||
|
|
||
| """ | ||
| # The docstring should be kept up to date. | ||
| # Keep docstring empty to re-use the one from specutils. | ||
| # Keeping the specutils doc introduces yet another name | ||
| # for what we call `doppler_convention`, `velocity_convention`. | ||
| # This is a source of frustration... | ||
|
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. Because specutils does not follow the astropy parameter name 'doppler_convention' in |
||
| # Rename kwargs to match specutils signature. | ||
| rename_dict = {"doppler_convention": "velocity_convention"} | ||
| new_kwargs = {rename_dict[key]: value for key, value in kwargs.items()} | ||
| spec = super().with_spectral_axis_unit(*args, **new_kwargs) | ||
| # Copy observer and target to support further frame conversions. | ||
| # See issue #1119. | ||
| spec._observer = self.observer.copy() | ||
| spec._spectral_axis.observer = self.spectral_axis.observer.copy() | ||
| spec._target = self.target.copy() | ||
| spec._spectral_axis.target = self.spectral_axis.target.copy() | ||
| return spec | ||
|
|
||
| def set_spectral_axis(self, unit=None, toframe=None, doppler_convention=None) -> None: | ||
| """ | ||
| Modifies the spectral axis to have units of `unit` in reference frame `toframe` | ||
| using Doppler convention `doppler_convention`. This changes the `Spectrum`. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| unit : `~astropy.units.quantity.Quantity` or str that can be converted to Quantity | ||
| The unit to which the axis is to be converted. | ||
| toframe : str | ||
| The coordinate frame to convert to, e.g. 'hcrs', 'icrs'. | ||
| doppler_convention : {None, 'relativistic', 'radio', 'optical'} | ||
| The Doppler convention to use when converting to velocity. | ||
| One of 'optical', 'radio', or 'relativistic'. | ||
| """ | ||
| if unit is None and toframe is not None: | ||
| self.set_frame(toframe) | ||
| if unit is None and doppler_convention is not None: | ||
| self.set_convention(doppler_convention) | ||
| if unit is not None: | ||
| sa = self.velocity_axis_to(unit=unit, toframe=toframe, doppler_convention=doppler_convention) | ||
| self._spectral_axis = sa | ||
|
|
||
| def axis_velocity(self, unit=KMS): | ||
| """Get the spectral axis in velocity units. | ||
| *Note*: This is not the same as `Spectrum.velocity`, which includes the source radial velocity. | ||
|
|
@@ -1123,7 +1190,7 @@ def velocity_axis_to(self, unit=KMS, toframe=None, doppler_convention=None): | |
| The unit to which the spectral axis is to be converted. | ||
| toframe : str | ||
| The coordinate frame to convert to, e.g. 'hcrs', 'icrs'. | ||
| doppler_convention : None or {'optical', 'radio', 'relativistic'} | ||
| doppler_convention : {None, 'relativistic', 'radio', 'optical'} | ||
| The Doppler convention to use when converting to velocity. | ||
| One of 'optical', 'radio', or 'relativistic'. | ||
|
|
||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cell 6: sdfits["CTYPE1"][0] returns nan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, sometimes notebook plots just hang but I don't belive that has anything to do with this PR.