Skip to content

Commit

Permalink
slim down to warming levels 1.2, 1.5, 2, 2.5, 3, ..., 5.5, 6.0 #30
Browse files Browse the repository at this point in the history
  • Loading branch information
perrette committed Jan 8, 2025
1 parent 7af07ed commit 909f113
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions rimeX/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ warming_level_min = 1
running_mean_window = 21
isimip_binned_backend = [ "csv", ]
projection_baseline = [ 1995, 2014,] # this is used in rime-preproc-digitize
quantilemap_warming_levels = [1.2, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0]
quantilemap_quantile_bins = 10

[preprocessing.regional]
weights = [ "latWeight", "gdp2015", "pop2015",]
Expand Down
10 changes: 8 additions & 2 deletions rimeX/preproc/quantilemaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def main():
group = parser.add_argument_group('Warming level matching')
group.add_argument("--running-mean-window", default=CONFIG["preprocessing.running_mean_window"], help="default: %(default)s years")
group.add_argument("--warming-level-file", default=None)
group.add_argument("--quantile-bins", default=10, type=int)
group.add_argument("--warming-levels", type=float, default=CONFIG["preprocessing.quantilemap_warming_levels"], nargs='+', help="default: %(default)s")
group.add_argument("--quantile-bins", default=CONFIG["preprocessing.quantilemap_quantile_bins"], type=int)

group = parser.add_argument_group('Indicator variable')
group.add_argument("-v", "--variable", nargs='+', default=[], choices=CONFIG["isimip.variables"])
Expand All @@ -127,26 +128,31 @@ def main():
o.warming_level_file = get_warming_level_file(**{**CONFIG, **vars(o)})

warming_levels = pd.read_csv(o.warming_level_file)

quantilemap_warming_levels = np.asarray(o.warming_levels)
warming_levels = warming_levels[warming_levels["warming_level"].isin(quantilemap_warming_levels)]

root_dir = Path(o.warming_level_file).parent

for name in o.variable + o.indicator:
indicator = Indicator.from_config(name)

for season in o.season:
if indicator.frequency == "annual" and season != "annual":
continue
filepath = root_dir / "quantilemaps" / indicator.name / season / f"{indicator.name}_{season}_quantilemaps.nc"
if filepath.exists() and not o.overwrite:
logger.info(f"{filepath} already exists. Use -O or --overwrite to reprocess.")
continue
filepath.parent.mkdir(parents=True, exist_ok=True)

array = make_quantile_map_array(indicator,
warming_levels,
season=season,
quantile_bins=o.quantile_bins,
running_mean_window=o.running_mean_window,
projection_baseline=o.projection_baseline,
)

logger.info(f"Write to {filepath}")
encoding = {array.name: {'zlib': True}}
array.to_netcdf(filepath, encoding=encoding)

0 comments on commit 909f113

Please sign in to comment.