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

Changeset 72

Show
Ignore:
Timestamp:
01/24/11 19:03:01
Author:
cbc
Message:

Add html generation to winddist.

Files:

Legend:

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

    r71 r72  
    2323next = files[1:] + [files[0]]  
    2424files = zip(previous,files,next)  
     25 
     26html1 = """<html>  
     27    <head>  
     28        <title>  
     29            Billy Mitchell Sodar :: """ 
     30 
     31 
     32html2 = """ :: Wind Distribution at """ 
     33 
     34html3 = """ Meters Above Sea Level 
     35        </title>  
     36    </head>  
     37    <body> 
     38        <form>  
     39            <a href=\"""" 
     40 
     41html4 = """\">&lt;Previous Month</a>&nbsp;&nbsp;&nbsp;  
     42            <a href=\"""" 
     43 
     44html5 = """\">Next Month&gt;</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
     45            <a href=\"""" 
     46 
     47html6 = """\">&lt;Previous Elevation</a>&nbsp;&nbsp;&nbsp;  
     48            <a href=\"""" 
     49 
     50html7 = """\">Next Elevation&gt;</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
     51            <a href=\"all.html\">&lt;All At Once&gt;</a> 
     52        </form> 
     53        <br/>  
     54        <img src=\"""" 
     55 
     56html8 = """\"/>  
     57    </body>  
     58</html>""" 
    2559  
    2660firstMonth = True  
     
    3670        previousMonth = previous[24:26]  
    3771        previousMonth = datetime.datetime(int(previousYear),int(previousMonth),1).strftime('%B')  
    38         previous = previous + os.extsep + htmlExt  
    3972    if next:  
    4073        next = os.path.splitext(os.path.basename(next))[0]  
     
    4275        nextMonth = next[24:26]  
    4376        nextMonth = datetime.datetime(int(nextYear),int(nextMonth),1).strftime('%B')  
    44         next = next + os.extsep + htmlExt  
    4577  
    4678    nc = pycdf.CDF(ncFile)  
     
    73105 
    74106    firstElevation = True 
    75     for x in range(0,rho.shape[0]): 
     107    indices = range(0,rho.shape[0]) 
     108    previousX = [indices[-1]] + indices[:-1]  
     109    nextX = indices[1:] + [indices[0]]  
     110    indices = zip(previousX,indices,nextX)  
     111    for previousX,x,nextX in indices: 
    76112        if rho[x].any(): 
    77113            fig = plt.figure(figsize=(8, 8), dpi=80, facecolor='w', edgecolor='w') 
     
    82118            fig.add_axes(ax) 
    83119            ax.bar(theta[x], rho[x], normed=True, opening=0.8, edgecolor='white') 
    84             l = ax.legend(axespad=-0.20
     120            l = ax.legend(axespad=-0.20,title="Magnitude (m/s)"
    85121            plt.setp(l.get_texts(), fontsize=8) 
    86122            if not os.path.exists(os.path.join(pngDir,ncFileName)): 
     
    88124            outFile = os.path.join(pngDir,ncFileName,('%dm' % z[x]) + os.extsep + pngExt)  
    89125            print 'Saving', outFile  
    90             fig.savefig(outFile)  
     126            fig.savefig(outFile) 
    91127 
     128            htmlFile = os.path.join(pngDir,ncFileName + "_" + ('%dm' % z[x]) + os.extsep + htmlExt)  
     129            html = html1 + month + " " + year 
     130            html = html + html2 + ('%dm' % z[x]) 
     131            html = html + html3 + previous + "_" + ('%dm' % z[x]) + os.extsep + htmlExt 
     132            html = html + html4 + next + "_" + ('%dm' % z[x]) + os.extsep + htmlExt 
     133            html = html + html5 + ncFileName + "_" + ('%dm' % z[previousX]) + os.extsep + htmlExt 
     134            html = html + html6 + ncFileName + "_" + ('%dm' % z[nextX]) + os.extsep + htmlExt 
     135            html = html + html7 + os.path.join(ncFileName,os.path.basename(outFile)) + html8  
     136            handle = open(htmlFile,'w')  
     137            handle.write(html)  
     138            handle.close()  
     139 
     140            if firstMonth and firstElevation:  
     141                firstMonth = False 
     142                firstElevation = False 
     143                htmlFile = os.path.join(pngDir,"index" + os.extsep + htmlExt)  
     144                handle = open(htmlFile,'w')  
     145                handle.write(html)  
     146                handle.close()  
     147