Mean for particular seasons over 32 yrs..say January to March(1:3),4:6,7:9,10:12

1 回表示 (過去 30 日間)
Sophia
Sophia 2015 年 9 月 8 日
コメント済み: Walter Roberson 2020 年 9 月 7 日
I want to take the mean season wise..say for Winter, Spring, Summer and Autumn.. and then need to show over a period of 32 years ..how the seasonal mean is changing.
datacoord = reshape(data, 361,361,4);
lat = squeeze(datacoord(:,:,3));
long = squeeze(datacoord(:,:,4));
%m_proj('Azimuthal Equal-area');
m_proj('stereographic','lat',90,'long',30,'radius',22);
m_grid('xtick',12,'tickdir','out','ytick',[65 70 75 80 85 90],'linest','-');
m_coast('patch',[.7 .7 .7],'edgecolor','r');
m_elev('contour',[ ],'edgecolor',' ');
for y=1979:2012,
% open binary file for
% Polar Pathfinder Daily 25 km EASE-Grid Sea Ice Motion Vectors, Version 2
folderpath = 'C:\Users\Documents\MATLAB\Mean_months\';
stryear = num2str(y);
filepath = fullfile(folderpath,stryear);
files = dir(fullfile(filepath,'\icemotion.mean.*.n.v02.bin') );
files = {files.name};
Umean = [];
Vmean = [];
for i=1:numel(files),
disp(files{i});
filename = fullfile(filepath,files{i});
fid = fopen(filename);
rawdata = fread(fid,[361, inf],'int16');
fclose(fid);
% reshape it into a [3x361x361] matrix
dd = reshape(rawdata,[3, 361, 361]);
% change 3d matrix to simple matrix, and divide by 10 to get cm/second
u = squeeze(dd(1,:,:)) ./ 10;
v = squeeze(dd(2,:,:)) ./ 10;
% Change the data values from cm/s to m/second by multiplying it with 1/100
u = u*1/100;
v = v*1/100;
end
find(lat < 1 | lat ~= fix(lat))
find(long < 1 | long ~= fix(long))
i = lat;
j = long;
k = 1:length(1979:2012);
u = u(i,j,k);
v = v(i,j,k);
yrlst = 1979:2012;
wintlst = 1:3;
for i = 1:length(yrlst)
tempwint = wintlst +(i-1)*12;
tmpu = squeeze(nanmean(u(:,:,tempwint),3));
tmpv = squeeze(nanmean(v(:,:,tempwint),3));
for j = 1:size(tmpu,1)
k = 1:size(tmpu,2)
tuwint(j,k,i) = tmpu(j,k);
tvwint(j,k,i) = tmpv(j,k);
end
end
end

回答 (1 件)

Chad Greene
Chad Greene 2015 年 9 月 13 日
It's hard to decipher your nested loops, but here's how I'd tackle it. I'll assume you have a big 3D matrix U whose dimensions correspond to (lon x lat x time) or (gridx x gridy x time) or something of the like. You probably also have a 3D matrix of the same size V for zonal motion, and I'll assume you have an array t and length(t) = size(U,3).
We're gonna trick downsample_ts into computing seasonal means like this:
1. Get t into components of year, month, and day:
[year,month,day] = datevec(t);
2. The downsample_ts function computes monthly means, so we'll lie to downsample_ts and tell it that all December and February data happened in January.
month(month==12) = 1;
month(month==2) = 1;
Do the same for the other seasons, i.e.,
month(month==3) = 4;
month(month==5) = 5;
And when you do the same for the other seasons, you should get
unique(month)
= [1, 4, 7, 10];
Create a new fake t2 vector:
t2 = datenum([year,month,day]);
Then a 32 year record of seasonal means can be obtained by
[Umean,tmean] = downsample_ts(U,t,'monthly','mean');
Vmean = downsample_ts(V,t,'monthly','mean');
Dimensions of Umean and Vmean will be size(U,1) x size(U,2) x 128 because 4 seasons times 32 years is 128. All DJF data will be given by
Umean(:,:,tmean==1);
And if you want to get a linear trend map of DJF seasonal averages over 32 years you could do
U_djf_trend = trend(Umean(:,:,tmean==1),1,3);
using the trend function.
  4 件のコメント
Max Reinicke
Max Reinicke 2016 年 5 月 22 日
Dear Chad,
How can I go back from the cryptic t2=datenum values to f.e. the year of the winter season?
so to have two columns of: year;season;Umean
Thanks for the great function and help!
Walter Roberson
Walter Roberson 2020 年 9 月 7 日
Dwaipayan Chatterjee comments to Chad Greene:
[Umean,tmean] = downsample_ts(U,t,'monthly','mean');
Vmean = downsample_ts(V,t,'monthly','mean');
At this stage I suppose instead of 't', 't2' should be used

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by