如何使用scala在NetCDf文件中计算每小时

时间:2016-06-18 09:57:06

标签: scala netcdf

是否有一种方法可以将单位从小时数转换为几天到this dataset

double time(time) ;
time:units = "hours since 1800-01-01 00:00:0.0" ;
time:long_name = "Time" ;
time:delta_t = "0000-01-00 00:00:00" ;
time:avg_period = "0000-01-00 00:00:00" ;
time:standard_name = "time" ;
time:axis = "T" ;
time:actual_range = 1569072., 1895592. ;

1 个答案:

答案 0 :(得分:-1)

如果你可以使用Python,这是一个简单的过程:

第一步是使用netCDF4 num2date将数字日期转换为日期时间对象。

第二步是计算每个日期时间对象与time变量(即1800-01-01)中的时间戳(或原始日期)之间的天数。

import netCDF4
import datetime

ncfile = netCDF4.Dataset('./precip.mon.mean.nc', 'r')
time = ncfile.variables['time']
# Convert from numeric times to datetime objects
dates = netCDF4.num2date(time[:], time.units)

# Compute number of days since the original date
orig_date = datetime.datetime(1800,1,1)
days_since = [(t - orig_date).days for t in dates]