pytuflow.HPCProject

pytuflow.HPCProject#

class HPCProject(name, output_dir, features=None, *, crs, create_empties=True, **kwargs)#

Bases: BaseEngineProject

HPC project generator.

The HPC project generator is a highly customisable class for generating a Classic/HPC project from scratch. The class uses template files, modular features, variables, and directives, which are fully customisable and extendable by the user.

When an HPC project is created for the first time, the template files are copied locally to the users home directory:

  • Windows: %userprofile%\.tuflow_model_files\project_templates

  • Linux: ~/.tuflow_model_files/project_templates

Subsequent calls will use these cached templates, and the user is free to modify and/or extend them.

Projects can also be created via the CLI with pytuflow-project create --engine hpc. The CLI is documented on the following page: pytuflow-project

It is also possible to insert features into an existing project using HPCProject.insert_feature_into() or via the CLI with pytuflow-project insert --engine hpc.

Parameters:
  • name (str) – The name to be used for the project/model.

  • output_dir (str | Path) – The directory to generate the project within.

  • features (list[str] | None, optional) – The features to include within the generated project. The available features are dynamic and can be modified or extended by the user. See the example section below to check the available features. features can also be added post project generation using HPCProject.insert_feature_into().

  • crs (str) – The CRS to use for the project in the form of “AUTHORITY:CODE”. E.g. the TUFLOW tutorial model would be "EPSG:32760"

  • create_empties (bool, optional) – Sets whether to generate empty files.

  • **kwargs – Sets any number of variables used in the template files. The available variables are pulled from the defaults.json and hpc_defaults.json files that are cached in the users home directory under .tuflow_model_files/project_templates. Any keyword arguments will override the default values listed in the json files. The user is free to modify the defaults or extend them.

Examples

List the available features:

>>> from pytuflow import HPCProject
>>> for mod in HPCProject.get_available_features():
...     print(mod)
ad
estry
events
po
quadtree
rf
sgs
soils
swmm
toc
tutorial

Or list the features via the CLI:

pytuflow-project list-features --engine hpc

(Re-)Initialise the template files:

>>> from pytuflow.project import TemplateManager
>>> manager = TemplateManager(engine_type='hpc')
>>> manager.init_cache(force=True)

Initialise the templates via the CLI:

pytuflow-project init-templates --engine hpc --force

Initialise an HPC project with SGS and event features. This example uses the TUFLOW tutorial model CRS.

>>> project = HPCProject(
...     name='Tutorial_Model',
...     output_dir='models/TUFLOW',
...     features=['sgs', 'events'],
...     crs='EPSG:32760',
...     create_empties=True
... )
>>> project.validate() # list any errors - empy list is good
[]
>>> project.create()
PosixPath('models/TUFLOW')

Taking the same example as above, and initialising it via the CLI:

pytuflow-project create \
    --engine hpc \
    --name Tutorial_Model \
    --output-dir models/TUFLOW \
    --crs "EPSG:32760" \
    --features sgs events

Initialise an HPC project using GPKG and customise the map outputs.

>>> project = HPCProject(
...     name='Tutorial_Model',
...     output_dir='models/TUFLOW',
...     crs='EPSG:32760',
...     create_empties=True,
...     gis_format='GPKG',
...     output_formats={
...         "XMDF": {
...             "data_types": ["h", "v", "d", "q", "ZAEM1"],
...             "interval": 3600
...         },
...         "TIF": {
...             "data_types": ["h", "v", "d", "ZAEM1"],
...             "interval": 0
...         }
...     }
... )
>>> project.validate() # list any errors - empy list is good
[]
>>> project.create()
PosixPath('models/TUFLOW')

Initialising the same example via the CLI.

pytuflow-project create \
    --engine hpc \
    --name Tutorial_Model \
    --output-dir models/TUFLOW \
    --crs "EPSG:32760" \
    --gis-format GPKG \
    --output-format '{"XMDF": {"data_types": "h v d q ZAEM1", "interval": 3600}, \
        "TIF": {"data_types": "h v d ZAEM1", "interval": 0}}'

Insert Quadtree into an existing model:

>>> HPCProject.insert_feature_into('quadtree', 'models/TUFLOW/runs/Tutorial_Model_001.tcf')

Insert PO int an existing model using the CLI:

pytuflow-project insert \
    --engine hpc \
    --cf models/TUFLOW/runs/Tutorial_Model_001.tcf \
    --feature po
__init__(name, output_dir, features=None, *, crs, create_empties=True, **kwargs)#
Parameters:
  • name (str)

  • output_dir (str | Path)

  • features (list[str] | None)

  • crs (str)

  • create_empties (bool)

Methods

create

The execuation step when creating a project.

get_available_features

Discover all available features for this engine from JSON files.

insert_feature_into

Inserts a feature into an existing project.

validate

Validates the class inputs.

Attributes