Skip to content

Commit

Permalink
Undo units hack
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
pllim committed Sep 12, 2022
1 parent 839c6dd commit 717cb1a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 18 deletions.
5 changes: 0 additions & 5 deletions jdaviz/configs/mosviz/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,6 @@ def on_mouse_or_key_event(self, data):
attribute = active_layer.attribute
value = image.get_data(attribute)[int(round(y)), int(round(x))]
unit = image.get_component(attribute).units

# Works around https://github.com/spacetelescope/jdaviz/issues/1625
if not unit:
unit = image.meta.get('BUNIT', '')

self.label_mouseover.value = f'{value:+10.5e} {unit}'
else:
self.label_mouseover.value = ''
Expand Down
8 changes: 1 addition & 7 deletions jdaviz/configs/specviz/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,20 +491,14 @@ def set_plot_axes(self):
# flux_unit_type = data.flux.unit.physical_type.title()
flux_unit_type = "Flux density"

# Works around https://github.com/spacetelescope/jdaviz/issues/1625
flux_unit_str = data.flux.unit.to_string()
if ((not flux_unit_str) or
(self.jdaviz_app.config == 'specviz2d' and flux_unit_str == 'DN')):
flux_unit_str = data.meta.get('BUNIT', '')

if data.spectral_axis.unit.is_equivalent(u.m):
spectral_axis_unit_type = "Wavelength"
elif data.spectral_axis.unit.is_equivalent(u.pixel):
spectral_axis_unit_type = "pixel"

label_0 = f"{spectral_axis_unit_type} [{data.spectral_axis.unit.to_string()}]"
self.figure.axes[0].label = label_0
self.figure.axes[1].label = f"{flux_unit_type} [{flux_unit_str}]"
self.figure.axes[1].label = f"{flux_unit_type} [{data.flux.unit.to_string()}]"

# Make it so y axis label is not covering tick numbers.
self.figure.axes[1].label_offset = "-50"
Expand Down
3 changes: 2 additions & 1 deletion jdaviz/configs/specviz2d/plugins/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def spec2d_1d_parser(app, data_obj, data_label=None, show_in_viewer=True):

if "WAVEND" in header and "WAVSTART" in header:
step = (header["WAVEND"] - header["WAVSTART"]) / flux.size
spectral_axis = (np.arange(header["WAVSTART"], header["WAVEND"], step) * u.m).to(u.micron) # noqa: E501
spectral_axis = np.arange(header["WAVSTART"], header["WAVEND"],
step) * u.m
else:
# u.Unit("m") is used if WAVEND and WAVSTART are present so
# we use it here as well, even though the actual unit is pixels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,9 @@ def export_extract(self, **kwargs):
self.update_marks(step='ext')

trace = self._get_ext_trace()
inp_sp2d = self._get_ext_input_spectrum()

# FIXME: Passing in Quantity turns MJy into MJy2. But not passing it in gives DN.
inp_sp2d = self._get_ext_input_spectrum().flux

if self.ext_type_selected == 'Boxcar':
ext = extract.BoxcarExtract(inp_sp2d.data, trace, width=self.ext_width)
Expand Down Expand Up @@ -679,10 +681,6 @@ def export_extract_spectrum(self, add_data=False, **kwargs):

# spectrum = Spectrum1D(spectral_axis=inp_sp2d.spectral_axis, flux=spectrum.flux)

# We preserve some original metadata, as needed.
for key in ('BUNIT', ):
spectrum.meta[key] = self.trace_dataset.selected_obj.meta[key]

if add_data:
self.ext_add_results.add_results_from_plugin(spectrum, replace=False)

Expand Down

0 comments on commit 717cb1a

Please sign in to comment.