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

read_spice_l2_fits fails on files with additional distortion information #208

Closed
ebuchlin opened this issue Jul 14, 2022 · 4 comments
Closed

Comments

@ebuchlin
Copy link

ebuchlin commented Jul 14, 2022

Describe the bug

read_spice_l2_fits() fails on SPICE files with additional distortion information as it considers the "WCSDVARR" ImageHDUs that are present in the FITS file in this case as windows.

To Reproduce

from sunraster.instr.spice import read_spice_l2_fits
data = read_spice_l2_fits('solo_L2_spice-n-ras_20220314T164032_V02_100663798-000.fits')

Trace:

WARNING: FITSFixedWarning: CROTA = 1.36558265159 / [deg] S/C counter-clockwise roll rel to Solar N
keyword looks very much like CROTAn but isn't. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: 'datfix' made the change 'Set MJDREF to 59652,694815 from DATEREF.
Set MJD-OBS to 59652,694815 from DATE-OBS.
Set MJD-BEG to 59652,694815 from DATE-BEG.
Set MJD-AVG to 59652,698056 from DATE-AVG.
Set MJD-END to 59652,701293 from DATE-END'. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: The WCS transformation has more axes (4) than the image it is associated with (1) [astropy.wcs.wcs]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-74-02927c7d39ea> in <module>
----> 1 raster = read_spice_l2_fits('solo_L2_spice-n-ras_20220314T164032_V02_100663798-000.fits')

~/.local/lib/python3.9/site-packages/sunraster/instr/spice.py in read_spice_l2_fits(filenames, windows, memmap, read_dumbbells)
     54         filenames = [filenames]
     55     # Read first file.
---> 56     first_cubes = _read_single_spice_l2_fits(
     57         filenames[0], windows=windows, memmap=memmap, read_dumbbells=read_dumbbells
     58     )

~/.local/lib/python3.9/site-packages/sunraster/instr/spice.py in _read_single_spice_l2_fits(filename, windows, memmap, read_dumbbells, output, spice_id)
    208                 wcs = WCS(new_header)
    209                 # Define exposure times from metadata.
--> 210                 exp_times = u.Quantity(np.zeros(hdu.data.shape[-1]) + meta.get("XPOSURE"), unit=u.s)
    211                 # Define data cube.
    212                 data = hdu.data

TypeError: unsupported operand type(s) for +: 'float' and 'NoneType'

What happened?

There are now additional "WCSDVARR" HDUs to represent additional distortion information (see the draft WCS IV paper). These are ImageHDUs, so they are not excluded by the test that has been implemented in v0.4.2 following #202, and so they are wrongly considered as spectral windows.

from astropy.io import fits
hdulist = fits.open('solo_L2_spice-n-ras_20220314T164032_V02_100663798-000.fits')
hdulist.info()
Filename: solo_L2_spice-n-ras_20220314T164032_V02_100663798-000.fits
No.    Name      Ver    Type      Cards   Dimensions   Format
  0  Ne VIII 770 - SH    1 PrimaryHDU     373   (112, 1024, 80, 1)   float32   
  1  Ne VIII 770 - LH    1 ImageHDU       374   (112, 1024, 80, 1)   float32   
  2  C III 977 - SH    1 ImageHDU       374   (112, 1024, 64, 1)   float32   
  3  C III 977 - LH    1 ImageHDU       374   (112, 1024, 64, 1)   float32   
  4  Ly Beta 1025 - SH    1 ImageHDU       374   (112, 1024, 62, 1)   float32   
  5  Ly Beta 1025 - LH    1 ImageHDU       374   (112, 1024, 62, 1)   float32   
  6  O VI 1032 - SH    1 ImageHDU       374   (112, 1024, 62, 1)   float32   
  7  O VI 1032 - LH    1 ImageHDU       374   (112, 1024, 62, 1)   float32   
  8  VARIABLE_KEYWORDS    1 BinTableHDU    305   1R x 21C   [112D, 112I, 112I, 112I, 112I, 112I, 112E, 112E, 112E, 112E, 2I, 2I, 2I, 2I, 2J, 2J, 2J, 2J, 2576A, 112D, 112D]   
  9  WCSDVARR      1 ImageHDU        26   (112,)   float64   
 10  WCSDVARR      2 ImageHDU        26   (112,)   float64   

Expected behavior

read_spice_l2_fits() should read such files with no error.

A possible solution is to exclude HDUs with name "WCSDVARR" from the list of windows. Such HDUs are not windows, so they have no XPOSURE header, hence the error.

(Of course, windows should not be named "WCSDVARR"...)

Screenshots

No response

System Details

==============================
sunpy Installation Information

General
#######
OS: Ubuntu (21.10, Linux 5.13.0-52-generic)
Arch: 64bit, (x86_64)
sunpy: 4.0.0
Installation path: /home/eric/.local/lib/python3.9/site-packages/sunpy-4.0.0.dist-info

Required Dependencies
#####################
astropy: 5.1
numpy: 1.22.4
packaging: 21.3
parfive: 1.5.1

Optional Dependencies
#####################
asdf: 2.8.1
asdf-astropy: 0.2.0
beautifulsoup4: 4.9.3
cdflib: 0.3.20
dask: 2021.1.0+dfsg
drms: 0.6.2
glymur: 0.9.9
h5netcdf: 0.11.0
h5py: 3.6.0
matplotlib: 3.5.0
mpl-animators: 1.0.0
pandas: 1.4.2
python-dateutil: 2.8.1
reproject: 0.8
scikit-image: 0.18.1
scipy: 1.8.0
sqlalchemy: 1.4.34
tqdm: 4.64.0
zeep: 4.1.0

Installation method

pip

@nabobalis
Copy link
Contributor

#215 was merged in that skips the problematic window but a formal treatment would be more useful. If future readers check the last part of the PR's comment.

@ebuchlin
Copy link
Author

ebuchlin commented Oct 7, 2022

@nabobalis should I open another issue to keep track of this, so that this issue can be closed?

@nabobalis
Copy link
Contributor

@nabobalis should I open another issue to keep track of this, so that this issue can be closed?

Sure! I was being lazy and repurposing this issue but a new one would be cleaner.

@ebuchlin
Copy link
Author

ebuchlin commented Oct 9, 2022

but a new one would be cleaner

This is now #216,

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

No branches or pull requests

2 participants