@@ -81,17 +81,16 @@ def _fields_url(self, hdu=False, aux=False):
8181 core = 'aux' if aux else 'core'
8282 return f'{ self .NAT_URL } /api/adv_search/{ core } _{ file } _fields'
8383
84- def _response_to_table (self , response_json , rectype = None ):
84+ def _response_to_table (self , response_json , sia = False ):
8585 """Convert a JSON response to a :class:`~astropy.table.Table`.
8686
8787 Parameters
8888 ----------
8989 response_json : :class:`list`
9090 A query response formatted as a list of objects. The query
9191 metadata is the first item in the list.
92- rectype : :class:`str`, optional
93- Expect response keys to be prepended with this string,
94- *e.g.* ``file:`` or ``hdu:``. The default is no qualifier.
92+ sia : :class:`bool`, optional
93+ If ``True``, `response_json` came from a SIA query.
9594
9695 Returns
9796 -------
@@ -103,18 +102,20 @@ def _response_to_table(self, response_json, rectype=None):
103102 -----
104103 * Metadata queries return columns that are qualified with ``file:`` or ``hdu:``,
105104 however SIA queries to not.
105+ * HDU queries will label HDU-specific fields with ``hdu:`` but other
106+ fields will be qualified with ``file:``.
106107 """
107- if rectype is None :
108+ if sia :
108109 raw_names = [k for k in response_json [0 ]['HEADER' ].keys ()]
109110 names = raw_names
110111 else :
111112 raw_names = [k for k in response_json [0 ]['HEADER' ].keys ()
112- if k .startswith (f" { rectype } :" )]
113+ if k .startswith ('file:' ) or k . startswith ( 'hdu:' )]
113114 names = [n .split (':' )[1 ] for n in raw_names ]
114115 rows = [[row [n ] for n in raw_names ] for row in response_json [1 :]]
115116 return astropy .table .Table (names = names , rows = rows )
116117
117- def service_metadata (self , hdu = False , cache = True ):
118+ def _service_metadata (self , hdu = False , cache = True ):
118119 """A SIA metadata query: no images are requested; only metadata
119120 should be returned.
120121
@@ -137,7 +138,7 @@ def service_metadata(self, hdu=False, cache=True):
137138 response = self ._request ('GET' , url , timeout = self .TIMEOUT , cache = cache )
138139 return response .json ()
139140
140- def query_region (self , coordinate , * , radius = 0.1 , hdu = False , cache = True ):
141+ def query_region (self , coordinate , * , radius = 0.1 , hdu = False , cache = True , async_ = False ):
141142 """Query for NOIRLab observations by region of the sky.
142143
143144 Given a sky coordinate and radius, returns a `~astropy.table.Table`
@@ -154,126 +155,76 @@ def query_region(self, coordinate, *, radius=0.1, hdu=False, cache=True):
154155 appropriate `~astropy.units.Quantity` object from
155156 `~astropy.units` may also be used.
156157 hdu : :class:`bool`, optional
157- If ``True`` return the URL for HDU-based queries .
158+ If ``True``, perform the query on HDUs .
158159 cache : :class:`bool`, optional
159- If ``True`` cache the result locally.
160+ If ``True``, cache the result locally.
161+ async : :class:`bool`, optional
162+ If ``True``, return the raw query response instead of a Table.
160163
161164 Returns
162165 -------
163166 :class:`~astropy.table.Table`
164167 A table containing the results.
165168 """
166- response = self .query_region_async (coordinate , radius = radius , hdu = hdu , cache = cache )
167- response .raise_for_status ()
168- rectype = 'hdu' if hdu else 'file'
169- return self ._response_to_table (response .json ())
170-
171- def query_region_async (self , coordinate , * , radius = 0.1 , hdu = False , cache = True ):
172- """Query for NOIRLab observations by region of the sky.
173-
174- Given a sky coordinate and radius, returns a `~astropy.table.Table`
175- of NOIRLab observations.
176-
177- Parameters
178- ----------
179- coordinate : :class:`str` or `~astropy.coordinates` object
180- The target region which to search. It may be specified as a
181- string or as the appropriate `~astropy.coordinates` object.
182- radius : :class:`str` or `~astropy.units.Quantity` object, optional
183- Default 0.1 degrees.
184- The string must be parsable by `~astropy.coordinates.Angle`. The
185- appropriate `~astropy.units.Quantity` object from
186- `~astropy.units` may also be used.
187- hdu : :class:`bool`, optional
188- If ``True`` return the URL for HDU-based queries.
189- cache : :class:`bool`, optional
190- If ``True`` cache the result locally.
191-
192- Returns
193- -------
194- :class:`~requests.Response`
195- Response object.
196- """
197169 self ._validate_version ()
198170 ra , dec = coordinate .to_string ('decimal' ).split ()
199171 url = f'{ self ._sia_url (hdu = hdu )} ?POS={ ra } ,{ dec } &SIZE={ radius } &VERB=3&format=json'
200172 response = self ._request ('GET' , url , timeout = self .TIMEOUT , cache = cache )
201- # response.raise_for_status()
202- return response
203-
204- def core_fields (self , hdu = False , cache = True ):
205- """List the available CORE fields for file or HDU searches.
206-
207- CORE fields are faster to search than AUX fields.
208-
209- Parameters
210- ----------
211- hdu : :class:`bool`, optional
212- If ``True`` return the fields for HDU-based queries.
213- cache : :class:`bool`, optional
214- If ``True`` cache the result locally.
215-
216- Returns
217- -------
218- :class:`list`
219- A list of field descriptions, each a :class:`dict`.
220- """
221- url = self ._fields_url (hdu = hdu , aux = False )
222- response = self ._request ('GET' , url , timeout = self .TIMEOUT , cache = cache )
173+ if async_ :
174+ return response
223175 response .raise_for_status ()
224- return response .json ()
176+ return self . _response_to_table ( response .json (), sia = True )
225177
226- def aux_fields (self , instrument , proctype , hdu = False , cache = True ):
227- """List the available AUX fields.
178+ def list_fields (self , * , aux = False , instrument = None , proctype = None , hdu = False ,
179+ categorical = False , cache = True ):
180+ """List the available fields for searches using
181+ :meth:`~astroquery.noirlab.NOIRLabClass.query_metadata`.
228182
229- AUX fields are any fields in the Archive FITS files that are not
230- CORE DB fields. These are generally common to a single instrument,
231- proctype combination. AUX fields are slower to search than CORE fields.
232- Acceptable values for ``instrument`` and ``proctype`` are listed in the
233- results of the :meth:`astroquery.noirlab.core.NOIRLabClass.categoricals`
234- method.
183+ The default is to return core fields for file-based queries.
235184
236185 Parameters
237186 ----------
238- instrument : :class:`str`
187+ aux : :class:`bool`, optional
188+ If ``True``, return aux fields. `instrument` and `proctype` must also be specified.
189+ instrument : :class:`str`, optional
239190 The specific instrument, *e.g.* '90prime' or 'decam'.
240- proctype : :class:`str`
191+ proctype : :class:`str`, optional
241192 A description of the type of image, *e.g.* 'raw' or 'instcal'.
242193 hdu : :class:`bool`, optional
243194 If ``True`` return the fields for HDU-based queries.
195+ categorical : :class:`bool`, optional
196+ If ``True`` return the categorical fields and their allowed values.
244197 cache : :class:`bool`, optional
245198 If ``True`` cache the result locally.
246199
247200 Returns
248201 -------
249- :class:`list`
202+ :class:`list` or :class:`dict`
250203 A list of field descriptions, each a :class:`dict`.
251- """
252- url = f'{ self ._fields_url (hdu = hdu , aux = True )} /{ instrument } /{ proctype } /'
253- response = self ._request ('GET' , url , timeout = self .TIMEOUT , cache = cache )
254- response .raise_for_status ()
255- return response .json ()
256-
257- def categoricals (self , cache = True ):
258- """List the currently acceptable values for each 'categorical field'
259- associated with Archive files.
260-
261- A 'categorical field' is one in which the values are restricted to a
262- specific set. The specific set may grow over time, but not often.
263- The categorical fields are: ``instrument``, ``obsmode``, ``obstype``,
264- ``proctype``, ``prodtype``, ``site``, ``survey``, ``telescope``.
204+ If ``categorical=True`` return a :class:`dict` describing the
205+ allowed values of each categorical field.
265206
266- Parameters
267- ----------
268- cache : :class:`bool`, optional
269- If ``True`` cache the result locally .
207+ Raises
208+ ------
209+ ValueError
210+ If ``aux= True`` and `instrument` or `proctype` are not specified .
270211
271- Returns
272- -------
273- :class:`dict`
274- A dictionary containing the category metadata.
212+ Notes
213+ -----
214+ * Core fields are faster to search than Aux fields.
215+ * The available fields depend on whether a File or a HDU query is requested.
216+ * Categorical fields can only take on one of a set of values.
275217 """
276- url = f'{ self .NAT_URL } /api/adv_search/cat_lists/?format=json'
218+ if categorical :
219+ url = f'{ self .NAT_URL } /api/adv_search/cat_lists/?format=json'
220+ else :
221+ url = self ._fields_url (hdu = hdu , aux = aux )
222+ if aux :
223+ if instrument is None :
224+ raise ValueError ("instrument must be specified if aux=True." )
225+ if proctype is None :
226+ raise ValueError ("instrument must be specified if aux=True." )
227+ url = f'{ url } /{ instrument } /{ proctype } /'
277228 response = self ._request ('GET' , url , timeout = self .TIMEOUT , cache = cache )
278229 response .raise_for_status ()
279230 return response .json ()
@@ -319,7 +270,7 @@ def query_metadata(self, qspec=None, sort=None, limit=1000, hdu=False, cache=Tru
319270 response = self ._request ('POST' , url , json = jdata ,
320271 timeout = self .TIMEOUT , cache = cache )
321272 response .raise_for_status ()
322- return self ._response_to_table (response .json (), rectype = rectype )
273+ return self ._response_to_table (response .json ())
323274
324275 def get_file (self , fileid ):
325276 """Simply fetch a file by MD5 ID.
0 commit comments