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

Changeset 150

Show
Ignore:
Timestamp:
04/09/08 16:54:31
Author:
cbc
Message:

Refactor "not at all" plotLatest into "good enough" copyLatest in plotSodar.py.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sodar/trunk/plotSodar.py

    r149 r150  
    1010import pylab as p 
    1111import os 
     12import shutil 
     13 
     14_uComponentsPlotName = 'uComponents.png' 
     15_vComponentsPlotName = 'vComponents.png' 
     16_wComponentsPlotName = 'wComponents.png' 
     17_echoStrengthsPlotName = 'echoStrengths.png' 
     18_quiverPlotName = 'quiver.png' 
     19_latestPlotNamePrefix = 'ims_sodar_latest_' 
    1220 
    1321def plotSingle(filein, pathout): 
     
    2533        os.makedirs(pathout, mode=0775) 
    2634     
    27     try: 
    28         rawDataHandle = openAnything.openAnything(filein) 
    29         rawDataString = rawDataHandle.read() 
    30         rawDataHandle.close() 
    31     except: 
    32         raise IOError("Failure to read raw data.") 
     35    rawDataHandle = openAnything.openAnything(filein) 
     36    rawDataString = rawDataHandle.read() 
     37    rawDataHandle.close() 
    3338     
    3439    rawDataObject = a.rawData.RawData(rawDataString) 
     
    7984    makePcolor(maskedUComponents.T, 
    8085               'U Component of Wind Velocity for %s' % 
    81                 (str(beginStamp)[:10],), 
    82                'uComponents.png'
     86               (str(beginStamp)[:10],), 
     87               _uComponentsPlotName
    8388               'Speed (cm/sec)') 
    8489     
     
    8893    makePcolor(maskedVComponents.T, 
    8994               'V Component of Wind Velocity for %s' % 
    90                 (str(beginStamp)[:10],), 
    91                'vComponents.png'
     95               (str(beginStamp)[:10],), 
     96               _vComponentsPlotName
    9297               'Speed (cm/sec)') 
    9398     
     
    97102    makePcolor(maskedWComponents.T, 
    98103               'W Component of Wind Velocity for %s' % 
    99                 (str(beginStamp)[:10],), 
    100                'wComponents.png'
     104               (str(beginStamp)[:10],), 
     105               _wComponentsPlotName
    101106               'Speed (cm/sec)') 
    102107     
     
    106111    makePcolor(maskedEchoStrenths.T, 
    107112               'Echo Strength for %s' % 
    108                 (str(beginStamp)[:10],), 
    109                'echoStrengths.png'
     113               (str(beginStamp)[:10],), 
     114               _echoStrengthsPlotName
    110115               'Strength (no units)') 
    111116     
     
    140145    # cb.set_label('W Component Speed (cm/sec)') 
    141146     
    142     # fig.savefig(os.path.join(pathout, 'quiver.png')) 
     147    # fig.savefig(os.path.join(pathout, _quiverPlotName)) 
    143148    # fig.clear() 
    144149     
    145150    return 0 
    146151 
    147  
    148 def plotLatest(filein, pathout): 
    149     """ 
    150     Plot latest sodar raw data file. 
    151      
    152     plotLatest(filein, pathout) -> rc 
    153      
    154     filein - path to raw data file
    155     pathout - path to plot images directory. 
     152def copyLatest(pathout, latest, plotName): 
     153    """ 
     154    Copy the latest plot to the official NCCOOS place. 
     155     
     156    copyLatest(pathout, latest, plotName) -> rc 
     157     
     158    pathout - path to directory where the latest plot is. 
     159    latest - path to directory where the latest plot is to be copied
     160    plotName - name of the plot file to copy. 
    156161    rc - 0 if successful 
    157162    """ 
    158      
    159     if not os.path.exists(pathout): 
    160         os.makedirs(pathout, mode=0775) 
    161      
    162     try: 
    163         rawDataHandle = openAnything.openAnything(filein) 
    164         rawDataString = rawDataHandle.read() 
    165         rawDataHandle.close() 
    166     except: 
    167         raise IOError("Failure to read raw data.") 
    168      
    169     rawDataObject = a.rawData.RawData(rawDataString) 
    170     formattedDataObject = a.formattedData.FormattedData(rawDataObject) 
    171     arrayDataObject = a.ArrayData(formattedDataObject) 
    172      
    173     beginStamp = arrayDataObject.beginStamp 
    174     endStamp = arrayDataObject.endStamp 
    175     numIntervals = arrayDataObject.numIntervals 
    176     timeInterval = arrayDataObject.timeInterval 
    177     minAltitude = arrayDataObject.minAltitude 
    178     numAltitudes = arrayDataObject.numAltitudes 
    179     altInterval = arrayDataObject.altInterval 
    180      
    181     def makePcolor(vector, title, fileout, cbLabel): 
    182         fig = p.figure(1) 
    183         axe = fig.add_subplot(1, 1, 1) 
    184         pc = axe.pcolor(vector) 
    185          
    186         axe.set_xlabel('Time (hh:mm UTC)') 
    187         axe.set_ylabel('Altitude (m)') 
    188         axe.set_xbound(upper=numIntervals) 
    189          
    190         xticks = axe.get_xticks() 
    191         xticklabels = [(int(x) * timeInterval) + beginStamp 
    192                        for x in xticks] 
    193         xticklabels = [':'.join(('%02u' % x.hour, '%02u' % x.minute)) 
    194                        for x in xticklabels] 
    195         axe.set_xticklabels(xticklabels) 
    196          
    197         yticks = axe.get_yticks() 
    198         yticklabels = [str(y * altInterval + minAltitude) 
    199                        for y in yticks] 
    200         axe.set_yticklabels(yticklabels) 
    201          
    202         axe.set_title(title) 
    203         cb = p.colorbar(pc) 
    204         cb.set_label(cbLabel) 
    205          
    206         fig.savefig(os.path.join(pathout, fileout)) 
    207         fig.clear() 
    208          
    209         return 0 
    210      
    211     uComponents = arrayDataObject.uComponents 
    212     maskedUComponents = n.ma.masked_where(n.isnan(uComponents), 
    213                                           uComponents) 
    214     makePcolor(maskedUComponents.T, 
    215                'U Component of Wind Velocity for %s' % 
    216                 (str(beginStamp)[:10],), 
    217                'ims_sodar_latest_uComponents.png', 
    218                'Speed (cm/sec)') 
    219      
    220     vComponents = arrayDataObject.vComponents 
    221     maskedVComponents = n.ma.masked_where(n.isnan(vComponents), 
    222                                           vComponents) 
    223     makePcolor(maskedVComponents.T, 
    224                'V Component of Wind Velocity for %s' % 
    225                 (str(beginStamp)[:10],), 
    226                'ims_sodar_latest_vComponents.png', 
    227                'Speed (cm/sec)') 
    228      
    229     wComponents = arrayDataObject.wComponents 
    230     maskedWComponents = n.ma.masked_where(n.isnan(wComponents), 
    231                                           wComponents) 
    232     makePcolor(maskedWComponents.T, 
    233                'W Component of Wind Velocity for %s' % 
    234                 (str(beginStamp)[:10],), 
    235                'ims_sodar_latest_wComponents.png', 
    236                'Speed (cm/sec)') 
    237      
    238     echoStrengths = arrayDataObject.echoStrengths 
    239     maskedEchoStrenths = n.ma.masked_where(n.isnan(echoStrengths), 
    240                                                    echoStrengths) 
    241     makePcolor(maskedEchoStrenths.T, 
    242                'Echo Strength for %s' % 
    243                 (str(beginStamp)[:10],), 
    244                'ims_sodar_latest_echoStrengths.png', 
    245                'Strength (no units)') 
    246      
    247     # timeComponent = n.array(range(numIntervals)) 
    248     # altComponent = n.array(range(numAltitudes)) 
    249     # fig = p.figure(1) 
    250     # axe = fig.add_subplot(1, 1, 1) 
    251     # qv = axe.quiver(altComponent, 
    252     #                 timeComponent, 
    253     #                 maskedUComponents.T, 
    254     #                 maskedVComponents.T) 
    255      
    256     # axe.set_xlabel('Time (min)') 
    257     # axe.set_ylabel('Altitude (m)') 
    258     # axe.set_xbound(upper=numIntervals) 
    259      
    260     # xticks = axe.get_xticks() 
    261     # xticklabels = [(int(x) * timeInterval) + beginStamp 
    262     #                for x in xticks] 
    263     # xticklabels = [':'.join(('%02u' % x.hour, '%02u' % x.minute)) 
    264     #                for x in xticklabels] 
    265     # axe.set_xticklabels(xticklabels) 
    266      
    267     # yticks = axe.get_yticks() 
    268     # yticklabels = [str(y * altInterval + minAltitude) 
    269     #                for y in yticks] 
    270     # axe.set_yticklabels(yticklabels) 
    271      
    272     # axe.set_title('Wind Velocty for %s' % 
    273     #               (str(beginStamp)[:10],)) 
    274     # cb = p.colorbar(qv) 
    275     # cb.set_label('W Component Speed (cm/sec)') 
    276      
    277     # fig.savefig(os.path.join(pathout, 'ims_sodar_latest_quiver.png')) 
    278     # fig.clear() 
    279      
     163    shutil.copy(os.path.join(pathout, plotName), 
     164                os.path.join(lastest, 
     165                             _latestPlotNamePrefix + plotName)) 
    280166    return 0 
    281167 
     
    304190        plotSingle(filein, pathout) 
    305191     
     192    if not os.path.exists(latest): 
     193        os.makedirs(latest, mode=0775) 
     194 
    306195    filein, pathout = walkList[-1] 
    307     plotLatest(filein, latest) 
     196    copyLatest(pathout, latest, _uComponentsPlotName) 
     197    copyLatest(pathout, latest, _vComponentsPlotName) 
     198    copyLatest(pathout, latest, _wComponentsPlotName) 
     199    copyLatest(pathout, latest, _echoStrengthsPlotName) 
     200    # copyLatest(pathout, latest, _quiverPlotName) 
    308201     
    309202    return 0