This notebook demonstrates access to CryoSat-2, GRACE 1/2, GRACE-FO 1/2, CSES, ePOP LR and HR, and Swarm A/B/C magnetic field measurements avaiable from the DISC VirES server.
from viresclient import SwarmRequest
SERVER_URL = 'https://staging.viresdisc.vires.services/ows' # DISC server
from matplotlib.pyplot import subplot, figure
class AttrDict(dict):
def __getattr__(self, key):
return self[key]
VECTORS = AttrDict({
"B_NEC_CHAOS": ["B_N_CHAOS", "B_E_CHAOS", "B_C_CHAOS"],
"B_NEC": ["B_N", "B_E", "B_C"],
"B_NEC1": ["B_N1", "B_E1", "B_C1"],
"B_NEC2": ["B_N2", "B_E2", "B_C2"],
"B_NEC3": ["B_N3", "B_E3", "B_C3"],
})
def plot_magnetic_data(data, product_type):
def _extract_variables(variables):
return AttrDict({
variable: data[variable].values
for variable in variables if variable in data
})
def _plot(ax, x, y, title, xlabel, ylabel, **opts):
ax.plot(x, y, '.', **opts)
ax.set_title(title)
ax.set_ylabel(ylabel)
ax.set_xlabel(xlabel)
ax.set_ylim([-250, 250])
ax.set_xlim([-90, 90])
ax.set_xticks([-90, -75, -60, -45, -30, -15, 0, 15, 30, 45, 60, 75, 90])
ax.grid()
return ax
coords = _extract_variables(['Timestamp', 'Latitude', 'Longitude', 'Radius', 'QDLat', 'MLT'])
models = _extract_variables(['F_CHAOS', 'B_NEC_CHAOS'])
f_variables = _extract_variables(["F"])
b_variables = _extract_variables(["B_NEC", "B_NEC1", "B_NEC2", "B_NEC3"])
for variable, values in f_variables.items():
delta = values - models.F_CHAOS
#fig = figure()
fig = figure(figsize=(18, 2), dpi=100)
_plot(
subplot(1, 1, 1),
coords.QDLat, delta, ms=2,
title=f'{product_type} - {variable}',
ylabel=f"{variable} - F_CHAOS / nT",
xlabel="QD-latitude / deg.",
)
for vvariable, values in b_variables.items():
delta = values - models.B_NEC_CHAOS
for idx, cvariable in enumerate(VECTORS[vvariable]):
fig = figure(figsize=(18, 2), dpi=100)
ax = subplot(1, 1, 1)
_plot(
ax, coords.QDLat, delta[:, idx], ms=2,
title=f'{product_type} - {vvariable}',
ylabel=f"{cvariable} - {VECTORS.B_NEC_CHAOS[idx]} / nT",
xlabel="QD-latitude / deg.",
)
avaiable demo data: 2019-01-01/2019-01-31
SwarmRequest.COLLECTIONS["MAG_CSES"] = ["CSES_01_MAG"]
SwarmRequest.PRODUCT_VARIABLES["MAG_CSES"] = [
"F", "B_NEC1","B_NEC2", "B_FGM1", "B_FGM2",
"q_NEC_CRF", "Flag_TBB", "Flag_MT", "Flag_SHW",
]
request = SwarmRequest(SERVER_URL)
request.set_collection("CSES_01_MAG")
request.set_products(
measurements=request.PRODUCT_VARIABLES["MAG_CSES"],
auxiliaries=["QDLat", "MLT"],
models=['CHAOS'],
sampling_step="PT10S",
#sampling_step="PT1S", # ~1Hz sampling
)
data = request.get_between(
start_time="2019-01-01T00:00:00Z",
end_time="2019-01-02T00:00:00Z",
).as_xarray()
print(data)
plot_magnetic_data(data, 'CSES')
avaiable data: 2010-08-01/2018-12-31
request = SwarmRequest(SERVER_URL)
request.set_collection("CS_OPER_MAG")
request.set_products(
measurements=request.PRODUCT_VARIABLES['MAG_CS'],
auxiliaries=["QDLat", "MLT"],
models=['CHAOS'],
sampling_step="PT10S",
#sampling_step="PT4S", # ~0.25Hz sampling
)
data = request.get_between(
start_time="2016-01-01T00:00:00Z",
end_time="2016-01-02T00:00:00Z",
).as_xarray()
print(data)
plot_magnetic_data(data, 'CryoSat-2')