Mapping sea surface temp with specific location? Struggling with geoshow function?
23 次查看(过去 30 天)
显示 更早的评论
Hello! Thank you for looking at my question I need a little bit of help with my code I am trying to plot sea surface temperature in the Baltic Sea for my uni coursework and plot it on a map on matlab with colour change gradients and contours however, I have been having very little luck with making the geoshow function work. My SST data ends up 3 dimensional and wont combine with my latitude and longtitude which are 2D variable and im not sure why that is I will attach my code here. my sst variable ends up being 383 x 523 x 56 double and my latitude one is 523x383 single, I have tried reshaping as well as putting it into just the two columns but then its not the same size. Any help would be much appreciated, thank you in advance! I have had a few attempts at reshaping which are percentaged below.
clc; close all ;
ncfile = 'CMEMS_BAL_PHY_reanalysis_monthlymeans_200809.nc' ; %loads temperature file
ncdisp(ncfile) %info about ncfile
sst = ncread(ncfile, 'thetao');
lon = ncread(ncfile,'longitude');
lat = ncread(ncfile,'latitude');
% Read in the sea_ice_fraction data and store in a new variable called ice:
%gets sea surface temperature value
time = ncread(ncfile,'time') ; nt = length(time) ; %reads the time variable and obtains its size
[X,Y] = meshgrid(lon,lat) ; % transform longitudes and latitudes into a grid of lon long x lat dimension
%% in case salinty wants to be used
%ncfileS = 'woa18_decav_s00_04.nc' ; %loads salinity file
sal = ncread(ncfile,'so'); %defines salinity variable
%%generates map
figure('Color','white'); %creates figure
ax=worldmap([45 90],[-45 45]); % loads world map with the limits for BALTICS
%newx= reshape(X, 383, 523);
%
%nsst = permute(sst,[1 3 2]);
%nsst = reshape(nsst,[],size(sst,2),1);
%nsst= reshape(sst, []);
%setm(ax,'mapprojection','mercator','Origin', [180 0 180]) %changes projection and changes origin reference for coordinates
levels=[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ]; % creates levels for contours
geoshow(double(Y),double(X),sst,'DisplayType','texturemap') %creates surface map of temperature
cb = contourcbar('peer',ax,'Location','northoutside'); %creates colorbar
caxis([15 35]) %defines limits for colorbar
colormap(jet) %sets color scheme
set(get(cb,'XLabel'),'String','SST (^oC)') %title for color bar
set(cb,'Position',[0.23 0.2417 0.5750 0.0335]) %adjust location and size of color bar
%levels=[28]; %sets level for contour defining specific
geoshow(double(Y),double(X),nsst,'DisplayType', 'contour','LevelList',levels,'LineColor','black') %plots temperature contour defining the western Pacific Warm Pool
hold on
land = shaperead('landareas.shp', 'UseGeoCoords', true); %define land areas
geoshow(land, 'FaceColor', [0 0 0]) % plots land areas in black
1 个评论
Rik
2021-3-14
I recovered the removed content from the Google cache (something which anyone can do). Editing away your question is very rude. Someone spent time reading your question, understanding your issue, figuring out the solution, and writing an answer. Now you repay that kindness by ensuring that the next person with a similar question can't benefit from this answer.
采纳的回答
Chad Greene
2021-3-2
For 3D data cubes of things like ocean temperature, you most often need to permute the first two dimensions when reading in from a netcdf. That would look like this for your data:
sst = permute(ncread(ncfile, 'thetao'),[2 1 3]);
To make a 2D map of this 3D data, you'll need to either pick a single time slice and plot it like this:
pcolorm(Lat,Lon,sst(:,:,3))
to plot the third map of SST data in the time series. Or perhaps you wish to plot the average SST map for all of your data. That would look like this:
pcolorm(Lat,Lon,mean(sst,3,'omitnan'))
which calculates the mean long the third dimension (time) and omits any missing data values if there are any.
A side note: As a matter of style, it's generally best if you can avoid using the variable names X and Y to mean longitude and latitude, because X and Y often refer to projected coordinates which are in meters, rather than degrees. In my own work, I typically use lowercase lon and lat for 1D arrays and uppercase Lon and Lat for 2D grids of longitdue and latitude. That would look like
[Lon,Lat] = meshgrid(lon,lat);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Mapping Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!