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.timeInterval = data.timeInterval |
---|
24 |
self.altInterval = data.altInterval |
---|
25 |
self.numAltitudes = data.numAltitudes |
---|
26 |
self.minAltitude = data.minAltitude |
---|
27 |
self.maxAltitude = data.maxAltitude |
---|
28 |
self._thetas(data) |
---|
29 |
self._uComponents(data) |
---|
30 |
self._vComponents(data) |
---|
31 |
self._wComponents(data) |
---|
32 |
|
---|
33 |
def _thetas(self, data): |
---|
34 |
"""Convert direction to polar azimuth in radians CW from North""" |
---|
35 |
self.thetas = n.pi * (n.array(data.thetas()) / 180) |
---|
36 |
|
---|
37 |
def _uComponents(self,data): |
---|
38 |
"""Compute u component array""" |
---|
39 |
self.uComponents = n.array(data.radials()) * n.cos(self.thetas) |
---|
40 |
|
---|
41 |
def _vComponents(self,data): |
---|
42 |
"""Compute v component array""" |
---|
43 |
self.vComponents = n.array(data.radials()) * n.sin(self.thetas) |
---|
44 |
|
---|
45 |
def _wComponents(self,data): |
---|
46 |
"""Create w component array""" |
---|
47 |
self.wComponents = n.array(data.wComponents()) |
---|
48 |
|
---|
49 |
|
---|
50 |
def _main(): |
---|
51 |
"""Process as script from command line.""" |
---|
52 |
import urllib2 |
---|
53 |
try: |
---|
54 |
rawDataHandle = urllib2.urlopen('http://nemo.isis.unc.edu/'\ |
---|
55 |
'data/nccoos/level0/dukeforest/sodar/'\ |
---|
56 |
'store/2007-06/20070601.dat') |
---|
57 |
rawDataString = rawDataHandle.read() |
---|
58 |
except: |
---|
59 |
raise IOError("Failure to read raw test data") |
---|
60 |
rawDataObject = rawData.RawData(rawDataString) |
---|
61 |
formattedDataObject = formattedData.FormattedData(rawDataObject) |
---|
62 |
arrayDataObject = ArrayData(formattedDataObject) |
---|
63 |
print arrayDataObject.thetas |
---|
64 |
print arrayDataObject.uComponents |
---|
65 |
print arrayDataObject.vComponents |
---|
66 |
print arrayDataObject.wComponents |
---|
67 |
|
---|
68 |
if __name__ == "__main__": |
---|
69 |
_main() |
---|