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

Changeset 78

Show
Ignore:
Timestamp:
10/06/11 14:29:05
Author:
cbc
Message:

Heavily refactor winddist to prevent memory leaks.

Files:

Legend:

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

    r75 r78  
    6868 
    6969    t = nc.var('time')[:]  
    70     z = nc.var('z')[:]  
     70    z = nc.var('z')[:] 
    7171    u = nc.var('u')[:]  
    7272    v = nc.var('v')[:]  
     
    107107    ylabel('Elevation (m)')  
    108108    xlim(-8,8) 
    109     ylim(0,200
     109    ylim(0,int(max(z))
    110110    xticks(fontsize=spt.get_fontsize()*0.6) 
    111111    plot(mumean.data,z,label=r'$\bar{u}$')  
     
    119119    xlabel('% of Samples per Month',fontsize=spt.get_fontsize()*0.6) 
    120120    xlim(0,100)  
    121     ylim(0,200)  
     121    ylim(0,int(max(z)))  
    122122    xticks(range(0,101,25),fontsize=spt.get_fontsize()*0.6) 
    123123    yticks([])  
     
    131131    xlabel('Velocity (m/s)',fontsize=spt.get_fontsize()*0.6) 
    132132    xlim(0,10)  
    133     ylim(0,200)  
     133    ylim(0,int(max(z)))  
    134134    xticks(fontsize=spt.get_fontsize()*0.6) 
    135135    yticks([])  
     
    142142    xlabel('Direction (Wind From)',fontsize=spt.get_fontsize()*0.6) 
    143143    xlim(0,360) 
    144     ylim(0,200)  
     144    ylim(0,int(max(z)))  
    145145    xticks(range(0,361,90),['N','E','S','W','N',], 
    146146           fontsize=spt.get_fontsize()*0.6) 
     
    155155    ylabel('Elevation (m)')  
    156156    xlim(0,16) 
    157     ylim(0,200
     157    ylim(0,int(max(z))
    158158    xticks(fontsize=spt.get_fontsize()*0.6) 
    159159    plot(mustd.data,z,label=r'$\sigma_u$')  
     
    167167    xlabel('% of Samples per Month',fontsize=spt.get_fontsize()*0.6) 
    168168    xlim(0,100)  
    169     ylim(0,200)  
     169    ylim(0,int(max(z)))  
    170170    xticks(range(0,101,25),fontsize=spt.get_fontsize()*0.6) 
    171171    yticks([])  
     
    179179    xlabel('Std Dev (m/s)',fontsize=spt.get_fontsize()*0.6) 
    180180    xlim(0,10)  
    181     ylim(0,200)  
     181    ylim(0,int(max(z)))  
    182182    xticks(fontsize=spt.get_fontsize()*0.6) 
    183183    yticks([])  
  • sodarplot/trunk/sodarplot/scintec/winddist.py

    r77 r78  
    11import os,datetime,glob 
     2import multiprocessing 
    23import numpy as np 
    34import matplotlib as mpl 
     
    1920ncFilePattern = os.path.join(ncDir,ncFileGlob)  
    2021files = glob.glob(ncFilePattern) 
    21 files = files[:-1] # sodar was broken last month 
     22# files = files[:-1] # sodar was broken last month 
     23# files = files[-4:] 
    2224previous = [files[-1]] + files[:-1]  
    2325next = files[1:] + [files[0]]  
     
    5860</html>""" 
    5961  
    60 firstMonth = True  
    61 for previous,ncFile,next in files:  
     62def winddist((previous, ncFile, next), pngDir, genHtml=False, firstMonth=False): 
    6263    print 'Processing',ncFile  
    6364    ncFileName = os.path.splitext(os.path.basename(ncFile))[0]  
    6465    year = ncFileName[19:23]  
    6566    month = ncFileName[24:26]  
    66     month = datetime.datetime(int(year),int(month),1).strftime('%B')  
     67    monthName = datetime.datetime(int(year),int(month),1).strftime('%B')  
    6768    if previous:  
    6869        previous = os.path.splitext(os.path.basename(previous))[0]  
    6970        previousYear = previous[19:23]  
    7071        previousMonth = previous[24:26]  
    71         previousMonth = datetime.datetime(int(previousYear),int(previousMonth),1).strftime('%B')  
     72        previousMonthName = datetime.datetime(int(previousYear),int(previousMonth),1).strftime('%B')  
    7273    if next:  
    7374        next = os.path.splitext(os.path.basename(next))[0]  
    7475        nextYear = next[19:23]  
    7576        nextMonth = next[24:26]  
    76         nextMonth = datetime.datetime(int(nextYear),int(nextMonth),1).strftime('%B')  
    77   
     77        nextMonthName = datetime.datetime(int(nextYear),int(nextMonth),1).strftime('%B')  
     78 
    7879    nc = pycdf.CDF(ncFile)  
    7980 
     
    126127        if rho[x].any(): 
    127128            fig = plt.figure(figsize=(8, 8), dpi=80, facecolor='w', edgecolor='w') 
    128             spt = fig.suptitle('Billy Mitchell Sodar :: ' + month + " " + year) 
     129            spt = fig.suptitle('Billy Mitchell Sodar :: ' + monthName + " " + year) 
    129130            rect = [0.16, 0.16, 0.68, 0.68] 
    130131            ax = WindroseAxes(fig, rect, axisbg='w') 
     
    138139            l = ax.legend(axespad=-0.20,title="Magnitude (m/s)") 
    139140            plt.setp(l.get_texts(), fontsize=8) 
    140             if not os.path.exists(os.path.join(pngDir,ncFileName)): 
    141                 os.mkdir(os.path.join(pngDir,ncFileName)) 
    142             outFile = os.path.join(pngDir,ncFileName,('%dm' % z[x]) + os.extsep + pngExt)  
     141            dirName = "%4u_%02u" % (int(year), int(month)) 
     142            if not os.path.exists(os.path.join(pngDir, dirName)): 
     143                os.mkdir(os.path.join(pngDir, dirName)) 
     144            outFile = os.path.join(pngDir,dirName,('%03um' % z[x]) + os.extsep + pngExt)  
    143145            print 'Saving', outFile  
    144146            fig.savefig(outFile) 
     147            fig.clear() 
    145148 
    146             # htmlFile = os.path.join(pngDir,ncFileName + "_" + ('%dm' % z[x]) + os.extsep + htmlExt)  
    147             # html = html1 + month + " " + year 
    148             # html = html + html2 + ('%dm' % z[x]) 
    149             # html = html + html3 + previous + "_" + ('%dm' % z[x]) + os.extsep + htmlExt 
    150             # html = html + html4 + next + "_" + ('%dm' % z[x]) + os.extsep + htmlExt 
    151             # html = html + html5 + ncFileName + "_" + ('%dm' % z[previousX]) + os.extsep + htmlExt 
    152             # html = html + html6 + ncFileName + "_" + ('%dm' % z[nextX]) + os.extsep + htmlExt 
    153             # html = html + html7 + os.path.join(ncFileName,os.path.basename(outFile)) + html8  
    154             # handle = open(htmlFile,'w')  
    155             # handle.write(html)  
    156             # handle.close()  
     149            if genHtml: 
     150                htmlFile = os.path.join(pngDir,ncFileName + "_" + ('%dm' % z[x]) + os.extsep + htmlExt)  
     151                html = html1 + monthName + " " + year 
     152                html = html + html2 + ('%dm' % z[x]) 
     153                html = html + html3 + previous + "_" + ('%dm' % z[x]) + os.extsep + htmlExt 
     154                html = html + html4 + next + "_" + ('%dm' % z[x]) + os.extsep + htmlExt 
     155                html = html + html5 + ncFileName + "_" + ('%dm' % z[previousX]) + os.extsep + htmlExt 
     156                html = html + html6 + ncFileName + "_" + ('%dm' % z[nextX]) + os.extsep + htmlExt 
     157                html = html + html7 + os.path.join(ncFileName,os.path.basename(outFile)) + html8  
     158                handle = open(htmlFile,'w')  
     159                handle.write(html)  
     160                handle.close()  
    157161 
    158             # if firstMonth and firstElevation:  
    159             #     firstMonth = False 
    160             #     firstElevation = False 
    161             #     htmlFile = os.path.join(pngDir,"index" + os.extsep + htmlExt)  
    162             #     handle = open(htmlFile,'w')  
    163             #     handle.write(html)  
    164             #     handle.close()  
    165   
     162                if firstMonth and firstElevation:  
     163                    firstElevation = False 
     164                    htmlFile = os.path.join(pngDir,"index" + os.extsep + htmlExt)  
     165                    handle = open(htmlFile,'w')  
     166                    handle.write(html)  
     167                    handle.close() 
     168 
     169if __name__ == "__main__": 
     170    firstMonth = True  
     171    for previous,ncFile,next in files: 
     172        p = multiprocessing.Process(target=winddist, args=((previous, ncFile, next), pngDir, {'genHtml':True, 'firstMonth':firstMonth})) 
     173        p.start() 
     174        p.join() 
     175        if p.exitcode: 
     176           print "Exitcode %s from processing %s" % (p.exitcode, ncFile)  
     177        firstMonth = False