Index: sodar/trunk/sodar.py =================================================================== --- sodar/trunk/sodar.py (revision 133) +++ sodar/trunk/sodar.py (revision 134) @@ -4,62 +4,70 @@ """ +import optparse +from sodar.utils import openAnything, findMissing +from sodar import arrayData as a +import pylab as p +import os + +def processSingle(filein, pathout): + if not os.path.exists(pathout): + os.makedirs(pathout, mode=0775) + + try: + rawDataHandle = openAnything.openAnything(filein) + rawDataString = rawDataHandle.read() + rawDataHandle.close() + except: + raise IOError("Failure to read raw data.") + + rawDataObject = a.rawData.RawData(rawDataString) + formattedDataObject = a.formattedData.FormattedData(rawDataObject) + arrayDataObject = a.ArrayData(formattedDataObject) + + fig = p.figure() + p.pcolor(arrayDataObject.uComponents.T) + p.colorbar() + fig.savefig(os.path.join(pathout, 'uComponents.png')) + + fig = p.figure() + p.pcolor(arrayDataObject.vComponents.T) + p.colorbar() + fig.savefig(os.path.join(pathout, 'vComponents.png')) + + fig = p.figure() + p.pcolor(arrayDataObject.wComponents.T) + p.colorbar() + fig.savefig(os.path.join(pathout, 'wComponents.png')) + + fig = p.figure() + p.pcolor(arrayDataObject.echoStrengths.T) + p.colorbar() + fig.savefig(os.path.join(pathout, 'echoStrengths.png')) + + fig = p.figure() + p.quiver(arrayDataObject.uComponents, + arrayDataObject.vComponents, + arrayDataObject.wComponents) + p.colorbar() + xmin,xmax,ymin,ymax = p.axis() + dx,dy = xmax-xmin, ymax-ymin + p.axis([xmin-0.1*dx, xmax+0.1*dx, ymin-0.1*dy, ymax+0.1*dy]) + p.title('Horizontal wind vectors: time vs. altitude') + fig.savefig(os.path.join(pathout, 'quiver.png')) + return 0 + +def processAll(source, destination): + walkList = findMissing.findMissing(source, destination) + + for filein, pathout in walkList: + processSingle(filein, pathout) + return 0 + def _main(): - import optparse - from sodar.utils import openAnything, findMissing - from sodar import arrayData as a - import pylab as p - import os - parser = optparse.OptionParser() (values, args) = parser.parse_args() (source, destination) = tuple(args) - - walkList = findMissing.findMissing(source, destination) - - for filein, pathout in walkList: - if not os.path.exists(pathout): - os.makedirs(pathout, mode=0775) - - try: - rawDataHandle = openAnything.openAnything(filein) - rawDataString = rawDataHandle.read() - rawDataHandle.close() - except: - raise IOError("Failure to read raw data.") - - rawDataObject = a.rawData.RawData(rawDataString) - formattedDataObject = a.formattedData.FormattedData(rawDataObject) - arrayDataObject = a.ArrayData(formattedDataObject) - - fig = p.figure() - p.pcolor(arrayDataObject.uComponents.T) - p.colorbar() - fig.savefig(os.path.join(pathout, 'uComponents.png')) - - fig = p.figure() - p.pcolor(arrayDataObject.vComponents.T) - p.colorbar() - fig.savefig(os.path.join(pathout, 'vComponents.png')) - - fig = p.figure() - p.pcolor(arrayDataObject.wComponents.T) - p.colorbar() - fig.savefig(os.path.join(pathout, 'wComponents.png')) - - fig = p.figure() - p.pcolor(arrayDataObject.echoStrengths.T) - p.colorbar() - fig.savefig(os.path.join(pathout, 'echoStrengths.png')) - - fig = p.figure() - p.quiver(arrayDataObject.uComponents, - arrayDataObject.vComponents, - arrayDataObject.wComponents) - p.colorbar() - xmin,xmax,ymin,ymax = p.axis() - dx,dy = xmax-xmin, ymax-ymin - p.axis([xmin-0.1*dx, xmax+0.1*dx, ymin-0.1*dy, ymax+0.1*dy]) - p.title('Horizontal wind vectors: time vs. altitude') - fig.savefig(os.path.join(pathout, 'quiver.png')) + processAll(source, destination) + return 0 if __name__ == "__main__":