NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/sodar/trunk/sodar/arrayData.py

Revision 81 (checked in by cbc, 17 years ago)

Saving work. show() throws numerix exception, though. Cutting tag on this changeset for debug demo puposes.

Exception (Using stock Enthon 1.0.0 on Win XP) looks like:

  File "C:\Python24\lib\site-packages\matplotlib\numerix\__init__.py", line 97, in angle
    return arctan2(a.imag, a.real)
ValueError: math domain error
Line 
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         rawDataHandle.close()
59     except:
60         raise IOError("Failure to read raw test data")
61     rawDataObject = rawData.RawData(rawDataString)
62     formattedDataObject = formattedData.FormattedData(rawDataObject)
63     arrayDataObject = ArrayData(formattedDataObject)
64     import pylab as p
65     p.figure()
66     p.quiver(arrayDataObject.uComponents, arrayDataObject.vComponents)
67     p.show()
68
69 if __name__ == "__main__":
70     _main()
Note: See TracBrowser for help on using the browser.