Hot Plasma Composition Analyzer#

author: Louis Richard
HPCA summary plot
[1]:
import numpy as np
import xarray as xr
import matplotlib.pyplot as plt

from pyrfu import mms
from pyrfu.plot import plot_line, plot_spectr, make_labels
Load IGRF coefficients ...

Define spacecraft index, time interval and species#

[2]:
ic = 1
mms.db_init("/Volumes/mms")
tint = ["2017-07-23T16:54:00.000", "2017-07-23T17:00:00.000"]
species = {
    "hplus": "$H^+$",
    "heplus": "$He^+$",
    "heplusplus": "$He^{2+}$",
    "oplus": "$O^+$",
}

Load data#

Load HPCA moments#

[3]:
n_hpca = [mms.get_data(f"n{s}_hpca_srvy_l2", tint, ic) for s in species.keys()]
v_xyz_hpca = [mms.get_data(f"v{s}_dbcs_hpca_srvy_l2", tint, ic) for s in species.keys()]
[08-Jun-23 17:39:51] INFO: Loading mms1_hpca_hplus_number_density...
[08-Jun-23 17:39:51] WARNING: /usr/local/lib/python3.10/site-packages/pyrfu/mms/get_ts.py:58: UserWarning: Epoch_plus_var/Epoch_minus_var units are not clear, assume s
  warnings.warn(message)

[08-Jun-23 17:39:51] INFO: Loading mms1_hpca_heplus_number_density...
[08-Jun-23 17:39:51] INFO: Loading mms1_hpca_heplusplus_number_density...
[08-Jun-23 17:39:51] INFO: Loading mms1_hpca_oplus_number_density...
[08-Jun-23 17:39:51] INFO: Loading mms1_hpca_hplus_ion_bulk_velocity...
[08-Jun-23 17:39:51] INFO: Loading mms1_hpca_heplus_ion_bulk_velocity...
[08-Jun-23 17:39:51] WARNING: /usr/local/lib/python3.10/site-packages/pyrfu/mms/get_ts.py:58: UserWarning: Epoch_plus_var/Epoch_minus_var units are not clear, assume s
  warnings.warn(message)

[08-Jun-23 17:39:51] INFO: Loading mms1_hpca_heplusplus_ion_bulk_velocity...
[08-Jun-23 17:39:51] WARNING: /usr/local/lib/python3.10/site-packages/pyrfu/mms/get_ts.py:58: UserWarning: Epoch_plus_var/Epoch_minus_var units are not clear, assume s
  warnings.warn(message)

[08-Jun-23 17:39:51] INFO: Loading mms1_hpca_oplus_ion_bulk_velocity...
[08-Jun-23 17:39:51] WARNING: /usr/local/lib/python3.10/site-packages/pyrfu/mms/get_ts.py:58: UserWarning: Epoch_plus_var/Epoch_minus_var units are not clear, assume s
  warnings.warn(message)

Load HPCA ion#

[4]:
flux_hpca = [mms.get_data(f"dpf{s}_hpca_srvy_l2", tint, ic) for s in species.keys()]
[08-Jun-23 17:39:51] INFO: Loading mms1_hpca_hplus_flux...
[08-Jun-23 17:39:51] WARNING: /usr/local/lib/python3.10/site-packages/pyrfu/mms/get_ts.py:58: UserWarning: Epoch_plus_var/Epoch_minus_var units are not clear, assume s
  warnings.warn(message)

[08-Jun-23 17:39:53] INFO: Loading mms1_hpca_heplus_flux...
[08-Jun-23 17:39:55] INFO: Loading mms1_hpca_heplusplus_flux...
[08-Jun-23 17:39:55] INFO: Loading mms1_hpca_oplus_flux...

Load magnetic field#

[5]:
b_xyz = mms.get_data("b_gse_fgm_srvy_l2", tint, ic)
[08-Jun-23 17:39:55] INFO: Loading mms1_fgm_b_gse_srvy_l2...

Compute ion fluxes#

[6]:
def calc_hpca_flux(flux):
    flux.data[flux.data <= 0] = np.nan
    coords = [flux.time.data, flux.ccomp.data]
    dims = ["time", "energy"]

    out = xr.DataArray(
        np.nanmean(flux.data, axis=1), coords=coords, dims=dims, attrs=flux.attrs
    )
    return out


flux_hpca = [calc_hpca_flux(flux) for flux in flux_hpca]
[08-Jun-23 17:39:55] WARNING: /var/folders/2t/0_80h219537d9f7j3ytlqtgh0000gn/T/ipykernel_66155/699958699.py:7: RuntimeWarning: Mean of empty slice
  np.nanmean(flux.data, axis=1), coords=coords, dims=dims, attrs=flux.attrs

Plot#

[7]:
legend_options = dict(
    ncol=1, frameon=False, loc="upper left", bbox_to_anchor=(1.0, 1.0)
)
[8]:
f, axs = plt.subplots(6, sharex="all", figsize=(9, 13))
f.subplots_adjust(hspace=0, left=0.1, right=0.82, bottom=0.05, top=0.95)


plot_line(axs[0], b_xyz)
axs[0].set_ylabel("$B_{GSE}$" + "\n" + "[nT]")
axs[0].legend(["$B_{x}$", "$B_{y}$", "$B_{z}$"], **legend_options)

labels = []
for n, s in zip(n_hpca, species.keys()):
    plot_line(axs[1], n, linestyle="-", marker="o")
    labels.append(species[s])

axs[1].set_yscale("log")
axs[1].set_ylabel("$n$" + "\n" + "[cm$^{-3}$]")
axs[1].legend(labels, **legend_options)

caxs = [None] * len(species)
for s, ax, cax, flux in zip(species.keys(), axs[2:], caxs, flux_hpca):
    ax, cax = plot_spectr(ax, flux, yscale="log", cscale="log", cmap="viridis")
    ax.set_ylabel("$E$" + "\n" + "[eV]")
    cax.set_ylabel("flux" + "\n" + "[1/cc s sr eV]")
    ax.text(0.05, 0.1, species[s], transform=ax.transAxes)

f.align_ylabels(axs)
make_labels(axs, [0.02, 0.85])
[8]:
array([<Axes: ylabel='$B_{GSE}$\n[nT]'>,
       <Axes: ylabel='$n$\n[cm$^{-3}$]'>, <Axes: ylabel='$E$\n[eV]'>,
       <Axes: ylabel='$E$\n[eV]'>, <Axes: ylabel='$E$\n[eV]'>,
       <Axes: ylabel='$E$\n[eV]'>], dtype=object)
../../_images/examples_01_mms_example_mms_hpca_15_1.png