Skip to content

Commit

Permalink
further bugfix #30
Browse files Browse the repository at this point in the history
  • Loading branch information
perrette committed Jan 8, 2025
1 parent 8a72a62 commit b9a5e67
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions rimeX/preproc/quantilemaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def make_quantile_map_array(indicator:Indicator, warming_levels:pd.DataFrame,
quant_step = 1/quant_bins
quants = np.linspace(quant_step/2, 1-quant_step/2, quant_bins)

all_warming_levels = []
warming_level_data = []
warming_level_coords = []

keywl = lambda r: r["warming_level"]
wl_records = sorted(warming_levels.to_dict(orient="records"), key=keywl)
Expand Down Expand Up @@ -86,13 +87,13 @@ def make_quantile_map_array(indicator:Indicator, warming_levels:pd.DataFrame,

samples = xa.concat(files_to_concat, dim="sample")
quantiles = samples.quantile(quants, dim="sample")
all_warming_levels.append(quantiles)
warming_level_data.append(quantiles)
warming_level_coords.append(wl)

warming_level_coords = [dat.coords["warming_level"] for dat in all_warming_levels]
all_warming_levels = xa.concat(all_warming_levels, dim="warming_level")
all_warming_levels = all_warming_levels.assign_coords({"warming_level": warming_level_coords}) # otherwise it's dropped apparently
all_warming_levels.name = indicator.name
return all_warming_levels
warming_level_data = xa.concat(warming_level_data, dim="warming_level")
warming_level_data = warming_level_data.assign_coords({"warming_level": warming_level_coords}) # otherwise it's dropped apparently
warming_level_data.name = indicator.name
return warming_level_data


def get_filepath(name, season="annual", root_dir=None, **kw):
Expand Down Expand Up @@ -139,6 +140,7 @@ def main():

root_dir = Path(o.warming_level_file).parent


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

Expand All @@ -161,4 +163,8 @@ def main():

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


if __name__ == "__main__":
main()

0 comments on commit b9a5e67

Please sign in to comment.