easy_vic_build.tools.params_func.GlobalParamParser

Parser utilities for VIC global parameter files.

Classes

GlobalParamParser()

Parser for VIC global-parameter text files.

GlobalParamSection([allow_duplicates])

Container for parameters within one global-parameter section.

class easy_vic_build.tools.params_func.GlobalParamParser.GlobalParamSection(allow_duplicates=False)[source]

Bases: object

Container for parameters within one global-parameter section.

Initialize a section container.

Parameters:

allow_duplicates (bool, optional) – Whether repeated parameter names should be stored as lists.

__init__(allow_duplicates=False)[source]

Initialize a section container.

Parameters:

allow_duplicates (bool, optional) – Whether repeated parameter names should be stored as lists.

add(name, value)[source]

Add one parameter entry.

Parameters:
  • name (str) – Parameter name.

  • value (str) – Parameter value.

Notes

If duplicates are enabled, values are appended as a list; otherwise the latest value overwrites previous value.

set_section(section_dict)[source]

Replace all parameters in the section.

Parameters:

section_dict (dict) – Mapping from parameter name to a single value or list of values.

Notes

Existing parameters are cleared before assignment.

class easy_vic_build.tools.params_func.GlobalParamParser.GlobalParamParser[source]

Bases: object

Parser for VIC global-parameter text files.

Initialize an empty parser state.

__init__()[source]

Initialize an empty parser state.

add_section(name)[source]

Add a section if it does not already exist.

Parameters:

name (str) – Section name.

Notes

Duplicate keys are enabled for sections matching FORCE_TYPE, DOMAIN_TYPE, and OUTVAR*.

set(section, name, value)[source]

Set one parameter value in a section.

Parameters:
  • section (str) – Section name.

  • name (str) – Parameter name.

  • value (str) – Parameter value.

Notes

Section is created automatically if missing.

set_section_values(section_name, section_dict)[source]

Replace all parameters in a section.

Parameters:
  • section_name (str) – Section name.

  • section_dict (dict) – Mapping from parameter name to value or list of values.

Notes

Existing parameters in this section are replaced.

get(section_name, param_name)[source]

Get one parameter value from a section.

Parameters:
  • section_name (str) – Section name.

  • param_name (str) – Parameter name.

Returns:

Parameter value.

Return type:

str

Raises:

KeyError – If section or parameter is missing.

load(file_or_path, header_lines=5)[source]

Load and parse global-parameter text.

Parameters:
  • file_or_path (str or file-like object) – File path or readable file-like object.

  • header_lines (int, optional) – Number of header lines to store before section parsing.

Raises:

ValueError – If input is neither path-like nor file-like.

write(file)[source]

Write parser content to a file-like object.

Parameters:

file (file-like object) – Writable file-like object.

remove_section(section_name)[source]

Remove a section from parser state.

Parameters:

section_name (str) – Section name.

Raises:

ValueError – If section name is not present in internal section order list.