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

Changeset 79

Show
Ignore:
Timestamp:
10/06/11 16:13:19
Author:
cbc
Message:

Small refactoring of winddist.py

Files:

Legend:

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

    r78 r79  
    2020ncFilePattern = os.path.join(ncDir,ncFileGlob)  
    2121files = glob.glob(ncFilePattern) 
    22 # files = files[:-1] # sodar was broken last month 
    23 # files = files[-4:] 
    2422previous = [files[-1]] + files[:-1]  
    2523next = files[1:] + [files[0]]  
     
    5957    </body>  
    6058</html>""" 
     59 
     60def _components(fileSpec): 
     61    "Figure out year and month from file specification." 
     62 
     63    fileName = os.path.splitext(os.path.basename(fileSpec))[0]  
     64    year = fileName[-7:-3]  
     65    month = fileName[-2:]  
     66    monthName = datetime.datetime(int(year),int(month),1).strftime('%B') 
     67    return (fileName, year, month, monthName)  
    6168  
    6269def winddist((previous, ncFile, next), pngDir, genHtml=False, firstMonth=False): 
    63     print 'Processing',ncFile  
    64     ncFileName = os.path.splitext(os.path.basename(ncFile))[0]  
    65     year = ncFileName[19:23]  
    66     month = ncFileName[24:26]  
    67     monthName = datetime.datetime(int(year),int(month),1).strftime('%B')  
    68     if previous:  
    69         previous = os.path.splitext(os.path.basename(previous))[0]  
    70         previousYear = previous[19:23]  
    71         previousMonth = previous[24:26]  
    72         previousMonthName = datetime.datetime(int(previousYear),int(previousMonth),1).strftime('%B')  
    73     if next:  
    74         next = os.path.splitext(os.path.basename(next))[0]  
    75         nextYear = next[19:23]  
    76         nextMonth = next[24:26]  
    77         nextMonthName = datetime.datetime(int(nextYear),int(nextMonth),1).strftime('%B')  
     70    print 'Processing',ncFile 
     71    ncFileName, year, month, monthName = _components(ncFile)  
     72    previous, previousYear, previousMonth, previousMonthName = _components(previous) 
     73    next, nextYear, nextMonth, nextMonthName = _components(next)  
    7874 
    7975    nc = pycdf.CDF(ncFile)  
     
    155151                html = html + html5 + ncFileName + "_" + ('%dm' % z[previousX]) + os.extsep + htmlExt 
    156152                html = html + html6 + ncFileName + "_" + ('%dm' % z[nextX]) + os.extsep + htmlExt 
    157                 html = html + html7 + os.path.join(ncFileName,os.path.basename(outFile)) + html8  
     153                html = html + html7 + os.path.join(dirName,os.path.basename(outFile)) + html8  
    158154                handle = open(htmlFile,'w')  
    159155                handle.write(html)  
     
    170166    firstMonth = True  
    171167    for previous,ncFile,next in files: 
    172         p = multiprocessing.Process(target=winddist, args=((previous, ncFile, next), pngDir, {'genHtml':True, 'firstMonth':firstMonth})) 
     168        p = multiprocessing.Process(target=winddist, args=((previous, ncFile, next), pngDir, True, firstMonth)) 
    173169        p.start() 
    174170        p.join()