-
Notifications
You must be signed in to change notification settings - Fork 76
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
Line Analysis Plugin now listens to unit conversion changes #3107
base: main
Are you sure you want to change the base?
Changes from 4 commits
fcede25
4cf5462
4e3eb8a
5826707
b9a273a
5ed5c70
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 |
---|---|---|
|
@@ -271,7 +271,8 @@ def _uncertainty(result): | |
if getattr(result, 'uncertainty', None) is not None: | ||
# we'll keep the uncertainty and result in the same unit (so | ||
# we only have to show the unit at the end) | ||
if np.isnan(result.uncertainty.value) or np.isinf(result.uncertainty.value): | ||
if (np.any(np.isnan(result.uncertainty.value)) or | ||
np.any(np.isinf(result.uncertainty.value))): | ||
return '' | ||
return str(result.uncertainty.to_value(result.unit)) | ||
else: | ||
|
@@ -287,14 +288,15 @@ def _uncertainty(result): | |
# TODO: update specutils to allow ALL analysis to take regions and continuum so we | ||
# don't need these if statements | ||
if function == "Line Flux": | ||
flux_unit = spec_subtracted.flux.unit | ||
flux_unit = self.app._get_display_unit('flux') | ||
if flux_unit == u.dimensionless_unscaled: | ||
add_flux = True | ||
flux_unit = u.Unit(self.spectrum_viewer.state.y_display_unit) | ||
else: | ||
add_flux = False | ||
# If the flux unit is equivalent to Jy, or Jy per spaxel for Cubeviz, | ||
# enforce integration in frequency space | ||
flux_unit = u.Unit(flux_unit) | ||
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. would it be useful if 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. Yes indeed. 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. added to #3112 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. Thank you! 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. although that is triggering a few test failures (sigh), so we may need to postpone that work, for now maybe it makes sense to just case to unit immediately so if/when we do implement that it will be easy to notice and remove the duplication
|
||
if (flux_unit.is_equivalent(u.Jy) or | ||
flux_unit.is_equivalent(u.Jy/u.sr)): | ||
# Perform integration in frequency space | ||
|
@@ -319,16 +321,13 @@ def _uncertainty(result): | |
self.update_results(None) | ||
return | ||
|
||
# When flux is equivalent to Jy, lineflux result should be shown in W/m2 | ||
if flux_unit.is_equivalent(u.Jy/u.sr): | ||
final_unit = u.Unit('W/(m2 sr)') | ||
else: | ||
final_unit = u.Unit('W/m2') | ||
|
||
temp_result = raw_result.to(final_unit) | ||
temp_result = np.mean(raw_result.to( | ||
flux_unit, | ||
equivalencies=u.spectral_density(freq_spec.spectral_axis))) | ||
if getattr(raw_result, 'uncertainty', None) is not None: | ||
temp_result.uncertainty = raw_result.uncertainty.to(final_unit) | ||
|
||
temp_result.uncertainty = np.mean(raw_result.uncertainty.to( | ||
flux_unit, | ||
equivalencies=u.spectral_density(freq_spec.spectral_axis))) | ||
# If the flux unit is instead equivalent to power density | ||
# (Jy, but defined in wavelength), enforce integration in wavelength space | ||
elif (flux_unit.is_equivalent(u.Unit('W/(m2 m)')) or | ||
|
@@ -353,15 +352,14 @@ def _uncertainty(result): | |
color="warning")) | ||
self.update_results(None) | ||
return | ||
# When flux is equivalent to Jy, lineflux result should be shown in W/m2 | ||
if flux_unit.is_equivalent(u.Unit('W/(m2 m)'/u.sr)): | ||
final_unit = u.Unit('W/(m2 sr)') | ||
else: | ||
final_unit = u.Unit('W/m2') | ||
|
||
temp_result = raw_result.to(final_unit) | ||
temp_result = np.mean(raw_result.to( | ||
flux_unit, | ||
equivalencies=u.spectral_density(wave_spec.spectral_axis))) | ||
if getattr(raw_result, 'uncertainty', None) is not None: | ||
temp_result.uncertainty = raw_result.uncertainty.to(final_unit) | ||
temp_result.uncertainty = np.mean(raw_result.uncertainty.to( | ||
flux_unit, | ||
equivalencies=u.spectral_density(wave_spec.spectral_axis))) | ||
|
||
# Otherwise, just rely on the default specutils line_flux result | ||
else: | ||
|
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.
Why not use
np.all(np.isfinite())
combo?