Menu

[r7886]: / trunk / py4science / examples / recarray / recarr_simple.py  Maximize  Restore  History

Download this file

44 lines (33 with data), 1.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Utility module to load measurements into Numpy record arrays.
Loading measurement files with the format:
#Station Lat Long Elev
BIRA 26.4840 87.2670 0.0120
BUNG 27.8771 85.8909 1.1910
etc...
"""
import numpy as np
import pylab as plt
# Simple example of usage
# Data descriptor to make a proper array.
dt = [('station','S4'),('lat',np.float32),('lon',np.float32),
('elev',np.float32)]
# This is an alternate and fully equivalent form:
dt = dict(names = ('station','lat','lon','elev'),
formats = ('S4',np.float32,np.float32,np.float32) )
# For more on dtypes, see:
# http://mentat.za.net/numpy/refguide/arrays.recarray.xhtml
import math
def tlog(s):
return np.float32(math.log(float(s)))
tab = np.loadtxt('HIMNTstations2.txt',dt,
converters={1:tlog})
print 'Stations:',tab['station']
print 'Elevations:',tab['elev']
print 'First station:',tab[0]
print 'Mean latitude:',tab['lat'].mean()
plt.figure()
plt.scatter(tab['lat'],tab['lon'],30*tab['elev'],
c=tab['elev'],
cmap=plt.cm.bone,
)
plt.show()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.