【发布时间】:2020-08-06 06:17:26
【问题描述】:
我有具有每日时间分辨率的气候数据,并且想要按月和按年计算有降水(例如,大于 1 毫米/天)的天数。
我尝试过eca_pd,1 和eca_rr1,但这些命令会返回所有年份的雨天总数。
例如,cdo eca_pd,1 infile outfile
是否有命令返回每个月和/或每年的雨天?
【问题讨论】:
标签: netcdf weather netcdf4 nco cdo-climate
我有具有每日时间分辨率的气候数据,并且想要按月和按年计算有降水(例如,大于 1 毫米/天)的天数。
我尝试过eca_pd,1 和eca_rr1,但这些命令会返回所有年份的雨天总数。
例如,cdo eca_pd,1 infile outfile
是否有命令返回每个月和/或每年的雨天?
【问题讨论】:
标签: netcdf weather netcdf4 nco cdo-climate
使用 NCO 的 ncap2,创建一个二进制标志,然后将其汇总到所需的维度:
ncap2 -s 'rainy=(precip > 1);rainy_days=rainy.total($time)' in.nc out.nc
【讨论】:
您可以使用 CDO 的屏蔽功能完成此任务。
第一步是制作一个等效文件,如果 P> 阈值(在您的情况下为 1 毫米/天),则为 1,否则为 0。为此,我们使用“大于或等于一个常数”的 gec 函数(如果您愿意,也可以使用 ge="greater than"):
cdo gec,1 input.nc mask.nc
(假设输入文件中的单位为毫米/天)。
然后您可以简单地将这个掩码在您想要统计的时间段(月、年等)内相加
cdo monsum mask.nc nwetdays_mon.nc
cdo yearsum mask.nc nwetdays_year.nc
当然,如果您想在一行上执行此操作,您可以通过管道进行此操作:例如
cdo monsum -gec,1 input.nc nwetdays_mon.nc
如果您想计算特定月份的气候学,我们可以更进一步。如果您有多年数据集,那么您可以使用出色的“ymonstat”命令。因此,例如,一旦您在上面计算了每月的一系列潮湿天数,您就可以使用
计算每个月的平均值cdo ymonmean nwetdays_mon.nc nwetdays_mon_clim.nc
然后,您可以将该系列与此月度气候学区分开来,为您提供该系列中每个月潮湿天数的异常情况
cdo ymonsub nwetdays_mon.nc nwetdays_mon_clim.nc nwetdays_mon_anom.nc
希望对你有帮助!
(ps:我通常总是发现以这种方式直接使用 CDO 计算这些统计数据更容易,我很少发现内置的气候函数准确按照我的方式计算统计数据想)。
【讨论】:
您也可以在 cf-python 中执行此操作,基本上使用与上述 CDO 示例相同的方法,但在 Python 环境中,使用 where 和 collapse 方法:
import cf
# Read the dataset
f = cf.read('filename.nc')[0]
# Mask out dry days (assuming that your data
# units are 'mm day-1' or 'kg m-2 day-1', etc.)
wet = f.where(cf.le(1), cf.masked)
# If the data are in units of 'metres/day', say, then you could do:
# wet = f.where(cf.le(0.001), cf.masked)
# or
# wet = f.where(cf.le(1, 'mm day-1'), cf.masked)
# etc.
# Count the wet day occurrences by month
count_monthly = wet.collapse('T: sample_size', group=cf.M())
# Count the wet day occurrences by year
count_yearly = wet.collapse('T: sample_size', group=cf.Y())
# Get the data as numpy arrays
print(count_monthly.array)
print(count_yearly.array)
# Count the wet day totals by month
wet_day_sum_monthly = wet.collapse('T: sum', group=cf.M())
# Count the wet day totals by year
wet_day_sum_yearly = wet.collapse('T: sum', group=cf.Y())
【讨论】: