Hydrologic Projects
ESPAM2 Recharge Tools 1.5 Documentation
espam.settings
Settings Reader and Validator
Reads settings from the settings.ini file, and validates setting location settings.ini file is encapsulated in the Settings object. All ESPAM file builders take an instance of the Settings class for inputs.
- class espam.settings.DatasetDefinition(name, path, fields)
DatasetDefinition encapsulates all dataset references used by the Settings class, except for PRISM and Irrigation Year data.
- findField(name)
Returns a field Definition using a field name
- updateField(name, new_field_value)
Updates a field definition with a new field value
Parameters: - name (str.) – Name of field to update
- new_field_value (str.) – New field value
- updatePath(path)
Update path with new path
Parameters: path (str.) – New path to dataset on disk
- class espam.settings.FieldDefs(expected, name, type)
FieldDefs encapsulates required and optional field information. Field information in the Settings object are defined using FieldDefs
- class espam.settings.IrrigationYearDatasetDefinition(name)
Manages reference to the Irrigation Year datasets, and their corresponding stress period.
- add_year(year, path, stress_period)
Add a new irrigation year dataset.
Parameters: - year – Irrigation Year
- path – Path to dataset
- stress_period – Stress Period of irrigation year
- all_years()
Return a list of all irrigation years defined
Returns: List of int – List of irrigation years as ints
- find_stress_period(stress_period)
Return record if found for the stress period passed in
Returns: dict {“year”,”stressperiod”,”path”} or None
- find_year(year)
Return record if found for the year passed in
Returns: dict {“year”,”stressperiod”,”path”} or None
- class espam.settings.PRISMDatasetDefinition(name, total_stress_periods)
Manages reference to PRISM datasets, and their corresponding stress period.
- add_stress_period(stress_period, path)
Add record by stress period
Parameters: - stress_period (int.) – Stress period of PRISM dataset
- path (str.) – Path to PRISM dataset
- find_stress_period(stress_period)
Search for record by stress period
Parameters: stress_period (int.) – Stress period to search for
- get_all_prism_datasets()
Return list of all prism datasets
- get_total_stress_periods()
Get total amount of stress periods
- class espam.settings.Settings
Object representation of settings.ini file. All file builders use a settings object to pass dataset information.
Instead of directly instantiating the Settings class, the classmethod get_Settings should be used to instantiate the object
>>> settingsObj = settings.Settings.getSettings()
- findDataset(name)
Retrieve a dataset using a the dataset name
Returns: DatasetDefinition, PRISMDatasetDefinition or IrrigationYearDatasetDefinition based on the dataset name supplied.
- classmethod getSettings(validate=True, xml_file=None, profile='default')
Static method to retrieve a Settings object. This is the only way to create a Settings object
Parameters: - xml_file (str) – Path XML file which contains settings information
- validate – Validate paths to datasets and supplied fields
before returning object :type validate: bool :param profile: Name of profile within xml document to load :type profile: str
- classmethod get_profiles(ini_file=None)
Static method to retrieve all profiles defined in settings file
Parameters: ini_file (str) – Path to INI File Which Contains Setting Information Returns: List of str - All profiles contained within settings.ini file
- replaceDataset(name, newDataset)
Replace the default dataset with a new dataset
Parameters: - name (DatasetDefinition, PRISMDatasetDefinition or IrrigationYearDatasetDefinition.) – Name of dataset to update
- newDataset – New dataset definition
- class espam.settings.Validator(xml_filename=None, dtd_filename=None)
Validate the settings file to make sure it is properly formed and all of the datasets are in the proper place
- validate()
Validate the settings xml file to ensure that all files are located where the file indicates, and that the appropriate fields exist
- espam.settings.base_settings_file_path()
Get the default location for the template settings.ini file
This will normally be under the espam package in the XML directory
- espam.settings.build_empty_settings_file()
Creates an empty settings file with all of the sections and required fields created, but with no values set
- espam.settings.default_schema_path()
Get the default location for the settings.dtd file
This will normally be under the espam package in the XML directory
- espam.settings.find_settings_errors()
Check for schema errors in settings file
- espam.settings.reset_settings_values(section, key)
To be called by ConfigObj::walk()
Resets all keys in settings.ini file to an empty string