How to Plot Time Series Data of a Temperature Map

14 visualizaciones (últimos 30 días)
John Ziggs
John Ziggs el 23 de Mzo. de 2021
Comentada: John Ziggs el 28 de Mzo. de 2021
Hi,
I am trying to plot a timeseries data of the SST at certain locations on the world but I keep getting a blank plot. This is my code:
load global_sst
figure
imagescn(lon,lat,mean(sst,3))
hold on
gomlon = [21.25 1.25 -18.75 111.25 -116.25 176.25 -91.25 136.25];
gomlat = [26.25 11.25 -13.75 61.25 16.25 31.25 -76.25 -23.75];
plot(gomlon,gomlat,'ro')
text(21.25 ,26.25,'1','color','red','horiz','center','vert','bot');
text(1.25 ,11.25,'2','color','red','horiz','center','vert','bot');
text(-18.75 ,-13.75,'3','color','red','horiz','center','vert','bot');
text(111.25 ,61.25,'4','color','red','horiz','center','vert','bot');
text(-116.25 ,16.25,'5','color','red','horiz','center','vert','bot');
text(176.25 ,31.25,'6','color','red','horiz','center','vert','bot');
text(-91.25 ,-76.25,'7','color','red','horiz','center','vert','bot');
text(136.25 ,-23.75,'8','color','red','horiz','center','vert','bot');
%% Location 1
gomlon1 = [18.75 18.75 23.75 23.75];
gomlat1 = [28.75 23.75 28.75 23.75];
[Lon,Lat] = meshgrid(lon,lat);
mask1 = geomask(Lat,Lon,gomlat1,gomlon1);
contour(Lon,Lat,double(mask1),[0.5 0.5],'b')
%% Location 2
gomlon2 = [3.75 3.75 -1.25 -1.25];
gomlat2 = [13.75 8.75 13.75 8.75];
[Lon,Lat] = meshgrid(lon,lat);
mask2 = geomask(Lat,Lon,gomlat2,gomlon2);
contour(Lon,Lat,double(mask2),[0.5 0.5],'b')
%% Location 3
gomlon3 = [-21.25 -21.25 -16.25 -16.25];
gomlat3 = [-16.25 -11.25 -16.25 -11.25];
[Lon,Lat] = meshgrid(lon,lat);
mask3 = geomask(Lat,Lon,gomlat3,gomlon3);
contour(Lon,Lat,double(mask3),[0.5 0.5],'b')
%% Location 4
gomlon4 = [113.75 113.75 108.75 108.75];
gomlat4 = [58.75 63.75 58.75 63.75];
[Lon,Lat] = meshgrid(lon,lat);
mask4 = geomask(Lat,Lon,gomlat4,gomlon4);
contour(Lon,Lat,double(mask4),[0.5 0.5],'b')
%% Location 5
gomlon5 = [-118.75 -118.75 -113.75 -113.75];
gomlat5 = [18.75 13.75 18.75 13.75];
[Lon,Lat] = meshgrid(lon,lat);
mask5 = geomask(Lat,Lon,gomlat5,gomlon5);
contour(Lon,Lat,double(mask5),[0.5 0.5],'b')
%% Location 6
gomlon6 = [178.75 173.75 178.75 173.75];
gomlat6 = [33.75 28.75 33.75 28.75];
[Lon,Lat] = meshgrid(lon,lat);
mask6 = geomask(Lat,Lon,gomlat6,gomlon6);
contour(Lon,Lat,double(mask6),[0.5 0.5],'b')
%% Location 7
gomlon7 = [-93.75 -93.75 -88.75 -88.75];
gomlat7 = [-78.75 -73.75 -78.75 -73.75];
[Lon,Lat] = meshgrid(lon,lat);
mask7 = geomask(Lat,Lon,gomlat7,gomlon7);
contour(Lon,Lat,double(mask7),[0.5 0.5],'b')
%% Location 8
gomlon8 = [138.75 138.75 133.75 133.75];
gomlat8 = [-26.25 -21.25 -26.25 -21.25];
[Lon,Lat] = meshgrid(lon,lat);
mask8 = geomask(Lat,Lon,gomlat8,gomlon8);
contour(Lon,Lat,double(mask8),[0.5 0.5],'b')
%%
figure
sst_gom = local(sst,mask7,'omitnan');
t=1:736;
figure(2)
plot(t,sst_gom)
axis tight
datetick('x','keeplimits')
ylabel 'y'
As an example, I tried plotting the time series plot of location 7. I did this by making a mask of the location, then tried plotting the data within this mask. However I get a blank plot. Any advice?
Also as a note, I am using the Climate Data Toolbox by Chad A. Greene and tried following his example.
Thanks.

Respuesta aceptada

Chad Greene
Chad Greene el 25 de Mzo. de 2021
Hi John,
A couple of things:
  1. Location number 7 is in Antarctica! The sea surface temperature data is all NaN on land, so averaging the grid cell values around Location 7 will just give you NaN.
  2. The global_sst.mat dataset is a static average, not a time series. This means that even in the ocean where all SST values are valid, if you take the average SST in a given mask, you'll just end up with a single scalar value. If you would like to apply the local function to an example time series of SSTs, use the pacific_sst.mat dataset, which contains a cube where the first two dimensions are spatial, and the third dimension is time.
  1 comentario
John Ziggs
John Ziggs el 28 de Mzo. de 2021
Hi Chad,
Thank you for your response. Your explanation makes sense. I guess my next question is what if the matrice dataset is not in the two dimension spatial, third dimension time format? I have to map out and find the time series of the dataset attached and it consists only of temperature measurements.
I mapped it out using:
inputdirTS = 'C:\Users\john\Desktop\HW 4\TS'; % directory where files are located
S = dir(fullfile(inputdirTS,'*.txt'));
for k = 1:numel(S)
fnm = fullfile(inputdirTS,S(k).name);
vectorTS = load(fnm);
TS = flipud(reshape(vectorTS,[72 144])); %diurnal (daily) temperature variations
end
figure(1)
[lat,lon] = cdtgrid(2.5); % creates a 2.5 degree global grid
pcolor(lon,lat,TS) % plots the grid
shading interp
cmocean thermal % sets the colormap
borders('countries','color',rgb('gray'))
xlabel longitude
ylabel latitude
title('Daily Average Sea Surface Temperature (TS)')
Then I did the geomask for one location and it loaded really slow.
gomlon = [21.25 1.25 -18.75 111.25 -116.25 176.25 -91.25 136.25];
gomlat = [26.25 11.25 -13.75 61.25 16.25 31.25 -76.25 -23.75];
plot(gomlon,gomlat,'ro')
text(21.25 ,26.25,'1','color','red','horiz','center','vert','bot'); % Location 1
text(1.25 ,11.25,'2','color','red','horiz','center','vert','bot');
text(-18.75 ,-13.75,'3','color','red','horiz','center','vert','bot');
text(111.25 ,61.25,'4','color','red','horiz','center','vert','bot');
text(-116.25 ,16.25,'5','color','red','horiz','center','vert','bot');
text(176.25 ,31.25,'6','color','red','horiz','center','vert','bot');
text(-91.25 ,-76.25,'7','color','red','horiz','center','vert','bot');
text(136.25 ,-23.75,'8','color','red','horiz','center','vert','bot');
%% Location 1
gomlon1 = [18.75 18.75 23.75 23.75]; %Location 1 lon
gomlat1 = [28.75 23.75 28.75 23.75]; % Location 1 lat
[Lon,Lat] = meshgrid(lon,lat);
mask1 = geomask(Lat,Lon,gomlat1,gomlon1);
contour(Lon,Lat,double(mask1),[0.5 0.5],'b')
Moving on from here, I'm not sure how I would go about doing a time series plot of the mask of Location 1. I tried this syntax but this is for the entire globe rather than Location 1.
figure
TS = mask1(:);
TS = TS(TS > 0);
x = timeseries(vectorTS);
% x = timeseries(TS); % plot gave a straight line
x.Name = 'Daily Count';
x.TimeInfo.Units = 'days';
x.TimeInfo.StartDate = '04-06-01 00:00'; % Set start date.
%x.TimeInfo.End = '04-08-31 21:00';
x.TimeInfo.Units = 'hours';
x.TimeInfo.Increment = 3;
x.TimeInfo.Format = 'yy-mm-dd HH:MM'; % Set format for display on x-axis.
x.Time = x.Time - x.Time(1); % Express time relative to the start date.
plot(x)
Any help and advice helps.
Thanks,
John

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by