Display data of a particular variable present in a netcdf file

13 visualizaciones (últimos 30 días)
Hello people!
I am a newbie in MATLAB who has just started to use for the past month or so am facing issue while learning to work with oceanic netcdf files for my project purpose.
I have a netcdf file as an output from my oceanographic simulation and I want to get a single ouput for a particular variable from my output file for a specific latitude longitude, time index and depth.
eg: I want to get the value of u momentum velocity from the variable u for latitude "-8.22426367031282" and longitude "115.309657931722" , level index = 1 (for my s_rho value) , and a specific oceantime say " 01-Apr-2008-15:00:00" or any such timestep, when I input all these values say u_vel[115.309657931722 ,-8.22426367031282, 1 , '01-Apr-2008-15:00:00'] , I hope to get an ouput like 0.25477523 (any units).
Here are my dimension of the output file and the variable:
Output file: Dimensions:
xi_rho = 100
xi_u = 99
xi_v = 100
xi_psi = 99
eta_rho = 50
eta_u = 50
eta_v = 49
eta_psi = 49
N = 15
s_rho = 15
s_w = 16
tracer = 1
boundary = 4
ocean_time = 7 (UNLIMITED)
u
Size: 99x50x15x273
Dimensions: xi_u,eta_u,s_rho,ocean_time
Datatype: single
Attributes:
long_name = 'u-momentum component'
units = 'meter second-1'
time = 'ocean_time'
grid = 'grid'
location = 'edge1'
coordinates = 'lon_u lat_u s_rho ocean_time'
v
Size: 100x49x15x7
Dimensions: xi_v,eta_v,s_rho,ocean_time
Datatype: single
Attributes:
long_name = 'v-momentum component'
units = 'meter second-1'
time = 'ocean_time'
grid = 'grid'
location = 'edge2'
coordinates = 'lon_v lat_v s_rho ocean_time'
field = 'v-velocity, scalar, series'
I wrote a code for an attempt but every time I execute my MATLAB crashes and also I am not sure if what I am doing will give me any result as well: If anybody please suggest me the right script for my intended job, that would be of great great help.
file = 'Lombok_roms_his.nc';
latitude = ncread(file,'lat_u');
longitude = ncread(file,'lon_u');
mask = ncread(file,'mask_rho');
time = ncread(file,'ocean_time');
u_vel = ncread(file,'u');
v_vel = ncread(file,'v');
%% this is the part which I try to exceute in command window%%
u_vel[115.309657931722 ,-8.22426367031282, 1 , '01-Apr-2008-15:00:00']
v_vel[115.309657931722 ,-8.22426367031282, 1 , '01-Apr-2008-15:00:00']

Respuesta aceptada

Walter Roberson
Walter Roberson el 14 de Jun. de 2021
Editada: Walter Roberson el 14 de Jun. de 2021
latitude is effectively "plaid" -- there are 50 columns and 50 different latitudes (to within round-off). But you cannot just use unique(): there are over 2800 "unique" latitudes, all of which are the same as other latitudes to within 4e-15 .
The fact that it is effectively "plaid" allows us to do interpolation over it to figure out where any particular latitude is represented.
Likewise, longitude is effectively plaid but in the other direction, with there being 99 rows and 99 distinct longitude values to within round-off error.
The latitude range in the file is -8.96036167119211 to -8.2089282952945.
The longitude range in the file is 115.175227369057 to 116.320809555245.
You are hoping for information about latitude 1.2417, longitude 103.8, depth 4... but that data simply does not exist in the file.
Is it correct that depth = 4 corresponds to the 4th entry along the s_rho dimension?
(My internal reference for this matter is T0098919)
  11 comentarios
Shankhaneel Basak
Shankhaneel Basak el 25 de Jun. de 2021
Thanks a lot Mr Walter Roberson. It was such a great help.
Kind regards
-Neel
Walter Roberson
Walter Roberson el 25 de Jun. de 2021
Note that that logic about finding the nearest point, interpolates at that nearest point. You should refrain from doing that if you can interpolate where you are instead.
... And if your origin point is 45 km from the nearest point you have data for, then it isn't clear that knowing about the data over there is meaningful. Moving the point could be useful for cases where you are shifting from just near the coast, over to coast that is effectively "right there" if only you had more precise positions (and data).

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by