ROMS output. Best technique to interpolate in the vertical
ROMS output. Best technique to interpolate in the vertical
Hi.
I'm working with an output from a ROMS model. I have the sigma levels (32) and some physical magnitudes as temperature and salinity. I have already converted sigma levels to depth.
I'm trying to interpolate the data in the vertical to a finer grid. I have the data order as (vertical_data,longitude_location) and I'm using a linear interpolation over one column at the time. However, the result is not good since the gradient of the field it's modified by my method. I have attached a image to show what I mean. So my question is, is there any "recommended" technique to interpolate in the vertical?
Thanks in advance.
I'm working with an output from a ROMS model. I have the sigma levels (32) and some physical magnitudes as temperature and salinity. I have already converted sigma levels to depth.
I'm trying to interpolate the data in the vertical to a finer grid. I have the data order as (vertical_data,longitude_location) and I'm using a linear interpolation over one column at the time. However, the result is not good since the gradient of the field it's modified by my method. I have attached a image to show what I mean. So my question is, is there any "recommended" technique to interpolate in the vertical?
Thanks in advance.
- Attachments
-
- pden.png (56.07 KiB) Viewed 16867 times
Re: ROMS output. Best technique to interpolate in the vertical
" linear interpolation over one column at the time" - that is probably not a good idea.
try a 2D interpolation scheme. Are you using matlab?
help scatteredInterpolant
F = scatteredInterpolant(x_rho,z_rho,salt);
saltnew= F(xnew,znew);
try a 2D interpolation scheme. Are you using matlab?
help scatteredInterpolant
F = scatteredInterpolant(x_rho,z_rho,salt);
saltnew= F(xnew,znew);
Re: ROMS output. Best technique to interpolate in the vertical
Thanks for your answer.
Indeed, I'm using Matlab. I should have said that I already tried with scatteredInterpolant but I didn't know how to use it in this case. When I try to use it, I got an error:
The variable x_rho is longitude so this is already in column-vector format. However, z_rho is not, since the points change according to the position of the longitude. Then I thought, "well, let's use it as a column-vector at the time" but this is no longer 2D interpolation scheme. So I ended up with the linear interpolation by column. Any ideas?
Indeed, I'm using Matlab. I should have said that I already tried with scatteredInterpolant but I didn't know how to use it in this case. When I try to use it, I got an error:
Code: Select all
F = scatteredInterpolant(x_rho,z_rho,salt);
Error using scatteredInterpolant
The input points must be specified in column-vector format.
Re: ROMS output. Best technique to interpolate in the vertical
it just wants you to enter the data as a column.
lets say this is a 2D field in x and z.
lets also say that you have 10 vertical layers and we are looking at the y index of 35 (just picking any number here).
N=10;
yidx=35;
X=repmat(lon_rho(:,yidx),N);
Z=z_rho(:,yidx,:);
S=squeeze(salt(:,yidx,:,tidx));
F = scatteredInterpolant(X(:),Z(:),S(:));
lets say this is a 2D field in x and z.
lets also say that you have 10 vertical layers and we are looking at the y index of 35 (just picking any number here).
N=10;
yidx=35;
X=repmat(lon_rho(:,yidx),N);
Z=z_rho(:,yidx,:);
S=squeeze(salt(:,yidx,:,tidx));
F = scatteredInterpolant(X(:),Z(:),S(:));
Re: ROMS output. Best technique to interpolate in the vertical
I had a hard time understanding your answer. But now I get it, thanks for your help!!!!
However, the results are not looking so good.
Looking information about scatteredinterpolant, I find the spline interpolation. And apparently, the results are better than any other methods I have tried so far. Still, I notice that both interpolation's method doesn't reach the right edge (See the longitude -72.2). Is this normal?
Thanks in advance.
However, the results are not looking so good.
Looking information about scatteredinterpolant, I find the spline interpolation. And apparently, the results are better than any other methods I have tried so far. Still, I notice that both interpolation's method doesn't reach the right edge (See the longitude -72.2). Is this normal?
Thanks in advance.
Re: ROMS output. Best technique to interpolate in the vertical
looking better.
there are 'extrapolation' options, which need to be used with caution.
but give that a try.
maybe someone else has a better idea.
there are 'extrapolation' options, which need to be used with caution.
but give that a try.
maybe someone else has a better idea.
Re: ROMS output. Best technique to interpolate in the vertical
I'll keep looking. But for now, I have a better interpolation than before. If I find a way to extrapolate in a nice way, I'll post it here.
So much thanks you for your help.
So much thanks you for your help.
Re: ROMS output. Best technique to interpolate in the vertical
So the problem with the right edge was not due to interpolation problem but a wrong definition on the finer grid I make.
Thanks John!
Thanks John!
Re: ROMS output. Best technique to interpolate in the vertical
Also, if you are concerned with the representation of the gradient, linear interpolation is C^0 (derivatives are discontinuous at cell edges), and using higher-order interpolation can introduce spurious results such as "unrealistic water masses". I am not an expert in the vertical interpolation of density, but I know people have worked on this. You might want to read this paper https://doi.org/10.1175/JTECH-D-19-0211.1
Matlab code for their interpolation is available at: https://www.teos-10.org/
Matlab code for their interpolation is available at: https://www.teos-10.org/