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

Changeset 80

Show
Ignore:
Timestamp:
10/07/11 14:25:08
Author:
cbc
Message:

Refactor meanspeed.py and make most recent plot the subject of index.html for both meanspeed.py and winddist.py.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sodarplot/trunk/sodarplot/scintec/meanspeed.py

    r78 r80  
    1 import os,datetime,glob  
     1import os,datetime,glob 
     2import multiprocessing 
    23import numpy as np  
    34import matplotlib as mpl  
     
    4445    </body>  
    4546</html>"""  
    46   
    47 first = True  
    48 for previous,ncFile,next in files:  
     47 
     48def _components(fileSpec): 
     49    "Figure out year and month from file specification." 
     50 
     51    fileName = os.path.splitext(os.path.basename(fileSpec))[0]                  
     52    year = fileName[-7:-3] 
     53    month = fileName[-2:] 
     54    monthName = datetime.datetime(int(year),int(month),1).strftime('%B') 
     55    return (fileName, year, month, monthName) 
     56 
     57def meanspeed((previous, ncFile, next), pngDir, genHtml=False, lastMonth=False): 
    4958    print 'Processing',ncFile  
    50     ncFileName = os.path.splitext(os.path.basename(ncFile))[0]  
    51     year = ncFileName[19:23]  
    52     month = ncFileName[24:26]  
    53     month = datetime.datetime(int(year),int(month),1).strftime('%B')  
    54     if previous:  
    55         previous = os.path.splitext(os.path.basename(previous))[0]  
    56         previousYear = previous[19:23]  
    57         previousMonth = previous[24:26]  
    58         previousMonth = datetime.datetime(int(previousYear),int(previousMonth),1).strftime('%B')  
    59         previous = previous + os.extsep + htmlExt  
    60     if next:  
    61         next = os.path.splitext(os.path.basename(next))[0]  
    62         nextYear = next[19:23]  
    63         nextMonth = next[24:26]  
    64         nextMonth = datetime.datetime(int(nextYear),int(nextMonth),1).strftime('%B')  
    65         next = next + os.extsep + htmlExt  
     59    ncFileName, year, month, monthName = _components(ncFile) 
     60    previous, previousYear, previousMonth, previousMonthName = _components(previous) 
     61    next, nextYear, nextMonth, nextMonthName = _components(next) 
    6662  
    6763    nc = pycdf.CDF(ncFile)  
     
    10096    fig = figure()  
    10197    fig.subplots_adjust(hspace=0.3) 
    102     spt = suptitle('Billy Mitchell Sodar :: ' + month + " " + year)  
     98    spt = suptitle('Billy Mitchell Sodar :: ' + monthName + " " + year)  
    10399 
    104100    subplot(2,4,1)  
     
    189185    print 'Saving', outFile  
    190186    fig.savefig(outFile)  
    191   
    192     htmlFile = os.path.join(pngDir,ncFileName + os.extsep + htmlExt)  
    193     html = html1 + month + " " + year  
    194     html = html + html2 + previous + html3 + next + html4  
    195     html = html + os.path.basename(outFile) + html5  
    196     handle = open(htmlFile,'w')  
    197     handle.write(html)  
    198     handle.close()  
    199   
    200     if first:  
    201         first = False  
    202         htmlFile = os.path.join(pngDir,"index" + os.extsep + htmlExt)  
     187    fig.clear() 
     188  
     189    if genHtml: 
     190        htmlFile = os.path.join(pngDir,ncFileName + os.extsep + htmlExt)  
     191        html = html1 + month + " " + year  
     192        html = html + html2 + previous + os.extsep + htmlExt 
     193        html = html + html3 + next + os.extsep + htmlExt + html4  
     194        html = html + os.path.basename(outFile) + html5  
    203195        handle = open(htmlFile,'w')  
    204196        handle.write(html)  
    205197        handle.close()  
     198  
     199        if lastMonth:  
     200            htmlFile = os.path.join(pngDir,"index" + os.extsep + htmlExt)  
     201            handle = open(htmlFile,'w')  
     202            handle.write(html)  
     203            handle.close()  
    206204          
    207   
     205if __name__ == "__main__": 
     206    lastMonth = False 
     207    for previous,ncFile,next in files:               
     208        if next <= ncFile: 
     209            lastMonth = True 
     210        p = multiprocessing.Process(target=meanspeed, args=((previous, ncFile, next), pngDir, True, lastMonth)) 
     211        p.start() 
     212        p.join() 
     213        if p.exitcode: 
     214           print "Exitcode %s from processing %s" % (p.exitcode, ncFile) 
  • sodarplot/trunk/sodarplot/scintec/winddist.py

    r79 r80  
    4848            <a href=\"""" 
    4949 
    50 html7 = """\">Next Elevation&gt;</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    51             <a href=\"all.html\">&lt;All At Once&gt;</a> 
     50html7 = """\">Next Elevation&gt;</a> 
    5251        </form> 
    5352        <br/>  
     
    6766    return (fileName, year, month, monthName)  
    6867  
    69 def winddist((previous, ncFile, next), pngDir, genHtml=False, firstMonth=False): 
     68def winddist((previous, ncFile, next), pngDir, genHtml=False, lastMonth=False): 
    7069    print 'Processing',ncFile 
    7170    ncFileName, year, month, monthName = _components(ncFile)  
     
    156155                handle.close()  
    157156 
    158                 if firstMonth and firstElevation:  
     157                if lastMonth and firstElevation:  
    159158                    firstElevation = False 
    160159                    htmlFile = os.path.join(pngDir,"index" + os.extsep + htmlExt)  
     
    164163 
    165164if __name__ == "__main__": 
    166     firstMonth = True  
     165    lastMonth = False  
    167166    for previous,ncFile,next in files: 
    168         p = multiprocessing.Process(target=winddist, args=((previous, ncFile, next), pngDir, True, firstMonth)) 
     167        if next <= ncFile: 
     168            lastMonth = True 
     169        p = multiprocessing.Process(target=winddist, args=((previous, ncFile, next), pngDir, True, lastMonth)) 
    169170        p.start() 
    170171        p.join() 
    171172        if p.exitcode: 
    172173           print "Exitcode %s from processing %s" % (p.exitcode, ncFile)  
    173         firstMonth = False