Skip to content

Commit 0bed33f

Browse files
ManonMarchandbsipocz
authored andcommitted
feat: new parameter 'criteria' in query_region and query_hips
1 parent 1d6c482 commit 0bed33f

File tree

5 files changed

+58
-50
lines changed

5 files changed

+58
-50
lines changed

CHANGES.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ mocserver
3131
- ``return_moc`` now allows to ask for a Time-MOC or a Space-Time MOC rather than only
3232
Space-MOCs [#3139]
3333

34-
- Fix query by MOC that would write a file ``moc.fits`` where the method was executed
35-
in overwriting mode (potentially deleting data if there was a conflicting file) [#3139]
34+
- Fix query by MOC that would write a file ``moc.fits`` where the method was executed in
35+
overwriting mode (potentially deleting data if there was a conflicting file) [#3139]
3636

37-
- Returned tables now have a default list of fields instead of the > 130 columns returned
38-
previously. The full list of fields can be displayed with the new method
39-
``MOCServer.list_fields`` [#3139]
37+
- [:warning: BREAKING] Returned tables now have a default list of fields instead of the
38+
> 130 columns returned previously. The full list of fields can be displayed with the
39+
new method ``MOCServer.list_fields`` [#3139]
4040

4141
- Add ``casesensitive`` parameter in the queries (previously, this was hardcoded
4242
to ``True``) [#3139]
@@ -48,6 +48,9 @@ mocserver
4848
- Add ``query_hips`` method, which is convenient to filter only Hierarchical progressive
4949
surveys [#3139]
5050

51+
- New parameter ``criteria`` in ``query_region`` and ``query_hips`` that has the same
52+
use than ``meta_data`` in the deprecated method ``find_datasets`` [#3139]
53+
5154
simbad
5255
^^^^^^
5356

@@ -61,6 +64,7 @@ simbad
6164

6265
- Fixed non existing flux filters as votable fields would fail silently [#3186]
6366

67+
6468
Infrastructure, Utility and Other Changes and Additions
6569
-------------------------------------------------------
6670

astroquery/mocserver/core.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self):
4242
def query_region(
4343
self, region=None,
4444
*,
45-
meta_data=None,
45+
criteria=None,
4646
intersect="overlaps",
4747
return_moc=None,
4848
max_norder=None,
@@ -63,8 +63,8 @@ def query_region(
6363
The region to query the MOCServer with. Note that this can also be a
6464
space-time region with the Time-MOCs and Space-Time-MOCs.
6565
Defaults to None, which means that the search will be on the whole sky.
66-
meta_data : str
67-
Algebraic expression to select the datasets.
66+
criteria : str
67+
Expression to select the datasets.
6868
Examples of expressions can be found `on the mocserver's examples page
6969
<http://alasky.unistra.fr/MocServer/example>`_.
7070
Example: "ID=*HST*" will return datasets with HST in their ID column. The
@@ -114,7 +114,7 @@ def query_region(
114114
115115
"""
116116
response = self.query_async(
117-
meta_data=meta_data,
117+
criteria=criteria,
118118
region=region,
119119
intersect=intersect,
120120
return_moc=return_moc,
@@ -133,7 +133,7 @@ def query_region(
133133
def query_hips(
134134
self,
135135
*,
136-
meta_data=None,
136+
criteria=None,
137137
region=None,
138138
intersect="overlaps",
139139
return_moc=None,
@@ -150,8 +150,8 @@ def query_hips(
150150
151151
Parameters
152152
----------
153-
meta_data : str
154-
Algebraic expression to select the datasets.
153+
criteria : str
154+
Expression to select the datasets.
155155
Examples of expressions can be found `on the mocserver's examples page
156156
<http://alasky.unistra.fr/MocServer/example>`_.
157157
Example: "ID=*HST*" will return datasets with HST in their ID column. The
@@ -204,12 +204,12 @@ def query_hips(
204204
union of the MOCs from all the retrieved data-sets.
205205
206206
"""
207-
if meta_data:
208-
meta_data = f"({meta_data})&&hips_frame=*"
207+
if criteria:
208+
criteria = f"({criteria})&&hips_frame=*"
209209
else:
210-
meta_data = "hips_frame=*"
210+
criteria = "hips_frame=*"
211211
return self.query_region(
212-
meta_data=meta_data,
212+
criteria=criteria,
213213
region=region,
214214
intersect=intersect,
215215
return_moc=return_moc,
@@ -224,7 +224,9 @@ def query_hips(
224224
)
225225

226226
@deprecated(since="v0.4.9",
227-
alternative="query_region")
227+
message="'find_datasets' is replaced by 'query_region' which has a new "
228+
"parameter 'criteria' that accepts the expressions that "
229+
"'meta_data' was accepting.")
228230
def find_datasets(
229231
self, meta_data,
230232
*,
@@ -245,7 +247,7 @@ def find_datasets(
245247
Parameters
246248
----------
247249
meta_data : str
248-
Algebraic expression to select the datasets.
250+
Expression to select the datasets.
249251
Examples of expressions can be found `on the mocserver's examples page
250252
<http://alasky.unistra.fr/MocServer/example>`_.
251253
Example: "ID=*HST*" will return datasets with HST in their ID column. The
@@ -299,7 +301,7 @@ def find_datasets(
299301
300302
"""
301303
return self.query_region(
302-
meta_data=meta_data,
304+
criteria=meta_data,
303305
region=region,
304306
intersect=intersect,
305307
return_moc=return_moc,
@@ -317,7 +319,7 @@ def query_async(
317319
self,
318320
*,
319321
region=None,
320-
meta_data=None,
322+
criteria=None,
321323
return_moc=None,
322324
max_norder=None,
323325
fields=None,
@@ -332,8 +334,8 @@ def query_async(
332334
333335
Parameters
334336
----------
335-
meta_data : str
336-
Algebraic expression to select the datasets.
337+
criteria : str
338+
Expression to select the datasets.
337339
Examples of expressions can be found `on the mocserver's examples page
338340
<http://alasky.unistra.fr/MocServer/example>`_.
339341
Example: "ID=*HST*" will return datasets with HST in their ID column. The
@@ -385,7 +387,7 @@ def query_async(
385387
386388
"""
387389
request_payload = _args_to_payload(
388-
meta_data=meta_data,
390+
criteria=criteria,
389391
return_moc=return_moc,
390392
max_norder=max_norder,
391393
fields=fields,
@@ -491,7 +493,7 @@ def list_coordinate_systems(self):
491493
The list of coordinate systems currently available in the MOC Server
492494
493495
"""
494-
frames = list(set(self.query_region(meta_data="hips_frame=*",
496+
frames = list(set(self.query_region(criteria="hips_frame=*",
495497
fields=["ID", "hips_frame"],
496498
coordinate_system=None)["hips_frame"]))
497499
# `C` is a special case that corresponds to both equatorial and galactic frames
@@ -502,7 +504,7 @@ def list_coordinate_systems(self):
502504

503505
def _args_to_payload(
504506
*,
505-
meta_data=None,
507+
criteria=None,
506508
return_moc=None,
507509
max_norder=None,
508510
fields=None,
@@ -566,8 +568,8 @@ def _args_to_payload(
566568
f" or 'mocpy.STMOC', but is of type '{type(region)}'."
567569
)
568570

569-
if meta_data:
570-
request_payload.update({"expr": meta_data})
571+
if criteria:
572+
request_payload.update({"expr": criteria})
571573

572574
if max_rec:
573575
request_payload.update({"MAXREC": str(max_rec)})

astroquery/mocserver/tests/test_mocserver.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_query_hips():
9292
payload = MOCServer.query_hips(get_query_payload=True)
9393
assert payload["expr"] == "hips_frame=*"
9494
# with meta
95-
payload = MOCServer.query_hips(meta_data="TEST", get_query_payload=True)
95+
payload = MOCServer.query_hips(criteria="TEST", get_query_payload=True)
9696
assert payload["expr"] == "(TEST)&&hips_frame=*"
9797

9898

@@ -138,7 +138,7 @@ def test_list_fields():
138138
def _mock_list_coordinate_systems(monkeypatch):
139139
# This list changes upstream. To regenerate it, do:
140140
# >>> from astroquery.mocserver import MOCServer
141-
# >>> hips_frames = MOCServer.query_region(meta_data="hips_frame=*",
141+
# >>> hips_frames = MOCServer.query_region(criteria="hips_frame=*",
142142
# ... fields=["hips_frame"],
143143
# ... coordinate_system=None, max_rec=100)
144144
# >>> hips_frames.remove_column("ID")
@@ -180,54 +180,54 @@ def test_intersect_param(intersect):
180180

181181
def test_fields():
182182
# check that it works for a single field
183-
payload = MOCServer.query_region(meta_data="", fields="ID", get_query_payload=True)
183+
payload = MOCServer.query_region(criteria="", fields="ID", get_query_payload=True)
184184
assert payload["fields"] == "ID"
185185
# as well as more fields
186186
payload = MOCServer.query_region(
187-
meta_data="", fields=["ID", "hips_properties"], get_query_payload=True
187+
criteria="", fields=["ID", "hips_properties"], get_query_payload=True
188188
)
189189
# cannot test the order, due to the use of set
190190
assert "hips_properties" in payload["fields"] and "ID" in payload["fields"]
191191
# ID has to be in fields
192192
payload = MOCServer.query_region(
193-
meta_data="", fields="hips_body", get_query_payload=True
193+
criteria="", fields="hips_body", get_query_payload=True
194194
)
195195
assert "ID" in payload["fields"]
196196

197197

198198
def test_caseinsensitive():
199199
# casesensitive was hardcoded to true until astroquery 0.4.8. It is now an option
200-
payload = MOCServer.query_region(meta_data="", fields="ID", get_query_payload=True)
200+
payload = MOCServer.query_region(criteria="", fields="ID", get_query_payload=True)
201201
assert payload["casesensitive"] == "false"
202202
payload = MOCServer.query_region(
203-
meta_data="", fields="ID", get_query_payload=True, casesensitive=True
203+
criteria="", fields="ID", get_query_payload=True, casesensitive=True
204204
)
205205
assert payload["casesensitive"] == "true"
206206

207207

208208
def test_maxrec():
209-
payload = MOCServer.query_region(meta_data="", max_rec=100, get_query_payload=True)
209+
payload = MOCServer.query_region(criteria="", max_rec=100, get_query_payload=True)
210210
assert payload["MAXREC"] == "100"
211211

212212

213213
def test_return_moc():
214214
# legacy compatibility, return_moc=True means a space-MOC
215215
payload = MOCServer.query_region(
216-
meta_data="", return_moc=True, max_norder=5, get_query_payload=True
216+
criteria="", return_moc=True, max_norder=5, get_query_payload=True
217217
)
218218
assert payload["get"] == "moc"
219219
assert payload["fmt"] == "ascii"
220220
assert payload["order"] == 5
221221
# no max_norder means maximum order available
222222
payload = MOCServer.query_region(
223-
meta_data="", return_moc=True, get_query_payload=True
223+
criteria="", return_moc=True, get_query_payload=True
224224
)
225225
assert payload["order"] == "max"
226226

227227

228228
def test_coordinate_system():
229229
payload = MOCServer.query_region(
230-
coordinate_system="sky", meta_data="", return_moc=True,
230+
coordinate_system="sky", criteria="", return_moc=True,
231231
max_norder=5, get_query_payload=True
232232
)
233233
assert payload["spacesys"] == "C"
@@ -271,6 +271,8 @@ def test_cast_to_float():
271271

272272
def test_find_datasets():
273273
# find datasets is useless as it does the same than query region
274-
with pytest.warns(AstropyDeprecationWarning, match="The find_datasets function *"):
274+
# and 'meta_data' is replaced byt the new argument 'criteria' in query_region
275+
with pytest.warns(AstropyDeprecationWarning, match="'find_datasets' is replaced "
276+
"by 'query_region' *"):
275277
old = MOCServer.find_datasets(meta_data="ID=*Euclid*", get_query_payload=True)
276-
assert old == MOCServer.query_region(meta_data="ID=*Euclid*", get_query_payload=True)
278+
assert old == MOCServer.query_region(criteria="ID=*Euclid*", get_query_payload=True)

astroquery/mocserver/tests/test_mocserver_remote.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_moc_order_param(self, moc_order):
5959
def test_stmoc_as_outputs(self):
6060
# chose a dataset with a MOC with few cells
6161
stmoc = MOCServer.query_region(
62-
meta_data="ID=CDS/J/AJ/157/109/table1", return_moc="stmoc"
62+
criteria="ID=CDS/J/AJ/157/109/table1", return_moc="stmoc"
6363
)
6464
assert isinstance(stmoc, STMOC)
6565

@@ -69,7 +69,7 @@ def test_temporal_mocs_as_inputs(self):
6969
region=tmoc,
7070
fields=["t_min"],
7171
max_rec=100,
72-
meta_data="dataproduct_type='image'&&t_min=*",
72+
criteria="dataproduct_type='image'&&t_min=*",
7373
)
7474
min_time_result = Time(result["t_min"].value, format="mjd")
7575
# the resulting datasets should only have starting times after the
@@ -78,7 +78,7 @@ def test_temporal_mocs_as_inputs(self):
7878

7979
def test_no_region(self):
8080
result = MOCServer.query_region(
81-
meta_data="moc_sky_fraction>0.5&&moc_sky_fraction=*",
81+
criteria="moc_sky_fraction>0.5&&moc_sky_fraction=*",
8282
fields=["ID", "moc_sky_fraction"],
8383
max_rec=100,
8484
)

docs/mocserver/mocserver.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ Querying by meta-data
127127
Retrieving datasets based on their meta-data values
128128
----------------------------------------------------
129129

130-
The ``meta_data`` parameter of :meth:`~astroquery.mocserver.MOCServerClass.query_region`
131-
allows to write an algebraic expression on the metadata.
130+
The ``criteria`` parameter of :meth:`~astroquery.mocserver.MOCServerClass.query_region`
131+
allows to write an expression on the dataset's metadata to filter the output.
132132
Let's add a criteria to get only images from the previous query:
133133

134134
.. doctest-requires:: mocpy
@@ -141,7 +141,7 @@ Let's add a criteria to get only images from the previous query:
141141
>>> cone = CircleSkyRegion(center, radius)
142142
>>> MOCServer.query_region(region=cone, intersect="enclosed",
143143
... fields=['ID', 'dataproduct_type', 'moc_sky_fraction'],
144-
... meta_data="dataproduct_type=image") # doctest: +IGNORE_OUTPUT +REMOTE_DATA
144+
... criteria="dataproduct_type=image") # doctest: +IGNORE_OUTPUT +REMOTE_DATA
145145
<Table length=336>
146146
ID dataproduct_type moc_sky_fraction
147147
str49 str5 float64
@@ -180,7 +180,7 @@ their identifier. These correspond to the Hubble surveys:
180180

181181
.. doctest-requires:: mocpy
182182

183-
>>> MOCServer.query_region(meta_data="ID=*HST*",
183+
>>> MOCServer.query_region(criteria="ID=*HST*",
184184
... fields=['ID', 'moc_access_url'],
185185
... casesensitive=False) # doctest: +IGNORE_OUTPUT +REMOTE_DATA
186186
<Table length=45>
@@ -215,7 +215,7 @@ The MOCServer contains an extensive list of `HiPS <https://ivoa.net/documents/Hi
215215
for images and catalogs. These progressive surveys can be displayed in applications
216216
such as `ipyaladin <https://github.com/cds-astro/ipyaladin>`_. The
217217
`astroquery.mocserver.MOCServerClass.query_hips` method allows to find these HiPS.
218-
It accepts the same parameters (``region`` and ``meta_data`` for example) as the other
218+
It accepts the same parameters (``region`` and ``criteria`` for example) as the other
219219
methods. The only difference is that the output will only contain HiPS data.
220220

221221
.. doctest-requires:: mocpy
@@ -332,7 +332,7 @@ Hubble surveys:
332332
>>> from astroquery.mocserver import MOCServer
333333
>>> moc = MOCServer.query_region(return_moc="smoc",
334334
... max_norder=20,
335-
... meta_data="ID=*HST*") # doctest: +REMOTE_DATA
335+
... criteria="ID=*HST*") # doctest: +REMOTE_DATA
336336

337337
The resulting MOC looks like:
338338

@@ -350,7 +350,7 @@ object) of the ``GALEXGR6/AIS/FUV`` survey.
350350

351351
>>> from mocpy import MOC
352352
>>> from astroquery.mocserver import MOCServer
353-
>>> moc_galex = MOCServer.query_region(meta_data="ID=CDS/P/GALEXGR6/AIS/FUV",
353+
>>> moc_galex = MOCServer.query_region(criteria="ID=CDS/P/GALEXGR6/AIS/FUV",
354354
... return_moc="stmoc", max_norder="s7 t26") # doctest: +REMOTE_DATA
355355
>>> print(f"GALEX GR6 contains data taken from {moc_galex.min_time.iso} to"
356356
... f" {moc_galex.max_time.iso}.") # doctest: +REMOTE_DATA

0 commit comments

Comments
 (0)