Exemplo n.º 1
0
 def test_logspace(self):
     """logspace should return know answer for known input"""
     try:
         from matplotlib.dates import date2num
     except ImportError: # just pass if matplotlib is not installed
         return
     real_ans = array([   1.        ,    3.16227766,   10.        ,   31.6227766 ,  100.        ])
     numpy.testing.assert_almost_equal(real_ans, tb.logspace(1, 100, 5) , 4)
     t1 = datetime.datetime(2000, 1, 1)
     t2 = datetime.datetime(2000, 1, 2)
     real_ans = [datetime.datetime(1999, 12, 31, 23, 59, 59, 999989),
         datetime.datetime(2000, 1, 1, 2, 39, 59, 994207),
         datetime.datetime(2000, 1, 1, 5, 19, 59, 989762),
         datetime.datetime(2000, 1, 1, 7, 59, 59, 986897),
         datetime.datetime(2000, 1, 1, 10, 39, 59, 985369),
         datetime.datetime(2000, 1, 1, 13, 19, 59, 985431),
         datetime.datetime(2000, 1, 1, 15, 59, 59, 986830),
         datetime.datetime(2000, 1, 1, 18, 39, 59, 989808),
         datetime.datetime(2000, 1, 1, 21, 19, 59, 994124),
         datetime.datetime(2000, 1, 2, 0, 0, 0, 30)]
     ans = tb.logspace(t1, t2, 10)
     numpy.testing.assert_almost_equal(date2num(real_ans), date2num(ans) , 4)
Exemplo n.º 2
0
 def test_logspace(self):
     """logspace should return know answer for known input"""
     try:
         from matplotlib.dates import date2num
     except ImportError: # just pass if matplotlib is not installed
         return
     real_ans = array([   1.        ,    3.16227766,   10.        ,   31.6227766 ,  100.        ])
     numpy.testing.assert_almost_equal(real_ans, tb.logspace(1, 100, 5) , 4)
     t1 = datetime.datetime(2000, 1, 1)
     t2 = datetime.datetime(2000, 1, 2)
     real_ans = [datetime.datetime(1999, 12, 31, 23, 59, 59, 999989),
         datetime.datetime(2000, 1, 1, 2, 39, 59, 994207),
         datetime.datetime(2000, 1, 1, 5, 19, 59, 989762),
         datetime.datetime(2000, 1, 1, 7, 59, 59, 986897),
         datetime.datetime(2000, 1, 1, 10, 39, 59, 985369),
         datetime.datetime(2000, 1, 1, 13, 19, 59, 985431),
         datetime.datetime(2000, 1, 1, 15, 59, 59, 986830),
         datetime.datetime(2000, 1, 1, 18, 39, 59, 989808),
         datetime.datetime(2000, 1, 1, 21, 19, 59, 994124),
         datetime.datetime(2000, 1, 2, 0, 0, 0, 30)]
     ans = tb.logspace(t1, t2, 10)
     numpy.testing.assert_almost_equal(date2num(real_ans), date2num(ans) , 4)
Exemplo n.º 3
0
def getSolarProtonSpectra(norm=3.20e7,
                          gamma=-0.96,
                          E0=15.0,
                          Emin=.1,
                          Emax=600,
                          nsteps=100):
    '''Returns a SpaceData with energy and fluence spectra of solar particle events

    The formulation follows that of:
    Ellison and Ramaty ApJ 298: 400-408, 1985
    dJ/dE = K^{-\gamma}exp(-E/E0)
    
    and the defualt values are the 10/16/2003 SEP event of:
    Mewaldt, R. A., et al. (2005), J. Geophys. Res., 110, A09S18, doi:10.1029/2005JA011038.

    Other Parameters
    ================
    norm : float
        Normilization factor for the intensity of the SEP event
    gamma : float
        Power law index
    E0 : float
        Expoential scaling factor
    Emin : float
        Minimum energy for fit
    Emax : float
        Maximum energy for fit
    nsteps : int
        The number of log spaced energy steps to return
        
    Returns
    =======
    data : dm.SpaceData
        SpaceData with the energy and fluence values
    '''
    E = tb.logspace(Emin, Emax, nsteps)
    fluence = norm * E**(gamma) * np.exp(-E / E0)
    ans = dm.SpaceData()
    ans['Energy'] = dm.dmarray(E)
    ans['Energy'].attrs = {
        'UNITS': 'MeV',
        'DESCRIPTION': 'Particle energy per nucleon'
    }
    ans['Fluence'] = dm.dmarray(fluence)
    ans['Fluence'].attrs = {
        'UNITS': 'cm^{-2} sr^{-1} (MeV/nuc)^{-1}',
        'DESCRIPTION': 'Fluence spectra fir to the model'
    }
    return ans
Exemplo n.º 4
0
def getSolarProtonSpectra(norm=3.20e7, gamma=-0.96, E0=15.0, Emin=.1, Emax=600, nsteps=100):
    '''Returns a SpaceData with energy and fluence spectra of solar particle events

    The formulation follows that of:
    Ellison and Ramaty ApJ 298: 400-408, 1985
    dJ/dE = K^{-\gamma}exp(-E/E0)
    
    and the defualt values are the 10/16/2003 SEP event of:
    Mewaldt, R. A., et al. (2005), J. Geophys. Res., 110, A09S18, doi:10.1029/2005JA011038.

    Other Parameters
    ==========
    norm : float
        Normilization factor for the intensity of the SEP event
    gamma : float
        Power law index
    E0 : float
        Expoential scaling factor
    Emin : float
        Minimum energy for fit
    Emax : float
        Maximum energy for fit
    nsteps : int
        The number of log spaced energy steps to return
        
    Returns
    =======
    data : dm.SpaceData
        SpaceData with the energy and fluence values
    '''
    E = tb.logspace(Emin, Emax, nsteps)
    fluence = norm*E**(gamma)*np.exp(-E/E0)
    ans = dm.SpaceData()
    ans['Energy'] = dm.dmarray(E)
    ans['Energy'].attrs = {'UNITS':'MeV',
                           'DESCRIPTION':'Particle energy per nucleon'}
    ans['Fluence'] = dm.dmarray(fluence)
    ans['Fluence'].attrs = {'UNITS' : 'cm^{-2} sr^{-1} (MeV/nuc)^{-1}',
                            'DESCRIPTION':'Fluence spectra fir to the model'}
    return ans
Exemplo n.º 5
0
    #    ans = np.sqrt(np.inner(data[0:n], data[0:n]))
    ans = np.sqrt(np.inner(data, data))


def extension_t(n, data):
    #    ans = tb.hypot(data[0:n])
    ans = tb.hypot(data)


ans = {}
ans['ctypes_t'] = []
ans['python_t'] = []
ans['numpy_t'] = []
ans['extension_t'] = []

for loop in tb.logspace(3, max_size, 20):
    print "loop", loop
    for bm in Benchmarker(width=25, cycle=5, extra=1):
        data = np.arange(1, loop, dtype=ctypes.c_double)
        bm.run(ctypes_t, loop, data)
        bm.run(python_t, loop, data)
        bm.run(numpy_t, loop, data)
        bm.run(extension_t, loop, data)
    for result in bm.results:
        ans[result.label].append((loop, result.real))

#==============================================================================
# plot up the times
#==============================================================================
plt.figure()
for key in ans:
Exemplo n.º 6
0
max_size = 1e6
date_data = np.arange(1, max_size , dtype=np.float)
date_data = np.asarray([datetime.datetime(2000, 1, 1) + datetime.timedelta(minutes=v) for v in date_data])

def date2num_mpl(data):
    ans = mpl_stock_date2num(data)

def date2num_spt(data):
    tt = spt.Ticktock(data)
    ans = tt.JD - 1721424.5

ans = {}
ans['date2num_mpl'] = []
ans['date2num_spt'] = []

for loop in tb.logspace(1, max_size, 20):
    print "loop", loop
    for bm in Benchmarker(width=25, cycle=5, extra=1):
        data = date_data[:loop]
        bm.run(date2num_mpl, data)
        bm.run(date2num_spt, data)
    for result in bm.results:
        ans[result.label].append((loop, result.real))

#==============================================================================
# plot up the times
#==============================================================================
plt.figure()
for key in ans:
    plt.loglog(zip(*ans[key])[0], zip(*ans[key])[1],'o-',  label=key[:-2], lw=2 )