parse_condition

sofia_redux.instruments.forcast.hdrequirements.parse_condition(condition)[source]

Parse a condition value defined in the keyword table

Conditions in the keyword table are usually defined as single condition=(KEYWORD<comparison operator>value) statements. However, there is a facility to provide AND or OR type logic across multiple conditions. The order in which conditions are supplied is important, as OR conditions will contain a set of AND conditions.

If all of the AND conditions in a single OR condition are satisfied then there is no need to check any of the other OR conditions and we can report that the full condition (the condition parameter) has passed. For example if condition string passed in was of the form:

<C1>&<C2>&<C3> | <C4><C5>

If all of the conditions in the first OR condition set (C1, C2, and C3) were satisfied, then we do not need to check C4 or C5 since the condition has already been satisfied. If one or more of the conditions was not met in the first OR set, we would need to check that both C4 and C5 in the second OR set are satisfied in order to report whether the overall condition has been met.

The return value of parse_condition examines the input <condition> string and returns an outer list of OR conditions containing an inner list of AND conditions. The above example would be converted to the form:

[[c1, c2, c3], [c4, c5]]

where the lowercase c now represents one of the AND conditions as a tuple of the form:

(keyword, comparison operator, value)
Parameters:
conditionstr

Of the form KEYWORD<comparison operator><value>

Returns:
list of list of tuple of str

The outer list contains a list of ‘OR’ (|, ||) conditions, which is a sublist or ‘AND’ (&, &&) conditions. i.e. ‘OR’ condition = [AND condition 1, AND condition 2,…]