Example #1
0
f.write('# Ligne de commentaire\n')
for it in xrange(len(temp)):
    t = strftime('%Y/%m/%dZ%H:%M',  ctime[it])
    f.write('%s %.4f %f %f\n' % (t, temp[it], u[it], v[it]))
f.close()
# => Practice: Read just a small part of the file (10 last lines and/or 10 first lines)

# Quick check (two first lines)
f = open('misc.io.ascii.1.dat')
print ''.join(f.readlines()[:3])
f.close()

# Quick writing using Numpy
# - Creation
time_units = 'hours since %s'%ctime[0]
newtime = ch_units(time, time_units)[:]
data = N.array([newtime,temp.filled(999.), 
    u.filled(999.), v.filled(999.)],copy=0)
f = open('misc.io.ascii.2.dat', 'w')
f.write('# Ligne de commentaire\n')
N.savetxt(f, data.transpose(), fmt='%.3f', delimiter='\t')
#   Note : we can enter f or the file name in N.savetxt()
# - Check
f = open('misc.io.ascii.2.dat')
print ''.join(f.readlines()[:2])
f.close()

# Advanced reading
# - Time converter
def convtime(s):
    return strptime(s, '%Y/%m/%dZ%H:%M').torel(time_units).value
Example #2
0
print are_valid_units(units)
#  -> True

# Same units?
print are_same_units('hours since 2000-1-15 06', units)
#  -> True

# Change axis time units
taxis = create_time(N.arange(6.) * 48, units)
# - before
print taxis.units, taxis[0:2]
print taxis.asComponentTime()[0:2]
#  -> hours since 2000-01-15 06:00 [  0.  48.]
#  -> [2000-1-15 6:0:0.0, 2000-1-17 6:0:0.0]
# - change
ch_units(taxis, 'days since 2000-1-15 06', copy=0)
# - after
print taxis.units, taxis[0:2]
print taxis.asComponentTime()[0:2]
#  -> days since 2000-1-15 06 [ 0.  2.]
#  -> [2000-1-15 6:0:0.0, 2000-1-17 6:0:0.0]

# Matplotlib times
taxis_mpl = mpl(taxis)
print taxis_mpl[0], taxis_mpl.units
#  -> 730134.25 days since 0001

# Change the time units of a variable
import MV2

var = MV2.array(MV2.arange(len(taxis)), dtype='f', axes=[taxis])
Example #3
0
print are_valid_units(units)
#  -> True

# Same units?
print are_same_units('hours since 2000-1-15 06', units)
#  -> True

# Change axis time units
taxis = create_time(N.arange(6.)*48, units)
# - before
print taxis.units, taxis[0:2]
print taxis.asComponentTime()[0:2]
#  -> hours since 2000-01-15 06:00 [  0.  48.]
#  -> [2000-1-15 6:0:0.0, 2000-1-17 6:0:0.0]
# - change
ch_units(taxis, 'days since 2000-1-15 06', copy=0)
# - after
print taxis.units, taxis[0:2]
print taxis.asComponentTime()[0:2]
#  -> days since 2000-1-15 06 [ 0.  2.]
#  -> [2000-1-15 6:0:0.0, 2000-1-17 6:0:0.0]

# Matplotlib times
taxis_mpl = mpl(taxis)
print taxis_mpl[0], taxis_mpl.units
#  -> 730134.25 days since 0001

# Change the time units of a variable
import MV2
var = MV2.array(MV2.arange(len(taxis)), dtype='f', axes=[taxis])
ch_units(var, 'hours since 2000-01-15 06')
Example #4
0
# We choose the french language
import locale
locale.setlocale(locale.LC_ALL, 'fr_FR')

# Write in a different format
print strftime('%e %B %Y a %Hh%M',
               mytime)  # => Practice: Try different formats

# ---- Time axes ----
print 10 * '-' + ' Time axes ' + 10 * '-'
units = 'hours since 2000-01-15 06:00'
taxis = create_time(N.arange(6.) * 48, units)
print taxis.getValue()
print 'Units before change: ', taxis.units
# - change units
ch_units(taxis, 'days since 2000-1-15 06:00', copy=0)
print taxis.getValue()
print 'Units after change: ', taxis.units

# ------------------------------------------------------------------------------------------------------------
# ---- lindates ----
print 10 * '-' + ' lindates ' + 10 * '-'
dates = lindates('2000', '2002-05', 3, 'months')
print dates
# => Practice: Try different arguments.

# ---- Intervals ----
print 10 * '-' + ' Intervals ' + 10 * '-'
for itv in Intervals(('2000', '2001', 'co'), (2, 'month')):
    print itv  # => Practice: try different Intervals (2 days, 2 hours)
print '-- List ...'
Example #5
0
# We choose the french language 
import locale
locale.setlocale(locale.LC_ALL,'fr_FR')

# Write in a different format
print strftime('%e %B %Y a %Hh%M',mytime) # => Practice: Try different formats

# ---- Time axes ---- 
print 10*'-'+' Time axes '+10*'-'
units = 'hours since 2000-01-15 06:00'
taxis = create_time(N.arange(6.)*48, units)
print taxis.getValue()
print 'Units before change: ',taxis.units
# - change units
ch_units(taxis, 'days since 2000-1-15 06:00', copy=0)
print taxis.getValue()
print 'Units after change: ',taxis.units

# ------------------------------------------------------------------------------------------------------------
# ---- lindates ----
print 10*'-'+' lindates '+10*'-'
dates = lindates('2000', '2002-05', 3, 'months')
print dates
# => Practice: Try different arguments.

# ---- Intervals ----
print 10*'-'+' Intervals '+10*'-'
for itv in Intervals(('2000','2001','co'),(2,'month')): print itv # => Practice: try different Intervals (2 days, 2 hours)
print '-- List ...'
print Intervals(('2000','2001','co'),12).tolist()