Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def runPAdungey(quality):
#test for range of pitch angles
ticks = spt.tickrange('2002-04-18', '2002-04-19', 1)
loci = spc.Coords([[-4,0,0], [-5,0,0]], 'SM', 'car')
vals = []
for pp in range(1,91):
dum = lgmpy.get_Lstar(loci.data[1], ticks.UTC[1], alpha=pp, coord_system='SM',
Bfield='Lgm_B_Dungey', extended_out=True, LstarQuality=quality)
try:
vals.extend(dum[pp]['Lstar'])
except (IndexError, TypeError): #get_Lstar returns a 0-D nan in some cases...
vals.extend([dum[pp]['Lstar'].tolist()])
fig = plt.figure()
expect = dungeyLeq(tb.hypot(loci.data[1]))
#print(expect)
plt.plot(100*(dm.dmarray(vals)-expect)/expect, drawstyle='steps-mid')
plt.ylim([-0.01, 0.01])
plt.xlabel('Pitch Angle')
plt.ylabel('100*(L* - L*$_{exp}$)/L*$_{exp}$')
plt.title('Dungey model [-5,0,0]$_{SM}$'+'; Quality ({0})'.format(str(quality)))
figname = 'MagEphem_Dungey_test_q{0}'.format(str(quality)) #'LGM_L*_vs_PA_cdip_q{0}'.format(str(quality))
plt.savefig(''.join([figname,'.png']), dpi=300)
plt.savefig(''.join([figname,'.pdf']))
Lgm_Convert_Coords( pointer(Pgsm), pointer(Pwgs), GSM_TO_WGS84, mmi.c )
Lgm_Convert_Coords( pointer(Pwgs), pointer(Pmlt), WGS84_TO_EDMAG, mmi.c )
R, MLat, MLon, MLT = c_double(), c_double(), c_double(), c_double(),
Lgm_EDMAG_to_R_MLAT_MLON_MLT( pointer(Pmlt), pointer(R), pointer(MLat), pointer(MLon),
pointer(MLT), mmi.c)
return MLT.value
gsm_ = numpy.asanyarray(gsm)
dt_ = numpy.asanyarray(dt)
if gsm_.ndim == 2:
if gsm_.shape[1] != 3:
raise(ValueError("Invalid vector shape"))
if gsm_.shape[0] != dt_.size:
if dt_.size == 1:
dt_ = dm.dmarray([dt_]*gsm_.shape[0])
else:
raise(ValueError("Array size mismatch"))
ans = dm.dmarray(numpy.empty(len(dt_)), dtype=numpy.double, attrs={'coord_system': 'EDMAG'})
for ii, (gsm_val, dt_val) in enumerate(itertools.izip(gsm_, dt_)):
ans[ii] = doConv(gsm_val, dt_val)
else:
ans = dm.dmarray(doConv(gsm_, dt_), attrs={'coord_system': 'EDMAG'})
return ans
ctypes.c_int(len(Alpha)),
np.require(Alpha, requirements=['C']).ctypes.data_as(ctypes.POINTER(ctypes.c_double)),
ctypes.c_int(Colorize), ctypes.pointer(MagEphemInfo) )
for ii, pa in enumerate(Alpha):
if int(pa) == pa:
pa = int(pa)
ans[pa] = dm.SpaceData()
ans[pa]['LHilton'] = MagEphemInfo.LHilton[ii]
ans[pa]['LMcIlwain'] = MagEphemInfo.LMcIlwain[ii]
ans[pa]['Lstar'] = MagEphemInfo.Lstar[ii]
# think in here, there are not owned by pyhton so there is no easy way to free the memory...
if extended_out:
ans[pa]['Bmin'] = dm.dmarray(np.zeros([MagEphemInfo.nShellPoints[ii], 3]))
ans[pa]['I'] = dm.dmarray(np.zeros([MagEphemInfo.nShellPoints[ii]]))
ans[pa]['Pmin'] = dm.dmarray(np.zeros([MagEphemInfo.nShellPoints[ii], 3]))
ans[pa]['Bmin'][:, 0] = [val.x for val in MagEphemInfo.Shell_Bmin[ii][0:MagEphemInfo.nShellPoints[ii]]]
ans[pa]['Bmin'][:, 1] = [val.y for val in MagEphemInfo.Shell_Bmin[ii][0:MagEphemInfo.nShellPoints[ii]]]
ans[pa]['Bmin'][:, 2] = [val.z for val in MagEphemInfo.Shell_Bmin[ii][0:MagEphemInfo.nShellPoints[ii]]]
ans[pa]['I'][:] = [val for val in MagEphemInfo.ShellI[ii][0:MagEphemInfo.nShellPoints[ii]]]
ans[pa]['Pmin'][:, 0] = [val.x for val in MagEphemInfo.Shell_Pmin[ii][0:MagEphemInfo.nShellPoints[ii]]]
ans[pa]['Pmin'][:, 1] = [val.y for val in MagEphemInfo.Shell_Pmin[ii][0:MagEphemInfo.nShellPoints[ii]]]
ans[pa]['Pmin'][:, 2] = [val.z for val in MagEphemInfo.Shell_Pmin[ii][0:MagEphemInfo.nShellPoints[ii]]]
return ans
R, MLat, MLon, MLT = c_double(), c_double(), c_double(), c_double(),
Lgm_EDMAG_to_R_MLAT_MLON_MLT( pointer(Pmlt), pointer(R), pointer(MLat), pointer(MLon),
pointer(MLT), mmi.c)
return MLT.value
gsm_ = numpy.asanyarray(gsm)
dt_ = numpy.asanyarray(dt)
if gsm_.ndim == 2:
if gsm_.shape[1] != 3:
raise(ValueError("Invalid vector shape"))
if gsm_.shape[0] != dt_.size:
if dt_.size == 1:
dt_ = dm.dmarray([dt_]*gsm_.shape[0])
else:
raise(ValueError("Array size mismatch"))
ans = dm.dmarray(numpy.empty(len(dt_)), dtype=numpy.double, attrs={'coord_system': 'EDMAG'})
for ii, (gsm_val, dt_val) in enumerate(itertools.izip(gsm_, dt_)):
ans[ii] = doConv(gsm_val, dt_val)
else:
ans = dm.dmarray(doConv(gsm_, dt_), attrs={'coord_system': 'EDMAG'})
return ans
Bmjunk = c_double()
Mjunk = c_double()
MagEphemInfo.LHilton.contents.value = Lgm_McIlwain_L(
MagEphemInfo.Date, MagEphemInfo.UTC, pointer(MagEphemInfo.P),
pa, 1, pointer(Ijunk), pointer(Bmjunk), pointer(Mjunk),
lstarinf.mInfo)
ans[pa]['LHilton'] = MagEphemInfo.LHilton.contents.value
MagEphemInfo.LMcIlwain.contents.value = Lgm_McIlwain_L(
MagEphemInfo.Date, MagEphemInfo.UTC, pointer(MagEphemInfo.P),
pa, 0, pointer(Ijunk), pointer(Bmjunk), pointer(Mjunk),
lstarinf.mInfo)
ans[pa]['LMcIlwain'] = MagEphemInfo.LMcIlwain.contents.value
if LS_Flag == -2: # mirror below southern hemisphere mirror alt
ans[pa]['Lstar'] = datamodel.dmarray([numpy.nan], attrs={'info':'S_LOSS'})
elif LS_Flag == -1: # mirror below northern hemisphere mirror alt
ans[pa]['Lstar'] = datamodel.dmarray([numpy.nan], attrs={'info':'N_LOSS'})
elif LS_Flag >= 0: # valid calc
ans[pa]['Lstar'] = datamodel.dmarray([lstarinf.LS], attrs={'info':'GOOD'}) # want better word?
MagEphemInfo.Lstar[i] = lstarinf.LS
# Save results to the MagEphemInfo structure.
MagEphemInfo.nShellPoints[i] = lstarinf.nPnts
## pull all this good extra info into numpy arrays
ans[pa]['I'] = datamodel.dmarray(lstarinf.I[0])
if extended_out:
ans[pa]['ShellI'] = \
datamodel.dmarray(numpy.ctypeslib.ndarray([len(lstarinf.I)],
dtype=c_double, buffer=lstarinf.I) ).copy()
ans[pa]['ShellEllipsoidFootprint_Pn'] = \
numpy.ctypeslib.ndarray(len(lstarinf.Ellipsoid_Footprint_Pn),
#make figure
fig = plt.figure(figsize=(17, 21))
#set up test runs
nvals, rvals = 5, [3,4,5,6]
dates = spt.tickrange('2001-04-22T12:00:00', '2001-04-22T12:01:00', dt.timedelta(seconds=5))
alpha = 45
print('T89: alpha=%s, date range [%s, %s]' % (alpha, dates.UTC[0], dates.UTC[-1]))
#loop over radial positions, dates and quality flags
for rval in rvals:
print('Radial Distance: %s' % rval)
Lstar = [[]]*nvals
for date, qual in itertools.product(dates.UTC, range(nvals)):
print('%s, Quality=%d' % (date, qual))
pos = dm.dmarray([-1*rval, 0, 0], attrs={'sys': 'GSM'})
data = lgmpy.get_Lstar(pos, date, alpha=alpha, coord_system='GSM', Bfield='Lgm_B_T89c', LstarThresh=20.0, extended_out=True, LstarQuality=qual)
try:
Lstar[qual].extend(data[alpha]['Lstar'])
except TypeError:
Lstar[qual].append(data[alpha]['Lstar'].tolist())
#make plots
fstr = '%d1%d' % (len(rvals), rval-rvals[0]+1)
ax = fig.add_subplot(fstr)
ax.boxplot(Lstar)
ax.set_title('T89 [-%d, 0, 0]$_{GSM}$; PA=%d$^{o}$' % (rval, alpha))
ax.set_ylabel('L* (LanlGeoMag)')
ax.set_xlabel('Quality Flag')
ax.set_xticklabels([str(n) for n in range(5)])
fig.savefig('lgm_T89_%d_zoom_5sec.png' % alpha, dpi=300)