1 |
|
---|
2 |
""" |
---|
3 |
Module to process sodar data. |
---|
4 |
""" |
---|
5 |
|
---|
6 |
import optparse |
---|
7 |
from sodar.utils import openAnything, findMissing |
---|
8 |
from sodar import arrayData as a |
---|
9 |
import pylab as p |
---|
10 |
import os |
---|
11 |
|
---|
12 |
def plotSingle(filein, pathout): |
---|
13 |
""" |
---|
14 |
Plot singe sodar raw data file. |
---|
15 |
|
---|
16 |
plotSingle(filein, pathout) -> rc |
---|
17 |
|
---|
18 |
filein - path to raw data file. |
---|
19 |
fileout - path to plot images directory. |
---|
20 |
rc - 0 if successful |
---|
21 |
""" |
---|
22 |
|
---|
23 |
walkList = findMissing.findMissing(source, destination) |
---|
24 |
if not os.path.exists(pathout): |
---|
25 |
os.makedirs(pathout, mode=0775) |
---|
26 |
|
---|
27 |
try: |
---|
28 |
rawDataHandle = openAnything.openAnything(filein) |
---|
29 |
rawDataString = rawDataHandle.read() |
---|
30 |
rawDataHandle.close() |
---|
31 |
except: |
---|
32 |
raise IOError("Failure to read raw data.") |
---|
33 |
|
---|
34 |
rawDataObject = a.rawData.RawData(rawDataString) |
---|
35 |
formattedDataObject = a.formattedData.FormattedData(rawDataObject) |
---|
36 |
arrayDataObject = a.ArrayData(formattedDataObject) |
---|
37 |
|
---|
38 |
fig = p.figure() |
---|
39 |
p.pcolor(arrayDataObject.uComponents.T) |
---|
40 |
p.colorbar() |
---|
41 |
fig.savefig(os.path.join(pathout, 'uComponents.png')) |
---|
42 |
|
---|
43 |
fig = p.figure() |
---|
44 |
p.pcolor(arrayDataObject.vComponents.T) |
---|
45 |
p.colorbar() |
---|
46 |
fig.savefig(os.path.join(pathout, 'vComponents.png')) |
---|
47 |
|
---|
48 |
fig = p.figure() |
---|
49 |
p.pcolor(arrayDataObject.wComponents.T) |
---|
50 |
p.colorbar() |
---|
51 |
fig.savefig(os.path.join(pathout, 'wComponents.png')) |
---|
52 |
|
---|
53 |
fig = p.figure() |
---|
54 |
p.pcolor(arrayDataObject.echoStrengths.T) |
---|
55 |
p.colorbar() |
---|
56 |
fig.savefig(os.path.join(pathout, 'echoStrengths.png')) |
---|
57 |
|
---|
58 |
fig = p.figure() |
---|
59 |
p.quiver(arrayDataObject.uComponents, |
---|
60 |
arrayDataObject.vComponents, |
---|
61 |
arrayDataObject.wComponents) |
---|
62 |
p.colorbar() |
---|
63 |
xmin,xmax,ymin,ymax = p.axis() |
---|
64 |
dx,dy = xmax-xmin, ymax-ymin |
---|
65 |
p.axis([xmin-0.1*dx, xmax+0.1*dx, ymin-0.1*dy, ymax+0.1*dy]) |
---|
66 |
p.title('Horizontal wind vectors: time vs. altitude') |
---|
67 |
fig.savefig(os.path.join(pathout, 'quiver.png')) |
---|
68 |
return 0 |
---|
69 |
|
---|
70 |
def plotAll(source, destination): |
---|
71 |
""" |
---|
72 |
Plot all sodar raw data files. |
---|
73 |
|
---|
74 |
plotAll(source, destination) -> rc |
---|
75 |
|
---|
76 |
source - path to raw data directory in NCCOOS format. |
---|
77 |
detination - path to plot images directory in NCCOOS format. |
---|
78 |
rc - 0 if successful |
---|
79 |
""" |
---|
80 |
|
---|
81 |
walkList = findMissing.findMissing(source, destination) |
---|
82 |
|
---|
83 |
for filein, pathout in walkList: |
---|
84 |
plotSingle(filein, pathout) |
---|
85 |
return 0 |
---|
86 |
|
---|
87 |
def _main(): |
---|
88 |
"""bin/python %prog [options] /path/to/raw/files/ /path/to/plots/dir/""" |
---|
89 |
|
---|
90 |
__description__ = 'Plot all sodar raw data files.' |
---|
91 |
|
---|
92 |
parser = optparse.OptionParser(usage=_main.__doc__, |
---|
93 |
version='1.0', |
---|
94 |
description=__description__) |
---|
95 |
(values, args) = parser.parse_args() |
---|
96 |
(source, destination) = tuple(args) |
---|
97 |
plotAll(source, destination) |
---|
98 |
return 0 |
---|
99 |
|
---|
100 |
if __name__ == "__main__": |
---|
101 |
_main() |
---|