how to analyze matlab grib files?
34 次查看(过去 30 天)
显示 更早的评论
Hello,
Could you tell me how can i read grib files in matlab on my mac? I have to use matlab cdi or can’t do this to my mac? Also i have downloaded nctoolbox if you know. Do you know how can install one of them and run it? Except this i want to make another work. I have grib files from ECMWF, one with velocities V (Vx,Vy) and another one with potential temperature T and i want to calculate the product image001.png. So i have to import and analyze grib files first and then to calculate this product. Do you know how can i do this? Please help me if you can, i will appreciate it a lot. It is for my diploma thesis and i don't know what i have to do.
Best regards
Sotiris Tsiougkos
0 个评论
采纳的回答
Jacob Halbrooks
2024-9-25
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 个评论
更多回答(10 个)
Kelly Kearney
2015-4-9
You mean GRIB files? Matlab doesn't handle GRIB format natively, so I recommend converting the files to netCDF if you want to read them into Matlab without needing an outside toolbox. The ECMWF servers offer this option when downoading the data. Or you can use a converter like the NCL (NCAR Command Language) grib2netCDF.
I've never used the nctoolbox package, but it looks like it can read GRIB, so just follow the installation instructions and run the setup script to get that working.
4 个评论
Kelly Kearney
2015-4-10
编辑:Kelly Kearney
2015-4-10
Look at the help for ncread; that's the easiest way to read in netCDF files.
As for GRIB to netCDF conversion, you may lose some of the global metadata through the conversion, but the data values themselves will be preserved, as well as the important attributes (units, short name, standard name, etc.)
sotiris tsiougkos
2015-4-12
编辑:per isakson
2015-4-14
1 个评论
Kelly Kearney
2015-4-13
I suggest you read through the Getting Started section of the documentation... it will teach you the basics of passing variables into functions. In this case, you need to include the full file name as the source (as a string), then the name of the variable. Use ncdisp to see the variables in your file. Here's an example with an ECMWF file I have on my computer (lines marked with >> are the ones I type at the command prompt):
>> file = ['/Volumes/MyPassportKak/LargeDatasets/ERA-Interim/' ...
'netcdf-atls05-20140820204544-48535-4662.nc'];
>> ncdisp(file)
Source:
/Volumes/MyPassportKak/LargeDatasets/ERA-Interim/netcdf-atls05-20140820204544-48535-4662.nc
Format:
classic
Global Attributes:
Conventions = 'CF-1.0'
history = '2014-08-20 20:46:19 GMT by grib_to_netcdf-1.13.0: grib_to_netcdf /data/data01/netcdf-atls05-20140820204435-48535-4661.target -o /data/data01/netcdf-atls05-20140820204544-48535-4662.nc'
Dimensions:
longitude = 2
latitude = 2
time = 14616
Variables:
longitude
Size: 2x1
Dimensions: longitude
Datatype: single
Attributes:
units = 'degrees_east'
long_name = 'longitude'
latitude
Size: 2x1
Dimensions: latitude
Datatype: single
Attributes:
units = 'degrees_north'
long_name = 'latitude'
time
Size: 14616x1
Dimensions: time
Datatype: int32
Attributes:
units = 'hours since 1900-01-01 00:00:0.0'
long_name = 'time'
ssrd
Size: 2x2x14616
Dimensions: longitude,latitude,time
Datatype: int16
Attributes:
scale_factor = 347.2613
add_offset = 11378362.3694
_FillValue = -32767
missing_value = -32767
units = 'J m**-2'
long_name = 'Surface solar radiation downwards'
standard_name = 'surface_downwelling_shortwave_flux_in_air'
>> v = ncread(file, 'ssrd');
sotiris tsiougkos
2015-4-14
编辑:per isakson
2015-4-14
1 个评论
mario rivera
2016-4-6
The variable u10, is the component "u" of the wind, measured at 10mts. For obtain the values you have to write
UWIND=ncread(file,'u10')
sotiris tsiougkos
2015-4-14
2 个评论
Kostas
2015-4-14
u10 is the U wind component, as you can notice it has dimensions of lon x lat x time, you can read it in matlab and store in a matrix with
u10 = ncread('file','u10');
i guess you must have a similar file where you have stored the V wind component, which you need to read it also and store it in matlab, so as to calculate the wind component and the product with the potential temperature. I would suggest you to read for the beginning how you could work with ERA-Interim netcdf file in matlab. You could find a good start in this link
mario rivera
2016-4-6
Hi, I have a question, but first I must to say that my english is not as good as I want, so I hope you can understand what I need.
I have a lot of files .nc into a folder and I need to read them all in just one order. Until now I have wrote this:
rout = ('/Users/aabb/Documents/MATLAB/EN3/');
# c=dir([rout,'*.nc']);
# cd = char(c.name);
#
# SERIETEMP=NaN(12,9,42,730);
# SERIESAL=NaN(12,9,42,730);
#
# for i=1:733
# capa=cd(i,:)
# files=netcdf.open(capa);
# temp= ncread(files,'temperature',[278, 92,1,1],[12,9,42,1],[1,1,1,1]);
# temp=temp-273.15;
# sal= ncread(files,'salinity',[278, 92,1,1],[12,9,42,1],[1,1,1,1]);
# SERIETEMP(:,:,:,i)=temp;
# SERIESAL(:,:,:,i)=sal;
# end
and it works good until the order temp=ncread(files,'temperature',[278, 92,1,1],[12,9,42,1],[1,1,1,1]);
and appear, those alerts:
Error using fopen
Invalid filename.
Error in internal.matlab.imagesci.nc/openToRead (line 1257)
fid = fopen(this.Filename,'r');
Error in internal.matlab.imagesci.nc (line 121)
this.openToRead();
Error in ncread (line 53)
ncObj = internal.matlab.imagesci.nc(ncFile);
I have not idea, about what does it means and how can I solve it. I appreciate a lot for your help.
my best regards,
Mario Rivera
1 个评论
Kelly Kearney
2016-4-6
Side note:
In the future, creating a new question on the forum is a better way to get an answer, rather than posting a question as an answer to a year-old question. Here, you can't accept the answer, and may confuse future readers of the original question.
-------------
Your problem is that you're mixing up high-level and low-level netcdf functions. When using the high-level ncread, you don't need to worry about opening, closing, etc. And the ncread function takes a file name (as a string) as its input, not a netCDF file identifier.
A few other issues with the code:
- Creating a character array of the filenames is unnecessary and messy; just stick with the structure output from dir.
- Using i as a variable is usually discouraged, since it has an alternative value in Matlab, i=sqrt(-1).
With those changes, your code can be rewritten as
rout = ('/Users/aabb/Documents/MATLAB/EN3/');
c = dir([rout,'*.nc']);
SERIETEMP=NaN(12,9,42,730);
SERIESAL=NaN(12,9,42,730);
for ii=1:733
temp= ncread(c(ii).name,'temperature',[278, 92,1,1],[12,9,42,1],[1,1,1,1]);
temp=temp-273.15;
sal= ncread(c(ii).name,'salinity',[278, 92,1,1],[12,9,42,1],[1,1,1,1]);
SERIETEMP(:,:,:,ii)=temp;
SERIESAL(:,:,:,ii)=sal;
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NetCDF 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!