尝试将.mat
文件中的数据转换为.nc
文件,以便我可以使用NCVIEW快速查看数据。
我要保存到.nc
文件中的变量如下所示:
Watts_Map
Wattages plotted over a set of geographic grid cells
可变尺寸:<225x61x2920 double>
所以这将是一个3-D netCDF文件。
对于每个时间步,矩阵为225
x 61
。有2920
个时间步长。每个网格单元包含一个瓦特值。因此,维度为2920
x 225
的矩阵61
。
经度:0W
至140W
,0.625 deg
分辨率,由225
纬度:0N
至30N
,0.5 deg
分辨率,由61
似乎没有直观的方法来做到这一点。试用nccreate
和ncwrite
。
有关如何执行此操作的建议吗?
以下是我正在尝试的代码:
% Clear out all data and clean up workspace
clc;
clear all;
% load the .mat file to be converted to netcdf file
%load('2000_ATL_Watts_Maps_inc_Land.mat');
% variable to be taken from .mat file and saved as netcdf file
% Watts_Map = W/sq m
% Dimensions: 225x61x2920 (lon x lat x time)
%
% Put another way, there are 2920 maps of size 225x61, containing W/sq m
% values for each grid cell
%
% Resolution: longitude = 0.625 deg
% latitude = 0.5 degree
% time = starts at midnight on Jan 1st of the year, increments
% every 3 hours. So timestep 1 is midnight on Jan 1st,
% timestep 2 is 3am on Jan 1st, and so on.
% Create and write data to netcdf file
nccreate('test_files.nc','Watts','Dimensions',{'time' 2920 'lon' 225 'lat' 61});
答案 0 :(得分:1)
希望这能让你开始:
%% Create
!rm test_files.nc
nccreate('test_files.nc','Watts','Dimensions',{'time' 2920 'lon' 225 'lat' 61});
nccreate('test_files.nc','lat','Dimensions',{'lat' 61});
nccreate('test_files.nc','lon','Dimensions',{'lon' 225});
nccreate('test_files.nc','time','Dimensions',{'time' 2920});
ncdisp('test_files.nc');
%% write dimensions
% https://www.unidata.ucar.edu/software/netcdf/docs/netcdf/Dimensions.html
%Latitude: 0N to 30N, 0.5 deg resolution, denoted by 61
ncwrite('test_files.nc','lat',0:.5:30);
%Longitude: 0W to 140W, 0.625 deg resolution, denoted by 225
ncwrite('test_files.nc','lon',0:.625:140);
% Time?
%% write data
ncwrite('test_files.nc','Watts',rand(2920,225,61));