How to extract data from .nc file based on latitude, longitude, time and wind?

9 次查看(过去 30 天)
Hello,
This is my first time trying to pull data from an netCDF file using MATLAB...
here's what I did...
clear all
close all
ncid = netcdf.open('uwnd.sig995.2016.nc','NC_NOWRITE');
lat = netcdf.getVar(ncid,0);
whos lat
lon = netcdf.getVar(ncid,1);
whos lon
time = netcdf.getVar(ncid,2);
whos time
wind = netcdf.getVar(ncid,3); %var3 wind 4x day
whos wind
latlim = [5 -5]; %5N 5S
lonlim = [-50 -45]; %-50W -45W
I dont know how to extrat one year for exemple 2016:
timelim = [ ? ]
and the wind for these lat lon and time...
Any help?
Thx in advance! Regards.
Below the data:
Format:
netcdf4_classic
Global Attributes:
Conventions = 'COARDS'
title = '4x daily NMC reanalysis (2014)'
history = 'created 2013/12 by Hoop (netCDF2.3)'
description = 'Data is from NMC initialized reanalysis
(4x/day). These are the 0.9950 sigma level values.'
platform = 'Model'
References = 'http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanalysis.html'
dataset_title = 'NCEP-NCAR Reanalysis 1'
Dimensions:
lat = 73
lon = 144
time = 1460 (UNLIMITED)
Variables:
lat
Size: 73x1
Dimensions: lat
Datatype: single
Attributes:
units = 'degrees_north'
actual_range = [9.00e+01 -9.00e+01]
long_name = 'Latitude'
standard_name = 'latitude'
axis = 'Y'
lon
Size: 144x1
Dimensions: lon
Datatype: single
Attributes:
units = 'degrees_east'
long_name = 'Longitude'
actual_range = [0.00e+00 3.58e+02]
standard_name = 'longitude'
axis = 'X'
time
Size: 1460x1
Dimensions: time
Datatype: double
Attributes:
long_name = 'Time'
delta_t = '0000-00-00 06:00:00'
standard_name = 'time'
axis = 'T'
units = 'hours since 1800-01-01 00:00:0.0'
actual_range = [1.88e+06 1.89e+06]
uwnd
Size: 144x73x1460
Dimensions: lon,lat,time
Datatype: single
Attributes:
long_name = '4xDaily u-wind at sigma level 995'
units = 'm/s'
precision = 2
least_significant_digit = 1
GRIB_id = 33
GRIB_name = 'UGRD'
var_desc = 'u-wind'
level_desc = 'Surface'
statistic = 'Individual Obs'
parent_stat = 'Other'
missing_value = -9.97e+36
valid_range = [-1.02e+02 1.02e+02]
dataset = 'NCEP Reanalysis'
actual_range = [-3.45e+01 3.71e+01]

采纳的回答

Walter Roberson
Walter Roberson 2016-11-14
Your data is not arranged by year, it is arranged by time.
You will need to retrieve the Time vector. According to the notes it is in 'hours since 1800-01-01 00:00:0.0' . So divide that by 24 (to get days) and add datenum('1800-01-01 00:00:0') to get a result which is in MATLAB datenum format. Use datevec() to convert those values into arrays with year, month, day, hour, minute, second components. Compare to the desired year(s) to find the indices of the entries of interest. Then, use those indices to access the third dimension of the uwnd data in order to get the data for those times.
  4 个评论

请先登录,再进行评论。

更多回答(1 个)

Rishwanth Darun A S
hello Truccolo, Can you post the code for the same? Your revised code for the final result
  4 个评论
Malaidevan
Malaidevan 2019-3-29
Now the nc file operates as no. of Hours from year 1900
So the corrected line for datevector will be:
"""
time_datenum = time / 24 + datenum('1900-01-01 00:00:00');
"""
Walter Roberson
Walter Roberson 2021-2-10
Elaine's files happened to be based from 1800 not 1900.
nc files can use any base time they want, and do not have to use hours as the increment. We had a struggle a while back with a person whose nc file headers said that the time increment was 3 hours each, which failed badly when compared to what they expected the times to be, which was more like 20 minutes each.

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by