Skip to content

Commit

Permalink
Merge 7b25755 into 56aff77
Browse files Browse the repository at this point in the history
  • Loading branch information
jklenzing committed Feb 26, 2020
2 parents 56aff77 + 7b25755 commit 8e1a633
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 134 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ The methods that run empirical models can also be exported to any pysat instrume

```
import pysat
import pysatMissions.methods.pyglow as mm_glow
import pysatMissions.methods.empirical as mm_emp
ivm = pysat.Instrument(platform='cnofs', name='ivm')
ivm.custom.add(mm_glow.add_iri_thermal_plasma, 'modify', glat_label='glat',
ivm.custom.add(mm_emp.add_iri_thermal_plasma, 'modify', glat_label='glat',
glong_label='glon', alt_label='altitude')
```
Once the custom function is added, the model will automatically be run when the dataset is loaded.
3 changes: 1 addition & 2 deletions docs/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ Main Features
-------------
- Simulate satellite orbits from TLEs and add data from empirical models
- Import ionosphere and thermosphere model values through pyglow
- Import magnetic coordinates through apexpy
- Import magnetic coordinates through aacgmv2
- Import magnetic coordinates through apexpy and aacgmv2
- Import geomagnetic basis vectors through pysatMagVect

This document covers installation, a tutorial on pysatMissions including demonstration code, and an API reference.
4 changes: 2 additions & 2 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ A number of methods are included to invoke several python wrappers for empirical
.. code:: python
import pysat
from pysatMissions.methods import pyglow as mm_glow
from pysatMissions.methods import empirical as mm_emp
ivm = pysat.Instrument(platform='cnofs', name='ivm')
ivm.custom.add(mm_glow.add_iri_thermal_plasma, 'modify', 'end', glat_label='glat', glong_label='glon', alt_label='altitude')
ivm.custom.add(mm_emp.add_iri_thermal_plasma, 'modify', 'end', glat_label='glat', glong_label='glon', alt_label='altitude')
Note that in this case, the latitude, longitude, and altitude variable names of the instrument must be specified since they are not identical to the default names in the function.
19 changes: 9 additions & 10 deletions pysatMissions/instruments/pysat_ephem.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
import pysatMagVect

from pysatMissions.instruments import _core as mcore
from pysatMissions.methods import aacgmv2 as mm_aacgm
from pysatMissions.methods import apexpy as mm_apex
from pysatMissions.methods import pyglow as mm_glow
from pysatMissions.methods import magcoord as mm_magcoord
from pysatMissions.methods import empirical as mm_emp
from pysatMissions.methods import spacecraft as mm_sc

# pysat required parameters
Expand All @@ -46,13 +45,13 @@ def init(self):
"""

self.custom.add(mm_apex.add_quasi_dipole_coordinates, 'modify')
self.custom.add(mm_aacgm.add_aacgm_coordinates, 'modify')
self.custom.add(mm_magcoord.add_quasi_dipole_coordinates, 'modify')
self.custom.add(mm_magcoord.add_aacgm_coordinates, 'modify')
self.custom.add(mm_sc.calculate_ecef_velocity, 'modify')
self.custom.add(mm_sc.add_sc_attitude_vectors, 'modify')
# project simulated vectors onto s/c basis
# IGRF
self.custom.add(mm_glow.add_igrf, 'modify')
self.custom.add(mm_emp.add_igrf, 'modify')
# create metadata to be added along with vector projection
in_meta = {'desc': 'IGRF geomagnetic field expressed in the s/c basis.',
'units': 'nT'}
Expand All @@ -62,12 +61,12 @@ def init(self):
'B_sc_z', meta=[in_meta.copy(), in_meta.copy(),
in_meta.copy()])
# Thermal Ion Parameters
self.custom.add(mm_glow.add_iri_thermal_plasma, 'modify')
self.custom.add(mm_emp.add_iri_thermal_plasma, 'modify')
# Thermal Neutral parameters
self.custom.add(mm_glow.add_msis, 'modify')
self.custom.add(mm_glow.add_hwm_winds_and_ecef_vectors, 'modify')
self.custom.add(mm_emp.add_msis, 'modify')
self.custom.add(mm_emp.add_hwm_winds_and_ecef_vectors, 'modify')
# project total wind vector
self.custom.add(mm_glow.project_hwm_onto_sc, 'modify')
self.custom.add(mm_emp.project_hwm_onto_sc, 'modify')


def load(fnames, tag=None, sat_id=None, obs_long=0., obs_lat=0., obs_alt=0.,
Expand Down
7 changes: 3 additions & 4 deletions pysatMissions/methods/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
the methods to interface with numerous empirical model packages
"""

from pysatMissions.methods import aacgmv2
from pysatMissions.methods import apexpy
from pysatMissions.methods import pyglow
from pysatMissions.methods import empirical
from pysatMissions.methods import magcoord
from pysatMissions.methods import spacecraft

__all__ = ['aacgmv2', 'apexpy', 'pyglow', 'spacecraft']
__all__ = ['empirical', 'magcoord', 'spacecraft']
67 changes: 0 additions & 67 deletions pysatMissions/methods/aacgmv2.py

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,73 @@
"""Provides default routines for projecting apexpy values onto locations
"""Provides default routines for projecting aacgmv2 model values onto locations
from pysat instruments.
"""

import aacgmv2
import apexpy


def add_aacgm_coordinates(inst, glat_label='glat', glong_label='glong',
alt_label='alt'):
"""
Uses AACGMV2 package to add AACGM coordinates to instrument object.
The Altitude Adjusted Corrected Geomagnetic Coordinates library is used
to calculate the latitude, longitude, and local time
of the spacecraft with respect to the geomagnetic field.
Parameters
----------
inst : pysat.Instrument
instrument object including lat, lon, and alt as timeseries
glat_label : string
label used in inst to identify WGS84 geodetic latitude (degrees N)
glong_label : string
label used in inst to identify WGS84 geodetic longitude (degrees E)
alt_label : string
label used in inst to identify WGS84 geodetic altitude (km, height
above surface)
Returns
-------
inst
Input pysat.Instrument object modified to include quasi-dipole
coordinates, 'aacgm_lat' for magnetic latitude, 'aacgm_long' for
longitude, and 'aacgm_mlt' for magnetic local time.
Example
-------
# function added velow modifies the inst object upon every inst.load
call inst.custom.add(add_quasi_dipole_coordinates, 'modify',
glat_label='custom_label')
"""

aalat = []
aalon = []
mlt = []
for lat, lon, alt, time in zip(inst[glat_label], inst[glong_label],
inst[alt_label], inst.data.index):
# aacgmv2 latitude and longitude from geodetic coords
tlat, tlon, tmlt = aacgmv2.get_aacgm_coord(lat, lon, alt, time)
aalat.append(tlat)
aalon.append(tlon)
mlt.append(tmlt)

inst['aacgm_lat'] = aalat
inst['aacgm_long'] = aalon
inst['aacgm_mlt'] = mlt

inst.meta['aacgm_lat'] = {'units': 'degrees',
'long_name': 'AACGM latitude'}
inst.meta['aacgm_long'] = {'units': 'degrees',
'long_name': 'AACGM longitude'}
inst.meta['aacgm_mlt'] = {'units': 'hrs',
'long_name': 'AACGM Magnetic local time'}

return


def add_quasi_dipole_coordinates(inst, glat_label='glat', glong_label='glong',
alt_label='alt'):
"""
Expand Down
40 changes: 0 additions & 40 deletions pysatMissions/tests/test_methods_apexpy.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import numpy as np
import pysat
from pysatMissions.methods import pyglow as mm_glow
from pysatMissions.methods import empirical as mm_emp


def add_altitude(inst, altitude=400.0):
Expand All @@ -25,7 +25,7 @@ def teardown(self):

def test_add_iri_thermal_plasma(self):
"""Test adding thermal plasma data to test inst"""
self.testInst.custom.add(mm_glow.add_iri_thermal_plasma, 'modify',
self.testInst.custom.add(mm_emp.add_iri_thermal_plasma, 'modify',
glat_label='latitude',
glong_label='longitude',
alt_label='altitude')
Expand All @@ -41,7 +41,7 @@ def test_add_iri_thermal_plasma(self):

def test_add_igrf(self):
"""Test adding igrf model to test inst"""
self.testInst.custom.add(mm_glow.add_igrf, 'modify',
self.testInst.custom.add(mm_emp.add_igrf, 'modify',
glat_label='latitude',
glong_label='longitude',
alt_label='altitude')
Expand All @@ -57,7 +57,7 @@ def test_add_igrf(self):

def test_add_msis(self):
"""Test adding msis model to test inst"""
self.testInst.custom.add(mm_glow.add_msis, 'modify',
self.testInst.custom.add(mm_emp.add_msis, 'modify',
glat_label='latitude',
glong_label='longitude',
alt_label='altitude')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import numpy as np
import pysat
import pysatMissions.methods.aacgmv2 as mm_aacgm
import pysatMissions.methods.magcoord as mm_magcoord


def add_altitude(inst, altitude=400.0):
Expand All @@ -25,7 +25,8 @@ def teardown(self):

def test_add_aacgm_coordinates(self):
"""Test adding thermal plasma data to test inst"""
self.testInst.custom.add(mm_aacgm.add_aacgm_coordinates, 'modify',
self.testInst.custom.add(mm_magcoord.add_aacgm_coordinates,
'modify',
glat_label='latitude',
glong_label='longitude',
alt_label='altitude')
Expand All @@ -37,3 +38,19 @@ def test_add_aacgm_coordinates(self):
assert not np.isnan(self.testInst[target]).any()
# Check if metadata is added
assert target in self.testInst.meta.data.index

def test_add_quasi_dipole_coordinates(self):
"""Test adding thermal plasma data to test inst"""
self.testInst.custom.add(mm_magcoord.add_quasi_dipole_coordinates,
'modify',
glat_label='latitude',
glong_label='longitude',
alt_label='altitude')
self.testInst.load(date=pysat.datetime(2009, 1, 1))
targets = ['qd_lat', 'qd_long', 'mlt']
for target in targets:
# Check if data is added
assert target in self.testInst.data.keys()
assert not np.isnan(self.testInst[target]).any()
# Check if metadata is added
assert target in self.testInst.meta.data.index

0 comments on commit 8e1a633

Please sign in to comment.