Postprocessor API

calvin.postprocessor.aggregate_regions(fp)

Read the results CSV files and aggregate results by region (optional).

Parameters:

fp – (string) directory where output files are written.

Returns:

nothing, but overwrites the results files with new columns added for regional aggregations.

calvin.postprocessor.combine_annual_results(years, annual_dir, output_dir=None)

Combine per-year result directories from a limited-foresight annual run into single concatenated CSV files.

Parameters:
  • years – iterable of water years (ints), e.g. range(1922, 2004)

  • annual_dir – directory containing per-year subdirectories named WY{year} (e.g. results/annual)

  • output_dir – directory to write combined CSVs. Defaults to the parent of annual_dir.

Returns:

output_dir path (string)

calvin.postprocessor.dict_insert(D, k1, k2, v, collision_rule=None)

Custom insertion into nested dictionary. Assign D[k1][k2] = v if those keys do not exist yet. If the keys do exist, follow instructions for collision_rule

calvin.postprocessor.postprocess(df, model, resultdir=None, annual=False, year=None)

Postprocess model results into timeseries CSV files.

Parameters:
  • df – (dataframe) network links data

  • model – (CALVIN object) model object, post-optimization

  • resultdir – (string) directory to place CSV file results

  • annual – (boolean) whether to run annual optimization or not

  • year – (int) for annual cosvf runs, the water year being postprocessed

Returns:

(dict) end-of-period storage keyed by node name (suitable for passing as ic to the next year’s CALVIN run), only when annual=True. Otherwise writes result CSVs and returns None.

calvin.postprocessor.save_dict_as_csv(data, filename)

Given nested dict data, write to CSV file where rows are timesteps and columns are links/nodes as appropriate.

Parameters:
  • data – (dict) Nested dictionary of results data

  • filename – (string) Output CSV filename

Returns:

nothing, but writes the output CSV file.