VirES - access to multi-mission spaceborne magnetic field measurements - non-public demo

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.

In [1]:
from viresclient import SwarmRequest

SERVER_URL = 'https://staging.viresdisc.vires.services/ows' # DISC server
In [2]:
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.",
            )

CSES Data

avaiable demo data: 2019-01-01/2019-01-31

In [3]:
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')
<xarray.Dataset>
Dimensions:      (B_FGM1_dim1: 3, B_FGM2_dim1: 3, NEC: 3, Timestamp: 6924, quaternion: 4)
Coordinates:
  * Timestamp    (Timestamp) datetime64[ns] 2019-01-01T00:10:15.410992128 ......
  * NEC          (NEC) <U1 'N' 'E' 'C'
  * quaternion   (quaternion) <U1 '1' 'i' 'j' 'k'
Dimensions without coordinates: B_FGM1_dim1, B_FGM2_dim1
Data variables: (12/17)
    Spacecraft   (Timestamp) object '-' '-' '-' '-' '-' ... '-' '-' '-' '-' '-'
    MLT          (Timestamp) float64 0.5488 0.5813 0.61 ... 1.514 1.527 1.54
    B_NEC_CHAOS  (Timestamp, NEC) float64 8.643e+03 -1.087e+04 ... -2.159e+04
    Flag_TBB     (Timestamp) uint8 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
    F_CHAOS      (Timestamp) float64 3.388e+04 3.353e+04 ... 2.473e+04 2.467e+04
    B_FGM1       (Timestamp, B_FGM1_dim1) float64 1.165e+04 ... -2.153e+04
    ...           ...
    q_NEC_CRF    (Timestamp, quaternion) float64 1.634e-05 0.0006313 ... 0.9971
    B_NEC2       (Timestamp, NEC) float64 8.618e+03 -1.095e+04 ... -2.159e+04
    Flag_SHW     (Timestamp) uint8 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 1 1 1 1 1 1
    B_FGM2       (Timestamp, B_FGM2_dim1) float64 1.179e+04 ... -2.155e+04
    Radius       (Timestamp) float64 6.894e+06 6.894e+06 ... 6.898e+06 6.898e+06
    Latitude     (Timestamp) float64 -64.31 -63.65 -63.04 ... -32.82 -32.2
Attributes:
    Sources:         ['CHAOS-7_static.shc', 'CSES_01_MAG_20190101T000000_2019...
    MagneticModels:  ["CHAOS = 'CHAOS-Core'(max_degree=20,min_degree=1) + 'CH...
    RangeFilters:    []

CryoSat-2 Data

avaiable data: 2010-08-01/2018-12-31

In [4]:
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')
<xarray.Dataset>
Dimensions:      (B_FGM1_dim1: 3, B_FGM2_dim1: 3, B_FGM3_dim1: 3, B_mod_NEC_dim1: 3, NEC: 3, Timestamp: 8640, quaternion: 4)
Coordinates:
  * Timestamp    (Timestamp) datetime64[ns] 2016-01-01T00:00:05.272000 ... 20...
  * NEC          (NEC) <U1 'N' 'E' 'C'
  * quaternion   (quaternion) <U1 '1' 'i' 'j' 'k'
Dimensions without coordinates: B_FGM1_dim1, B_FGM2_dim1, B_FGM3_dim1, B_mod_NEC_dim1
Data variables: (12/19)
    Spacecraft   (Timestamp) object '-' '-' '-' '-' '-' ... '-' '-' '-' '-' '-'
    F            (Timestamp) float64 nan 4.641e+04 4.643e+04 ... 3.879e+04 nan
    Longitude    (Timestamp) float64 150.0 149.8 149.7 ... -31.06 -31.17 -31.34
    B_FGM2       (Timestamp, B_FGM2_dim1) float64 -2.113e+03 ... -3.393e+04
    B_mod_NEC    (Timestamp, B_mod_NEC_dim1) float64 4.117e+03 ... 3.767e+04
    B_NEC_CHAOS  (Timestamp, NEC) float64 4.119e+03 2.974e+03 ... 3.767e+04
    ...           ...
    B_NEC        (Timestamp, NEC) float64 nan nan nan 3.499e+03 ... nan nan nan
    F_CHAOS      (Timestamp) float64 4.633e+04 4.637e+04 ... 3.878e+04 3.893e+04
    B_NEC3       (Timestamp, NEC) float64 3.929e+03 2.849e+03 ... 3.767e+04
    q_error      (Timestamp) float64 4.642 5.272 5.717 ... 6.663 6.496 6.37
    B_NEC2       (Timestamp, NEC) float64 3.921e+03 2.863e+03 ... 3.769e+04
    QDLat        (Timestamp) float64 -70.0 -70.76 -71.27 ... 63.22 63.76 64.57
Attributes:
    Sources:         ['CHAOS-7_static.shc', 'CS_OPER_MAG_20160101T000000_2016...
    MagneticModels:  ["CHAOS = 'CHAOS-Core'(max_degree=20,min_degree=1) + 'CH...
    RangeFilters:    []