Unable to read grib2 data with nctoolbox

28 views (last 30 days)
John Cruce
John Cruce on 14 Sep 2021
Answered: Jacob Halbrooks on 25 Sep 2024
I'm attempting to read MRMS radar data from here:
I grabbed a sample grib2 file. I've used nctoolbox for several years and this is the first time I've run into an issue reading data. The variable I'm having issues with is the reflectivity data (VAR209-3-57_FROM_161-0-0_altitude_above_msl).
Here is the simple read code:
nc=ncgeodataset('MRMS_ReflectivityAtLowestAltitude_00.50_20210913-194039.grib2');
time=nc.geovariable('time');
time=time.data(:);
altitude=nc.geovariable('altitude_above_msl');
altitude=altitude.data(:);
lat=nc.geovariable('lat');
lat=lat.data(:);
lon=nc.geovariable('lon');
lon=lon.data(:);
lowestalt=nc.geovariable('VAR209-3-57_FROM_161-0-0_altitude_above_msl');
lowestalt=squeeze(lowestalt.data(:,:,:,:));
I encouter the following error upon running:
Error using ncdataset/readdata (line 494)
Java exception occurred:
java.lang.UnsupportedOperationException: Unsupported DRS type = 41
at ucar.nc2.grib.grib2.Grib2Drs.factory(Grib2Drs.java:59)
at
ucar.nc2.grib.grib2.Grib2SectionDataRepresentation.getDrs(Grib2SectionDataRepresentation.java:73)
at ucar.nc2.grib.grib2.Grib2Record.readData(Grib2Record.java:271)
at ucar.nc2.grib.grib2.Grib2Iosp$DataReader.read(Grib2Iosp.java:983)
at ucar.nc2.grib.grib2.Grib2Iosp.readDataFromCollection(Grib2Iosp.java:912)
at ucar.nc2.grib.grib2.Grib2Iosp.readData(Grib2Iosp.java:722)
at ucar.nc2.NetcdfFile.readData(NetcdfFile.java:1941)
at ucar.nc2.Variable.reallyRead(Variable.java:859)
at ucar.nc2.Variable._read(Variable.java:831)
at ucar.nc2.Variable.read(Variable.java:709)
at ucar.nc2.dataset.VariableDS.reallyRead(VariableDS.java:518)
at ucar.nc2.dataset.VariableDS._read(VariableDS.java:502)
at ucar.nc2.dataset.VariableDS._read(VariableDS.java:526)
at ucar.nc2.Variable.read(Variable.java:695)
at ucar.nc2.Variable.read(Variable.java:669)
Error in ncdataset/data (line 171)
d = obj.readdata(variable, first, last, stride);
Error in ncgeodataset/subsref (line 630)
B = builtin('subsref',obj,g);
Error in ncvariable/somedata (line 406)
data = obj.dataset.data(name, first, last, stride);
Error in ncvariable/data (line 189)
d = somedata(obj, 1, first, last, stride);
Error in ncgeovariable/subsref (line 1116)
sref = obj.data(first, last, stride);
Error in ncgeodataset/subsref (line 660)
B = v.data(s(2).subs{:});
Any thoughts on what might be the issue here?
  1 Comment
Muyin Wang
Muyin Wang on 14 Oct 2022
I ran into similar problems. My code worked last year on Matlab2020a. But then I got a new MacBook Pro (with M1 chips), then the same code stopped working. I also tried MatlabR2018a, still, I got the following error messages:
Error using ncdataset (line 97)
Failed to open CFS-mon/ocnh06.gdas.202001.grib2
Error in cfdataset (line 59)
obj = obj@ncdataset(url);
Error in ncgeodataset (line 74)
obj = obj@cfdataset(url);
Error in comp_theta_steveupdate1 (line 29)
grb2=ncgeodataset(file);
Caused by:
Error using ncdataset (line 81)
Java exception occurred:
java.lang.RuntimeException: java.lang.NoClassDefFoundError:
ucar/nc2/util/CloseableIterator
at ucar.nc2.NetcdfFile.<init>(NetcdfFile.java:1535)
at ucar.nc2.NetcdfFile.open(NetcdfFile.java:887)
at ucar.nc2.NetcdfFile.open(NetcdfFile.java:496)
at ucar.nc2.dataset.NetcdfDataset.openOrAcquireFile(NetcdfDataset.java:693)
at ucar.nc2.dataset.NetcdfDataset.openDataset(NetcdfDataset.java:424)
at ucar.nc2.dataset.NetcdfDataset.openDataset(NetcdfDataset.java:407)
at ucar.nc2.dataset.NetcdfDataset.openDataset(NetcdfDataset.java:392)
at ucar.nc2.dataset.NetcdfDataset.openDataset(NetcdfDataset.java:379)
Caused by: java.lang.NoClassDefFoundError: ucar/nc2/util/CloseableIterator
at
ucar.nc2.grib.grib2.Grib2CollectionBuilder.<init>(Grib2CollectionBuilder.java:115)
at
ucar.nc2.grib.grib2.Grib2CollectionBuilder.readOrCreateIndexFromSingleFile(Grib2CollectionBuilder.java:76)
at
ucar.nc2.grib.GribIndex.makeGribCollectionFromSingleFile(GribIndex.java:123)
at ucar.nc2.grib.grib2.Grib2Iosp.open(Grib2Iosp.java:310)
at ucar.nc2.NetcdfFile.<init>(NetcdfFile.java:1499)
... 7 more
Caused by: java.lang.ClassNotFoundException: ucar.nc2.util.CloseableIterator
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 12 more

Sign in to comment.

Answers (2)

Jacob Halbrooks
Jacob Halbrooks on 25 Sep 2024
As of R2023b, you can read data from a GRIB file (.grb, .grib, .grib2) using the Mapping Toolbox readgeoraster function. You can also get information about a GRIB file by using the georasterinfo function. These functions were enhanced in R2024b to support GRIB files that use CCSDS compression.

Feixiong Huang
Feixiong Huang on 18 Oct 2021
You have to use MATLAB2017 or lower version
  1 Comment
Muyeqingfeng
Muyeqingfeng on 9 Jun 2022
I don't think that. I'm using the version of 2020b, but there also always appear wrong.

Sign in to comment.

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!