各位老师,同学大家好
此处为基于matlab处理的源代码,使用nc文件内置的日期及日历编写输出名称
此处为简单的处理的代码,高手请绕路,仅作为文章内容进行记录
%%
clc
clear
%%
% 设置数据文件名和保存路径
filename = 'Ew_1980-2021_GLEAM_v3.6a_MO.nc';% SMsurf SMroot S Ew Et Es Ep Ei Eb E
output_path = 'E:\测试\gleammonth\Ew_1980-2021_GLEAM\';
%fl='CSR_GRACE_GRACE-FO_RL06_Mascons_all-corrections_v02.nc'
% 打开nc数据文件
ncid = netcdf.open(filename,'NC_NOWRITE');
ncdisp(filename)
%ncdisp(fl)
% 获取时间变量的数据
timeid = netcdf.inqVarID(ncid,'time');
time = netcdf.getVar(ncid,timeid);
% 获取经度和纬度变量的数据
lonid = netcdf.inqVarID(ncid,'lon');
lon = netcdf.getVar(ncid,lonid);
latid = netcdf.inqVarID(ncid,'lat');
lat = netcdf.getVar(ncid,latid);
% 获取水平变量的数据
% 关闭nc数据文件
netcdf.close(ncid);
% 获取时间维度的信息
nt = length(time);
ncdisp(filename)
%timeunits = netcdf.getAtt(ncid,timeid,'Units');
%timecalendar = netcdf.getAtt(ncid,timeid,'calendar');
timeunits = 'days since 1980-01-31 00:00:00';
timecalendar ='proleptic_gregorian';
timebase = datenum('1980-01-31 00:00:00','yyyy-mm-dd HH:MM:SS');
timevec = datevec(timebase + double(time),timeunits,timecalendar);
year = timevec(:,1);
month = timevec(:,2);
lwe_thickness=ncread(filename,'Ew'); %修改变量
lon=double(ncread(filename,'lon'));
lat=double(ncread(filename,'lat'));
% 将数据保存为TIF格式文件
for i = 1:nt
lwe=lwe_thickness(:,:,nt);
% 构建文件名
lwe=rot90(lwe);
outname = sprintf('%d-%02d',year(i),month(i))
filepath = fullfile(output_path,outname);
R=georasterref('RasterSize',size(lwe),'Latlim',[double(min(lat)) double(max(lat))],'Lonlim',[double(min(lon)) double(max(lon))]);
% 保存为TIF格式文件
geotiffwrite([output_path, '\',outname,'.tif'],lwe,R)
% geotiffwrite();
end
此处为30天的分享期限
gleam原数据
链接:https://pan.baidu.com/s/1WJHTWR6rEti00tYvMZMNrg?pwd=xi4b
提取码:xi4b
--来自百度网盘超级会员V4的分享
以下是处理好的gleam数据
整体数据类型
数据内容处理后结果