From 26c445120f25fc90feb0d32feb18514b21aaa8e3 Mon Sep 17 00:00:00 2001 From: Clara Brasseur Date: Mon, 6 May 2019 09:52:58 -0400 Subject: [PATCH 1/6] setting up for coverals --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 7de299bde07ccdddeb245bb142e5fa4fe5e8b66b Mon Sep 17 00:00:00 2001 From: Clara Brasseur Date: Mon, 6 May 2019 14:51:38 -0400 Subject: [PATCH 2/6] adding more unit tests --- astrocut/tests/test_cube_cut.py | 72 +++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/astrocut/tests/test_cube_cut.py b/astrocut/tests/test_cube_cut.py index ab756c6a..2a5f2655 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,74 @@ def test_cube_cutout(tmpdir): checkcutout(cutfile, pixcrd[i], world_coords[i], csize[i], ecube) + +def test_cutout_individual_functions(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) + + # Opening the cube file + cube = fits.open(cube_file) + myfactory = CutoutFactory() + + ########################### + # Test _parse_table_info # + ########################### + data_ind = int(len(cube[2].data)/2) # using the middle file for table info + myfactory._parse_table_info(cube[2].header, cube[2].data[data_ind]) + + 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 + + + ############################ + # Test _get_cutout_limits # + ############################ + coordinates = SkyCoord(249.5, 2.5, frame='icrs', unit='deg') + myfactory.center_coord = coordinates + + cutout_size = [5,3] + myfactory._get_cutout_limits(cutout_size) + 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] + myfactory._get_cutout_limits(cutout_size) + 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] + myfactory._get_cutout_limits(cutout_size) + xmin,xmax = myfactory.cutout_lims[0] + ymin,ymax = myfactory.cutout_lims[1] + + assert (xmax-xmin) == 9 + assert (ymax-ymin) == 15 + + cutout_size = [1*u.arcsec,5*u.arcsec] + myfactory._get_cutout_limits(cutout_size) + xmin,xmax = myfactory.cutout_lims[0] + ymin,ymax = myfactory.cutout_lims[1] + + assert (xmax-xmin) == 1 + assert (ymax-ymin) == 1 + + + + + + From 8612835d29aa9df41214c04ab2f7c344a2a9016a Mon Sep 17 00:00:00 2001 From: Clara Brasseur Date: Tue, 7 May 2019 10:52:42 -0400 Subject: [PATCH 3/6] adding a bunch more tests --- astrocut/tests/test_cube_cut.py | 90 +++++++++++++++++++++++---------- 1 file changed, 63 insertions(+), 27 deletions(-) diff --git a/astrocut/tests/test_cube_cut.py b/astrocut/tests/test_cube_cut.py index 2a5f2655..87bb83f7 100644 --- a/astrocut/tests/test_cube_cut.py +++ b/astrocut/tests/test_cube_cut.py @@ -134,7 +134,7 @@ def test_cube_cutout(tmpdir): -def test_cutout_individual_functions(tmpdir): +def test_cutout_extras(tmpdir): # Making the test cube cube_maker = CubeFactory() @@ -145,62 +145,98 @@ def test_cutout_individual_functions(tmpdir): ffi_files = create_test_ffis(img_sz, num_im) cube_file = cube_maker.make_cube(ffi_files, "make_cube-test-cube", verbose=False) - # Opening the cube file - cube = fits.open(cube_file) + # Making the cutout myfactory = CutoutFactory() + coord = SkyCoord(256.88, 6.38, frame='icrs', unit='deg') ########################### # Test _parse_table_info # ########################### - data_ind = int(len(cube[2].data)/2) # using the middle file for table info - myfactory._parse_table_info(cube[2].header, cube[2].data[data_ind]) - + 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 - ############################ # Test _get_cutout_limits # ############################ - coordinates = SkyCoord(249.5, 2.5, frame='icrs', unit='deg') - myfactory.center_coord = coordinates - - cutout_size = [5,3] - myfactory._get_cutout_limits(cutout_size) - xmin,xmax = myfactory.cutout_lims[0] - ymin,ymax = myfactory.cutout_lims[1] + 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] - myfactory._get_cutout_limits(cutout_size) - xmin,xmax = myfactory.cutout_lims[0] - ymin,ymax = myfactory.cutout_lims[1] + 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] - myfactory._get_cutout_limits(cutout_size) - xmin,xmax = myfactory.cutout_lims[0] - ymin,ymax = myfactory.cutout_lims[1] + 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 - assert (xmax-xmin) == 9 + 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] - myfactory._get_cutout_limits(cutout_size) - xmin,xmax = myfactory.cutout_lims[0] - ymin,ymax = myfactory.cutout_lims[1] + 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() From 70a3ee2c978abd71bf3414eee315701c6f203aeb Mon Sep 17 00:00:00 2001 From: Clara Brasseur Date: Tue, 7 May 2019 11:11:34 -0400 Subject: [PATCH 4/6] pep8 and one more test --- astrocut/tests/test_cube_cut.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/astrocut/tests/test_cube_cut.py b/astrocut/tests/test_cube_cut.py index 87bb83f7..06c6b87a 100644 --- a/astrocut/tests/test_cube_cut.py +++ b/astrocut/tests/test_cube_cut.py @@ -147,7 +147,7 @@ def test_cutout_extras(tmpdir): # Making the cutout myfactory = CutoutFactory() - coord = SkyCoord(256.88, 6.38, frame='icrs', unit='deg') + coord = "256.88 6.38" ########################### # Test _parse_table_info # @@ -161,6 +161,10 @@ def test_cutout_extras(tmpdir): 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 # ############################ @@ -231,11 +235,11 @@ def test_cutout_extras(tmpdir): cutout_img = tpf_table[0]['FLUX'] assert cutout_img.shape == (3, 5) - assert cutout_img.dtype.name =='float32' + assert cutout_img.dtype.name == 'float32' aperture = tpf[2].data assert aperture.shape == (3, 5) - assert aperture.dtype.name =='int32' + assert aperture.dtype.name == 'int32' tpf.close() From 6c5fc027d8d6593acdc5e45e9f7073deda22f6f0 Mon Sep 17 00:00:00 2001 From: Clara Brasseur Date: Tue, 7 May 2019 11:26:46 -0400 Subject: [PATCH 5/6] changelog --- CHANGES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 12078a74..b752d2cb 100644 --- a/CHANGES +++ b/CHANGES @@ -1,7 +1,7 @@ 0.4 (unreleased) ---------------- -- No changes yet +- Adding more unit tests and coveralls setup [#11] 0.3 (2019-05-03) From c59bf7aba2df50596b99c15a46bd8cc7c1c276c5 Mon Sep 17 00:00:00 2001 From: Clara Brasseur Date: Tue, 7 May 2019 11:27:51 -0400 Subject: [PATCH 6/6] making changelog have the expexted filename --- CHANGES => CHANGES.rst | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename CHANGES => CHANGES.rst (100%) diff --git a/CHANGES b/CHANGES.rst similarity index 100% rename from CHANGES rename to CHANGES.rst