pytuflow.Scope

pytuflow.Scope#

class Scope(type_name, name='', var=None, else_=False)#

Bases: object

Scope class for storing information about the input in regards to where/when it is used in the model.

Scope objects typically store the scope names in a list (e.g. Scope = SCENARIO, names = [‘D01’, ‘D02’]). This is due to how the model defines blocks (e.g. If Scenario == D01 | D02). This means that when checking for a scope, scopes names within a single Scope class are considered to be ‘or’ (i.e. D01 or D02). e.g.:

If Scenario == D01 | D02
    Read GIS Z shape == 2d_zsh_D01.shp
End if

The above is represented by: * Scope('SCENARIO', ['D01', 'D02'])

Even though TUFLOW does not support ‘AND’ logic in a single IF statement, it does support nested IF statements which is pretty much the same as ‘AND’. This is treated by using a list of Scope objects. e.g.:

If Scenario == D01
    If Scenario == D02
        Read GIS Z shape == 2d_zsh_D01_D02.shp
    End if
End if

The above is represented by: * [Scope('SCENARIO', ['D01']), Scope('SCENARIO', ['D02'])]

Because TUFLOW supports “Else IF” and “ELSE” blocks, the scope object can also store negative scopes prefixed with “!”. Consider the example below:

If Scenario == D01 | D02
    Read GIS Z shape == 2d_zsh_D01.shp
Else if Scenario == D03
    Read GIS Z shape == 2d_zsh_D03.shp
Else
    Read GIS Z shape == 2d_zsh_EXG.shp
End if

The Scope objects for each input would look like:

  • code:”Read GIS Z shape == 2d_zsh_D01.shp” -> Scope(‘SCENARIO’, [‘D01’, ‘D02])

  • code:”Read GIS Z shape == 2d_zsh_D03.shp” -> [Scope(‘SCENARIO’, [‘D03’]), Scope(‘SCENARIO’, [‘!D01’, ‘!D02’])]

  • code:”Read GIS Z shape == 2d_zsh_EXG.shp” -> [Scope(‘SCENARIO’, [‘!D01’, ‘!D02’]), Scope(‘SCENARIO’, [‘!D03’])]

Parameters:
  • type_name (str) – The type of scope (e.g. ‘SCENARIO’, ‘EVENT’, ‘VARIABLE’, etc.)

  • name (str, optional) – The name/value of the scope e.g. D01, or EXG

  • var (str, optional) – The variable name. e.g. for variables it would be Scope(‘Variable’, ‘5’, var=’CELL_SIZE’)

  • else (bool, optional) – Whether the scope is in after an ELSE statement.

  • else_ (bool)

__init__(type_name, name='', var=None, else_=False)#
Parameters:
  • type_name (str)

  • name (str)

  • var (str)

  • else_ (bool)

Methods

as_neg

Returns a new Scope object with the same type and names, but with the negative status set to True.

as_pos

Returns a new Scope object with the same type and names, but with the negative status set to False.

explode

Explodes a Scope instance that may have multiple names into a list of Scope instances.

from_string

Extracts scope from a string.

is_else

Returns whether the scope object is from an ELSE block.

is_neg

Returns whether the scope object is negative or not.

pretty_print

Returns a string representation of the scope object.

resolvable

Returns whether the scope object can be resolved.

resolve_scope

Resolve scope names from a list of scopes and a string to compare to.

set_else

Sets the ELSE status of the scope object.

supports_else_if

Returns whether the scope object supports ELSE IF statements.

to_string_end

Returns a TUFLOW string representation of the end of the scope object.

to_string_start

Returns a TUFLOW string representation of the start of the scope object.

Attributes

name_string

type

The type of scope (e.g. 'SCENARIO', 'EVENT', 'VARIABLE', etc.).

names

The names of the scope (e.g. ['D01', 'D02'] for a scenario scope).

var

The variable name (e.g. 'CELL_SIZE' for a variable scope).

known

For variable scopes - whether the variable value is known or not