Ejemplo n.º 1
0
def SVM(X, Y, ktype): 

	svmScores = []
	kf = KFold(n=len(Y), n_folds = nfolds)
	for train_index, test_index in kf:
		X_train, X_test = X[train_index], X[test_index]
		y_train, y_test = Y[train_index], Y[test_index]

		# SVC fit
		clf = svm.SVC(C=1.0, kernel= ktype)
		clf.fit(X_train, y_train)
		svmScores.append(clf.score(X_test, y_test))

		print "scores" , svmScores
		
		xx, yy = np.meshgrid(np.linspace(-10, 10, 500), np.linspace(-10, 10, 500))

		Z = clf.decision_function(np.c_[xx.ravel(), yy.ravel()])
		Z = Z.reshape(xx.shape)

		plt.contourf(xx, yy, Z, levels=np.linspace(Z.min(), 0, 7), cmap=pl.cm.Blues_r)
		a = pl.contour(xx, yy, Z, levels=[0], linewidths=2, colors='red')
		pl.contourf(xx, yy, Z, levels=[0, Z.max()], colors='orange')

		colors = ['w' if i == 0 else 'k' for i in Y]
		plt.scatter(X[:,0], X[:,1], color = colors, alpha=1.0)

		# Plt that plot yoz. and make the xylim not shitty
		plt.xlim([np.min(X)-5,np.max(X)+5])
		plt.ylim([np.min(X)-5,np.max(X)+5])
		plt.show()
Ejemplo n.º 2
0
def Contour(X,Y,Z, label='', levels=None, cmapidx=0, colors=None, fmt='%g', lwd=1, fsz=10,
        inline=0, wire=True, cbar=True, zorder=None, markZero='', clabels=True):
    """
    Plot contour
    ============
    """
    L = None
    if levels != None:
        if not hasattr(levels, "__iter__"): # not a list or array...
            levels = linspace(Z.min(), Z.max(), levels)
    if colors==None:
        c1 = contourf (X,Y,Z, cmap=Cmap(cmapidx), levels=levels, zorder=None)
    else:
        c1 = contourf (X,Y,Z, colors=colors, levels=levels, zorder=None)
    if wire:
        c2 = contour (X,Y,Z, colors=('k'), levels=levels, linewidths=[lwd], zorder=None)
        if clabels:
            clabel (c2, inline=inline, fontsize=fsz)
    if cbar:
        cb = colorbar (c1, format=fmt)
        cb.ax.set_ylabel (label)
    if markZero:
        c3 = contour(X,Y,Z, levels=[0], colors=[markZero], linewidths=[2])
        if clabels:
            clabel(c3, inline=inline, fontsize=fsz)
Ejemplo n.º 3
0
        def doSubplot(multiplier=1.0, layout=(-1, -1)):
            pylab.contour(xs, ys, vr_obs[0][bounds], colors='k', linestyles='-', levels=np.arange(-50, 60, 10))
            pylab.contour(xs, ys, model_obs['vr'][0][bounds], colors='k', linestyles='--', levels=np.arange(-50, 60, 10))
            pylab.contourf(xs, ys, (model_obs['vr'][0] - vr_obs[0])[bounds], cmap=matplotlib.cm.get_cmap('RdBu_r'), zorder=-1)

            grid.drawPolitical()
            return
Ejemplo n.º 4
0
def plotData():
    marr = fetchData()
    textsize = 18

    yticks([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], xt, size=textsize)
    ylabel("Periode [s]", size=textsize)
    xticks([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], yt, size=textsize)
    xlabel("Ausstattung [%]", size=textsize)
    title(
        "Abweichung der Geschwindigkeit zwischen FCD und des simulierten Verkehrs", size=textsize)
    # title("Relative Anzahl erfasster Kanten", size=textsize)
    figtext(0.7865, 0.92, '[%]', size=textsize)

    # levels=arange(mmin-mmin*.1, mmax+mmax*.1, (mmax-mmin)/10.))
    contourf(marr, 50)
    # set fontsize and ticks for the colorbar:
    if showVal == EDGENO:
        cb = colorbar(ticks=[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100])
    else:
        # cb = colorbar(ticks=range(17))
        cb = colorbar()
    for t in cb.ax.get_yticklabels():  # set colorbar fontsize of each tick
        t.set_fontsize(textsize)

    show()
Ejemplo n.º 5
0
def main():
    base_path = "/caps2/tsupinie/1kmf-control/"
    temp = goshen_1km_temporal(start=14400, end=14400)
    grid = goshen_1km_grid()
    n_ens_members = 40

    np.seterr(all='ignore')

    ens = loadEnsemble(base_path, [ 11 ], temp.getTimes(), ([ 'pt', 'p' ], computeDensity))
    ens = ens[0, 0]

    zs = decompressVariable(nio.open_file("%s/ena001.hdfgrdbas" % base_path, mode='r', format='hdf').variables['zp'])
    xs, ys = grid.getXY()
    xs = xs[np.newaxis, ...].repeat(zs.shape[0], axis=0)
    ys = ys[np.newaxis, ...].repeat(zs.shape[0], axis=0)

    eff_buoy = effectiveBuoyancy(ens, (zs, ys, xs), plane={'z':10})
    print eff_buoy

    pylab.figure()
    pylab.contourf(xs[0], ys[0], eff_buoy[0], cmap=matplotlib.cm.get_cmap('RdBu_r'))
    pylab.colorbar()

    grid.drawPolitical()

    pylab.suptitle("Effective Buoyancy")
    pylab.savefig("eff_buoy.png")
    pylab.close()
    return
def render(
    src: array,
    height: int,
    width: int,
    isostep: int,
    dpi: int,
    output_file_path: Path,
) -> None:

    height = height // MAP_SCALE
    width = width // MAP_SCALE

    image_size = (
        (width / dpi),
        (height / dpi),
    )

    data = np.array(src).reshape((height, width))
    isohypses = list(range(0, data.max(), isostep))

    plt.clf()
    plt.axis('off')
    plt.figure(dpi=dpi)

    fig = plt.figure(figsize=image_size, frameon=False)
    fig.add_axes([0, 0, 1, 1])

    contourf(data, 256, cmap=CMAP)
    contour(data, isohypses, colors=ISOHYPSE_COLOR, linewidths=ISOHYPSE_WIDTH)

    output_file_path.parent.parent.mkdir(parents=True, exist_ok=True)
    plt.savefig(str(output_file_path), bbox_inches=0, dpi=dpi)
Ejemplo n.º 7
0
def plotSurface(pt, td, winds, map, stride, title, file_name):
    pylab.figure()
    pylab.axes((0.05, 0.025, 0.9, 0.9))

    u, v = winds

    nx, ny = pt.shape
    gs_x, gs_y = goshen_3km_gs
    xs, ys = np.meshgrid(gs_x * np.arange(nx), gs_y * np.arange(ny))   

    data_thin = tuple([ slice(None, None, stride) ] * 2)

    td_cmap = matplotlib.cm.get_cmap('Greens')
    td_cmap.set_under('#ffffff')
    pylab.contourf(xs, ys, td, levels=np.arange(40, 80, 5), cmap=td_cmap)
    pylab.colorbar()
    CS = pylab.contour(xs, ys, pt, colors='r', linestyles='-', linewidths=1.5, levels=np.arange(288, 324, 4))
    pylab.clabel(CS, inline_spacing=0, fmt="%d K", fontsize='x-small')
    pylab.quiver(xs[data_thin], ys[data_thin], u[data_thin], v[data_thin])

    drawPolitical(map, scale_len=75)

    pylab.suptitle(title)
    pylab.savefig(file_name)
    pylab.close()
    return
Ejemplo n.º 8
0
def main():
    zbar = 0.7
    vbar = 500  # km/s comoving distance
    ncc = 1024
    npp = 200000  # total mass = 1e9*2e5 M_sun/h
    bsz = 3.0  # Mpc/h comoving distance

    file_particles = sys.argv[1]

    sdens = call_sph_sdens(file_particles, bsz, ncc, npp)
    sdens.astype(np.float32).tofile("./output_files/cnfw_sdens.bin")

    ksz_map = ksz_based_on_sdens(zbar, vbar, sdens)
    # ---------------------------
    # Save 2d array to a binary file.
    ksz_map.astype(np.float32).tofile("./output_files/cnfw_ksz.bin")
    # ---------------------------

    # ---------------------------
    # Read the output binary files.
    a0 = np.fromfile("./output_files/cnfw_ksz.bin", dtype=np.float32)
    a0 = a0.reshape((ncc, ncc))
    # ---------------------------

    # ---------------------------
    # Plot the contours
    import pylab as pl

    pl.contourf(np.log10(a0))
    pl.colorbar()
    pl.show()

    return 0
Ejemplo n.º 9
0
  def __init__(self, name, nx, ng, np, opts={}):
    Callback.__init__(self)

    self.nx = nx
    self.ng = ng
    self.np = np

    opts['input_scheme'] = nlpsol_out()
    opts['output_scheme'] = ['ret']

    figure(1)
    subplot(111)
    
    x_,y_ = mgrid[-1:1.5:0.01,-1:1.5:0.01]
    z_ = DM.zeros(x_.shape)
    
    for i in range(x_.shape[0]):
      for j in range(x_.shape[1]):
        z_[i,j] = fcn(x_[i,j],y_[i,j])
    contourf(x_,y_,z_)
    colorbar()
    title('Iterations of Rosenbrock')
    draw()
    
    self.x_sols = []
    self.y_sols = []

    # Initialize internal objects
    self.construct(name, opts)
Ejemplo n.º 10
0
def postplot(x,y,arr,plottitle,showplot=True):
    """ Post process in 2D"""
    levels = linspace(min(arr.ravel())*0.9,max(arr.ravel())*1.1,50)
    contourf(x,y,arr.T,levels=levels);
    title(plottitle); colorbar();
    show()
    return
def ScatterWithLinearSVC(X_,class_,C_,TrainedSVC,Labels_):
    ##"Train" the data, aka fit with vectorial distance to a line, since we are using a linear kernel
    ## Here we essentially minimize the total distance that each point is to a decision boundary
    ## Based on which side of the boundary the point lies (if distance is "positive" or "negative"), the decision is made
    #TrainedSVC = SVC(C = C_, kernel = 'linear').fit(X_,class_)
    if np.shape(X_)[1] >2:
        print "X is larger than 2!"
    Xvalues=X_[:,0]
    Yvalues=X_[:,1]
    xmax, ymax, xmin,ymin =Xvalues.max(), Yvalues.max(), Xvalues.min(), Yvalues.min()
    binning=100.
    ### Make a big grid of coordinates, as a matrix of X positions and a matrix of y positions
    X, Y = np.meshgrid(np.arange(xmin,xmax, (xmax-xmin)/binning),
                       np.arange(ymin,ymax, (ymax-ymin)/binning))
    ### Ravel the X and Y matrices up into vectors, put them together, and feed them to the predict function
    GridPredictions=TrainedSVC.predict(np.c_[X.ravel(), Y.ravel()])
    ### Re-form a matrix of Grid predictions
    GridPredictions=np.reshape(GridPredictions,np.shape(X))
    ### Plot a contour, with coloring each area, fading to 1/3 of the color "strength"
    fig=plt.figure()
    plt.contourf(X,Y,GridPredictions,alpha=0.33)
    plt.scatter(Xvalues, Yvalues,c=class_)   
    plt.scatter(Xvalues, Yvalues,c=class_)   
    plt.ylabel(Labels_[0])
    plt.xlabel(Labels_[1])
    #plt.legend([GridPredictions], ["Training accuracy"])

    fig.savefig('result.png')
Ejemplo n.º 12
0
        def doSubplot(multiplier=1.0, layout=(-1, -1)):
            exp_vort = cPickle.load(open("vort_time_height_%s.pkl" % exp[5:], 'r'))
            vort_data[exp] = exp_vort
            print "Max vorticity:", exp_vort.max()

            cmap = cm.get_cmap('RdYlBu_r')
            cmap.set_under('#ffffff')

#           pylab.pcolormesh(boundCoordinate(np.array(temp.getTimes())), boundCoordinate(z_column / 1000.), exp_vort.T, cmap=cmap, vmin=min_vorticity, vmax=max_vorticity)
            pylab.contourf(temp.getTimes(), z_column / 1000., exp_vort.T, cmap=cmap, levels=np.arange(min_vorticity, max_vorticity + 0.0024, 0.0025))

            pylab.xlim(temp.getTimes()[0], temp.getTimes()[-1])
            pylab.ylim([z_column[0] / 1000, 10])

            layout_r, layout_c = layout
            if layout_r == 2 and layout_c == 1 or layout_r == -1 and layout_c == -1:
                pylab.xlabel("Time (UTC)", size='large')
                pylab.ylabel("Height (km MSL)", size='large')

#           pylab.axvline(14400, color='k', linestyle=':')

                pylab.xticks(temp.getTimes(), temp.getStrings('%H%M', aslist=True), size='large')
                pylab.yticks(size='large')
            else:
                pylab.xticks(temp.getTimes(), [ '' for t in temp ])
                pylab.yticks(pylab.yticks()[0], [ '' for z in pylab.yticks()[0] ])

            pylab.text(0.05, 0.95, experiments[exp], ha='left', va='top', transform=pylab.gca().transAxes, size=18 * multiplier)
            pylab.xlim(temp.getTimes()[0], temp.getTimes()[3])
            pylab.ylim([z_column[1] / 1000, 6])
#           pylab.title(exp)
            return
Ejemplo n.º 13
0
def plot_function_contour(x, y, function, **kwargs):
    """Make a contour plot of a function of two variables.

    Parameters
    ----------
    x, y : array_like of float
        The positions of the nodes of a plotting grid.
    function : function
        The function to plot.
    filling : bool
        Fill contours if True (default).
    num_contours : int
        The number of contours to plot, 50 by default.
    xlabel, ylabel : str, optional
        The axes labels. Empty by default.
    title : str, optional
        The title. Empty by default.

    """
    X, Y = numpy.meshgrid(x, y)
    Z = []
    for y_value in y:
        Z.append([])
        for x_value in x:
            Z[-1].append(function(x_value, y_value))
    Z = numpy.array(Z)
    num_contours = kwargs.get('num_contours', 50)
    if kwargs.get('filling', True):
        pylab.contourf(X, Y, Z, num_contours, cmap=pylab.cm.jet)
    else:
        pylab.contour(X, Y, Z, num_contours, cmap=pylab.cm.jet)
    pylab.xlabel(kwargs.get('xlabel', ''))
    pylab.ylabel(kwargs.get('ylabel', ''))
    pylab.title(kwargs.get('title', ''))
Ejemplo n.º 14
0
def plotComparison(ens_mean, ens_ob_mean, ens_ob_std, obs, ob_locations, refl, grid, levels, cmap, title, file_name):
    max_std = 5.0

    xs, ys = grid.getXY()
    obs_xs, obs_ys = grid(*ob_locations)

    clip_box = Bbox([[0, 0], [1, 1]])

    pylab.figure()

    pylab.contourf(xs, ys, ens_mean, cmap=cmap, levels=levels)
    pylab.colorbar()

    pylab.contour(xs, ys, refl, colors='k', levels=np.arange(20, 80, 20))

    for ob_x, ob_y, ob, ob_mean, ob_std in zip(obs_xs, obs_ys, obs, ens_ob_mean, ens_ob_std):
        color_bin = np.argmin(np.abs(ob - levels))
        if ob > levels[color_bin]: color_bin += 1
        color_level = float(color_bin) / len(levels)

        ob_z_score = (ob - ob_mean) / ob_std

        print "Ob z-score:", ob_z_score, "Ob:", ob, "Ob mean:", ob_mean, "Ob std:", ob_std

        pylab.plot(ob_x, ob_y, 'ko', markerfacecolor=cmap(color_level), markeredgecolor=std_cmap(ob_z_score / max_std), markersize=4, markeredgewidth=1)
#       pylab.text(ob_x - 1000, ob_y + 1000, "%5.1f" % temp_K, ha='right', va='bottom', size='xx-small', clip_box=clip_box, clip_on=True)

    grid.drawPolitical()

    pylab.suptitle(title)
    pylab.savefig(file_name)
    pylab.close()
    return
Ejemplo n.º 15
0
def main():
    buffer_width=40000
    reports = loadReports("snowfall_2013022600_m.txt")
#   map = Basemap(projection='lcc', resolution='i', area_thresh=10000.,
#                 llcrnrlat=20., llcrnrlon=-120., urcrnrlat=48., urcrnrlon=-60.,
#                 lat_0=34.95, lon_0=-97.0, lat_1=30., lat_2=60.)

    map = Basemap(projection='lcc', resolution='i', area_thresh=10000.,
                  llcrnrlat=25., llcrnrlon=-110., urcrnrlat=40., urcrnrlon=-90.,
                  lat_0=34.95, lon_0=-97.0, lat_1=30., lat_2=60.)

    width, height = map(map.urcrnrlon, map.urcrnrlat)
    report_xs, report_ys = map(reports['longitude'], reports['latitude'])

    keep_idxs = np.where((report_xs >= -buffer_width) & (report_xs <= width + buffer_width) & (report_ys >= -buffer_width) & (report_ys <= height + buffer_width))

    spacing = findAvgStationSpacing(*map(reports['longitude'][keep_idxs], reports['latitude'][keep_idxs]))

    dx = dy = floor(spacing * 0.75 / 2000) * 2000
    print dx, dy
    xs, ys = np.meshgrid(np.arange(0, width, dx), np.arange(0, height, dy))

    grid = griddata((report_xs[keep_idxs], report_ys[keep_idxs]), reports['amount'][keep_idxs], (xs, ys))

    pylab.contourf(xs, ys, grid / 2.54, levels=np.arange(2, 22, 2), cmap=pylab.cool())
    pylab.colorbar(orientation='horizontal')

    map.drawcoastlines()
    map.drawcountries()
    map.drawstates()
    pylab.savefig("snow.png")
    return
Ejemplo n.º 16
0
        def doSubplot(multiplier=1.0, layout=(-1, -1)):
            data = cPickle.load(open("cold_pool_%s.pkl" % exp, 'r'))
            wdt = temporal.getTimes().index(time_sec)

            try:
                mo = ARPSModelObsFile("%s/%s/KCYSan%06d" % (base_path, exp, time_sec))
            except AssertionError:
                mo = ARPSModelObsFile("%s/%s/KCYSan%06d" % (base_path, exp, time_sec), mpi_config=(2, 12))
            except:
                print "Can't load reflectivity ..."
                mo = {'Z':np.zeros((1, 255, 255), dtype=np.float32)}

            cmap = matplotlib.cm.get_cmap('Blues_r')
            cmap.set_over('#ffffff')
#           cmap.set_under(tuple( cmap._segmentdata[c][0][-1] for c in ['red', 'green', 'blue'] ))
#           cmap.set_under(cmap[0])

            xs, ys = grid.getXY()
#           pylab.pcolormesh(xs, ys, data['t'][2][domain_bounds], cmap=cmap, vmin=288., vmax=295.)
            pylab.contour(xs, ys, mo['Z'][0][domain_bounds], levels=np.arange(10, 80, 10), colors='k', zorder=10)
            pylab.contourf(xs, ys, data['t'][wdt][domain_bounds], levels=range(289, 296), cmap=cmap)

            grid.drawPolitical(scale_len=10)

#           pylab.plot(track_xs, track_ys, 'mv-', lw=2.5, mfc='k', ms=8)

            pylab.text(0.05, 0.95, experiments[exp], ha='left', va='top', transform=pylab.gca().transAxes, size=14 * multiplier)
            return
def main():

    nnn = 512
    boxsize = 4.0
    dsx = boxsize/nnn
    xi1 = np.linspace(-boxsize/2.0,boxsize/2.0-dsx,nnn)+0.5*dsx
    xi2 = np.linspace(-boxsize/2.0,boxsize/2.0-dsx,nnn)+0.5*dsx
    xi1,xi2 = np.meshgrid(xi1,xi2)

    #----------------------------------------------------
    # lens parameters for main halo
    xlc1 = 0.0
    xlc2 = 0.0
    ql0 = 0.799999999999
    rc0 = 0.100000000001
    re0 = 1.0
    phi0 = 0.0

    g_ycen = 0.0
    g_xcen = 0.0

    phi,td,ai1,ai2,kappa,mu,yi1,yi2 = nie_all(xi1,xi2,xlc1,xlc2,re0,rc0,ql0,phi0,g_ycen,g_xcen)

    pl.figure(figsize=(10,10))
    pl.contourf(td)
    pl.show()
Ejemplo n.º 18
0
def trainStep(fnn, trainer, trndata, tstdata):
    trainer.trainEpochs(1)
    trnresult = percentError(trainer.testOnClassData(), trndata["class"])
    tstresult = percentError(trainer.testOnClassData(dataset=tstdata), tstdata["class"])

    print "epoch: %4d" % trainer.totalepochs, "  train error: %5.2f%%" % trnresult, "  test error: %5.2f%%" % tstresult

    out = fnn.activateOnDataset(griddata)
    out = out.argmax(axis=1)  # the highest output activation gives the class
    out = out.reshape(X.shape)

    figure(1)
    ioff()  # interactive graphics off
    clf()  # clear the plot
    hold(True)  # overplot on
    for c in [0, 1, 2]:
        here, _ = where(trndata["class"] == c)
        plot(trndata["input"][here, 0], trndata["input"][here, 1], "o")
    if out.max() != out.min():  # safety check against flat field
        contourf(X, Y, out)  # plot the contour
    ion()  # interactive graphics on
    draw()  # update the plot

    figure(2)
    ioff()  # interactive graphics off
    clf()  # clear the plot
    hold(True)  # overplot on
    for c in [0, 1, 2]:
        here, _ = where(tstdata["class"] == c)
        plot(tstdata["input"][here, 0], tstdata["input"][here, 1], "o")
    if out.max() != out.min():  # safety check against flat field
        contourf(X, Y, out)  # plot the contour
    ion()  # interactive graphics on
    draw()  # update the plot
Ejemplo n.º 19
0
 def plot(self,scatter=None,screen=True,out=None):
     """ Plot the VLEP landscape. """
     X = np.linspace(0.5,3.2,100)
     Y = np.linspace(-2,1.4,100)
     Z=np.zeros((100,100))
     for i,x in enumerate(X):
         for j,y in enumerate(Y):
             Z[j,i]=self._function(x,y)
             
     pl.contourf(X,Y,Z,100)
     pl.hot()
     
     if scatter!=None:
         pl.scatter(scatter[0,:],scatter[1,:],color='b')
     #if plot!=None:
         #pl.plot(plot[0,:],plot[1,:],color='y')
         #pl.scatter(plot[0,:],plot[1,:],color='y')
         
     if screen==True:
         pl.show()
     else:
         assert out!=None
         pl.savefig(out)
         pl.clf()
     self.it+=1
Ejemplo n.º 20
0
 def view_pcem(self,PCEM):
   nbins = np.sqrt(len(PCEM))
   levels=[0.0,0.01,0.02,0.03,0.04,0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5]
   #levels2=[0.0,0.01,0.05,0.1,0.2,0.3,0.4,0.5,1.0]
 
   T1 = PCEM[:,0].reshape( (nbins,nbins))
   T2 = PCEM[:,1].reshape( (nbins,nbins))
   E  = PCEM[:,2].reshape( (nbins,nbins))
   EC  = PCEM[:,3].reshape( (nbins,nbins))
   M  = PCEM[:,4].reshape( (nbins,nbins))
   pp.figure()
   pp.subplot(1,2,1)
   pp.contour( T1, T2, E, levels,linewidths=0.5,colors="k",linestyles='solid'  )
   pp.contourf( T1, T2, E, levels, alpha=0.75  )
   pp.xlabel( "proposal")
   pp.ylabel( "current")
   pp.title( "Error" )
   pp.colorbar()
   # pp.subplot(1,3,2)
   # pp.contour( T1, T2, EC, levels,linewidths=0.5,colors="k",linestyles='solid'  )
   # pp.contourf( T1, T2, EC, levels, alpha=0.75  )
   # pp.xlabel( "proposal")
   # pp.ylabel( "current")
   # pp.colorbar()
   # pp.title( "Corrected Error" )
   pp.subplot(1,2,2)
   pp.contour( T1, T2, M, 20,linewidths=1.0,colors="k",linestyles='solid'  )
   pp.contourf( T1, T2, M, 20  )
   pp.xlabel( "proposal")
   pp.ylabel( "current")
   pp.colorbar()
   pp.title("MU Z")
Ejemplo n.º 21
0
        def doSubplot(multiplier=1.0, layout=(-1, -1)):
            if time_sec < 16200:
                xs, ys = xs_1, ys_1
                domain_bounds = bounds_1sthalf
                grid = grid_1
            else:
                xs, ys = xs_2, ys_2
                domain_bounds = bounds_2ndhalf
                grid = grid_2

            try:
                mo = ARPSModelObsFile("%s/%s/KCYS%03dan%06d" % (base_path, exp, min_ens, time_sec))
            except AssertionError:
                mo = ARPSModelObsFile("%s/%s/KCYS%03dan%06d" % (base_path, exp, min_ens, time_sec), mpi_config=(2, 12))
            except:
                print "Can't load reflectivity ..."
                mo = {'Z':np.zeros((1, 255, 255), dtype=np.float32)}

            pylab.contour(xs, ys, wind[exp]['w'][wdt][domain_bounds], levels=np.arange(2, 102, 2), styles='-', colors='k')
            pylab.contour(xs, ys, wind[exp]['w'][wdt][domain_bounds], levels=np.arange(-100, 0, 2), styles='--', colors='k')

            pylab.quiver(xs[thin], ys[thin], wind[exp]['u'][wdt][domain_bounds][thin], wind[exp]['v'][wdt][domain_bounds][thin])

            pylab.contourf(xs, ys, mo['Z'][0][domain_bounds], levels=np.arange(10, 85, 5), cmap=NWSRef, zorder=-10)

            grid.drawPolitical(scale_len=10)

            row, col = layout
            if col == 1:
                pylab.text(-0.075, 0.5, exp_names[exp], transform=pylab.gca().transAxes, rotation=90, ha='center', va='center', size=12 * multiplier)
Ejemplo n.º 22
0
def makemap( name, 
             bamfile,
             window,
             stride, 
             highest,
             lowest,
             bins ) :
    """
    This function drives the genome map making workflow.
    """
    import pylab 

    logfile = name + '.mapmaker.log'
    mapfile = name + '.map.gff'
    
    pique.msg( logfile, 'starting mapmaker for project : ' + name )
    
    pique.msg( logfile, '  -> BAM file    : ' + bamfile      )
    pique.msg( logfile, '  -> map file    : ' + mapfile      )
    pique.msg( logfile, '  -> window      : ' + str(window)  )
    pique.msg( logfile, '  -> stride      : ' + str(stride)  )
    pique.msg( logfile, '  -> bins        : ' + str(bins)    )
    pique.msg( logfile, '  -> highest bin : ' + str(highest) )
    pique.msg( logfile, '  -> lowest bin  : ' + str(lowest)  )
    
    pique.msg( logfile, 'loading data...' )
    
    data = pique.fileIO.loadBAM( bamfile )
    
    pique.msg( logfile, '  found contigs :' )
    
    for contig in data.keys() :
        pique.msg( logfile, '    ' + contig )
        pique.msg( logfile, '      ' + str(len(data[contig]['forward'])) )
    
    pique.msg( logfile, 'making spectral histograms...' )
    
    sh = {}
    for contig in data.keys() :
        pique.msg( logfile, '  :: making sectral histogram for contig ' + contig )
        d = numpy.array( data[contig]['forward'] + data[contig]['reverse'], dtype = int )
        sh[contig] = pique.mapmaker.hist(   d,
                                            lowest,
                                            highest,
                                            bins,
                                            window,
                                            stride     )
    
    # save images of spectral histograms
    pique.msg( logfile, 'saving images of spectral histograms...' )
    
    for contig in sh.keys() :
        pylab.cla() # clean up crumbs from last plot
        pylab.clf() # clean up crumbs from last plot
        pique.msg( logfile, '  :: saving image for contig ' + contig )
        pylab.contourf( sh[contig], bins )
        pylab.title( name + ' : ' + contig )
        imgname = name + '_' + contig + '.png'
        pylab.savefig( imgname, format='png' )
Ejemplo n.º 23
0
def main():
    base_path = "/caps2/tsupinie/"
    ap = argparse.ArgumentParser()
    ap.add_argument('--exp-name', dest='exp_name', required=True)

    args = ap.parse_args()

    n_ens_members = 40
    exp_name = args.exp_name

    bounds_obs = (slice(100, 180), slice(90, 170))
    grid_obs = goshen_1km_grid(bounds=bounds_obs)

    bounds = (slice(None), slice(None))
    grid = goshen_1km_grid(bounds=bounds)

    temp = goshen_1km_temporal(start=14400)

    obs_file_names = ['psu_straka_mesonet.pkl', 'ttu_sticknet.pkl', 'asos.pkl']
    all_obs = loadObs(obs_file_names, temp.getDatetimes(aslist=True), grid_obs, grid_obs.getWidthHeight())
    obs_xy = np.vstack(grid(all_obs['longitude'], all_obs['latitude'])).T

    ens = loadEnsemble("/caps2/tsupinie/%s/" % exp_name, n_ens_members, temp.getTimes(), (['u', 'v', 'pt', 'p', 'qv'], getTempDewpRefl), {'sigma':2}, agl=True, wrap=True) 

    grid_xs, grid_ys = grid.getXY()
    obs_t_verif = []
    for wdt, (time_sec, time_epoch) in enumerate(zip(temp, temp.getEpochs())):

        try:
            mo = ARPSModelObsFile("%s/%s/KCYSan%06d" % (base_path, exp_name, time_sec))
        except AssertionError:
            mo = ARPSModelObsFile("%s/%s/KCYSan%06d" % (base_path, exp_name, time_sec), mpi_config=(2, 12))
        except:
            print "Can't load reflectivity ..."
            mo = {'Z':np.zeros((1, 255, 255), dtype=np.float32)}

        time_ob_idxs = np.where(all_obs['nom_time'] == time_epoch)[0]

        time_obs = all_obs[time_ob_idxs]
        time_obs_xy = obs_xy[time_ob_idxs]

        obs_intrp = griddata(time_obs_xy, 5. / 9. * (time_obs['temp'] - 32) + 273.15, (grid_xs, grid_ys))
        print np.isfinite(obs_intrp).sum()

        pylab.figure()

        pylab.contourf(grid_xs, grid_ys, ens['t'][:, wdt].mean(axis=0)[bounds] - obs_intrp, levels=np.arange(-6, 6.5, 0.5), cmap=matplotlib.cm.get_cmap("RdBu_r"))
        pylab.colorbar()

        pylab.contour(grid_xs, grid_ys, mo['Z'][0][tuple(reversed(bounds))], levels=np.arange(10, 80, 10), colors='k')

        grid.drawPolitical()

        pylab.savefig("obs_verif/obs_%s_t_grid_%06d.png" % (exp_name[5:], time_sec))
        pylab.close()
        obs_t_verif.append(ens['t'][:, wdt].mean(axis=0) - obs_intrp)

    cPickle.dump(np.array(obs_t_verif), open("obs_verif/obs_verif_%s.pkl" % exp_name, 'w'), -1)
    return
Ejemplo n.º 24
0
def plot_options(K_vals, sigma_vals, prices):
    """Make a contour plot of the option prices."""
    import pylab
    pylab.contourf(sigma_vals, K_vals, prices)
    pylab.colorbar()
    pylab.title("Option Price")
    pylab.xlabel("Volatility")
    pylab.ylabel("Strike Price")
Ejemplo n.º 25
0
def ContourPlot2D(u, v, p, Y, X):
    pl.figure(figsize = (11,7), dpi = 100)
    pl.contourf(X,Y,p,alpha=0.5,cmap=cm.gist_heat)# plotting the pressure field contours
    pl.colorbar()
    pl.quiver(X[::2,::2],Y[::2,::2],u[::2,::2],v[::2,::2]) # plotting velocity vectors
    pl.xlabel('X')
    pl.ylabel('Y')
    pl.title('Pressure contours and velocity vectors')
Ejemplo n.º 26
0
def plot(H, w1, w2):
    eva, eve = eigh(H)
    Y, X = np.meshgrid(w2, w1)
    plt.contourf(X, Y, np.log(eva), 50)
    plt.colorbar()
    plt.xlabel(r"$\omega_1$")
    plt.ylabel(r"$\omega_2$")
    plt.title("greatest eigenvalue of second derivatives (log scale)")
def graphs_parameters_svm(filename):
    #reading the features and target variables from the file
    features, target = read_data(filename)
    # to normalize the data by subtracting mean and dividing by standard deviation
    scaler = StandardScaler()
    features = scaler.fit_transform(features)
    #setting the ranges of gamma and C
    C_2d_range = [1, 1e2, 1e4, 1e5]
    gamma_2d_range = [1e-1, 1, 1e1, 1e2]
    #classifiers will contain list of all the models for various ranges of C and gamma
    classifiers = []
    for C in C_2d_range:
        for gamma in gamma_2d_range:
            clf = SVC(kernel='rbf', C=C, gamma=gamma)
            clf.fit(features, target)
            classifiers.append((C, gamma, clf))
    target = [int(y) for y in target]

    pl.figure(figsize=(12, 10))
    # construct a mesh
    h = .02
    x = np.array(features, dtype=float)
    y = np.array(target, dtype= int)
    x_min, x_max = x[:, 0].min() - 1, x[:, 0].max() + 1
    y_min, y_max = x[:, 1].min() - 1, x[:, 1].max() + 1
    xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
    #Plotting Support vectors
    for (k, (C, gamma, clf)) in enumerate(classifiers):
        Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
        Z = Z.reshape(xx.shape)
        pl.subplot(len(C_2d_range), len(gamma_2d_range), k + 1)
        pl.title("gamma 10^%d, C 10^%d" % (np.log10(gamma), np.log10(C)),size='medium')
        pl.contourf(xx, yy, Z, cmap=pl.cm.Paired)
        pl.scatter(clf.support_vectors_[:, 0],clf.support_vectors_[:, 1], c=y[clf.support_], cmap=pl.cm.Paired)
        pl.xticks(())
        pl.yticks(())
        pl.axis('tight')
    pl.show()

    pl.figure(figsize=(12, 10))
    #plotting decision boundary
    for (k, (C, gamma, clf)) in enumerate(classifiers):
        # evaluate decision function in a grid
        Z = clf.decision_function(np.c_[xx.ravel(), yy.ravel()])
        Z = Z.reshape(xx.shape)
        # visualize decision function for these parameters
        pl.subplot(len(C_2d_range), len(gamma_2d_range), k + 1)
        pl.title("gamma 10^%d, C 10^%d" % (np.log10(gamma), np.log10(C)),
                 size='medium')
        # visualize parameter's effect on decision function
        pl.pcolormesh(xx, yy, -Z, cmap=pl.cm.jet)
        pl.scatter(features[:, 0], features[:, 1], c=target, cmap=pl.cm.jet)
        pl.xticks(())
        pl.yticks(())
        pl.axis('tight')
    pl.show()
    optimal_model = grid_search(clf, x, y)
    print " the optimal parameters are (C gamma):(", optimal_model.C,optimal_model._gamma, ")"
Ejemplo n.º 28
0
def plot_contour(Z, fname, title):
  xm, tm = np.meshgrid(x, time)
  pl.contourf(xm, tm, Z,100)
  pl.title(title, fontsize=20)
  pl.colorbar()
  pl.xlabel('x')
  pl.ylabel('t [sec]')
  pl.savefig(fname+'.png')
  pl.clf()
Ejemplo n.º 29
0
def show_cmap(cmap, levs):
    n = 10
    x = np.linspace(0,n,n)
    y = np.linspace(0,n,n)
    z = levs.min() + np.random.random((n,n)) * (levs.max() - levs.min())

    pl.figure()
    pl.contourf(x,y,z,levs,extend='both',cmap=cmap)
    pl.colorbar() 
Ejemplo n.º 30
0
def plotSpread(spread, title, file_name):
    pylab.clf()
    ny, nx = spread.shape
    x, y = np.meshgrid(np.arange(nx), np.arange(ny))
    pylab.contourf(x, y, spread)
    pylab.colorbar()
    pylab.title(title)
    pylab.savefig(file_name)
    return
Ejemplo n.º 31
0
def TimeIntegrate():

    global Nx, Nz, hx, hz, x, z, dt
    global U, W, P, T
    global Hx, Hz, Pp, Ht
    
    time = 0
    fwTime = 0.0
    iCnt = 1
    
    Hx.fill(0.0)
    Hz.fill(0.0)
    Ht.fill(0.0)

    while True:

        if iCnt % opInt == 0:

            Re = np.mean(np.sqrt(U[1:Nx-1, 1:Nz-1]**2.0 + W[1:Nx-1, 1:Nz-1]**2.0))/nu
            Nu = 1.0 + np.mean(W[1:Nx-1, 1:Nz-1]*T[1:Nx-1, 1:Nz-1])/kappa
            maxDiv = getDiv(U, W)

            print("%f    %f    %f    %f" %(time, Re, Nu, maxDiv))           


    
        Hx = computeNLinDiff_X(U, W)
        Hz = computeNLinDiff_Z(U, W)
        Ht = computeNLinDiff_T(U, W, T)  
    
    
    
    
        # Calculating guessed values of U implicitly
        Hx[1:Nx-1, 1:Nz-1] = U[1:Nx-1, 1:Nz-1] + dt*(Hx[1:Nx-1, 1:Nz-1]  - (P[2:Nx, 1:Nz-1] - P[0:Nx-2, 1:Nz-1])/(2.0*hx))
        uJacobi(Hx)
    
        # Calculating guessed values of W implicitly
        Hz[1:Nx-1, 1:Nz-1] = W[1:Nx-1, 1:Nz-1] + dt*(Hz[1:Nx-1, 1:Nz-1] - ((P[1:Nx-1, 2:Nz] - P[1:Nx-1, 0:Nz-2])/(2.0*hz)) + T[1:Nx-1, 1:Nz-1])
        wJacobi(Hz)
    
        # Calculating guessed values of T implicitly
        Ht[1:Nx-1, 1:Nz-1] = T[1:Nx-1, 1:Nz-1] + dt*Ht[1:Nx-1, 1:Nz-1]
        TJacobi(Ht)   
    
        #print(np.amax(U), np.amax(V), np.amax(W))
    
        # Calculating pressure correction term
        rhs = np.zeros([Nx, Nz])
        rhs[1:Nx-1, 1:Nz-1] = ((U[2:Nx, 1:Nz-1] - U[0:Nx-2, 1:Nz-1])/(2.0*hx) +
                               (W[1:Nx-1, 2:Nz] - W[1:Nx-1, 0:Nz-2])/(2.0*hz))/dt
    
        #ps.multigrid(Pp, rhs)
    
        Pp = PoissonSolver(rhs)
    
        # Add pressure correction.
        P = P + Pp
    
        # Update new values for U, V and W
        U[1:Nx-1, 1:Nz-1] = U[1:Nx-1, 1:Nz-1] - dt*(Pp[2:Nx, 1:Nz-1] - Pp[0:Nx-2, 1:Nz-1])/(2.0*hx)
        W[1:Nx-1, 1:Nz-1] = W[1:Nx-1, 1:Nz-1] - dt*(Pp[1:Nx-1, 2:Nz] - Pp[1:Nx-1, 0:Nz-2])/(2.0*hz)

        imposeUBCs(U)                               
        imposeWBCs(W)                               
        imposePBCs(P)                               
        imposeTBCs(T) 

        #print(np.amax(U), np.amax(W))      

        #if abs(fwTime - time) < 0.5*dt:
        if abs(time - tMax)<1e-5:
            writeSoln(U, W, P, T, time)
            Z, X = np.meshgrid(x,z)
            plt.contourf(X, Z, T, 500, cmap=cm.coolwarm)
            clb = plt.colorbar()
            plt.quiver(X, Z, U, W)
            plt.axis('scaled')
            clb.ax.set_title(r'$T$', fontsize = 20)
            plt.show()
            fwTime = fwTime + fwInt                                 


        if time > tMax:
            break   

    
        time = time + dt
    
        iCnt = iCnt + 1
Ejemplo n.º 32
0
def plot_PDF_log(data, x_, y_, z_, ZZ, var_name1, var_name2, var_name3, amp_qt,
                 amp_w, time, z):
    fig = plt.figure(figsize=(20, 15))

    plt.subplot(3, 5, 1)
    plt.scatter(data[:, 0], data[:, 1], s=2, alpha=0.3)
    plt.title('data')
    axis_label(var_name1, var_name2, amp_qt, amp_w)
    plt.subplot(3, 5, 2)
    ax1 = plt.hist2d(data[:, 0],
                     data[:, 1],
                     bins=30,
                     norm=LogNorm(),
                     normed=True)
    plt.colorbar(shrink=0.8)
    axis_label(var_name1, var_name2, amp_qt, amp_w)
    plt.title('data histogram')
    plt.subplot(3, 5, 3)
    ax1 = plt.contourf(x_, y_, np.sum(np.exp(ZZ), axis=2).T, norm=LogNorm())
    plt.colorbar(ax1, shrink=0.8)
    plt.title('EM2 PDF')
    axis_label(var_name1, var_name2, amp_qt, amp_w)
    plt.subplot(3, 5, 4)
    ax1 = plt.hist2d(data[:, 0],
                     data[:, 1],
                     bins=30,
                     normed=True,
                     norm=LogNorm())
    # xxx
    lvls = np.logspace(-1, 6, 10)
    ax2 = plt.contour(x_,
                      y_,
                      np.sum(np.exp(ZZ), axis=2).T,
                      levels=lvls,
                      colors='w',
                      norm=LogNorm(),
                      linewidths=3)
    plt.colorbar(ax2, shrink=0.8)
    # xxx
    plt.title('EM2 PDF')
    axis_label(var_name1, var_name2, amp_qt, amp_w)

    plt.subplot(3, 5, 6)
    plt.scatter(data[:, 0], data[:, 2], s=2, alpha=0.3)
    plt.title('data')
    axis_label(var_name1, var_name3, amp_qt, amp_w)
    plt.subplot(3, 5, 7)
    ax1 = plt.hist2d(data[:, 0],
                     data[:, 2],
                     bins=30,
                     norm=LogNorm(),
                     normed=True)
    plt.colorbar(shrink=0.8)
    axis_label(var_name1, var_name3, amp_qt, amp_w)
    plt.title('data histogram')
    plt.subplot(3, 5, 8)
    # xxx
    ax1 = plt.contourf(x_, z_, np.sum(np.exp(ZZ), axis=1).T, norm=LogNorm())
    # xxx
    plt.colorbar(ax1, shrink=0.8)
    plt.title('EM2 PDF')
    axis_label(var_name1, var_name3, amp_qt, amp_w)
    plt.subplot(3, 5, 9)
    ax1 = plt.hist2d(data[:, 0],
                     data[:, 2],
                     bins=30,
                     normed=True,
                     norm=LogNorm())
    # xxx
    # lvls = np.exp(np.arange(-5,6,1))
    lvls = np.logspace(-1, 5, 10)
    ax2 = plt.contour(x_,
                      z_,
                      np.sum(np.exp(ZZ), axis=1).T,
                      levels=lvls,
                      colors='w',
                      norm=LogNorm(),
                      linewidths=3)
    plt.colorbar(ax2, shrink=0.8)
    # xxx
    plt.title('EM2 PDF')
    axis_label(var_name1, var_name3, amp_qt, amp_w)

    plt.subplot(3, 5, 11)
    plt.scatter(data[:, 1], data[:, 2], s=2, alpha=0.3)
    plt.title('data')
    axis_label(var_name2, var_name3, amp_qt, amp_w)
    plt.subplot(3, 5, 12)
    ax1 = plt.hist2d(data[:, 1],
                     data[:, 2],
                     bins=30,
                     norm=LogNorm(),
                     normed=True)
    plt.colorbar(shrink=0.8)
    plt.title('data histogram')
    plt.subplot(3, 5, 13)
    # xxx
    ax1 = plt.contourf(y_, z_, np.sum(np.exp(ZZ), axis=0).T, norm=LogNorm())
    # xxx
    plt.title('EM2 PDF')
    axis_label(var_name2, var_name3, amp_qt, amp_w)
    plt.colorbar(ax1, shrink=0.8)
    plt.subplot(3, 5, 14)
    ax1 = plt.hist2d(data[:, 1],
                     data[:, 2],
                     bins=30,
                     normed=True,
                     norm=LogNorm())
    # xxx
    lvls = np.logspace(-1, 6, 10)
    ax2 = plt.contour(y_,
                      z_,
                      np.sum(np.exp(ZZ), axis=0).T,
                      levels=lvls,
                      colors='w',
                      linewidths=3,
                      norm=LogNorm())
    plt.colorbar(ax2, shrink=0.8)
    # xxx
    plt.title('EM2 PDF')
    axis_label(var_name2, var_name3, amp_qt, amp_w)
    # plt.colorbar(ax1, shrink=0.8)

    fig.suptitle('EM2 PDF: ' + var_name1 + var_name2 + var_name3 + ' (t=' +
                 str(time) + ', z=' + str(z) + 'm)',
                 fontsize=20)
    plt.savefig(
        os.path.join(
            path, 'EM2_trivar_figures',
            'EM2_PDF_trivariate_' + var_name1 + var_name2 + var_name3 + '_' +
            str(time) + '_z' + str(np.int(z)) + 'm_log.png'))

    plt.close()

    return
Ejemplo n.º 33
0
        X = mData[:, :, 0] * 1.475
        Y = mData[:, :, 1] * 1.475
    elif str(sys.argv[3]) == "yz":
        X = mData[:, :, 1] * 1.475
        Y = mData[:, :, 2] * 1.475
    else:
        print("only xz and xy slices supported")
        exit

    F = mData[:, :, 3] * Fscale

    fig, axes = plt.subplots(nrows=1, ncols=1)
    fig.set_size_inches((12, 12))
    sp = subplot(111)
    if useLog == 1:
        im2 = contourf(X, Y, log10(F + F0), colouraxis, cmap=cmapname)
    else:
        im2 = contourf(X, Y, F + F0, colouraxis, cmap=cmapname)
    plt.xlabel("$X [km]$", fontsize=36, color=bgcolor)
    plt.ylabel("$Y [km]$", fontsize=36, color=bgcolor)

    dt = NextTime * 0.00496
    titlestring = "t - $t_{\\rm merge}$ = %.02f ms" % (dt)
    plt.title(titlestring, fontsize=36, color=bgcolor)

    ax = plt.gca()
    ax.xaxis.set_major_locator(majorLocatorX)
    ax.xaxis.set_minor_locator(minorLocatorX)
    ax.xaxis.set_ticklabels(Xlab, fontsize=32, color=bgcolor)
    ax.xaxis.set_tick_params(which='minor', length=5, width=2)
    ax.xaxis.set_tick_params(which='major', width=3, length=10)
Ejemplo n.º 34
0
#Pseudo density
nt, atoms = read_cube('water_pseudo_density.cube', read_data=True)
x = len(nt) // 2
nt = nt[x]

# All electron density and bader volumes
n, atoms = read_cube('water_density.cube', read_data=True)
#bader, atoms2 = read_cube('AtIndex.cube', read_data=True)
x = len(n) // 2
n = n[x]
#bader = bader[x]

# plot
fig = pl.figure(figsize=(6.2, 3))
pl.subplot(121)
pl.contourf(nt.T, vals, origin='lower', extend='neither', colors=colors)
pl.axis('equal')
pl.axis([52-25, 52+25, 52-25, 52+25])
pl.axis('off')
pl.text(52.5, 55, '$7.07e$', size=20, ha='center', va='center')
pl.title('Pseudo density', size=20)

pl.subplot(122)
pl.contourf(n.T, vals, colors=colors,
           origin='lower', extend='neither')
#pl.contour(bader.T, [1.5], origin='lower', extend='neither', colors='k')
pl.axis('equal')
pl.axis([104-50, 104+50, 104-50, 104+50])
pl.axis('off')
pl.text(104.0, 112.0, '$9.12e$', size=20, ha='center', va='center')
pl.text( 86.5,  97.5, '$0.44e$', size=20, ha='right', va='center')
Ejemplo n.º 35
0
def plot_sim_reflect():
	print("    SIM REFLECTIVITY")
	# Set Figure Size (1000 x 800)
	pylab.figure(figsize=(width,height),frameon=False)
	QR = nc.variables['QRAIN']
	QS = nc.variables['QSNOW']

	# Define 'constant' densities (kg m-3)
	rhor = 1000
	rhos = 100
	rhog = 400
	rhoi = 917

	# Define "fixed intercepts" (m-4)
	Norain = 8.0E6
	#Nosnow = 2.0E7
	Nosnow = 2.0E6*np.exp(-0.12 * (temps[time]-273))
	Nograu = 4.0E6


	# First, find the density at the first sigma level
	# above the surface
	density = np.divide(psfc[time],(287.0 * temps[time]))
	#print "Rho: ", np.mean(density)
	Qra = QR[time,1]
	Qsn = QS[time,1]
	Qra = np.nan_to_num(Qra)
	Qsn = np.nan_to_num(Qsn)

	# Calculate slope factor lambda
	lambr = np.divide((3.14159 * Norain * rhor), np.multiply(density, Qra))
	lambr = lambr ** 0.25

	#lambs = np.divide((3.14159 * Nosnow * rhoi), np.multiply(density, Qsn))
	#lambs = lambs ** 0.25
	lambs = np.exp(-0.0536 * (temps[time] - 273))
	
	# Calculate equivalent reflectivity factor
	Zer = (720.0 * Norain * (lambr ** -7.0)) * 1E18
	Zes = (0.224 * 720.0 * Nosnow * (lambr ** -7.0) * (rhos/rhoi) ** 2) * 1E18
	Zes_int = np.divide((lambs * Qsn * density), Nosnow)
	Zes = ((0.224 * 720 * 1E18) / (3.14159 * rhor) ** 2) * Zes_int ** 2 



	Ze = np.add(Zer, Zes)
	#Ze = Zer
	# Convert to dBZ

	dBZ = 10 * np.log10(Ze)	
	dBZ = np.nan_to_num(dBZ)
	units = 'dBZe'
	print "      MAX: ", np.max(dBZ)
	# Now plot
	REF_LEVELS = range(5,90,5)
	SREFLECT=pylab.contourf(x,y,dBZ,REF_LEVELS,cmap=coltbls.reflect())
	#SREFLECT=pylab.contourf(x,y,dBZ)
	title = 'Simulated Surface Reflectivity'
	prodid = 'sref'

	drawmap(SREFLECT, title, prodid, units) 	
Ejemplo n.º 36
0
    tstresult = percentError(trainer.testOnClassData(
           dataset=tstdata), tstdata['class'])

    print "epoch: %4d" % trainer.totalepochs, \
          "  train error: %5.2f%%" % trnresult, \
          "  test error: %5.2f%%" % tstresult

    """ Run our grid data through the FNN, get the most likely class
    and shape it into a square array again. """
    out = fnn.activateOnDataset(griddata)
    out = out.argmax(axis=1)  # the highest output activation gives the class
    out = out.reshape(X.shape)

    """ Now plot the test data and the underlying grid as a filled contour. """
    figure(1)
    ioff()  # interactive graphics off
    clf()   # clear the plot
    hold(True) # overplot on
    for c in [0, 1, 2]:
        here, _ = where(tstdata['class'] == c)
        plot(tstdata['input'][here, 0], tstdata['input'][here, 1], 'o')
    if out.max() != out.min():  # safety check against flat field
        contourf(X, Y, out)   # plot the contour
    ion()   # interactive graphics on
    draw()  # update the plot

""" Finally, keep showing the plot until user kills it. """
ioff()
show()

# title for the plots
titles = [
    'SVC with rbf kernel',
    'SVC (linear kernel)\n with Fourier rbf feature map\n'
    'n_components=100', 'SVC (linear kernel)\n with Nystroem rbf feature map\n'
    'n_components=100'
]

pl.tight_layout()
pl.figure(figsize=(12, 5))

# predict and plot
for i, clf in enumerate((kernel_svm, nystroem_approx_svm, fourier_approx_svm)):
    # Plot the decision boundary. For that, we will asign a color to each
    # point in the mesh [x_min, m_max]x[y_min, y_max].
    pl.subplot(1, 3, i + 1)
    Z = clf.predict(flat_grid)

    # Put the result into a color plot
    Z = Z.reshape(grid.shape[:-1])
    pl.contourf(multiples, multiples, Z, cmap=pl.cm.Paired)
    pl.axis('off')

    # Plot also the training points
    pl.scatter(X[:, 0], X[:, 1], c=targets_train, cmap=pl.cm.Paired)

    pl.title(titles[i])
pl.tight_layout()
pl.show()
Ejemplo n.º 38
0
def plotMixtureEntropy(mix, axis):
    """ 
    @param axis: matlab-like axis coordinates: [x_start, x_end, y_start, y_end] 
    
    """

    # -5, 10.0, -5.0, 10.0

    x = pylab.arange(axis[0], axis[1] + 0.1, 0.1)
    y = pylab.arange(axis[2], axis[3] + 0.1, 0.1)

    #print x
    #print y

    #print len(x)
    #print len(y)

    #X,Y = pylab.meshgrid(x,y)
    #z = pylab.exp(-(X*X + Y*Y)) + 0.6*pylab.exp(-((X+1.8)**2 + Y**2))
    #pylab.contour(x,y,z)

    z = numpy.zeros((len(y), len(x)), dtype='Float64')
    for i in range(len(y)):
        dat = numpy.zeros((len(x), 2), dtype='Float64')
        dat[:, 1] = y[i]
        dat[:, 0] = x
        #print numpy.exp(mix.pdf(dat))

        #print "---------------------------\n",dat
        data = mixture.DataSet()
        data.fromList(dat)
        data.internalInit(mix)

        l = mixture.get_posterior(mix, data, logreturn=False)

        #print l

        #print numpy.exp(mix.pdf(dat)).tolist()
        for j in range(len(x)):

            z[i, j] = mixture.entropy(l[:, j])
            #print dat[j,:] ,":",l[:,j], "=",z[i,j]
        #print "---------------------------\n"

    #print "z", len(z),'x', len(z[0]) ,'=', len(z) * len(z[0])

    print "max", z.max()
    #max_val = z.max()

    max_val = numpy.log(mix.G)  # maximum entropy for a vector of length mix.G
    print "theor. max", max_val

    step = max_val / 10.0
    print "step", step

    #pylab.figure(1)
    #pylab.contour(x,y,z)

    #pylab.figure(2)
    #pylab.contour(x,y,z,pylab.arange(0,max_val,step))
    #pylab.legend()

    #    pylab.colorbar()
    pylab.contourf(
        x,
        y,
        z,
    )  # pylab.arange(0,max_val,step)

    pylab.title('Posterior Entropy Plot')
Ejemplo n.º 39
0
def plotNormalMixtureDensity(mix,
                             axis,
                             title=None,
                             newfigure=False,
                             fill=True,
                             alpha=1.0):
    """ 
    @param axis: matlab-like axis coordinates: [x_start, x_end, y_start, y_end] 
    
    """

    if newfigure == True:
        pylab.figure()

    # -5, 10.0, -5.0, 10.0

    x = pylab.arange(axis[0], axis[1] + 0.1, 0.1)
    y = pylab.arange(axis[2], axis[3] + 0.1, 0.1)

    #print len(x)
    #print len(y)

    #X,Y = pylab.meshgrid(x,y)
    #z = pylab.exp(-(X*X + Y*Y)) + 0.6*pylab.exp(-((X+1.8)**2 + Y**2))
    #pylab.contour(x,y,z)

    z = numpy.zeros((len(y), len(x)), dtype='Float64')
    for i in range(len(y)):
        ndat = numpy.zeros((len(x), 2), dtype='Float64')
        ndat[:, 1] = y[i]
        ndat[:, 0] = x
        #print numpy.exp(mix.pdf(dat))

        dat = mixture.DataSet()
        dat.fromList(ndat)
        dat.internalInit(mix)

        # XXX pdf is log valued, we want the true value XXX

        #print numpy.exp(mix.pdf(dat)).tolist()

        z[i, :] = numpy.exp(mix.pdf(dat))

    #print "z", len(z),'x', len(z[0]) ,'=', len(z) * len(z[0])

    #print "max",z.max()
    max_val = z.max()

    step = max_val / 40.0

    #step = max_val / 200.0

    #print "step",step

    #pylab.figure(1)
    #pylab.contour(x,y,z)

    if fill == True:
        pylab.contourf(x, y, z, pylab.arange(0, max_val, step), alpha=alpha)
    else:
        pylab.contour(x, y, z, pylab.arange(0, max_val, step), alpha=alpha)

    if title:
        pylab.title(title)
    else:
        pylab.title('Normal Mixture Density Plot')
Ejemplo n.º 40
0
    print re0, le, ql, ph, ex_shs, ex_sha

    yi1 = x1 - al1
    yi2 = x2 - al2

    xroot1, xroot2, nroots = trf.mapping_triangles(ys1, ys2, x1, x2, yi1, yi2)

    if (nroots > len(ximgs[np.nonzero(ximgs)])):
        xroot = np.sqrt(xroot1 * xroot1 + xroot2 * xroot2)
        idx = xroot == xroot.min()
        xroot1[idx] = 0.0
        xroot2[idx] = 0.0

    simg = gauss_2d(x1, x2, ys1, ys2, 0.05)
    limg = gauss_2d(yi1, yi2, ys1, ys2, 0.05)

    levels_kappa = [0.8, 0.9, 1.0, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 2.8]

    levels = [0.45, 0.6, 0.75, 0.9, 1.0]

    pl.figure(figsize=(8, 8))
    pl.contourf(x1, x2, limg, levels)
    pl.contour(x1, x2, np.log(kap), levels_kappa, colors=('k', ))
    pl.contour(x1, x2, simg, levels)
    pl.plot(ys1, ys2, 'rx')
    pl.plot(ximgs[np.nonzero(ximgs)], yimgs[np.nonzero(yimgs)], 'bo')
    pl.plot(xroot1[np.nonzero(xroot1)], xroot2[np.nonzero(xroot2)], 'rx')
    #---------------------------------------------
    pl.show()
Ejemplo n.º 41
0
def make_contour(r, var, model, vel, par, mode, x):
    global new_r, new_zp
    import seaborn as sns
    sns.set(style="white",
            rc={
                "figure.figsize": (8, 8),
                'axes.labelsize': 16,
                'ytick.labelsize': 12,
                'xtick.labelsize': 12,
                'axes.titlesize': 18
            })

    t_var = np.empty(var[x::, :].shape)
    t_r = np.empty(t_var.shape)
    for i in range(len(r[0, :])):
        t_var[:, i] = var[x::, i]
        t_r[:, i] = np.linspace(r[0, i], r[-1, i], len(t_var[:, i]))

    var = 1. * t_var
    r = 1. * t_r

    new_r = lint.leg_interp(r[0:-2, :], 8, "EVEN")
    new_zp = lint.leg_interp(var[0:-2, :], 8, "EVEN")
    #levels = np.linspace(np.min(new_zp),np.max(new_zp), 40)

    #####REMOVE 0-10deg at the pole:
    new_r = new_r[:, 11::]
    new_zp = new_zp[:, 11::]
    theta = np.linspace(0, np.deg2rad(90), 89)
    #########################################

    #theta = np.linspace(0,np.deg2rad(90),100)
    newt, n_r = np.meshgrid(theta, new_r[:, 0])

    plt.contourf((new_r * np.sin(newt)), (new_r * np.cos(newt)),
                 new_zp,
                 100,
                 cmap=plt.cm.gnuplot,
                 vmax=np.max(new_zp),
                 vmin=np.min(new_zp))
    plt.contourf((new_r * np.sin(newt)),
                 -(new_r * np.cos(newt)),
                 new_zp,
                 100,
                 cmap=plt.cm.gnuplot,
                 vmax=np.max(new_zp),
                 vmin=np.min(new_zp))
    plt.contourf(-(new_r * np.sin(newt)),
                 -(new_r * np.cos(newt)),
                 new_zp,
                 100,
                 cmap=plt.cm.gnuplot,
                 vmax=np.max(new_zp),
                 vmin=np.min(new_zp))
    plt.contourf(-(new_r * np.sin(newt)), (new_r * np.cos(newt)),
                 new_zp,
                 100,
                 cmap=plt.cm.gnuplot,
                 vmax=np.max(new_zp),
                 vmin=np.min(new_zp))
    #CSl = plt.contour((new_r*np.sin(newt)),(new_r*np.cos(newt)),new_zp, 20, colors="k")
    #CS = plt.contourf((new_r*np.cos(newt)), (new_r*np.sin(newt)), new_zp, cmap=plt.cm.Spectral,levels=levels)
    #plt.axes().set_aspect('equal')
    #plt.xlim(np.ceil(r[-1,-1]))
    plt.ylim(-plt.xlim()[1], plt.xlim()[1])
    #plt.xlabel("Radius [R$_{\odot}$]")
    #plt.ylabel("Radius [R$_{\odot}$]")
    plt.axis('off')
    try:
        m = (find_name(model, vel, par, mode)).strip()
    except:
        m = "freq_%.5f" % find_sigma(model, vel, par, mode)
    v = find_vel(model, vel)

    plt.title("M" + model[0] + "_V" + v + " - mode: " + m)
    return
Ejemplo n.º 42
0
griddata._convertToOneOfMany()

for i in range(20):
    trainer.trainEpochs(1) # usually 5
    
trainresult = percentError(trainer.testOnClassData(), traindata["class"])
testresult = percentError(trainer.testOnClassData(), testdata["class"])

print("epoch %4d" % trainer.totalepochs, "trainerror %5.2f%%" % trainresult, "testerror %5.2f%%" % testresult)
    
out = fnn.activateOnDataset(griddata)
out = out.argmax(axis=1)
out = out.reshape(X.shape)

figure(1)
 # might be the wrong import for the following lines
ioff()  
clf()
hold(True)
for c in [0,1,2]:
    here, _ = where(testdata["class"]==c)
    plot(testdata["input"][here, 0], testdata["input"][here, 1], 'o')
if out.max()!=out.min():
    contourf(X, Y, out)
ion()
draw()

ioff()
show()

Ejemplo n.º 43
0
def pair_posterior(atpy_table, weights, outfile=None, title=None, priors=None, sim_vals=None):
    """
    pair_posterior(atpy_table)

    :Arguments:
    atpy_table:       Contains 1 column for each parameter with samples.
    weights:          The weights from the MultiNest results. Should have been
                      removed from the table.
    outfile:          The root name of the output file.
    title:
    priors:           A dictionary of priors??
    sim_vals:         A dictionary containing the input values. 
    
    Produces a matrix of plots. On the diagonals are the marginal
    posteriors of the parameters. On the off-diagonals are the
    marginal pairwise posteriors of the parameters.
    """

    params = atpy_table.keys()
    pcnt = len(params)

    fontsize = 6
    
    plt.close(10)
    plt.figure(10, figsize = (40,40))
    plt.subplots_adjust(left=0.05, right=0.98, bottom=0.05, top=0.98)

    # Marginalized 1D
    for ii in range(pcnt):
        ax = plt.subplot(pcnt, pcnt, ii*(pcnt+1)+1)
        plt.setp(ax.get_xticklabels(), fontsize=fontsize)
        plt.setp(ax.get_yticklabels(), fontsize=fontsize)
        n, bins, patch = plt.hist(atpy_table[params[ii]], normed=True,
                                 histtype='step', weights=weights, bins=50)
        plt.xlabel(params[ii], size=fontsize)
        plt.ylim(0, n.max()*1.1)

        if (sim_vals != None) and (params[ii] in sim_vals):
            plt.axvline(sim_vals[params[ii]], color='red', linestyle='-')
        
        ax.get_xaxis().get_major_formatter().set_useOffset(False)        
        ax.get_xaxis().get_major_formatter().set_scientific(False)

        x_limits = ax.get_xlim()
        y_limits = ax.get_ylim()

        x_sep = (x_limits[1] - x_limits[0]) / 2.1
        y_sep = (y_limits[1] - y_limits[0]) / 2.1
        x_majorLocator = MultipleLocator(x_sep)
        y_majorLocator = MultipleLocator(y_sep)

        ax.xaxis.set_major_locator(x_majorLocator)
        ax.yaxis.set_major_locator(y_majorLocator)

    # Bivariates
    for ii in range(pcnt - 1):
        for jj in range(ii+1, pcnt):
            ax = plt.subplot(pcnt, pcnt, ii*pcnt + jj+1)
            plt.setp(ax.get_xticklabels(), fontsize=fontsize)
            plt.setp(ax.get_yticklabels(), fontsize=fontsize)

            (H, x, y) = np.histogram2d(atpy_table[params[jj]], atpy_table[params[ii]],
                                       weights=weights, bins=50)
            xcenter = x[:-1] + (np.diff(x) / 2.0)
            ycenter = y[:-1] + (np.diff(y) / 2.0)

            plt.contourf(xcenter, ycenter, H.T, cmap=plt.cm.gist_yarg)
            
            if (sim_vals != None) and (params[ii] in sim_vals) and (params[jj] in sim_vals):
                plt.plot(sim_vals[params[jj]], sim_vals[params[ii]], 'r.')

            plt.xlabel(params[jj], size=fontsize)
            plt.ylabel(params[ii], size=fontsize)

            ax.get_xaxis().get_major_formatter().set_useOffset(False)        
            ax.get_xaxis().get_major_formatter().set_scientific(False)        

            ax.get_yaxis().get_major_formatter().set_useOffset(False)        
            ax.get_yaxis().get_major_formatter().set_scientific(False)        
                        
            x_limits = ax.get_xlim()
            y_limits = ax.get_ylim()

            x_sep = (x_limits[1] - x_limits[0]) / 2.1
            y_sep = (y_limits[1] - y_limits[0]) / 2.1
            x_majorLocator = MultipleLocator(x_sep)
            y_majorLocator = MultipleLocator(y_sep)

            ax.xaxis.set_major_locator(x_majorLocator)
            ax.yaxis.set_major_locator(y_majorLocator)

    #if title != None:
    #    plt.suptitle(title)
    plt.subplots_adjust(wspace=0.3, hspace=0.3)
    if outfile != None:
        plt.savefig(outfile, bbox_inches='tight', pad_inches=0.05)

    return
Ejemplo n.º 44
0
    density = moments[:, :, 0]
    j_x     = moments[:, :, 1]
    j_y     = moments[:, :, 2]

    lagrange_multipliers = \
        io.readBinaryFile(lagrange_multiplier_files[file_number])
    lagrange_multipliers = lagrange_multipliers[0].reshape(N_q2, N_q1, 5)
    
    mu           = lagrange_multipliers[:, :, 0]
    mu_ee        = lagrange_multipliers[:, :, 1]
    T_ee         = lagrange_multipliers[:, :, 2]
    vel_drift_x  = lagrange_multipliers[:, :, 3]
    vel_drift_y  = lagrange_multipliers[:, :, 4]

    
    pl.contourf(q1_meshgrid, q2_meshgrid, density.T, 100, cmap='bwr')
    pl.title(r'Time = ' + "%.2f"%(time_array[file_number]) + " ps")
    pl.streamplot(q1, q2, 
                  vel_drift_x, vel_drift_y,
                  density=2, color='k',
                  linewidth=0.7, arrowsize=1
                 )
    
    pl.xlim([q1[0], q1[-1]])
    pl.ylim([q2[0], q2[-1]])
    
    pl.gca().set_aspect('equal')
    pl.xlabel(r'$x\;(\mu \mathrm{m})$')
    pl.ylabel(r'$y\;(\mu \mathrm{m})$')
    pl.suptitle('$\\tau_\mathrm{mc} = \infty$, $\\tau_\mathrm{mr} = \infty$')
    pl.savefig('images/dump_' + '%06d'%file_number + '.png')
Ejemplo n.º 45
0
idx = largest_indices(wcfl, max_locs)

for n in np.arange(max_locs):
    k = idx[0][n]
    j = idx[1][n]
    i = idx[2][n]
    print(" N=%3.3d, K=%3.3d, LAT=%7.3f, LON=%7.3f, OMEGA_CFL=%4.2f, W=%4.2f, W+1=%4.2f, DZ=%4.1f, U=%4.1f  V=%4.1f " % \
          (n, k, lat[j,i], lon[j,i], wcfl[k,j,i], W[k,j,i], W[k+1,j,i], dz[k,j,i], U[k,j,i], V[k,j,i]))

k = idx[0][0]
_w_min = 1.0
ctable = 'viridis'

scale_w_clevels = min(max(np.int(z[k].mean() / 1000.), 1.0), 7.0)
clevels = scale_w_clevels * np.arange(-10., 11., 1.)
wmask = np.ma.masked_array(W[k],
                           mask=[np.abs(W[k]) <= scale_w_clevels * _w_min])
plot = P.contourf(lon, lat, wmask, clevels, cmap=P.get_cmap(ctable))
#cbar    = P.colorbar(plot,location='right',pad="5%")
plot = P.contour(lon, lat, wmask, clevels[::2], colors='k', linewidths=0.5)
#cbar.set_label('%s' % ("$m s^{-1}$"))
title = ("Vertical Velocity  K = %d " % (k))
P.title(title, fontsize=10)
P.show()

f.close()

#at = AnchoredText("Max W: %4.1f \n Min W: %4.1f" % (w.max(),w.min()), loc=4, prop=dict(size=6), frameon=True,)
#at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
#ax2.add_artist(at)
Ejemplo n.º 46
0
def plotPosteriorMax(mix, axis):
    """ 
    @param axis: matlab-like axis coordinates: [x_start, x_end, y_start, y_end] 
    
    """

    # -5, 10.0, -5.0, 10.0

    x = pylab.arange(axis[0], axis[1], 0.1)
    y = pylab.arange(axis[2], axis[3], 0.1)

    #print len(x)
    #print len(y)

    # XXX colors hard coded here XXX
    color = ['b', 'r', 'g', 'm', 'c', 'y']
    assert mix.G <= len(color)

    z = numpy.zeros((len(y), len(x)), dtype='Float64')
    for i in range(len(y)):
        dat = numpy.zeros((len(x), 2), dtype='Float64')
        dat[:, 1] = y[i]
        dat[:, 0] = x
        #print numpy.exp(mix.pdf(dat))

        #print "---------------------------\n",dat
        l = mixture.get_posterior(mix, dat)

        #print l

        # XXX pdf is log valued, we want the true value XXX

        #print numpy.exp(mix.pdf(dat)).tolist()
        for j in range(len(x)):

            z[i, j] = numpy.argmax(l[:, j])
            #print dat[j,:] ,":",l[:,j],numpy.argmax(l[:,j])

            #print dat[j,:] ,":",l[:,j], "=",z[i,j]
        #print "---------------------------\n"

    #print "z", len(z),'x', len(z[0]) ,'=', len(z) * len(z[0])

    print "max", z.max()
    #max_val = z.max()

    max_val = numpy.log(mix.G)  # maximum entropy for a vector of length mix.G
    print "theor. max", max_val

    step = max_val / 40.0
    print "step", step

    #pylab.figure(1)
    #pylab.contour(x,y,z)

    #pylab.figure(2)
    #pylab.contour(x,y,z,pylab.arange(0,max_val,step))
    #pylab.legend()

    pylab.figure()
    #    pylab.colorbar()

    pylab.contourf(x, y, z, cmap=pylab.cm.hsv)  # pylab.arange(0,max_val,step)

    pylab.title('Posterior Maximum Plot')
Ejemplo n.º 47
0
def plot_precip_type():
	print("    PRECIP TYPE")
	# Set Figure Size (1000 x 800)
	pylab.figure(figsize=(width,height),frameon=False)

	sr = nc.variables['SR']
	tsk = nc.variables['TSK']
	rainc =  nc.variables['RAINC']
	rainnc = nc.variables['RAINNC']


	type_pct = sr[time]
	if time == 0:
		prev_total = rainc[time] + rainnc[time]
	else:
		prev_total = rainc[time-1] + rainnc[time-1]
	total_accum = rainc[time] + rainnc[time]
	precip_tend = total_accum  - prev_total
	
	snow_precip = []
	mix_precip = []
	rain_precip = []
	for j in range(len(precip_tend)):
		cur_col_rain = []
		cur_col_mix = []
		cur_col_snow = []
		for i in range(len(precip_tend[0])):
			if (0.20 < type_pct[j,i] < 0.90):
				cur_col_mix.append(precip_tend[j,i])
				cur_col_snow.append(0.)
				cur_col_rain.append(0.)	
			elif (type_pct[j,i] >= 0.90):
				cur_col_mix.append(0.)
				cur_col_snow.append(precip_tend[j,i])
				cur_col_rain.append(0.)	
				#print type_pct[j,i]	

			else:
				cur_col_mix.append(0.)
				cur_col_snow.append(0.)
				cur_col_rain.append(precip_tend[j,i])
		snow_precip.append(cur_col_snow)
		mix_precip.append(cur_col_mix)
		rain_precip.append(cur_col_rain)		
	#print snow_precip
	#raw_input()
	PCP_LEVELS = [0.01,0.03,0.05,0.10,0.15,0.20,0.25,0.30,0.40,0.50,0.60,0.70,0.80,0.90,1.00,1.25,1.50,1.75,2.00,2.50]

	MIXT=pylab.contourf(x,y,mix_precip,PCP_LEVELS,extend='max',cmap=coltbls.mixprecip1())
	RAINT=pylab.contourf(x,y,rain_precip,PCP_LEVELS,extend='max',cmap=coltbls.rain1())
	SNOWT=pylab.contourf(x,y,snow_precip,PCP_LEVELS,extend='max',cmap=coltbls.snow1())

	ftemps = (9./5.)*(temps[time]-273) + 32
	ftsk = (9./5.)*(tsk[time] - 273) + 32
	T=pylab.contour(x,y,ftemps,[32],colors='red',linestyles='solid')
	TS=pylab.contour(x,y,ftsk,[32],colors='purple',linestyles='dashdot')

	#RAINT=pylab.contourf(x,y,type_pct,extend='max',cmap=pylab.cm.copper)

	title = 'Frozen Precipitation'
	prodid = 'ptype'
	units = 'in'

	drawmap(RAINT, title, prodid, 'in') 	
Ejemplo n.º 48
0
        # make a plot of the centers of the cells
        scat = plt.plot(ra, dec, 'o', c='k', markersize=2)

        if straylight:
            if magnitudes:
                CS = plt.contour(xi,
                                 yi,
                                 zi,
                                 vf,
                                 linewidths=0.5,
                                 colors='k',
                                 extent=extent)
                CS = plt.contourf(xi,
                                  yi,
                                  zi,
                                  vf,
                                  cmap=plt.cm.jet,
                                  extent=extent)
            else:
                CS = plt.contour(xi,
                                 yi,
                                 zi,
                                 vf,
                                 linewidths=0.5,
                                 colors='k',
                                 extent=extent,
                                 locator=ticker.LogLocator())
                CS = plt.contourf(xi,
                                  yi,
                                  zi,
                                  vf,
Ejemplo n.º 49
0
def plot_comp_reflect():
	print("    COMP REFLECTIVITY")
	# Set Figure Size (1000 x 800)
	pylab.figure(figsize=(width,height),frameon=False)
	QR = nc.variables['QRAIN']
	QS = nc.variables['QSNOW']

	# Define 'constant' densities (kg m-3)
	rhor = 1000
	rhos = 100
	rhog = 400
	rhoi = 917

	# Define "fixed intercepts" (m-4)
	Norain = 8.0E6
	#Nosnow = 2.0E7
	Nosnow = 2.0E6*np.exp(-0.12 * (temps[time]-273))
	Nograu = 4.0E6


	# First, find the density at the first sigma level
	# above the surface
	density = np.divide(psfc[time],(287.0 * temps[time]))
	#print "Rho: ", np.mean(density)
	Qra_all = QR[time]
	Qsn_all = QS[time]

	for j in range(len(Qra_all[1,:,1])):
		curcol_r = []
		curcol_s = []
		for i in range(len(Qra_all[1,1,:])):
				maxrval = np.max(Qra_all[:,j,i])
				maxsval = np.max(Qsn_all[:,j,i])
				curcol_r.append(maxrval)		
				curcol_s.append(maxsval)
		np_curcol_r = np.array(curcol_r)
		np_curcol_s = np.array(curcol_s)
		if j == 0:
			Qra = np_curcol_r
			Qsn = np_curcol_s
		else:
			Qra = np.row_stack((Qra, np_curcol_r))
			Qsn = np.row_stack((Qsn, np_curcol_s))

	#print "Qra shp: ", np.shape(Qra)
	#print "Den shp: ", np.shape(density)
	


	# Calculate slope factor lambda
	lambr = np.divide((3.14159 * Norain * rhor), np.multiply(density, Qra))
	lambr = lambr ** 0.25

	#lambs = np.divide((3.14159 * Nosnow * rhoi), np.multiply(density, Qsn))
	#lambs = lambs ** 0.25
	lambs = np.exp(-0.0536 * (temps[time] - 273))
	
	# Calculate equivalent reflectivity factor
	Zer = (720.0 * Norain * (lambr ** -7.0)) * 1E18
	Zes = (0.224 * 720.0 * Nosnow * (lambr ** -7.0) * (rhos/rhoi) ** 2) * 1E18
	Zes_int = np.divide((lambs * Qsn * density), Nosnow)
	Zes = ((0.224 * 720 * 1E18) / (3.14159 * rhor) ** 2) * Zes_int ** 2 



	Ze = np.add(Zer, Zes)
	#Ze = Zer
	# Convert to dBZ
	dBZ = 10 * np.log10(Ze)	
	dBZ = np.nan_to_num(dBZ)
	units = 'dBZe'
	print "      MAX: ", np.max(dBZ)
	# Now plot
	REF_LEVELS = range(5,90,5)
	CREFLECT=pylab.contourf(x,y,dBZ,REF_LEVELS,cmap=coltbls.reflect())
	#SREFLECT=pylab.contourf(x,y,dBZ)
	title = 'Simulated Composite Reflectivity'
	prodid = 'cref'

	drawmap(CREFLECT, title, prodid, units) 	
Ejemplo n.º 50
0
    #(E_p,E_m,Qj)=IntElfield(theta,1.540562,array([1-.15E-04/2+0.35E-06j/2,1-.45E-04/2+0.60E-05j/2,1]),array([0,1000]))
    from paratt import Refl
    #c=Refl(theta,1.54,array([1-7.57e-6+1.73e-7j,1-2.24e-5+2.89e-6j,1-7.57e-6+1.73e-7j,1-2.24e-5+2.89e-6j,1-7.57e-6+1.73e-7j,1-2.24e-5+2.89e-6j,1-7.57e-6+1.73e-7j,1]),array([80,20,80,20,80,20]),0)
    c = Refl(theta, 1.54,
             array([1 - 7.57e-6 + 1.73e-7j, 1 - 2.24e-5 + 2.89e-6j, 1]),
             array([0, 1000, 0]), array([0, 0, 0]))
    #gplt.plot(theta,log10(abs(E_m[-1]/E_p[-1])**2),theta,log10(abs(c**2)))
    #f=f=open('Specrefl.dat','r')
    #t=io.read_array(f)
    #t=transpose(t)
    #gplt.plot(theta,log10(abs(E_m[-1]/E_p[-1])**2),t[0],log10(t[1]))
    k = 2 * math.pi / 1.54
    n = [1, 1 - 2.24e-5 + 2.89e-6j, 1 - 7.57e-6 + 1.73e-7j]
    n = array(n)
    z = array([0, -1000])
    #(T,R,k)=AmpElfield2(k*cos(theta*math.pi/180),k*ones(theta.shape), n,z)
    #(T,R,k)=IntElfield(theta,1.54, n, array([0,1000]))
    (T, R, zc, E) = AmpElfield_test(theta, 1.54, n, array([0, 1000, 0]))
    #print T[0]
    pylab.subplot(211)
    pylab.plot(theta, log10(abs(R)), theta, log10(abs(c)), '.-')
    pylab.ylabel('R')
    pylab.xlabel('theta [deg]')
    pylab.legend(('Abeles', 'Parratt'))
    pylab.subplot(212)
    pylab.contourf(theta, zc, E.transpose())
    #print zc.shape, zc[-1]
    #print log10(E[0,:]).shape
    #pylab.plot(zc, (E[1,:]))
    pylab.show()
Ejemplo n.º 51
0
            #map the consistency values into weights
            #weights = []
            # for user_name in individualConsistency:
            #     try:
            #         weights.append(min(1., math.pow(individualConsistency[user_name]/0.6,8.5)))
            #     except ValueError:
            #         print individualConsistency[user_name]
            #         raise
            weights = {
                user_name: min(
                    1.,
                    math.pow(individualConsistency[user_name] / wParam1,
                             wParam2))
                for user_name in individualConsistency
            }
            #results.append([individualConsistency[user_name] for user_name in individualConsistency])
            results.append([weights[user_name] for user_name in weights])

        #print len(individualConsistency)
        from scipy.stats import ks_2samp
        diff = ks_2samp(results[0], results[1])

        mesh[i1][i2] = diff[0]

print mesh
import pylab as pl
pl.contourf(param2Range, param1Range, mesh)
#P.hist(results[0], 50, normed=1, histtype='step', cumulative=True)
#P.show()
pl.colorbar()
pl.show()
Ejemplo n.º 52
0
def embed_dat_matrix_two_dimensions(low_dimension_data_matrix,
                                    y=None,
                                    labels=None,
                                    density_colormap='Blues',
                                    instance_colormap='YlOrRd'):
    from sklearn.preprocessing import scale
    low_dimension_data_matrix = scale(low_dimension_data_matrix)
    # make mesh
    x_min, x_max = low_dimension_data_matrix[:, 0].min(
    ), low_dimension_data_matrix[:, 0].max()
    y_min, y_max = low_dimension_data_matrix[:, 1].min(
    ), low_dimension_data_matrix[:, 1].max()
    step_num = 50
    h = min((x_max - x_min) / step_num,
            (y_max - y_min) / step_num)  # step size in the mesh
    b = h * 10  # border size
    x_min, x_max = low_dimension_data_matrix[:, 0].min(
    ) - b, low_dimension_data_matrix[:, 0].max() + b
    y_min, y_max = low_dimension_data_matrix[:, 1].min(
    ) - b, low_dimension_data_matrix[:, 1].max() + b
    xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
                         np.arange(y_min, y_max, h))

    # induce a one class model to estimate densities
    from sklearn.svm import OneClassSVM
    gamma = max(x_max - x_min, y_max - y_min)
    clf = OneClassSVM(gamma=gamma, nu=0.1)
    clf.fit(low_dimension_data_matrix)

    # Plot the decision boundary. For that, we will assign a color to each
    # point in the mesh [x_min, m_max] . [y_min, y_max].
    if hasattr(clf, "decision_function"):
        score_matrix = clf.decision_function(np.c_[xx.ravel(), yy.ravel()])
    else:
        score_matrix = clf.predict_proba(np.c_[xx.ravel(), yy.ravel()])[:, 1]
    # Put the result into a color plot
    levels = np.linspace(min(score_matrix), max(score_matrix), 40)
    score_matrix = score_matrix.reshape(xx.shape)

    if y is None:
        y = 'white'

    plt.contourf(xx,
                 yy,
                 score_matrix,
                 cmap=plt.get_cmap(density_colormap),
                 alpha=0.9,
                 levels=levels)
    plt.scatter(low_dimension_data_matrix[:, 0],
                low_dimension_data_matrix[:, 1],
                alpha=.5,
                s=70,
                edgecolors='gray',
                c=y,
                cmap=plt.get_cmap(instance_colormap))
    # labels
    if labels is not None:
        for id in range(low_dimension_data_matrix.shape[0]):
            label = labels[id]
            x = low_dimension_data_matrix[id, 0]
            y = low_dimension_data_matrix[id, 1]
            plt.annotate(label,
                         xy=(x, y),
                         xytext=(0, 0),
                         textcoords='offset points')
Ejemplo n.º 53
0
headerfile.close()

rawFilename = header[1].split()[1]

res_x = int(header[2].split()[1][:-1])  # remove the ',' at end of string
res_y = int(header[2].split()[2][:-1])  # remove the ',' at end of string
print 'xdim %s' % res_x
print 'ydim %s' % res_y

data = np.fromfile(rawFilename, dtype=np.double, count=-1, sep='')
assert data.shape[
    0] == res_x * res_y, "raw data array does not match the resolution in the header"

x = np.linspace(0., 1., res_x)
y = np.linspace(0., 1. * res_y / res_x, res_y)
X, Y = np.meshgrid(x, y)
# number of contours we wish to see
N = 12
pl.contourf(X, Y, data.reshape(res_y, res_x), N, alpha=.75, cmap='jet')
C = pl.contour(X,
               Y,
               data.reshape(res_y, res_x),
               N,
               colors='black',
               linewidth=.1)

#pl.clabel(C, inline=1)
pl.axes().set_aspect('equal')
pl.savefig("output.png", dpi=72)
pl.show()
Ejemplo n.º 54
0
                              2 * v[1]**0.5,
                              180 + angle,
                              color=color)
    ell.set_clip_box(splot.bbox)
    ell.set_alpha(0.5)
    splot.add_artist(ell)


xx, yy = np.meshgrid(np.linspace(4, 8.5, 200), np.linspace(1.5, 4.5, 200))
X_grid = np.c_[xx.ravel(), yy.ravel()]
zz_lda = lda.predict_proba(X_grid)[:, 1].reshape(xx.shape)
zz_qda = qda.predict_proba(X_grid)[:, 1].reshape(xx.shape)

pl.figure()
splot = pl.subplot(1, 2, 1)
pl.contourf(xx, yy, zz_lda > 0.5, alpha=0.5)
pl.scatter(X[y == 0, 0], X[y == 0, 1], c='b', label=target_names[0])
pl.scatter(X[y == 1, 0], X[y == 1, 1], c='r', label=target_names[1])
pl.contour(xx, yy, zz_lda, [0.5], linewidths=2., colors='k')
plot_ellipse(splot, lda.means_[0], lda.covariance_, 'b')
plot_ellipse(splot, lda.means_[1], lda.covariance_, 'r')
pl.legend()
pl.axis('tight')
pl.title('Linear Discriminant Analysis')

splot = pl.subplot(1, 2, 2)
pl.contourf(xx, yy, zz_qda > 0.5, alpha=0.5)
pl.scatter(X[y == 0, 0], X[y == 0, 1], c='b', label=target_names[0])
pl.scatter(X[y == 1, 0], X[y == 1, 1], c='r', label=target_names[1])
pl.contour(xx, yy, zz_qda, [0.5], linewidths=2., colors='k')
plot_ellipse(splot, qda.means_[0], qda.covariances_[0], 'b')
Ejemplo n.º 55
0
 def animate(i):
     ## create a frame
     Z = get_animation_data(i)
     contour = pylab.contourf(X, Y, Z, cmap=plt.cm.bone)
     plt.title('t = %.1f' % ((nT / n_frames) * (i + 1)))
     return contour
Ejemplo n.º 56
0
    np.savetxt(
        "%s_V%d_%dd_%dm.dat" %
        (orbit_id, mag_max, nb_obs_day, min_t_obs_per_orbit), data_grid)
    np.savetxt("ra_grid.dat", ra_grid)
    np.savetxt("dec_grid.dat", dec_grid)

data_grid = np.fliplr(data_grid)
ra_grid = rah_grid

v = np.arange(min_val, max_val + step_scale, step_scale)

CS = plt.contour(ra_grid, dec_grid, data_grid, colors='k', levels=v)

plt.clabel(CS, inline=1, fmt='%d', colors='k', fontsize=12)

CS = plt.contourf(ra_grid, dec_grid, data_grid, levels=v, cmap=plt.cm.winter)

plt.yticks(np.arange(-80, 100, 20.))

if include_constellation:
    for co in constel.constellations:

        co = np.asarray(co, dtype=np.float)

        co[:, 1] = co[:, 1] / 1800.
        co[:, 2] = co[:, 2] / 60.

        idc = np.where(co[:, 1] < 12.)
        co[idc, 1] = 12. - co[idc, 1]

        idc = np.where(co[:, 1] > 12.)
Ejemplo n.º 57
0
def plot2d_contour(self,
                   x=None,
                   y=None,
                   what="count(*)",
                   limits=None,
                   shape=256,
                   selection=None,
                   f="identity",
                   figsize=None,
                   xlabel=None,
                   ylabel=None,
                   aspect="auto",
                   levels=None,
                   fill=False,
                   colorbar=False,
                   colorbar_label=None,
                   colormap=None,
                   colors=None,
                   linewidths=None,
                   linestyles=None,
                   vmin=None,
                   vmax=None,
                   grid=None,
                   show=None,
                   **kwargs):
    """
    Plot conting contours on 2D grid.

    :param x: {expression}
    :param y: {expression}
    :param what: What to plot, count(*) will show a N-d histogram, mean('x'), the mean of the x column, sum('x') the sum, std('x') the standard deviation, correlation('vx', 'vy') the correlation coefficient. Can also be a list of values, like ['count(x)', std('vx')], (by default maps to column)
    :param limits: {limits}
    :param shape: {shape}
    :param selection: {selection}
    :param f: transform values by: 'identity' does nothing 'log' or 'log10' will show the log of the value
    :param figsize: (x, y) tuple passed to pylab.figure for setting the figure size
    :param xlabel: label of the x-axis (defaults to param x)
    :param ylabel: label of the y-axis (defaults to param y)
    :param aspect: the aspect ratio of the figure
    :param levels: the contour levels to be passed on pylab.contour or pylab.contourf
    :param colorbar: plot a colorbar or not
    :param colorbar_label: the label of the colourbar (defaults to param what)
    :param colormap: matplotlib colormap to pass on to pylab.contour or pylab.contourf
    :param colors: the colours of the contours
    :params linewidths: the widths of the contours
    :params linestyles: the style of the contour lines
    :param vmin: instead of automatic normalization, scale the data between vmin and vmax
    :param vmax: see vmin
    :param grid: {grid}
    :param show:
    """

    # Get the function out of the string
    f = vaex.dataset._parse_f(f)

    # Internals on what to bin
    binby = []
    x = vaex.dataset._ensure_strings_from_expressions(x)
    y = vaex.dataset._ensure_strings_from_expressions(y)
    for expression in [y, x]:
        if expression is not None:
            binby = [expression] + binby

    # The shape
    shape = vaex.dataset._expand_shape(shape, 2)

    # The limits and
    limits = self.limits(binby, limits)

    # Constructing the 2d histogram
    if grid is None:
        if what:
            if isinstance(what, (vaex.stat.Expression)):
                grid = what.calculate(self,
                                      binby=binby,
                                      limits=limits,
                                      shape=shape,
                                      selection=selection)
            else:
                what = what.strip()
                index = what.index("(")
                groups = re.match("(.*)\((.*)\)", what).groups()
                if groups and len(groups) == 2:
                    function = groups[0]
                    arguments = groups[1].strip()
                    functions = ["mean", "sum", "std", "count"]
                    if function in functions:
                        # grid = getattr(self, function)(arguments, binby, limits=limits, shape=shape, selection=selection)
                        grid = getattr(vaex.stat,
                                       function)(arguments).calculate(
                                           self,
                                           binby=binby,
                                           limits=limits,
                                           shape=shape,
                                           selection=selection)
                    elif function == "count" and arguments == "*":
                        grid = self.count(binby=binby,
                                          shape=shape,
                                          limits=limits,
                                          selection=selection)
                    elif function == "cumulative" and arguments == "*":
                        # TODO: comulative should also include the tails outside limits
                        grid = self.count(binby=binby,
                                          shape=shape,
                                          limits=limits,
                                          selection=selection)
                        grid = np.cumsum(grid)
                    else:
                        raise ValueError(
                            "Could not understand method: %s, expected one of %r'"
                            % (function, functions))
                else:
                    raise ValueError(
                        "Could not understand 'what' argument %r, expected something in form: 'count(*)', 'mean(x)'"
                        % what)
        else:
            grid = self.histogram(binby,
                                  size=shape,
                                  limits=limits,
                                  selection=selection)

    # Apply the function on the grid
    fgrid = f(grid)

    # Figure creation
    if figsize is not None:
        fig = plt.figure(num=None,
                         figsize=figsize,
                         dpi=80,
                         facecolor='w',
                         edgecolor='k')
    fig = plt.gcf()

    # labels
    plt.xlabel(xlabel or x)
    plt.ylabel(ylabel or y)

    # The master contour plot
    if fill == False:
        value = plt.contour(fgrid.T,
                            origin="lower",
                            extent=np.array(limits).ravel().tolist(),
                            linestyles=linestyles,
                            linewidths=linewidths,
                            levels=levels,
                            colors=colors,
                            cmap=colormap,
                            vmin=vmin,
                            vmax=vmax,
                            **kwargs)
    else:
        value = plt.contourf(fgrid.T,
                             origin="lower",
                             extent=np.array(limits).ravel().tolist(),
                             linestyles=linestyles,
                             levels=levels,
                             colors=colors,
                             cmap=colormap,
                             vmin=vmin,
                             vmax=vmax,
                             **kwargs)
    if colorbar:
        plt.colorbar(label=colorbar_label or what)

    # Wrap things up
    if show:
        plt.show()
    return value
Ejemplo n.º 58
0
    def graph_dos_real_space_atk(self):

        #print "NUMBER OF LDDSO BJECTS"
        #print len(nlread(self.device_config_path, LocalDeviceDensityOfStates))
        lddos_list = nlread(self.device_config_path,
                            LocalDeviceDensityOfStates)
        if not lddos_list:
            self.generate_dos_real_space()
            lddos_list = nlread(self.device_config_path,
                                LocalDeviceDensityOfStates)

        #Find the z-spacing
        dX, dY, dZ = lddos_list[0].volumeElement().convertTo(Ang)
        dz = dZ.norm()
        shape = lddos_list[0].shape()
        z = dz * numpy.arange(shape[2])

        # calculate average lddos along z for each spectrum
        energies = []
        lddos_z = []
        for lddos in lddos_list:
            energies = energies + [lddos.energy().inUnitsOf(eV)]
            avg_z = numpy.apply_over_axes(numpy.mean, lddos[:, :, :],
                                          [0, 1]).flatten()
            lddos_z = lddos_z + [avg_z]

        # plot as contour plot
        # make variables
        energies = numpy.array(energies)
        X, Y = numpy.meshgrid(z, energies)
        Z = numpy.array(lddos_z).reshape(numpy.shape(X))
        #print "X = "
        #print X
        #print "Y = "
        #print Y
        #print "Z = "
        #print Z
        #print "X min, max"
        #print numpy.amax(X)
        #print numpy.amin(X)
        #print "Y min, max"
        #print numpy.amax(Y)
        #print numpy.amin(Y)
        #print "Z min, max"
        #print numpy.amax(Z)
        #print numpy.amin(Z)

        import pylab
        #plot the LDDOS(E, z)
        pylab.xlabel('z (Angstrom)', fontsize=12, family='sans-serif')
        pylab.ylabel('Energy (eV)', fontsize=12, family='sans-serif')

        contour_values = numpy.linspace(0, numpy.amax(Z), 25)
        pylab.contourf(X, Y, Z, contour_values)
        pylab.colorbar()
        pylab.axis(
            [numpy.amin(X),
             numpy.amax(X),
             numpy.amin(Y),
             numpy.amax(Y)])

        pylab.title(self.device_config_path + ": E vs. z")
        pylab.savefig(self.device_config_path + 'lddos.png', dpi=100)
Ejemplo n.º 59
0
    density = density + np.flip(density, axis=1)
    density_min = -0.0015  #np.min(density)
    density_max = 0.0015  #np.max(density)

    J = np.sqrt(j_x**2 + j_y**2)
    j_x_m = np.ma.masked_where(J < 2e-10, j_x)
    j_y_m = np.ma.masked_where(J < 2e-10, j_y)

    print("x.shape : ", x.shape)

    #    plot_grid(x[::1, ::1], y[::1, ::1], alpha=0.5)
    #im = pl.contourf(x, y, density.T, 100, norm=MidpointNormalize(midpoint=0, vmin=density_min, vmax=density_max), cmap='bwr')
    im = pl.contourf(x,
                     y,
                     density.T,
                     200,
                     norm=colors.SymLogNorm(linthresh=density.max() / 20,
                                            vmin=density_min,
                                            vmax=density_max),
                     cmap='bwr')
    m = pl.cm.ScalarMappable(cmap='bwr')
    m.set_array(density.T)
    m.set_clim(density_min, density_max)
    pl.colorbar(m, boundaries=np.linspace(density_min, density_max, 100))
    pl.title(r'Time = ' + "%.2f" % (time_array[start_index + file_number]) +
             " ps")

    #pl.streamplot(x[:, 0], y[0, :],
    #              j_x_m, j_y_m,
    #              density=2, color='k',
    #              linewidth=1, arrowsize=1.2
    #             )
Ejemplo n.º 60
0
y = np.arange(-1, 13, dx)

x_src = np.array([1, 2.50, 2.5, 1])
y_src = np.array([1, 5, 10, 1])

x_src = np.array([1, 1, 1, 1])
y_src = np.array([10, 7, 4, 1])

S = np.array([x_src, y_src]).transpose()

xx, yy = np.meshgrid(x, y)

V = 0.1 * np.ones_like(xx)
V[yy > 6] = 0.15
V[np.logical_and(np.abs(yy) > 7, xx > 2.5)] = 0.18

t_map = eikonal(x, y, [], V, S)

#%%
plt.subplot(1, 1, 1)
plt.pcolor(x, y, V)
plt.axis('image')
plt.show

#%%
for i in range(S.shape[0]):
    plt.subplot(1, S.shape[0] + 1, i + 1)
    plt.contourf(x, y, t_map[i])
    plt.axis('image')
plt.show()