Skip to content

Commit

Permalink
Merge c59bf7a into 0ddd733
Browse files Browse the repository at this point in the history
  • Loading branch information
C. E. Brasseur committed May 7, 2019
2 parents 0ddd733 + c59bf7a commit a3426a2
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -150,4 +150,4 @@ script:
after_success:
# If coveralls.io is set up for this package, uncomment the line below.
# The coveragerc file may be customized as needed for your package.
# - if [[ $SETUP_CMD == *coverage* ]]; then coveralls --rcfile='astrocut/tests/coveragerc'; fi
- if [[ $SETUP_CMD == *coverage* ]]; then coveralls --rcfile='astrocut/tests/coveragerc'; fi
2 changes: 1 addition & 1 deletion CHANGES → CHANGES.rst
@@ -1,7 +1,7 @@
0.4 (unreleased)
----------------

- No changes yet
- Adding more unit tests and coveralls setup [#11]


0.3 (2019-05-03)
Expand Down
112 changes: 112 additions & 0 deletions astrocut/tests/test_cube_cut.py
Expand Up @@ -3,6 +3,7 @@
from astropy.io import fits
from astropy import wcs
from astropy.coordinates import SkyCoord
import astropy.units as u

from .utils_for_test import create_test_ffis
from ..make_cube import CubeFactory
Expand Down Expand Up @@ -132,3 +133,114 @@ def test_cube_cutout(tmpdir):
checkcutout(cutfile, pixcrd[i], world_coords[i], csize[i], ecube)



def test_cutout_extras(tmpdir):

# Making the test cube
cube_maker = CubeFactory()

img_sz = 10
num_im = 100

ffi_files = create_test_ffis(img_sz, num_im)
cube_file = cube_maker.make_cube(ffi_files, "make_cube-test-cube", verbose=False)

# Making the cutout
myfactory = CutoutFactory()
coord = "256.88 6.38"

###########################
# Test _parse_table_info #
###########################
cutout_size = [5, 3]
out_file = myfactory.cube_cut(cube_file, coord, cutout_size, verbose=False)
assert "256.880000_6.380000_5x3_astrocut.fits" in out_file

assert isinstance(myfactory.cube_wcs, wcs.WCS)
ra, dec = myfactory.cube_wcs.wcs.crval
assert round(ra, 4) == 250.3497
assert round(dec, 4) == 2.2809

# checking on the center coordinate too
coord = SkyCoord(256.88, 6.38, frame='icrs', unit='deg')
assert myfactory.center_coord.separation(coord) == 0

############################
# Test _get_cutout_limits #
############################
xmin, xmax = myfactory.cutout_lims[0]
ymin, ymax = myfactory.cutout_lims[1]

assert (xmax-xmin) == cutout_size[0]
assert (ymax-ymin) == cutout_size[1]

cutout_size = [5*u.pixel, 7*u.pixel]
out_file = myfactory.cube_cut(cube_file, coord, cutout_size, verbose=False)
assert "256.880000_6.380000_5x7_astrocut.fits" in out_file

xmin, xmax = myfactory.cutout_lims[0]
ymin, ymax = myfactory.cutout_lims[1]

assert (xmax-xmin) == cutout_size[0].value
assert (ymax-ymin) == cutout_size[1].value

cutout_size = [3*u.arcmin, 5*u.arcmin]
out_file = myfactory.cube_cut(cube_file, coord, cutout_size, verbose=False)
assert "256.880000_6.380000_8x15_astrocut.fits" in out_file

xmin, xmax = myfactory.cutout_lims[0]
ymin, ymax = myfactory.cutout_lims[1]

assert (xmax-xmin) == 8
assert (ymax-ymin) == 15

cutout_size = [1*u.arcsec, 5*u.arcsec]
out_file = myfactory.cube_cut(cube_file, coord, cutout_size, verbose=False)
assert "256.880000_6.380000_1x1_astrocut.fits" in out_file

xmin, xmax = myfactory.cutout_lims[0]
ymin, ymax = myfactory.cutout_lims[1]

assert (xmax-xmin) == 1
assert (ymax-ymin) == 1

#########################
# Test _get_cutout_wcs #
#########################
cutout_size = [5, 3]
out_file = myfactory.cube_cut(cube_file, coord, cutout_size, verbose=False)

cutout_wcs_dict = myfactory._get_cutout_wcs()

assert cutout_wcs_dict["1CTYP{}"][0] == 'RA---TAN-SIP'
assert cutout_wcs_dict["1CRPX{}"][0] == 1043
assert round(cutout_wcs_dict["1CRVL{}"][0], 4) == 250.3497

###########################
# Test target pixel file #
###########################

# Testing the cutout content is in test_cube_cutout
# this tests that the format of the tpf is what it should be
tpf = fits.open(out_file)

assert tpf[0].header["ORIGIN"] == 'STScI/MAST'

tpf_table = tpf[1].data
assert len(tpf_table.columns) == 12
assert "TIME" in tpf_table.columns.names
assert "FLUX" in tpf_table.columns.names
assert "FLUX_ERR" in tpf_table.columns.names
assert "FFI_FILE" in tpf_table.columns.names

cutout_img = tpf_table[0]['FLUX']
assert cutout_img.shape == (3, 5)
assert cutout_img.dtype.name == 'float32'

aperture = tpf[2].data
assert aperture.shape == (3, 5)
assert aperture.dtype.name == 'int32'

tpf.close()


0 comments on commit a3426a2

Please sign in to comment.