Trouble loading data from .nc file

3 visualizaciones (últimos 30 días)
Ryan
Ryan el 12 de Nov. de 2013
Comentada: Kelly Kearney el 12 de Nov. de 2013
Hi,
This is my first time trying to pull data from an netCDF file using MATLAB. I'm having difficulty pulling data from this file below:
url = 'http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/pressure/hgt.1968.nc';
This is a file that basically should have the "thickness" (height) of the atmosphere at certain: levels (different from height), latitude, longitude and time. When I use netcdf.getVar(ncid, var) I can get data about each of those 4 variables but not the thickness data itself... does that make sense?
Anyways, any help is appreciated and sorry in advance if this seems vague b/c I don't know where to start.
Thanks!

Respuesta aceptada

Kelly Kearney
Kelly Kearney el 12 de Nov. de 2013
What version of Matlab are you running? They've introduced some nice higher-level reading and writing functions in more recent versions (R2010 and above, I think). You should be able to get the data quickly via ncread. Based on the file details:
ncdisp(url, '/', 'min')
Source:
http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/pressure/hgt.1968.nc
Format:
64bit
Variables:
level
Size: 17x1
Dimensions: level
Datatype: single
lat
Size: 73x1
Dimensions: lat
Datatype: single
lon
Size: 144x1
Dimensions: lon
Datatype: single
time
Size: 1464x1
Dimensions: time
Datatype: double
hgt
Size: 144x73x17x1464
Dimensions: lon,lat,level,time
Datatype: int16
you might not want to read in that whole variable all at once (b/c it has a scale factor and offset, it will be read in as a double array). To get one slice at time 1 and level 1:
x = ncread(url, 'hgt', [1 1 1 1], [Inf Inf 1 1]);
  2 comentarios
Ryan
Ryan el 12 de Nov. de 2013
Thanks Kelly this helps a lot! I'm running an up-to-date MATLAB so it worked well. A couple questions though just so I understand:
1) What does [1 1 1 1], [Inf Inf 1 1] mean?
2) The variable (hgt) that I'm reading in is by definition a positive number however there is both positive and negative values. I'll look into if this is how that data is packaged or if these are anomalies but if there is a coding reason behind this let me know.
Thanks again!
Kelly Kearney
Kelly Kearney el 12 de Nov. de 2013
The ncread function allows you to specify the start, count, and stride values to read certain subsets along each dimension. hgt is a 4-dimensional lat x lon x level x time variable, so I requested that the read start on the first index of each of these 4 dimensions; for the first two dimensions, Inf indicates to read until the end of that dimension, and for the latter 2 I only chose to read a single value (resulting in a 144 x 73 x 1 x 1 array).
Regarding the values, according to the attributes, it looks like those values are as intended:
>> ncdisp(url, 'hgt')
Source:
http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/pressure/hgt.1968.nc
Format:
64bit
Dimensions:
lon = 144
lat = 73
level = 17
time = 1464 (UNLIMITED)
Variables:
hgt
Size: 144x73x17x1464
Dimensions: lon,lat,level,time
Datatype: int16
Attributes:
long_name = '4xDaily Geopotential height'
actual_range = [-5.55e+02 3.24e+04]
unpacked_valid_range = [-7.00e+02 3.50e+04]
units = 'm'
add_offset = 3.21e+04
scale_factor = 1
missing_value = 3.28e+04
precision = 0
least_significant_digit = 0
GRIB_id = 7
GRIB_name = 'HGT'
var_desc = 'Geopotential height'
dataset = 'NMC Reanalysis'
level_desc = 'Multiple levels'
statistic = 'Individual Obs'
parent_stat = 'Other'
valid_range = [-3.28e+04 2.93e+03]
Perhaps these are geopotential height anomalies instead of absolute values?

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by