Skip to content

Commit

Permalink
Merge 4bc38d4 into 5d9b8c9
Browse files Browse the repository at this point in the history
  • Loading branch information
aburrell committed Mar 24, 2021
2 parents 5d9b8c9 + 4bc38d4 commit 6f0cce9
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 151 deletions.
1 change: 0 additions & 1 deletion .travis.yml
@@ -1,7 +1,6 @@
language: python

python:
- "2.7"
- "3.6"
- "3.7"
- "3.8"
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -2,6 +2,11 @@
Changelog
=========

1.1.1 (2021-06-05)
------------------
* Removed Python 2 support
* Updated community and package documentation

1.1.0 (2021-03-05)
------------------
* Adapted Fortran to read IRGF coefficients from a file (updated to IGRF-13)
Expand Down
41 changes: 23 additions & 18 deletions README.rst
Expand Up @@ -29,28 +29,33 @@ which requires both libgfortran and gfortran to be installed on your system.
Conversion is done by creating an ``Apex`` object and using its methods to
perform the desired calculations. Some simple examples::

>>> from apexpy import Apex
>>> from __future__ import print_function
>>> A = Apex(date=2015.3) # datetime objects are also supported
>>> # geo to apex, scalar input
>>> mlat, mlon = A.convert(60, 15, 'geo', 'apex', height=300)
>>> print("{:.12f}, {:.12f}".format(mlat, mlon))
from apexpy import Apex
import datetime as dt
atime = dt.datetime(2015, 2, 10, 18, 0, 0)
apex15 = Apex(date=2015.3) # dt.date and dt.datetime objects also work

# Geodetic to apex, scalar input
mlat, mlon = apex15.convert(60, 15, 'geo', 'apex', height=300)
print("{:.12f}, {:.12f}".format(mlat, mlon))
57.477310180664, 93.590156555176
>>> # apex to geo, array input
>>> glat, glon = A.convert([90, -90], 0, 'apex', 'geo', height=0)
>>> print(["{:.12f}, {:.12f}".format(ll, glon[i]) for i,ll in enumerate(glat)])

# Apex to geodetic, array input
glat, glon = apex15.convert([90, -90], 0, 'apex', 'geo', height=0)
print(["{:.12f}, {:.12f}".format(ll, glon[i]) for i,ll in enumerate(glat)])
['83.103820800781, -84.526657104492', '-74.388252258301, 125.736274719238']
>>> # geo to MLT
>>> import datetime as dt
>>> mlat, mlt = A.convert(60, 15, 'geo', 'mlt', datetime=dt.datetime(2015, 2, 10, 18, 0, 0))
>>> print("{:.12f}, {:.12f}".format(mlat, mlt))

# Geodetic to magnetic local time
mlat, mlt = apex15.convert(60, 15, 'geo', 'mlt', datetime=atime)
print("{:.12f}, {:.12f}".format(mlat, mlt))
56.598316192627, 19.107861709595
>>> # can also convert magnetic longitude to mlt
>>> mlt = A.mlon2mlt(120, dt.datetime(2015, 2, 10, 18, 0, 0))
>>> print("{:.2f}".format(mlt))

# can also convert magnetic longitude to mlt
mlt = apex15.mlon2mlt(120, atime)
print("{:.2f}".format(mlt))
20.90

If you don't know or use Python, you can also use the command line. See details in the full documentation.
If you don't know or use Python, you can also use the command line. See details
in the full documentation.

Documentation
=============
Expand Down Expand Up @@ -88,7 +93,7 @@ Badges
| |wheel| |supported-implementations|
.. |docs| image:: https://readthedocs.org/projects/apexpy/badge/?style=flat
:target: https://readthedocs.org/projects/apexpy
:target: https://apexpy.readthedocs.io/en/latest/
:alt: Documentation Status

.. |travis| image:: https://travis-ci.org/aburrell/apexpy.svg?branch=main
Expand Down
10 changes: 0 additions & 10 deletions appveyor.yml
Expand Up @@ -8,16 +8,6 @@ environment:
MINICONDA_HOME: 'C:\Miniconda'
TESTSCRIPT: 'python setup.py check --strict --metadata --restructuredtext && check-manifest && flake8 src tests'
INSTALL_EXTRA_DEPS: 'pip install docutils check-manifest flake8 readme pygments sphinx_rtd_theme'
- TESTENV: '2.7-nocover-64'
PYTHON_VERSION: '2.7'
MINICONDA_HOME: C:\Miniconda-x64
TESTSCRIPT: 'python -m pytest'

- TESTENV: '2.7-nocover-32'
PYTHON_VERSION: '2.7'
MINICONDA_HOME: C:\Miniconda
TESTSCRIPT: 'python -m pytest'

- TESTENV: '3.6-nocover-64'
PYTHON_VERSION: '3.6'
MINICONDA_HOME: C:\Miniconda-x64
Expand Down
5 changes: 4 additions & 1 deletion docs/installation.rst
Expand Up @@ -33,10 +33,13 @@ This is the default option for Linux, and so should not be an issue there. On
Windows with the Mingw32 compiler, you might find `this information <https://wiki.python.org/moin/WindowsCompilers#GCC_-_MinGW-w64_.28x86.2C_x64.29>`_
useful for helping build apexpy.

ApexPy is not compatible with numpy version 1.19.X, older and newer versions
of numpy work without issue.

The package has been tested with the following setups (others might work, too):

* Windows (32/64 bit Python), Linux (64 bit), and Mac (64 bit)
* Python 2.7, 3.6, 3.7, 3.8, 3.9
* Python 3.6, 3.7, 3.8, 3.9


.. _installation-cmd:
Expand Down
2 changes: 0 additions & 2 deletions setup.cfg
Expand Up @@ -28,7 +28,6 @@ classifiers =
Operating System :: Microsoft :: Windows
Operating System :: MacOS :: MacOS X
Programming Language :: Python
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Expand Down Expand Up @@ -147,7 +146,6 @@ multi_line_output = 0
# - can use as many you want

python_versions =
2.7
3.6
3.7
3.8
Expand Down
15 changes: 7 additions & 8 deletions src/apexpy/__init__.py
@@ -1,16 +1,15 @@
from __future__ import absolute_import, division, print_function
from sys import stderr

from .apex import Apex, ApexHeightError
from . import helpers
from apexpy.apex import Apex, ApexHeightError
from apexpy import helpers

# Below try..catch required for autodoc to work on readthedocs
try:
from . import fortranapex
from apexpy import fortranapex
except ImportError:
print("".join(["ERROR: fortranapex module could not be imported. ",
"apexpy probably won't work"]))

stderr.write("".join(["fortranapex module could not be imported. ",
"apexpy probably won't work"]))

# Define the global variables
__version__ = "1.1.0"

__all__ = ['Apex', 'fortranapex', 'helpers', 'ApexHeightError']
45 changes: 23 additions & 22 deletions src/apexpy/__main__.py
@@ -1,29 +1,22 @@
# -*- coding: utf-8 -*-

"""Entry point for the CLI"""
"""Entry point for the Command Line Interface"""

from __future__ import division, absolute_import

import sys
import argparse
import datetime as dt
import numpy as np
import sys

import apexpy

try:
# Python 3
STDIN = sys.stdin.buffer
STDOUT = sys.stdout.buffer
except AttributeError:
# Python 2
STDIN = sys.stdin
STDOUT = sys.stdout
STDIN = sys.stdin.buffer
STDOUT = sys.stdout.buffer


def main():
"""Entry point for the script"""

# Construct the description and parser for command-line arguments
desc = 'Converts between geodetic, modified apex, quasi-dipole and MLT'
parser = argparse.ArgumentParser(description=desc, prog='apexpy')

Expand All @@ -33,40 +26,48 @@ def main():
parser.add_argument('dest', metavar='DEST',
choices=['geo', 'apex', 'qd', 'mlt'],
help='Convert to {geo, apex, qd, mlt}')
desc = 'YYYY[MM[DD[HHMMSS]]] date/time for IGRF coefficients, time part '
desc += 'required for MLT calculations'
desc = ''.join(['YYYY[MM[DD[HHMMSS]]] date/time for IGRF coefficients, ',
'time part required for MLT calculations'])
parser.add_argument('date', metavar='DATE', help=desc)
parser.add_argument('--height', dest='height', default=0, metavar='HEIGHT',
type=float, help='height for conversion')
parser.add_argument('--refh', dest='refh', metavar='REFH', type=float,
default=0,
help='reference height for modified apex coordinates')

parser.add_argument('-i', '--input', dest='file_in', metavar='FILE_IN',
type=argparse.FileType('r'), default=STDIN,
help='input file (stdin if none specified)')
parser.add_argument('-o', '--output', dest='file_out', metavar='FILE_OUT',
type=argparse.FileType('wb'), default=STDOUT,
help='output file (stdout if none specified)')

# Get the command line arguements
args = parser.parse_args()
arg_array = np.loadtxt(args.file_in, ndmin=2)

array = np.loadtxt(args.file_in, ndmin=2)

# Test the input arguments
if 'mlt' in [args.source, args.dest] and len(args.date) < 14:
desc = 'full date/time YYYYMMDDHHMMSS required for MLT calculations'
raise ValueError(desc)
if 9 <= len(args.date) and len(args.date) <= 13:
desc = 'full date/time must be given as YYYYMMDDHHMMSS, not ' \
+ 'YYYYMMDDHHMMSS'[:len(args.date)]
raise ValueError(desc)
datetime = dt.datetime.strptime(args.date,
'%Y%m%d%H%M%S'[:len(args.date) - 2])
A = apexpy.Apex(date=datetime, refh=args.refh)
lats, lons = A.convert(array[:, 0], array[:, 1], args.source, args.dest,
args.height, datetime=datetime)

# Format the time input
in_time = dt.datetime.strptime(args.date,
'%Y%m%d%H%M%S'[:len(args.date) - 2])

# Run the desired apex conversion
apex_obj = apexpy.Apex(date=in_time, refh=args.refh)
lats, lons = apex_obj.convert(arg_array[:, 0], arg_array[:, 1], args.source,
args.dest, args.height, datetime=in_time)

# Save the output to a file
np.savetxt(args.file_out, np.column_stack((lats, lons)), fmt='%.8f')

return


if __name__ == '__main__':
sys.exit(main())

0 comments on commit 6f0cce9

Please sign in to comment.