25
25
from astropy .table import Table
26
26
from astropy .io import fits
27
27
28
+ from .. import log
28
29
from ..exceptions import InputWarning , NoResultsWarning , InvalidQueryError
29
30
30
31
from .utils import parse_input_location
34
35
__all__ = ["TesscutClass" , "Tesscut" , "ZcutClass" , "Zcut" ]
35
36
36
37
37
- def _parse_cutout_size (size ):
38
+ def _parse_cutout_size (size , timeout_add = None , mission = None ):
38
39
"""
39
40
Take a user input cutout size and parse it into the regular format
40
41
[ny,nx] where nx/ny are quantities with units either pixels or degrees.
@@ -48,6 +49,17 @@ def _parse_cutout_size(size):
48
49
``(ny, nx)`` order. Scalar numbers in ``size`` are assumed to be in
49
50
units of pixels. `~astropy.units.Quantity` objects must be in pixel or
50
51
angular units.
52
+ mission : str, optional
53
+ The mission for which the size parsing is being done. This parameter
54
+ is mainly meant to trigger a cutout size warning specifically for TESSCut
55
+ requests. Default is None.
56
+ timeout_add : int or float, optional
57
+ The amount (in seconds) by which the request processing time upper limit will be changed.
58
+ The request processing time by default is 600 seconds, meaning an attempt at communicating
59
+ with the API will take 600 seconds before timing out. In the context of this function, this
60
+ parameter is meant to keep track of whether or not the timeout limit has been modified, which
61
+ will affect whether or not a warning message about the cutout size gets triggered.
62
+ Default is None.
51
63
52
64
Returns
53
65
-------
@@ -60,31 +72,50 @@ def _parse_cutout_size(size):
60
72
if np .isscalar (size ):
61
73
size = np .repeat (size , 2 )
62
74
75
+ limit_reached = size [0 ] > 30 or size [1 ] > 30
76
+
63
77
if isinstance (size , u .Quantity ):
64
78
size = np .atleast_1d (size )
79
+
65
80
if len (size ) == 1 :
66
81
size = np .repeat (size , 2 )
67
82
83
+ # Based on the literature, TESS resolution is approx. 21 arcseconds per pixel.
84
+ # We will convert the recommended upper limit for a dimension from pixels
85
+ # to degrees.
86
+ unit = size [0 ].unit
87
+ upper_limit = (30 * 21 * u .arcsec ).to (unit ).value
88
+ limit_reached = size [0 ].value > upper_limit or size [1 ].value > upper_limit
89
+
68
90
if len (size ) > 2 :
69
91
warnings .warn ("Too many dimensions in cutout size, only the first two will be used." ,
70
92
InputWarning )
71
93
72
94
# Getting x and y out of the size
95
+
73
96
if np .isscalar (size [0 ]):
74
97
x = size [1 ]
75
98
y = size [0 ]
76
99
units = "px"
100
+
77
101
elif size [0 ].unit == u .pixel :
78
102
x = size [1 ].value
79
103
y = size [0 ].value
80
104
units = "px"
105
+
81
106
elif size [0 ].unit .physical_type == 'angle' :
82
107
x = size [1 ].to (u .deg ).value
83
108
y = size [0 ].to (u .deg ).value
84
109
units = "d"
110
+
85
111
else :
86
112
raise InvalidQueryError ("Cutout size must be in pixels or angular quantity." )
87
113
114
+ if (mission == 'TESS' ) & (limit_reached ) & (not timeout_add ):
115
+ warnings .warn ("You have selected a large cutout size that may result in a timeout error. We suggest limiting"
116
+ " the size of your requested cutout, or changing the request timeout limit from its"
117
+ " default 600 seconds to something higher, using the timeout_add argument." , InputWarning )
118
+
88
119
return {"x" : x , "y" : y , "units" : units }
89
120
90
121
@@ -108,6 +139,7 @@ def __init__(self):
108
139
109
140
def get_sectors (self , * , coordinates = None , radius = 0 * u .deg , product = 'SPOC' , objectname = None ,
110
141
moving_target = False , mt_type = None ):
142
+
111
143
"""
112
144
Get a list of the TESS data sectors whose footprints intersect
113
145
with the given search area.
@@ -223,7 +255,8 @@ def get_sectors(self, *, coordinates=None, radius=0*u.deg, product='SPOC', objec
223
255
return Table (sector_dict )
224
256
225
257
def download_cutouts (self , * , coordinates = None , size = 5 , sector = None , product = 'SPOC' , path = "." ,
226
- inflate = True , objectname = None , moving_target = False , mt_type = None , verbose = False ):
258
+ inflate = True , objectname = None , moving_target = False , mt_type = None , verbose = False ,
259
+ timeout_add = None ):
227
260
"""
228
261
Download cutout target pixel file(s) around the given coordinates with indicated size.
229
262
@@ -315,7 +348,7 @@ def download_cutouts(self, *, coordinates=None, size=5, sector=None, product='SP
315
348
astrocut_request = f"astrocut?ra={ coordinates .ra .deg } &dec={ coordinates .dec .deg } "
316
349
317
350
# Adding the arguments that are common between moving/still astrocut requests
318
- size_dict = _parse_cutout_size (size )
351
+ size_dict = _parse_cutout_size (size , timeout_add = timeout_add , mission = 'TESS' )
319
352
astrocut_request += f"&y={ size_dict ['y' ]} &x={ size_dict ['x' ]} &units={ size_dict ['units' ]} "
320
353
321
354
# Making sure input product is either SPOC or TICA,
@@ -359,7 +392,7 @@ def download_cutouts(self, *, coordinates=None, size=5, sector=None, product='SP
359
392
return localpath_table
360
393
361
394
def get_cutouts (self , * , coordinates = None , size = 5 , product = 'SPOC' , sector = None ,
362
- objectname = None , moving_target = False , mt_type = None ):
395
+ objectname = None , moving_target = False , mt_type = None , timeout_add = None ):
363
396
"""
364
397
Get cutout target pixel file(s) around the given coordinates with indicated size,
365
398
and return them as a list of `~astropy.io.fits.HDUList` objects.
@@ -408,14 +441,25 @@ def get_cutouts(self, *, coordinates=None, size=5, product='SPOC', sector=None,
408
441
first majorbody is tried and then smallbody if a matching majorbody is not found.
409
442
410
443
NOTE: If moving_target is supplied, this argument is ignored.
444
+ timeout_add : int or float, optional
445
+ The amount (in seconds) by which the request processing time upper limit will be changed.
446
+ The request processing time by default is 600 seconds, meaning an attempt at communicating
447
+ with the API will take 600 seconds before timing out. The timeout upper limit can be modified
448
+ using this argument for large cutout requests via TESSCut. Default is None.
411
449
412
450
Returns
413
451
-------
414
452
response : A list of `~astropy.io.fits.HDUList` objects.
415
453
"""
416
454
455
+ # Modify TIMEOUT attribute if necessary (usually this is modified for large requests)
456
+ if timeout_add :
457
+ self ._service_api_connection .TIMEOUT = self ._service_api_connection .TIMEOUT + timeout_add
458
+ log .info (f"Request timeout upper limit is being changed to { self ._service_api_connection .TIMEOUT } "
459
+ " seconds." )
460
+
417
461
# Setting up the cutout size
418
- param_dict = _parse_cutout_size (size )
462
+ param_dict = _parse_cutout_size (size , timeout_add = timeout_add , mission = 'TESS' )
419
463
420
464
# Add sector if present
421
465
if sector :
@@ -548,7 +592,7 @@ def get_surveys(self, coordinates, *, radius="0d"):
548
592
return survey_json
549
593
550
594
def download_cutouts (self , coordinates , * , size = 5 , survey = None , cutout_format = "fits" , path = "." , inflate = True ,
551
- verbose = False , ** img_params ):
595
+ verbose = False , timeout_add = None , ** img_params ):
552
596
"""
553
597
Download cutout FITS/image file(s) around the given coordinates with indicated size.
554
598
@@ -589,12 +633,24 @@ def download_cutouts(self, coordinates, *, size=5, survey=None, cutout_format="f
589
633
The Column Name is the keyword, with the argument being one or more acceptable
590
634
values for that parameter, except for fields with a float datatype where the
591
635
argument should be in the form [minVal, maxVal].
636
+ timeout_add : int or float, optional
637
+ The amount (in seconds) by which the request processing time upper limit will be changed.
638
+ The request processing time by default is 600 seconds, meaning an attempt at communicating
639
+ with the API will take 600 seconds before timing out. The timeout upper limit can be modified
640
+ using this argument for large cutout requests via TESSCut. Default is None.
592
641
593
642
Returns
594
643
-------
595
644
response : `~astropy.table.Table`
596
645
Cutout file(s) for given coordinates
597
646
"""
647
+
648
+ # Modify TIMEOUT attribute if necessary (usually this is modified for large requests)
649
+ if timeout_add :
650
+ self ._service_api_connection .TIMEOUT = self ._service_api_connection .TIMEOUT + timeout_add
651
+ log .info (f"Request timeout upper limit is being changed to { self ._service_api_connection .TIMEOUT } "
652
+ " seconds." )
653
+
598
654
# Get Skycoord object for coordinates/object
599
655
coordinates = parse_input_location (coordinates )
600
656
size_dict = _parse_cutout_size (size )
0 commit comments