26
26
from astropy .io import fits
27
27
28
28
from .. import log
29
- from ..exceptions import InputWarning , NoResultsWarning , InvalidQueryError
29
+ from ..exceptions import InputWarning , LargeQueryWarning , NoResultsWarning , InvalidQueryError
30
30
31
31
from .utils import parse_input_location
32
32
from .core import MastQueryWithLogin
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
@@ -68,11 +68,15 @@ def _parse_cutout_size(size, timeout_add=None, mission=None):
68
68
either pixels or degrees.
69
69
"""
70
70
71
+ # This local variable will change to True if input cutout size exceeds recommended limits for TESS
72
+ limit_reached = False
73
+
71
74
# Making size into an array [ny, nx]
72
75
if np .isscalar (size ):
73
76
size = np .repeat (size , 2 )
74
77
75
- limit_reached = size [0 ] > 30 or size [1 ] > 30
78
+ if mission == 'TESS' :
79
+ limit_reached = (size > 30 ).any ()
76
80
77
81
if isinstance (size , u .Quantity ):
78
82
size = np .atleast_1d (size )
@@ -83,14 +87,24 @@ def _parse_cutout_size(size, timeout_add=None, mission=None):
83
87
# Based on the literature, TESS resolution is approx. 21 arcseconds per pixel.
84
88
# We will convert the recommended upper limit for a dimension from pixels
85
89
# 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
90
+ if mission == 'TESS' :
91
+ with u . set_enabled_equivalencies ( u . pixel_scale ( 21 * u .arcsec / u . pixel )):
92
+ limit_reached = ( size > 30 * u . pixel ). any ()
89
93
90
94
if len (size ) > 2 :
91
95
warnings .warn ("Too many dimensions in cutout size, only the first two will be used." ,
92
96
InputWarning )
93
-
97
+
98
+ # Checking 2d size inputs for the recommended cutout size
99
+ if (len (size ) == 2 ) & (mission == 'TESS' ):
100
+
101
+ if np .isscalar (size [0 ]):
102
+ print (size )
103
+ size = size * u .pixel
104
+
105
+ with u .set_enabled_equivalencies (u .pixel_scale (21 * u .arcsec / u .pixel )):
106
+ limit_reached = (size * size [0 ].unit > 30 * u .pixel ).any ()
107
+
94
108
# Getting x and y out of the size
95
109
96
110
if np .isscalar (size [0 ]):
@@ -111,10 +125,10 @@ def _parse_cutout_size(size, timeout_add=None, mission=None):
111
125
else :
112
126
raise InvalidQueryError ("Cutout size must be in pixels or angular quantity." )
113
127
114
- if (mission == 'TESS' ) & ( limit_reached ) & (not timeout_add ):
128
+ if (limit_reached ) & (not timeout ):
115
129
warnings .warn ("You have selected a large cutout size that may result in a timeout error. We suggest limiting"
116
130
" 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 )
131
+ " default 600 seconds to something higher, using the timeout argument." , LargeQueryWarning )
118
132
119
133
return {"x" : x , "y" : y , "units" : units }
120
134
@@ -137,6 +151,11 @@ def __init__(self):
137
151
}
138
152
self ._service_api_connection .set_service_params (services , "tesscut" )
139
153
154
+ def _get_default_timeout (self ):
155
+ """ Gets the default request timeout limit. """
156
+
157
+ return self ._service_api_connection .TIMEOUT
158
+
140
159
def get_sectors (self , * , coordinates = None , radius = 0 * u .deg , product = 'SPOC' , objectname = None ,
141
160
moving_target = False , mt_type = None ):
142
161
@@ -256,7 +275,7 @@ def get_sectors(self, *, coordinates=None, radius=0*u.deg, product='SPOC', objec
256
275
257
276
def download_cutouts (self , * , coordinates = None , size = 5 , sector = None , product = 'SPOC' , path = "." ,
258
277
inflate = True , objectname = None , moving_target = False , mt_type = None , verbose = False ,
259
- timeout_add = None ):
278
+ timeout = None ):
260
279
"""
261
280
Download cutout target pixel file(s) around the given coordinates with indicated size.
262
281
@@ -313,12 +332,23 @@ def download_cutouts(self, *, coordinates=None, size=5, sector=None, product='SP
313
332
first majorbody is tried and then smallbody if a matching majorbody is not found.
314
333
315
334
NOTE: If moving_target is supplied, this argument is ignored.
335
+ timeout : int or float, optional
336
+ The modified request timeout limit.
337
+ The request processing time by default is 600 seconds, meaning an attempt at communicating
338
+ with the API will take 600 seconds before timing out. The timeout upper limit can be modified
339
+ using this argument for large cutout requests via TESSCut. Default is None.
316
340
317
341
Returns
318
342
-------
319
343
response : `~astropy.table.Table`
320
344
"""
321
345
346
+ # Modify TIMEOUT attribute if necessary (usually this is modified for large requests)
347
+ if timeout :
348
+ self ._service_api_connection .TIMEOUT = timeout
349
+ log .info (f"Request timeout upper limit is being changed to { self ._service_api_connection .TIMEOUT } "
350
+ " seconds." )
351
+
322
352
if moving_target :
323
353
324
354
# The Moving Targets service is currently only available for SPOC
@@ -348,7 +378,7 @@ def download_cutouts(self, *, coordinates=None, size=5, sector=None, product='SP
348
378
astrocut_request = f"astrocut?ra={ coordinates .ra .deg } &dec={ coordinates .dec .deg } "
349
379
350
380
# Adding the arguments that are common between moving/still astrocut requests
351
- size_dict = _parse_cutout_size (size , timeout_add = timeout_add , mission = 'TESS' )
381
+ size_dict = _parse_cutout_size (size , timeout = timeout , mission = 'TESS' )
352
382
astrocut_request += f"&y={ size_dict ['y' ]} &x={ size_dict ['x' ]} &units={ size_dict ['units' ]} "
353
383
354
384
# Making sure input product is either SPOC or TICA,
@@ -389,10 +419,14 @@ def download_cutouts(self, *, coordinates=None, size=5, sector=None, product='SP
389
419
os .remove (zipfile_path )
390
420
391
421
localpath_table ['Local Path' ] = [path + x for x in cutout_files ]
422
+
423
+ if timeout :
424
+ self ._service_api_connection .TIMEOUT = self ._get_default_timeout ()
425
+
392
426
return localpath_table
393
427
394
428
def get_cutouts (self , * , coordinates = None , size = 5 , product = 'SPOC' , sector = None ,
395
- objectname = None , moving_target = False , mt_type = None , timeout_add = None ):
429
+ objectname = None , moving_target = False , mt_type = None , timeout = None ):
396
430
"""
397
431
Get cutout target pixel file(s) around the given coordinates with indicated size,
398
432
and return them as a list of `~astropy.io.fits.HDUList` objects.
@@ -441,8 +475,8 @@ def get_cutouts(self, *, coordinates=None, size=5, product='SPOC', sector=None,
441
475
first majorbody is tried and then smallbody if a matching majorbody is not found.
442
476
443
477
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 .
478
+ timeout : int or float, optional
479
+ The modified request timeout limit.
446
480
The request processing time by default is 600 seconds, meaning an attempt at communicating
447
481
with the API will take 600 seconds before timing out. The timeout upper limit can be modified
448
482
using this argument for large cutout requests via TESSCut. Default is None.
@@ -453,13 +487,13 @@ def get_cutouts(self, *, coordinates=None, size=5, product='SPOC', sector=None,
453
487
"""
454
488
455
489
# 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
490
+ if timeout :
491
+ self ._service_api_connection .TIMEOUT = timeout
458
492
log .info (f"Request timeout upper limit is being changed to { self ._service_api_connection .TIMEOUT } "
459
493
" seconds." )
460
494
461
495
# Setting up the cutout size
462
- param_dict = _parse_cutout_size (size , timeout_add = timeout_add , mission = 'TESS' )
496
+ param_dict = _parse_cutout_size (size , timeout = timeout , mission = 'TESS' )
463
497
464
498
# Add sector if present
465
499
if sector :
@@ -529,6 +563,9 @@ def get_cutouts(self, *, coordinates=None, size=5, product='SPOC', sector=None,
529
563
# preserve the original filename in the fits object
530
564
cutout_hdus_list [- 1 ].filename = name
531
565
566
+ if timeout :
567
+ self ._service_api_connection .TIMEOUT = self ._get_default_timeout ()
568
+
532
569
return cutout_hdus_list
533
570
534
571
@@ -592,7 +629,7 @@ def get_surveys(self, coordinates, *, radius="0d"):
592
629
return survey_json
593
630
594
631
def download_cutouts (self , coordinates , * , size = 5 , survey = None , cutout_format = "fits" , path = "." , inflate = True ,
595
- verbose = False , timeout_add = None , ** img_params ):
632
+ verbose = False , ** img_params ):
596
633
"""
597
634
Download cutout FITS/image file(s) around the given coordinates with indicated size.
598
635
@@ -633,24 +670,13 @@ def download_cutouts(self, coordinates, *, size=5, survey=None, cutout_format="f
633
670
The Column Name is the keyword, with the argument being one or more acceptable
634
671
values for that parameter, except for fields with a float datatype where the
635
672
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
673
642
674
Returns
643
675
-------
644
676
response : `~astropy.table.Table`
645
677
Cutout file(s) for given coordinates
646
678
"""
647
679
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
680
# Get Skycoord object for coordinates/object
655
681
coordinates = parse_input_location (coordinates )
656
682
size_dict = _parse_cutout_size (size )
0 commit comments