-
Notifications
You must be signed in to change notification settings - Fork 1
Bugfix/filter sed conversion #80
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -292,10 +292,49 @@ def interpolate(self, wavelength=None): | |
| return self.response | ||
|
|
||
| def _check_spectra(self, spectra, default_unit=u.Lsun / u.angstrom / u.cm**2): | ||
| if spectra is not None and not isinstance(spectra, u.Quantity): | ||
| return spectra * default_unit | ||
| else: | ||
| """ | ||
| Ensure that ``spectra`` is an astropy Quantity and return it as flux density | ||
| per wavelength (F_lambda), using `self.wavelength` for conversions if | ||
| necessary. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| spectra : array-like or ~astropy.units.Quantity | ||
| Spectrum values. If array-like (dimensionless), it will be multiplied by | ||
| `default_unit`. If a Quantity, it may be either F_nu (per frequency) or | ||
| F_lambda (per wavelength). | ||
| default_unit : ~astropy.units.Unit, optional | ||
| Target per-wavelength flux-density unit to return, e.g. Lsun / Å / cm² | ||
| (must be equivalent to power / area / length). | ||
|
|
||
| Returns | ||
| ------- | ||
| astropy.units.Quantity | ||
| Spectrum expressed in `default_unit` (per-wavelength flux density). | ||
|
|
||
| Notes | ||
| ----- | ||
| - Requires `self.wavelength` to be defined as an astropy Quantity with | ||
|
Owner
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. Looks like we should implement
Collaborator
Author
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. I am not sure, |
||
| length units. | ||
| - If `spectra` is already per wavelength, only a unit conversion is applied. | ||
| - If `spectra` is per frequency, the conversion uses | ||
| `equivalencies=u.spectral_density(self.wavelength)`. | ||
| """ | ||
| if spectra is None: | ||
| return None | ||
|
|
||
| if not isinstance(spectra, u.Quantity): | ||
| spectra = u.Quantity(spectra, default_unit) | ||
| # Check flux density units | ||
| if spectra.unit.is_equivalent(u.W / (u.m**2 * u.m)): | ||
| return spectra | ||
|
Owner
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. Actually, what about the following helper function? def ensure_unit(x, unit, just_equivalent=True, equivalence=None):
if not isinstance(x, u.Quantity):
return x << unit
if x.unit.is_equivalent(unit):
if just_equivalent:
return x
else:
return x.to(unit)
else:
return x.to(unit, equivalencies=equivalence)and then ensure_unit(wavelength, u.AA)
ensure_unit(spectra, u.Lsun/u.angstrom, equivalence=u.spectral_density(wavelength))
Collaborator
Author
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. I modified the |
||
| elif spectra.unit.is_equivalent(u.W / (u.m**2 * u.Hz)): | ||
| return spectra.to(default_unit, equivalencies=u.spectral_density(self.wavelength)) | ||
| else: | ||
| raise ValueError( | ||
| f"Cannot interpret spectral flux units {spectra.unit}. " | ||
| "Expected per-frequency or per-wavelength flux density." | ||
| ) | ||
|
|
||
| def get_photons(self, spectra, spectra_err=None, mask_nan=True): | ||
| r"""Compute the photon flux from an input spectra. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Perhaps
_ensure_f_lambda,_ensure_f_lambda_units, orensure_spectra_unitswould be more descriptive... I think I lean towards the second (perhaps renamingspectraasf_lambda?)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.
And
unitfor the argumentThere 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.
This is a private method. I don't know to what extent we need to be that careful given the docstrings... I don't understand the comment about the
unitargument.