ncread not identifying missing values

조회 수: 2 (최근 30일)
Emily
Emily 2011년 11월 21일
댓글: Walter Roberson 2021년 2월 6일
I'm using ncread to open a netcfd4 file. First, I used ncdisp and ncinfo to determine that my temperature variable of interest has a scale factor and missing value attribute associated with it. However, when I use ncread to read in this temperature variable, the scale factor and missing value attribute are not taken into account. For example, missing values still appear as "-327.6", the missing value ID, rather than NaN. What am I doing wrong? I thought ncread was automatically supposed to use the missing value attribute information and apply it to the dataset when it reads in the variable. How can I do this? Thank you! -Emily

답변 (2개)

Ashish Uthama
Ashish Uthama 2011년 11월 23일
Emily, the replacing fill values and applying scale and offset values is a convention. (i.e its not part of the file format specification), hence they need to have specific names. ncread will honor attributes with these specific names: _FillValue, scale_factor and add_offset: more here.
If your attribute names are not the same as the above convention, your best bet is to use the ncreadatt function to read in those attributes and perform the conversion.
If they have the standard names, and are not being honored, consider contacting tech support or posting a sample file for us to check.
  댓글 수: 2
sara niazi
sara niazi 2021년 2월 6일
my problem is :
how wrf_chem model understand missing value?(-9999.0) or NAN in wrfchemistry files as it's input file?
Could you guide me, please? I have made wrfchemistry files for the wrf_chem model as input files. some of my data has a missing value(-9999.0) in wrfchemistry file(wrfchemi_d01_2010-07-16_12:00:00) (here is the link of my file:https://drive.google.com/file/d/1Fk8HPKyiQU1-dFq5yu5Q3XApTIYLJRGR/view?usp=sharing).my question is how to determine the missing value in the wrfchemistry file so that it is understandable for the WRF_Chem model.I want my model(WRF_Chem ) doesn't have any valu on points with 9999.0 value.
how shall I create or describe my attributes in my netcdf file(wrfchemi_d01_2010-07-16_12:00:00)
has my wrfchemi file true attribute:
dimensions:
Time = 1 ;
DateStrLen = 19 ;
south_north = 124 ;
west_east = 173 ;
emissions_zdim = 1 ;
variables:
char Times(Time, DateStrLen) ;
double E_CO2(Time, emissions_zdim, south_north, west_east) ;
E_CO2:FieldType = 104. ;
E_CO2:MemoryOrder = "XYZ" ;
E_CO2:units = "mol km^-2 hr^-1" ;
E_CO2:stagger = "" ;
**E_CO2:missing_value = "-9999.f" ;
E_CO2:FillValue = "-9999.f" ; ** is that true?
E_CO2:coordinates = "XLONG XLAT" ;**
shall I fill the variables in the wrfchemistry file(wrfchemi_d01_2010-07-16_12:00:00) with "NaN" or "-9999.0"?
I always recieve thes Error:
Error using netcdflib
The NetCDF library encountered an error during execution of 'endDef' function - 'Not a valid data type or _FillValue type mismatch (NC_EBADTYPE)'.
Thank you for the response
Walter Roberson
Walter Roberson 2021년 2월 6일
The fill value and missing value are configured as a string, but the data is configured as numeric.

댓글을 달려면 로그인하십시오.


Lucio
Lucio 2012년 6월 15일
Hi, I am having exactly the same problem as Emily. But, I am using the right specific names when writing the attributes.
So, for writing the NetCDF I use
ncwriteatt(ncfile,'vr','_FillValue',single(fillval));
where ncfile is the full name of my NetCDF file and 'vr' is the variable of interest. Then, when I read by typing
data.vr = double(ncread(ncfile,'vr'));
I get no NaN and the value of the fill value instead. I have Matlab R2012a on a Linux Debian Squeeze 64 bits. Any guess? Lucio
  댓글 수: 1
John
John 2012년 6월 15일
If your file is netcdf-4, you probably shouldn't do that with fill values. The "fill value" in this case is a dataset creation property in the underlying netCDF/HDF5 file format, and therefore can only be set when the netcdf variable is first created. The "_FillValue" attribute is, in this case, just an attribute. If you change it, then the attribute is out of sync with the real "fill value" of the netCDF/HDF5 file.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 NetCDF에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by