14
14
from astropy .table import Table
15
15
from astropy .io .votable import parse
16
16
from astroquery import log
17
+ import numpy as np
17
18
18
19
# 3. local imports - use relative imports
19
20
# commonly required local imports shown below as example
@@ -125,7 +126,7 @@ def _args_to_payload(self, radius=1*u.arcmin, **kwargs):
125
126
if channel is not None :
126
127
raise ValueError ("Either 'channel' or 'band' values may be provided but not both." )
127
128
128
- if (not isinstance (band , (list , tuple ))) or len (band ) != 2 or \
129
+ if (not isinstance (band , (list , tuple , np . ndarray ))) or len (band ) != 2 or \
129
130
(band [0 ] is not None and not isinstance (band [0 ], u .Quantity )) or \
130
131
(band [1 ] is not None and not isinstance (band [1 ], u .Quantity )):
131
132
raise ValueError ("The 'band' value must be a list of 2 wavelength or frequency values." )
@@ -137,22 +138,31 @@ def _args_to_payload(self, radius=1*u.arcmin, **kwargs):
137
138
if bandBoundedLow or bandBoundedHigh :
138
139
unit = band [0 ].unit if bandBoundedLow else band [1 ].unit
139
140
if unit .physical_type == 'length' :
140
- min_band = '-Inf' if not bandBoundedLow else str ( band [0 ].to (u .m ).value )
141
- max_band = '+Inf' if not bandBoundedHigh else str ( band [1 ].to (u .m ).value )
141
+ min_band = '-Inf' if not bandBoundedLow else band [0 ].to (u .m ).value
142
+ max_band = '+Inf' if not bandBoundedHigh else band [1 ].to (u .m ).value
142
143
elif unit .physical_type == 'frequency' :
143
144
# Swap the order when changing frequency to wavelength
144
- min_band = '-Inf' if not bandBoundedHigh else str ( band [1 ].to (u .m , equivalencies = u .spectral ()).value )
145
- max_band = '+Inf' if not bandBoundedLow else str ( band [0 ].to (u .m , equivalencies = u .spectral ()).value )
145
+ min_band = '-Inf' if not bandBoundedHigh else band [1 ].to (u .m , equivalencies = u .spectral ()).value
146
+ max_band = '+Inf' if not bandBoundedLow else band [0 ].to (u .m , equivalencies = u .spectral ()).value
146
147
else :
147
148
raise ValueError ("The 'band' values must be wavelengths or frequencies." )
149
+ # If values were provided in the wrong order, swap them
150
+ if bandBoundedLow and bandBoundedHigh and min_band > max_band :
151
+ temp_val = min_band
152
+ min_band = max_band
153
+ max_band = temp_val
148
154
149
155
request_payload ['BAND' ] = f'{ min_band } { max_band } '
150
156
151
157
if channel is not None :
152
- if not isinstance (channel , (list , tuple )) or len (channel ) != 2 or \
153
- not isinstance (channel [0 ], int ) or not isinstance (channel [1 ], int ):
158
+ if not isinstance (channel , (list , tuple , np . ndarray )) or len (channel ) != 2 or \
159
+ not isinstance (channel [0 ], ( int , np . integer )) or not isinstance (channel [1 ], ( int , np . integer ) ):
154
160
raise ValueError ("The 'channel' value must be a list of 2 integer values." )
155
- request_payload ['CHANNEL' ] = f'{ channel [0 ]} { channel [1 ]} '
161
+ if channel [0 ] <= channel [1 ]:
162
+ request_payload ['CHANNEL' ] = f'{ channel [0 ]} { channel [1 ]} '
163
+ else :
164
+ # If values were provided in the wrong order, swap them
165
+ request_payload ['CHANNEL' ] = f'{ channel [1 ]} { channel [0 ]} '
156
166
157
167
return request_payload
158
168
@@ -310,7 +320,8 @@ def cutout(self, table, *, coordinates=None, radius=None, height=None,
310
320
311
321
job_url = self ._create_job (table , 'cutout_service' , verbose )
312
322
313
- cutout_spec = self ._args_to_payload (radius = radius , ** kwargs )
323
+ cutout_spec = self ._args_to_payload (radius = radius , coordinates = coordinates , height = height , width = width ,
324
+ band = band , channel = channel , verbose = verbose )
314
325
315
326
if not cutout_spec :
316
327
raise ValueError ("Please provide cutout parameters such as coordinates, band or channel." )
0 commit comments