-
Notifications
You must be signed in to change notification settings - Fork 75
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
display units: fix failing tests #2132
Changes from 11 commits
c879296
970836d
c1e19b7
b4e5d3e
f6058f2
83994c8
3690143
ee12c73
c4bb23d
a41c92f
f030cce
7bda40b
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -361,8 +361,10 @@ def add_data(self, data, color=None, alpha=None, **layer_state): | |||||||||
result = super().add_data(data, color, alpha, **layer_state) | ||||||||||
|
||||||||||
if reset_plot_axes: | ||||||||||
self.state.x_display_unit = data.get_component(self.state.x_att.label).units | ||||||||||
self.state.y_display_unit = data.get_component("flux").units | ||||||||||
x_units = data.get_component(self.state.x_att.label).units | ||||||||||
y_units = data.get_component("flux").units | ||||||||||
self.state.x_display_unit = x_units if len(x_units) else None | ||||||||||
self.state.y_display_unit = y_units if len(y_units) else None | ||||||||||
Comment on lines
+366
to
+367
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 don't think len is needed.
Suggested change
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. woops, turns out it was necessary (CI fails everywhere otherwise) 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. Hmm, weird, but ok. |
||||||||||
self.set_plot_axes() | ||||||||||
|
||||||||||
self._plot_uncertainties() | ||||||||||
|
@@ -489,7 +491,8 @@ def _plot_uncertainties(self): | |||||||||
def set_plot_axes(self): | ||||||||||
# Set axes labels for the spectrum viewer | ||||||||||
flux_unit_type = "Flux density" | ||||||||||
x_unit = u.Unit(self.state.x_display_unit) | ||||||||||
x_disp_unit = self.state.x_display_unit | ||||||||||
x_unit = u.Unit(x_disp_unit) if x_disp_unit else u.dimensionless_unscaled | ||||||||||
if x_unit.is_equivalent(u.m): | ||||||||||
spectral_axis_unit_type = "Wavelength" | ||||||||||
elif x_unit.is_equivalent(u.Hz): | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -415,13 +415,20 @@ def _handle_display_units(data, use_display_units): | |
spectral_unit = self.app._get_display_unit('spectral') | ||
if not spectral_unit: | ||
return data | ||
if self.app.config == 'cubeviz' and spectral_unit == 'deg': | ||
# this happens before the correct axis is set for the spectrum-viewer | ||
# and would result in a unit-conversion error if attempting to convert | ||
# to the display units. This should only ever be temporary during | ||
# app intialization. | ||
return data | ||
flux_unit = self.app._get_display_unit('flux') | ||
# TODO: any other attributes (meta, wcs, etc)? | ||
# TODO: implement uncertainty.to upstream | ||
new_uncert = data.uncertainty.__class__(data.uncertainty.quantity.to(flux_unit)) if data.uncertainty is not None else None # noqa | ||
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. Wut... the uncertainty object cannot convert unit natively? 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. nope! I put a todo comment above, but probably should file an issue upstream. Probably in |
||
data = Spectrum1D(spectral_axis=data.spectral_axis.to(spectral_unit, | ||
u.spectral()), | ||
flux=data.flux.to(flux_unit), | ||
uncertainty=data.uncertainty.__class__(data.uncertainty.quantity.to(flux_unit))) # noqa | ||
uncertainty=new_uncert) | ||
else: # pragma: nocover | ||
raise NotImplementedError(f"converting {data.__class__.__name__} to display units is not supported") # noqa | ||
return data | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
|
||
__all__ = ['OffscreenLinesMarks', 'BaseSpectrumVerticalLine', 'SpectralLine', | ||
'SliceIndicatorMarks', 'ShadowMixin', 'ShadowLine', 'ShadowLabelFixedY', | ||
'PluginMark', 'PluginLine', 'PluginScatter', | ||
'PluginMark', 'LinesAutoUnit', 'PluginLine', 'PluginScatter', | ||
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 does not look related. 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. its needed for RTD to be able to pull in the API docs for the classes that inherit from it. |
||
'LineAnalysisContinuum', 'LineAnalysisContinuumCenter', | ||
'LineAnalysisContinuumLeft', 'LineAnalysisContinuumRight', | ||
'LineUncertainties', 'ScatterMask', 'SelectedSpaxel', 'MarkersMark'] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
|
||
|
||
__all__ = ['show_widget', 'TemplateMixin', 'PluginTemplateMixin', | ||
'ViewerPropertiesMixin', | ||
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 does not look related. 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. (same as above - needed for RTD) |
||
'BasePluginComponent', 'SelectPluginComponent', 'UnitSelectPluginComponent', | ||
'PluginSubcomponent', | ||
'SubsetSelect', 'SpatialSubsetSelectMixin', 'SpectralSubsetSelectMixin', | ||
|
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.
we might want to discuss the default option here and in
get_subsets
(but can change that anytime before merging the dev unit conversion branch into main)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.
I can see arguments both ways but being a data purist, I would want the regions to be in data unit, not display unit.