Skip to content
Merged
11 changes: 8 additions & 3 deletions pysat-tutorial/03 - ICON-IVM_Plot-by-orbit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"# Import packages\n",
"import datetime as dt\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np"
"import numpy as np\n",
"import warnings"
]
},
{
Expand Down Expand Up @@ -53,7 +54,11 @@
"source": [
"# Register instruments with pysat. Only needed once per install.\n",
"import pysatNASA\n",
"pysat.utils.registry.register_by_module(pysatNASA.instruments)"
"pysat.utils.registry.register_by_module(pysatNASA.instruments)\n",
"\n",
"# Improvements for loading ICON metadata are currently in\n",
"# https://github.com/pysat/pysatNASA/pull/100.\n",
"warnings.simplefilter('ignore', UserWarning)"
]
},
{
Expand Down Expand Up @@ -353,4 +358,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
49 changes: 34 additions & 15 deletions pysat-tutorial/04 - ICON-MIGHTI_Variety-of-Plots.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"# Import packages\n",
"import datetime as dt\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np"
"import numpy as np\n",
"import warnings"
]
},
{
Expand Down Expand Up @@ -53,7 +54,11 @@
"source": [
"# Register instruments with pysat. Only needed once per install.\n",
"import pysatNASA\n",
"pysat.utils.registry.register_by_module(pysatNASA.instruments)"
"pysat.utils.registry.register_by_module(pysatNASA.instruments)\n",
"\n",
"# Improvements for loading ICON metadata are currently in\n",
"# https://github.com/pysat/pysatNASA/pull/100.\n",
"warnings.simplefilter('ignore', UserWarning)"
]
},
{
Expand All @@ -67,10 +72,12 @@
"\n",
"# Instantiate pysat.Instrument objects for the MIGHTI data products\n",
"# MIGHTI Vector wind red.\n",
"mighti_vw_red = pysat.Instrument('icon', 'mighti', tag='vector_wind_red', inst_id='vector')\n",
"mighti_vw_red = pysat.Instrument('icon', 'mighti', tag='vector_wind_red',\n",
" inst_id='vector')\n",
"\n",
"# MIGHTI Vector wind green.\n",
"mighti_vw_green = pysat.Instrument('icon', 'mighti', tag='vector_wind_green', inst_id='vector')\n",
"mighti_vw_green = pysat.Instrument('icon', 'mighti', tag='vector_wind_green',\n",
" inst_id='vector')\n",
"\n",
"# MIGHTI Temperature.\n",
"mighti_temp_a = pysat.Instrument('icon', 'mighti', tag='temperature',\n",
Expand Down Expand Up @@ -144,6 +151,10 @@
"source": [
"# Produce simple overview plot of MIGHTI winds for a day of data.\n",
"\n",
"vmin = -250.\n",
"vmax = 250.\n",
"cmap = plt.cm.RdBu\n",
"\n",
"# pysat features a variety of internal data checks to ensure data is\n",
"# consistent with expectations. Warnings are raised below relating to the\n",
"# treatment of ICON's metadata. An upcoming release to pysat improves the\n",
Expand All @@ -155,29 +166,35 @@
"mighti_vw_green.load(2020, 2)\n",
"\n",
"# Zonal wind plot, red line\n",
"mighti_vw_red['Zonal_Wind'].transpose().plot(cbar_kwargs={'label': 'Zonal Wind (m/s)'})\n",
"plt.title('MIGHTI Zonal Wind')\n",
"mighti_vw_red['Zonal_Wind'].transpose().plot(\n",
" cbar_kwargs={'label': 'Zonal Wind (m/s)'}, vmin=vmin, vmax=vmax, cmap=cmap)\n",
"plt.title('MIGHTI Zonal Wind - Red Line')\n",
"\n",
"# Use pysat's stored metadata to get units\n",
"ylabel = ''.join(['Altitude (', mighti_vw_red.meta['Altitude', 'units'], ')'])\n",
"plt.ylabel(ylabel)\n",
"\n",
"# Meridional wind plot, red line\n",
"plt.figure()\n",
"mighti_vw_red['Meridional_Wind'].transpose().plot(cbar_kwargs={'label': 'Meridional Wind (m/s)'})\n",
"plt.title('MIGHTI Meridional Wind')\n",
"mighti_vw_red['Meridional_Wind'].transpose().plot(\n",
" cbar_kwargs={'label': 'Meridional Wind (m/s)'}, vmin=vmin, vmax=vmax,\n",
" cmap=cmap)\n",
"plt.title('MIGHTI Meridional Wind - Red Line')\n",
"plt.ylabel(ylabel)\n",
"\n",
"# Zonal wind plot, green line\n",
"plt.figure()\n",
"mighti_vw_green['Zonal_Wind'].transpose().plot(cbar_kwargs={'label': 'Zonal Wind (m/s)'})\n",
"plt.title('MIGHTI Zonal Wind')\n",
"mighti_vw_green['Zonal_Wind'].transpose().plot(\n",
" cbar_kwargs={'label': 'Zonal Wind (m/s)'}, vmin=vmin, vmax=vmax, cmap=cmap)\n",
"plt.title('MIGHTI Zonal Wind - Green Line')\n",
"plt.ylabel(ylabel)\n",
"\n",
"# Meridional wind plot, green line\n",
"plt.figure()\n",
"mighti_vw_green['Meridional_Wind'].transpose().plot(cbar_kwargs={'label': 'Meridional Wind (m/s)'})\n",
"plt.title('MIGHTI Meridional Wind')\n",
"mighti_vw_green['Meridional_Wind'].transpose().plot(\n",
" cbar_kwargs={'label': 'Meridional Wind (m/s)'}, vmin=vmin, vmax=vmax,\n",
" cmap=cmap)\n",
"plt.title('MIGHTI Meridional Wind - Green Line')\n",
"plt.ylabel(ylabel)"
]
},
Expand Down Expand Up @@ -248,7 +265,8 @@
"\n",
" # Make plot.\n",
" a.transpose().plot(ax=axs[i], x='average_local_time', y='Altitude',\n",
" cbar_kwargs={'label': 'Zonal Wind (m/s)'})\n",
" cbar_kwargs={'label': 'Zonal Wind (m/s)'},\n",
" vmin=vmin, vmax=vmax, cmap=cmap)\n",
" axs[i].set_xlim((0, 24))\n",
" axs[i].set_xticks([])\n",
" axs[i].set_xlabel('')\n",
Expand All @@ -259,7 +277,8 @@
"\n",
" # Make plot.\n",
" a.transpose().plot(ax=axsm[i], x='average_local_time', y='Altitude',\n",
" cbar_kwargs={'label': 'Meridional Wind (m/s)'})\n",
" cbar_kwargs={'label': 'Meridional Wind (m/s)'},\n",
" vmin=vmin, vmax=vmax, cmap=cmap)\n",
" axsm[i].set_xlim((0, 24))\n",
" axsm[i].set_xticks([])\n",
" axsm[i].set_xlabel('')\n",
Expand Down Expand Up @@ -394,4 +413,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
186 changes: 186 additions & 0 deletions pysat-tutorial/06 - pysatMissions-demo.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "e2269eab",
"metadata": {},
"outputs": [],
"source": [
"import datetime as dt"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c26e4e94",
"metadata": {},
"outputs": [],
"source": [
"import pysat\n",
"import pysatMissions"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "444b11e1",
"metadata": {},
"outputs": [],
"source": [
"# Register the data plug-ins in pysatMissions. Only once per installation.\n",
"pysat.utils.registry.register_by_module(pysatMissions.instruments)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "64972e71",
"metadata": {},
"outputs": [],
"source": [
"# Define on-the-fly orbit breakdown input. Note that `mlt` variable will be added by custom function.\n",
"orbit_info = {'kind': 'lt', 'index': 'mlt', 'period': dt.timedelta(minutes=95)}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f8ad44dc",
"metadata": {},
"outputs": [],
"source": [
"# Instantiate satellite propagator. Note that `inclination` and `alt_periapsis` are keywords defined by \n",
"# `missions_sgp4` module, not pysat itself.\n",
"inst = pysat.Instrument('missions', 'sgp4', orbit_info=orbit_info, inclination=10, alt_periapsis=500.)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0964c596",
"metadata": {},
"outputs": [],
"source": [
"# Get information on SGP4 support as well as defined keyword arguments.\n",
"help(inst.inst_module)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2055abad",
"metadata": {},
"outputs": [],
"source": [
"# Add additional information, like location in magnetic coordinates, including `mlt`.\n",
"inst.custom_attach(pysatMissions.methods.magcoord.add_quasi_dipole_coordinates, \n",
" kwargs={'glong_label': 'geod_longitude', 'glat_label': 'geod_latitude',\n",
" 'alt_label': 'geod_altitude' })"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "22c5b758",
"metadata": {},
"outputs": [],
"source": [
"# Load a day of data and plot raw `mlt`. pysat appplies all custom functions during load process.\n",
"inst.load(2019, 2, use_header=True)\n",
"inst['mlt'].plot(title='Simulated Spacecraft Day', ylabel='MLT (hours)')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7b29a4c3",
"metadata": {},
"outputs": [],
"source": [
"# Check out data before orbit breakdown. Full day of data.\n",
"inst.data"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d07ffe7b",
"metadata": {},
"outputs": [],
"source": [
"# Iterate orbit-by-orbit. Plot the first orbit then stop. To create this plot pysat also loads/simulates\n",
"# day previous to ensure that the first orbit is complete. \n",
"for orbit_inst in inst.orbits:\n",
" orbit_inst.data.plot(y='latitude', x='mlt', title='Single Orbit', ylabel='Latitude (degrees)')\n",
" break"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a29dad08",
"metadata": {},
"outputs": [],
"source": [
"# Check out data after first orbit breakdown. Single orbit of data. Notice the first samples come from 2019, 1.\n",
"# pysat does its best to form complete orbits when possible, with a minimum of data loading. \n",
"inst.data"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "66aa0410",
"metadata": {},
"outputs": [],
"source": [
"# The for loop above first takes some time to calculate as it is loading/simulating data.\n",
"# Now that is complete, moving forward in orbits will be fast until we get close to the end of the day.\n",
"# pysat will then load the next day, with the communserate simulation time.\n",
"# Move forward with orbits.next(), backward with orbits.prev(), and select particular orbit with orbits[]\n",
"\n",
"inst.orbits.next()\n",
"# inst.orbits.prev()\n",
"# inst.orbits[5]\n",
"\n",
"# Title string\n",
"date_str = '%x %X'\n",
"title = ''.join(['Orbit: ', repr(inst.orbits.current), ' ', inst.index[0].strftime(date_str), \n",
" ' - ', inst.index[-1].strftime(date_str)])\n",
"\n",
"# Make plot\n",
"inst['mlt'].plot(title=title, ylabel='MLT (hours)')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1c331762",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading