Skip to content

Commit 63713e8

Browse files
committed
Update docs.
1 parent c882340 commit 63713e8

File tree

8 files changed

+163
-67
lines changed

8 files changed

+163
-67
lines changed

README.rst

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
===========
2-
viresclient
3-
===========
41

52
.. image:: https://badge.fury.io/py/viresclient.svg
63
:target: https://badge.fury.io/py/viresclient
@@ -22,10 +19,85 @@ viresclient
2219
.. image:: https://zenodo.org/badge/138034133.svg
2320
:target: https://zenodo.org/badge/latestdoi/138034133
2421

25-
``viresclient`` is a tool which connects to a VirES server through the `WPS <http://www.opengeospatial.org/standards/wps>`_ interface and handles product requests and downloads.
26-
27-
Install with::
22+
::
2823

2924
pip install viresclient
3025

31-
Full documentation: http://viresclient.readthedocs.io/
26+
viresclient_ is a Python package which connects to a VirES_ server through the WPS_ interface and handles product requests and downloads. This enables easy access to ESA's `Swarm mission`_ data and models. This service is provided for ESA by EOX_. For enquiries or help, please email [email protected] or `raise an issue on GitHub`_.
27+
28+
.. _viresclient: https://github.com/ESA-VirES/VirES-Python-Client
29+
.. _VirES: https://vires.services
30+
.. _WPS: http://www.opengeospatial.org/standards/wps
31+
.. _`Swarm mission`: https://earth.esa.int/web/guest/missions/esa-operational-eo-missions/swarm
32+
.. _EOX: https://eox.at/category/vires/
33+
.. _`raise an issue on GitHub`: https://github.com/ESA-VirES/VirES-Python-Client/issues
34+
35+
Data and models are processed on demand on the server - a combination of measurements from any time interval can be accessed. These are the same data that can be accessed by the `VirES GUI`_. *viresclient* handles the returned data to allow direct loading as a single pandas.DataFrame_, or xarray.Dataset_.
36+
37+
.. _pandas.DataFrame: https://pandas.pydata.org/pandas-docs/stable/dsintro.html#dataframe
38+
.. _xarray.Dataset: http://xarray.pydata.org/en/stable/data-structures.html#dataset
39+
.. _`VirES GUI`: https://vires.services
40+
41+
.. code-block:: python
42+
43+
from viresclient import SwarmRequest
44+
45+
# Set up connection with server
46+
request = SwarmRequest()
47+
# Set collection to use
48+
request.set_collection("SW_OPER_MAGA_LR_1B")
49+
# Set mix of products to fetch:
50+
# measurements (variables from the given collection)
51+
# models (magnetic model predictions at spacecraft sampling points)
52+
# auxiliaries (variables available with any collection)
53+
request.set_products(
54+
measurements=["F", "B_NEC"],
55+
models=["CHAOS-Core"],
56+
auxiliaries=["QDLat", "QDLon"],
57+
sampling_step="PT10S"
58+
)
59+
# Fetch data from a given time interval
60+
data = request.get_between(
61+
start_time="2014-01-01T00:00",
62+
end_time="2014-01-01T01:00"
63+
)
64+
# Load the data as an xarray.Dataset
65+
ds = data.as_xarray()
66+
67+
.. code-block::
68+
69+
<xarray.Dataset>
70+
Dimensions: (NEC: 3, Timestamp: 360)
71+
Coordinates:
72+
* Timestamp (Timestamp) datetime64[ns] 2014-01-01 ... 2014-01-01T00:59:50
73+
Dimensions without coordinates: NEC
74+
Data variables:
75+
Spacecraft (Timestamp) <U1 'A' 'A' 'A' 'A' 'A' ... 'A' 'A' 'A' 'A'
76+
Latitude (Timestamp) float64 -1.229 -1.863 -2.496 ... 48.14 48.77
77+
Longitude (Timestamp) float64 -14.12 -14.13 -14.15 ... 153.6 153.6
78+
Radius (Timestamp) float64 6.878e+06 6.878e+06 ... 6.868e+06
79+
F (Timestamp) float64 2.287e+04 2.281e+04 ... 4.021e+04
80+
F_CHAOS-Core (Timestamp) float64 2.287e+04 2.282e+04 ... 4.02e+04
81+
B_NEC (Timestamp, NEC) float64 2.01e+04 -4.126e+03 ... 3.558e+04
82+
B_NEC_CHAOS-Core (Timestamp, NEC) float64 2.011e+04 ... 3.557e+04
83+
QDLat (Timestamp) float64 -11.99 -12.6 -13.2 ... 41.59 42.25
84+
QDLon (Timestamp) float64 58.02 57.86 57.71 ... -135.9 -136.0
85+
Attributes:
86+
Sources: ['SW_OPER_MAGA_LR_1B_20140101T000000_20140101T235959_050...
87+
MagneticModels: ["CHAOS-Core = 'CHAOS-Core'(max_degree=20,min_degree=1)"]
88+
RangeFilters: []
89+
90+
91+
*viresclient* is installed on the `"Virtual Research Environment" (VRE)`_, which is a managed Jupyter-based system provided for ESA by EOX. The service is free and open to all.
92+
93+
.. _`"Virtual Research Environment" (VRE)`: https://vre.vires.services/
94+
95+
.. image:: https://github.com/ESA-VirES/Swarm-VRE/raw/master/docs/images/VRE_shortest_demo.gif
96+
97+
98+
How to acknowledge VirES
99+
------------------------
100+
101+
You can reference *viresclient* directly using the DOI of our zenodo_ record. VirES uses data from a number of different sources so please also acknowledge these appropriately.
102+
103+
.. _zenodo: https://doi.org/10.5281/zenodo.2554162

docs/available_parameters.rst

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ Models are evaluated along the satellite track at the positions of the time seri
9898
MMA_SHA_2F-Primary, MMA_SHA_2F-Secondary,
9999

100100
# CHAOS models:
101-
CHAOS-6-Core,
102-
CHAOS-6-Static,
103-
CHAOS-6-MMA-Primary, CHAOS-6-MMA-Secondary
101+
CHAOS-Core,
102+
CHAOS-Static,
103+
CHAOS-MMA-Primary, CHAOS-MMA-Secondary
104104

105105
# Other lithospheric models:
106106
MF7, LCS-1
@@ -111,7 +111,15 @@ Flexible evaluation of models and defining new derived models is possible with t
111111

112112
.. code-block:: python
113113
114-
"Combined_model = 'MMA_SHA_2F-Primary'(min_degree=1,max_degree=1) + 'MMA_SHA_2F-Secondary'(min_degree=1,max_degree=1)"
114+
request.set_products(
115+
...
116+
models=["Combined_model = 'MMA_SHA_2F-Primary'(min_degree=1,max_degree=1) + 'MMA_SHA_2F-Secondary'(min_degree=1,max_degree=1)"],
117+
...
118+
)
119+
120+
In this case, model evaluations will then be available in the returned data under the name "Combined_model", but you can name it however you like.
121+
122+
NB: When using model names containing a hyphen (``-``) then extra single (``'``) or double (``"``) quotes must be used around the model name. This is to distinguish from arithmetic minus (``-``).
115123

116124
----
117125

@@ -134,7 +142,7 @@ Flexible evaluation of models and defining new derived models is possible with t
134142

135143
.. note::
136144

137-
- The AMPS model is currently accessible as "auxiliaries" instead of a "model"
145+
- The AMPS model is currently accessible as "auxiliaries" instead of a "model" (On the DISC server it is now accessible as a regular model)
138146
- ``Kp`` provides the Kp values in fractional form (e.g 2.2), and ``Kp10`` is multiplied by 10 (as integers)
139147
- ``F107`` is the hourly 10.7 cm solar radio flux value, and ``F10_INDEX`` is the daily average
140148
- ``QDLat`` and ``QDLon`` are quasi-dipole coordinates

docs/installation.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Installation and first usage
88

99
viresclient is already installed so skip this step. Log in at https://vre.vires.services/ and refer to documentation at https://swarm-vre.readthedocs.io/
1010

11-
You will still need to configure viresclient (see step 2)
11+
You may still need to configure viresclient (see step 2)
1212

1313
Python ≥ 3.5 is required. Tested primarily on Linux, but macOS and Windows should also work (on v0.4+).
1414

@@ -54,6 +54,15 @@ Recommended setup if starting without Python already
5454

5555
.. note:: For Jupyter notebook users:
5656

57+
On creation of a SwarmRequest object, you will automatically be prompted to set a token. Just try::
58+
59+
from viresclient import SwarmRequest
60+
request = SwarmRequest()
61+
62+
and follow the instructions.
63+
64+
[ Below instructions to be updated with new notebook. ]
65+
5766
The guide for first time usage are also provided as a Jupyter notebook. Download the notebook to your environment and follow the instructions.
5867

5968
https://github.com/smithara/viresclient_examples/blob/master/0_first_usage.ipynb

docs/readme.rst

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,4 @@
11
Introduction
22
============
33

4-
This is the documentation for the ``viresclient`` Python package. This is a tool which connects to a VirES_ server through the WPS_ interface and handles product requests and downloads. This enables easy access to ESA's Swarm mission data and models. For enquiries or help, please email [email protected] or `raise an issue on GitHub`_
5-
6-
.. _VirES: https://vires.services
7-
.. _WPS: http://www.opengeospatial.org/standards/wps
8-
.. _`raise an issue on GitHub`: https://github.com/ESA-VirES/VirES-Python-Client/issues
9-
10-
Some links where you can read more about VirES:
11-
12-
- `VirES web service`_
13-
- `Swarm DQW slides about viresclient`_
14-
- `EOX blog posts`_
15-
- `Swarm mission`_
16-
17-
.. _`VirES web service`: https://vires.services/
18-
.. _`Swarm DQW slides about viresclient`: https://github.com/smithara/viresclient_examples/blob/master/viresclient_SwarmDQW8.pdf
19-
.. _`EOX blog posts`: https://eox.at/category/vires/
20-
.. _`Swarm mission`: https://earth.esa.int/web/guest/missions/esa-operational-eo-missions/swarm
21-
22-
``viresclient`` is installed on the "Virtual Research Environment" (VRE), which is a managed Jupyter-based system provided by ESA:
23-
24-
- `VRE documentation`_
25-
26-
.. _`VRE documentation`: https://swarm-vre.readthedocs.io/
27-
28-
Data can be accessed from the server as CSV or CDF files and saved to disk, or loaded directly into Python objects pandas.DataFrame_, or xarray.Dataset_.
29-
30-
.. _pandas.DataFrame: https://pandas.pydata.org/pandas-docs/stable/dsintro.html#dataframe
31-
32-
.. _xarray.Dataset: http://xarray.pydata.org/en/stable/data-structures.html#dataset
33-
34-
cdflib_ is used to read CDF files.
35-
36-
.. _cdflib: https://github.com/MAVENSDC/cdflib
37-
38-
The project is on GitHub at https://github.com/ESA-VirES/VirES-Python-Client - please feel free to contribute with any code/suggestions/comments.
39-
40-
A repository of example notebooks can be found at https://github.com/smithara/viresclient_examples. We welcome contribution of notebooks to this repository that show some short analyses or generating useful figures. It can be hard to remember or figure how do things (e.g. remembering Swarm product names; understanding the VirES "language" and what is possible; making certain kinds of figures with various libraries) so these notebooks are meant to act as recipes we can follow, to demonstrate code that can be copied and adapted for other purposes.
41-
42-
How to acknowledge VirES
43-
------------------------
44-
45-
You can reference ``viresclient`` directly using the DOI of our zenodo_ record. VirES uses data from a number of different sources so please also acknowledge these appropriately.
46-
47-
.. _zenodo: https://doi.org/10.5281/zenodo.2554163
4+
.. include:: ../README.rst

docs/release_notes.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
Release notes
22
=============
33

4+
Changes from 0.4.2 to 0.4.3
5+
---------------------------
6+
7+
- AMPS is now accessible as a regular model on the DISC server, see::
8+
9+
request = SwarmRequest("https://staging.viresdisc.vires.services/ows")
10+
request.get_model_info(["AMPS"])
11+
12+
- xarray.Dataset objects now contain dimension names for all variables. Variables containing "B_NEC" get the "NEC" dimension name.
13+
- CHAOS model series have changed name: "CHAOS-6-Core" etc. is dropped for "CHAOS-Core" etc. which provides the latest version of the CHAOS models (currently CHAOS-7)
14+
- Better error message when authentication with server fails.
15+
- When in notebooks: Detect empty or invalid credentials (e.g. on first usage), direct user to the token generation page, and prompt for token input.
16+
- Added ``request.list_jobs()`` to give info on previous two jobs on the server (failed/running/succeeded).
17+
418
Changes from 0.4.1 to 0.4.2
519
---------------------------
620

viresclient/_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,11 @@ def get_between(self, start_time=None, end_time=None,
560560
return retdatagroup
561561

562562
def list_jobs(self):
563-
""" Return job information from the server """
563+
""" Return job information from the server.
564+
565+
Returns:
566+
dict
567+
"""
564568
templatefile = TEMPLATE_FILES['list_jobs']
565569
template = JINJA2_ENVIRONMENT.get_template(templatefile)
566570
request = template.render().encode('UTF-8')

viresclient/_client_swarm.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,17 +296,37 @@ def custom_shc(self, custom_shc):
296296
class SwarmRequest(ClientRequest):
297297
"""Handles the requests to and downloads from the server.
298298
299-
Steps to download data:
300-
301-
1. Set up a connection to the server with: request = SwarmRequest()
302-
303-
2. Set collections to use with: request.set_collections()
304-
305-
3. Set parameters to get with: request.set_products()
299+
Example usage::
300+
301+
from viresclient import SwarmRequest
302+
# Set up connection with server
303+
request = SwarmRequest()
304+
# Set collection to use
305+
request.set_collection("SW_OPER_MAGA_LR_1B")
306+
# Set mix of products to fetch:
307+
# measurements (variables from the given collection)
308+
# models (magnetic model predictions at spacecraft sampling points)
309+
# auxiliaries (variables available with any collection)
310+
request.set_products(
311+
measurements=["F", "B_NEC"],
312+
models=["CHAOS-Core"],
313+
auxiliaries=["QDLat", "QDLon"],
314+
sampling_step="PT10S"
315+
)
316+
# Fetch data from a given time interval
317+
data = request.get_between(
318+
start_time="2014-01-01T00:00",
319+
end_time="2014-01-01T01:00"
320+
)
321+
# Load the data as an xarray.Dataset
322+
ds = data.as_xarray()
306323
307-
4. Set filters to apply with: request.set_range_filter()
324+
Check what data are available with::
308325
309-
5. Get the data in a chosen time window: request.get_between()
326+
request.available_collections(details=False)
327+
request.available_measurements("MAG")
328+
request.available_auxiliaries()
329+
request.available_models(details=False)
310330
311331
Args:
312332
url (str):
@@ -623,6 +643,7 @@ def set_collection(self, *args):
623643
)
624644
self._collection_list = collections
625645
self._request_inputs.set_collections(collections)
646+
return self
626647

627648
def set_products(self, measurements=None, models=None, custom_model=None,
628649
auxiliaries=None, residuals=False, sampling_step=None
@@ -717,6 +738,7 @@ def set_products(self, measurements=None, models=None, custom_model=None,
717738
self._request_inputs.variables = variables
718739
self._request_inputs.sampling_step = sampling_step
719740
self._request_inputs.custom_shc = custom_shc
741+
return self
720742

721743
def set_range_filter(self, parameter=None, minimum=None, maximum=None):
722744
"""Set a filter to apply.
@@ -743,11 +765,13 @@ def set_range_filter(self, parameter=None, minimum=None, maximum=None):
743765
filters = ';'.join(self._filterlist)
744766
# Update the SwarmWPSInputs object
745767
self._request_inputs.filters = filters
768+
return self
746769

747770
def clear_range_filter(self):
748771
"""Remove all applied filters."""
749772
self._filterlist = []
750773
self._request_inputs.filters = None
774+
return self
751775

752776
def get_times_for_orbits(self, spacecraft, start_orbit, end_orbit):
753777
"""Translate a pair of orbit numbers to a time interval.

viresclient/_data_handling.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,14 @@ class ReturnedData(object):
398398
The number of them, N, is set upon initialisation.
399399
Access the ReturnedDataFile objects directly via the list in ReturnedData.contents.
400400
401+
Example usage::
402+
403+
...
404+
data = request.get_between(..., ...)
405+
data.as_xarray()
406+
data.as_dataframe(expand=True)
407+
data.to_file()
408+
401409
"""
402410

403411
def __init__(self, filetype=None, N=1, tmpdir=None):

0 commit comments

Comments
 (0)