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

Changeset 139

Show
Ignore:
Timestamp:
03/27/08 01:32:20
Author:
cbc
Message:

Fixed ridiculous nesting and path separator bugs in plotSodar.py.

Files:

Legend:

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

    r137 r139  
    2424    if not os.path.exists(pathout): 
    2525        os.makedirs(pathout, mode=0775) 
    26          
    27         try: 
    28             rawDataHandle = openAnything.openAnything(filein) 
    29             rawDataString = rawDataHandle.read() 
    30             rawDataHandle.close() 
    31         except: 
    32             raise IOError("Failure to read raw data.") 
    33          
    34         rawDataObject = a.rawData.RawData(rawDataString) 
    35         formattedDataObject = a.formattedData.FormattedData(rawDataObject) 
    36         arrayDataObject = a.ArrayData(formattedDataObject) 
    37          
    38         beginStamp = arrayDataObject.beginStamp 
    39         endStamp = arrayDataObject.endStamp 
    40         numIntervals = arrayDataObject.numIntervals 
    41         timeInterval = arrayDataObject.timeInterval 
    42         timeInterval = (((float(timeInterval.days) * 24.0) + 
    43                          (timeInterval.seconds / 3600.0)) * 60.0) 
    44         minAltitude = arrayDataObject.minAltitude 
    45         altInterval = arrayDataObject.altInterval 
    46          
    47         def makePcolor(vector, title, fileout, cbLabel): 
    48             fig = p.figure(1) 
    49             axe = fig.add_subplot(1, 1, 1) 
    50             pc = axe.pcolor(vector) 
    51              
    52             axe.set_xlabel('Time (min)') 
    53             axe.set_ylabel('Altitude (m)') 
    54             axe.set_xbound(upper=numIntervals) 
    55              
    56             xticks = axe.get_xticks() 
    57             xticklabels = [str(x * timeInterval) 
    58                            for x in xticks] 
    59             axe.set_xticklabels(xticklabels) 
    60              
    61             yticks = axe.get_yticks() 
    62             yticklabels = [str(y * altInterval + minAltitude) 
    63                            for y in yticks] 
    64             axe.set_yticklabels(yticklabels) 
    65              
    66             axe.set_title(title) 
    67             cb = p.colorbar(pc) 
    68             cb.set_label(cbLabel) 
    69              
    70             fig.savefig(os.path.join(pathout, fileout)) 
    71             fig.clear() 
    72              
    73             return 0 
    74          
    75         uComponents = arrayDataObject.uComponents 
    76         maskedUComponents = n.ma.masked_where(n.isnan(uComponents), 
    77                                               uComponents) 
    78         makePcolor(maskedUComponents.T, 
    79                    'U Component of Wind Veloctiy\nFrom %s To %s' % 
    80                    (beginStamp, endStamp), 
    81                    'uComponents.png', 
    82                    'Speed (cm/sec)') 
    83          
    84         vComponents = arrayDataObject.vComponents 
    85         maskedVComponents = n.ma.masked_where(n.isnan(vComponents), 
    86                                               vComponents) 
    87         makePcolor(maskedVComponents.T, 
    88                    'V Component of Wind Veloctiy\nFrom %s To %s' % 
    89                    (beginStamp, endStamp), 
    90                    'vComponents.png', 
    91                    'Speed (cm/sec)') 
    92          
    93         wComponents = arrayDataObject.wComponents 
    94         maskedWComponents = n.ma.masked_where(n.isnan(wComponents), 
    95                                               wComponents) 
    96         makePcolor(maskedWComponents.T, 
    97                    'W Component of Wind Veloctiy\nFrom %s To %s' % 
    98                    (beginStamp, endStamp), 
    99                    'wComponents.png', 
    100                    'Speed (cm/sec)') 
    101          
    102         echoStrengths = arrayDataObject.echoStrengths 
    103         maskedEchoStrenths = n.ma.masked_where(n.isnan(echoStrengths), 
    104                                                        echoStrengths) 
    105         makePcolor(maskedEchoStrenths.T, 
    106                    'Echo Strength\nFrom %s To %s' % 
    107                    (beginStamp, endStamp), 
    108                    'echoStrengths.png', 
    109                    'Strength (no units)') 
    110          
     26     
     27    try: 
     28        rawDataHandle = openAnything.openAnything(filein) 
     29        rawDataString = rawDataHandle.read() 
     30        rawDataHandle.close() 
     31    except: 
     32        raise IOError("Failure to read raw data.") 
     33     
     34    rawDataObject = a.rawData.RawData(rawDataString) 
     35    formattedDataObject = a.formattedData.FormattedData(rawDataObject) 
     36    arrayDataObject = a.ArrayData(formattedDataObject) 
     37     
     38    beginStamp = arrayDataObject.beginStamp 
     39    endStamp = arrayDataObject.endStamp 
     40    numIntervals = arrayDataObject.numIntervals 
     41    timeInterval = arrayDataObject.timeInterval 
     42    timeInterval = (((float(timeInterval.days) * 24.0) + 
     43                     (timeInterval.seconds / 3600.0)) * 60.0) 
     44    minAltitude = arrayDataObject.minAltitude 
     45    altInterval = arrayDataObject.altInterval 
     46     
     47    def makePcolor(vector, title, fileout, cbLabel): 
    11148        fig = p.figure(1) 
    11249        axe = fig.add_subplot(1, 1, 1) 
    113         qv = axe.quiver(maskedUComponents, 
    114                         maskedVComponents, 
    115                         maskedWComponents) 
     50        pc = axe.pcolor(vector) 
     51         
    11652        axe.set_xlabel('Time (min)') 
    11753        axe.set_ylabel('Altitude (m)') 
    11854        axe.set_xbound(upper=numIntervals) 
     55         
    11956        xticks = axe.get_xticks() 
    12057        xticklabels = [str(x * timeInterval) 
    12158                       for x in xticks] 
    12259        axe.set_xticklabels(xticklabels) 
     60         
    12361        yticks = axe.get_yticks() 
    12462        yticklabels = [str(y * altInterval + minAltitude) 
    12563                       for y in yticks] 
    12664        axe.set_yticklabels(yticklabels) 
    127         axe.set_title('Wind Velocty\nFrom %s To %s' % 
    128                       (beginStamp, endStamp)) 
    129         cb = p.colorbar(qv) 
    130         cb.set_label('W Component Speed (cm/sec)') 
    131         fig.savefig(os.path.join(pathout, 'quiver.png')) 
     65         
     66        axe.set_title(title) 
     67        cb = p.colorbar(pc) 
     68        cb.set_label(cbLabel) 
     69         
     70        fig.savefig(os.path.join(pathout, fileout)) 
    13271        fig.clear() 
    13372         
    13473        return 0 
     74     
     75    uComponents = arrayDataObject.uComponents 
     76    maskedUComponents = n.ma.masked_where(n.isnan(uComponents), 
     77                                          uComponents) 
     78    makePcolor(maskedUComponents.T, 
     79               'U Component of Wind Veloctiy\nFrom %s To %s' % 
     80               (beginStamp, endStamp), 
     81               'uComponents.png', 
     82               'Speed (cm/sec)') 
     83     
     84    vComponents = arrayDataObject.vComponents 
     85    maskedVComponents = n.ma.masked_where(n.isnan(vComponents), 
     86                                          vComponents) 
     87    makePcolor(maskedVComponents.T, 
     88               'V Component of Wind Veloctiy\nFrom %s To %s' % 
     89               (beginStamp, endStamp), 
     90               'vComponents.png', 
     91               'Speed (cm/sec)') 
     92     
     93    wComponents = arrayDataObject.wComponents 
     94    maskedWComponents = n.ma.masked_where(n.isnan(wComponents), 
     95                                          wComponents) 
     96    makePcolor(maskedWComponents.T, 
     97               'W Component of Wind Veloctiy\nFrom %s To %s' % 
     98               (beginStamp, endStamp), 
     99               'wComponents.png', 
     100               'Speed (cm/sec)') 
     101     
     102    echoStrengths = arrayDataObject.echoStrengths 
     103    maskedEchoStrenths = n.ma.masked_where(n.isnan(echoStrengths), 
     104                                                   echoStrengths) 
     105    makePcolor(maskedEchoStrenths.T, 
     106               'Echo Strength\nFrom %s To %s' % 
     107               (beginStamp, endStamp), 
     108               'echoStrengths.png', 
     109               'Strength (no units)') 
     110     
     111    fig = p.figure(1) 
     112    axe = fig.add_subplot(1, 1, 1) 
     113    qv = axe.quiver(maskedUComponents, 
     114                    maskedVComponents, 
     115                    maskedWComponents) 
     116    axe.set_xlabel('Time (min)') 
     117    axe.set_ylabel('Altitude (m)') 
     118    axe.set_xbound(upper=numIntervals) 
     119    xticks = axe.get_xticks() 
     120    xticklabels = [str(x * timeInterval) 
     121                   for x in xticks] 
     122    axe.set_xticklabels(xticklabels) 
     123    yticks = axe.get_yticks() 
     124    yticklabels = [str(y * altInterval + minAltitude) 
     125                   for y in yticks] 
     126    axe.set_yticklabels(yticklabels) 
     127    axe.set_title('Wind Velocty\nFrom %s To %s' % 
     128                  (beginStamp, endStamp)) 
     129    cb = p.colorbar(qv) 
     130    cb.set_label('W Component Speed (cm/sec)') 
     131    fig.savefig(os.path.join(pathout, 'quiver.png')) 
     132    fig.clear() 
     133     
     134    return 0 
    135135 
    136136def plotAll(source, destination): 
     
    145145    """ 
    146146     
     147    if source.endswith(os.path.sep): 
     148        source = source.rstrip(os.path.sep) 
     149     
     150    if destination.endswith(os.path.sep): 
     151        destination = destination.rstrip(os.path.sep) 
     152     
    147153    walkList = findMissing.findMissing(source, destination) 
    148154     
    149155    for filein, pathout in walkList: 
    150156        plotSingle(filein, pathout) 
     157     
    151158    return 0 
    152159 
     
    162169    (source, destination) = tuple(args) 
    163170    plotAll(source, destination) 
     171     
    164172    return 0 
    165173