How to open netcdf4 file in MATLAB

43 次查看(过去 30 天)
Hello there!
I am trying to open file - A20021822002212.L3b_MO_CHL.nc in MATLAB. After issuing the command -
ncdisp('/home/xyz/Desktop/abc/chlorophyl_Data/A20021822002212.L3b_MO_CHL.nc'),
I see the following details:
Source:
/home/xyz/Desktop/abc/chlorophyll_Data/A20021822002212.L3b_MO_CHL.nc
Format:
netcdf4
Global Attributes:
* product_name = 'A20021822002212.L3b_MO_CHL.nc'
* title = 'MODIS Level-3 Binned Data'
* instrument = 'MODIS'
* platform = 'Aqua'
* temporal_range = '26-day'
* start_orbit_number = 885
* end_orbit_number = 1.26e+03
* date_created = '2015177112310000'
* processing_version = '2014.0'
* history = 'l3bin
* par=A20021822002212.L3b_MO_CHL.param'
* time_coverage_start = '2002-07-03T22:55:06.000Z'
* time_coverage_end = '2002-07-29T18:40:05.000Z'
* northernmost_latitude = 83.7
* southernmost_latitude = -49
* easternmost_longitude = 180
* westernmost_longitude = -180
* geospatial_lat_max = 83.7
* geospatial_lat_min = -49
* geospatial_lon_max = 180
* geospatial_lon_min = -180
* geospatial_lat_units = 'degrees_north'
* geospatial_lon_units = 'degrees_east'
* geospatial_lon_resolution = 0.0417
* geospatial_lat_resolution = 0.0417
* spatialResolution = '4.6 km'
* data_bins = 1.11e+07
* percent_data_bins = 46.9
* units = 'chlor_a:mg m^-3,chl_ocx:mg m^-3'
* binning_scheme = 'Integerized Sinusoidal Grid'
* project = 'Ocean Biology Processing Group (NASA/GSFC/OBPG)'
* institution = 'NASA Goddard Space Flight Center, Ocean Ecology Laboratory, Ocean Biology Processing Group'
* standard_name_vocabulary = 'NetCDF Climate and Forecast (CF) Metadata Conventions'
* Metadata_Conventions = 'Unidata Dataset Discovery v1.0'
* Conventions = 'CF-1.6, Unidata Dataset Discovery v1.0'
* naming_authority = 'gov.nasa.gsfc.sci.oceandata'
* id = 'A20021822002212.L3b_MO_CHL.nc/L3/A20021822002212.L3b_MO_CHL.nc'
* license = 'http://science.nasa.gov/earth-science/earth-science-data/data-information-policy/'
* creator_name = 'NASA/GSFC/OBPG'
* publisher_name = 'NASA/GSFC/OBPG'
* creator_email = 'data@oceancolor.gsfc.nasa.gov'
* publisher_email = 'data@oceancolor.gsfc.nasa.gov'
* creator_url = 'http://oceandata.sci.gsfc.nasa.gov'
* publisher_url = 'http://oceandata.sci.gsfc.nasa.gov'
* processing_level = 'L3 Binned'
* cdm_data_type = 'point'
* identifier_product_doi_authority = 'http://dx.doi.org'
* identifier_product_doi = '10.5067/AQUA/MODIS_OC.2014.0'
* keywords = 'Oceans > Ocean Chemistry > Chlorophyll; Oceans > Ocean Optics > Ocean Color'
* keywords_vocabulary = 'NASA Global Change Master Directory (GCMD) Science Keywords'
*
Groups:
/level-3_binned_data/
Dimensions:
* binListDim = 11145203 (UNLIMITED)
* binDataDim = 11145203 (UNLIMITED)
* binIndexDim = 4320 (UNLIMITED)
Variables:
BinList
* Size: 11145203x1
* Dimensions: binListDim
* Datatype: UNSUPPORTED DATATYPE
chlor_a
* Size: 11145203x1
* Dimensions: binDataDim
* Datatype: UNSUPPORTED DATATYPE
chl_ocx
* Size: 11145203x1
* Dimensions: binDataDim
* Datatype: UNSUPPORTED DATATYPE
BinIndex
* Size: 4320x1
* Dimensions: binIndexDim
* Datatype: UNSUPPORTED DATATYPE
/processing_control/
Attributes:
* software_name = 'L3BIN'
* software_version = '4.03'
* source = 'A20021852002192.L3b_8D_CHL.nc,A20021932002200.L3b_8D_CHL.nc,A20022012002208.L3b_8D_CHL.nc,A2002184.L3b_DAY_CHL.nc,A2002209.L3b_DAY_CHL.nc,A2002210.L3b_DAY_CHL.nc'
l2_flag_names = 'ATMFAIL,LAND,HILT,HISATZEN,STRAYLIGHT,CLDICE,COCCOLITH,LOWLW,CHLWARN,CHLFAIL,NAVWARN,MAXAERITER,ATMWARN,HISOLZEN,NAVFAIL,FILTER,HIGLINT'
Groups:
/processing_control/input_parameters/
Attributes:
* infile = '/data2/sdpsoper/vdc/vpu1/workbuf/l3inlist.dat'
* ofile = 'A20021822002212.L3b_MO_CHL.nc'
* pfile = 'A20021822002212.L3b_MO_CHL.nc'
* oformat = 'netCDF4'
* syear = '2002'
* eyear = '2002'
* sday = '182'
* eday = '212'
* sorbit = '-1'
* eorbit = '-1'
* out_parm = 'DEFAULT'
* processing_version = '2014.0'
* reduce_fac = '1'
* merged = ''
* loneast = '180.000000'
* lonwest = '-180.000000'
* latnorth = '90.000000'
* latsouth = '-90.000000'
* verbose = '0'
* unit_wgt = '0'
* median = '0'
* deflate = '4'
But, When I issue the command :
cc=ncread('/home/xyz/Desktop/abc/chlorophyll_Data/A20021822002212.L3b_MO_CHL.nc','/level-3_binned_data/chlor_a');
I see the following error:
Error using netcdf.getVar (line 134)
33 is not a recognized netCDF datatype.
Error in internal.matlab.imagesci.nc/read (line 606)
data = netcdf.getVar(gid, varid);
Error in ncread (line 59)
vardata = ncObj.read(varName, varargin{:});
Please help me to rectify this error.
I have also tried h5read, but no use.
Thanks

采纳的回答

Chad Greene
Chad Greene 2017-9-10
If the NetCDF file you are using is one of the ones found here, I was able to access the data like this:
A = h5read('A20021822002212.L3b_MO_CHL.nc','/level-3_binned_data/chlor_a');
then there seems to be two arrays in a structure. They're called sum and sum_squared. Plotting them against each other looks like this:
plot(A.sum,A.sum_squared,'b.')
  3 个评论
Chad Greene
Chad Greene 2017-9-12
The 'b.' is just shorthand for "blue dots". It's the same as writing this:
plot(A.sum,A.sum_squared,,'color','blue','marker','.')
The georeferencing problem is less straightforward. It's an interesting problem, so I wrote a function for it and used your example in the documentation. The function is now on File Exchange here.

请先登录,再进行评论。

更多回答(1 个)

Priya Patil
Priya Patil 2017-9-17
编辑:Priya Patil 2017-9-17
Thanks Chad. I went through the function - binind2latlon(binind,varargin) written by you. It proved to be helpful in getting a 2D plot for the variable chlor_a. Now, I need to perform an analysis (eof, correlation, etc.) upon this data.I am thinking to convert monthly satellite data for a specific time range (for example, year 2002- 2008) into the gridded data form and store it in a single file.
So, can I save this data in a simple netcdf form, so that I can access it with utility such as GrADS or with simple ncread command of MATLAB? I mean, instead of running this function everytime to get a 2D plot for a single month, can I run it once to get the 'chlor_a' variable and store it in a (.dat) file so that next time I can simply access it using ncread command?
Again, I want to aggregate/merge these files of different months into a single .dat file so that I can perform monthly/seasonal analysis of the data. can you give any clue/direction upon both of these questions?
Thanks

标签

Community Treasure Hunt

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

Start Hunting!

Translated by