Index: sodar/trunk/plotSodar.py =================================================================== --- sodar/trunk/plotSodar.py (revision 149) +++ sodar/trunk/plotSodar.py (revision 150) @@ -10,4 +10,12 @@ import pylab as p import os +import shutil + +_uComponentsPlotName = 'uComponents.png' +_vComponentsPlotName = 'vComponents.png' +_wComponentsPlotName = 'wComponents.png' +_echoStrengthsPlotName = 'echoStrengths.png' +_quiverPlotName = 'quiver.png' +_latestPlotNamePrefix = 'ims_sodar_latest_' def plotSingle(filein, pathout): @@ -25,10 +33,7 @@ os.makedirs(pathout, mode=0775) - try: - rawDataHandle = openAnything.openAnything(filein) - rawDataString = rawDataHandle.read() - rawDataHandle.close() - except: - raise IOError("Failure to read raw data.") + rawDataHandle = openAnything.openAnything(filein) + rawDataString = rawDataHandle.read() + rawDataHandle.close() rawDataObject = a.rawData.RawData(rawDataString) @@ -79,6 +84,6 @@ makePcolor(maskedUComponents.T, 'U Component of Wind Velocity for %s' % - (str(beginStamp)[:10],), - 'uComponents.png', + (str(beginStamp)[:10],), + _uComponentsPlotName, 'Speed (cm/sec)') @@ -88,6 +93,6 @@ makePcolor(maskedVComponents.T, 'V Component of Wind Velocity for %s' % - (str(beginStamp)[:10],), - 'vComponents.png', + (str(beginStamp)[:10],), + _vComponentsPlotName, 'Speed (cm/sec)') @@ -97,6 +102,6 @@ makePcolor(maskedWComponents.T, 'W Component of Wind Velocity for %s' % - (str(beginStamp)[:10],), - 'wComponents.png', + (str(beginStamp)[:10],), + _wComponentsPlotName, 'Speed (cm/sec)') @@ -106,6 +111,6 @@ makePcolor(maskedEchoStrenths.T, 'Echo Strength for %s' % - (str(beginStamp)[:10],), - 'echoStrengths.png', + (str(beginStamp)[:10],), + _echoStrengthsPlotName, 'Strength (no units)') @@ -140,142 +145,23 @@ # cb.set_label('W Component Speed (cm/sec)') - # fig.savefig(os.path.join(pathout, 'quiver.png')) + # fig.savefig(os.path.join(pathout, _quiverPlotName)) # fig.clear() return 0 - -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. +def copyLatest(pathout, latest, plotName): + """ + Copy the latest plot to the official NCCOOS place. + + copyLatest(pathout, latest, plotName) -> rc + + pathout - path to directory where the latest plot is. + latest - path to directory where the latest plot is to be copied. + plotName - name of the plot file to copy. 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 Velocity 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 Velocity 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 Velocity 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() - + shutil.copy(os.path.join(pathout, plotName), + os.path.join(lastest, + _latestPlotNamePrefix + plotName)) return 0 @@ -304,6 +190,13 @@ plotSingle(filein, pathout) + if not os.path.exists(latest): + os.makedirs(latest, mode=0775) + filein, pathout = walkList[-1] - plotLatest(filein, latest) + copyLatest(pathout, latest, _uComponentsPlotName) + copyLatest(pathout, latest, _vComponentsPlotName) + copyLatest(pathout, latest, _wComponentsPlotName) + copyLatest(pathout, latest, _echoStrengthsPlotName) + # copyLatest(pathout, latest, _quiverPlotName) return 0