使用iris转换日历

2024-04-26 17:36:58 发布

您现在位置:Python中文网/ 问答频道 /正文

如何转换带虹膜的日历?例如,将“公历”转换为“365天”?在

目前,我正在

original_tcoord = cube_in.coords()[tcoord_idx]

tmp_time = cf_units.num2date(
    original_tcoord.points, 
    original_tcoord.units.name, 
    target_calendar,
)

new_time = cf_units.date2num(
    tmp_time, 
    original_tcoord.units.name, 
    target_calendar,
)
new_unit = cf_units.Unit(
    original_tcoord.units.name,
    calendar=target_calendar
)
new_tcoord = iris.coords.DimCoord(
    new_time,
    standard_name=original_tcoord.standard_name, 
    long_name=original_tcoord.long_name, 
    var_name=original_tcoord.var_name,
    units=new_unit,
)

cube_adjusted = cube_in.copy()
cube_adjusted.remove_coord('time')
cube_adjusted.add_dim_coord(
    new_tcoord, 
    tcoord_idx
)

当然这不是最快的方法吗?在


Tags: nameintargetnewtimecoordscalendartmp
1条回答
网友
1楼 · 发布于 2024-04-26 17:36:58

这可能更简单,只需替换现有坐标上的单位即可:

tcoord = cube.coord('time')
tcoord.units = cf_units.Unit(tcoord.units.origin, calendar='gregorian')

这个建议来自于露丝·科默,不是我,但我会按照建议重新张贴在这里。在

相关问题 更多 >