Skip to content

Commit

Permalink
quick fixes for style and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
snbianco committed May 22, 2024
1 parent 4fde345 commit 6af5564
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion astrocut/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions astrocut/asdf_cutouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
18 changes: 9 additions & 9 deletions astrocut/tests/test_asdf_cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.):
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion docs/astrocut/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 6af5564

Please sign in to comment.