-
Notifications
You must be signed in to change notification settings - Fork 5
Create monthly mean fields from daily data and write results into netCDF files
HappySpring edited this page Jun 6, 2021
·
1 revision
-
Update
- file structure changed.
- this is used to handle two-sat merged data (only two satellites are used even if others are available)
-
file structrue
| current folder
|-- 1993
|-- 01
| -- dt_global_twosat_phy_l4_19930101_vDT2018.nc.nc
| -- dt_global_twosat_phy_l4_19930102_vDT2018.nc.nc
| -- dt_global_twosat_phy_l4_19930102_vDT2018.nc.nc
...
|-- 02
| -- dt_global_twosat_phy_l4_19930201_vDT2018.nc.nc
| -- dt_global_twosat_phy_l4_19930202_vDT2018.nc.nc
| -- dt_global_twosat_phy_l4_19930202_vDT2018.nc.nc
...
...
...
|-- 12
| -- dt_global_twosat_phy_l4_19931201_vDT2018.nc.nc
| -- dt_global_twosat_phy_l4_19931202_vDT2018.nc.nc
| -- dt_global_twosat_phy_l4_19931202_vDT2018.nc.nc
...
|-- 1994
|-- 01
| -- dt_global_twosat_phy_l4_19940101_vDT2018.nc.nc
| -- dt_global_twosat_phy_l4_19940102_vDT2018.nc.nc
| -- dt_global_twosat_phy_l4_19940102_vDT2018.nc.nc
...
...
...
- code
% Generate monthly mean data
clear
close all
clc
%% parameters ====================================================
input_root = fullfile( '.', 'daily' );
output_dir = 'Monthly_mean_SlefGen';
% output_dir = 'F:\temporary\testnc';
mkdir( output_dir );
file_prefix = 'dt_global_twosat_phy_l4_';
%% ===============================================================
yearlist = 1993:2016;
for year_now = yearlist
for month_now = 1:12
%
time_mean = datenum(year_now, month_now, 16);
disp([datestr(now,0) ': start averaging data duirng ' datestr(time_mean,'yyyy-mm') ])
% input path
input_dir_now = fullfile( input_root, num2str( year_now ), num2str( month_now, '%02d' ) );
% list all files in this month
file_marker_now = fullfile( input_dir_now, [ file_prefix num2str(year_now) num2str(month_now,'%02i') '*.nc' ] );
filelist_now = dir( file_marker_now );
% convert
compatibility_mode = 0;
merge_dim_name = 'time';
output_filename_now = fullfile( output_dir, [ file_prefix file_prefix num2str(year_now) num2str(month_now,'%02i') '.nc' ] );
FUN_nc_merge_save_mean( input_dir_now, filelist_now, output_filename_now, merge_dim_name, compatibility_mode )
end
end
It converts daily gridded sea level data (distributed by CMEMS) to monthly means.
- file structrue
| current folder
|-- 1993
|-- dt_global_allsat_phy_l4_19930101_20170110.nc
|-- dt_global_allsat_phy_l4_19930102_20170110.nc
|-- dt_global_allsat_phy_l4_19930103_20170110.nc
...
|-- 1994
|-- dt_global_allsat_phy_l4_19940101_20170110.nc
|-- dt_global_allsat_phy_l4_19940102_20170110.nc
|-- dt_global_allsat_phy_l4_19940103_20170110.nc
- code
% Generate monthly mean data
clear
close all
clc
%% parameters ====================================================
input_root = fullfile( '.', 'daily' );
output_dir = 'Monthly_mean_SlefGen';
% output_dir = 'F:\temporary\testnc';
mkdir( output_dir );
file_prefix = 'dt_global_allsat_phy_l4_';
%% ===============================================================
yearlist = 1993:2016;
for year_now = yearlist
for month_now = 1:12
%
timelimit_now = [ datenum(year_now, month_now, 1, 0, 0, 0) datenum( year_now, month_now + 1, 0, 23, 59, 59 ) ];
time_mean = datenum(year_now, month_now, 16);
disp([datestr(now,0) ': start averaging data duirng ' datestr(time_mean,'yyyy-mm') ', timelimit: ' datestr(timelimit_now(1),0) ' to ' datestr(timelimit_now(2),0)])
%
input_dir_now = fullfile( input_root, num2str( year_now ) );
file_marker_now = fullfile( input_dir_now, [ file_prefix num2str(year_now) num2str(month_now,'%02i') '*.nc' ] );
filelist_now = dir( file_marker_now );
compatibility_mode = 0;
merge_dim_name = 'time';
output_filename_now = fullfile( output_dir, [ file_prefix file_prefix num2str(year_now) num2str(month_now,'%02i') '.nc' ] );
FUN_nc_merge_save_mean( input_dir_now, filelist_now, output_filename_now, merge_dim_name, compatibility_mode )
end
end