Skip to content

Commit 3cca659

Browse files
committed
Comments, reworking inheritance of method
1 parent e64a15e commit 3cca659

File tree

7 files changed

+26
-22
lines changed

7 files changed

+26
-22
lines changed

CHANGES.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,20 @@ Unreleased
55
the specified coordinates. [#166]
66
- Added ``write_as_zip`` method to ``ASDFCutout``, ``FITSCutout``, ``TessCubeCutout``, and ``TessFootprintCutout`` classes to facilitate
77
writing multiple cutouts into a single ZIP archive. [#167]
8-
- Updated the format of cube cutout filenames to include a hyphen between the dimensions (e.g., ``10-x-10`` instead of ``10x10``)
9-
for improved readability and consistency with other classes. [#168]
8+
9+
Breaking Changes
10+
^^^^^^^^^^^^^^^^
11+
12+
- Cube cutout filenames now use a hyphen between dimensions (e.g., ``10-x-10`` instead of ``10x10``). They also include unit suffixes when
13+
users request sizes as an `astropy.units.Quantity` object (e.g., ``5arcmin-x-4arcmin`` or ``30arcsec-x-20arcsec``). This change may break
14+
code that parses filenames or relies on old glob patterns. [#167]
15+
16+
Migration:
17+
18+
- Update glob patterns from ``*_<ra>_<dec>_<ny>x<nx>_astrocut.fits`` to ``*_<ra>_<dec>_*-x-*_astrocut.fits``.
19+
- If parsing filenames, adjust regex accordingly (e.g., replace ``(?P<ny>\d+)x(?P<nx>\d+)`` with
20+
``(?P<ny>\d+(?:\.\d+)?)(?P<ny_unit>arcsec|arcmin|deg|pixel|pix)?-x-(?P<nx>\d+(?:\.\d+)?)(?P<nx_unit>arcsec|arcmin|deg|pixel|pix)?``).
21+
- Prefer reading dimensions from file metadata (e.g., FITS headers) when possible to avoid filename coupling.
1022

1123

1224
1.1.0 (2025-09-15)

astrocut/asdf_cutout.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ def write_as_asdf(self, output_dir: Union[str, Path] = '.') -> List[str]:
518518
return self._write_as_format(output_format='.asdf', output_dir=output_dir)
519519

520520
def write_as_zip(self, output_dir: Union[str, Path] = '.', filename: Union[str, Path, None] = None,
521-
*, format: str = '.asdf') -> str:
521+
*, output_format: str = '.asdf') -> str:
522522
"""
523523
Package the ASDF or FITS cutouts into a zip archive without writing intermediates.
524524
@@ -530,15 +530,15 @@ def write_as_zip(self, output_dir: Union[str, Path] = '.', filename: Union[str,
530530
Name (or path) of the output zip file. If not provided, defaults to
531531
'cutouts_{YYYYmmdd_HHMMSS}.zip'. If provided without a '.zip' suffix,
532532
the suffix is added automatically.
533-
format : str, optional
533+
output_format : str, optional
534534
Either '.asdf' (default) or '.fits'. Determines which in-memory representation is zipped.
535535
536536
Returns
537537
-------
538538
str
539539
Path to the created zip file.
540540
"""
541-
fmt = format.lower().strip()
541+
fmt = output_format.lower().strip()
542542
fmt = '.' + fmt if not fmt.startswith('.') else fmt
543543
if fmt not in ('.asdf', '.fits'):
544544
raise InvalidInputError("File format must be either '.asdf' or '.fits'")
@@ -551,7 +551,7 @@ def build_entries():
551551
arcname = self._make_cutout_filename(file, fmt)
552552
yield arcname, objs[i]
553553

554-
return super().write_as_zip(output_dir=output_dir, filename=filename, build_entries=build_entries)
554+
return self._write_cutouts_to_zip(output_dir=output_dir, filename=filename, build_entries=build_entries)
555555

556556

557557
def get_center_pixel(gwcsobj: gwcs.wcs.WCS, ra: float, dec: float) -> Tuple[Tuple[int, int], WCS]:

astrocut/cutout.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,7 @@ def _obj_to_bytes(self, obj: Union[fits.HDUList, asdf.AsdfFile]) -> bytes:
193193
buf = io.BytesIO()
194194
with warnings.catch_warnings():
195195
warnings.simplefilter('ignore', fits.verify.VerifyWarning)
196-
try:
197-
obj.writeto(buf, overwrite=True, checksum=True)
198-
except TypeError:
199-
obj.writeto(buf)
196+
obj.writeto(buf, overwrite=True, checksum=True)
200197
# `AsdfFile` to bytes
201198
elif isinstance(obj, asdf.AsdfFile):
202199
buf = io.BytesIO()
@@ -208,11 +205,11 @@ def _obj_to_bytes(self, obj: Union[fits.HDUList, asdf.AsdfFile]) -> bytes:
208205

209206
return buf.getvalue()
210207

211-
def write_as_zip(
208+
def _write_cutouts_to_zip(
212209
self,
213210
output_dir: Union[str, Path] = ".",
214211
filename: Optional[Union[str, Path]] = None,
215-
build_entries: Optional[Callable[[], Iterable[Tuple[str, Any]]]] = None,
212+
build_entries: Optional[Callable[[], Iterable[Tuple[str, Any]]]] = None
216213
) -> str:
217214
"""
218215
Create a zip archive containing all cutout files without writing intermediate files.

astrocut/fits_cutout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ def build_entries():
461461
hdu = self.fits_cutouts[i]
462462
yield arcname, hdu
463463

464-
return super().write_as_zip(output_dir=output_dir, filename=filename, build_entries=build_entries)
464+
return self._write_cutouts_to_zip(output_dir=output_dir, filename=filename, build_entries=build_entries)
465465

466466
class CutoutInstance:
467467
"""

astrocut/tess_cube_cutout.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,10 @@ def write_as_zip(self, output_dir: Union[str, Path] = '.', filename: Union[str,
530530
"""
531531
def build_entries():
532532
for file, tpf in self.tpf_cutouts_by_file.items():
533-
arcname = self._make_cutout_filename(file)
533+
arcname = self._make_cutout_filename(Path(file).stem.rstrip('-cube'))
534534
yield arcname, tpf
535535

536-
return super().write_as_zip(output_dir=output_dir, filename=filename, build_entries=build_entries)
536+
return self._write_cutouts_to_zip(output_dir=output_dir, filename=filename, build_entries=build_entries)
537537

538538
class CubeCutoutInstance(CubeCutout.CubeCutoutInstance):
539539
"""

astrocut/tess_footprint_cutout.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,6 @@ def write_as_zip(self, output_dir: Union[str, Path] = '.', filename: Union[str,
253253
-------
254254
zip_path : str
255255
Path to the created zip file.
256-
257-
Notes
258-
-----
259-
This method will call `write_as_tpf` to ensure the cutout files exist on disk,
260-
then archive those files into a single zip.
261256
"""
262257
return self.tess_cube_cutout.write_as_zip(output_dir, filename)
263258

astrocut/tests/test_asdf_cutout.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def test_asdf_cutout_write_to_file(test_images, center_coord, cutout_size, tmpdi
196196
def test_asdf_cutout_write_to_zip(tmpdir, test_images, center_coord, cutout_size, output_format):
197197
# Zip ASDF representations
198198
cutout = ASDFCutout(test_images, center_coord, cutout_size)
199-
zip_path = cutout.write_as_zip(output_dir=tmpdir, format=output_format)
199+
zip_path = cutout.write_as_zip(output_dir=tmpdir, output_format=output_format)
200200
assert Path(zip_path).exists()
201201

202202
with zipfile.ZipFile(zip_path, 'r') as zf:
@@ -223,7 +223,7 @@ def test_asdf_cutout_write_to_zip_invalid_format(tmpdir, test_images, center_coo
223223
# Invalid output format for zip
224224
cutout = ASDFCutout(test_images, center_coord, cutout_size)
225225
with pytest.raises(InvalidInputError, match="File format must be either '.asdf' or '.fits'"):
226-
cutout.write_as_zip(output_dir=tmpdir, format='.invalid')
226+
cutout.write_as_zip(output_dir=tmpdir, output_format='.invalid')
227227

228228

229229
def test_asdf_cutout_lite(test_images, center_coord, cutout_size, tmpdir):

0 commit comments

Comments
 (0)