VirES is a platform for data access, analysis, and visualisation for ESA's magnetic mission, Swarm
This tutorial introduces the Python interface to VirES, viresclient
For more information see:
To access VirES through Python code, you first need to generate an authentication token from your VirES account:
This can also be done via the command line. For more info, see https://viresclient.readthedocs.io/en/latest/installation.html
%%HTML
<iframe width="840" height="472" src="https://www.youtube.com/embed/L25IvTwgjG4" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
from viresclient import ClientConfig
cc = ClientConfig()
cc.set_site_config("https://vires.services/ows", token="...")
cc.default_url = "https://vires.services/ows"
cc.save()
Import the SwarmRequest
object which provides the VirES interface, and datetime
which gives convenient time objects which can be used by SwarmRequest.get_between()
from viresclient import SwarmRequest
import datetime as dt
%matplotlib inline
The following code will fetch one day (i.e. around 15 orbits) of the scalar (F
) measurements from Swarm Alpha. The data are then loaded as a pandas
dataframe. sampling_step="PT10S"
donwsamples the data to 10 seconds, from the MAGx_LR
default of 1 second.
request = SwarmRequest()
request.set_collection("SW_OPER_MAGA_LR_1B")
request.set_products(
measurements=["F"],
sampling_step="PT10S"
)
data = request.get_between(
start_time=dt.datetime(2016,1,1),
end_time=dt.datetime(2016,1,2)
)
df = data.as_dataframe()
df.head()
Try plotting some things to visualise the data. The following shows the variation in field strength measured by the satellite as it passes between high and low latitudes, varying from one orbit to the next as it samples a different longitude.
df.plot(y="F")
df.plot(y="F", x="Latitude")
df.plot(y="Latitude", x="Longitude")
df.plot(y="Latitude", x="Longitude", c="F", kind="scatter")
Various (mostly spherical harmonic) models of the magnetic field are produced as Swarm mission products and these are available through VirES. They are evaluated on demand at the same points and times as the data sample points. Here we ask for the MCO_SHA_2D
model, a dedicated core field model produced from Swarm data. By supplying residuals=True
we will get the data-model residuals, named in the dataframe as F_res_MCO_SHA_2D
.
request = SwarmRequest()
request.set_collection("SW_OPER_MAGA_LR_1B")
request.set_products(
measurements=["F"],
models=["MCO_SHA_2D"],
residuals=True,
sampling_step="PT10S"
)
data = request.get_between(
start_time=dt.datetime(2016,1,1),
end_time=dt.datetime(2016,1,2)
)
df = data.as_dataframe()
df.head()
The core field has been removed from the data so the amplitudes are much smaller. Can you interprete the new signals in terms of external fields, i.e. from the ionosphere and magnetosphere?
df.plot(y="F_res_MCO_SHA_2D")
df.plot(y="F_res_MCO_SHA_2D", x="Latitude")
df.plot(y="Latitude", x="Longitude", c="F_res_MCO_SHA_2D", kind="scatter")
To find out what other data and models are available, see https://viresclient.readthedocs.io/en/latest/available_parameters.html
For examples see https://github.com/smithara/viresclient_examples (sorry they are a bit messy now and undocumented!)