Skip to content

Commit

Permalink
simplify prereqs and make optional
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Feb 27, 2018
1 parent 45f829d commit 88f2264
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
9 changes: 5 additions & 4 deletions pyiri2016/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
except (ImportError,AttributeError): # Python < 3.5
from pathlib2 import Path
#%%
from datetime import datetime
import datetime
from dateutil.parser import parse
from iri2016 import iriwebg
from numpy import arange, nan, ones, squeeze, where
Expand Down Expand Up @@ -68,10 +68,11 @@ def Switches(self):

#%%

def IRI(self, ap=5, f107=150, glat=0., glon=0., time=datetime.now(),
def IRI(self, ap=5, f107=150, glat=0., glon=0., time=datetime.datetime.now(),
ssn=150, var=1, vbeg=130., vend=130.+1., vstp=1.):

time = parse(time)
if isinstance(time, str):
time = parse(time)
# doy = squeeze(TimeUtilities().CalcDOY(year, month, dom))

# IRI options
Expand Down Expand Up @@ -174,7 +175,7 @@ def _RmNeg(self, inputs):
class IRI2016Profile(IRI2016):

def __init__(self, alt=300., altlim=[90.,150.], altstp=2., htecmax=0,
time=datetime.now(), hrlim=[0., 24.], hrstp=.25,
time=datetime.datetime.now(), hrlim=[0., 24.], hrstp=.25,
iut=1, jmag=0,
lat=0., latlim=[-90, 90], latstp=10.,
lon=0., lonlim=[-180,180], lonstp=20.,
Expand Down
32 changes: 17 additions & 15 deletions pyiri2016/iri2016prof2D.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path
import logging
from numpy import arange, array, ceil, empty, floor, isnan, linspace, \
log10, meshgrid, nan, tile, transpose, where
log10, meshgrid, nan, tile, transpose, where, hypot
from numpy.ma import masked_where
from matplotlib.pyplot import close, cm, colorbar, figure, savefig
try:
Expand All @@ -16,15 +16,15 @@
pyapex=None

try:
from pyigrf.pyigrf import GetIGRF
import pyigrf12
except ImportError:
GetIGRF = None
pyigrf12 = None

from scipy.interpolate import interp2d#, RectBivariateSpline
#
from pyiri2016 import IRI2016
from pyiri2016 import IRI2016Profile
from iri2016 import irisubgl, firisubl
import iri2016
from timeutil import TimeUtilities
#
cwd = Path(__file__).parent
Expand Down Expand Up @@ -119,7 +119,7 @@ def LatVsFL(self, date=[2003, 11, 21], FIRI=False, IGRF=False, time=[23, 15, 0],

# hlim -> Height range at equator, in km
# hstp -> height resolution at equator, in km
# mlatlim -> Geom. latitude range, in degrees
# mlatlim -> Geom. latitude range, in degreesgetIGRF
# mlatstp -> Geom. latitude resolution, in degrees

#
Expand Down Expand Up @@ -181,7 +181,7 @@ def LatVsFL(self, date=[2003, 11, 21], FIRI=False, IGRF=False, time=[23, 15, 0],

if len(ind[0]) > 0:

outf, oarr = irisubgl(jf, jmag, year, mmdd, hour2, \
outf, oarr = iri2016.irisubgl(jf, jmag, year, mmdd, hour2, \
curr_coordl[ind[0], :], DataFolder)

self.ne[ind[0], fl] = outf[0, :]
Expand All @@ -190,7 +190,7 @@ def LatVsFL(self, date=[2003, 11, 21], FIRI=False, IGRF=False, time=[23, 15, 0],
self.ti[ind[0], fl] = outf[2, :]
self.te[ind[0], fl] = outf[3, :]

if FIRI: self.neFIRI[ind[0], fl], ierr = firisubl(year, doy, hour2, \
if FIRI: self.neFIRI[ind[0], fl], ierr = iri2016.firisubl(year, doy, hour2, \
curr_coordl[ind[0], :], DataFolder)

self.nHe[ind[0], fl] = outf[20, :]
Expand All @@ -201,8 +201,10 @@ def LatVsFL(self, date=[2003, 11, 21], FIRI=False, IGRF=False, time=[23, 15, 0],
self.nH[ind[0], fl] = outf[26, :]
self.nN[ind[0], fl] = outf[27, :]

self.babs[ind[0], fl] = list(self.getIGRF(curr_coordl[ind[0], :], date2)) \
if IGRF else outf[19, :]
if IGRF:
self.babs[ind[0], fl] = list(self.getIGRF(curr_coordl[ind[0], :], date2))
else:
self.babs[ind[0], fl] = outf[19, :]

self.hlim = hlim

Expand All @@ -225,19 +227,19 @@ def _Get_Title(self):
self._title2 = '{:s} - {:s}'.format(f107Str, ApStr)


def getIGRF(self, coordl, year):
if GetIGRF is None:
def getIGRF(self, coordl, yeardec):
if pyigrf12 is None:
logging.error('pyIGRF is not installed')
return

for lon, alt, lat in coordl:
for glon, alt, glat in coordl:

bn, be, bd, xl, icode = GetIGRF(lat, lon, alt, year)
Bnorth, Beast, Bdown, Btotal = pyigrf12.runigrf12(yeardec, glat, glon, alt)

# Horizontal component
bh = (bn**2 + be**2)**.5
Bh = hypot(Bnorth, Beast)

yield bh
yield Bh


def PlotLatVsFL(self):
Expand Down
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
install_requires = ['python-dateutil','numpy','pathlib2',
'timeutil']
install_requires = ['python-dateutil','numpy','pathlib2']
tests_require = ['nose','coveralls']
name = 'pyiri2016'
# %%
Expand Down Expand Up @@ -52,7 +51,7 @@
ext_modules = [ext],
data_files = iriDataFiles,
install_requires = install_requires,
extras_require={'plot':['matplotlib','seaborn','scipy',],
extras_require={'plot':['matplotlib','seaborn','scipy','timeutil','pyigrf12','cartopy','pyapex'],
'tests':tests_require,},
tests_require = tests_require,
python_requires='>=2.7',
Expand Down

0 comments on commit 88f2264

Please sign in to comment.