简体   繁体   English

使用气候数据运营商 (CDO) 的每日数据得出的每月潮湿天数总和

[英]Monthly sum of wet days from daily data using Climate Data Operators (CDO)

I have climate data with a daily temporal resolution and would like a count of days that have precipitation (eg, greater than 1mm/day) by month and by year.我有具有每日时间分辨率的气候数据,并且想要按月和按年计算有降水(例如,大于 1 毫米/天)的天数。

I've tried eca_pd,1 and eca_rr1 , but these commands return wet-day totals for all years.我已经尝试过eca_pd,1eca_rr1 ,但是这些命令会返回所有年份的雨天总数。

For example, cdo eca_pd,1 infile outfile例如cdo eca_pd,1 infile outfile

Is there a command to return wet-days for each month and/or year?是否有命令返回每个月和/或每年的雨天?

With NCO's ncap2 , create a binary flag then total it in the desired dimension(s):使用 NCO 的ncap2创建一个二进制标志,然后将其汇总到所需的维度:

ncap2 -s 'rainy=(precip > 1);rainy_days=rainy.total($time)' in.nc out.nc

You can accomplish this task with CDO's masking function.您可以使用 CDO 的屏蔽 function 完成此任务。

The first step is to make an equivalent file with 1 if P>threshold (1mm/day in your case) and 0 otherwise.第一步是制作一个等效文件,如果 P> 阈值(在您的情况下为 1 毫米/天),则为 1,否则为 0。 For this we use the "greater than or equal to a constant" gec function (or ge="greater than" if you prefer):为此,我们使用“大于或等于一个常数”gec function(或 ge="greater than",如果您愿意):

cdo gec,1 input.nc mask.nc 

(assuming units are mm/day in your input file). (假设输入文件中的单位是毫米/天)。

Then you can simply sum this mask over the period (months, years etc) that you want your statistic然后,您可以简单地将这个掩码在您想要统计的期间(月、年等)相加

cdo monsum mask.nc nwetdays_mon.nc 
cdo yearsum mask.nc nwetdays_year.nc

Of course you can pipe this if you like to do this on one line: eg当然你可以 pipe 如果你想在一行上这样做:例如

cdo monsum -gec,1 input.nc nwetdays_mon.nc 

We can take this even further if you want to work out the climatology for a particular month.如果您想计算特定月份的气候学,我们可以更进一步。 If you have a multiyear dataset then you can use the wonderful "ymonstat" commands.如果您有多年数据集,那么您可以使用出色的“ymonstat”命令。 So for example, once you have calculated your monthly series of wet days above, you can calculate the average for each month with因此,例如,一旦您计算了上述雨天的每月系列,您可以计算每个月的平均值

cdo ymonmean nwetdays_mon.nc nwetdays_mon_clim.nc

You can then difference the series from this monthly climatology to give you the anomaly of wet days in each month over the series然后,您可以将该系列与此月度气候学区分开来,为您提供该系列中每个月潮湿天数的异常情况

cdo ymonsub nwetdays_mon.nc nwetdays_mon_clim.nc nwetdays_mon_anom.nc

I hope that helps!我希望这会有所帮助!

(ps: I usually always find it is easier to calculate these kinds of statistics directly with CDO in this way, I rarely find that the built in climate functions calculate exactly the statistic as/how I want). (ps:我通常总是发现以这种方式直接使用 CDO 计算这些统计数据更容易,我很少发现内置的气候函数可以准确地计算出我想要的统计数据)。

You can also do this in cf-python , essentially using the same methodology as the CDO example above, but in a Python environment, using thewhere and collapse methods:您也可以在cf-python中执行此操作,基本上使用与上述 CDO 示例相同的方法,但在 Python 环境中,使用wherecollapse方法:

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())

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

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