Exemple #1
0
def plotTable(v, vol, prob, lbds, MOQ, name):
    """
   DEFINITION:
   v: index in volatility array
   vol: volatility array. Contains simulated volatilities.
   name: name of the plot. 
   """
    np, _, nr, _ = shape(MOQ)
    MOQshape = zeros((np, nr))
    for p in xrange(len(prob)):
        for r in xrange(len(lbds)):
            MOQshape[p, r] = mean(MOQ[p, v, r, :])
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    X = lbds
    Y = prob
    X, Y = meshgrid(X, Y)
    Z = MOQshape
    plt.xlabel('Lambdas')
    plt.ylabel('Probabilities')
    plt.title(name + ' for fixed lambdas - v=' + str(vol[v]))
    surf = ax.plot_surface(X,
                           Y,
                           Z,
                           rstride=1,
                           cstride=1,
                           cmap=cm.jet,
                           linewidth=0,
                           antialiased=False)
    ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
    fig.colorbar(surf, shrink=0.5, aspect=5)
Exemple #2
0
def study_consts_proximity(in_file, acc = 3):
    
    print 'studying consts proximity..'
    
    try:
        params, asurf =   read_bender_output(in_file)[:2] # + 'params.txt')
    except IOError as e:
        print 'there, is no file for this input... got ' + e 
    
    #print params[("consts")]
                
    phi_period  =   params[("phiperiod")]
    hangle      =   params[("height")] / 2 / pi
    system      =   params[("system")]
    
    ue          =   u(hangle, phi_period, asurf, system = system, consts = params[("consts")])
    energies    =   deform_energies(ue)
    
    delx        =   abs(params[("consts")][0]) / 10.
    delA        =   abs(params[("consts")][1]) / 2.
    x, A        =   params[("consts")][:2]

    if delA     ==   0.:
        Amin    =   0
        Amax    =   params[("height")]/70.
    else:
        Amin, Amax =   A - 2*delA, A + delA
    
    x_set       =   np.linspace(x - delx, x + delx, acc)        
    A_set       =   np.linspace(Amin, Amax, acc)  
    curve_start =   params[("consts")][2]
    mid         =   params[("consts")][3]
    n_wave      =   params[("consts")][4]
    
    mesh_x, mesh_A \
                =   meshgrid(x_set, A_set)  
    
    E_b_mat     =   np.zeros(mesh_x.shape)
    E_s_mat     =   np.zeros(mesh_x.shape)
    
    for index, x in np.ndenumerate(mesh_x):
        A       =   mesh_A[index]
        consts  =   [x, A, curve_start, mid, n_wave]
        E_b_mat[index], E_s_mat[index] \
                =   energies.calc_energies(consts)[:2]
        
    #print E_s_mat
    #print E_b_mat
    
    folder = parse_path(params, params[("moldy_opm")]) + 'opm_consts_proxm/'
    
    if not exists(folder):
        makedirs(folder)   
    
    np.save(folder + 'mesh_x'   , mesh_x) 
    np.save(folder + 'mesh_A'   , mesh_A) 
    np.save(folder + 'E_b_mat_consts_proxm', E_b_mat) 
    np.save(folder + 'E_s_mat_consts_proxm', E_s_mat) 
    
    plot_consts_proxm(mesh_x, mesh_A, E_b_mat, E_s_mat, folder, from_file = False, acc = acc)
Exemple #3
0
def plot3D(a):
    b = np.array(range(-100,100))
    c = np.array(range(-100,100))
    B,C = meshgrid(b,c)
    d=eval(a)  
    d=np.expand_dims(d,axis=0)

    fig = plt.figure()
    ax = Axes3D(fig)
    ax.plot_surface(B,C,d, rstride=1, cstride=1,
                cmap='viridis', edgecolor='none')
    plt.xlabel('b')
    plt.ylabel('c')
    plt.savefig("An\\plot3D.png")
    plt.close()
Exemple #4
0
def plot_hipothesys_fit(feats, X, theta_opt):

    def _minmax(v1, v2):
        return min(v1), max(v1), min(v2), max(v2)

    f1 = figure('fig1')
    ax = f1.gca(projection='3d')
    minx, maxx, miny, maxy = _minmax(X[:, 1], X[:, 2])
    zi = np.matrix([
        [1, minx, miny],
        [1, minx, maxy],
        [1, maxx, miny],
        [1, maxx, maxy],
    ]).dot(theta_opt)
    zi = [z[0, 0] for z in zi]
    minf0, maxf0, minf1, maxf1 = _minmax(feats[:, 0], feats[:, 1])
    f0i = [minf0, minf0, maxf0, maxf0]
    f1i = [minf1, maxf1, minf1, maxf1]
    f0im, f1im = meshgrid(f0i, f1i)
    ax.plot_surface(f0im, f1im, zi)
Exemple #5
0
def main():
    path = "/home/huziy/skynet3_exec1/from_guillimin/cell_area.rpn"
    r = RPN(path)
    tile = r.get_first_record_for_name("TILE")
    lkid = r.get_first_record_for_name("LKID")
    larea = r.get_first_record_for_name("AREA")
    r.close()



    #path = "/home/huziy/skynet3_exec1/from_guillimin/infocell.rpn"
    path = "infocell_260x260.rpn"
    rObj = RPN(path)
    dirs = rObj.get_first_record_for_name("FLDR")
    facc = rObj.get_first_record_for_name("FACC")
    lkfr = rObj.get_first_record_for_name("LKFR")
    lkou = rObj.get_first_record_for_name("LKOU")
    lons2d, lats2d = rObj.get_longitudes_and_latitudes()
    rObj.close()


    di_list = np.array([1,1,0,-1,-1,-1,0,1])
    dj_list = np.array([0,-1,-1,-1,0,1,1,1])

    delta_indices = np.log2(dirs[dirs > 0])
    delta_indices = delta_indices.astype(int)

    di = di_list[delta_indices].astype(float)
    dj = dj_list[delta_indices].astype(float)

    du = di / np.sqrt(di ** 2 + dj ** 2)
    dv = dj / np.sqrt(di ** 2 + dj ** 2)


    for i in range(100):
        print(du[i], dv[i], np.log2(dirs[dirs > 0][i]))

    du2d = np.ma.masked_all(dirs.shape)
    dv2d = np.ma.masked_all(dirs.shape)

    du2d[dirs>0] = du
    dv2d[dirs>0] = dv

    print(du2d[161,145],dv2d[161,145],dirs[161,145])

    iv = range(dirs.shape[0])
    jv = range(dirs.shape[1])

    jv, iv = meshgrid(jv, iv)


    iv = iv.astype(float)
    jv = jv.astype(float)

    iv -= 0.5
    jv -= 0.5

    print(iv.min(), iv.max())

    plt.figure()
    #field = np.ma.masked_where((field > 1e10) | (field < 1e7) , field)
    #tile1 = np.ma.masked_where((tile != 25) & (tile != 26), tile)
    plt.pcolormesh(iv,jv,tile,cmap = cm.get_cmap("jet", 36))
    plt.colorbar()
    plt.xlim(75, 100)
    plt.ylim(130,142)


    
    plt.figure()
    lkid = lkid.astype(int)
    print(lkid[161,146], lkid[161,145],lkid[160,145:148])

    
    for i in range(1,121):
        x = np.ma.masked_where(lkid != i, lkid)
        if x.count() == 1 or x.count() == 0:
            print(i, x.count())
    #lkid = np.ma.masked_where(~((lkid == 27)|(lkid == 28)) , lkid)

    lkid = np.ma.masked_where(lkid <= 0, lkid)
    b, lons2d, lats2d = draw_regions.get_basemap_and_coords(
        file_path=path,
        lon1=-68, lat1=52, lon2=16.65, lat2=0
    )
    x,y = b(lons2d, lats2d)
    img = b.pcolormesh(x,y,lkid,cmap = cm.get_cmap("jet", 100))
    plt.colorbar(img, ticks = MultipleLocator(base = 10))
    b.contour(x, y,tile, levels = range(48), colors = "k", linewidth = 0.5)
    b.drawcoastlines(linewidth=0.5)

    #plt.quiver(iv+0.5, jv+0.5, du2d, dv2d, scale = 30, width = 0.005, color="k", pivot="middle")
    #plt.xlim(30, 70)
    #plt.ylim(10,35)

    plt.figure()
    plt.pcolormesh(iv,jv,lkfr,cmap = cm.get_cmap("jet", 11))
    plt.colorbar()
    plt.xlim(155, 165)
    plt.ylim(140,150)


    

    plt.figure()
    d = np.ma.masked_all(dirs.shape)
    d[dirs > 0] = np.log2(dirs[dirs > 0]) 
    plt.pcolormesh(iv, jv, d,cmap = cm.get_cmap("jet", 8))
    plt.xlim(155, 165)
    plt.ylim(140,150)
    plt.colorbar(ticks = MultipleLocator(base = 1))
    plt.quiver(iv+0.5, jv+0.5, du2d, dv2d, scale = 4.5, width = 0.035, color="k", pivot="middle", units="inches")


    plt.figure()
    plt.title("Lake area")
    plt.pcolormesh(iv, jv, np.ma.masked_where( larea < 1.0e8, np.log(larea) ),cmap = cm.get_cmap("jet", 8))
    #plt.xlim(155, 165)
    #plt.ylim(140,150)
    print(larea.min(), larea.max())
    plt.colorbar(ticks = LinearLocator(numticks = 10))
    #plt.quiver(iv+0.5, jv+0.5, du2d, dv2d, scale = 4.5, width = 0.035, color="k", pivot="middle", units="inches")



    plt.show()

    pass
Exemple #6
0
def read_directions():
    #path = "/home/huziy/skynet3_exec1/from_guillimin/infocell.rpn"
    path = "infocell_260x260.rpn"

    i_start = 20
    j_start = 20
    i_end = i_start + 200
    j_end = j_start + 200
    rObj = RPN(path)
    dirs = rObj.get_first_record_for_name("FLDR")[i_start:i_end, j_start:j_end]
    facc = rObj.get_first_record_for_name("FACC")[i_start:i_end, j_start:j_end]
    lkfr = rObj.get_first_record_for_name("LKFR")[i_start:i_end, j_start:j_end]
    lkou = rObj.get_first_record_for_name("LKOU")[i_start:i_end, j_start:j_end]
    lons2d, lats2d = rObj.get_longitudes_and_latitudes()
    rObj.close()


    di_list = np.array([1,1,0,-1,-1,-1,0,1])
    dj_list = np.array([0,-1,-1,-1,0,1,1,1])



    delta_indices = np.log2(dirs[dirs > 0])
    delta_indices = delta_indices.astype(int)

    di = di_list[delta_indices].astype(float)
    dj = dj_list[delta_indices].astype(float)

    du = di / (di ** 2 + dj ** 2)
    dv = dj / (di ** 2 + dj ** 2)


    du_2d = np.ma.masked_all(dirs.shape)
    dv_2d = np.ma.masked_all(dirs.shape)

    du_2d[dirs > 0] = du
    dv_2d[dirs > 0] = dv


    assert isinstance(delta_indices, np.ndarray)
    print(delta_indices.shape)



    di_field = np.ma.masked_all(dirs.shape)
    dj_field = np.ma.masked_all(dirs.shape)


    di_field[dirs > 0] = di_list[delta_indices]
    dj_field[dirs > 0] = dj_list[delta_indices]


    di_field = di_field.astype(int)
    dj_field = dj_field.astype(int)

    nx, ny = dirs.shape
    i_p = range(nx)
    j_p = range(ny)

    j_p, i_p = meshgrid(j_p, i_p)
    i_n, j_n = np.zeros(i_p.shape), np.zeros(j_p.shape)

    i_n[dirs > 0] = i_p[dirs > 0] + di_field[dirs > 0]
    j_n[dirs > 0] = j_p[dirs > 0] + dj_field[dirs > 0]



    cells = []
    for i in range(nx):
        cells.append([])
        for j in range(ny):
            cells[i].append(Cell(i, j))

    for i in range(nx):
        for j in range(ny):
            cells[i][j].lakefr = lkfr[i,j]
            if dirs[i, j] <= 0:
                cells[i][j].set_next(None)
                continue

            di = di_field[i, j]
            dj = dj_field[i, j]

            cells[i][j].set_next(cells[i+di][j+dj])


    lkou = lkou.astype(int)
    iou, jou = np.where(lkou == 1)

    for i,j in zip(iou, jou):
        print((i,j, cells[i][j].get_lake_size_in_indexes(), cells[i][j].lakefr))

    print(dirs[54, 150], dirs[53, 151])

    ii = 33
    jj = 96

    outlet = cells[ii][jj]
    i_lake, j_lake = outlet.get_prev_lake_indexes()

    save = di_field[i_lake, j_lake]
    di_field = np.ma.masked_all(di_field.shape)
    di_field[i_lake, j_lake] = save

    save = dj_field[i_lake, j_lake]
    dj_field = np.ma.masked_all(dj_field.shape)
    dj_field[i_lake, j_lake] = save




    plt.figure()
    #plt.contourf(dirs, levels = map( lambda x, p: x ** p, [2]*8, range(8)))
    #plt.pcolormesh(facc.transpose())




    plt.quiver(i_p,j_p, du_2d, dv_2d , scale = 0.5, width = 0.1 ,
        units = "xy", pivot = "middle", zorder = 5)

    plt.pcolormesh(i_p, j_p, dirs)
    plt.colorbar()

    print(list(map( lambda x, p: x ** p, [2]*8, list(range(8)))))
    #plt.colorbar()



    #plot



    plt.show()
Exemple #7
0
def main():
    path = "/home/huziy/skynet3_exec1/from_guillimin/cell_area.rpn"
    r = RPN(path)
    tile = r.get_first_record_for_name("TILE")
    lkid = r.get_first_record_for_name("LKID")
    larea = r.get_first_record_for_name("AREA")
    r.close()

    #path = "/home/huziy/skynet3_exec1/from_guillimin/infocell.rpn"
    path = "infocell_260x260.rpn"
    rObj = RPN(path)
    dirs = rObj.get_first_record_for_name("FLDR")
    facc = rObj.get_first_record_for_name("FACC")
    lkfr = rObj.get_first_record_for_name("LKFR")
    lkou = rObj.get_first_record_for_name("LKOU")
    lons2d, lats2d = rObj.get_longitudes_and_latitudes()
    rObj.close()

    di_list = np.array([1, 1, 0, -1, -1, -1, 0, 1])
    dj_list = np.array([0, -1, -1, -1, 0, 1, 1, 1])

    delta_indices = np.log2(dirs[dirs > 0])
    delta_indices = delta_indices.astype(int)

    di = di_list[delta_indices].astype(float)
    dj = dj_list[delta_indices].astype(float)

    du = di / np.sqrt(di**2 + dj**2)
    dv = dj / np.sqrt(di**2 + dj**2)

    for i in range(100):
        print(du[i], dv[i], np.log2(dirs[dirs > 0][i]))

    du2d = np.ma.masked_all(dirs.shape)
    dv2d = np.ma.masked_all(dirs.shape)

    du2d[dirs > 0] = du
    dv2d[dirs > 0] = dv

    print(du2d[161, 145], dv2d[161, 145], dirs[161, 145])

    iv = range(dirs.shape[0])
    jv = range(dirs.shape[1])

    jv, iv = meshgrid(jv, iv)

    iv = iv.astype(float)
    jv = jv.astype(float)

    iv -= 0.5
    jv -= 0.5

    print(iv.min(), iv.max())

    plt.figure()
    #field = np.ma.masked_where((field > 1e10) | (field < 1e7) , field)
    #tile1 = np.ma.masked_where((tile != 25) & (tile != 26), tile)
    plt.pcolormesh(iv, jv, tile, cmap=cm.get_cmap("jet", 36))
    plt.colorbar()
    plt.xlim(75, 100)
    plt.ylim(130, 142)

    plt.figure()
    lkid = lkid.astype(int)
    print(lkid[161, 146], lkid[161, 145], lkid[160, 145:148])

    for i in range(1, 121):
        x = np.ma.masked_where(lkid != i, lkid)
        if x.count() == 1 or x.count() == 0:
            print(i, x.count())
    #lkid = np.ma.masked_where(~((lkid == 27)|(lkid == 28)) , lkid)

    lkid = np.ma.masked_where(lkid <= 0, lkid)
    b, lons2d, lats2d = draw_regions.get_basemap_and_coords(file_path=path,
                                                            lon1=-68,
                                                            lat1=52,
                                                            lon2=16.65,
                                                            lat2=0)
    x, y = b(lons2d, lats2d)
    img = b.pcolormesh(x, y, lkid, cmap=cm.get_cmap("jet", 100))
    plt.colorbar(img, ticks=MultipleLocator(base=10))
    b.contour(x, y, tile, levels=range(48), colors="k", linewidth=0.5)
    b.drawcoastlines(linewidth=0.5)

    #plt.quiver(iv+0.5, jv+0.5, du2d, dv2d, scale = 30, width = 0.005, color="k", pivot="middle")
    #plt.xlim(30, 70)
    #plt.ylim(10,35)

    plt.figure()
    plt.pcolormesh(iv, jv, lkfr, cmap=cm.get_cmap("jet", 11))
    plt.colorbar()
    plt.xlim(155, 165)
    plt.ylim(140, 150)

    plt.figure()
    d = np.ma.masked_all(dirs.shape)
    d[dirs > 0] = np.log2(dirs[dirs > 0])
    plt.pcolormesh(iv, jv, d, cmap=cm.get_cmap("jet", 8))
    plt.xlim(155, 165)
    plt.ylim(140, 150)
    plt.colorbar(ticks=MultipleLocator(base=1))
    plt.quiver(iv + 0.5,
               jv + 0.5,
               du2d,
               dv2d,
               scale=4.5,
               width=0.035,
               color="k",
               pivot="middle",
               units="inches")

    plt.figure()
    plt.title("Lake area")
    plt.pcolormesh(iv,
                   jv,
                   np.ma.masked_where(larea < 1.0e8, np.log(larea)),
                   cmap=cm.get_cmap("jet", 8))
    #plt.xlim(155, 165)
    #plt.ylim(140,150)
    print(larea.min(), larea.max())
    plt.colorbar(ticks=LinearLocator(numticks=10))
    #plt.quiver(iv+0.5, jv+0.5, du2d, dv2d, scale = 4.5, width = 0.035, color="k", pivot="middle", units="inches")

    plt.show()

    pass
Exemple #8
0
def read_directions():
    #path = "/home/huziy/skynet3_exec1/from_guillimin/infocell.rpn"
    path = "infocell_260x260.rpn"

    i_start = 20
    j_start = 20
    i_end = i_start + 200
    j_end = j_start + 200
    rObj = RPN(path)
    dirs = rObj.get_first_record_for_name("FLDR")[i_start:i_end, j_start:j_end]
    facc = rObj.get_first_record_for_name("FACC")[i_start:i_end, j_start:j_end]
    lkfr = rObj.get_first_record_for_name("LKFR")[i_start:i_end, j_start:j_end]
    lkou = rObj.get_first_record_for_name("LKOU")[i_start:i_end, j_start:j_end]
    lons2d, lats2d = rObj.get_longitudes_and_latitudes()
    rObj.close()

    di_list = np.array([1, 1, 0, -1, -1, -1, 0, 1])
    dj_list = np.array([0, -1, -1, -1, 0, 1, 1, 1])

    delta_indices = np.log2(dirs[dirs > 0])
    delta_indices = delta_indices.astype(int)

    di = di_list[delta_indices].astype(float)
    dj = dj_list[delta_indices].astype(float)

    du = di / (di**2 + dj**2)
    dv = dj / (di**2 + dj**2)

    du_2d = np.ma.masked_all(dirs.shape)
    dv_2d = np.ma.masked_all(dirs.shape)

    du_2d[dirs > 0] = du
    dv_2d[dirs > 0] = dv

    assert isinstance(delta_indices, np.ndarray)
    print(delta_indices.shape)

    di_field = np.ma.masked_all(dirs.shape)
    dj_field = np.ma.masked_all(dirs.shape)

    di_field[dirs > 0] = di_list[delta_indices]
    dj_field[dirs > 0] = dj_list[delta_indices]

    di_field = di_field.astype(int)
    dj_field = dj_field.astype(int)

    nx, ny = dirs.shape
    i_p = range(nx)
    j_p = range(ny)

    j_p, i_p = meshgrid(j_p, i_p)
    i_n, j_n = np.zeros(i_p.shape), np.zeros(j_p.shape)

    i_n[dirs > 0] = i_p[dirs > 0] + di_field[dirs > 0]
    j_n[dirs > 0] = j_p[dirs > 0] + dj_field[dirs > 0]

    cells = []
    for i in range(nx):
        cells.append([])
        for j in range(ny):
            cells[i].append(Cell(i, j))

    for i in range(nx):
        for j in range(ny):
            cells[i][j].lakefr = lkfr[i, j]
            if dirs[i, j] <= 0:
                cells[i][j].set_next(None)
                continue

            di = di_field[i, j]
            dj = dj_field[i, j]

            cells[i][j].set_next(cells[i + di][j + dj])

    lkou = lkou.astype(int)
    iou, jou = np.where(lkou == 1)

    for i, j in zip(iou, jou):
        print(
            (i, j, cells[i][j].get_lake_size_in_indexes(), cells[i][j].lakefr))

    print(dirs[54, 150], dirs[53, 151])

    ii = 33
    jj = 96

    outlet = cells[ii][jj]
    i_lake, j_lake = outlet.get_prev_lake_indexes()

    save = di_field[i_lake, j_lake]
    di_field = np.ma.masked_all(di_field.shape)
    di_field[i_lake, j_lake] = save

    save = dj_field[i_lake, j_lake]
    dj_field = np.ma.masked_all(dj_field.shape)
    dj_field[i_lake, j_lake] = save

    plt.figure()
    #plt.contourf(dirs, levels = map( lambda x, p: x ** p, [2]*8, range(8)))
    #plt.pcolormesh(facc.transpose())

    plt.quiver(i_p,
               j_p,
               du_2d,
               dv_2d,
               scale=0.5,
               width=0.1,
               units="xy",
               pivot="middle",
               zorder=5)

    plt.pcolormesh(i_p, j_p, dirs)
    plt.colorbar()

    print(list(map(lambda x, p: x**p, [2] * 8, list(range(8)))))
    #plt.colorbar()

    #plot

    plt.show()