Downloading GRIB files directly into Matlab
38 views (last 30 days)
Show older comments
Yoni Verhaegen
on 30 May 2019
Answered: Jacob Halbrooks
on 25 Sep 2024
I want to read in data from the GFS weather forecasting model. The NOAA has some URL links from which the data can be downloaded, e.g.:
In the internet browser, this link autmatically downloads a file. In Matlab I do the following:
fullURL = ['https://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_0p25_1hr.pl?file=gfs.t06z.pgrb2.0p25.f011&lev_surface=on&var_CAPE=on&leftlon=0&rightlon=360&toplat=90&bottomlat=-90&dir=%2Fgfs.2019053006'];
filename = 'cape_test.anl';
urlwrite(fullURL,filename);
These files open well in GIS software such as QGIS or ArcGIS. But how can I now read in these files automatically in MatLab so I can display them with the imagesc() command? Can someone help me?
Thanks already!
0 Comments
Accepted Answer
meghannmarie
on 2 Jun 2019
I would download nctoolbox from:
Below is some example code to get data using toolbox.
fullURL = ['https://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_0p25_1hr.pl?file=gfs.t06z.pgrb2.0p25.f011&lev_surface=on&var_CAPE=on&leftlon=0&rightlon=360&toplat=90&bottomlat=-90&dir=%2Fgfs.2019053006'];
filename = 'cape_test.anl';
urlwrite(fullURL,filename);
addpath('nctoolbox-1.1.3');
setup_nctoolbox;
grib = ncgeodataset(filename);
variables = grib.variables;
data = grib.geovariable('Convective_available_potential_energy_surface');
grib_data = double(data.data(:));
lat = grib.geovariable('lat');
grib_lat = double(lat.data(:));
lon = grib.geovariable('lon');
grib_lon = double(lon.data(:));
time = grib.geovariable('time');
grib_time = double(time.data(:));
2 Comments
More Answers (1)
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.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!