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

[EXP] Example notebook to load large 4D cube #110

Closed
wants to merge 4 commits into from

Conversation

pllim
Copy link
Member

@pllim pllim commented Feb 6, 2020

DO NOT MERGE YET

This example notebook illustrate how one can load a data cube into a widget and:

  1. Have a slider to see desired slice.
  2. Have a plot to drill through the slice at a data point you click on. (This one can have some lag when you slice through a big cube at points that are not contiguous in memory.)

It also attempts to load a large TESS or JWST/NIRCam cube (the experimental part) using Dask support in ejeschke/ginga#805 and without.

p.s. I ended up using notebook partly due to ejeschke/ginga#824 but mainly due to JWST's investment in notebook analysis.

p.p.s. I also concluded that Dask is not necessary if you stick to FITS memmap.

Example screenshots

JWST/NIRCam:

Screenshot from 2020-02-10 15-49-51

TESS:

widget_4d_tess_cube

TODO

cc @hcferguson and @larrybradley

example_notebooks/cube_4d.ipynb Outdated Show resolved Hide resolved
@ejeschke
Copy link
Contributor

ejeschke commented Feb 7, 2020

It takes way too long is locking up the computer a little.

What happens when you try to load a slice from a command line python session. i.e. Just navigate to the slice and then use numpy style slicing on the slice. Something like

data_2d = (extract 2D slice)
ht, wd = data_2d.shape
res = data_2d[0:ht:10, 0:wd:10]

Does this also take a lot of time?

@pllim

This comment has been minimized.

@pllim
Copy link
Member Author

pllim commented Feb 7, 2020

@ejeschke , I tracked this down to the transpose operation, which is out of scope for Ginga. I have a detailed write-up at ejeschke/ginga#805 (comment) . Sorry for the noise!

"source": [
"# Loading a fake WCS into widget sometimes gives error.\n",
"# Try reloading before giving up.\n",
"w.load_nddata(im)"
Copy link
Member Author

Choose a reason for hiding this comment

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

The first time I call this, I get this error. But when I rerun the cell subsequently, it goes way. @ejeschke , do you know why?

2020-02-07 13:05:18,025 | E | Callback.py:172 (_do_callbacks) |
  Error making callback 'cursor-changed': DEC (2048.500000) > 90.0
2020-02-07 13:05:18,026 | E | Callback.py:173 (_do_callbacks) | Traceback:
  File ".../ginga/misc/Callback.py", line 156, in _do_callbacks
    res = method(*cb_args, **cb_kwargs)

  File ".../astrowidgets/core.py", line 214, in _mouse_move_cb
    raDegToString(ra), decDegToString(dec))

  File ".../ginga/util/wcs.py", line 137, in decDegToString
    sign, dec_degree, dec_min, dec_sec = degToDms(dec_deg)

  File ".../ginga/util/wcs.py", line 81, in degToDms
    assert dec <= 90, WCSError("DEC (%f) > 90.0" % (dec))

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a WCS check that we probably should look at. It's just trying to format the coordinates to string values and finding an invalid DEC. Even though this is a load operation, the formatting happens because of a callback in the viewer when the image changes. Not sure why it wouldn't occur again if you re-execute the cell, but it might depend on where it thinks the cursor is WRT the window.

"outputs": [],
"source": [
"# If plot shows, rerun cell to hide it.\n",
"ax = plt.gca();\n",
Copy link
Member Author

Choose a reason for hiding this comment

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

@mwcraig , do you know any notebook tricks to not show the Matplotlib window in this cell? It ways show on first run, but then disappears in subsequent runs in the same session.

Choose a reason for hiding this comment

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

Hi, I think this works:
plt.ioff()

I've been using a version of this code in a notebook I've made for displaying HETDEX data cubes. I had to switch the axis around.

https://github.com/HETDEX/hetdex_api/blob/master/hetdex_api/cube_widget.py

Copy link
Member Author

Choose a reason for hiding this comment

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

The plot doesn't seem to show at the wrong place for me anymore either; perhaps something was fixed upstream. Thanks for letting us know!

Switching axis is probably normal since images taken with different instruments/telescopes have different formats.

@pllim

This comment has been minimized.

@ejeschke
Copy link
Contributor

ejeschke commented Feb 8, 2020

If you add a logging debug message at the beginning of that handler, does it show it being executed?

@pllim
Copy link
Member Author

pllim commented Feb 10, 2020

does it show it being executed?

@ejeschke , thanks for the tip! I inserted some debugging logs, and turns out it was choking at decDegToString(dec) conversion.

@ejeschke
Copy link
Contributor

inserted some debugging logs, and turns out it was choking at decDegToString(dec) conversion

I think this could be a general problem in Ginga noted here, which could use some attention at a hack session sometime. WCS is tricky that way: when it's broken, you want to know it's broken, but then again you don't want to be nagged that its broken. 😺

@pllim pllim changed the title [WIP] Example notebook to load large 4D cube [EXP] Example notebook to load large 4D cube Feb 10, 2020
@pllim pllim requested a review from eteq February 10, 2020 22:12
@pllim
Copy link
Member Author

pllim commented Dec 8, 2020

I am not sure if I'll ever get that "feedback from stakeholders," so @mwcraig , if you think this should go in, then I'll squash the commits. Otherwise, I'll just leave it open. cc @eteq

Base automatically changed from master to main March 9, 2021 22:47
@pllim pllim closed this Jun 16, 2023
@pllim pllim deleted the viz-tess-cube branch June 16, 2023 15:11
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.

None yet

3 participants