コード例 #1
0
ファイル: plot_ensemble.py プロジェクト: myying/rankine
Rmw = 5  # radius of maximum wind
Vmax = 50  # maximum wind speed
Vout = 0  # wind speed outside of vortex
iStorm = 63  # location of vortex in i, j
jStorm = 63
wind_highlight = (-15, 15)

##truth
Xt = np.load(outdir + 'truth_state.npy')[:, t]

# plt.switch_backend('Agg')
plt.figure(figsize=(10, 10))
cmap = [plt.cm.jet(x) for x in np.linspace(0, 1, nens)]

ax = plt.subplot(221)
u, v = rv.X2uv(ni, nj, Xt)
zeta = rv.uv2zeta(u, v, dx)
ii, jj = np.mgrid[0:ni, 0:nj]
# ax.contourf(ii, jj, u, np.arange(-70, 71, 5), cmap='bwr')
ax.contourf(ii, jj, zeta, np.arange(-3, 3, 0.1) * 1e-3, cmap='bwr')
ax.contour(ii, jj, u, wind_highlight, colors='k', linewidths=3)
ax.set_title('Truth', fontsize=20)
ax.tick_params(labelsize=15)

for k in range(len(filter_kind)):
    Xa = np.load(outdir + filter_kind[k] + '_ens.npy')[:, :, 1, t]
    ax = plt.subplot(2, 2, k + 2)
    for m in range(nens):
        u, v = rv.X2uv(ni, nj, Xa[:, m])
        ax.contour(ii,
                   jj,
コード例 #2
0
ファイル: run_single.py プロジェクト: cd10kfsu/rankine
jBias = 0
Rsprd = 0
Vsprd = 0

filter_kind = sys.argv[1]  #'EnSRF'
ns = int(sys.argv[2])
nens = int(sys.argv[3])  # ensemble size
Csprd = int(sys.argv[4])
obsR = int(sys.argv[5])
obserr = int(sys.argv[6])  # observation error spread
localize_cutoff = 0

##truth
iX, jX = rv.make_coords(ni, nj)
Xt = rv.make_state(ni, nj, nv, iStorm, jStorm, Rmw, Vmax, Vout)
ut, vt = rv.X2uv(ni, nj, Xt)

##DA trials
casename = '{}_s{}_N{}_C{}_R{}_err{}'.format(filter_kind, ns, nens, Csprd,
                                             obsR, obserr)

if os.path.exists(outdir + casename + '.npy'):
    state_error = np.load(outdir + casename + '.npy')
else:
    state_error = np.zeros((nrealize, nens + 1))
    state_error[:, :] = np.nan

for realize in range(r0, r0 + 100):
    np.random.seed(realize)  # fix random number seed, make results predictable

    ##Prior ensemble
コード例 #3
0
casename = ('NoDA_s1', 'obs.intv.1/EnSRF_s1', 'obs.intv.1/EnSRF_s4'
            )  #sys.argv[1] #'EnSRF_s3'
col = ([.3, .6, .3], [.8, .3, .1], [.2, .7, .9])
for c in range(3):
    X = np.load(outdir + 'truth_state.npy')
    loc = np.load(outdir + 'truth_ij.npy')
    wind = np.load(outdir + 'truth_wind.npy')
    Xens = np.load(outdir + casename[c] + '_ens.npy')
    loc_ens = np.load(outdir + casename[c] + '_ij.npy')
    wind_ens = np.load(outdir + casename[c] + '_wind.npy')
    nX, nens, nc, nt = Xens.shape
    tt = np.arange(0, nt * 2, 2)  ##time in h
    cmap = [plt.cm.jet(x) for x in np.linspace(0, 1, nens)]

    ii, jj = np.mgrid[0:ni, 0:nj]
    u, v = rv.X2uv(ni, nj, X[:, -1])
    zeta = rv.uv2zeta(u, v, dx)

    ##track errors
    ax = plt.subplot(231)
    # c = ax.contourf(ii, jj, zeta, np.arange(-3, 3, 0.1)*1e-3, cmap='bwr')
    # c = ax.contourf(ii, jj, u, np.arange(-70, 70, 5), cmap='bwr')
    for m in range(nens):
        ax.plot(loc_ens[0, m, 1, 0:nt],
                loc_ens[1, m, 1, 0:nt],
                color=col[c],
                marker=None)  ##member
    # ax.plot(loc[0, nens, 0:nt], loc_ens[1, nens, 0:nt], 'g', linewidth=3) ##ens mean
    ax.plot(loc[0, 0:nt], loc[1, 0:nt], 'k', linewidth=3)  ##true
    ax.set_xlim(20, 80)
    ax.set_ylim(40, 100)
コード例 #4
0
X = np.zeros((ni * nj * nv, nt + 1))
loc = np.zeros((2, nt + 1))
wind = np.zeros((nt + 1, ))
obs = np.zeros((nt + 1, nobs * nv))
iObs = np.zeros((nt + 1, nobs * nv))
jObs = np.zeros((nt + 1, nobs * nv))
vObs = np.zeros((nt + 1, nobs * nv))

##initial state
np.random.seed(0)
X_bkg = rv.make_background_flow(ni, nj, nv, dx, ampl=1e-4)
X[:, 0] = X_bkg + rv.make_state(ni, nj, nv, iStorm, jStorm, Rmw, Vmax, Vout)

for n in range(nt + 1):
    print(n)
    u, v = rv.X2uv(ni, nj, X[:, n])
    zeta = rv.uv2zeta(u, v, dx)
    loc[0, n], loc[1, n] = rv.get_center_ij(u, v, dx)
    wind[n] = rv.get_max_wind(u, v)

    for p in range(nobs):
        for v in range(nv):
            iObs[n, p * nv +
                 v] = np.random.uniform(-obs_range, obs_range) + loc[0, n]
            jObs[n, p * nv +
                 v] = np.random.uniform(-obs_range, obs_range) + loc[1, n]
            vObs[n, p * nv + v] = v
    H = rv.obs_operator(iX, jX, nv, iObs[n, :], jObs[n, :], vObs[n, :])
    obs[n, :] = np.dot(H, X[:, n]) + np.random.normal(0.0, obserr,
                                                      (nobs * nv, ))
コード例 #5
0
nj = 128
nv = 2  # number of variables, (u, v)
dx = 9000
nt = 12
obs_int = 1
cmap = [plt.cm.jet(x) for x in np.linspace(0, 1, nt)]

X = np.load(outdir + 'truth_state.npy')

obs = np.load(outdir + 'obs.npy')
iObs = np.load(outdir + 'obs_i.npy')
jObs = np.load(outdir + 'obs_j.npy')
nt1, nobs1 = obs.shape
nobs = int(nobs1 / 2)

ii, jj = np.mgrid[0:ni, 0:nj]
u, v = rv.X2uv(ni, nj, X[:, -1])
zeta = rv.uv2zeta(u, v, dx)

plt.figure(figsize=(10, 8))
ax = plt.subplot(111)
for n in range(0, nt, obs_int):
    ax.scatter(iObs[n, ::2], jObs[n, ::2], s=50, color=[cmap[n][0:3]])
#for p in range(nobs):

ax.set_xlim(0, ni)
ax.set_ylim(0, nj)

# plt.savefig('1.pdf')
plt.show()
コード例 #6
0
                               obs, obserr, 0, np.arange(1, 2), 'EnSRF')
Xa[2, :, :] = DA.filter_update(ni, nj, nv, Xb, iX, jX, H, iObs, jObs, vObs,
                               obs, obserr, 0, np.arange(1, 2), 'EnSRF')
Xa[3, :, :] = DA.filter_update(ni, nj, nv, Xb, iX, jX, H, iObs, jObs, vObs,
                               obs, obserr, 0, np.arange(1, 2), 'PF')

##plot
plt.switch_backend('Agg')
plt.figure(figsize=(7, 7))
ii, jj = np.mgrid[0:ni, 0:nj]
cmap = [plt.cm.jet(m) for m in np.linspace(0.2, 0.8, nens)]

for i in range(4):
    ax = plt.subplot(2, 2, i + 1)
    for m in range(nens):
        u, v = rv.X2uv(ni, nj, Xa[i, m, :])
        ax.contour(ii, jj, u, (-15, 15), colors=[cmap[m][0:3]], linewidths=2)
    # u, v = rv.X2uv(ni, nj, np.mean(Xa[i, :, :], axis=0))
    # ax.contour(ii, jj, u, (-15, 15), colors='r', linewidths=3)
    ut, vt = rv.X2uv(ni, nj, Xt)
    ax.contour(ii, jj, ut, (-15, 15), colors='k', linewidths=3)
    ax.plot(iObs, jObs, 'k+', markersize=10, markeredgewidth=2)
    ax.plot(iout, jout, 'kx', markersize=10, markeredgewidth=2)
    ax.set_aspect('equal', 'box')
    ax.set_xlim(43, 83)
    ax.set_ylim(43, 83)
    ax.set_xticks(np.arange(43, 84, 10))
    ax.set_xticklabels(np.arange(-20, 21, 10))
    ax.set_yticks(np.arange(43, 84, 10))
    ax.set_yticklabels(np.arange(-20, 21, 10))
    ax.tick_params(labelsize=12)
コード例 #7
0
ファイル: plot_spaghetti.py プロジェクト: myying/rankine
### Rankine Vortex definition, truth
Rmw = 5  # radius of maximum wind
Vmax = 50  # maximum wind speed
Vout = 0  # wind speed outside of vortex
iStorm = 63  # location of vortex in i, j
jStorm = 63

##truth
Xt = np.load(outdir + 'truth_state.npy')[:, t]

plt.switch_backend('Agg')
plt.figure(figsize=(10, 10))
cmap = [plt.cm.jet(x) for x in np.linspace(0, 1, nens)]

ax = plt.subplot(221)
u, v = rv.X2uv(ni, nj, Xt)
ii, jj = np.mgrid[0:ni, 0:nj]
ax.contourf(ii, jj, u, np.arange(-50, 51, 5), cmap='bwr')
g.plot_contour(ax, ni, nj, Xt, 'black', 3)
g.set_axis(ax, ni, nj)
ax.set_title('Truth', fontsize=20)
ax.tick_params(labelsize=15)

for k in range(len(filter_kind)):
    Xa = np.load(outdir + filter_kind[k] + '_ens.npy')[:, :, t]
    ax = plt.subplot(2, 2, k + 2)
    for n in range(nens):
        g.plot_contour(ax, ni, nj, Xa[:, n], [cmap[n][0:3]], 1)
    g.plot_contour(ax, ni, nj, Xt, 'black', 3)
    g.set_axis(ax, ni, nj)
    ax.set_title(filter_kind[k], fontsize=20)