Index: sodar/trunk/plotSodar.py =================================================================== --- sodar/trunk/plotSodar.py (revision 142) +++ sodar/trunk/plotSodar.py (revision 148) @@ -13,10 +13,10 @@ def plotSingle(filein, pathout): """ - Plot singe sodar raw data file. + Plot single sodar raw data file. plotSingle(filein, pathout) -> rc filein - path to raw data file. - fileout - path to plot images directory. + pathout - path to plot images directory. rc - 0 if successful """ @@ -145,5 +145,140 @@ return 0 -def plotAll(source, destination, force): + +def plotLatest(filein, pathout): + """ + Plot latest sodar raw data file. + + plotLatest(filein, pathout) -> rc + + filein - path to raw data file. + pathout - path to plot images directory. + rc - 0 if successful + """ + + 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) + + beginStamp = arrayDataObject.beginStamp + endStamp = arrayDataObject.endStamp + numIntervals = arrayDataObject.numIntervals + timeInterval = arrayDataObject.timeInterval + minAltitude = arrayDataObject.minAltitude + numAltitudes = arrayDataObject.numAltitudes + altInterval = arrayDataObject.altInterval + + def makePcolor(vector, title, fileout, cbLabel): + fig = p.figure(1) + axe = fig.add_subplot(1, 1, 1) + pc = axe.pcolor(vector) + + axe.set_xlabel('Time (hh:mm UTC)') + axe.set_ylabel('Altitude (m)') + axe.set_xbound(upper=numIntervals) + + xticks = axe.get_xticks() + xticklabels = [(int(x) * timeInterval) + beginStamp + for x in xticks] + xticklabels = [':'.join(('%02u' % x.hour, '%02u' % x.minute)) + for x in xticklabels] + axe.set_xticklabels(xticklabels) + + yticks = axe.get_yticks() + yticklabels = [str(y * altInterval + minAltitude) + for y in yticks] + axe.set_yticklabels(yticklabels) + + axe.set_title(title) + cb = p.colorbar(pc) + cb.set_label(cbLabel) + + fig.savefig(os.path.join(pathout, fileout)) + fig.clear() + + return 0 + + uComponents = arrayDataObject.uComponents + maskedUComponents = n.ma.masked_where(n.isnan(uComponents), + uComponents) + makePcolor(maskedUComponents.T, + 'U Component of Wind Veloctiy for %s' % + (str(beginStamp)[:10],), + 'ims_sodar_latest_uComponents.png', + 'Speed (cm/sec)') + + vComponents = arrayDataObject.vComponents + maskedVComponents = n.ma.masked_where(n.isnan(vComponents), + vComponents) + makePcolor(maskedVComponents.T, + 'V Component of Wind Veloctiy for %s' % + (str(beginStamp)[:10],), + 'ims_sodar_latest_vComponents.png', + 'Speed (cm/sec)') + + wComponents = arrayDataObject.wComponents + maskedWComponents = n.ma.masked_where(n.isnan(wComponents), + wComponents) + makePcolor(maskedWComponents.T, + 'W Component of Wind Veloctiy for %s' % + (str(beginStamp)[:10],), + 'ims_sodar_latest_wComponents.png', + 'Speed (cm/sec)') + + echoStrengths = arrayDataObject.echoStrengths + maskedEchoStrenths = n.ma.masked_where(n.isnan(echoStrengths), + echoStrengths) + makePcolor(maskedEchoStrenths.T, + 'Echo Strength for %s' % + (str(beginStamp)[:10],), + 'ims_sodar_latest_echoStrengths.png', + 'Strength (no units)') + + # timeComponent = n.array(range(numIntervals)) + # altComponent = n.array(range(numAltitudes)) + # fig = p.figure(1) + # axe = fig.add_subplot(1, 1, 1) + # qv = axe.quiver(altComponent, + # timeComponent, + # maskedUComponents.T, + # maskedVComponents.T) + + # axe.set_xlabel('Time (min)') + # axe.set_ylabel('Altitude (m)') + # axe.set_xbound(upper=numIntervals) + + # xticks = axe.get_xticks() + # xticklabels = [(int(x) * timeInterval) + beginStamp + # for x in xticks] + # xticklabels = [':'.join(('%02u' % x.hour, '%02u' % x.minute)) + # for x in xticklabels] + # axe.set_xticklabels(xticklabels) + + # yticks = axe.get_yticks() + # yticklabels = [str(y * altInterval + minAltitude) + # for y in yticks] + # axe.set_yticklabels(yticklabels) + + # axe.set_title('Wind Velocty for %s' % + # (str(beginStamp)[:10],)) + # cb = p.colorbar(qv) + # cb.set_label('W Component Speed (cm/sec)') + + # fig.savefig(os.path.join(pathout, 'ims_sodar_latest_quiver.png')) + # fig.clear() + + return 0 + +def plotAll(source, destination, latest, force): """ Plot all sodar raw data files. @@ -153,4 +288,5 @@ source - path to raw data directory in NCCOOS format. detination - path to plot images directory in NCCOOS format. + latest - path to latest plots images directory in NCCOOS format. force - update all destination plots for which raw data sources exist. rc - 0 if successful @@ -168,8 +304,11 @@ plotSingle(filein, pathout) + filein, pathout = walkList[-1] + plotLatest(filein, latest) + return 0 def _main(): - """bin/python %prog [options] /path/to/raw/files/ /path/to/plots/dir/""" + """bin/python %prog [options] /path/to/raw/files/ /path/to/plots/ /path/to/latest/plot/""" __description__ = 'Plot all sodar raw data files.' @@ -184,6 +323,6 @@ help='update all plots for which raw data exists') (values, args) = parser.parse_args() - (source, destination) = tuple(args) - plotAll(source, destination, values.force) + (source, destination, latest) = tuple(args) + plotAll(source, destination, latest, values.force) return 0