{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Ion Distribution From MMS\n", "\n", "This notebook shows how to create 2D slices of 3D particle data from FPI using PySPEDAS. `pyspedas` is the Python implementation of SPEDAS orginally coded in IDL. It is not as feature-complete as the IDL version." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Obtaining MMS FPI Data\n", "\n", "Here is a recorded bi-directional field-aligned beam of 0-300 eV ions observed by FPI. Due to a bug in the `time` argument of `mms_part_slice2d`, we currently need to specify the start and end time of the interval as a list." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pytplot import time_double, time_string\n", "\n", "time = \"2017-09-10/09:32:20\"\n", "window = 4.\n", "trange = [time_double(time)-window/2, time_double(time)+window/2]\n", "\n", "time_string(trange)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The data is downloaded automatically to the `pydata` folder under the current directory if not found." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pyspedas.mms.particles.mms_part_slice2d import mms_part_slice2d\n", "\n", "mms_part_slice2d(\n", " time=time,\n", " instrument=\"fpi\",\n", " species=\"i\",\n", " rotation=\"bv\",\n", " erange=[0, 300],\n", " cmap=\"turbo\",\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Basic operations\n", "\n", "To return the slice data structure instead of plotting, set the `return_slice` keyword to `True`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "the_slice = mms_part_slice2d(\n", " return_slice=True,\n", " time=time,\n", " instrument=\"fpi\",\n", " species=\"i\",\n", " rotation=\"bv\",\n", " erange=[0, 300],\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The slice is stored as a dictionary:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "the_slice.keys()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can create 1D cuts through the 2D slice by specifying the velocity range:\n", "\n", "(hyzhou: why is the unit still the same as in 2D/3D?)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pyspedas.particles.spd_slice2d.slice1d_plot import plot\n", "\n", "plot(the_slice, 'x', [-100, 100]) # summed from Vv=[-100, 100]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## FPI ions with 2D interpolation\n", "\n", "The data are rotated such that the x axis is parallel to B field and the bulk velocity defines the x-y plane, and plotted using 2D interpolation (data points within the specified theta or z-axis range are projected onto the slice plane and linearly interpolated onto a regular 2D grid). The default theta range is [-20, +20]." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "mms_part_slice2d(interpolation=\"2d\", time=time, instrument=\"fpi\", species=\"i\", rotation=\"bv\", erange=[0, 300], cmap=\"turbo\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "slicemms2d = mms_part_slice2d(return_slice=True, interpolation=\"2d\", time=time, instrument=\"fpi\", species=\"i\", rotation=\"bv\", erange=[0, 300])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import matplotlib.colors as colors\n", "import numpy as np\n", "\n", "plt.pcolormesh(slicemms2d[\"xgrid\"], slicemms2d[\"ygrid\"], slicemms2d[\"data\"].T,\n", " norm=colors.LogNorm(1e-24, np.nanmax(slicemms2d[\"data\"])),\n", " cmap=\"turbo\")\n", "plt.colorbar()\n", "plt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "vdfpy-L8WReCYd-py3.11", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.7" } }, "nbformat": 4, "nbformat_minor": 2 }