Time format in netcdf files
53 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
II want to extract time series from a netcdf file but the time format is like this:
datetime_start = 2006-01-16T12:00:00Z
datetime_stop = 2100-12-16T12:00:00Z
ncid = netcdf.open('pr_Amon_inmcm4_rcp85_r1i1p1_200601-210012.nc','NC_NOWRITE');
filename = ncinfo('pr_Amon_inmcm4_rcp85_r1i1p1_200601-210012.nc');
disp(filename);
ncdisp('pr_Amon_inmcm4_rcp85_r1i1p1_200601-210012.nc');
% 2. EXTRACT VARIABLES
longitude = ncread('pr_Amon_BNU-ESM_rcp85_r1i1p1_200601-210012.nc','lon');%
latitude = ncread('pr_Amon_BNU-ESM_rcp85_r1i1p1_200601-210012.nc','lat');%
time = ncread('pr_Amon_BNU-ESM_rcp85_r1i1p1_200601-210012.nc','time');% the time is in months
So how can I extract time series from this file from 2020-01-01 to 2050-01-12
2 comentarios
dpb
el 28 de Jun. de 2020
Would help to have a (small) sample file if want folks to try something...I've never used netcdf so "know nuthink!" about it. Looks like a standard time format, though.
What's the problem?
Walter Roberson
el 28 de Jun. de 2020
I have never seen a netcdf file that represented time in anything like 2006-01-16T12:00:00Z .
The netcdf files I have seen represent time in terms of elapsed fixed-length units since a particular date. For example "days" where "day" has been defined as 24*60*60 seconds (so ignoring leap seconds and ignoring timezones.) The only time I have seen "months" as the units was when an integral number of months was used, in which case you could never narrow in as finely as a particular time of a particular day of the month.
It is not uncommon in netcdf to use time units of convenience that do not correspond to real practices -- for example using months as is they were exactly 30 days each, or using fixed 365 day years as if leap years do not exist.
Respuestas (2)
per isakson
el 28 de Jun. de 2020
Editada: per isakson
el 28 de Jun. de 2020
"I want to extract time series from a netcdf file but the time format is like this: " Why "but", that's the way date-time is stored in this particular nc-file. You need to convert the text of the nc-file to a suitable Matlab data type, e.g. datetime
>> dt = datetime( '2100-12-16T12:00:00Z' ...
, 'InputFormat','yyyy-MM-dd''T''HH:mm:ssXXX' ...
, 'TimeZone','UTC' )
dt =
datetime
16-Dec-2100 12:00:00
"So how can I extract time series from this file from 2020-01-01 to 2050-01-12" You cannot use these dates as input arguments to the function, ncread(). There are two alternatives
- read the entire time series as you show in your question, convert the values of your variable, time, to a datetime variable, and finally delete the parts of the series that you don't need.
- You know beforehand which "rows" you want to read and use the input arguments, start and count of ncread()
2 comentarios
Walter Roberson
el 29 de Jun. de 2020
Are you expecting that the data in the file goes to December 2100 ? (Note: I do not mean December 2010 !!)
If I read the attributes correctly, the file is using a fixed 365 day year, and the entries in the variable time are days since 1850-1-1 . If you use days(TheTime) + datetime(1850,1,1) then all of the entries come out as nice noon or midnights. But if you start to correct for leap years, then the entries get messy.
Ver también
Categorías
Más información sobre NetCDF en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!