Skip to content

Commit

Permalink
Review of the modules' documentation - clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
pacesm committed Mar 21, 2023
1 parent 42ef03a commit 7f57779
Show file tree
Hide file tree
Showing 31 changed files with 184 additions and 48 deletions.
2 changes: 1 addition & 1 deletion eoxmagmod/eoxmagmod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
from .dipole_coords import (
get_dipole_rotation_matrix, convert_to_dipole, vrot_from_dipole,
)
from .sheval_dipole import sheval_dipole
from .dipole import sheval_dipole
from .magnetic_time import mjd2000_to_magnetic_universal_time
from .magnetic_model.loader_shc import load_model_shc, load_model_shc_combined
from .magnetic_model.loader_igrf import load_model_igrf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
)
from .dipole_coords import convert_to_dipole, vrot_from_dipole

__all__ = ["sheval_dipole", "rotate_vectors_from_dipole"]


def sheval_dipole(arr_in, coef, lat_ngp, lon_ngp,
coord_type_in=GEODETIC_ABOVE_WGS84,
Expand Down
6 changes: 6 additions & 0 deletions eoxmagmod/eoxmagmod/dipole_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
GEOCENTRIC_SPHERICAL, GEOCENTRIC_CARTESIAN,
)

__all__ = [
"get_dipole_rotation_matrix",
"convert_to_dipole",
"vrot_from_dipole",
]

DEG2RAD = pi / 180.0


Expand Down
10 changes: 10 additions & 0 deletions eoxmagmod/eoxmagmod/magnetic_model/coefficients.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
coeff_size, convert_value,
)

__all__ = [
"SHCoefficients",
"ComposedSHCoefficients",
"CombinedSHCoefficients",
"SparseSHCoefficients",
"SparseSHCoefficientsTimeDependent",
"SparseSHCoefficientsConstant",
"SparseSHCoefficientsTimeDependentDecimalYear",
]


class SHCoefficients:
""" Abstract base class for all spherical harmonic coefficients. """
Expand Down
7 changes: 5 additions & 2 deletions eoxmagmod/eoxmagmod/magnetic_model/coefficients_mio.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#-------------------------------------------------------------------------------
#pylint: disable=no-name-in-module

from math import pi
from collections import namedtuple
from numpy import asarray, zeros, arange, broadcast_to, sin, cos
from numpy import asarray, zeros
from .coefficients import SparseSHCoefficients, coeff_size
from ..time_util import (
mjd2000_to_year_fraction as mjd2000_to_year_fraction_default,
)
from .._pymm import fourier2d

__all__ = [
"SparseSHCoefficientsMIO",
]

SCALE_SEASONAL = 2*pi
SCALE_DIURNAL = 2*pi/24.

Expand Down
2 changes: 2 additions & 0 deletions eoxmagmod/eoxmagmod/magnetic_model/field_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
from .._pymm import GEOCENTRIC_CARTESIAN, GEOCENTRIC_SPHERICAL, convert
from ..util import vnorm, vrotate

__all__ = ["trace_field_line"]

EARTH_RADIUS = 6371.2
DEFAULT_MIN_RADIUS = 0.9977 * EARTH_RADIUS
DEFAULT_MAX_RADIUS = 1e6 * EARTH_RADIUS
Expand Down
2 changes: 2 additions & 0 deletions eoxmagmod/eoxmagmod/magnetic_model/loader_emm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
)
from .parser_emm import combine_emm_coefficients, parse_emm_file

__all__ = ["load_model_emm", "load_coeff_emm"]


def load_model_emm(path_static, path_secvar):
""" Load model from a EMM coefficient files. """
Expand Down
2 changes: 2 additions & 0 deletions eoxmagmod/eoxmagmod/magnetic_model/loader_igrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
from .coefficients import SparseSHCoefficientsTimeDependentDecimalYear
from .parser_igrf import parse_igrf_file

__all__ = ["load_model_igrf", "load_coeff_igrf"]


def load_model_igrf(path):
""" Load model from an IGRF coefficient file.
Expand Down
7 changes: 7 additions & 0 deletions eoxmagmod/eoxmagmod/magnetic_model/loader_mio.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
from .coefficients_mio import SparseSHCoefficientsMIO
from .parser_mio import parse_swarm_mio_file

__all__ = [
"load_model_swarm_mio_internal",
"load_model_swarm_mio_external",
"load_coeff_swarm_mio_internal",
"load_coeff_swarm_mio_external",
"convert_external_mio_coeff",
]

def load_model_swarm_mio_internal(path):
""" Load internal (secondary field) model from a Swarm MIO_SHA_2* product.
Expand Down
15 changes: 15 additions & 0 deletions eoxmagmod/eoxmagmod/magnetic_model/loader_mma.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@
read_swarm_mma_2f_sm_internal, read_swarm_mma_2f_sm_external,
)

__all__ = [
"load_model_swarm_mma_2c_internal",
"load_model_swarm_mma_2c_external",
"load_model_swarm_mma_2f_geo_internal",
"load_model_swarm_mma_2f_geo_external",
"load_model_swarm_mma_2f_sm_internal",
"load_model_swarm_mma_2f_sm_external",
"load_coeff_swarm_mma_2c_internal",
"load_coeff_swarm_mma_2c_external",
"load_coeff_swarm_mma_2f_geo_internal",
"load_coeff_swarm_mma_2f_geo_external",
"load_coeff_swarm_mma_2f_sm_internal",
"load_coeff_swarm_mma_2f_sm_external",
]

# North geomagnetic coordinates used by the MMA products (IGRF-11, 2010.0)
MMA2C_NGP_LATITUDE = 90 - 9.92 # deg.
MMA2C_NGP_LONGITUDE = 287.78 - 360.0 # deg.
Expand Down
16 changes: 14 additions & 2 deletions eoxmagmod/eoxmagmod/magnetic_model/loader_shc.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,28 @@
)
from .parser_shc import parse_shc_file

__all__ = [
"load_model_shc_combined",
"load_model_shc",
"load_coeff_shc_combined",
"load_coeff_shc_composed",
"load_coeff_shc",
]


def load_model_shc_combined(*paths, **kwargs):
""" Load model with coefficients combined from multiple SHC files. """
""" Load model with coefficients combined from multiple SHC files.
E.g., combining core and lithospheric models.
"""
return SphericalHarmomicGeomagneticModel(
load_coeff_shc_combined(*paths, **kwargs)
)


def load_model_shc(*paths, **kwargs):
""" Load model from an SHC file. """
""" Load composed model from one or more SHC files.
E.g., composing multiple core models, each with a different time extent.
"""
return SphericalHarmomicGeomagneticModel(
load_coeff_shc_composed(*paths, **kwargs)
)
Expand Down
2 changes: 2 additions & 0 deletions eoxmagmod/eoxmagmod/magnetic_model/loader_wmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
from .coefficients import SparseSHCoefficientsTimeDependentDecimalYear
from .parser_wmm import parse_wmm_file

__all__ = ["load_model_wmm", "load_coeff_wmm"]


def load_model_wmm(path):
""" Load model from a WMM COF file. """
Expand Down
8 changes: 7 additions & 1 deletion eoxmagmod/eoxmagmod/magnetic_model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@

from numpy import asarray, empty, full, nan, nditer
from .._pymm import GRADIENT, GEOCENTRIC_SPHERICAL, sheval, shevaltemp
from ..sheval_dipole import rotate_vectors_from_dipole
from ..dipole import rotate_vectors_from_dipole
from ..dipole_coords import convert_to_dipole
from .util import reshape_times_and_coordinates
from .coefficients import (
SparseSHCoefficientsTimeDependent,
CombinedSHCoefficients,
)

__all__ = [
"GeomagneticModel",
"SphericalHarmomicGeomagneticModel",
"DipoleSphericalHarmomicGeomagneticModel",
]


class GeomagneticModel:
""" Abstract base class of the Earth magnetic field model. """
Expand Down
1 change: 1 addition & 0 deletions eoxmagmod/eoxmagmod/magnetic_model/model_composed.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
)
from .model import GeomagneticModel

__all__ = ["ComposedGeomagneticModel"]

Component = namedtuple("_Component", ["model", "scale", "parameters"])

Expand Down
5 changes: 4 additions & 1 deletion eoxmagmod/eoxmagmod/magnetic_model/model_mio.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#-------------------------------------------------------------------------------
# pylint: disable=too-many-arguments,too-many-locals
# pylint: disable=too-many-arguments

from numpy import nan, asarray, empty, isnan, full
from .._pymm import GRADIENT, GEOCENTRIC_SPHERICAL, convert, sheval2dfs
Expand All @@ -34,6 +34,8 @@
from .model import GeomagneticModel, DipoleSphericalHarmomicGeomagneticModel
from .util import reshape_times_and_coordinates, reshape_array, mask_array

__all__ = ["DipoleMIOGeomagneticModel", "MIOPrimaryGeomagneticModel"]

MIO_HEIGHT = 110.0 # km
MIO_EARTH_RADIUS = 6371.2 # km
MIO_WOLF_RATIO = 0.014850
Expand Down Expand Up @@ -135,6 +137,7 @@ class DipoleMIOGeomagneticModel(DipoleSphericalHarmomicGeomagneticModel):

def __init__(self, coefficients, north_pole, wolf_ratio=MIO_WOLF_RATIO,
height=MIO_HEIGHT, earth_radius=MIO_EARTH_RADIUS):
del height, earth_radius

if not isinstance(coefficients, SparseSHCoefficientsMIO):
raise TypeError(
Expand Down
4 changes: 4 additions & 0 deletions eoxmagmod/eoxmagmod/magnetic_model/parser_emm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
import re
from numpy import array, stack

__all__ = [
"combine_emm_coefficients",
"parse_emm_file",
]

RE_HEADER_LINE = re.compile(r'^-+$')
EMM_VALIDITY_PERIOD = 5.0 # years
Expand Down
2 changes: 2 additions & 0 deletions eoxmagmod/eoxmagmod/magnetic_model/parser_igrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

from numpy import array

__all__ = ["parse_igrf_file"]

IGRF_EXTRAPOLATION_PERIOD = 5.0 # years


Expand Down
3 changes: 3 additions & 0 deletions eoxmagmod/eoxmagmod/magnetic_model/parser_mio.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from numpy import array
from .parser_shc import _strip_shc_comments

__all__ = ["parse_swarm_mio_file"]


def parse_swarm_mio_file(file_in):
""" Parse Swarm MIO_SHA_2* product file format and return a dictionary
Expand All @@ -41,6 +43,7 @@ def parse_swarm_mio_file(file_in):
data["degree_max"] = data["nm"][:, 0].max()
return data


def parse_swarm_mio_coefficients(lines, data):
""" Parse the Swarm MIO_SHA_2* coefficients. """
nm_idx = []
Expand Down
9 changes: 9 additions & 0 deletions eoxmagmod/eoxmagmod/magnetic_model/parser_mma.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
from numpy import array
from spacepy import pycdf

__all__ = [
"read_swarm_mma_2c_internal",
"read_swarm_mma_2c_external",
"read_swarm_mma_2f_geo_internal",
"read_swarm_mma_2f_geo_external",
"read_swarm_mma_2f_sm_internal",
"read_swarm_mma_2f_sm_external",
]

CDF_EPOCH_TYPE = pycdf.const.CDF_EPOCH.value
CDF_EPOCH_2000 = 63113904000000.0
CDF_EPOCH_TO_DAYS = 1.0/86400000.0
Expand Down
2 changes: 2 additions & 0 deletions eoxmagmod/eoxmagmod/magnetic_model/parser_shc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

from numpy import inf, array

__all__ = ["parse_shc_file", "parse_shc_header"]


def parse_shc_file(file_in):
""" Parse SHC file and return a dictionary containing the parsed model data.
Expand Down
2 changes: 2 additions & 0 deletions eoxmagmod/eoxmagmod/magnetic_model/parser_wmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import re
from numpy import array

__all__ = ["parse_wmm_file"]

RE_TERMINATING_LINE = re.compile(r'^9+$')
WMM_VALIDITY_PERIOD = 5.0 # years

Expand Down
2 changes: 1 addition & 1 deletion eoxmagmod/eoxmagmod/magnetic_model/tests/model_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
GEOCENTRIC_CARTESIAN, GEODETIC_ABOVE_WGS84, GEOCENTRIC_SPHERICAL, convert,
GRADIENT, sheval,
)
from eoxmagmod.sheval_dipole import sheval_dipole
from eoxmagmod.dipole import sheval_dipole


class SHModelTestMixIn:
Expand Down
11 changes: 11 additions & 0 deletions eoxmagmod/eoxmagmod/magnetic_model/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
from numpy import inf
from numpy.lib.stride_tricks import as_strided

__all__ = [
"coeff_size",
"convert_value",
"parse_file",
"reshape_times_and_coordinates",
"mask_array",
"reshape_array",
"get_nonoverlapping_intervals",
"aggregate_intersected_intervals",
]


def coeff_size(degree):
""" Calculate size of the full coefficient array from the given degree. """
Expand Down
2 changes: 2 additions & 0 deletions eoxmagmod/eoxmagmod/magnetic_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
from numpy import sin, cos, arctan2
from .solar_position import sunpos

__all__ = ["mjd2000_to_magnetic_universal_time"]

DEG2RAD = pi/180.0
RAD2HOUR = 12.0/pi

Expand Down
7 changes: 7 additions & 0 deletions eoxmagmod/eoxmagmod/quasi_dipole_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
from . import _pyqd
from .data import APEX

__all__ = [
"eval_qdlatlon",
"eval_qdlatlon_with_base_vectors",
"eval_mlt",
"eval_subsol",
]


def eval_qdlatlon(gclat, gclon, gcrad, time, fname=APEX):
"""
Expand Down
2 changes: 2 additions & 0 deletions eoxmagmod/eoxmagmod/solar_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

from . import _pysunpos

__all__ = ["sunpos"]


def sunpos(time_mjd2k, lat, lon, rad=6371.2, dtt=0):
""" Calculate solar equatorial and horizontal coordinates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
convert, relradpow, loncossin, legendre, spharpot, sphargrd,
)
from eoxmagmod.dipole_coords import convert_to_dipole, vrot_from_dipole
from eoxmagmod.sheval_dipole import sheval_dipole
from eoxmagmod.dipole import sheval_dipole
from eoxmagmod.tests.data import mma_external, mma_internal


Expand Down
Loading

0 comments on commit 7f57779

Please sign in to comment.