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

test_ndcube_components_after_slicing was skipped due to a bug #190

Closed
nabobalis opened this issue Nov 8, 2021 · 3 comments
Closed

test_ndcube_components_after_slicing was skipped due to a bug #190

nabobalis opened this issue Nov 8, 2021 · 3 comments

Comments

@nabobalis
Copy link
Contributor

nabobalis commented Nov 8, 2021

So the test that is failing is:

sunraster/tests/test_spectrogram.py::test_ndcube_components_after_slicing
at

sunraster/spectrogram.py:258: in __str__
    if self.time.isscalar:

with TypeError: Unsupported operand type(s) for ufunc add: 'Time,Quantity',

Situation before it fails

function = <ufunc 'add'>, method = '__call__', args = (<Time object: scale='utc' format='iso' value=2017-01-01 00:00:00.000>, <Quantity [nan] s>), ufunc_helper = <function get_converters_and_unit at 0x7f6ee0f7e040>, units = [None, Unit("s")], converters = [False, None]

The test is using:

(Pdb)  spectrogram_instrument_axes
<sunraster.spectrogram.SpectrogramCube object at 0x7ff87753a970>
SpectrogramCube
---------------
Time Period: ['2017-01-01 00:00:00.000' '2017-01-01 00:00:01.000']
Instrument axes: ['a' 'b' 'c']
Pixel dimensions: [2 2 3] pix
Longitude range: [2159.96856373 3600.        ] arcsec
Latitude range: [4.56894119e-02 1.80000000e+03] arcsec
Spectral range: [1.02e-09 1.06e-09] m
Data unit: ct

The constructed test Cube also has the same problem:

(Pdb) spectrogram_instrument_axes.data[item]
array([[[0.563]]])
(Pdb) spectrogram_instrument_axes.uncertainty[item]
UnknownUncertainty([[[0.75033326]]])
(Pdb) spectrogram_instrument_axes.mask[item]
array([[[False]]])
(Pdb) ec0
['time', 0, <Time object: scale='utc' format='iso' value=['2017-01-01 00:00:00.000']>]
(Pdb) spectrogram_instrument_axes.wcs[item]
WCS Keywords

Number of WCS axes: 3
CTYPE : 'WAVE'  'HPLT-TAN'  'HPLN-TAN'  
CRVAL : 1e-09  0.5  1.0  
CRPIX : 0.0  2.0  2.0  
PC1_1 PC1_2 PC1_3  : 1.0  0.0  0.0  
PC2_1 PC2_2 PC2_3  : 0.0  1.0  0.0  
PC3_1 PC3_2 PC3_3  : 0.0  0.0  1.0  
CDELT : 2.0000000000000002e-11  0.5  0.4  
NAXIS : 1  1  1

It goes to:

Time(self._get_axis_coord(self._time_name, self._time_loc))

and errors on self._get_axis_coord, which is from self.axis_world_coords(wcs=self.extra_coords[axis_name])[0]

Here the wcs is ExtraCoords(time ((0,)) None: TimeTableCoordinate ['time'] [None]: ['2017-01-01 00:00:00.000'])

Inside that, it errors in axis_world_coords from ndcube, at

        axes_coords = values_to_high_level_objects(
            *axes_coords, low_level_wcs=wcs)

with the inputs to that being:

(Pdb) axes_coords
[<Quantity [nan] s>]
(Pdb) wcs
<WCS(output_frame=TemporalFrame, input_frame=PixelFrame, forward_transform=Model: Tabular1D
N_inputs: 1
N_outputs: 1
Parameters: 
  points: (<Quantity [0.] pix>,)
  lookup_table: [0.] s
  method: linear
  fill_value: nan
  bounds_error: False)>

and axes_coords comes from self._generate_world_coords(pixel_corners, wcs) with the input being:

(Pdb) pixel_corners, wcs
(False, <ndcube.extra_coords.extra_coords.ExtraCoords object at 0x7fae6699d760>
ExtraCoords(time ((0,)) None: TimeTableCoordinate ['time'] [None]: ['2017-01-01 00:00:00.000']))

#184 (comment)

The problem is that the sliced extra_coords wcs return nan for the world value of the 0th pixel:

>>> sliced_cube.extra_coords["time"].wcs.pixel_to_world_values(0)
nan

where

>>> sliced_cube.extra_coords["time"].wcs
<WCS(output_frame=TemporalFrame, input_frame=PixelFrame, forward_transform=Model: Tabular1D
N_inputs: 1
N_outputs: 1
Parameters: 
  points: (<Quantity [0.] pix>,)
  lookup_table: [0.] s
  method: linear
  fill_value: nan
  bounds_error: False)>

The question is why is this happening?

@nabobalis nabobalis added the bug label Nov 8, 2021
@Cadair
Copy link
Member

Cadair commented Nov 10, 2021

kinda related to spacetelescope/gwcs#333

@Cadair
Copy link
Member

Cadair commented Nov 10, 2021

This appears to be an astropy bug with length-1 tables:

In [5]: t = Tabular1D([0]*u.pix, lookup_table=[0]*u.s)

In [6]: t
Out[6]: <Tabular1D(points=(<Quantity [0.] pix>,), lookup_table=[0.] s)>

In [7]: t(0)
/home/stuart/.virtualenvs/sunpy-dev/lib/python3.9/site-packages/scipy/interpolate/interpolate.py:2532: RuntimeWarning: invalid value encountered in true_divide
  norm_distances.append((x - grid[i]) /
Out[7]: nan

In [8]: t = Tabular1D([0,1]*u.pix, lookup_table=[0,1]*u.s)

In [9]: t(0)
Out[9]: 0.0

@nabobalis
Copy link
Contributor Author

I recall we patched this in ndcube.

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