Configuration

gdal_conf

Stores GDAL configuration options for the current process.

get_config

Returns the content of a config.ini file as a dictionary.

get_keys

get all allowed configuration keys for a section

init

Initialize a configuration file.

keyval_check

Check and clean up key,value pairs while parsing a config file.

read_config_file

Reads a configuration file and returns a ConfigParser object

validate_options

Validate a configuration option against a set of allowed options.

validate_value

Validate the value of a configuration option.

write

Write configuration options to a config file.

s1ard.config.gdal_conf(config)[source]

Stores GDAL configuration options for the current process.

Parameters:

config (dict) – Dictionary of the parsed config parameters for the current process.

Returns:

Dictionary containing GDAL configuration options for the current process.

Return type:

dict

s1ard.config.get_config(config_file=None, **kwargs)[source]

Returns the content of a config.ini file as a dictionary.

Parameters:
  • config_file (str | None) – Full path to the config file that should be parsed to a dictionary.

  • kwargs (dict[str, str]) – further keyword arguments overriding configuration found in the config file.

Return type:

dict[str, Any]

Returns:

Dictionary of the parsed config parameters. The keys correspond to the config sections in lowercase letters.

s1ard.config.get_keys(section)[source]

get all allowed configuration keys for a section

Parameters:

section (str) – the configuration section to get the allowed keys for. Either ‘processing’, ‘metadata’ or the name of a SAR processor plugin e.g. ‘snap’.

Return type:

list[str]

Returns:

a list of keys

s1ard.config.init(target, source=None, overwrite=False, **kwargs)[source]

Initialize a configuration file.

Parameters:
  • target (str) – Path to the target configuration file.

  • source (str | None) – Path to the source file to read the configuration from. If not provided, a default configuration file within the package will be used.

  • overwrite (bool) – Overwrite an existing file?

  • kwargs (dict[str, str]) – Additional keyword arguments for overwriting the configuration in source.

Return type:

None

Examples

Create a file in the current working directory. work_dir and a scene search option (in this case SQLite via db_file) must be defined, other configuration is read from the default configuration file.

>>> from s1ard.config import init
>>> init(target='config.ini', work_dir='.', db_file='scenes.db')
s1ard.config.keyval_check(key, val, allowed_keys)[source]

Check and clean up key,value pairs while parsing a config file.

Parameters:
  • key (str) – the parameter key

  • val (str) – the parameter value

  • allowed_keys (list[str]) – a list of allowed keys

Return type:

str | None

s1ard.config.read_config_file(config_file=None)[source]

Reads a configuration file and returns a ConfigParser object

Parameters:

config_file (str or None) – the configuration file name. If None, the default configuration file within the package will be used.

Return type:

ConfigParser

Returns:

the configuration object

s1ard.config.validate_options(k, v, options)[source]

Validate a configuration option against a set of allowed options.

Parameters:
  • k (str) – the configuration key

  • v (str) – the configuration value

  • options (dict[str, list[str]]) – the configuration options

s1ard.config.validate_value(k, v)[source]

Validate the value of a configuration option.

Parameters:
  • k (str) – the configuration key

  • v (Any) – the configuration value

s1ard.config.write(config, target, overwrite=False, **kwargs)[source]

Write configuration options to a config file.

Parameters:
  • config (dict) – the configuration as returned by get_config()

  • target (str) – the name of the output file

  • overwrite (bool) – overwrite an existing file if it exists?

  • kwargs – further keyword arguments overriding configuration found in config.