Commit 84b0f140 authored by BorjaEst's avatar BorjaEst
Browse files

Added decade option

parent 65c212ea
......@@ -17,7 +17,7 @@ def cmdline_args():
p.add_argument("-f", "--sources_file", type=str, default="./sources.yaml",
help="custom sources YAML configuration (default: %(default)s)")
p.add_argument("-s", "--split_by", type=str, default=None,
choices=['year'],
choices=['year', 'decade'],
help="Period time to split output (default: %(default)s)")
p.add_argument("-v", "--verbosity", type=str, default='ERROR',
choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
......
......@@ -58,6 +58,13 @@ def to_netcdf(dirname, name, dataset, groupby=None):
fnames = [dirname + "/" + name + "_%s.nc" % y for y in years]
return fnames, dsx
def split_by_decade(dataset):
"""Splits a dataset by decade"""
decades = dataset.indexes["time"].year//10*10
decades, dsx = zip(*dataset.groupby(xr.DataArray(decades)))
fnames = [dirname + "/" + name + "_%s-%s.nc" % (d, d+10) for d in decades]
return fnames, dsx
def no_split(dataset):
"""Does not split a dataset"""
dsx = (dataset,)
......@@ -65,7 +72,8 @@ def to_netcdf(dirname, name, dataset, groupby=None):
return fnames, dsx
split_by = {
"year": split_by_year
"year": split_by_year,
"decade": split_by_decade
}
fnames, dsx = split_by.get(groupby, no_split)(dataset)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment