Skip to content

Commit

Permalink
Fix slice with different spectral_axis_index, add specutils_format kw…
Browse files Browse the repository at this point in the history
…arg to cubeviz parser
  • Loading branch information
rosteen committed Mar 19, 2024
1 parent 274d1ea commit 65b00e6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
18 changes: 17 additions & 1 deletion jdaviz/configs/cubeviz/plugins/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


@data_parser_registry("cubeviz-data-parser")
def parse_data(app, file_obj, data_type=None, data_label=None):
def parse_data(app, file_obj, data_type=None, data_label=None, specutils_format=None):
"""
Attempts to parse a data file and auto-populate available viewers in
cubeviz.
Expand All @@ -37,6 +37,11 @@ def parse_data(app, file_obj, data_type=None, data_label=None):
The data type used to explicitly differentiate parsed data.
data_label : str, optional
The label to be applied to the Glue data component.
specutils_format : str, optional
Optional format string to pass to Spectrum1D.read(), see
https://specutils.readthedocs.io/en/stable/spectrum1d.html#list-of-loaders
for valid format strings. Useful for processed files that may not include
the original headers with information used to auto-identify.
"""

flux_viewer_reference_name = app._jdaviz_helper._default_flux_viewer_reference_name
Expand Down Expand Up @@ -67,6 +72,17 @@ def parse_data(app, file_obj, data_type=None, data_label=None):
spectrum_viewer_reference_name=spectrum_viewer_reference_name)
return

elif specutils_format is not None:
sc = Spectrum1D.read(file_obj, format=specutils_format)
_parse_spectrum1d_3d(
app, sc, data_label=data_label,
flux_viewer_reference_name=flux_viewer_reference_name,
spectrum_viewer_reference_name=spectrum_viewer_reference_name,
uncert_viewer_reference_name=uncert_viewer_reference_name
)
app.get_tray_item_from_name("Spectral Extraction").disabled_msg = ""
return

file_name = os.path.basename(file_obj)

with fits.open(file_obj) as hdulist:
Expand Down
2 changes: 0 additions & 2 deletions jdaviz/configs/cubeviz/plugins/slice/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def _initialize_location(self, *args):
# initialize value_unit (this has to wait until data is loaded to an existing
# slice_indicator_viewer, so we'll keep trying until it is set - after that, changes
# will be handled by a change to global display units)
print("Initializing slice location")
if not self.value_unit:
for viewer in self.slice_indicator_viewers:
# ignore while x_display_unit is unset or still degrees (before data transpose)
Expand Down Expand Up @@ -311,7 +310,6 @@ def _on_snap_to_slice_changed(self, event):
@observe('show_indicator', 'show_value')
def _on_setting_changed(self, event):
msg = SliceToolStateMessage({event['name']: event['new']}, viewer=None, sender=self)
print(msg)
self.session.hub.broadcast(msg)

def vue_goto_first(self, *args):
Expand Down
13 changes: 11 additions & 2 deletions jdaviz/configs/cubeviz/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,19 @@ def _set_slice_indicator_value(self, value):


class WithSliceSelection:
@property
@cached_property
def slice_index(self):
# index in state.slices corresponding to the slice axis
return 2
for layer in self.layers:
try:
data_obj = layer.layer.data
return data_obj.meta['spectral_axis_index']
except (AttributeError, KeyError):
raise
else:
break
else:
return 2

@property
def slice_component_label(self):
Expand Down

0 comments on commit 65b00e6

Please sign in to comment.