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

Update 1D Profile viewer to use wcsaxes for plotting and add sliders #2167

Closed
wants to merge 14 commits into from
Closed

Update 1D Profile viewer to use wcsaxes for plotting and add sliders #2167

wants to merge 14 commits into from

Conversation

kakirastern
Copy link

Description

To replace #2156.

Tasks accomplished with this PR:

  1. Update the existing glue's 1D Profile viewer to use astropy's wcsaxes for plotting.
  2. Add a 'slice' function option to the 1D Profile to enable plotting a 1D spectrum of a data cube (e.g. an IRIS raster data cube) at a position picked out by glue-solar's pixel extraction tool.
  3. Add sliders to 1D Profile viewer to update plot.
  4. Enable deletion of BaseData type data so that now the dataset in the data collection generated by glue-solar's pixel extraction tool can be deleted.

@codecov
Copy link

codecov bot commented Aug 13, 2020

Codecov Report

Merging #2167 into master will decrease coverage by 0.14%.
The diff coverage is 79.05%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2167      +/-   ##
==========================================
- Coverage   87.89%   87.74%   -0.15%     
==========================================
  Files         246      248       +2     
  Lines       22764    22912     +148     
==========================================
+ Hits        20009    20105      +96     
- Misses       2755     2807      +52     
Impacted Files Coverage Δ
glue/viewers/image/qt/data_viewer.py 100.00% <ø> (ø)
glue/viewers/image/qt/profile_viewer_tool.py 23.91% <ø> (+0.50%) ⬆️
glue/viewers/image/qt/slice_widget.py 71.87% <50.00%> (-0.76%) ⬇️
glue/viewers/profile/qt/options_widget.py 76.59% <54.54%> (-23.41%) ⬇️
glue/viewers/profile/qt/slice_widget.py 70.37% <70.37%> (ø)
glue/viewers/profile/state.py 95.28% <86.84%> (-3.55%) ⬇️
glue/app/qt/layer_tree_widget.py 80.22% <100.00%> (ø)
glue/core/data.py 90.64% <100.00%> (ø)
glue/utils/wcs.py 100.00% <100.00%> (ø)
glue/viewers/common/qt/data_slice_widget.py 83.21% <100.00%> (ø)
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6634973...462c534. Read the comment docs.

Copy link
Member

@astrofrog astrofrog left a comment

Choose a reason for hiding this comment

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

This is looking good! In addition to the comments below:

glue/app/qt/layer_tree_widget.py Outdated Show resolved Hide resolved
glue/core/visual.py Outdated Show resolved Hide resolved
glue/viewers/image/qt/data_viewer.py Outdated Show resolved Hide resolved
glue/viewers/matplotlib/state.py Outdated Show resolved Hide resolved
glue/viewers/profile/layer_artist.py Outdated Show resolved Hide resolved
glue/viewers/profile/state.py Show resolved Hide resolved
@kakirastern
Copy link
Author

There are also changes here that add the pixel extraction to the image viewer by default, which I'm not sure we want to do yet?

Yeah, I could revert the changes made regarding the pixel extraction tool, but I would like to add the image to the glue repo so we could use it in glue-solar... Would that be okay?

@kakirastern
Copy link
Author

Removed pixel extraction tool code, but kept the new image for glue-solar use.

@kakirastern
Copy link
Author

@astrofrog PR ready for another review

@Cadair
Copy link
Contributor

Cadair commented Aug 20, 2020

I have noticed two major usability issues with this:

  1. When you move the sliders the view changes, it would be good if you zoom in to a region of interest and then move the sliders, the view stays where you put it.
  2. When the function isn't slice, the sliders shouldn't be visible. This will really confuse people if they are there and useless.

@kakirastern
Copy link
Author

So have just updated the 1D Profile viewer modules to show spectra as profile plots.

Regarding the comments:

I have noticed two major usability issues with this:

  1. When you move the sliders the view changes, it would be good if you zoom in to a region of interest and then move the sliders, the view stays where you put it.
  2. When the function isn't slice, the sliders shouldn't be visible. This will really confuse people if they are there and useless.

These will involve some deep changes and hence will need some time to accomplish.

@kakirastern
Copy link
Author

But I reckon we could enhance this PR with regards to #2167 (comment) in a separate PR at a later stage.

@kakirastern
Copy link
Author

Turned out the code I wrote was only working in this case only if one tweaks the opacity slider. (And it was working fine for sequentially stacked IRIS Level 2 datacubes.) And I have just fixed the underlying bugs so it is working fine for the typical FITS files containing data cubes as well. See the following for a demo:

Screenshot 2020-08-21 at 2 04 58 AM

@kakirastern
Copy link
Author

Just added code to hide the extra sliders in the 1D Profile viewer's options widget when we have

self.viewer_state != 'slice'

@astrofrog
Copy link
Member

This is looking good! I did run into an issue with the controls in the lower left when changing the x axis:

Screenshot 2020-08-24 at 09 30 06

Do you see this too or shall I provide a data file to replicate this?

glue/viewers/image/qt/slice_widget.py Outdated Show resolved Hide resolved
glue/viewers/profile/layer_artist.py Outdated Show resolved Hide resolved
glue/viewers/profile/qt/options_widget.py Outdated Show resolved Hide resolved
@kakirastern
Copy link
Author

This is looking good! I did run into an issue with the controls in the lower left when changing the x axis:

Screenshot 2020-08-24 at 09 30 06

Do you see this too or shall I provide a data file to replicate this?

Yeah, did you use the "spectrum tool" button? It is a known issue and I have a fix for it which I can implement it soon. I did meant to ask you but didn't get a chance to yet.

@kakirastern
Copy link
Author

Yeah, did you use the "spectrum tool" button? It is a known issue and I have a fix for it which I can implement it soon. I did meant to ask you but didn't get a chance to yet.

Just patched this error. Actually I was baffled by why it was the case before as @Cadair never saw the extra sliders but I could. It was because he was using the drag-and-drop action to initiate the 1D Profile viewer. To tackle this error from using the spectrum tool button, I have just removed the code snippets that would cause such an issue in the commit da82536.

Copy link
Member

@astrofrog astrofrog left a comment

Choose a reason for hiding this comment

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

This is almost good to go! A few usability issues:

  • Currently the subset profiles don't seem to be right in slice mode, for instance if I make a small subset and push the sliders to the edge of the dataset then the subset profile should be empty/not shown:

Screenshot 2020-09-01 at 13 08 46

  • Currently I can't get this to work with 2-d datasets - this used to work for non slice modes but appears broken for all modes now.

  • The font size in the profile viewer doesn't seem to be the same as for the image viewer:

Screenshot 2020-09-01 at 13 03 51

I'll review the code in detail below.

glue/viewers/image/qt/profile_viewer_tool.py Outdated Show resolved Hide resolved
glue/viewers/profile/layer_artist.py Outdated Show resolved Hide resolved
glue/viewers/profile/qt/options_widget.py Outdated Show resolved Hide resolved
elif self._sliders[i] is None:
slices.append(0)

self.viewer_state.slices = slices
Copy link
Member

Choose a reason for hiding this comment

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

I think in future we'll want to try and avoid duplication with the image viewer - I can investigate once we add this to the 3-d viewer (to visualize >3-d datasets)

Copy link
Author

Choose a reason for hiding this comment

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

Sure

glue/viewers/profile/state.py Outdated Show resolved Hide resolved
glue/viewers/profile/state.py Show resolved Hide resolved
glue/viewers/profile/state.py Show resolved Hide resolved
glue/viewers/profile/viewer.py Outdated Show resolved Hide resolved
@kakirastern
Copy link
Author

Have made the changes according to the suggestions given. PR is ready for another review.

Copy link
Member

@astrofrog astrofrog left a comment

Choose a reason for hiding this comment

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

Looks good to me! I'm now going to be a bit annoying and ask if you could add a test - a lot of the code here isn't covered by the test suite since there isn't a test for the profile viewer in slice mode. There are other tests in glue/viewers/profile/qt/tests you could perhaps start from ?

if force or any(prop in changed for prop in ('layer', 'slices', 'x_att', 'x_att_pixel', 'attribute',
'function', 'normalize', 'v_min', 'v_max', 'visible')):
self._update_visual_attributes()
self._calculate_profile(reset=True)
Copy link
Member

Choose a reason for hiding this comment

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

For other viewers the approach is instead to do:

self._calculate_profile(reset=True)
force=True

which ensures the visual properties are updated next. Maybe switch to this approach?

Copy link
Author

Choose a reason for hiding this comment

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

Sure

Copy link
Author

Choose a reason for hiding this comment

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

Tried changing to

    self._calculate_profile(reset=True)
    self._update_profile(force=True)

But error was thrown upon attempting to view via 1D Profile viewer as data cannot be added for some reason...

glue/viewers/profile/state.py Outdated Show resolved Hide resolved
glue/viewers/profile/tests/test_state.py Outdated Show resolved Hide resolved
@kakirastern
Copy link
Author

Looks good to me! I'm now going to be a bit annoying and ask if you could add a test - a lot of the code here isn't covered by the test suite since there isn't a test for the profile viewer in slice mode. There are other tests in glue/viewers/profile/qt/tests you could perhaps start from ?

Yup, sure. I could add some unit tests for the CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants