简体   繁体   English

日期之间的小时数

[英]number of hours between dates

I have a netCDF file and I am attempting to identify the first date in the file and the 'base date'. 我有一个netCDF文件,正在尝试确定文件中的第一个日期和“基准日期”。 The file contains monthly data. 该文件包含每月数据。 My notes, which are fairly old, indicate the first date is January 1, 1948. 我的笔记相当陈旧,表明第一次约会是1948年1月1日。

The following R code gives the first date as 17067072: 以下R代码将第一个日期定为17067072:

library(ncdf)
library(chron)
my.data <- open.ncdf('my.netCDF.nc')
x = get.var.ncdf(my.data, "lon" )
y = get.var.ncdf(my.data, "lat" )
z = get.var.ncdf(my.data, "time")
z[1:5]

#  [1] 17067072 17067816 17068512 17069256 17069976

I downloaded an application called ncdump.exe and after typing the following line in the Windows command window: 我下载了一个名为ncdump.exe的应用程序,并在Windows命令窗口中键入以下行:

C:\Users\Mark W Miller\ncdump>ncdump -h my.netCDF.nc

I learned that the base date is: 我了解到基准日期是:

time:units = "hours since 1-1-1 00:00:0.0" ;

This same base data is obtained in R using: 使用R在R中获得相同的基础数据:

att.get.ncdf(my.data,"time","units")$value
[1] "hours since 1-1-1 00:00:0.0"

I tried to verify that with the following R code: 我尝试使用以下R代码进行验证:

date1 <- as.Date("01/01/0001", "%m/%d/%Y")
date1
# [1] "0001-01-01"

date2 <- as.Date("01/01/1948", "%m/%d/%Y")
date2
# [1] "1948-01-01"

period <- as.Date(date1:date2, origin = "00-01-01")

hours <- 24 * (length(period)-1)
hours
# [1] 17067024

There is a difference of 48 hours between the number in z[1] and the number returned by the R code immediately above: z[1]的数字与紧接上方的R代码返回的数字之间相差48小时:

17067072 - 17067024
[1] 48

Where is my error? 我的错误在哪里? Since the netCDF file contains monthly data I doubt the first date is January 3, 1948. The website from which I downloaded the data does not offer the option of selecting the day within month. 由于netCDF文件包含每月数据,因此我怀疑第一个日期是1948年1月3日。我从中下载数据的网站没有提供选择月份内日期的选项。

The application ncdump.exe can be downloaded from here: 可以从这里下载应用程序ncdump.exe

http://www.narccap.ucar.edu/data/ascii-howto.html http://www.narccap.ucar.edu/data/ascii-howto.html

If I can figure out how to subset the netCDF file I might upload the smaller file somewhere. 如果可以弄清楚netCDF文件的子集,可以将较小的文件上传到某个地方。

Thank you for any advice. 感谢您的任何建议。

Have you looked at your period vector? 你看过你的period向量了吗? when I looked at the first few and last few values the year comes out as something that does not make sense. 当我查看前几个值和最后几个值时,一年的结果是没有意义的。 Possibly something is messed up in one of the conversions. 可能是其中一项转换搞砸了。

Also note that same computer programs treat 1900 as a leap year even though it was not, a difference between 2 programs on that factor could account for 24 of the hours in your difference. 另请注意,即使没有,相同的计算机程序也将1900视为a年,因此两个程序之间的差异可能会导致您有24小时的时间差。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM