フィルターのクリア

Analyse Time Series Data based on Seasonality

6 ビュー (過去 30 日間)
Long
Long 2023 年 3 月 28 日
編集済み: Long 2023 年 8 月 18 日
Hello everyone,
I'm trying to analyse seasonal dataset from 2015 to 2022. I have total 88 'nc' file. file name as "H08_20190301_0000_1MSST200_FLDK.06001_06001.ncI". I aims to seperate data into four seasons (e.g., Spring from March to May). I used coding below to store all data into cell structure.
My problem is I don't know how to scanning the file name to seperate and integrate data into season. For example, this data name ""H08_20190301_0000_1MSST200_FLDK.06001_06001.ncI" provides time in 20190301 belonging to Spring. I need to read specific date time to store all data with same season into one strucuture. Please help me to deal with this. Thank in advance!
pth = 'C:\Users\LongHoang\OneDrive\Desktop\Spring_2023\Ocean_Atmosphere_Mathlab\Mid_Term\H8_SST\H8_SST\';
ncvars = {'lat', 'lon', 'sea_surface_temperature'};
dinfo = dir( fullfile(pth, '*.nc') );
num_files = length(dinfo);
filenames = fullfile( pth, {dinfo.name} );
name = fullfile({dinfo.name}); %I have cell file to store all file name but don't know how to scan the file to get
% date time
lats = cell(num_files, 1);
lons = cell(num_files, 1);
ssts = cell(num_files, 1);
for k = 1: num_files
this_file = filenames{k};
Name_file = name{k};
lats{k} = ncread(this_file, ncvars{1});
lons{k} = ncread(this_file, ncvars{2});
ssts{k} = ncread(this_file, ncvars{3});
end
  1 件のコメント
Peter Perkins
Peter Perkins 2023 年 4 月 6 日
編集済み: Peter Perkins 2023 年 4 月 6 日
Long, it's not clear what are in your files. Does each file contain one lat-by-lon SST array for each season in each year? That sounds wrong, because that would be 8*4=32 files, not 88. Does each file contain daily SST values, i.e. lat-by-lon-by-day, over some range, like monthly files?

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

採用された回答

Mathieu NOE
Mathieu NOE 2023 年 3 月 28 日
編集済み: Mathieu NOE 2023 年 3 月 28 日
hello
I wished I had some files to test the code , but let's go directly to the task
I simply extracted from the filename the number corresponding to the month , then you make a simple test to store the data in the correct array depending of the month number
I was lazy so I created explicitely one array per season like lats_spring , lats_summer, lats_fall , lats_winter
but you could change that to a structure or cell array if you prefer
also for each season instead or storing in separate cells you might want simply to concatenate the data and have one unique array at the end (your preference ?)
could be something like this :
pth = 'C:\Users\LongHoang\OneDrive\Desktop\Spring_2023\Ocean_Atmosphere_Mathlab\Mid_Term\H8_SST\H8_SST\';
ncvars = {'lat', 'lon', 'sea_surface_temperature'};
dinfo = dir( fullfile(pth, '*.nc') );
num_files = length(dinfo);
filenames = fullfile( pth, {dinfo.name} );
name = fullfile({dinfo.name}); %I have cell file to store all file name but don't know how to scan the file to get
% date time
lats = cell(num_files, 1);
lons = cell(num_files, 1);
ssts = cell(num_files, 1);
k1 = 0; % "winter" counter init
k2 = 0; % "spring" counter init
k3 = 0; % "summer" counter init
k4 = 0; % "fall" counter init
for k = 1: num_files
this_file = filenames{k};
Name_file = name{k};
% new code
fulldate = split(Name_file,'_');
fulldate = fulldate{2}; % assuming the date appears always in second position in the filename (between '_')
monthsnumber = str2num(fulldate(5:6)); % to have the month corresponding to the file
if monthsnumber >= 12 && monthsnumber <= 2 % winter
k1 = k1 + 1; % counter
lats_winter{k1} = ncread(this_file, ncvars{1});
lons_winter{k1} = ncread(this_file, ncvars{2});
ssts_winter{k1} = ncread(this_file, ncvars{3});
end
if monthsnumber >= 3 && monthsnumber <= 5 % spring
k2 = k2 + 1; % counter
lats_spring{k2} = ncread(this_file, ncvars{1});
lons_spring{k2} = ncread(this_file, ncvars{2});
ssts_spring{k2} = ncread(this_file, ncvars{3});
end
if monthsnumber >= 6 && monthsnumber <= 8 % summer
k3 = k3 + 1; % counter
lats_summer{k3} = ncread(this_file, ncvars{1});
lons_summer{k3} = ncread(this_file, ncvars{2});
ssts_summer{k3} = ncread(this_file, ncvars{3});
end
if monthsnumber >= 9 && monthsnumber <= 11 % fall
k4 = k4 + 1; % counter
lats_fall{k4} = ncread(this_file, ncvars{1});
lons_fall{k4} = ncread(this_file, ncvars{2});
ssts_fall{k4} = ncread(this_file, ncvars{3});
end
end
  6 件のコメント
Mathieu NOE
Mathieu NOE 2023 年 6 月 28 日
Hello
Problem solved ?
would you mind accepting my answer ? thanks !
Long
Long 2023 年 8 月 18 日
編集済み: Long 2023 年 8 月 18 日
I had accepted your answer. Sorry for some inconvience stuff.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by