parasolpy.util

Utility functions: unit conversions, path helpers, time-series pivoting, XML parsing.

Functions

convert_cfs_to_af(val)

Convert cubic feet per second (daily) to acre-feet for numeric scalar/vector inputs.

convert_cfs_to_cms(val)

Convert cubic feet per second to cubic meters per second for numeric scalar/vector inputs.

convert_cms_to_mcm(val)

Convert cubic meters per second (daily) to million cubic meters for numeric scalar/vector inputs.

ensure_dir(path)

Create a directory (and parents) if missing and return it as a Path.

pivot_timeseries_by_year(data[, ...])

Pivot a DatetimeIndex time series into day-of-year (rows) by year (columns).

process_xml(filename[, ...])

Parse XML configuration into decision names, objective names, and optional objective directions.

read_xml(filename)

Read an XML file and return a BeautifulSoup XML document.

script_local_path(filename[, must_exist, ...])

Resolve a path relative to the calling script file.

parasolpy.util.script_local_path(filename, must_exist=True, caller_file=None)[source]

Resolve a path relative to the calling script file.

Parameters:
  • filename – File name or relative path from the script directory.

  • must_exist – If True, raise FileNotFoundError when the resolved path does not exist.

  • caller_file – Optional script path override; defaults to the caller’s file.

parasolpy.util.ensure_dir(path)[source]

Create a directory (and parents) if missing and return it as a Path.

parasolpy.util.convert_cfs_to_af(val)[source]

Convert cubic feet per second (daily) to acre-feet for numeric scalar/vector inputs.

parasolpy.util.convert_cfs_to_cms(val)[source]

Convert cubic feet per second to cubic meters per second for numeric scalar/vector inputs.

parasolpy.util.convert_cms_to_mcm(val)[source]

Convert cubic meters per second (daily) to million cubic meters for numeric scalar/vector inputs.

parasolpy.util.pivot_timeseries_by_year(data, value_column=None, aggfunc='mean')[source]

Pivot a DatetimeIndex time series into day-of-year (rows) by year (columns).

Parameters:
  • data – pandas Series or DataFrame with a DatetimeIndex.

  • value_column – Required for multi-column DataFrames; ignored for Series.

  • aggfunc – Aggregation used by pandas pivot_table when duplicate day/year entries occur. Common options: "mean" (good default for rate-like data), "sum" (additive quantities), "min", "max", "median", "first", "last". Any aggregation string accepted by pandas pivot_table is valid.

parasolpy.util.read_xml(filename)[source]

Read an XML file and return a BeautifulSoup XML document.

parasolpy.util.process_xml(filename, include_objective_directions=False, default_objective_direction='minimize')[source]

Parse XML configuration into decision names, objective names, and optional objective directions.

Parameters:
  • filename – Path to XML configuration file.

  • include_objective_directions – If True, also return objective direction values.

  • default_objective_direction – Direction to use when an objective has no <sense> tag. Must be either “minimize” or “maximize”.