35
35
__all__ = ["TesscutClass" , "Tesscut" , "ZcutClass" , "Zcut" ]
36
36
37
37
38
- def _parse_cutout_size (size , timeout_add = None , mission = None ):
38
+ def _parse_cutout_size (size , timeout = None , mission = None ):
39
39
"""
40
40
Take a user input cutout size and parse it into the regular format
41
41
[ny,nx] where nx/ny are quantities with units either pixels or degrees.
@@ -53,8 +53,8 @@ def _parse_cutout_size(size, timeout_add=None, mission=None):
53
53
The mission for which the size parsing is being done. This parameter
54
54
is mainly meant to trigger a cutout size warning specifically for TESSCut
55
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 .
56
+ timeout : int or float, optional
57
+ The modified request timeout limit.
58
58
The request processing time by default is 600 seconds, meaning an attempt at communicating
59
59
with the API will take 600 seconds before timing out. In the context of this function, this
60
60
parameter is meant to keep track of whether or not the timeout limit has been modified, which
@@ -72,7 +72,7 @@ def _parse_cutout_size(size, timeout_add=None, mission=None):
72
72
if np .isscalar (size ):
73
73
size = np .repeat (size , 2 )
74
74
75
- limit_reached = size [ 0 ] > 30 or size [ 1 ] > 30
75
+ limit_reached = ( size > 30 ). any ()
76
76
77
77
if isinstance (size , u .Quantity ):
78
78
size = np .atleast_1d (size )
@@ -83,9 +83,8 @@ def _parse_cutout_size(size, timeout_add=None, mission=None):
83
83
# Based on the literature, TESS resolution is approx. 21 arcseconds per pixel.
84
84
# We will convert the recommended upper limit for a dimension from pixels
85
85
# to the unit being passed.
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
86
+ with u .set_enabled_equivalencies (u .pixel_scale (21 * u .arcsec / u .pixel )):
87
+ limit_reached = (size > 30 * u .pixel ).any ()
89
88
90
89
if len (size ) > 2 :
91
90
warnings .warn ("Too many dimensions in cutout size, only the first two will be used." ,
@@ -111,10 +110,10 @@ def _parse_cutout_size(size, timeout_add=None, mission=None):
111
110
else :
112
111
raise InvalidQueryError ("Cutout size must be in pixels or angular quantity." )
113
112
114
- if (mission == 'TESS' ) & (limit_reached ) & (not timeout_add ):
113
+ if (mission == 'TESS' ) & (limit_reached ) & (not timeout ):
115
114
warnings .warn ("You have selected a large cutout size that may result in a timeout error. We suggest limiting"
116
115
" 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 )
116
+ " default 600 seconds to something higher, using the timeout argument." , InputWarning )
118
117
119
118
return {"x" : x , "y" : y , "units" : units }
120
119
@@ -137,6 +136,11 @@ def __init__(self):
137
136
}
138
137
self ._service_api_connection .set_service_params (services , "tesscut" )
139
138
139
+ def _get_default_timeout (self ):
140
+ """ Gets the default request timeout limit. """
141
+
142
+ return self ._service_api_connection .TIMEOUT
143
+
140
144
def get_sectors (self , * , coordinates = None , radius = 0 * u .deg , product = 'SPOC' , objectname = None ,
141
145
moving_target = False , mt_type = None ):
142
146
@@ -256,7 +260,7 @@ def get_sectors(self, *, coordinates=None, radius=0*u.deg, product='SPOC', objec
256
260
257
261
def download_cutouts (self , * , coordinates = None , size = 5 , sector = None , product = 'SPOC' , path = "." ,
258
262
inflate = True , objectname = None , moving_target = False , mt_type = None , verbose = False ,
259
- timeout_add = None ):
263
+ timeout = None ):
260
264
"""
261
265
Download cutout target pixel file(s) around the given coordinates with indicated size.
262
266
@@ -313,12 +317,23 @@ def download_cutouts(self, *, coordinates=None, size=5, sector=None, product='SP
313
317
first majorbody is tried and then smallbody if a matching majorbody is not found.
314
318
315
319
NOTE: If moving_target is supplied, this argument is ignored.
320
+ timeout : int or float, optional
321
+ The modified request timeout limit.
322
+ The request processing time by default is 600 seconds, meaning an attempt at communicating
323
+ with the API will take 600 seconds before timing out. The timeout upper limit can be modified
324
+ using this argument for large cutout requests via TESSCut. Default is None.
316
325
317
326
Returns
318
327
-------
319
328
response : `~astropy.table.Table`
320
329
"""
321
330
331
+ # Modify TIMEOUT attribute if necessary (usually this is modified for large requests)
332
+ if timeout :
333
+ self ._service_api_connection .TIMEOUT = timeout
334
+ log .info (f"Request timeout upper limit is being changed to { self ._service_api_connection .TIMEOUT } "
335
+ " seconds." )
336
+
322
337
if moving_target :
323
338
324
339
# The Moving Targets service is currently only available for SPOC
@@ -348,7 +363,7 @@ def download_cutouts(self, *, coordinates=None, size=5, sector=None, product='SP
348
363
astrocut_request = f"astrocut?ra={ coordinates .ra .deg } &dec={ coordinates .dec .deg } "
349
364
350
365
# Adding the arguments that are common between moving/still astrocut requests
351
- size_dict = _parse_cutout_size (size , timeout_add = timeout_add , mission = 'TESS' )
366
+ size_dict = _parse_cutout_size (size , timeout = timeout , mission = 'TESS' )
352
367
astrocut_request += f"&y={ size_dict ['y' ]} &x={ size_dict ['x' ]} &units={ size_dict ['units' ]} "
353
368
354
369
# Making sure input product is either SPOC or TICA,
@@ -389,10 +404,14 @@ def download_cutouts(self, *, coordinates=None, size=5, sector=None, product='SP
389
404
os .remove (zipfile_path )
390
405
391
406
localpath_table ['Local Path' ] = [path + x for x in cutout_files ]
407
+
408
+ if timeout :
409
+ self ._service_api_connection .TIMEOUT = self ._get_default_timeout ()
410
+
392
411
return localpath_table
393
412
394
413
def get_cutouts (self , * , coordinates = None , size = 5 , product = 'SPOC' , sector = None ,
395
- objectname = None , moving_target = False , mt_type = None , timeout_add = None ):
414
+ objectname = None , moving_target = False , mt_type = None , timeout = None ):
396
415
"""
397
416
Get cutout target pixel file(s) around the given coordinates with indicated size,
398
417
and return them as a list of `~astropy.io.fits.HDUList` objects.
@@ -441,8 +460,8 @@ def get_cutouts(self, *, coordinates=None, size=5, product='SPOC', sector=None,
441
460
first majorbody is tried and then smallbody if a matching majorbody is not found.
442
461
443
462
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 .
463
+ timeout : int or float, optional
464
+ The modified request timeout limit.
446
465
The request processing time by default is 600 seconds, meaning an attempt at communicating
447
466
with the API will take 600 seconds before timing out. The timeout upper limit can be modified
448
467
using this argument for large cutout requests via TESSCut. Default is None.
@@ -453,13 +472,13 @@ def get_cutouts(self, *, coordinates=None, size=5, product='SPOC', sector=None,
453
472
"""
454
473
455
474
# 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
475
+ if timeout :
476
+ self ._service_api_connection .TIMEOUT = timeout
458
477
log .info (f"Request timeout upper limit is being changed to { self ._service_api_connection .TIMEOUT } "
459
478
" seconds." )
460
479
461
480
# Setting up the cutout size
462
- param_dict = _parse_cutout_size (size , timeout_add = timeout_add , mission = 'TESS' )
481
+ param_dict = _parse_cutout_size (size , timeout = timeout , mission = 'TESS' )
463
482
464
483
# Add sector if present
465
484
if sector :
@@ -529,6 +548,9 @@ def get_cutouts(self, *, coordinates=None, size=5, product='SPOC', sector=None,
529
548
# preserve the original filename in the fits object
530
549
cutout_hdus_list [- 1 ].filename = name
531
550
551
+ if timeout :
552
+ self ._service_api_connection .TIMEOUT = self ._get_default_timeout ()
553
+
532
554
return cutout_hdus_list
533
555
534
556
@@ -592,7 +614,7 @@ def get_surveys(self, coordinates, *, radius="0d"):
592
614
return survey_json
593
615
594
616
def download_cutouts (self , coordinates , * , size = 5 , survey = None , cutout_format = "fits" , path = "." , inflate = True ,
595
- verbose = False , timeout_add = None , ** img_params ):
617
+ verbose = False , ** img_params ):
596
618
"""
597
619
Download cutout FITS/image file(s) around the given coordinates with indicated size.
598
620
@@ -633,24 +655,13 @@ def download_cutouts(self, coordinates, *, size=5, survey=None, cutout_format="f
633
655
The Column Name is the keyword, with the argument being one or more acceptable
634
656
values for that parameter, except for fields with a float datatype where the
635
657
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.
641
658
642
659
Returns
643
660
-------
644
661
response : `~astropy.table.Table`
645
662
Cutout file(s) for given coordinates
646
663
"""
647
664
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
-
654
665
# Get Skycoord object for coordinates/object
655
666
coordinates = parse_input_location (coordinates )
656
667
size_dict = _parse_cutout_size (size )
0 commit comments