Skip to content

Commit

Permalink
hotfix for cube_cut checking for valid WCS info (#70)
Browse files Browse the repository at this point in the history
* hotfix for cube_cut checking for valid WCS info

* moving astropy note to line 22
  • Loading branch information
jaymedina authored Dec 2, 2022
1 parent 9425944 commit 311488d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
12 changes: 5 additions & 7 deletions astrocut/cube_cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@

import os
import warnings

from time import time
from itertools import product
from time import time

import astropy
import astropy.units as u
import numpy as np

from astropy import wcs
from astropy.coordinates import SkyCoord
from astropy.io import fits
from astropy.time import Time

from . import __version__
from . import __version__
from .exceptions import InputWarning, InvalidQueryError

# Note: Use the astropy function if available, TODO: fix > 4.3 astropy fitting
import astropy
if astropy.utils.minversion(astropy, "4.0.2") and (float(astropy.__version__[:3]) < 4.3):
from astropy.wcs.utils import fit_wcs_from_points
else:
Expand Down Expand Up @@ -115,8 +113,8 @@ def _parse_table_info(self, product, table_data, verbose=False):
table_row = table_data[data_ind]

# Making sure we have a row with wcs info.
wcsaxes_keyword = 'WCSAXES' if product == 'SPOC' else 'WCAX3'
if table_row[wcsaxes_keyword] != 2:
wcsaxes_keyword = 'CTYPE2'
if table_row[wcsaxes_keyword] != 'DEC--TAN-SIP':
table_row = None
data_ind += 1
if data_ind == len(table_data):
Expand Down
20 changes: 10 additions & 10 deletions astrocut/tests/test_cube_cut.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import pytest
import numpy as np
from os import path

from astropy.io import fits
import astropy.units as u
import numpy as np
import pytest
from astropy import wcs
from astropy.coordinates import SkyCoord
from astropy.io import fits
from astropy.time import Time
import astropy.units as u

from .utils_for_test import create_test_ffis
from ..make_cube import CubeFactory, TicaCubeFactory
from ..cube_cut import CutoutFactory
from ..exceptions import InvalidQueryError, InputWarning
from ..exceptions import InputWarning, InvalidQueryError
from ..make_cube import CubeFactory, TicaCubeFactory
from .utils_for_test import create_test_ffis


def checkcutout(product, cutfile, pixcrd, world, csize, ecube, eps=1.e-7):
Expand Down Expand Up @@ -343,12 +343,12 @@ def test_exceptions(tmpdir, ffi_type):
cube_table = hdu[2].data

# Testing when none of the FFIs have good wcs info
wcsaxes = 'WCSAXES' if ffi_type == 'SPOC' else 'WCAX3'
cube_table[wcsaxes] = 0
wcsaxes = 'CTYPE2'
cube_table[wcsaxes] = 'N/A'
with pytest.raises(Exception, match='No FFI rows contain valid WCS keywords.') as e:
cutout_maker._parse_table_info(product=ffi_type, table_data=cube_table)
assert e.type is wcs.NoWcsKeywordsFoundError
cube_table[wcsaxes] = 2
cube_table[wcsaxes] = 'DEC--TAN-SIP'

# Testing when nans are present
cutout_maker._parse_table_info(product=ffi_type, table_data=cube_table)
Expand Down

0 comments on commit 311488d

Please sign in to comment.