Skip to content

Commit a73bc42

Browse files
committed
update random_perturb: to match the current version of mod_random_forcing
1 parent d201d5b commit a73bc42

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

NEDAS/utils/random_perturb.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def random_perturb(grid, fields, prev_perturb, dt=1, n=0, seed=None, **kwargs):
7878
for vname in ['atmos_surf_velocity', 'atmos_surf_press']:
7979
assert vname in params.keys(), f'{vname} not in variable list, cannot run press_wind_relate option'
8080

81-
for s in range(ns):
81+
for s in range(params['atmos_surf_press']['nscale']):
8282
perturb['atmos_surf_velocity'][s] = get_velocity_from_press(grid, perturb['atmos_surf_press'][s], ('scale_wind' in other_opts), params['atmos_surf_press']['amp'][s], params['atmos_surf_press']['hcorr'][s], params['atmos_surf_velocity']['amp'][s])
8383

8484
##now add perturbations to each field
@@ -158,14 +158,14 @@ def get_velocity_from_press(grid, pres, scale_wind=False, press_amp=None, press_
158158
##grid spacing
159159
dx = grid.dx / grid.mfx
160160
dy = grid.dy / grid.mfy
161-
##hcorr = rh * dx according to mid-domain dx (to be consistent with ReanalysisTP5/Perturb_forcing)
161+
##mid-domain dx (to be consistent with ReanalysisTP5/Perturb_forcing)
162162
dx_ = grid.dx / grid.mfx[grid.ny//2, grid.nx//2]
163163

164164
wprsfac = 1.
165165
if scale_wind:
166-
ds = 0.54 * press_hcorr / dx_ * np.hypot(dx, dy) ##horizontal scale
167-
wind_scale = press_amp / ds / fcor / rhoa ##expected wind scale from pressure field
168-
wprsfac = wind_amp / wind_scale ##scaling factor to match wind perturbation with given amp
166+
ds = (press_hcorr / dx_) * np.hypot(dx, dy) * 0.96 ##horizontal scale rh * dx, 0.96 is a tuning factor
167+
wind_scale = press_amp / ds / fcor ##expected wind scale from pressure field
168+
wprsfac = wind_amp / wind_scale ##scaling factor to match wind perturbation with given amp
169169

170170
##pres gradients
171171
dpresx = gradx(pres, dx, grid.cyclic_dim) * wprsfac
@@ -276,7 +276,7 @@ def random_displacement(grid, mask, amp, hcorr):
276276

277277
##distance to masked area
278278
dist = distance_transform_edt(1-mask.astype(float))
279-
dist /= np.max(dist)
279+
#dist /= dist.max()
280280
dist = gaussian_filter(dist, sigma=10)
281281
dist[mask] = 0
282282

0 commit comments

Comments
 (0)