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

Changeset 148

Show
Ignore:
Timestamp:
04/08/08 17:58:43
Author:
cbc
Message:

Add plotLatest to plotSodar.py to make Data Monitor green.

Files:

Legend:

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

    r142 r148  
    1313def plotSingle(filein, pathout): 
    1414    """ 
    15     Plot singe sodar raw data file. 
     15    Plot single sodar raw data file. 
    1616     
    1717    plotSingle(filein, pathout) -> rc 
    1818     
    1919    filein - path to raw data file. 
    20     fileout - path to plot images directory. 
     20    pathout - path to plot images directory. 
    2121    rc - 0 if successful 
    2222    """ 
     
    145145    return 0 
    146146 
    147 def plotAll(source, destination, force): 
     147 
     148def 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. 
     156    rc - 0 if successful 
     157    """ 
     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 Veloctiy 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 Veloctiy 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 Veloctiy 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     
     280    return 0 
     281 
     282def plotAll(source, destination, latest, force): 
    148283    """ 
    149284    Plot all sodar raw data files. 
     
    153288    source - path to raw data directory in NCCOOS format. 
    154289    detination - path to plot images directory in NCCOOS format. 
     290    latest - path to latest plots images directory in NCCOOS format. 
    155291    force - update all destination plots for which raw data sources exist. 
    156292    rc - 0 if successful 
     
    168304        plotSingle(filein, pathout) 
    169305     
     306    filein, pathout = walkList[-1] 
     307    plotLatest(filein, latest) 
     308     
    170309    return 0 
    171310 
    172311def _main(): 
    173     """bin/python %prog [options] /path/to/raw/files/ /path/to/plots/dir/""" 
     312    """bin/python %prog [options] /path/to/raw/files/ /path/to/plots/ /path/to/latest/plot/""" 
    174313     
    175314    __description__ = 'Plot all sodar raw data files.' 
     
    184323                      help='update all plots for which raw data exists') 
    185324    (values, args) = parser.parse_args() 
    186     (source, destination) = tuple(args) 
    187     plotAll(source, destination, values.force) 
     325    (source, destination, latest) = tuple(args) 
     326    plotAll(source, destination, latest, values.force) 
    188327     
    189328    return 0