#!/usr/bin/env python # Last modified: Time-stamp: <2008-12-05 12:38:36 haines> """ims_sodar_plot_month""" # plot each month import os, sys, glob, re import datetime, time, dateutil, dateutil.tz import pycdf import numpy sys.path.append('/home/haines/nccoos/raw2proc') del(sys) os.environ["MPLCONFIGDIR"]="/home/haines/.matplotlib/" from pylab import figure, twinx, savefig, setp, getp, cm, colorbar from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, DateFormatter, date2num, num2date import procutil print 'ims_sodar2_plot_month ...' proc_dir = '/seacoos/data/nccoos/level1/ims/sodar/' fns = glob.glob((os.path.join(proc_dir, '*.nc'))) fns.sort() for fn in fns: m=re.search('\d{4}_\d{2}', fn) yyyy_mm = m.group() prev_month, this_month, next_month = procutil.find_months(yyyy_mm) # load data print ' ... ... read: ' + fn nc = pycdf.CDFMF((fn,)) ncvars = nc.variables() # print ncvars es = nc.var('time')[:] units = nc.var('time').units dt = [procutil.es2dt(e) for e in es] # set timezone info to UTC (since data from level1 should be in UTC!!) dt = [e.replace(tzinfo=dateutil.tz.tzutc()) for e in dt] # return new datetime based on computer local dt_local = [e.astimezone(dateutil.tz.tzlocal()) for e in dt] dn = date2num(dt) z = nc.var('z')[:] val1 = nc.var('val1')[:] val2 = nc.var('val2')[:] val3 = nc.var('val3')[:] spu1 = nc.var('spu1')[:] spu2 = nc.var('spu2')[:] spu3 = nc.var('spu3')[:] n1 = numpy.floor(nc.var('nois1')[:]/10.) n2 = numpy.floor(nc.var('nois2')[:]/10.) n3 = numpy.floor(nc.var('nois3')[:]/10.) s1 = numpy.floor(nc.var('snr1')[:]/10.) s2 = numpy.floor(nc.var('snr2')[:]/10.) s3 = numpy.floor(nc.var('snr3')[:]/10.) r1 = 10.*(nc.var('snr1')[:]-10.*s1) r2 = 10.*(nc.var('snr2')[:]-10.*s2) r3 = 10.*(nc.var('snr3')[:]-10.*s3) fe11 = nc.var('fe11')[:] fe12 = nc.var('fe12')[:] fe21 = nc.var('fe21')[:] fe22 = nc.var('fe22')[:] nc.close() # last dt in data for labels dt1 = dt[-1] dt2 = dt_local[-1] diff = abs(dt1 - dt2) if diff.days>0: last_dt_str = dt1.strftime("%H:%M %Z on %b %d, %Y") + ' (' + dt2.strftime("%H:%M %Z, %b %d") + ')' else: last_dt_str = dt1.strftime("%H:%M %Z") + ' (' + dt2.strftime("%H:%M %Z") + ')' \ + dt2.strftime(" on %b %d, %Y") fig = figure(figsize=(10, 8)) fig.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.9, wspace=0.1, hspace=0.1) ####################################### # Plot month ####################################### ax = fig.add_subplot(6,1,1) axs = [ax] # ax.plot returns a list of lines, so unpack tuple l1, = ax.plot_date(dt, val1, fmt='b-') l1.set_label('val1 per beam') l2, = ax.plot_date(dt, val2, fmt='c-') l2.set_label('val2') l3, = ax.plot_date(dt, val3, fmt='g-') l3.set_label('val3') ax.set_ylabel('Validations') ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) ax.set_xticklabels([]) # this only moves the label not the tick labels ax.xaxis.set_label_position('top') ax.set_xlabel('IMS SODAR -- ' + yyyy_mm) # legend ls1 = l1.get_label() ls2 = l2.get_label() ls3 = l3.get_label() leg = ax.legend((l1,l2,l3), (ls1,ls2,ls3), loc='upper left') ltext = leg.get_texts() # all the text.Text instance in the legend llines = leg.get_lines() # all the lines.Line2D instance in the legend frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend frame.set_facecolor('0.80') # set the frame face color to light gray frame.set_alpha(0.5) # set alpha low to see through setp(ltext, fontsize='small') # the legend text fontsize setp(llines, linewidth=1.5) # the legend linewidth # leg.draw_frame(False) # don't draw the legend frame ####################################### # ax = fig.add_subplot(6,1,2) axs.append(ax) # ax.plot returns a list of lines, so unpack tuple l1, = ax.plot_date(dt, spu1, fmt='b-') l1.set_label('spu1 (<=3 OK)') l2, = ax.plot_date(dt, spu2, fmt='c-') l2.set_label('spu2') l3, = ax.plot_date(dt, spu3, fmt='g-') l3.set_label('spu3') ax.set_ylabel('False\n Signal') ax.set_ylim(0,10) ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) ax.set_xticklabels([]) # legend ls1 = l1.get_label() ls2 = l2.get_label() ls3 = l3.get_label() leg = ax.legend((l1,l2,l3), (ls1,ls2,ls3), loc='upper left') ltext = leg.get_texts() # all the text.Text instance in the legend llines = leg.get_lines() # all the lines.Line2D instance in the legend frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend frame.set_facecolor('0.80') # set the frame face color to light gray frame.set_alpha(0.5) # set alpha low to see through setp(ltext, fontsize='small') # the legend text fontsize setp(llines, linewidth=1.5) # the legend linewidth # leg.draw_frame(False) # don't draw the legend frame ####################################### # ax = fig.add_subplot(6,1,3) axs.append(ax) # ax.plot returns a list of lines, so unpack tuple l1, = ax.plot_date(dt, n1, fmt='b-') l1.set_label('n1') l2, = ax.plot_date(dt, n2, fmt='c-') l2.set_label('n2') l3, = ax.plot_date(dt, n3, fmt='g-') l3.set_label('n3') ax.set_ylabel('Ambient\n Noise') ax.set_ylim(20,120) ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) ax.set_xticklabels([]) # legend ls1 = l1.get_label() ls2 = l2.get_label() ls3 = l3.get_label() leg = ax.legend((l1,l2,l3), (ls1,ls2,ls3), loc='upper left') ltext = leg.get_texts() # all the text.Text instance in the legend llines = leg.get_lines() # all the lines.Line2D instance in the legend frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend frame.set_facecolor('0.80') # set the frame face color to light gray frame.set_alpha(0.5) # set alpha low to see through setp(ltext, fontsize='small') # the legend text fontsize setp(llines, linewidth=1.5) # the legend linewidth # leg.draw_frame(False) # don't draw the legend frame ####################################### # ax = fig.add_subplot(6,1,4) axs.append(ax) # ax.plot returns a list of lines, so unpack tuple l1, = ax.plot_date(dt, s1, fmt='b-') l1.set_label('s1 SNR') l2, = ax.plot_date(dt, s2, fmt='c-') l2.set_label('s2') l3, = ax.plot_date(dt, s3, fmt='g-') l3.set_label('s3') ax.set_ylabel('Signal to \nNoise') ax.set_ylim(6, 12) ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) ax.set_xticklabels([]) # legend ls1 = l1.get_label() ls2 = l2.get_label() ls3 = l3.get_label() leg = ax.legend((l1,l2,l3), (ls1,ls2,ls3), loc='upper left') ltext = leg.get_texts() # all the text.Text instance in the legend llines = leg.get_lines() # all the lines.Line2D instance in the legend frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend frame.set_facecolor('0.80') # set the frame face color to light gray frame.set_alpha(0.5) # set alpha low to see through setp(ltext, fontsize='small') # the legend text fontsize setp(llines, linewidth=1.5) # the legend linewidth # leg.draw_frame(False) # don't draw the legend frame ####################################### # ax = fig.add_subplot(6,1,5) axs.append(ax) # ax.plot returns a list of lines, so unpack tuple l1, = ax.plot_date(dt, r1, fmt='b-') l1.set_label('BW1 (<50% bad)') l2, = ax.plot_date(dt, r2, fmt='c-') l2.set_label('BW2') l3, = ax.plot_date(dt, r3, fmt='g-') l3.set_label('BW3') ax.set_ylabel('Percent\n Total\n Bandwidth') ax.set_ylim(0,100) ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) ax.set_xticklabels([]) # legend ls1 = l1.get_label() ls2 = l2.get_label() ls3 = l3.get_label() leg = ax.legend((l1,l2,l3), (ls1,ls2,ls3), loc='upper left') ltext = leg.get_texts() # all the text.Text instance in the legend llines = leg.get_lines() # all the lines.Line2D instance in the legend frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend frame.set_facecolor('0.80') # set the frame face color to light gray frame.set_alpha(0.5) # set alpha low to see through setp(ltext, fontsize='small') # the legend text fontsize setp(llines, linewidth=1.5) # the legend linewidth # leg.draw_frame(False) # don't draw the legend frame ####################################### # ax = fig.add_subplot(6,1,6) axs.append(ax) # ax.plot returns a list of lines, so unpack tuple l1, = ax.plot_date(dt, fe11, fmt='b-') l1.set_label('fe11 (9 max)') l2, = ax.plot_date(dt, fe12, fmt='c-') l2.set_label('fe12') l3, = ax.plot_date(dt, fe21, fmt='g-') l3.set_label('fe21') l4, = ax.plot_date(dt, fe22, fmt='k-') l4.set_label('fe22') ax.set_ylabel('Number of \nfreq emitted') ax.set_ylim(0,15) ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) ax.set_xlabel('IMS SODAR -- ' + yyyy_mm) # legend ls1 = l1.get_label() ls2 = l2.get_label() ls3 = l3.get_label() ls4 = l4.get_label() leg = ax.legend((l1,l2,l3,l4), (ls1,ls2,ls3,ls4), loc='upper left') ltext = leg.get_texts() # all the text.Text instance in the legend llines = leg.get_lines() # all the lines.Line2D instance in the legend frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend frame.set_facecolor('0.80') # set the frame face color to light gray frame.set_alpha(0.5) # set alpha low to see through setp(ltext, fontsize='small') # the legend text fontsize setp(llines, linewidth=1.5) # the legend linewidth # leg.draw_frame(False) # don't draw the legend frame # save figure ofn = '/home/haines/rayleigh/img/ims/ims_sodar2_'+yyyy_mm+'.png' print '... ... write: %s' % (ofn,) savefig(ofn)