22
33"""This module implements the cutout functionality."""
44
5- from typing import Literal , Union
5+ from pathlib import Path
6+ from typing import Literal , Optional , Union , List , Tuple
7+
8+ import astropy .units as u
9+ import numpy as np
10+ from astropy .coordinates import SkyCoord
11+ from s3path import S3Path
612
713from .TessCubeCutout import TessCubeCutout
814
@@ -20,18 +26,11 @@ class CutoutFactory():
2026 `~astrocut.TessCubeCutout` class.
2127 """
2228
23- def cube_cut (
24- self ,
25- cube_file ,
26- coordinates ,
27- cutout_size ,
28- product = "SPOC" ,
29- target_pixel_file = None ,
30- output_path = "." ,
31- memory_only = False ,
32- threads : Union [int , Literal ["auto" ]] = 1 ,
33- verbose = False ,
34- ):
29+ def cube_cut (self , cube_file : Union [str , Path , S3Path ], coordinates : Union [SkyCoord , str ],
30+ cutout_size : Union [int , np .ndarray , u .Quantity , List [int ], Tuple [int ]],
31+ product : str = 'SPOC' , target_pixel_file : Optional [str ] = None ,
32+ output_path : Union [str , Path ] = '.' , memory_only : bool = False ,
33+ threads : Union [int , Literal ["auto" ]] = 1 , verbose : bool = False ):
3534 """
3635 Takes a cube file (as created by `~astrocut.CubeFactory`), and makes a cutout target pixel
3736 file of the given size around the given coordinates. The target pixel file is formatted like
@@ -79,9 +78,10 @@ def cube_cut(
7978
8079 Returns
8180 -------
82- response: string or None
83- If successful, returns the path to the target pixel file,
84- if unsuccessful returns None.
81+ response: string or `~astropy.io.fits.HDUList` or None
82+ If successful, returns the target pixel file as an `~astropy.io.fits.HDUList` object,
83+ or the path to the target pixel file if saved to disk.
84+ If unsuccessful returns None.
8585 """
8686 cube_cutout = TessCubeCutout (input_files = cube_file ,
8787 coordinates = coordinates ,
@@ -102,3 +102,75 @@ def cube_cut(
102102
103103 return cube_cutout .write_as_tpf (output_dir = output_path ,
104104 output_file = target_pixel_file )[0 ]
105+
106+
107+
108+ def cube_cut (cube_file : Union [str , Path , S3Path ], coordinates : Union [SkyCoord , str ],
109+ cutout_size : Union [int , np .ndarray , u .Quantity , List [int ], Tuple [int ]],
110+ product : str = 'SPOC' , target_pixel_file : Optional [str ] = None ,
111+ output_path : Union [str , Path ] = '.' , memory_only : bool = False ,
112+ threads : Union [int , Literal ["auto" ]] = 1 , verbose : bool = False ):
113+ """
114+ Takes a cube file (as created by `~astrocut.CubeFactory`), and makes a cutout target pixel
115+ file of the given size around the given coordinates. The target pixel file is formatted like
116+ a TESS pipeline target pixel file.
117+
118+ This function is maintained for backwards compatibility. For maximum flexibility, we recommend using the
119+ `~astrocut.TessCubeCutout` class.
120+
121+ Parameters
122+ ----------
123+ cube_file : str
124+ The cube file containing all the images to be cutout.
125+ Must be in the format returned by ~astrocut.make_cube.
126+ coordinates : str or `astropy.coordinates.SkyCoord` object
127+ The position around which to cutout.
128+ It may be specified as a string ("ra dec" in degrees)
129+ or as the appropriate `~astropy.coordinates.SkyCoord` object.
130+ cutout_size : int, array-like, `~astropy.units.Quantity`
131+ The size of the cutout array. If ``cutout_size``
132+ is a scalar number or a scalar `~astropy.units.Quantity`,
133+ then a square cutout of ``cutout_size`` will be created. If
134+ ``cutout_size`` has two elements, they should be in ``(ny, nx)``
135+ order. Scalar numbers in ``cutout_size`` are assumed to be in
136+ units of pixels. `~astropy.units.Quantity` objects must be in pixel or
137+ angular units.
138+ product : str
139+ The product type to make the cutouts from.
140+ Can either be 'SPOC' or 'TICA' (default is 'SPOC').
141+ target_pixel_file : str
142+ Optional. The name for the output target pixel file.
143+ If no name is supplied, the file will be named:
144+ ``<cube_file_base>_<ra>_<dec>_<cutout_size>_astrocut.fits``
145+ output_path : str
146+ Optional. The path where the output file is saved.
147+ The current directory is default.
148+ memory_only : bool
149+ Optional. If true, the cutout is made in memory only and not saved to disk.
150+ Default is False.
151+ threads : int, "auto", default=1
152+ Number of threads to use when making remote (e.g. s3) cutouts, will not use threads for local access
153+ <=1 disables the threadpool, >1 sets threadpool to the specified number of threads,
154+ "auto" uses `concurrent.futures.ThreadPoolExecutor`'s default: cpu_count + 4, limit to max of 32
155+ verbose : bool
156+ Optional. If true intermediate information is printed.
157+
158+ Returns
159+ -------
160+ response: string or `~astropy.io.fits.HDUList` or None
161+ If successful, returns the target pixel file as an `~astropy.io.fits.HDUList` object,
162+ or the path to the target pixel file if saved to disk.
163+ If unsuccessful, returns None.
164+ """
165+ cube_cutout = TessCubeCutout (input_files = cube_file ,
166+ coordinates = coordinates ,
167+ cutout_size = cutout_size ,
168+ product = product ,
169+ threads = threads ,
170+ verbose = verbose )
171+
172+ if memory_only :
173+ return cube_cutout .tpf_cutouts [0 ]
174+
175+ return cube_cutout .write_as_tpf (output_dir = output_path ,
176+ output_file = target_pixel_file )[0 ]
0 commit comments