How to use the spacepy.time function in spacepy

To help you get started, we’ve selected a few spacepy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github drsteve / LANLGeoMag / Python / scripts / lgm_dipole_verify.py View on Github external
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}$')
github drsteve / LANLGeoMag / Python / scripts / lgm_T89_verify.py View on Github external
from __future__ import division
import matplotlib.pyplot as plt
import itertools
import datetime as dt
import lgmpy, copy
import spacepy.time as spt
import spacepy.datamodel as dm
import spacepy.toolbox as tb

#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