我正在处理用xarray导入的NetCDF格式的古气候数据(536-550 CE)。时间格式有点奇怪:
import xarray as xr
ds_tas_01 = xr.open_dataset('ue536a01_temp2_seasmean.nc')
ds_tas_01['time']
<xarray.DataArray 'time' (time: 61)>
array([15360215.25, 15360430.75, 15360731.75, 15361031.75, 15370131.75,
15370430.75, 15370731.75, 15371031.75, 15380131.75, 15380430.75,
15380731.75, 15381031.75, 15390131.75, 15390430.75, 15390731.75,
15391031.75, 15400131.75, 15400430.75, 15400731.75, 15401031.75,
15410131.75, 15410430.75, 15410731.75, 15411031.75, 15420131.75,
15420430.75, 15420731.75, 15421031.75, 15430131.75, 15430430.75,
15430731.75, 15431031.75, 15440131.75, 15440430.75, 15440731.75,
15441031.75, 15450131.75, 15450430.75, 15450731.75, 15451031.75,
15460131.75, 15460430.75, 15460731.75, 15461031.75, 15470131.75,
15470430.75, 15470731.75, 15471031.75, 15480131.75, 15480430.75,
15480731.75, 15481031.75, 15490131.75, 15490430.75, 15490731.75,
15491031.75, 15500131.75, 15500430.75, 15500731.75, 15501031.75,
15501231.75])
Coordinates:
* time (time) float64 1.536e+07 1.536e+07 1.536e+07 ... 1.55e+07 1.55e+07
Attributes:
standard_name: time
bounds: time_bnds
units: day as %Y%m%d.%f
calendar: proleptic_gregorian
axis: T
因此,我想制作自己的时间数组,以用于绘制气候数据。对于我使用的每月数据:
import numpy as np
time = np.arange('0536-01-31', '0551-01-31', dtype='datetime64[M]')
这为我提供了两个日期之间的年和月的数组。
现在我使用cdo seasmean('djf','mam',jja,'son')按季节对数据进行分组,并得到61个值而不是180个值。是否可以将“时间”数组重新组合为季节性值,还是创建一个与季节性数据相对应的新时间数组?
答案 0 :(得分:0)
我通过在np.arange中设置步数来使其工作:
time = np.arange('0536-01-31', '0551-01-31', steps=3, dtype='datetime64[M]')
这每三个月给出一个时间步长,因此基本上是每个“季节”。