How to plot an ocean depth profile colormap for a angled coast?

I'm trying to plot a colormap depth profile of a section of the ocean that runs along an angle (along the coast of Nova Scotia). I am able to use a single latitude to plot along several longitudes (or vice versa), but I don't know how to use several latitudes/longitudes to plot a section on a 60 degree angle. Basically I can plot profiles with depth on the y axis and lat/long on the x-axis, and then my variable (temperature/oxygen/salinity) as the color, but I can't figure out how to do it on an angle along the coast.
This is the code required to plot a horizontal section at 43.25 degrees latitude:
nt=31; %number of days
varname='oxygen'; % which tracer to plot
name='D:\ModelResults\simulation_20220119\L3_model_results\ControlRun_realistic\ControlRun201808\ocean_avg.nc'; %dataset
lon=ncread(name,'lon_rho',[1 1],[Inf 1]); %longitude
lat=ncread(name,'lat_rho',[1 1],[1 Inf]); %latitude
king1=find(lat>=43.25-1/216&lat<=43.25+1/216); %specific latitude to plot at
LatP=lat(king1);
topography=depths(name,'E:\oxygen_model_201801_scratch\ROMS_TRUNK\Data\ROMS\Grid\grid_L3.nc',1,0,1); %grid for depths/topography
TopographyP=topography(:,king1,:);
dim=size(TopographyP);
sum=zeros(dim);
Tracer=ncread(name,varname);
for days=1:1:nt
sum=sum+Tracer(:,king1,:,days);
end
TracerAvg=sum/nt; %find the average
for i=1:1:size(lon)
for j=1:1:dim(3)
LonP(i,1,j)=lon(i,1);
end
end
subplot(1,1,1)
pcolor(squeeze(LonP-360),squeeze(TopographyP),squeeze(TracerAvg));shading flat
hold on
[C,f]=contour(squeeze(LonP-360),squeeze(TopographyP),squeeze(TracerAvg),8:2:26,'color','k');
clabel(C,f,8:2:26)

Risposte (1)

Hello,
The 2D or 3D interpolation may help.
The method of reading lon and lat suggests your ROMS's grid in a form of "ndgrid", right? Then griddedInterpolant is a good choice. For example:
[x,y,~]=ndgrid(lon,lat,1:size(topography,3));
% in the loop
f=griddedInterpolant(x,y,topography,Tracer(:,:,:,days));
% target lon, lat, depth
[LonP,LatP,TopographyP]=ndgrid([80 87],[40 50 55],[0:10:1000]);
t=f(LonP, LatP, TopographyP);

3 Commenti

Hi, sorry I'm a new matlab user so I'm sure I'm doing something wrong. I've written in what I think you've suggested:
[x,y,~]=ndgrid(lon,lat,1:size(topography,3));
% in the loop
for days=1:1:nt
f=griddedInterpolant(x,y,topography,Tracer(:,:,:,days));
% target lon, lat, depth
[LonP,LatP,TopographyP]=ndgrid([80 87],[40 50 55],[0:10:1000]);
t=f(LonP, LatP, TopographyP);
end
and I receive an error saying that the grid arrays must have NDGRID structure, however I'm not sure how to convert (if you can??) the data into ndgrid.
  1. Please make sure your ROMS's grid is indeed in a form of "ndgrid". (I guess it because there are lines like this: lon=ncread(name,'lon_rho',[1 1],[Inf 1]); %longitude )
  2. Pay attention to "topography". I can't find whether it a ndgrid format or not... If not, Tracer will not be ndgrid neither. Then you may interpolate on every vertical layer to avoid the 3rd dimension of depth, like this one:
[x,y]=ndgrid(lon,lat);
f=griddedInterpolant(x,y,Tracer(:,:,layer,days));
[LonP,LatP]=ndgrid([80 87],[40 50 55]);
t=f(LonP, LatP);
PS: Another option is "scatteredInterpolant"
I have to include the depth, since I'm trying to plot a depth vs longitude profile. The topography and Tracer are not NDGRID, so I'm still lost.

Accedi per commentare.

Categorie

Scopri di più su Oceanography and Hydrology in Centro assistenza e File Exchange

Richiesto:

il 25 Giu 2022

Commentato:

il 4 Lug 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by