Skip to content

Commit aa6725d

Browse files
committed
Move _build_tpf, add comments about backwards compatibility
1 parent 50e979e commit aa6725d

File tree

3 files changed

+50
-47
lines changed

3 files changed

+50
-47
lines changed

astrocut/CubeCutout.py

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from . import log
1818
from .Cutout import Cutout
19-
from .exceptions import DataWarning, InvalidQueryError
19+
from .exceptions import InvalidQueryError
2020
from .utils.wcs_fitting import fit_wcs_from_points
2121

2222

@@ -64,8 +64,6 @@ class CubeCutout(Cutout, ABC):
6464
Adding extra keywords to the table header.
6565
_apply_header_inherit(hdu_list)
6666
Apply header inheritance to the cutout target pixel file.
67-
_build_tpf(cube, cutout, cutout_wcs_dict)
68-
Build the cutout target pixel file.
6967
_cutout_file(file)
7068
Make a cutout from a single cube file.
7169
cutout()
@@ -262,53 +260,15 @@ def _apply_header_inherit(self, hdu_list: fits.HDUList):
262260
for kwd, val in primary_header.items():
263261
if (kwd not in header) and (kwd not in reserved_kwds):
264262
header[kwd] = (val, primary_header.comments[kwd])
265-
266-
@abstractmethod
267-
def _build_tpf(self, cube_fits: fits.HDUList, cutout: 'CubeCutoutInstance') -> fits.HDUList:
268-
"""
269-
Build the cutout target pixel file (TPF).
270-
271-
This method is abstract and should be defined in subclasses.
272-
"""
273-
pass
274263

264+
@abstractmethod
275265
def _cutout_file(self, file: Union[str, Path, S3Path]):
276266
"""
277267
Make a cutout from a single cube file.
278268
279-
Parameters
280-
----------
281-
file : str, Path, or S3Path
282-
The path to the cube file.
269+
This method is abstract and should be defined in subclasses.
283270
"""
284-
# Read in file data
285-
cube = self._load_file_data(file)
286-
287-
# Parse table info
288-
cube_wcs = self._parse_table_info(cube[2].data)
289-
290-
# Get cutouts
291-
try:
292-
cutout = self.CubeCutoutInstance(cube, file, cube_wcs, self._has_uncertainty, self)
293-
except InvalidQueryError:
294-
warnings.warn(f'Cutout footprint does not overlap with data in {file}, skipping...', DataWarning)
295-
cube.close()
296-
return
297-
298-
# Build TPF
299-
self._build_tpf(cube, cutout)
300-
cube.close()
301-
302-
# Log coordinates
303-
log.debug('Cutout center coordinate: %s, %s', self._coordinates.ra.deg, self._coordinates.dec.deg)
304-
305-
# Get cutout WCS info
306-
max_dist, sigma = cutout.wcs_fit['WCS_MSEP'][0], cutout.wcs_fit['WCS_SIG'][0]
307-
log.debug('Maximum distance between approximate and true location: %s', max_dist)
308-
log.debug('Error in approximate WCS (sigma): %.4f', sigma)
309-
310-
# Store cutouts with filename
311-
self.cutouts_by_file[file] = cutout
271+
pass
312272

313273
def cutout(self):
314274
"""

astrocut/TessCubeCutout.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
from astropy.wcs import WCS
1212
from s3path import S3Path
1313

14-
from astrocut.exceptions import InvalidInputError
15-
1614
from . import __version__, log
1715
from .CubeCutout import CubeCutout
16+
from .exceptions import DataWarning, InvalidInputError, InvalidQueryError
1817

1918

2019
class TessCubeCutout(CubeCutout):
@@ -67,6 +66,8 @@ class TessCubeCutout(CubeCutout):
6766
as placeholders.
6867
_build_tpf(cube, cutout, cutout_wcs_dict)
6968
Build the cutout target pixel file.
69+
_cutout_file(file)
70+
Make a cutout from a single TESS cube file.
7071
write_as_tpf(output_dir, output_file)
7172
Write the cutouts to target pixel files.
7273
"""
@@ -427,6 +428,44 @@ def _build_tpf(self, cube_fits: fits.HDUList, cutout: CubeCutout.CubeCutoutInsta
427428

428429
return cutout_hdu_list
429430

431+
def _cutout_file(self, file: Union[str, Path, S3Path]):
432+
"""
433+
Make a cutout from a single cube file.
434+
435+
Parameters
436+
----------
437+
file : str, Path, or S3Path
438+
The path to the cube file.
439+
"""
440+
# Read in file data
441+
cube = self._load_file_data(file)
442+
443+
# Parse table info
444+
cube_wcs = self._parse_table_info(cube[2].data)
445+
446+
# Get cutouts
447+
try:
448+
cutout = self.CubeCutoutInstance(cube, file, cube_wcs, self._has_uncertainty, self)
449+
except InvalidQueryError:
450+
warnings.warn(f'Cutout footprint does not overlap with data in {file}, skipping...', DataWarning)
451+
cube.close()
452+
return
453+
454+
# Build TPF
455+
self._build_tpf(cube, cutout)
456+
cube.close()
457+
458+
# Log coordinates
459+
log.debug('Cutout center coordinate: %s, %s', self._coordinates.ra.deg, self._coordinates.dec.deg)
460+
461+
# Get cutout WCS info
462+
max_dist, sigma = cutout.wcs_fit['WCS_MSEP'][0], cutout.wcs_fit['WCS_SIG'][0]
463+
log.debug('Maximum distance between approximate and true location: %s', max_dist)
464+
log.debug('Error in approximate WCS (sigma): %.4f', sigma)
465+
466+
# Store cutouts with filename
467+
self.cutouts_by_file[file] = cutout
468+
430469
def write_as_tpf(self, output_dir: Union[str, Path] = '.', output_file: str = None):
431470
"""
432471
Write the cutouts to disk as target pixel files.

astrocut/cube_cut.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class CutoutFactory():
1616
SPOC (Science Processing Operations Center) and TICA (Tess Image CAlibration)
1717
full frame image cubes.
1818
19-
Future versions will include more generalized cutout functionality.
19+
This class is maintained for backwards compatibility. For maximum flexibility, we recommend using the
20+
`~astrocut.TessCubeCutout` class.
2021
"""
2122

2223
def cube_cut(
@@ -36,6 +37,9 @@ def cube_cut(
3637
file of the given size around the given coordinates. The target pixel file is formatted like
3738
a TESS pipeline target pixel file.
3839
40+
This function is maintained for backwards compatibility. For maximum flexibility, we recommend using the
41+
`~astrocut.TessCubeCutout` class.
42+
3943
Parameters
4044
----------
4145
cube_file : str

0 commit comments

Comments
 (0)