IPDxIRR_2F (Ionospheric plasma densities)

Abstract: Access to the derived plasma characteristics at 1Hz (level 2 product).

%load_ext watermark
%watermark -i -v -p viresclient,pandas,xarray,matplotlib
Python implementation: CPython
Python version       : 3.9.7
IPython version      : 8.0.1

viresclient: 0.10.3
pandas     : 1.4.1
xarray     : 0.21.1
matplotlib : 3.5.1
from viresclient import SwarmRequest
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter

request = SwarmRequest()

IPDxIRR_2F product information

Derived plasma characteristics at 1Hz, for each Swarm spacecraft.

Documentation:

Check what “IPD” data variables are available

request.available_collections("IPD", details=False)
{'IPD': ['SW_OPER_IPDAIRR_2F', 'SW_OPER_IPDBIRR_2F', 'SW_OPER_IPDCIRR_2F']}
request.available_measurements("IPD")
['Ne',
 'Te',
 'Background_Ne',
 'Foreground_Ne',
 'PCP_flag',
 'Grad_Ne_at_100km',
 'Grad_Ne_at_50km',
 'Grad_Ne_at_20km',
 'Grad_Ne_at_PCP_edge',
 'ROD',
 'RODI10s',
 'RODI20s',
 'delta_Ne10s',
 'delta_Ne20s',
 'delta_Ne40s',
 'Num_GPS_satellites',
 'mVTEC',
 'mROT',
 'mROTI10s',
 'mROTI20s',
 'IBI_flag',
 'Ionosphere_region_flag',
 'IPIR_index',
 'Ne_quality_flag',
 'TEC_STD']

Fetch three hours of IPD data

request.set_collection("SW_OPER_IPDAIRR_2F")
request.set_products(measurements=request.available_measurements("IPD"))
data = request.get_between(
    dt.datetime(2014,12,21, 0),
    dt.datetime(2014,12,21, 3)
)

Load and plot using pandas/matplotlib

df = data.as_dataframe()
df.head()
Grad_Ne_at_50km Te Ne_quality_flag PCP_flag Longitude ROD mVTEC IBI_flag IPIR_index RODI20s ... delta_Ne40s TEC_STD mROTI10s Spacecraft mROTI20s Radius mROT RODI10s Grad_Ne_at_100km Num_GPS_satellites
Timestamp
2014-12-21 00:00:00.196999936 -0.403940 2212.28 20000 0 -128.771412 0.0 51.786939 -1 7 7764.002532 ... 3811.1 3.131452 0.001472 A 0.002676 6.840395e+06 -0.011013 10238.517220 -0.084919 4
2014-12-21 00:00:01.196999936 0.144877 2165.19 20000 0 -128.772618 0.0 51.768987 -1 6 7181.496228 ... 16343.3 3.122495 0.001386 A 0.002732 6.840404e+06 -0.011013 3263.138721 -0.144009 4
2014-12-21 00:00:02.196999936 -0.123734 1544.87 20000 0 -128.773822 0.0 51.746903 -1 6 7181.496228 ... 3246.4 3.113831 0.001310 A 0.002750 6.840413e+06 -0.008833 3263.138721 -0.058276 4
2014-12-21 00:00:03.196999936 -0.131441 1228.50 20000 0 -128.775026 0.0 51.728764 -1 6 7390.308480 ... 848.3 3.104260 0.001930 A 0.003277 6.840422e+06 -0.008151 3263.138721 -0.144613 4
2014-12-21 00:00:04.196999936 -0.403369 2681.51 20000 0 -128.776229 0.0 51.711319 -1 6 7554.331699 ... 6448.3 3.097485 0.002434 A 0.003744 6.840430e+06 -0.007051 3263.138721 -0.039358 4

5 rows × 29 columns

df.columns
Index(['Grad_Ne_at_50km', 'Te', 'Ne_quality_flag', 'PCP_flag', 'Longitude',
       'ROD', 'mVTEC', 'IBI_flag', 'IPIR_index', 'RODI20s', 'delta_Ne20s',
       'Grad_Ne_at_PCP_edge', 'delta_Ne10s', 'Background_Ne', 'Foreground_Ne',
       'Ne', 'Grad_Ne_at_20km', 'Latitude', 'Ionosphere_region_flag',
       'delta_Ne40s', 'TEC_STD', 'mROTI10s', 'Spacecraft', 'mROTI20s',
       'Radius', 'mROT', 'RODI10s', 'Grad_Ne_at_100km', 'Num_GPS_satellites'],
      dtype='object')
fig, axes = plt.subplots(nrows=7, ncols=1, figsize=(20,18), sharex=True)
df.plot(ax=axes[0], y=['Background_Ne', 'Foreground_Ne', 'Ne'], alpha=0.8)
df.plot(ax=axes[1], y=['Grad_Ne_at_100km', 'Grad_Ne_at_50km', 'Grad_Ne_at_20km'])
df.plot(ax=axes[2], y=['RODI10s', 'RODI20s'])
df.plot(ax=axes[3], y=['ROD'])
df.plot(ax=axes[4], y=['mROT'])
df.plot(ax=axes[5], y=['delta_Ne10s', 'delta_Ne20s', 'delta_Ne40s'])
df.plot(ax=axes[6], y=['mROTI20s', 'mROTI10s'])
axes[0].set_ylabel("[cm$^{-3}$]")
axes[1].set_ylabel("[cm$^{-3}$m$^{-1}$]")
axes[2].set_ylabel("[cm$^{-3}$s$^{-1}$]")
axes[3].set_ylabel("[cm$^{-3}$m$^{-1}$]")
axes[4].set_ylabel("[TECU s$^{-1}$]")
axes[5].set_ylabel("[cm$^{-3}$m$^{-1}$]")
axes[6].set_ylabel("[TECU s$^{-1}$]")
axes[6].set_xlabel("Timestamp")

for ax in axes:
    # Reformat time axis
    # https://www.earthdatascience.org/courses/earth-analytics-python/use-time-series-data-in-python/customize-dates--matplotlib-plots-python/
    ax.xaxis.set_major_formatter(DateFormatter("%Y-%m-%d\n%H:%M:%S"))
    ax.legend(loc="upper right")
    ax.grid()
fig.subplots_adjust(hspace=0)
../_images/03c__Demo-IPDxIRR_2F_12_0.png

Load as xarray

ds = data.as_xarray()
ds
<xarray.Dataset>
Dimensions:                 (Timestamp: 10800)
Coordinates:
  * Timestamp               (Timestamp) datetime64[ns] 2014-12-21T00:00:00.19...
Data variables: (12/29)
    Spacecraft              (Timestamp) object 'A' 'A' 'A' 'A' ... 'A' 'A' 'A'
    Grad_Ne_at_50km         (Timestamp) float64 -0.4039 0.1449 ... 0.9347 0.9775
    Te                      (Timestamp) float64 2.212e+03 ... 1.723e+03
    Ne_quality_flag         (Timestamp) int32 20000 20000 20000 ... 20000 20000
    PCP_flag                (Timestamp) int32 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0
    Longitude               (Timestamp) float64 -128.8 -128.8 ... -175.4 -175.4
    ...                      ...
    mROTI20s                (Timestamp) float64 0.002676 0.002732 ... 0.0114
    Radius                  (Timestamp) float64 6.84e+06 6.84e+06 ... 6.835e+06
    mROT                    (Timestamp) float64 -0.01101 -0.01101 ... 0.09621
    RODI10s                 (Timestamp) float64 1.024e+04 3.263e+03 ... 503.7
    Grad_Ne_at_100km        (Timestamp) float64 -0.08492 -0.144 ... 0.9621
    Num_GPS_satellites      (Timestamp) int32 4 4 4 4 4 4 4 4 ... 6 6 6 6 6 6 6
Attributes:
    Sources:         ['SW_OPER_IPDAIRR_2F_20141221T000000_20141221T235959_0301']
    MagneticModels:  []
    RangeFilters:    []

Alternative plot setup

To plot the data from xarray, we need a different plotting setup. This does however give us more control over the plot. The units are extracted directly from the xarray object.

fig, axes = plt.subplots(nrows=7, ncols=1, figsize=(20,18), sharex=True)
def subplot(ax=None, y=None, **kwargs):
    """Plot combination of variables onto a given axis"""
    units = ds[y[0]].units
    for var in y:
        ax.plot(ds["Timestamp"], ds[var], label=var, **kwargs)
        if units != ds[var].units:
            raise ValueError(f"Units mismatch for {var}")
    ax.set_ylabel(f"[{units}]")
    # Reformat time axis
    # https://www.earthdatascience.org/courses/earth-analytics-python/use-time-series-data-in-python/customize-dates--matplotlib-plots-python/
    ax.xaxis.set_major_formatter(DateFormatter("%Y-%m-%d\n%H:%M:%S"))
    ax.legend(loc="upper right")
    ax.grid()
subplot(ax=axes[0], y=['Background_Ne', 'Foreground_Ne', 'Ne'])
subplot(ax=axes[1], y=['Grad_Ne_at_100km', 'Grad_Ne_at_50km', 'Grad_Ne_at_20km'])
subplot(ax=axes[2], y=['RODI10s', 'RODI20s'])
subplot(ax=axes[3], y=['ROD'])
subplot(ax=axes[4], y=['mROT'])
subplot(ax=axes[5], y=['delta_Ne10s', 'delta_Ne20s', 'delta_Ne40s'])
subplot(ax=axes[6], y=['mROTI20s', 'mROTI10s'])
fig.subplots_adjust(hspace=0)
../_images/03c__Demo-IPDxIRR_2F_16_0.png