Example #1
0
def main():
    from warnings import warn
    from .pncparse import pncparse
    from PseudoNetCDF.core._functions import pncfunc, pncbfunc
    from PseudoNetCDF.pncparse import getparser, pncparse

    parser = getparser(has_ofile = False, plot_options = False, interactive = True)
    parser.add_argument('--funcs', default = __all__, type = lambda x: x.split(','), help='Functions to evaluate split by , (default: %s)' % ','.join(__all__))

    import numpy as np
    np.seterr(divide = 'ignore', invalid = 'ignore')
    ifiles, options = pncparse(has_ofile = False, interactive = True, parser = parser)
    if options.variables is None:
        options.variables = set(ifiles[0].variables.keys()).difference(options.coordkeys)
    console = createconsole(ifiles, options)
    warn("Assumes input order is obs model")
    ifile1, ifile2 = ifiles
    for k in options.funcs:
        console.locals[k] = func = eval(k)
        console.locals[k+'_f'] = ofile = pncbfunc(func, ifile1, ifile2)
        times = ifile1.variables['time']
        tstart = times[:].min()
        tstop = times[:].max()
        dt = tstop - tstart
        for vk in options.variables:
            if vk in ('time', 'TFLAG'): continue
            print('%.2f,%.2f,%.2f,%s,%s,%s,%f' % (tstart, tstop, dt, vk, func.__doc__.strip(), k, ofile.variables[vk].ravel()[0]))
    np.seterr(divide = 'warn', invalid = 'warn')
    if options.interactive:
        console.interact()
Example #2
0
                        help = "Use quartiles to set range (xmin, xmax); defaults 0,100.")

    parser.add_argument("--out-unit", dest = "outunit", type = str, default = 'ppb',
                        help = "Defaults ppb.")

    parser.add_argument("--tes-paths", dest = "tespaths", type = str, default = [], action = "append",
                        help = "Plot tes on top of boundary from paths; defaults to []")

    parser.add_argument("--omi-paths", dest = "omipaths", type = str, default = [], action = "append",
                        help = "Plot omi on top of boundary from paths; defaults to []")

    parser.add_argument("--itertime", dest = "itertime", default = False, action = 'store_true',
                        help = "Iterate over times and plot each one.")
                        
    parser.add_argument("--edges", dest = "edges", default = False, action = "store_true",
                        help = "Plot S,E,N,W edges instead of a single plot.")
    parser.epilog = """
Example:
    $ pncvertprofile.py outputs/ts20120301.bpch.BCON.nc test_profile -v O3  --edges --minmaxq .5,99.5 --tes-paths=~/Data/test/*
"""
    
    ifiles, args = pncparse(has_ofile = True, parser = parser)
    if args.variables is None:
        raise ValueError('User must specify variable(s) to plot:\n%s' % '\n\t'.join(ifiles[0].variables.keys()))
    if len(args.tespaths) > 0:
        args.tespaths = reduce(list.__add__, [tp.split(',') for tp in args.tespaths])
        
    if len(args.omipaths) > 0:
        args.omipaths = reduce(list.__add__, [op.split(',') for op in args.omipaths])
    plot(ifiles, args)
Example #3
0
                extend = 'neither'
            cbar = fig.colorbar(patches, orientation = orientation, cax = cax, extend = extend, format = formatter)
            del cbar.ax.texts[:]
            cbar.set_label(varkey + ' (' + varunit + '; min=%.3g; max=%.3g)' % (var[:].min(), var[:].max()))
 #           if orientation == 'vertical':
 #               cbar.ax.text(.5, 1.05, '%.3g' % var[:].max(), horizontalalignment = 'center', verticalalignment = 'bottom')
#                cbar.ax.text(.5, -.06, '%.3g ' % var[:].min(), horizontalalignment = 'center', verticalalignment = 'top')
#            else:
#                cbar.ax.text(1.05, .5, ' %.3g' % var[:].max(), verticalalignment = 'center', horizontalalignment = 'left')
#                cbar.ax.text(-.06, .5, '%.3g ' % var[:].min(), verticalalignment = 'center', horizontalalignment = 'right')
            #cbar.update_ticks()
            fmt = 'png'
            outpath = options.outpath
            if len(ifiles) > 1:
                
                outpath += ('_%%0%dd' % len(str(len(ifiles)))) % fi
            figpath = os.path.join(outpath + varkey + '.' + fmt)
            if options.interactive:
                csl = PNCConsole(locals = globals())
                csl.interact()
            
            fig.savefig(figpath)
            print('Saved fig', figpath)
        
if __name__ == '__main__':
    from PseudoNetCDF.pncparse import pncparse, getparser
    parser = getparser(has_ofile = True, plot_options = True, interactive = True)
    parser.add_argument('--swapaxes', action = 'store_true', help = 'Swap x-y axes')
    ifiles, options = pncparse(has_ofile = True, plot_options = True, interactive = True, parser = parser)
    make2d(ifiles, options)
Example #4
0
    rectangles = [plt.Rectangle((0, 0), 1, 1, color = ubc) for ubc in ubcs]
    fig.legend(rectangles, labels, ncol = 3, bbox_to_anchor = (.5, 0.025), loc = 'lower center')
    ticks = np.linspace(0, args.maxpct, 6)[1:]
    labels = ['%s%%' % i for i in ticks]
    plt.yticks(ticks, labels)
    ax.set_rmax(args.maxpct)
    ax.set_clip_on(False)
    fig.savefig(args.outpath)
    plt.close(fig)
    
if __name__ == '__main__':
    from PseudoNetCDF.pncparse import getparser, pncparse
    parser = getparser(has_ofile = True, plot_options = False, interactive = False)
    parser.add_argument('--wind-speed', dest = 'windspeed', default = 'WS', help = 'Wind speed variable')
    parser.add_argument('--mask-var', dest = 'maskvar', default = 'WS', help = 'Variable from file two for masking')
    parser.add_argument('--wind-dir', dest = 'winddir', default = 'WD', help = 'Wind direction variable')
    parser.add_argument('--title', default = None, help = 'Title for wind rose')
    parser.add_argument('--binwidth', dest = 'binwidth', type = float, default = 45., help = 'Direction bin widths in degrees.')
    parser.add_argument('--max-pct', dest = 'maxpct', type = float, default = 50., help = 'Maximum percent on plot')
    parser.add_argument('--fromnorth', dest = 'fromnorth', action = 'store_true', default = False, help = 'Bins should start from north (i.e., not bound north)')
    parser.add_argument('--bounds', dest = 'bounds', type = lambda x: np.array(eval(x)), default = np.array([1, 2, 3, 5, 10, np.inf]), help = 'Boundaries for wind speed')
    parser.epilog = """
Example:
    $ pncwindrose.py -s time,600,None --max-pct=35 --wind-dir wd --wind-speed ws  --mask-var="ws[:].mask.all(0)[None,:].repeat(ws.shape[0], 0)" --bounds="[0.5,1,2,3.5,4.5,6.5,np.inf]"  --title obs  Bogota_2012_s12345.nc df.nc oct_obs

Description:
    Create windrose for timestep 600 and on where wind-direction is name wd, and windspeed is named ws. Masking is applied from df.nc file where all times for ws are masked (useful for ignoring monitors). Values less than 0.5 will be masked.
"""
    ifiles, args = pncparse(has_ofile = True, plot_options = False, interactive = False, args = None, parser = parser)
    out = pncwindrose(ifiles, args)