From 6af5564085e2df9081447f0c8100b36540645330 Mon Sep 17 00:00:00 2001 From: Sam Bianco Date: Wed, 22 May 2024 16:08:16 -0400 Subject: [PATCH] quick fixes for style and tests --- astrocut/__init__.py | 2 +- astrocut/asdf_cutouts.py | 8 ++++---- astrocut/tests/test_asdf_cut.py | 18 +++++++++--------- docs/astrocut/index.rst | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/astrocut/__init__.py b/astrocut/__init__.py index 594dc527..fc30bdd3 100644 --- a/astrocut/__init__.py +++ b/astrocut/__init__.py @@ -27,4 +27,4 @@ class UnsupportedPythonError(Exception): from .cutouts import fits_cut, img_cut, normalize_img # noqa from .cutout_processing import (path_to_footprints, center_on_path, # noqa CutoutsCombiner, build_default_combine_function) # noqa - from .asdf_cutouts import asdf_cut, get_center_pixel + from .asdf_cutouts import asdf_cut, get_center_pixel # noqa diff --git a/astrocut/asdf_cutouts.py b/astrocut/asdf_cutouts.py index 19a64796..ba85aac2 100644 --- a/astrocut/asdf_cutouts.py +++ b/astrocut/asdf_cutouts.py @@ -76,9 +76,9 @@ def get_center_pixel(gwcsobj: gwcs.wcs.WCS, ra: float, dec: float) -> tuple: def _get_cutout(data: asdf.tags.core.ndarray.NDArrayType, coords: Union[tuple, SkyCoord], - wcs: astropy.wcs.wcs.WCS = None, size: int = 20, outfile: str = "example_roman_cutout.fits", - write_file: bool = True, fill_value: Union[int, float] = np.nan, - gwcsobj: gwcs.wcs.WCS = None) -> astropy.nddata.Cutout2D: + wcs: astropy.wcs.wcs.WCS = None, size: int = 20, outfile: str = "example_roman_cutout.fits", + write_file: bool = True, fill_value: Union[int, float] = np.nan, + gwcsobj: gwcs.wcs.WCS = None) -> astropy.nddata.Cutout2D: """ Get a Roman image cutout. @@ -286,4 +286,4 @@ def asdf_cut(input_file: str, ra: float, dec: float, cutout_size: int = 20, # create the 2d image cutout return _get_cutout(data, pixel_coordinates, wcs, size=cutout_size, outfile=output_file, - write_file=write_file, fill_value=fill_value, gwcsobj=gwcsobj) + write_file=write_file, fill_value=fill_value, gwcsobj=gwcsobj) diff --git a/astrocut/tests/test_asdf_cut.py b/astrocut/tests/test_asdf_cut.py index 0193674d..3b3f4e5b 100644 --- a/astrocut/tests/test_asdf_cut.py +++ b/astrocut/tests/test_asdf_cut.py @@ -13,7 +13,7 @@ from astropy.wcs.utils import pixel_to_skycoord from gwcs import wcs from gwcs import coordinate_frames as cf -from astrocut.asdf_cutouts import get_center_pixel, get_cutout, asdf_cut, _slice_gwcs, _get_cloud_http +from astrocut.asdf_cutouts import get_center_pixel, asdf_cut, _get_cutout, _slice_gwcs, _get_cloud_http def make_wcs(xsize, ysize, ra=30., dec=45.): @@ -137,7 +137,7 @@ def test_get_cutout(output, fakedata, quantity): data = data.value # create cutout - cutout = get_cutout(data, skycoord, wcs, size=10, outfile=output_file) + cutout = _get_cutout(data, skycoord, wcs, size=10, outfile=output_file) assert_same_coord(5, 10, cutout, wcs) @@ -185,7 +185,7 @@ def test_fail_write_asdf(fakedata, output): data, gwcs = fakedata skycoord = gwcs(25, 25, with_units=True) wcs = WCS(gwcs.to_fits_sip()) - get_cutout(data, skycoord, wcs, size=10, outfile=output_file) + _get_cutout(data, skycoord, wcs, size=10, outfile=output_file) def test_cutout_nofile(make_file, output): @@ -217,7 +217,7 @@ def test_cutout_poles(makefake): wcs = WCS(gwcs.to_fits_sip()) # get cutout - cutout = get_cutout(data, cc, wcs, size=50, write_file=False) + cutout = _get_cutout(data, cc, wcs, size=50, write_file=False) assert_same_coord(5, 10, cutout, wcs) # check cutout contains all data @@ -232,7 +232,7 @@ def test_fail_cutout_outside(fakedata): with pytest.raises(RuntimeError, match='Could not create 2d cutout. The requested ' 'cutout does not overlap with the original image'): - get_cutout(data, cc, wcs, size=50, write_file=False) + _get_cutout(data, cc, wcs, size=50, write_file=False) def assert_same_coord(x, y, cutout, wcs): @@ -251,7 +251,7 @@ def test_partial_cutout(makefake, asint, fill): wcs = WCS(gwcs.to_fits_sip()) cc = coord.SkyCoord(29.999, 44.998, unit=u.degree) - cutout = get_cutout(data, cc, wcs, size=50, write_file=False, fill_value=fill) + cutout = _get_cutout(data, cc, wcs, size=50, write_file=False, fill_value=fill) assert cutout.shape == (50, 50) if asint: assert -9999 in cutout.data @@ -266,7 +266,7 @@ def test_bad_fill(makefake): wcs = WCS(gwcs.to_fits_sip()) cc = coord.SkyCoord(29.999, 44.998, unit=u.degree) with pytest.raises(ValueError, match='fill_value is inconsistent with the data type of the input array'): - get_cutout(data, cc, wcs, size=50, write_file=False) + _get_cutout(data, cc, wcs, size=50, write_file=False) def test_cutout_raedge(makefake): @@ -284,7 +284,7 @@ def test_cutout_raedge(makefake): wcs = WCS(gg.to_fits_sip()) # get cutout - cutout = get_cutout(data, cc, wcs, size=100, write_file=False) + cutout = _get_cutout(data, cc, wcs, size=100, write_file=False) assert_same_coord(5, 10, cutout, wcs) # assert the RA cutout bounds are > 359 and < 0 @@ -299,7 +299,7 @@ def test_slice_gwcs(fakedata): skycoord = gwcsobj(250, 250) wcs = WCS(gwcsobj.to_fits_sip()) - cutout = get_cutout(data, skycoord, wcs, size=50, write_file=False) + cutout = _get_cutout(data, skycoord, wcs, size=50, write_file=False) sliced = _slice_gwcs(gwcsobj, cutout.slices_original) diff --git a/docs/astrocut/index.rst b/docs/astrocut/index.rst index fd9083b7..f21f2833 100644 --- a/docs/astrocut/index.rst +++ b/docs/astrocut/index.rst @@ -373,7 +373,7 @@ The function `asdf_cut` performs a cutout of an ASDF file and returns the result >>> from astropy.coordinates import SkyCoord >>> from astropy.io import fits - >>> input_file = # Path to local ASDF file or URI + >>> input_file = "" # Path to local ASDF file or URI >>> center_coord = SkyCoord("80.15189743 29.74561219", unit='deg')