Skip to content

Commit

Permalink
Maybe Dask not necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
pllim committed Feb 10, 2020
1 parent 4dd9903 commit 6d4fe3d
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions example_notebooks/cube_4d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"metadata": {},
"outputs": [],
"source": [
"from astropy import units as u\n",
"from astropy.nddata import NDData\n",
"from astropy.wcs import WCS\n",
"from ginga.misc.log import get_logger\n",
Expand Down Expand Up @@ -140,10 +141,13 @@
"import numpy as np\n",
"\n",
"pf = None # Not using FITS file pointer\n",
"cube4d = np.random.random((2, 5, 100, 200))\n",
"cube4d = np.random.random((2, 5, 100, 200)).astype(np.float32)\n",
"\n",
"# Convert to NDData.\n",
"im = NDData(cube4d, wcs=WCS(naxis=4))"
"im = NDData(cube4d, wcs=WCS(naxis=4))\n",
"\n",
"# Memory footprint\n",
"print((cube4d.size * 32 * u.bit).to(u.kB))"
]
},
{
Expand All @@ -152,9 +156,7 @@
"source": [
"**--- OR ---**\n",
"\n",
"Load an existing data cube.\n",
"\n",
"Dask support requires https://github.com/ejeschke/ginga/pull/805."
"Load an existing data cube."
]
},
{
Expand All @@ -163,21 +165,22 @@
"metadata": {},
"outputs": [],
"source": [
"import dask.array as da\n",
"from astropy.io import fits\n",
"\n",
"# This is a large cube that is 6GB.\n",
"# This is a large cube.\n",
"filename = '/redkeep/ironthrone/ssb/stginga/test_data/NRCN815A_LIN_20160115_uncal.fits'\n",
"pf = fits.open(filename, memmap=True)\n",
"\n",
"# There is no WCS assigned for UNCAL file yet.\n",
"# This is a dummy WCS.\n",
"im_wcs = WCS(pf[1].header)\n",
"\n",
"# Convert to NDData that wraps a Dask array.\n",
"# Must provide Dask with a name to avoid hashing.\n",
"# Pass memmap-ed FITS data into NDData.\n",
"# Shape is (1, 190, 2048, 2048)\n",
"im = NDData(da.from_array(pf[1].data, name='nircam_sci'), wcs=im_wcs)"
"im = NDData(pf[1].data, wcs=im_wcs)\n",
"\n",
"# Memory footprint\n",
"print((im.data.size * 32 * u.bit).to(u.GB))"
]
},
{
Expand Down Expand Up @@ -209,8 +212,6 @@
"metadata": {},
"outputs": [],
"source": [
"# Loading a fake WCS into widget sometimes gives error.\n",
"# Try reloading before giving up.\n",
"w.load_nddata(im)"
]
},
Expand Down Expand Up @@ -298,9 +299,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Display the widgets.\n",
"\n",
"*Dev notes: Seems to be a few seconds lag when clicking on new region far away from the current one on the image when testing with 6GB JWST/NIRCam \"uncal\" cube. This is probably due to Dask loading new chunks for processing. At least it did not try to load all the 6GB of data, which is a good sign.*"
"Display the widgets."
]
},
{
Expand Down

0 comments on commit 6d4fe3d

Please sign in to comment.