How to convert 15days data into monthly scale?

3 views (last 30 days)
Aarti Soni
Aarti Soni on 25 May 2023
Moved: Mathieu NOE on 19 Jul 2023
I have 15days global temperature data for 10years (240 files in .tif format). For every month 2 files are given and I need to take mean of these 15days data to convert into monthly scale (120 files).
Any kind of help would be appreciated.
Thanks
  5 Comments
Mathieu NOE
Mathieu NOE on 11 Jul 2023
ok
can you share a couple of data files and the code your struggling with ?
Aarti Soni
Aarti Soni on 19 Jul 2023
https://zenodo.org/record/7441559#.ZEe5AHZBxPY these are the data I am using to create time series. these are the 15days mean data (for 38 years total 912 files), every month is having two files. I just want to take monthly mean of every two data files
Output should be 38year_data = lat X lon X 456

Sign in to comment.

Answers (1)

Mathieu NOE
Mathieu NOE on 19 Jul 2023
Moved: Mathieu NOE on 19 Jul 2023
hello
I downloaded some files (not all as they are pretty big) to test my code
the image format is grayscale so I get a 2D array (2160x4320) - there is no 3rd dimensions here
the code I suggest so far is pretty simple :
fileDir = pwd; % current directory (or specify which one is the working directory)
S = dir(fullfile(fileDir,'PKU*.tif')); % get list of data files in directory
%% step 1 : get years and month data from file names
for k = 1:numel(S)
file = S(k).name; %
% get year / month data
i1 = findstr(file,'_');
i2 = findstr(file,'.tif'); % or tif
tmp = file(i1(end)+1:i2-1);
file_year(k) = str2num(tmp(1:4));
file_month(k) = str2num(tmp(5:6));
filename{k} = file;
end
%% step 2 : process the data
[file_year_unic,ia,ic] = unique(file_year);
for k = 1:numel(file_year_unic) % loop over years
y = file_year_unic(k);
for m = 1:12 % loop over 12 months
id = find(file_year==y & file_month == m); % find which file names to pick
% load data files
nid = numel(id);
if nid == 1 % we have only one file
out = imread( fullfile(fileDir, filename{id})); %
elseif nid == 2 % we have two files per month
out1 = imread( fullfile(fileDir, filename{id(1)})); %
out2 = imread( fullfile(fileDir, filename{id(2)})); %
out = (out1+out2)/2; % mean values (NB : NaN + numeric = NaN output)
end
% store the results only if nid > 0
if nid>0
filename_out = ['averaged_' sprintf('%04d', y) sprintf('%02d', m) '.tif'];
imwrite(out,fullfile(fileDir,filename_out));
end
end
end

Categories

Find more on Search Path in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!