forked from arthurBarthe/swe_stochastic_param
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spinup.py
77 lines (62 loc) · 2.19 KB
/
spinup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
A script to spinup a high-resolution instance of the
shallow water model as a test.
"""
from shallowwater import ShallowWaterModel
from netCDF4 import Dataset
from utils import coarsen
import numpy as np
from os.path import join
import matplotlib.pyplot as plt
import matplotlib
output_path = '/media/arthur/DATA/NYU/simulations/'
# output_path = '/scratch/ag7531/shallowWaterModel/'
from_spinup = False
n_years = 10
domain_size = 3840
factor = 1
i_run = 'non_parameterized_'
model = ShallowWaterModel(output_path=output_path,
Nx=domain_size // 10 // factor,
Ny=domain_size // 10 // factor,
Lx=domain_size * 1e3,
Ly=domain_size * 1e3,
Nt=n_years*360*24*60*60,
dump_freq=1*24*60*60, dump_output=True, tau0=0.12,
model_name='eddy_permitting',
run_name=str(i_run))
u, v, eta = model.set_initial_cond(init='rest')
if from_spinup:
# load high-rez simulation, coarse-grain
u_dataset = Dataset('spinup1/u_eddy_permitting__10yr_spinup.nc')
v_dataset = Dataset('spinup1/v_eddy_permitting__10yr_spinup.nc')
eta_dataset = Dataset('spinup1/eta_eddy_permitting__10yr_spinup.nc')
u = u_dataset.variables['u'][-1, ...]
v = v_dataset.variables['v'][-1, ...]
eta = eta_dataset.variables['eta'][-1, ...]
u = coarsen(u, 4)
v = coarsen(v, 4)
eta = coarsen(eta, 4)
u = np.squeeze(u.reshape((-1, 1)))
v = np.squeeze(v.reshape((-1, 1)))
eta = np.squeeze(eta.reshape((-1, 1)))
model.u = u
model.v = v
model.eta = eta
last_percent = None
for i in range( model.N_iter ) :
percent = int(1000.0 * float(i) / model.N_iter)
if percent != last_percent:
print( "{}%".format( percent / 10 ) )
last_percent = percent
plt.imshow(model.u2mat(u), vmin=-0.5, vmax=0.5, cmap='PuOr')
plt.show(block=False)
plt.draw()
plt.pause(1)
u_new, v_new, eta_new = model.integrate_forward( u, v, eta )
if u_new is None :
print( "Integration finished!" )
break
u = u_new
v = v_new
eta = eta_new