Need assistance properly plotting a 3D variable from a NetCDF (.nc) file.
6 次查看(过去 30 天)
显示 更早的评论
I want to spatially show the evapotranspiration data contained within a NetCDF file, but almost all of the values appear the same color when plotted, when in reality there should be a wide range of colors. I think I may need to employ the Attributes of the variable in some way, but I am not sure how. Or, perhaps it is an issue with some outlier value that is making the majority of data points look the same. Here is what I have:
%% LOAD THE FILE INTO THE WORKSPACE
% Save the NetCDF file name as a character variable:
filename = 'Evapotranspiration-Data.nc';
% Display contents of NetCDF file (output pasted at the bottom of the question)
ncdisp(filename);
% Get the structure of the file
S = ncinfo(filename);
% Extract the variables
lon = abs(ncread(filename, 'longitude')-360); % longitudes in degress W
lat = ncread(filename, 'latitude'); % latitudes in degrees N
t = ncread(filename, 'time'); % time in 'hours since 1901-01-01 00:00:00'
ET = ncread(filename, 'evavt'); % Evapotranspiration in 'meters H20 equiv.'
% Standardize ET data
% 1. Extract missing value from structure
mv = S.Variables(4).Attributes(4).Value; % missing value
% 2. Standardize
ET = standardizeMissing(ET,mv); % Set all "missing values" to NaN
%% PLOT THE DATA
figure
imagescn(lat,lon,ET(:,:,1)) % plot first month of ET data
% I am using the function imagescn() from
% https://www.mathworks.com/matlabcentral/fileexchange/61293-imagescn,
% but I am also happy to work with:
% contourf(lat,lon,ET(:,:,1),'EdgeColor','none')
% Although the results are basically the same.
% Adjust orientation of figure and set color scheme
view([-90 90])
colormap winter
% Make a colorbar and give it a label
cb = colorbar;
cb.Label.String = 'Evapotranspiration (m w.e.)';
Here is the figure:
Here is the output from ncdisp(filename):
Dimensions:
longitude = 451
latitude = 301
time = 732
Variables:
longitude
Size: 451x1
Dimensions: longitude
Datatype: single
Attributes:
units = 'degrees_east'
long_name = 'longitude'
latitude
Size: 301x1
Dimensions: latitude
Datatype: single
Attributes:
units = 'degrees_north'
long_name = 'latitude'
time
Size: 732x1
Dimensions: time
Datatype: int32
Attributes:
units = 'hours since 1900-01-01 00:00:00.0'
long_name = 'time'
calendar = 'gregorian'
evavt
Size: 451x301x732
Dimensions: longitude,latitude,time
Datatype: int16
Attributes:
scale_factor = 1.1369e-07
add_offset = -0.0037253
_FillValue = -32767
missing_value = -32767
units = 'm of water equivalent'
long_name = 'Evaporation from vegetation transpiration'
2 个评论
Cris LaPierre
2021-12-21
Can you share you nc file? You will have to change the extenstion to .txt to attach it here (using the paperclip icon)
回答(1 个)
Cris LaPierre
2021-12-21
The difference is that your color variable is 3D. Each sheet corresponds to a different time. For visualizing, I think you want to pick a specific time.
filename = 'Evapotranspiration-Data.nc';
lon = ncread(filename, 'longitude'); % longitudes in degrees W
lat = ncread(filename, 'latitude'); % latitudes in degrees N
t = ncread(filename, 'time'); % time in 'hours since 1901-01-01 00:00:00'
ET = ncread(filename, 'evavt'); % Evapotranspiration in 'meters H20 equiv.'
% Standardize ET data
mv = S.Variables(4).Attributes(4).Value; % missing value
ET = standardizeMissing(ET,mv); % Set all "missing values" to NaN
[Lat Lon] = meshgrid(lat_range,lon_range);
%% PLOT THE DATA
figure
axesm('eqdcylin',"MapLatLimit",lat([1,end]),"MapLonLimit",lon([1,end]))
pcolorm(Lat,Lon,ET(:,:,1));
demcmap(ET(:,:,1))
tightmap
colorbar
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NetCDF 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!