2.2. floodestimation.parsers — Parsing FEH data files

Parsers for FEH-style data files.

Module contains base parser class and subclassses for parsing CD3 files, AMAX files, etc.

Example:

>>> from floodestimation import parsers
>>> catchment = parsers.Cd3Parser().parse("17002.CD3")
>>> catchment.amax_records = parsers.AmaxParser().parse("17002.AM")
>>> catchment.id
17002
>>> catchment.watercourse
'River Leven'
>>> catchment.descriptors.dtm_area
416.56
>>> catchment.descriptors.centroid_ngr
(317325, 699832)
>>> catchment.amax_records[0].water_year
1968
>>> catchment.amax_records[0].flow
34.995

2.2.1. FehFileParser — Base file parser class

class floodestimation.parsers.FehFileParser[source]

Generic parser for FEH file format.

File consists typically of multiple sections as follows:

[Section Name]
field, value
another field, value 1, value 2
[End]
parsed_class

Class of object to be returned by parser.

alias of object

object = None

Object that will be returned at end of parsing.

parse_str(s)[source]

Parse string and return relevant object

Parameters:s (str) – string to parse
Returns:Parsed object
parse(file_name)[source]

Parse entire file and return relevant object.

Parameters:file_name (str) – File path
Returns:Parsed object
static parse_feh_date_format(s)[source]

Return a date object from a string in FEH date format, e.g. 01 Jan 1970

Parameters:s (str) – Formatted date string
Returns:date object
Return type:datetime.date

2.2.2. Cd3Parser — Parsing catchment files

class floodestimation.parsers.Cd3Parser[source]

Bases: floodestimation.parsers.FehFileParser

parsed_class

Class to be returned by parse(). In this case Catchment objects.

alias of Catchment

parse(file_name)

Parse entire file and return relevant object.

Parameters:file_name (str) – File path
Returns:Parsed object
parse_feh_date_format(s)

Return a date object from a string in FEH date format, e.g. 01 Jan 1970

Parameters:s (str) – Formatted date string
Returns:date object
Return type:datetime.date
parse_str(s)

Parse string and return relevant object

Parameters:s (str) – string to parse
Returns:Parsed object

2.2.3. XmlCatchmentParser — Parsing catchments saved as xml files

class floodestimation.parsers.XmlCatchmentParser[source]

Parser for XML catchment files as exported from FEH CD-ROM (v3).

An xml schema is not available.

parse(file_name)[source]

Parse entire file and return a Catchment object.

Parameters:file_name (str) – File path
Returns:Parsed object
Return type:Catchment
parse_str(s)[source]

Parse entire file and return a Catchment object.

Parameters:file_name (str) – File path
Returns:Parsed object
Return type:Catchment

2.2.4. AmaxParser — Parsing annual maximum flow records

class floodestimation.parsers.AmaxParser[source]

Bases: floodestimation.parsers.FehFileParser

parsed_class

Class to be returned by parse(). In this case a list of AmaxRecord objects.

alias of list

parse(file_name)

Parse entire file and return relevant object.

Parameters:file_name (str) – File path
Returns:Parsed object
parse_feh_date_format(s)

Return a date object from a string in FEH date format, e.g. 01 Jan 1970

Parameters:s (str) – Formatted date string
Returns:date object
Return type:datetime.date
parse_str(s)

Parse string and return relevant object

Parameters:s (str) – string to parse
Returns:Parsed object

2.2.5. PotParser — Parsing peaks-over-threshold (POT) records

class floodestimation.parsers.PotParser[source]

Bases: floodestimation.parsers.FehFileParser

parsed_class

Class to be returned by parse(). In this case a PotDataset objects.

alias of PotDataset

parse(file_name)

Parse entire file and return relevant object.

Parameters:file_name (str) – File path
Returns:Parsed object
parse_feh_date_format(s)

Return a date object from a string in FEH date format, e.g. 01 Jan 1970

Parameters:s (str) – Formatted date string
Returns:date object
Return type:datetime.date
parse_str(s)

Parse string and return relevant object

Parameters:s (str) – string to parse
Returns:Parsed object