Skip to content

Missions demo #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 186 additions & 0 deletions pysatTutorials/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
}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ numpy
matplotlib
pysat >= 3.0.0
pysatMadrigal
pysatMissions
pysatNASA
pysatSpaceWeather
scipy