spacetelescope / jdaviz

JWST astronomical data analysis tools in the Jupyter platform
https://jdaviz.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
134 stars 72 forks source link

Not able to read in wavelength unit with MUSE data cubes? #2502

Open ke27whal opened 11 months ago

ke27whal commented 11 months ago

Two problems

  1. Parsing logic needs fixing, see https://github.com/spacetelescope/jdaviz/pull/2504 for the fix. 🐱
  2. Performance issue when large cube is loaded into Cubeviz. For example, when I create a second elliptical Subset (there is already a circular one), and then I use Subset Tool to rotate it, it eats up CPU resource and took a very long time (a few minutes) to update but there is no indication that anything is happening anywhere in the app. 🐱

Jdaviz component

Cubeviz

Description

Hi,

I'm trying to analyze VLT MUSE data cubes and I'm running into a problem where cubeviz is unable to recognize the wavelength units from the fits header. Opening the cube in DS9 allows me to toggle through the different wavelength bins, and looking at the header, the unit is given in CUNIT3='Angstrom.'

I was going to see if this was a display issue by trying to use the unit conversion functionality detailed in the documents, but that option is unavailable to me in the GUI (see screenshot in how to reproduce).

Also, is Cubeviz supposed to lag a bit?

Thanks for your help, Kelly

How to Reproduce

See screenshot.

github_cubeviz_error

Expected behavior

I expected to be able to have the tab for unit conversion

Browser

No response

Jupyter

jupyter notebook version 7.0.2

Software versions

No response

pllim commented 11 months ago

Thank you for reaching out to us.

unable to recognize the wavelength units from the fits header

Are you able to get anything useful only using specutils? https://specutils.readthedocs.io/en/stable/

from specutils import Spectrum1D

sp = Spectrum1D.read(filename)
sp.spectral_axis  # check the printed unit

is Cubeviz supposed to lag a bit?

Can you please clarify what you were doing when you saw the lag? Is the lag temporary or persistent?

pllim commented 11 months ago

Also to be sure I am not misunderstanding, is there an extra period in your CUNIT3 value? You said CUNIT3='Angstrom.'

ke27whal commented 11 months ago

Thank you so much for your response!

Trying to read my fits file using specutils throws me the following error:

IORegistryError                           Traceback (most recent call last)

Cell In[11], line 3

      1 from specutils import Spectrum1D

----> 3 sp = Spectrum1D.read('/Users/kewhalen/seyferts_npp/data/ngc0863/CARS_ifu_ngc0863/ADP.2016-06-17T18:47:32.888.fits')#, format='MaNGA cube')

      4 sp.spectral_axis

File ~/miniforge3/envs/jdaviz-env/lib/python3.9/site-packages/astropy/nddata/mixins/ndio.py:59, in NDDataRead.__call__(self, *args, **kwargs)

     58 def __call__(self, *args, **kwargs):

---> 59     return self.registry.read(self._cls, *args, **kwargs)

File ~/miniforge3/envs/jdaviz-env/lib/python3.9/site-packages/astropy/io/registry/core.py:213, in UnifiedInputRegistry.read(self, cls, format, cache, *args, **kwargs)

    210             path = None

    211             fileobj = args[0]

--> 213     format = self._get_valid_format(

    214         "read", cls, path, fileobj, args, kwargs

    215     )

    217 reader = self.get_reader(format, cls)

    218 data = reader(*args, **kwargs)

File ~/miniforge3/envs/jdaviz-env/lib/python3.9/site-packages/astropy/io/registry/base.py:358, in _UnifiedIORegistryBase._get_valid_format(self, mode, cls, path, fileobj, args, kwargs)

    356 if len(valid_formats) == 0:

    357     format_table_str = self._get_format_table_str(cls, mode.capitalize())

--> 358     raise IORegistryError(

    359         "Format could not be identified based on the"

    360         " file name or contents, please provide a"

    361         " 'format' argument.\n"

    362         f"The available formats are:\n{format_table_str}"

    363     )

    364 elif len(valid_formats) > 1:

    365     return self._get_highest_priority_format(mode, cls, valid_formats)

IORegistryError: Format could not be identified based on the file name or contents, please provide a 'format' argument.

The available formats are:

      Format      Read Write Auto-identify

----------------- ---- ----- -------------

      6dFGS-split  Yes    No           Yes

    6dFGS-tabular  Yes    No           Yes

    APOGEE apStar  Yes    No           Yes

   APOGEE apVisit  Yes    No           Yes

APOGEE aspcapStar  Yes    No           Yes

            ASCII  Yes    No           Yes

             ECSV  Yes    No           Yes

          HST/COS  Yes    No           Yes

         HST/STIS  Yes    No           Yes

             IPAC  Yes    No           Yes

         JWST c1d  Yes    No           Yes

         JWST s2d  Yes    No           Yes

         JWST s3d  Yes    No           Yes

         JWST x1d  Yes    No           Yes

      MUSCLES SED  Yes    No           Yes

       MaNGA cube  Yes    No           Yes

        MaNGA rss  Yes    No           Yes

     SDSS spPlate  Yes    No           Yes

SDSS-I/II spSpec  Yes    No           Yes

SDSS-III/IV spec  Yes    No           Yes

Subaru-pfsObject  Yes    No           Yes

             iraf  Yes    No           Yes

     tabular-fits  Yes   Yes           Yes

       wcs1d-fits  Yes   Yes           Yes

And, apologies, autocorrect threw the period in there. It's CUNIT3='Angstrom'

ke27whal commented 11 months ago

It lags on the order for 3-10s whenever I try to use any of the plugin tools. I have had to refresh my page a few times, as well.

pllim commented 11 months ago

I think to effectively debug this, we would need a copy of the data or something equivalent if the original data is not public. Is this from VLT MUSE archive or something? How are we able to get a copy? Thanks.

ke27whal commented 11 months ago

Yes, it's from the VLT MUSE archive.

http://archive.eso.org/wdb/wdb/adp/phase3_main/query?collection_name=MUSE&version=&object===HE%202302-0857&order_main=wavelmin%2Cfilter%2Cexp_start%2Cexptime%2Corigfile&top=10000

pllim commented 11 months ago

Thanks! Looks like the cube is a whooping 3 GB. ~I'll post more when it is done downloading...~ πŸ˜…

Filename: ADP.2016-06-17T18_47_32.888.fits
No.    Name      Ver    Type      Cards   Dimensions   Format
  0  PRIMARY       1 PrimaryHDU    1291   ()      
  1  DATA          1 ImageHDU        43   (321, 315, 3682)   float32   
  2  STAT          1 ImageHDU        43   (321, 315, 3682)   float32   
pllim commented 11 months ago

First of all, the slider tool is broken because of the wonky wavelength axis in spectrum viewer. Still investigating why spectral axis won't load. Looks like Cubeviz isn't using Spectrum1D.read after all, so thanks for checking.

Secondly, any tool that results in re-collapsing the cube (e.g., drawing a circle on the image viewer) would be laggy. Otherwise, if I just pan/zoom on the image, I do not see any lag, so please be more specific on what tool you were using and how. Maybe would also be helpful to pull up your OS memory monitoring app to make sure it is not memory swapping. This is because to collapse a 3 GB cube for the spectrum viewer would require pulling in the whole cube into memory; I saw my RAM usage jump a whole 20% during that process on load (and also waiting a long time for it).

ke27whal commented 11 months ago

Okay, great, thank you for checking.

Ahh, gotcha. Yes, I was trying to draw circles and to select a spectral region so that makes sense. Thanks for clearing that up.

pllim commented 11 months ago

So, I fixed the unit in https://github.com/spacetelescope/jdaviz/pull/2504 (feel free to try it out if you know how to install Jdaviz from an unmerged PR branch). Unfortunately the performance issues are real and not trivial to fix, so I will bring them back to the team and add info to your original post above.

Thank you for reporting this!

stscijgbot-jwql commented 2 months ago

This issue is tracked on JIRA as JDAT-3884.