Scenario Manager Library

Revision as of 20:19, 9 November 2026 by BFilstrup (talk | contribs) (New page: Scenario Manager Library)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The Scenario Manager Library saves model outputs to CSV files, one file per output per scenario, reads them back into Analytica as arrays indexed by scenario, and lets you review the results and write them to Excel. It is a single Analytica file, Scenario_Manager_Library.ana, that you open to learn and embed in your own model to use.

Typical uses:

  • Run a model once per scenario and keep each run's results on disk.
  • Compare saved scenarios side by side without re-running the model.
  • Hand results to another model, or to colleagues, as plain CSV files.
  • Fill a formatted Excel report template with selected outputs.

Requirements

  • Analytica 7.1 is recommended (it was developed and tested in 7.1).
  • Writing spreadsheets uses Analytica's built-in spreadsheet functions (SpreadsheetOpen, SpreadsheetSetRange, SpreadsheetSave) and needs Analytica Developer edition or higher. No add-ins or extra libraries are needed: the library uses SpreadsheetOpen with backend: 'LibXl', which is built into Analytica.
  • Creating folders from the model (Create folder..., and automatic creation of a missing results folder) needs Analytica Enterprise or higher. With other editions, create the folder in Windows instead.

Getting started

  1. Open Scenario_Manager_Library.ana to see the guided front panel and a small worked example. Every button works as-is.
  2. In your own model, use File > Add Module..., pick Scenario_Manager_Library.ana and choose Embed (your model gets its own copy; the library file never changes).
  3. Inside the embedded module, delete the module Example (delete after setup). Its controls on the front panel are removed with it; nothing else depends on it.
  4. Open Scenario Manager library > Settings and fill in Outputs to save (and, if you like, Output settings and Scenario label).
  5. Check Settings check: each output shows the file it will write and its columns, or what still needs fixing.

Optional: if you use an Analytica version older than 7.1 and want to write spreadsheets, put Blank_workbook.xlsx (it comes with the library) next to your model. In 7.1 a new workbook is created automatically when needed.

Step by step (the front panel)

Step 1. Choose what to save

  • Outputs to save: identifiers of the variables to save, as text, e.g. ['Generation','Capacity'].
  • Output settings (one row per output, every column optional):
    • Result name: prefix of the file names. Blank = the output's identifier.
    • Keep zeroes: unticked (default) leaves cells that are 0 out of the file.
    • Export last: writes this output after the Before last export hook runs.
    • Spread across columns: an index identifier such as 'Year' gives one column per year instead of a single Value column.
  • Settings check: for example OK: Generation-Base.csv - columns: Year, Plant, Season, Value (GWh).

Step 2. Choose where files go

  • Results folder: blank = a CSV_Results folder next to the model, or type a full path. Missing folders (any number of levels) are created automatically.
  • One sub-folder per run (ticked by default): each run goes into its own sub-folder. Use Create folder... to make one; if you export without choosing one, you are asked for a name. Untick it to keep every file in the results folder itself.

Step 3. Name the run and export

  • Scenario label: the name used in the file names. Keep Base, or type your scenario variable's identifier without quotes (e.g. Demand_scenario) so each export is named after the selected scenario.
  • Example file name: a preview, e.g. Generation-Reference.csv.
  • Export to CSV saves every output for the current run. To export many scenarios, loop over them in a button script, setting your scenario variable and calling the export button each time (the example's loop button shows the pattern). With Scenario label set to Demand_scenario:
For s := Demand_case Do (
  Demand_scenario := s;
  Csv_export_button
)
  • If a file already exists you are asked whether to overwrite it, skip it or stop (Warn before overwriting files, on by default).

Step 4. Read results back

  • Read from folders: one or more run folders (not needed without sub-folders).
  • Results found lists every result saved there (found with FileSystemListing from the .schema files), including results written by another model.
  • Result to read and Read-back result show a result as an array indexed by scenario (and by folder, if several are selected) plus its own indexes.
  • In your own formulas use Csv_import('Generation'). It accepts an identifier from Outputs to save or any result name found in the folders.

Step 5. Review and write to Excel

  • Output to review, Scenarios to show (empty = all) and Flat data show the saved rows.
  • Keep these columns, Aggregation method and Aggregated view summarise them (Sum, Min, Max, Average, Percentiles, ...).
  • Spreadsheet output:
    • Leave out columns: e.g. Folder and Scenario.
    • Spread across columns: e.g. Year gives one column per year in place of the Value column; Scenario puts scenarios side by side. Values are never added together.
    • Spreadsheet preview: exactly what will be written.
    • Review spreadsheet file: a file name (kept in the results folder) or a full path to your own workbook. Its other tabs are kept.
    • Template workbook: copied when the review workbook does not exist yet, e.g. a report template with formatted tabs.
    • Tabs in template and Tab for each output: each output gets a dropdown listing the template's tabs; (result name) creates a tab named after the result.
    • If the tab exists: Replace the tab, or Write into the tab (keep formatting).
    • Start cell: e.g. A3 to leave room for a title.
    • Write review to spreadsheet writes the output being reviewed; Write all outputs to spreadsheet writes every output to its chosen tab.

Optional features

All are off by default and live in Settings > Optional features:

Setting What it does
File name parts / File name values File names made of several parts, e.g. <Result>-<Scenario>-<Initials>.csv. Reading back adds one column per part.
Split files by index One file per element of an index (e.g. one file per region).
Clean file name parts Replaces characters that are not allowed in file names.
User initials / today's date Helpers to use in file name parts or folder names.
Suggested folder name Pre-filled name offered by Create folder...
Sub-folder depth Lets you read nested run folders (e.g. 2026\Run_A).
Export sets Named subsets of outputs; tick Leave out for outputs a set should skip.
Rename CSV columns A different column header for an index (default: the index Title).
Before export / Before last export / After export Buttons whose scripts run around every export; replace Null with your own statements.
Spreadsheet backend 'LibXl' (default, built in) or 'Excel' (uses Microsoft Excel).

File format

For each output, an export writes:

  • <Result name>-<file name parts>.csv: a header row, then one column per index (headed with the index Title) and a Value (units) column, or one value column per element when Spread across columns is used.
  • <Result name>.schema: a small CSV that records the index identifier behind each column (blank for the value column, @Index for spread value columns) and, when several file name parts are used, their names separated by |.

Reading back uses the schema to rebuild the array with your model's own indexes. CSV files made elsewhere can be read too, as long as they follow this convention and have a schema file next to them.

Tips

  • Type names that contain spaces in quotes (e.g. 'Sales data') so Analytica's autocomplete does not change them.
  • A stray Enter in an input box is harmless: line breaks and extra spaces are removed from names and paths.
  • Leaving out the Scenario column while several scenarios are shown gives unlabelled repeated rows; pick one scenario, keep the column, or spread Scenario across columns instead.
  • The library's internal identifiers start with Csv_ (from its earlier name, the CSV I/O library).

See also

Comments
Loading comments...