Skip to content

Commit

Permalink
ci: consolidate
Browse files Browse the repository at this point in the history
black style

use pyproject.toml alone

python >= 3.9 required
  • Loading branch information
scivision committed Jun 28, 2023
1 parent e9509df commit f5559f9
Show file tree
Hide file tree
Showing 19 changed files with 211 additions and 266 deletions.
141 changes: 96 additions & 45 deletions .archive/iri2016prof2D.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
from pathlib import Path
import logging
from numpy import arange, array, ceil, empty, floor, isnan, linspace, log10, meshgrid, nan, tile, transpose, where, hypot
from numpy import (
arange,
array,
ceil,
empty,
floor,
isnan,
linspace,
log10,
meshgrid,
nan,
tile,
transpose,
where,
hypot,
)
from numpy.ma import masked_where
from matplotlib.pyplot import close, cm, colorbar, figure

Expand Down Expand Up @@ -33,7 +48,6 @@


class IRI2016_2DProf:

# def __init__(self):

# pass
Expand All @@ -43,7 +57,6 @@ class IRI2016_2DProf:
# IRI2016Profile()._GetTitle(__self__)

def HeightVsTime(self, FIRI, hrlim, hrstp=1.0):

self.option = 1
nhrstp = int((hrlim[1] + hrstp - hrlim[0]) / hrstp) + 1
hrbins = list(map(lambda x: hrlim[0] + float(x) * hrstp, range(nhrstp)))
Expand All @@ -67,12 +80,25 @@ def HeightVsTime(self, FIRI, hrlim, hrstp=1.0):
# self._GetTitle()

altbins = arange(self.vbeg, self.vend + self.vstp, self.vstp)
self.data2D = {"alt": altbins, "hour": hrbins, "Ne": Ne, "Te": Te, "Ti": Ti, "title1": self.title1, "title2": self.title2}
self.data2D = {
"alt": altbins,
"hour": hrbins,
"Ne": Ne,
"Te": Te,
"Ti": Ti,
"title1": self.title1,
"title2": self.title2,
}
if FIRI:
self.FIRI2D = {"alt": altbins, "hour": hrbins, "Ne": NeFIRI, "title1": self.title1, "title2": self.title2}
self.FIRI2D = {
"alt": altbins,
"hour": hrbins,
"Ne": NeFIRI,
"title1": self.title1,
"title2": self.title2,
}

def LatVsLon(self, lonlim, lonstp):

self.option = 2
nlonstp = int((lonlim[1] + lonstp - lonlim[0]) / lonstp) + 1
lonbins = list(map(lambda x: lonlim[0] + float(x) * lonstp, range(nlonstp)))
Expand All @@ -91,10 +117,17 @@ def LatVsLon(self, lonlim, lonstp):
dip[i, :] = self.b[24, range(self.numstp)]

latbins = arange(self.vbeg, self.vend + self.vstp, self.vstp)
self.data2D = {"lat": latbins, "lon": lonbins, "NmF2": NmF2, "hmF2": hmF2, "B0": B0, "dip": dip, "title": self.title3}
self.data2D = {
"lat": latbins,
"lon": lonbins,
"NmF2": NmF2,
"hmF2": hmF2,
"B0": B0,
"dip": dip,
"title": self.title3,
}

def LatVsFL(self, date, FIRI, IGRF, time, gc, hlim, hstp, mlatlim, mlatstp):

if pyapex is None:
logging.error("PyApex is needed for LatVsFL")
return
Expand Down Expand Up @@ -125,8 +158,9 @@ def LatVsFL(self, date, FIRI, IGRF, time, gc, hlim, hstp, mlatlim, mlatstp):
self.coordl, self.qdcoordl = [], []

for h in arange(hlim[0], hlim[1] + hstp, hstp):

gc, qc = pyapex.ApexFL().getFL(date=date2, dlon=dlon, dlat=dlat, hateq=h, mlatRange=mlatlim, mlatSTP=mlatstp)
gc, qc = pyapex.ApexFL().getFL(
date=date2, dlon=dlon, dlat=dlat, hateq=h, mlatRange=mlatlim, mlatSTP=mlatstp
)

# x, y, z = gc['lat'], gc['alt'], gc['lon']

Expand Down Expand Up @@ -163,14 +197,14 @@ def LatVsFL(self, date, FIRI, IGRF, time, gc, hlim, hstp, mlatlim, mlatstp):
self.neFIRI = tile(nan, (np, nfl))

for fl in range(nfl):

curr_coordl = transpose(self.coordl[fl, :, :])

ind = where(curr_coordl[:, 1] >= (hlim[0] - 10.0))

if len(ind[0]) > 0:

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

self.ne[ind[0], fl] = outf[0, :]

Expand All @@ -179,7 +213,9 @@ def LatVsFL(self, date, FIRI, IGRF, time, gc, hlim, hstp, mlatlim, mlatstp):
self.te[ind[0], fl] = outf[3, :]

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

self.nHe[ind[0], fl] = outf[20, :]
self.nO[ind[0], fl] = outf[21, :]
Expand All @@ -201,7 +237,6 @@ def LatVsFL(self, date, FIRI, IGRF, time, gc, hlim, hstp, mlatlim, mlatstp):
self.ap, self.Ap = oarr[50, 0], oarr[51, 0]

def _Get_Title(self):

dateStr = "DATE: {:4d}/{:02d}/{:02d}".format(self.date[0], self.date[1], self.date[2])
timeStr = "TIME: {:02d}:{:02d} UT".format(self.time[0], self.time[1])
f107Str = "F107: {:6.2f}".format(self.f107cm)
Expand All @@ -219,7 +254,6 @@ def getIGRF(self, coordl, yeardec):
return

for glon, alt, glat in coordl:

Bnorth, Beast, Bdown, Btotal = pyigrf12.runigrf12(yeardec, glat, glon, alt)

# Horizontal component
Expand All @@ -228,7 +262,6 @@ def getIGRF(self, coordl, yeardec):
yield Bh

def PlotLatVsFL(self):

self._Get_Title()

nrow, ncol = 2, 2
Expand All @@ -242,9 +275,7 @@ def PlotLatVsFL(self):
f = figure(figsize=(16, 6))

for _ in range(nrow):

for _ in range(ncol):

pn = f.add_subplot(spID + (counter + 1))

if counter == 0:
Expand Down Expand Up @@ -289,7 +320,6 @@ def PlotLatVsFL(self):
counter += 1

def PlotLatVsFLFIRI(self, save=False, verbose=False):

self._Get_Title()

nrow, ncol = 1, 1
Expand All @@ -303,9 +333,7 @@ def PlotLatVsFLFIRI(self, save=False, verbose=False):
fg = figure(figsize=(16, 6))

for _ in range(nrow):

for _ in range(ncol):

pn = fg.add_subplot(spID + (counter + 1))

if counter == 0:
Expand Down Expand Up @@ -334,7 +362,9 @@ def PlotLatVsFLFIRI(self, save=False, verbose=False):
counter += 1

if save:
gpath = Path("../figures") / "{:04d}{:02d}{:02d}/".format(self.year, self.month, self.dom)
gpath = Path("../figures") / "{:04d}{:02d}{:02d}/".format(
self.year, self.month, self.dom
)
gpath.mkdir(parents=True, exist_ok=True)

figname = gpath / "firi-{:02d}{:02d}.jpg".format(self.time[0], self.time[1])
Expand All @@ -352,10 +382,11 @@ def Plot2D(self, save=False):
fg = figure(figsize=(24, 6))

if self.option == 1:

pn = fg.add_subplot(131)
X, Y = meshgrid(self.data2D["hour"], self.data2D["alt"])
ipc = pn.pcolor(X, Y, transpose(log10(self.data2D["Ne"])), cmap=cm.jet, vmax=13, vmin=9)
ipc = pn.pcolor(
X, Y, transpose(log10(self.data2D["Ne"])), cmap=cm.jet, vmax=13, vmin=9
)
pn.set_title(self.data2D["title1"])
pn.set_xlabel("Hour (UT)")
pn.set_ylabel("Altitude (km)")
Expand All @@ -378,7 +409,6 @@ def Plot2D(self, save=False):
cp1.set_label(r"T$_i$ ($^\circ$)")

elif self.option == 2:

pn1 = fg.add_subplot(111)

m = Basemap(
Expand All @@ -391,13 +421,24 @@ def Plot2D(self, save=False):
m.drawcoastlines()

parallelsLim = self._RoundLim([self.data2D["lat"][0], self.data2D["lat"][-1]])
m.drawparallels(arange(parallelsLim[0], parallelsLim[1], 20.0), labels=[True, False, False, True])
m.drawparallels(
arange(parallelsLim[0], parallelsLim[1], 20.0), labels=[True, False, False, True]
)

meridiansLim = self._RoundLim([self.data2D["lon"][0], self.data2D["lon"][-1]])
m.drawmeridians(arange(meridiansLim[0], meridiansLim[1], 30.0), labels=[True, False, False, True])
m.drawmeridians(
arange(meridiansLim[0], meridiansLim[1], 30.0), labels=[True, False, False, True]
)

X, Y = meshgrid(self.data2D["lon"], self.data2D["lat"])
ipc = m.pcolor(X, Y, transpose(9.0 * self.data2D["NmF2"] ** 0.5 * 1e-6), cmap=cm.jet, vmax=15.0, vmin=0)
ipc = m.pcolor(
X,
Y,
transpose(9.0 * self.data2D["NmF2"] ** 0.5 * 1e-6),
cmap=cm.jet,
vmax=15.0,
vmin=0,
)
m.contour(X, Y, transpose(self.data2D["dip"]), colors="k", linestyles="--")
pn1.set_title(self.data2D["title"])

Expand All @@ -408,28 +449,28 @@ def Plot2D(self, save=False):
pass

if save:
gpath = Path("../figures") / "{:04d}{:02d}{:02d}/".format(self.year, self.month, self.dom)
gpath = Path("../figures") / "{:04d}{:02d}{:02d}/".format(
self.year, self.month, self.dom
)
gpath.mkdir(parents=True, exist_ok=True)

figname = gpath / "iri-{:02d}{:02d}.jpg".format(self.HH, self.MM)
fg.savefig(figname, bbox_inches="tight", format="jpg", dpi=100)
# convert -resize 50% -delay 20 -loop 0 *.jpg myimage.gif

def PlotFIRI2D(self):

f = figure(figsize=(8, 6))

pn = f.add_subplot(111)

if self.option == 1:

X, Y = meshgrid(self.FIRI2D["hour"], self.FIRI2D["alt"])

# ipc = pn.pcolor(X, Y, transpose(log10(self.FIRI2D['Ne'])), cmap=cm.jet,
# vmax=12, vmin=9)

Z = self.FIRI2D["Ne"]
Z[where(Z < 10 ** 9)] = 10 ** 9
Z[where(Z < 10**9)] = 10**9
Z = transpose(log10(Z))

C = linspace(9, 12, 24 + 1, endpoint=True)
Expand All @@ -440,18 +481,15 @@ def PlotFIRI2D(self):
pn.set_ylabel("Altitude (km)")

elif self.option == 2:

pass

cp = colorbar(ipc)
cp.set_label("Log$_{10}$N$_e$(m$^{-3}$)")

def _RoundLim(self, lim):

return list(map(lambda x: x * 10.0, [floor(lim[0] / 10.0), ceil(lim[1] / 10.0)]))

def Plot2DMUF(self):

f = figure(figsize=(16, 12))

f.add_subplot(231)
Expand All @@ -474,7 +512,6 @@ def Plot2DMUF(self):
self.MapPColorInt(self.data2DInt["B0"], 250.0, 100.0)

def MapPColor(self, arr, vmax, vmin):

self.m = Basemap(
llcrnrlon=self.data2D["lon"][0],
llcrnrlat=self.data2D["lat"][0],
Expand All @@ -486,10 +523,14 @@ def MapPColor(self, arr, vmax, vmin):
self.m.drawcountries()

parallelsLim = self._RoundLim([self.data2D["lat"][0], self.data2D["lat"][-1]])
self.m.drawparallels(arange(parallelsLim[0], parallelsLim[1], 2.0), labels=[True, False, False, True])
self.m.drawparallels(
arange(parallelsLim[0], parallelsLim[1], 2.0), labels=[True, False, False, True]
)

meridiansLim = self._RoundLim([self.data2D["lon"][0], self.data2D["lon"][-1]])
self.m.drawmeridians(arange(meridiansLim[0], meridiansLim[1], 5.0), labels=[True, False, False, True])
self.m.drawmeridians(
arange(meridiansLim[0], meridiansLim[1], 5.0), labels=[True, False, False, True]
)

X, Y = meshgrid(self.data2D["lon"], self.data2D["lat"])
# ipc = self.m.pcolor(X, Y, transpose(arr), cmap=cm.jet, vmax=vmax, vmin=vmin)
Expand All @@ -506,7 +547,6 @@ def MapPColor(self, arr, vmax, vmin):
# ------------------------------------------------------------------------------

def IntLatVsLon(self, lat0=-11.95, lon0=-76.87):

# self.m.plot(lon0, lat0, 'bx')

X0, Y0 = meshgrid(self.data2D["lon"], self.data2D["lat"])
Expand All @@ -520,13 +560,20 @@ def IntLatVsLon(self, lat0=-11.95, lon0=-76.87):
hmF2 = interp2d(x0, y0, transpose(self.data2D["hmF2"]))(lon1, lat1)
B0 = interp2d(x0, y0, transpose(self.data2D["B0"]))(lon1, lat1)

self.data2DInt = {"lon": lon1, "lat": lat1, "foF2": transpose(foF2), "hmF2": transpose(hmF2), "B0": transpose(B0)}
self.data2DInt = {
"lon": lon1,
"lat": lat1,
"foF2": transpose(foF2),
"hmF2": transpose(hmF2),
"B0": transpose(B0),
}

self.data2DTX = {}
self.data2DTX["foF2"] = interp2d(x0, y0, 9.0 * transpose(self.data2D["NmF2"]) ** 0.5 * 1e-6)(lon0, lat0)[0]
self.data2DTX["foF2"] = interp2d(
x0, y0, 9.0 * transpose(self.data2D["NmF2"]) ** 0.5 * 1e-6
)(lon0, lat0)[0]

def MapPColorInt(self, arr, vmax, vmin):

self.m = Basemap(
llcrnrlon=self.data2D["lon"][0],
llcrnrlat=self.data2D["lat"][0],
Expand All @@ -538,10 +585,14 @@ def MapPColorInt(self, arr, vmax, vmin):
self.m.drawcountries()

parallelsLim = self._RoundLim([self.data2D["lat"][0], self.data2D["lat"][-1]])
self.m.drawparallels(arange(parallelsLim[0], parallelsLim[1], 2.0), labels=[True, False, False, True])
self.m.drawparallels(
arange(parallelsLim[0], parallelsLim[1], 2.0), labels=[True, False, False, True]
)

meridiansLim = self._RoundLim([self.data2D["lon"][0], self.data2D["lon"][-1]])
self.m.drawmeridians(arange(meridiansLim[0], meridiansLim[1], 5.0), labels=[True, False, False, True])
self.m.drawmeridians(
arange(meridiansLim[0], meridiansLim[1], 5.0), labels=[True, False, False, True]
)

X, Y = meshgrid(self.data2DInt["lon"], self.data2DInt["lat"])
# ipc = self.m.pcolor(X, Y, transpose(arr), cmap=cm.jet, vmax=vmax, vmin=vmin)
Expand Down
Loading

0 comments on commit f5559f9

Please sign in to comment.