Package ftep_util

Generic F-TEP related utility classes and methods

Version 0.3 (11.10.2022)

Functions

def convert_to_python_re(userRegExp)

Converts the given expression to Python regular expression.

Makes it a global pattern by adding ^ and $ in the ends, escapes all dots to literal dots and converts all asterisks to .*

def detectFiles(dir, supported_extensions=None, pattern=None, verbose=False)

Detects files from a directory tree starting from the given dir

Returns a tuple (files, filtered_files). The returned files have path.

If extensions list is given collects only those files that end with one of the extensions.

If a pattern is given only file names matching the pattern are returned in the filtered list. The pattern is applied to the full path of the files. By default '*/' is added to the start of the pattern which makes it match file names (e.g. *.tif), or it can be used to match folders as well (e.g. 2020/*.tif)

Raises ValueError if dir is not valid.

def detectImageFiles(dir, supported_extensions=None, pattern=None, verbose=False)

Detects files from a directory tree starting from the given dir. Accepts all GDAL supported image files, with additional extensions and pattern filtering.

Returns a tuple (files, filtered_files). The returned files have path.

If extensions list is given collects only those files that end with one of the extensions.

If a pattern is given only file names matching the pattern are returned in the filtered list. The pattern is applied to the full path of the files. By default '*/' is added to the start of the pattern which makes it match file names (e.g. *.tif), or it can be used to match folders as well (e.g. 2020/*.tif)

Raises ValueError if dir is not valid.

Classes

class Params (list_variables=[])

A convenience class for handling service parameters in F-TEP.

Example:

# Default parameter values
params = ftep.Params()
params.setValue('band', 1)
params.setValue('window', 5)
params.setValue('set_nodata', True)

# Add parameters from file
params.readFile(parameterFile)

Methods

def appendValue(self, key, value)
def getBoolean(self, key)

Returns True if the parameter value is case-insensitive true or 1, False otherwise. Return False if the parameter value does not exist.

def getFloat(self, key, minvalue=None, maxvalue=None)

Return the value of the parameter as a float, or None if the parameter does not exist.

Raises ValueError if the value cannot be converted to a float.

Raises ValueError if the value is not within the optional bounds.

def getFloatList(self, key, minvalue=None, maxvalue=None, delimiter=None)

Return the value of the parameter as a list of floats, or None if the parameter does not exist.

Raises ValueError if the value cannot be converted to a float.

Raises ValueError if the value is not within the optional bounds.

def getInt(self, key, minvalue=None, maxvalue=None)

Return the value of the parameter as an integer, or None if the parameter does not exist.

Raises ValueError if the value cannot be converted to an integer.

Raises ValueError if the value is not within the optional bounds.

def getIntList(self, key, minvalue=None, maxvalue=None, delimiter=None)

Return the value of the parameter as a list of integers, or None if the parameter does not exist.

Raises ValueError if the value cannot be converted to an integer.

Raises ValueError if the value is not within the optional bounds.

def getListOfIntLists(self, key, minvalue=None, maxvalue=None, delimiter=None, listdelimiter=';')

Return the value of the parameter as a list of lists of integers, or None if the parameter does not exist. The lists should be separated with listdelimiter string.

Raises ValueError if the value cannot be converted to an integer.

Raises ValueError if the value is not within the optional bounds.

def getString(self, key)

Return the value of the parameter as a string, or None if the parameter does not exist or if the value is None.

def getValue(self, key)

Gets the value of a parameter as an object.

def readFile(self, file)

Reads a properties file with key=value pairs

If value starts with def (case insensitive) does not modify the default value. If value equals none (case insensitive) sets the value explicitly to None. Lines starting with # are comments. Leading and trailing whitespace is removed.

def setValue(self, key, value)

Sets the value of a parameter.