How to read and plot NetCDF files with Matlab, file extension .nc - with script (2020)
HTML-код
- Опубликовано: 10 сен 2024
- This is a tutorial of how to read netcdf files and plot its variables in a matlab colored graph. This code also works in octave. Have a look to the script: bernardobastie...
Amazing video! Saved me. For some people who have asked in the comments:
1. I am currently running Matlab 2020 and I needed to download the "Mapping Toolbox" in order for the load coast command to work.
2. If the map appears all black you need to the remove the edges using the .EdgeAlpha=0 function.
Thanks so much for the video, Bernardo. super helpful and comprehensible! I really appreciate it :)
Eres una máquina Bernardo, me acabas de salvar el TFG muchas gracias!!
wow man ..you are great , saved my life ..thank you so much from india :)
Tu vídeo solucionó totalmente mis dudas, muchas gracias :)
Hi Bernardo!Thank you for this helpful video. I would like to ask you how to plot ECMWF ERA-Interim data for the sea surface temperature. I have opened the netCDF file but the matrix for the SST has an extra dimension ' time' and this makes it more cmplicated for me.Has anyone any suggestions how to plot my data in matlab?
Yes, I am facing the same issue too. Any updates? Did you manage to figure it out?
Hi Bernardo, I tried like you show, but appear and error after executing :
>>ncdisp(filename)
Error using internal.matlab.imagesci.nc/openToRead (line 1272)
Could not open gebco_2020_n24.400634765625_s22.965087667107582_w-107.59277299046518_e-105.77636629343034.nc for reading.
In the current folder appears some files, Do I need them? I am using a R2020b, regards
Sir to plot a graph, my third variable is in column matrix, hence it is not plotting graph, can you plz tell me how I can make it a matrix so that I can use it in plotting
Hi I got this error:
Error using pcolor (line 61)
Matrix dimensions must agree.
when running :
filename = 'xndcaa.pmh9jul.nc';
lat = ncread(filename, 'latitude');
lon = ncread(filename, 'longitude');
temp = ncread(filename, 'surf_temp') - 273.15;
mymap = pcolor(lon, lat, temp);
Do you know how to fix that? I'm running Matlab 2018a.
Nice one, Berny. This is really helpful as I develop my Matlab NetCDF skills :) Thanks mate!
Hi, I tried to use the relevant m file, but got the error below:
Error using netcdflib
The NetCDF library encountered an error during execution of 'inqVar' function - 'Variable not found
(NC_ENOTVAR)'
Any suggestion?
Ben Osborne the great sent me here. COool stuff man. Do a meet and greet so I can give you me XD
Hi Bernardo, I'm trying to extract the points inside a watershed from a netcdf file. The file is a cmip5 output file in a daily time step and has four dimensions (lat, lon, time and bnds) and seven variables (lat, lat_bnds, lon, lon_bnds, time, time_bnds, pr).
Could you please help me with this problem?
Hi this is very useful. Thanks Bernardo Adolfo Bastién Olvera! Just trying to plot the upwelling case for ROMS, if anyone is familiar with that...attempting to plot:
pcolor(x_rho, y_rho, h)
with the error:
Warning: MATLAB has disabled some advanced graphics rendering features by
switching to software OpenGL. For more information, click here.
Thanks
hi, thabk you! I haven't heard about ROMS, and also the warning looks wierd. Maybe is not the coding but the matlab version or something in your computer. I am not sure, sorry.
Extremely uselful video, thanks bunch for this
load coast is not working in my matlab. its saying its unknown.
Thank you for your help. I have the data in the same extension but doesn't the figure the dimensio is not equal.How can I extract globally longitude and a specific latitude at a given globally longitude and latitude data. If you help me to extract my data I can write your contribution in my paper puplished. Thank you
Why when I print a variable I get a bunch of NaNs?
Hi what if I want o display the name of the oceans and the continents on my graph?
Good video. What about 3d arrays (sometimes Cordex data are reported as 3d arrays) with rotated lat lon? How can we easily read and extract these types of data?
awesome! thank you very much for doing this helpful video
Thank you so much for the illustration!
Do u have the scripts ? Link is not working
Very useful!! thank you so much!!
Hey Jos, how u doin man
Yeah I also find it very hepful, the video
Great vídeo. Very helpful !! Tks
Hi Bernardo! I've just started using MATLAB to open NetCDF files and mine is different dataset(Sea Surface Height Altimeter). When I tried to create the figure using pcolor (X,Y,C) function I got the error below and I can't create my figure. Any suggestion?
Error using pcolor (line 54)
Color data input must be a matrix.
I've tried the input pcolor(C) still the error is there. Can help?
Have you solve this ?
If your data is 3-D use this to take slices out of it. slice = squeeze(var( : , : , "your desired slice e.g. 10"));
Thanks so much for this!!
Gemma Ives you're welcome!! :)
Estimado Bernardo, Muchas gracias por este tutorial! Mi variable tiene 3 dimensiones (T2) y eso no me permite graficarla, qué debo hacer? Agradecería mucho tu ayuda!
It was a great video. Thanks.
Can you please help me in resolving the error during 'pcolor' command as it says "dimension of matrix must same",?
Probably, dimension of your data is reverse. You can transpoze of the data you want to plot. For example: transpose(temp)
Hola Bernardo, gracias por el vídeo, ayúdame por favor. A la hora de colocar el comando "load coast" me bota el siguiente error:
Error using load
Unable to read file 'coast'. No such file or directory.
que puedo hacer en este caso?
Hi, Use the load coastlines
thanks man for this but im looking to extract and export data from netCDF data with matlab ...there is a solution for this ?
Great video, very helpful
Thanks. very helpful.
thanks so much for the file, I can't get the map to load, and thoughts?
hello Bernardo! thanks for the useful video. I would like to ask you, why you have added 360 to the long values ? as we know that the basemap has endpoints longitudes as -180 and -180 (let's say where these two met) so you should have added 180 only to the long values. it would show the actual world map. Now here in your video, the left and right side of the world map got shifted, which will give wrong latitude, longitude, and temp values. please correct me if I am wrong.
may i help? firstly, the coastline data is shifted but the temp is not because the coastline comes from different source, which is matlab. secondly, 360 is added because if we only add 180, the two half of the coastline map would be stacked on top of each other. The temp map has endpoints from 0 to 360 when the coastline from -180 to 180, to shift -180 to 180, you need to add 360.
How to get some specific coordinates from the global data..BTW your video was was very easy,thank you for sharing!
Thank you very helpful , can i make a correlation on the geographic map between two variables?
very helpful video. can you help us with ordinary CDF file data from THEMIS satellite . all the data from it are stored in CDF format.
Hi Bernardo, Thanks a lot. This tutorial is so helpful :) In matlab, can we display the data covering only the specific area (e.g. watershed)?
Hi Ayu! is good to know that =)
I think it would be possible. I would suggest to look to the function shaperead(filename)to read the watershed shapefile and then try to "crop" the gcm data. Actually I need to do the same in a problem that I'm solving. So as soon as I know the clear path to do it I might upload a video.
Thanks, Ayu, this is very important
Hi can you kindly update a video where we can plot data between particular lat long... say over india region
Thanks
Hello Link is not working can anyone help
Hi, try this one: createclimate.wordpress.com/codesandmodels/
Hi Bernardo! I am just getting started using MatLab to handle NetCDF files and this is very useful. I'm trying with a slightly different data set (Sea Level Data) and keep getting a pcolor plot which shows up all black. Can you offer any advice as to why this may be the case?
This is the data set!
podaac.jpl.nasa.gov/dataset/SEA_SURFACE_HEIGHT_ALT_GRIDS_L4_2SATS_5DAY_6THDEG_V_JPL1609
more specifically, the plot is not actually black, but the mymap.EdgeAlpha=0 command returns the error "Warning: Struct field assignment overwrites a value with class "double"", and the pixel edges are not removed. Any help?
Hi Max, I promise to look at it as soon as I have a break from a current deadline that I'm working in. Hope you can solve this!
i managed to work it out don't worry!
Hi Max. I'm facing the same case like you. Did you get anything by inputing mymap=pcolor(x,y,z)? I got is Error using pcolor (line 54). Can help?
You have found a solution for this problème??