Skip to content
This repository was archived by the owner on Aug 11, 2022. It is now read-only.

Commit d4a1d67

Browse files
committed
black_format
1 parent 4f9c20f commit d4a1d67

File tree

10 files changed

+182
-123
lines changed

10 files changed

+182
-123
lines changed

.github/workflows/ci.yml

+16-13
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,39 @@ jobs:
1313
linux:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v1
17-
- uses: actions/setup-python@v1
16+
- uses: actions/checkout@v2
17+
- uses: actions/setup-python@v2
1818
with:
1919
python-version: '3.x'
20-
- run: sudo apt install -yq --no-install-recommends gfortran ninja-build
20+
21+
- run: sudo apt install -yq --no-install-recommends ninja-build
2122
- run: pip install -e .[tests,lint]
23+
2224
- run: flake8
23-
- run: mypy .
24-
- run: pytest -r a -v
25+
- run: mypy
26+
- run: pytest
2527

2628
macos:
2729
runs-on: macos-latest
2830
steps:
29-
- uses: actions/checkout@v1
30-
- uses: actions/setup-python@v1
31+
- uses: actions/checkout@v2
32+
- uses: actions/setup-python@v2
3133
with:
3234
python-version: '3.x'
33-
- run: brew install gcc ninja
35+
36+
- run: brew install ninja
3437
- run: pip install -e .[tests]
35-
- run: pytest -r a -v
38+
- run: pytest
3639

3740
windows:
3841
runs-on: windows-latest
3942
steps:
40-
- uses: actions/checkout@v1
41-
- uses: actions/setup-python@v1
43+
- uses: actions/checkout@v2
44+
- uses: actions/setup-python@v2
4245
with:
4346
python-version: '3.x'
44-
- run: cinst -y ninja
47+
4548
- run: echo "[build]`ncompiler=mingw32" | Out-File -Encoding ASCII ~/pydistutils.cfg
4649
shell: powershell
4750
- run: pip install -e .[tests]
48-
- run: pytest -r a -v
51+
- run: pytest

mypy.ini renamed to .mypy.ini

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
[mypy]
2+
files = iri90/
3+
24
ignore_missing_imports = True
3-
strict_optional = False
45
allow_redefinition = True
56
show_error_context = False
67
show_column_numbers = True
78
warn_unreachable = False
8-
9-
[mypy-xarray]
10-
follow_imports = skip

AltitudeProfile.py

+22-10
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,35 @@
99

1010
def main():
1111
p = ArgumentParser()
12-
p.add_argument('--alt', help='START STOP STEP altitude [km]', type=float, nargs=3, default=(85, 500, 1.))
13-
p.add_argument('-t', '--time', help='date and time of simulation', default='2012-07-21T12:35')
14-
p.add_argument('-c', '--latlon', help='geodetic coordinates of simulation', default=(65, -147.5), type=float)
15-
p.add_argument('--f107', type=float, default=200.)
16-
p.add_argument('--f107a', type=float, default=200.)
17-
p.add_argument('--ap', type=int, default=4)
12+
p.add_argument(
13+
"--alt",
14+
help="START STOP STEP altitude [km]",
15+
type=float,
16+
nargs=3,
17+
default=(85, 500, 1.0),
18+
)
19+
p.add_argument("-t", "--time", help="date and time of simulation", default="2012-07-21T12:35")
20+
p.add_argument(
21+
"-c",
22+
"--latlon",
23+
help="geodetic coordinates of simulation",
24+
default=(65, -147.5),
25+
type=float,
26+
)
27+
p.add_argument("--f107", type=float, default=200.0)
28+
p.add_argument("--f107a", type=float, default=200.0)
29+
p.add_argument("--ap", type=int, default=4)
1830
p = p.parse_args()
19-
# %% user parameters
31+
# %% user parameters
2032
altkm = np.arange(p.alt[0], p.alt[1], p.alt[2])
2133
dtime = parse(p.time)
22-
# %% run IRI90 across altitude
34+
# %% run IRI90 across altitude
2335
iono = iri90.runiri(dtime, altkm, p.latlon, p.f107, p.f107a, ap=p.ap)
24-
# %% altitude profile plot
36+
# %% altitude profile plot
2537
print(iono)
2638
ipt.plotalt(iono)
2739
show()
2840

2941

30-
if __name__ == '__main__':
42+
if __name__ == "__main__":
3143
main()

TimeProfile.py

+30-14
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,44 @@
99

1010

1111
def main():
12-
p = ArgumentParser(description='IRI90 time profile plot')
13-
p.add_argument('-t', '--trange', help='START STOP STEP (hours) time [UTC]', nargs=3,
14-
default=('2012-08-21', '2012-08-22', 0.25))
15-
p.add_argument('--alt', help='START STOP STEP altitude [km]', type=float, nargs=3, default=(120, 180, 20))
16-
p.add_argument('-c', '--latlon', help='geodetic coordinates of simulation',
17-
type=float, default=(65, -148))
18-
p.add_argument('--f107', type=float, default=200.)
19-
p.add_argument('--f107a', type=float, default=200.)
20-
p.add_argument('--ap', type=int, default=4)
21-
p.add_argument('--species', help='species to plot', nargs='+', default=('ne'))
12+
p = ArgumentParser(description="IRI90 time profile plot")
13+
p.add_argument(
14+
"-t",
15+
"--trange",
16+
help="START STOP STEP (hours) time [UTC]",
17+
nargs=3,
18+
default=("2012-08-21", "2012-08-22", 0.25),
19+
)
20+
p.add_argument(
21+
"--alt",
22+
help="START STOP STEP altitude [km]",
23+
type=float,
24+
nargs=3,
25+
default=(120, 180, 20),
26+
)
27+
p.add_argument(
28+
"-c",
29+
"--latlon",
30+
help="geodetic coordinates of simulation",
31+
type=float,
32+
default=(65, -148),
33+
)
34+
p.add_argument("--f107", type=float, default=200.0)
35+
p.add_argument("--f107a", type=float, default=200.0)
36+
p.add_argument("--ap", type=int, default=4)
37+
p.add_argument("--species", help="species to plot", nargs="+", default=("ne"))
2238
p = p.parse_args()
23-
# %% user parameters
39+
# %% user parameters
2440
tlim = (parse(p.trange[0]), parse(p.trange[1]))
2541
dt = timedelta(hours=p.trange[2]) # timedelta reduces to seconds, etc for sub-hour step size
2642

2743
altkm = np.arange(*p.alt)
28-
# %% run IRI90 across time
44+
# %% run IRI90 across time
2945
iono = iri90.timeprofile(tlim, dt, altkm, p.latlon, p.f107, p.f107a, ap=p.ap)
30-
# %% plots
46+
# %% plots
3147
ipt.plottime(iono, p.species)
3248
show()
3349

3450

35-
if __name__ == '__main__':
51+
if __name__ == "__main__":
3652
main()

iri90/__init__.py

+65-43
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
import numpy as np
77
import xarray
88
from typing import Sequence
9+
910
#
1011
import iri90fort
1112

1213
rdir = Path(__file__).parent
13-
Ts = ['Tn', 'Ti', 'Te']
14-
simout = ['ne', 'Tn', 'Ti', 'Te', 'nO+', 'nH+', 'nHe+', 'nO2+', 'nNO+']
14+
Ts = ["Tn", "Ti", "Te"]
15+
simout = ["ne", "Tn", "Ti", "Te", "nO+", "nH+", "nHe+", "nO2+", "nNO+"]
1516

1617

1718
def datetimerange(start: datetime, end: datetime, step: timedelta) -> list:
@@ -20,72 +21,93 @@ def datetimerange(start: datetime, end: datetime, step: timedelta) -> list:
2021
assert isinstance(end, datetime)
2122
assert isinstance(step, timedelta)
2223

23-
return [start + i*step for i in range((end-start) // step)]
24-
24+
return [start + i * step for i in range((end - start) // step)]
2525

26-
def runiri(time: datetime, altkm: float, glatlon: tuple, f107: float, f107a: float, ap: int) -> xarray.DataArray:
2726

27+
def runiri(
28+
time: datetime, altkm: np.ndarray, glatlon: tuple, f107: float, f107a: float, ap: int
29+
) -> xarray.DataArray:
2830
def _collect_output() -> xarray.DataArray:
29-
""" collect IRI90 output into xarray.DataArray with metadata"""
30-
iono = xarray.DataArray(outf[:9, :].T,
31-
coords={'alt_km': altkm, 'sim': simout},
32-
dims=['alt_km', 'sim'],
33-
attrs={'f107': f107, 'f107a': f107a, 'ap': ap, 'glatlon': glatlon, 'time': time})
34-
35-
# i=(iono['Ti']<iono['Tn']).values
36-
# iono.ix[i,'Ti'] = iono.ix[i,'Tn']
37-
38-
# i=(iono['Te']<iono['Tn']).values
39-
# iono.ix[i,'Te'] = iono.ix[i,'Tn']
40-
41-
# %% iri90 outputs percentage of Ne
42-
iono.loc[:, ['nO+', 'nH+', 'nHe+', 'nO2+', 'nNO+']] *= iono.loc[:, 'ne']/100.
43-
# %% These two parameters only output if JF(6)=False, otherwise bogus values
31+
"""collect IRI90 output into xarray.DataArray with metadata"""
32+
iono = xarray.DataArray(
33+
outf[:9, :].T,
34+
coords={"alt_km": altkm, "sim": simout},
35+
dims=["alt_km", "sim"],
36+
attrs={
37+
"f107": f107,
38+
"f107a": f107a,
39+
"ap": ap,
40+
"glatlon": glatlon,
41+
"time": time,
42+
},
43+
)
44+
45+
# i=(iono['Ti']<iono['Tn']).values
46+
# iono.ix[i,'Ti'] = iono.ix[i,'Tn']
47+
48+
# i=(iono['Te']<iono['Tn']).values
49+
# iono.ix[i,'Te'] = iono.ix[i,'Tn']
50+
51+
# %% iri90 outputs percentage of Ne
52+
iono.loc[:, ["nO+", "nH+", "nHe+", "nO2+", "nNO+"]] *= iono.loc[:, "ne"] / 100.0
53+
# %% These two parameters only output if JF(6)=False, otherwise bogus values
4454
# iono['nClusterIons'] = iono['ne'] * outf[9,:]/100.
4555
# iono['nN+'] = iono['ne'] * outf[10,:]/100.
46-
# %% negative indicates undefined
56+
# %% negative indicates undefined
4757
for c in iono.sim:
48-
iono.loc[iono.loc[:, c] <= 0., c] = np.nan
58+
iono.loc[iono.loc[:, c] <= 0.0, c] = np.nan
4959

5060
return iono
5161

5262
glat, glon = glatlon
5363
jmag = 0 # coordinates are: 0:geographic 1: magnetic
5464

55-
JF = np.array((1, 1, 1, 1, 0, 1,
56-
1, 1, 1, 1, 1, 1), bool) # Solomon 1993 version of IRI
65+
JF = np.array((1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1), bool) # Solomon 1993 version of IRI
5766
# JF = (1,1,1) + (0,0,0) +(1,)*14 + (0,1,0,1,1,1,1,0,0,0,1,1,0,1,0,1,1,1) #for 2013 version of IRI
5867

59-
monthday = time.month*100 + time.day # yep, that's how the IRI code wants it, NOT as character.
68+
monthday = (
69+
time.month * 100 + time.day
70+
) # yep, that's how the IRI code wants it, NOT as character.
6071
# + 25 hours for UTC time
61-
hourfrac = (time.hour+25) + time.minute/60 + time.second/3600
62-
datadir = str(rdir/'data')+'/'
63-
# %% call IRI
64-
outf, oarr = iri90fort.iri90(JF, jmag,
65-
glat, glon % 360.,
66-
-f107,
67-
monthday, # integer
68-
hourfrac,
69-
altkm,
70-
datadir)
72+
hourfrac = (time.hour + 25) + time.minute / 60 + time.second / 3600
73+
datadir = str(rdir / "data") + "/"
74+
# %% call IRI
75+
outf, oarr = iri90fort.iri90(
76+
JF,
77+
jmag,
78+
glat,
79+
glon % 360.0,
80+
-f107,
81+
monthday, # integer
82+
hourfrac,
83+
altkm,
84+
datadir,
85+
)
7186

7287
iono = _collect_output()
7388

7489
return iono
7590

7691

77-
def timeprofile(tlim: Sequence[datetime], dt: timedelta,
78-
altkm: np.ndarray, glatlon: tuple,
79-
f107: float, f107a: float, ap: int) -> xarray.DataArray:
92+
def timeprofile(
93+
tlim: Sequence[datetime],
94+
dt: timedelta,
95+
altkm: np.ndarray,
96+
glatlon: tuple,
97+
f107: float,
98+
f107a: float,
99+
ap: int,
100+
) -> xarray.DataArray:
80101
"""compute IRI90 at a single altiude, over time range"""
81102

82103
T = datetimerange(tlim[0], tlim[1], dt)
83104

84-
iono = xarray.DataArray(np.empty((len(T), altkm.size, 9)),
85-
coords={'time': T, 'alt_km': altkm, 'sim': simout},
86-
dims=['time', 'alt_km', 'sim'],
87-
attrs={'f107': f107, 'f107a': f107a, 'ap': ap, 'glatlon': glatlon}
88-
)
105+
iono = xarray.DataArray(
106+
np.empty((len(T), altkm.size, 9)),
107+
coords={"time": T, "alt_km": altkm, "sim": simout},
108+
dims=["time", "alt_km", "sim"],
109+
attrs={"f107": f107, "f107a": f107a, "ap": ap, "glatlon": glatlon},
110+
)
89111

90112
for t in T:
91113
iono.loc[t, ...] = runiri(t, altkm, glatlon, f107, f107a, ap)

0 commit comments

Comments
 (0)