Filter löschen
Filter löschen

How to convert 15days data into monthly scale?

2 Ansichten (letzte 30 Tage)
Aarti Soni
Aarti Soni am 25 Mai 2023
Verschoben: Mathieu NOE am 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 Kommentare
Mathieu NOE
Mathieu NOE am 11 Jul. 2023
ok
can you share a couple of data files and the code your struggling with ?
Aarti Soni
Aarti Soni am 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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Mathieu NOE
Mathieu NOE am 19 Jul. 2023
Verschoben: Mathieu NOE am 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

Kategorien

Mehr zu Search Path finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by