From 39f4d5a895ea8f602f3e8016634b935b78717d89 Mon Sep 17 00:00:00 2001 From: Russell Stoneback Date: Wed, 18 May 2022 10:25:32 -0500 Subject: [PATCH 1/2] ENH: pysatMissions demo --- pysatTutorials/pysatMissions-demo.ipynb | 186 ++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 pysatTutorials/pysatMissions-demo.ipynb diff --git a/pysatTutorials/pysatMissions-demo.ipynb b/pysatTutorials/pysatMissions-demo.ipynb new file mode 100644 index 0000000..90f643a --- /dev/null +++ b/pysatTutorials/pysatMissions-demo.ipynb @@ -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 +} From 7aeff3fbb46139be6f57649a2941583ee039e840 Mon Sep 17 00:00:00 2001 From: Russell Stoneback Date: Wed, 18 May 2022 10:25:56 -0500 Subject: [PATCH 2/2] ENH: Update requirements --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 5166352..6c33d01 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,7 @@ numpy matplotlib pysat >= 3.0.0 pysatMadrigal +pysatMissions pysatNASA pysatSpaceWeather scipy