how to get variables from a netcdf file
11 views (last 30 days)
Show older comments
Hi, could anyone help me? I imported this netcdf file of a weather wrf model, which analyzed some parameters for the month of June 2017. I don't know how to see the temperature variable, given that it has 3 dimensions (171x171x720). How can I get something like this for this variable, for example a column for the date (01/06/2017 00:00:00, 01:00:00 etc..) and a column for the temperature 15.7, 13.2 etc. also having the coordinates (lat,lon) as reference.
Thanks so much to anyone who can help me :)
ncdisp(filename)
filename = 'meteo_jun.nc'
Source:
C:\Users\sanny\linux\meteo_jun.nc
Format:
64bit
Global Attributes:
TITLE = ' OUTPUT FROM WRF V3.9.1.1 MODEL'
START_DATE = '2017-06-01_00:00:00'
SIMULATION_START_DATE = '2017-05-28_00:00:00'
WEST-EAST_GRID_DIMENSION = 172
SOUTH-NORTH_GRID_DIMENSION = 172
BOTTOM-TOP_GRID_DIMENSION = 56
DX = 1333.333
DY = 1333.333
Dimensions:
Time = 720 (UNLIMITED)
south_north = 171
west_east = 171
DateStrLen = 19
Variables:
T2
Size: 171x171x720
Dimensions: west_east,south_north,Time
Datatype: single
Attributes:
FieldType = 104
MemoryOrder = 'XY '
description = 'TEMP at 2 M'
units = 'K'
stagger = ''
coordinates = 'XLONG XLAT XTIME'
Times
Size: 19x720
Dimensions: DateStrLen,Time
Datatype: char
XLAT
Size: 171x171
Dimensions: west_east,south_north
Datatype: single
Attributes:
FieldType = 104
MemoryOrder = 'XY '
description = 'LATITUDE, SOUTH IS NEGATIVE'
units = 'degree_north'
stagger = ''
coordinates = 'XLONG XLAT'
cell_methods = 'Time: mean'
XLONG
Size: 171x171
Dimensions: west_east,south_north
Datatype: single
Attributes:
FieldType = 104
MemoryOrder = 'XY '
description = 'LONGITUDE, WEST IS NEGATIVE'
units = 'degree_east'
stagger = ''
coordinates = 'XLONG XLAT'
cell_methods = 'Time: mean'
1 Comment
dpb
on 25 Sep 2023
As per usual, you'd probably find more folks willing to poke at it in more detail if you were to attach the file for them to work with...
But, in general, you will use find() or ismembertol() to locate the position in the XLONG, XLAT arrays of the desired coordinates, then use that pair of values to index into the T2() array by the third dimension as T2(ix,iy,:) that will return a vector if ix,iy are single points. That will depend upon whether the grid is regular as presume will be, but we can't see it from here to know for absolute certain.
Answers (1)
Luis Jesús Olvera Lazcano
on 27 Sep 2023
In order to see the temperature variable, you will need to plot in an specified time. To find a specific date, it would be better to have time variable as datetime:
mystring = ncread(filename,'Times');
time = datetime(my_string,'InputFormat','yyyy-MM-dd HH:mm:ss.S'); % where my_string is your t variable
To find an specific datetime, for example "01/06/2017":
date = datetime('2017-06-01'); % considering only one date
td = ismember(time,date); % logical values, being 1 the only ones with the date specified
% Extract only one date in T2 data.
T2date = t2(:,:,td); % this will extract only the times that have the date in question.
[LAT LON] = meshgrid(lat,lon);
figure(1)
for i=1:length(T2date(1,1,:)) % to show time per time the T2 values in a LAT LON grid
pcolor(LAT,LON,t2date(:,:,i)), shading interp
pause(0.5) % in order to see each time with a 0.5 seconds duration
end
Let me know if this helps.
0 Comments
See Also
Categories
Find more on NetCDF in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!