Skip to content

Commit 9d1cfe0

Browse files
authored
Add get_collection_info (#100)
1 parent 3cd1075 commit 9d1cfe0

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

docs/capabilities.rst

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ VirES provides more than just *access* to data. Some operations can be peformed
2121
| :py:meth:`viresclient.SwarmRequest.available_times`
2222
| :py:meth:`viresclient.SwarmRequest.get_orbit_number`
2323
| :py:meth:`viresclient.SwarmRequest.get_times_for_orbits`
24+
| :py:meth:`viresclient.SwarmRequest.get_collection_info`
2425
**Geomagnetic model evaluation**
2526
| Forwards evaluation of magnetic field models when a magnetic dataset is selected (e.g. ``MAGx_LR``). For more detail, see :ref:`Geomagnetic model handling`.
2627
| :py:meth:`viresclient.SwarmRequest.available_models`

src/viresclient/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@
3535
from ._config import ClientConfig, set_token
3636
from ._data_handling import ReturnedData, ReturnedDataFile
3737

38-
__version__ = "0.12.3"
38+
__version__ = "0.13.0"

src/viresclient/_client_swarm.py

+40
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"times_from_orbits": "vires_times_from_orbits.xml",
2727
"get_observatories": "vires_get_observatories.xml",
2828
"get_conjunctions": "vires_get_conjunctions.xml",
29+
"get_collection_info": "vires_get_collection_info.xml",
2930
}
3031

3132
REFERENCES = {
@@ -2243,6 +2244,45 @@ def applied_filters(self):
22432244
for filter_ in self._filterlist:
22442245
print(filter_)
22452246

2247+
def get_collection_info(self, collections):
2248+
"""Get information about a list of collections
2249+
2250+
Args:
2251+
collections (str | list[str]): Collection or list of collections
2252+
2253+
Returns:
2254+
list[dict]: A list of dictionaries containing information about each collection
2255+
2256+
Examples:
2257+
2258+
.. code-block:: python
2259+
2260+
from viresclient import SwarmRequest
2261+
request = SwarmRequest("https://vires.services/ows")
2262+
info = request.get_collection_info("SW_OPER_MAGA_LR_1B")
2263+
2264+
gives::
2265+
2266+
[{'name': 'SW_OPER_MAGA_LR_1B',
2267+
'productType': 'SW_MAGx_LR_1B',
2268+
'productCount': 3579,
2269+
'timeExtent': {'start': '2013-11-25T11:02:52Z',
2270+
'end': '2023-09-28T23:59:59Z'}}]
2271+
"""
2272+
if isinstance(collections, str):
2273+
collections = [collections]
2274+
if not isinstance(collections, list):
2275+
raise TypeError("collections must be a string or list")
2276+
templatefile = TEMPLATE_FILES["get_collection_info"]
2277+
template = JINJA2_ENVIRONMENT.get_template(templatefile)
2278+
request = template.render(
2279+
collections=",".join(collections),
2280+
response_type="application/json",
2281+
).encode("UTF-8")
2282+
response = self._get(request, asynchronous=False, show_progress=False)
2283+
response = json.loads(response.decode("UTF-8"))
2284+
return response
2285+
22462286
def get_times_for_orbits(
22472287
self, start_orbit, end_orbit, mission="Swarm", spacecraft=None
22482288
):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0"?>
2+
<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">
3+
<ows:Identifier>vires:get_collection_info</ows:Identifier>
4+
<wps:DataInputs>
5+
<wps:Input>
6+
<ows:Identifier>collection</ows:Identifier>
7+
<wps:Data>
8+
<wps:LiteralData>{{ collections }}</wps:LiteralData>
9+
</wps:Data>
10+
</wps:Input>
11+
</wps:DataInputs>
12+
<wps:ResponseForm>
13+
<wps:RawDataOutput mimeType="{{ response_type }}">
14+
<ows:Identifier>output</ows:Identifier>
15+
</wps:RawDataOutput>
16+
</wps:ResponseForm>
17+
</wps:Execute>

0 commit comments

Comments
 (0)