diff --git a/.travis.yml b/.travis.yml index 2eb4d68e..b7accf91 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/CHANGES b/CHANGES.rst similarity index 90% rename from CHANGES rename to CHANGES.rst index 12078a74..b752d2cb 100644 --- a/CHANGES +++ b/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) diff --git a/astrocut/tests/test_cube_cut.py b/astrocut/tests/test_cube_cut.py index ab756c6a..06c6b87a 100644 --- a/astrocut/tests/test_cube_cut.py +++ b/astrocut/tests/test_cube_cut.py @@ -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 @@ -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() + +