Skip to content

Commit

Permalink
use python -m iri2016. instead of console_scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Oct 12, 2020
1 parent c1489fb commit 523d937
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 105 deletions.
28 changes: 28 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
dist: bionic
# Matlab R2020a libstdc++ needs Ubuntu 18.04

language: matlab

matlab:
- latest

os:
- linux

git:
- depth: 3
- quiet: true

addons:
apt:
packages:
- gfortran
snaps:
- name: cmake
confinement: classic

before_script:
- export PATH=/snap/bin:$PATH

script:
- matlab -batch "r = runtests('iri2016'); assert(~isempty(r)); assertSuccess(r)"
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![image](https://zenodo.org/badge/DOI/10.5281/zenodo.240895.svg)](https://doi.org/10.5281/zenodo.240895)
![Actions Status](https://github.com/space-physics/iri2016/workflows/ci/badge.svg)
[![Build Status](https://travis-ci.com/space-physics/iri2016.svg?branch=master)](https://travis-ci.com/space-physics/iri2016)
[![PyPi version](https://img.shields.io/pypi/pyversions/iri2016.svg)](https://pypi.python.org/pypi/iri2016)
[![PyPi Download stats](https://static.pepy.tech/badge/iri2016)](https://pepy.tech/project/iri2016)

Expand All @@ -13,7 +14,7 @@ A Fortran compiler is required to build the IRI2016 code.

## Install

**Prerequisites**
Prerequisites

* Fortran compiler--any modern Fortran compiler will do. Here's how to get Gfortran:
* Linux: `apt install gfortran`
Expand Down Expand Up @@ -55,21 +56,21 @@ ctest -S iri2016/src/iri2016/setup.cmake -VV
* Altitude Profile: plot density and temperatures vs altitude

```sh
iri2016_altitude 2003-11-21T12 -11.95 -76.77
python -m iri2016.altitude 2003-11-21T12 -11.95 -76.77
```

![image](./figures/iri1DExample01.png)
* Latitude profile: plot densities and height at the peak of F2, F2, and E regions vs geographic latitude

```sh
iri2016_latitude 2004-11-21T17 -76.77
python -m iri2016.latitude 2004-11-21T17 -76.77
```

![image](./figures/iri1DExample02.png)
* Time profile: plot densities and height at the peak of F2, F2, and E regions vs UTC

```sh
iri2016_time 2014-11-21 2014-11-22 1 -11.95 -76.77
python -m iri2016.time 2014-11-21 2014-11-22 1 -11.95 -76.77
```

![image](./figures/plasma.png)
Expand Down
12 changes: 2 additions & 10 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = iri2016
version = 1.10.2
version = 1.11.0
author = Michael Hirsch, Ph.D.; Ronald Ilma
author_email = scivision@users.noreply.github.com
description = IRI2016 International Reference Ionosphere from Python
Expand All @@ -14,9 +14,7 @@ classifiers =
Intended Audience :: Science/Research
Operating System :: OS Independent
Programming Language :: Fortran
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3
Topic :: Scientific/Engineering :: Atmospheric Science
license_files =
LICENSE.txt
Expand Down Expand Up @@ -55,9 +53,3 @@ plot =
pyigrf12
cartopy
pyapex

[options.entry_points]
console_scripts =
iri2016_altitude = iri2016.__main__:altitude
iri2016_latitude = iri2016.__main__:latitude
iri2016_time = iri2016.__main__:time_profile
71 changes: 0 additions & 71 deletions src/iri2016/__main__.py

This file was deleted.

33 changes: 33 additions & 0 deletions src/iri2016/altitude.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from .base import IRI

from argparse import ArgumentParser
import typing as T


def main(time: str, alt_km: T.Sequence[float], glat: float, glon: float):
""" Height Profile Example """

return IRI(time, alt_km, glat, glon)


def cli():
p = ArgumentParser(description="IRI2016 altitude profile")
p.add_argument("time", help="time of simulation")
p.add_argument("latlon", help="geodetic latitude, longitude (degrees)", type=float, nargs=2)
p.add_argument("-alt_km", help="altitude START STOP STEP (km)", type=float, nargs=3, default=(80, 1000, 10))
P = p.parse_args()

iono = main(P.time, P.alt_km, *P.latlon)

try:
from matplotlib.pyplot import show
import iri2016.plots as piri

piri.altprofile(iono)
show()
except ImportError:
pass


if __name__ == "__main__":
cli()
6 changes: 3 additions & 3 deletions src/iri2016/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import io
import os
import numpy as np
import typing
import typing as T
import importlib.resources

iri_name = "iri2016_driver"
Expand All @@ -21,13 +21,13 @@
__all__ = ["IRI"]


def IRI(time: datetime, altkmrange: typing.Sequence[float], glat: float, glon: float) -> xarray.Dataset:
def IRI(time: T.Union[str, datetime], altkmrange: T.Sequence[float], glat: float, glon: float) -> xarray.Dataset:

if isinstance(time, str):
time = parse(time)

assert len(altkmrange) == 3, "altitude (km) min, max, step"
assert isinstance(glat, float) and isinstance(glon, float), "glat, glon is scalar"
assert isinstance(glat, (int, float)) and isinstance(glon, (int, float)), "glat, glon is scalar"

with importlib.resources.path(__package__, iri_name) as exe:
cmd = [
Expand Down
43 changes: 43 additions & 0 deletions src/iri2016/latitude.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from .profile import geoprofile

from pathlib import Path
from argparse import ArgumentParser
import typing as T


def main(time: str, alt_km: float, glat: T.Sequence[float], glon: float, outfn: Path = None):
""" latitude Profile Example """

iono = geoprofile(latrange=glat, glon=glon, altkm=alt_km, time=time)

if outfn:
outfn = Path(outfn).expanduser()
print("writing", outfn)
iono.to_netcdf(outfn)

return iono


def cli():
p = ArgumentParser(description="IRI2016 latitude profile")
p.add_argument("time", help="time of simulation")
p.add_argument("glon", help="geodetic longitude (degrees)", type=float)
p.add_argument("-glat", help="geodetic latitude START STOP STEP (degrees)", type=float, nargs=3, default=(-60, 60, 2.0))
p.add_argument("-alt_km", help="altitude (km)", type=float, default=300.0)
p.add_argument("-o", "--outfn", help="write data to file")
P = p.parse_args()

iono = main(P.time, P.alt_km, P.glat, P.glon, P.outfn)

try:
from matplotlib.pyplot import show
import iri2016.plots as piri

piri.latprofile(iono)
show()
except ImportError:
pass


if __name__ == "__main__":
cli()
8 changes: 4 additions & 4 deletions src/iri2016/profile.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import xarray
from dateutil.parser import parse
from datetime import datetime, timedelta
import typing
import typing as T
import numpy as np

from .base import IRI

__all__ = ["datetimerange", "timeprofile", "geoprofile"]


def datetimerange(start: datetime, end: datetime, step: timedelta) -> typing.List[datetime]:
def datetimerange(start: datetime, end: datetime, step: timedelta) -> T.List[datetime]:
"""like range() for datetime"""
if isinstance(start, str):
start = parse(start)
Expand All @@ -24,7 +24,7 @@ def datetimerange(start: datetime, end: datetime, step: timedelta) -> typing.Lis
return [start + i * step for i in range((end - start) // step)]


def timeprofile(tlim: tuple, dt: timedelta, altkmrange: list, glat: float, glon: float) -> xarray.Dataset:
def timeprofile(tlim: tuple, dt: timedelta, altkmrange: T.Sequence[float], glat: float, glon: float) -> xarray.Dataset:
"""compute IRI altitude profile over time range for fixed lat/lon
"""

Expand All @@ -51,7 +51,7 @@ def timeprofile(tlim: tuple, dt: timedelta, altkmrange: list, glat: float, glon:
return iono


def geoprofile(latrange: typing.Sequence[float], glon: float, altkm: float, time: datetime) -> xarray.Dataset:
def geoprofile(latrange: T.Sequence[float], glon: float, altkm: float, time: T.Union[str, datetime]) -> xarray.Dataset:
"""compute IRI altitude profiles at time, over lat or lon range
"""

Expand Down
19 changes: 6 additions & 13 deletions src/iri2016/tests/test_scripts.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import pytest
import iri2016.time as time_profile
import iri2016.latitude as lat_profile
import iri2016.altitude as alt_profile

import subprocess
import os


@pytest.mark.skipif(os.environ.get("CI") is not None, reason="CI no display")
def test_latitude():
pytest.importorskip("matplotlib")
subprocess.check_call(["iri2016_latitude", "-148"])
lat_profile.main("2012-01-01", 300, (-60, 60, 2.0), -148)


@pytest.mark.skipif(os.environ.get("CI") is not None, reason="CI no display")
def test_time():
pytest.importorskip("matplotlib")
subprocess.check_call(["iri2016_time", "2012-01-01", "2012-01-02", "1.0", "65", "-148"])
time_profile.main(("2012-01-01", "2012-01-02", 1.0), (100, 200, 20), 65, -148)


@pytest.mark.skipif(os.environ.get("CI") is not None, reason="CI no display")
def test_alt():
pytest.importorskip("matplotlib")
subprocess.check_call(["iri2016_altitude", "2012-01-01", "65", "-148"])
alt_profile.main("2012-01-01", (80, 1000, 10), 65, -148)
33 changes: 33 additions & 0 deletions src/iri2016/time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from .profile import timeprofile

from argparse import ArgumentParser
from datetime import timedelta
import typing as T


def main(time: T.Sequence[str], alt_km: T.Sequence[float], glat: float, glon: float):
""" IRI2016 time profile """
return timeprofile((time[0], time[1]), timedelta(hours=float(time[2])), alt_km, glat, glon)


def cli():
p = ArgumentParser()
p.add_argument("time", help="start yy-mm-dd, stop yy-mm-dd, step_hour", nargs=3)
p.add_argument("latlon", help="geodetic latitude, longitude (degrees)", nargs=2, type=float)
p.add_argument("-alt_km", help="altitude START STOP STEP (km)", type=float, nargs=3, default=(100, 200, 20))
P = p.parse_args()

iono = main(P.time, P.alt_km, *P.latlon)

try:
from matplotlib.pyplot import show
import iri2016.plots as piri

piri.timeprofile(iono)
show()
except ImportError:
pass


if __name__ == "__main__":
cli()

0 comments on commit 523d937

Please sign in to comment.