1 |
#!/usr/bin/python |
---|
2 |
""" |
---|
3 |
Module to handle sodar data samples as arrays. |
---|
4 |
""" |
---|
5 |
|
---|
6 |
__author__ = 'Chris Calloway' |
---|
7 |
__email__ = 'cbc@unc.edu' |
---|
8 |
__copyright__ = 'Copyright 2007 UNC-CH Department of Marine Science' |
---|
9 |
__license__ = 'GPL2' |
---|
10 |
|
---|
11 |
import rawData |
---|
12 |
import formattedData |
---|
13 |
import numpy as n |
---|
14 |
import datetime |
---|
15 |
|
---|
16 |
class ArrayData(object): |
---|
17 |
|
---|
18 |
"""Class to handle Daily sodar file data as arrays.""" |
---|
19 |
|
---|
20 |
def __init__(self, data): |
---|
21 |
"""Create arrays from formatted data.""" |
---|
22 |
super(ArrayData, self).__init__() |
---|
23 |
self.beginStamp = data.beginStamp |
---|
24 |
self.endStamp = data.endStamp |
---|
25 |
self.numIntervals = data.numIntervals |
---|
26 |
self.timeInterval = data.timeInterval |
---|
27 |
self.altInterval = data.altInterval |
---|
28 |
self.numAltitudes = data.numAltitudes |
---|
29 |
self.minAltitude = data.minAltitude |
---|
30 |
self.maxAltitude = data.maxAltitude |
---|
31 |
self._thetas(data) |
---|
32 |
self._uComponents(data) |
---|
33 |
self._vComponents(data) |
---|
34 |
self._wComponents(data) |
---|
35 |
self._echoStrengths(data) |
---|
36 |
|
---|
37 |
def _thetas(self, data): |
---|
38 |
"""Convert direction to polar azimuth in radians CW from North""" |
---|
39 |
self.thetas = n.pi * (n.array(data.thetas()) / 180.0) |
---|
40 |
|
---|
41 |
def _uComponents(self,data): |
---|
42 |
"""Compute u component array""" |
---|
43 |
self.uComponents = n.array(data.radials()) * n.sin(self.thetas) |
---|
44 |
|
---|
45 |
def _vComponents(self,data): |
---|
46 |
"""Compute v component array""" |
---|
47 |
self.vComponents = n.array(data.radials()) * n.cos(self.thetas) |
---|
48 |
|
---|
49 |
def _wComponents(self,data): |
---|
50 |
"""Create w component array""" |
---|
51 |
self.wComponents = n.array(data.wComponents()) |
---|
52 |
|
---|
53 |
def _echoStrengths(self,data): |
---|
54 |
"""Create an echo strength array""" |
---|
55 |
self.echoStrengths = n.array(data.echoStrengths()) |
---|
56 |
|
---|
57 |
|
---|
58 |
def _main(): |
---|
59 |
"""Process as script from command line.""" |
---|
60 |
import urllib2 |
---|
61 |
try: |
---|
62 |
rawDataHandle = urllib2.urlopen('http://nemo.isis.unc.edu/'\ |
---|
63 |
'data/nccoos/level0/ims/sodar/'\ |
---|
64 |
'2008_01/20080101.dat') |
---|
65 |
rawDataString = rawDataHandle.read() |
---|
66 |
rawDataHandle.close() |
---|
67 |
except: |
---|
68 |
raise IOError("Failure to read raw test data") |
---|
69 |
rawDataObject = rawData.RawData(rawDataString) |
---|
70 |
formattedDataObject = formattedData.FormattedData(rawDataObject) |
---|
71 |
arrayDataObject = ArrayData(formattedDataObject) |
---|
72 |
|
---|
73 |
import pylab as p |
---|
74 |
|
---|
75 |
home = '/var/www/html/sodar/plots/' |
---|
76 |
|
---|
77 |
fig = p.figure() |
---|
78 |
p.pcolor(arrayDataObject.uComponents.T) |
---|
79 |
p.colorbar() |
---|
80 |
fig.savefig(home + 'uComponents.png') |
---|
81 |
|
---|
82 |
fig = p.figure() |
---|
83 |
p.pcolor(arrayDataObject.vComponents.T) |
---|
84 |
p.colorbar() |
---|
85 |
fig.savefig(home + 'vComponents.png') |
---|
86 |
|
---|
87 |
fig = p.figure() |
---|
88 |
p.pcolor(arrayDataObject.wComponents.T) |
---|
89 |
p.colorbar() |
---|
90 |
fig.savefig(home + 'wComponents.png') |
---|
91 |
|
---|
92 |
fig = p.figure() |
---|
93 |
p.pcolor(arrayDataObject.echoStrengths.T) |
---|
94 |
p.colorbar() |
---|
95 |
fig.savefig(home + 'echoStrengths.png') |
---|
96 |
|
---|
97 |
fig = p.figure() |
---|
98 |
p.quiver(arrayDataObject.uComponents, |
---|
99 |
arrayDataObject.vComponents, |
---|
100 |
arrayDataObject.wComponents) |
---|
101 |
p.colorbar() |
---|
102 |
xmin,xmax,ymin,ymax = p.axis() |
---|
103 |
dx,dy = xmax-xmin, ymax-ymin |
---|
104 |
p.axis([xmin-0.1*dx, xmax+0.1*dx, ymin-0.1*dy, ymax+0.1*dy]) |
---|
105 |
p.title('Horizontal wind vectors: time vs. altitude') |
---|
106 |
fig.savefig(home + 'quiver.png') |
---|
107 |
|
---|
108 |
if __name__ == "__main__": |
---|
109 |
_main() |
---|