-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path01-make_bathy_bumps.m
133 lines (109 loc) · 2.99 KB
/
01-make_bathy_bumps.m
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
% will be python very soon >>>
%#!/usr/bin/env python
%# -*- coding: utf-8 -*-
%"""
% Generate bathymetry ensemble
%"""
%__author__ = "Saeed Moghimi"
%__copyright__ = "Copyright 2015, Oregon State University"
%__license__ = "GPL"
%__version__ = "0.1"
%__email__ = "[email protected]"
%
%#############################################
%# Saeed Moghimi; [email protected]
%# Logs:
%# 1.0 Greg Wilson adapted for matlab
%# 2.0
%# 3.0
%# 4.0
%#########################################################
%
% generate bathymetry ensemble
%
%inp_dir=getenv('INP_DIR');
%addpath ([inp_dir '/scr/mat/tools/'])
%addpath ([inp_dir '/scr/mat/randomField/'])
%addpath ([inp_dir '/scr/mat/assimilate/'])
%scr_dir=getenv('SCR_DIR');
% Read params from text file
%param=load('input_param.txt')
%N =param(1)
% perturbation scales
%Li =param(2)
%Lj =param(3)
%Lz =param(4)
%type1=param(5)
fid=fopen('input_param.txt');
param=textscan(fid,'%s');
scr_dir = cell2mat(param{1}(1))
inp_dir = cell2mat(param{1}(2))
N =str2num(cell2mat(param{1}(3)))
Li =str2num(cell2mat(param{1}(4)))
Lj =str2num(cell2mat(param{1}(5)))
Lz =str2num(cell2mat(param{1}(6)))
type1 =str2num(cell2mat(param{1}(7)))
fclose(fid);
dh_min = -3
disp('dh min set to -3')
addpath ([scr_dir '/mat/tools/'])
addpath ([scr_dir '/mat/randomField/'])
addpath ([scr_dir '/mat/assimilate/'])
out_bathy='../01_bat_inp/bath'
infile='prior.nc'
if(matlabpool('size')==0)
matlabpool
end
if(type1==1)
disp('load prior bathymetry')
h=nc_varget(infile,'h');
x=nc_varget(infile,'x_rho'); x=x(1,:)';
y=nc_varget(infile,'y_rho'); y=y(:,1);
dx=x(2)-x(1);
dy=y(2)-y(1);
nx=length(x);
ny=length(y);
dh = generate2Dp(nx,ny,dx,dy,Li,Lj,Lz,N);
% add the perturbations to the prior
h0=h;
h=repmat(h0,[1 1 N])+dh;
[x,y]=meshgrid(x,y);
for n=1:N
disp(n)
mat2roms(x,y,dh(:,:,n),[out_bathy num2str(1000+n) '.nc'],0);
end
else
grdfile='nri_curv_grid.nc'
%N=200;
disp('load prior bathymetry')
h=nc_varget(infile,'h');
x=nc_varget(infile,'x_rho'); x=x(1,:)';
y=nc_varget(infile,'y_rho'); y=y(:,1);
dx=x(2)-x(1);
dy=y(2)-y(1);
nx=length(x);
ny=length(y);
disp('load curvilinear grid')
xc=nc_varget(grdfile,'x_rho');
yc=nc_varget(grdfile,'y_rho');
[nyc,nxc]=size(xc);
[ic,jc]=meshgrid(1:nxc,1:nyc);
disp('perturbation scales')
%Li=25; %Redius equal to LixLj times number of grid point perturbations
%Lj=25;
%Lz=0.5;
% all horizontal units are in grid points
dhc=generate2Dp(nxc,nyc,1,1,Li,Lj,Lz,N);
disp('Interpolation on the actual grid')
[xg,yg]=meshgrid(x,y);
parfor n=1:N
F=TriScatteredInterp(xc(:),yc(:),reshape(dhc(:,:,n),[nyc*nxc 1]));
dh(:,:,n)=F(xg,yg);
end
[x,y]=meshgrid(x,y);
for n=1:N
disp(n)
mat2roms(x,y,dh(:,:,n),[out_bathy num2str(1000+n) '.nc'],dh_min);
end
end
matlabpool close