Skip to content

Add get_collection_info #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 28, 2025
1 change: 1 addition & 0 deletions docs/capabilities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ VirES provides more than just *access* to data. Some operations can be peformed
| :py:meth:`viresclient.SwarmRequest.available_times`
| :py:meth:`viresclient.SwarmRequest.get_orbit_number`
| :py:meth:`viresclient.SwarmRequest.get_times_for_orbits`
| :py:meth:`viresclient.SwarmRequest.get_collection_info`
**Geomagnetic model evaluation**
| Forwards evaluation of magnetic field models when a magnetic dataset is selected (e.g. ``MAGx_LR``). For more detail, see :ref:`Geomagnetic model handling`.
| :py:meth:`viresclient.SwarmRequest.available_models`
Expand Down
2 changes: 1 addition & 1 deletion src/viresclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
from ._config import ClientConfig, set_token
from ._data_handling import ReturnedData, ReturnedDataFile

__version__ = "0.12.3"
__version__ = "0.13.0"
40 changes: 40 additions & 0 deletions src/viresclient/_client_swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"times_from_orbits": "vires_times_from_orbits.xml",
"get_observatories": "vires_get_observatories.xml",
"get_conjunctions": "vires_get_conjunctions.xml",
"get_collection_info": "vires_get_collection_info.xml",
}

REFERENCES = {
Expand Down Expand Up @@ -2243,6 +2244,45 @@ def applied_filters(self):
for filter_ in self._filterlist:
print(filter_)

def get_collection_info(self, collections):
"""Get information about a list of collections

Args:
collections (str | list[str]): Collection or list of collections

Returns:
list[dict]: A list of dictionaries containing information about each collection

Examples:

.. code-block:: python

from viresclient import SwarmRequest
request = SwarmRequest("https://vires.services/ows")
info = request.get_collection_info("SW_OPER_MAGA_LR_1B")

gives::

[{'name': 'SW_OPER_MAGA_LR_1B',
'productType': 'SW_MAGx_LR_1B',
'productCount': 3579,
'timeExtent': {'start': '2013-11-25T11:02:52Z',
'end': '2023-09-28T23:59:59Z'}}]
"""
if isinstance(collections, str):
collections = [collections]
if not isinstance(collections, list):
raise TypeError("collections must be a string or list")
templatefile = TEMPLATE_FILES["get_collection_info"]
template = JINJA2_ENVIRONMENT.get_template(templatefile)
request = template.render(
collections=",".join(collections),
response_type="application/json",
).encode("UTF-8")
response = self._get(request, asynchronous=False, show_progress=False)
response = json.loads(response.decode("UTF-8"))
return response

def get_times_for_orbits(
self, start_orbit, end_orbit, mission="Swarm", spacecraft=None
):
Expand Down
17 changes: 17 additions & 0 deletions src/viresclient/_wps/templates/vires_get_collection_info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<wps:Execute xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" version="1.0.0" service="WPS">
<ows:Identifier>vires:get_collection_info</ows:Identifier>
<wps:DataInputs>
<wps:Input>
<ows:Identifier>collection</ows:Identifier>
<wps:Data>
<wps:LiteralData>{{ collections }}</wps:LiteralData>
</wps:Data>
</wps:Input>
</wps:DataInputs>
<wps:ResponseForm>
<wps:RawDataOutput mimeType="{{ response_type }}">
<ows:Identifier>output</ows:Identifier>
</wps:RawDataOutput>
</wps:ResponseForm>
</wps:Execute>
Loading