Skip to content
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

lcviz cube support #2678

Merged
merged 7 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions jdaviz/components/viewer_data_select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ module.exports = {
if (this.$props.viewer.reference === 'spectrum-2d-viewer') {
multi_select = false
}
} else if (this.$props.viewer.config === 'lcviz') {
if (this.$props.viewer.reference.startsWith('image')) {
multi_select = false
}
}
return {
// default to passed values, whenever value or uncertainty are changed
Expand Down Expand Up @@ -193,14 +197,17 @@ module.exports = {
}
} else if (this.$props.viewer.config === 'lcviz') {
// TODO: generalize itemIsVisible so downstream apps can provide their own customized filters
if (this.$props.viewer.reference.startsWith('image')) {
return (item.ndims === 3 && this.dataItemInViewer(item, returnExtraItems))
}
if (item.meta._LCVIZ_EPHEMERIS !== undefined) {
if (!this.$props.viewer.reference.startsWith('flux-vs-phase:')) {
return false
}
var viewer_ephem_comp = this.$props.viewer.reference.split('flux-vs-phase:')[1].split('[')[0]
return item.meta._LCVIZ_EPHEMERIS.ephemeris == viewer_ephem_comp && this.dataItemInViewer(item, returnExtraItems)
return item.ndims === 1 && item.meta._LCVIZ_EPHEMERIS.ephemeris == viewer_ephem_comp && this.dataItemInViewer(item, returnExtraItems)
}
return this.dataItemInViewer(item, returnExtraItems)
return item.ndims === 1 && this.dataItemInViewer(item, returnExtraItems)
} else if (this.$props.viewer.config === 'imviz') {
return this.dataItemInViewer(item, returnExtraItems && !this.wcsOnlyItem(item))
}
Expand Down
7 changes: 4 additions & 3 deletions jdaviz/configs/default/plugins/plot_options/plot_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,15 +878,16 @@
if not len(self.layer.selected_obj[0]):
return
# multiselect case (but we won't check multiselect since the selection can lag behind)
data = self.layer.selected_obj[0][0].layer
layer = self.layer.selected_obj[0][0]

Check warning on line 881 in jdaviz/configs/default/plugins/plot_options/plot_options.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/default/plugins/plot_options/plot_options.py#L881

Added line #L881 was not covered by tests
else:
data = self.layer.selected_obj[0].layer
layer = self.layer.selected_obj[0]
data = layer.layer

if isinstance(data, GroupedSubset):
# don't update histogram for subsets:
return

comp = data.get_component(data.main_components[0])
comp = data.get_component(layer.state.attribute)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really equivalent to main_component[0]?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but I think its what we actually want. Shouldn't this always be the plotted data?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dunno. Further down, there is a block that calls data.get_component under some condition. Will that still be consistent?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That logic probably also could use rewriting to be more specific as well (currently only applies to 2d spectral viewers, afaik), but should not affect this at all (that is for the x-y limit determination, this is for the actual "color" axis of the image which is what should be plotted on the histogram). Feel free to find a case that breaks if you have any concerns!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not expert in Plot Options, so this is fine. I won't do this to, say, aperture photometry though, but that is irrelevant here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

layer.state.attribute is the requested column to be plotted, data.main_components[0] is just the first "main" component (which probably is the default column to be plotted, but is not general enough). For the histogram, we definitely want to plot the same data in the histogram as is shown in the image viewer itself, so I think the previous assumption is not general enough.


# TODO: further optimization could be done by caching sub_data
if self.stretch_hist_zoom_limits and (not self.layer_multiselect or len(self.layer_selected) == 1): # noqa
Expand Down
33 changes: 20 additions & 13 deletions jdaviz/configs/imviz/plugins/coords_info/coords_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,24 @@ def update_display(self, viewer, x, y):
(ImvizImageView, CubevizImageView, MosvizImageView, MosvizProfile2DView)):
self._image_viewer_update(viewer, x, y)

def _image_shape_inds(self, image):
if image.ndim == 3:
# cubeviz case
return (0, 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer you keep the ix_shape and iy_shape assignments here instead of tuples without any explanation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clarified with inline comments

elif image.ndim == 2:
return (1, 0)
else: # pragma: no cover
raise ValueError(f'does not support ndim={image.ndim}')

def _get_cube_value(self, image, arr, x, y, viewer):
if image.ndim == 3:
# cubeviz case:
return arr[int(round(x)), int(round(y)), viewer.state.slices[-1]]
elif image.ndim == 2:
return arr[int(round(y)), int(round(x))]
else: # pragma: no cover
raise ValueError(f'does not support ndim={image.ndim}')

def _image_viewer_update(self, viewer, x, y):
# Display the current cursor coordinates (both pixel and world) as
# well as data values. For now we use the first dataset in the
Expand Down Expand Up @@ -406,15 +424,7 @@ def _image_viewer_update(self, viewer, x, y):

# Extract data values at this position.
# Check if shape is [x, y, z] or [y, x] and show value accordingly.
if image.ndim == 3:
# needed for cubeviz
ix_shape = 0
iy_shape = 1
elif image.ndim == 2:
ix_shape = 1
iy_shape = 0
else: # pragma: no cover
raise ValueError(f'does not support ndim={image.ndim}')
ix_shape, iy_shape = self._image_shape_inds(image)

if (-0.5 < x < image.shape[ix_shape] - 0.5 and -0.5 < y < image.shape[iy_shape] - 0.5
and hasattr(active_layer, 'attribute')):
Expand All @@ -425,10 +435,7 @@ def _image_viewer_update(self, viewer, x, y):
elif isinstance(viewer, CubevizImageView):
arr = image.get_component(attribute).data
unit = image.get_component(attribute).units
if image.ndim == 3:
value = arr[int(round(x)), int(round(y)), viewer.state.slices[-1]]
else: # 2
value = arr[int(round(y)), int(round(x))]
value = self._get_cube_value(image, arr, x, y, viewer)
self.row1b_title = 'Value'
self.row1b_text = f'{value:+10.5e} {unit}'
self._dict['value'] = float(value)
Expand Down