Model base
QGIS CPLUS plugin models.
Activity
dataclass
Activity(uuid, name, description, path='', layer_type=LayerType.UNDEFINED, user_defined=False, pathways=list(), priority_layers=list(), layer_styles=dict(), mask_paths=list(), style_pixel_value=-1)
Bases: LayerModelComponent
Contains information about an activity used in a scenario. If the layer has been set then it will not be possible to add NCS pathways unless the layer is cleared. Priority will be given to the layer property.
__post_init__
Pre-checks on initialization.
Source code in src/cplus_plugin/models/base.py
activity_layer_style_info
Returns the color ramp properties for styling the activity layer resulting from a scenario run.
Returns:
Type | Description |
---|---|
dict
|
Color ramp properties for the activity styling or an empty dictionary if there was no definition found in the root style. |
Source code in src/cplus_plugin/models/base.py
add_ncs_pathway
Adds an NCS pathway object to the collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ncs |
NcsPathway
|
NCS pathway to be added to the activity. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the NCS pathway was successfully added, else False if there was an existing NCS pathway object with a similar UUID or the layer property had already been set. |
Source code in src/cplus_plugin/models/base.py
clear_layer
color_ramp
Create a color ramp for styling the activity layer resulting from a scenario run.
Returns:
Type | Description |
---|---|
QgsColorRamp
|
A color ramp for styling the activity layer or None if there was no definition found. |
Source code in src/cplus_plugin/models/base.py
contains_pathway
Checks if there is an NCS pathway matching the given UUID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pathway_uuid |
str
|
UUID to search for in the collection. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if there is a matching NCS pathway, else False. |
Source code in src/cplus_plugin/models/base.py
from_dict
classmethod
Create an Activity object from Activity dict.
Source code in src/cplus_plugin/models/base.py
is_pwls_valid
Checks if the priority layers are valid.
Returns:
Type | Description |
---|---|
bool
|
True if all priority layers are valid, else False if even one is invalid. If there are no priority layers defined, it will always return True. |
Source code in src/cplus_plugin/models/base.py
is_valid
Includes an additional check to assert if NCS pathways have been specified if the layer has not been set or is not valid.
Does not check for validity of individual NCS pathways in the collection.
Source code in src/cplus_plugin/models/base.py
pathway_by_uuid
Returns an NCS pathway matching the given UUID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pathway_uuid |
str
|
UUID for the NCS pathway to retrieve. |
required |
Returns:
Type | Description |
---|---|
NcsPathway
|
NCS pathway object matching the given UUID else None if not found. |
Source code in src/cplus_plugin/models/base.py
pw_layers
Returns the list of priority weighting layers defined under
the :py:attr:~priority_layers
attribute.
Returns:
Type | Description |
---|---|
list
|
Priority layers for the implementation or an empty list if the path is not defined. |
Source code in src/cplus_plugin/models/base.py
remove_ncs_pathway
Removes the NCS pathway with a matching UUID from the collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pathway_uuid |
str
|
UUID for the NCS pathway to be removed. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the NCS pathway object was successfully removed, else False if there is no object matching the given UUID. |
Source code in src/cplus_plugin/models/base.py
scenario_fill_symbol
Creates a fill symbol for the activity in the scenario.
Returns:
Type | Description |
---|---|
QgsFillSymbol
|
Fill symbol for the activity in the scenario or None if there was no definition found. |
Source code in src/cplus_plugin/models/base.py
scenario_layer_style_info
Returns the fill symbol properties for styling the activity layer in the final scenario result.
Returns:
Type | Description |
---|---|
dict
|
Fill symbol properties for the activity layer styling in the scenario layer or an empty dictionary if there was no definition found in the root style. |
Source code in src/cplus_plugin/models/base.py
BaseModelComponent
dataclass
Base class for common model item properties.
__eq__
Test equality of object with another BaseModelComponent object using the attributes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
BaseModelComponent
|
BaseModelComponent object to compare with this object. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the all the attribute values match, else False. |
Source code in src/cplus_plugin/models/base.py
LayerModelComponent
dataclass
LayerModelComponent(uuid, name, description, path='', layer_type=LayerType.UNDEFINED, user_defined=False)
Bases: BaseModelComponent
Base class for model components that support a map layer.
layer_uuid
property
Return Layer UUID for default layer.
Default layer's path will start with 'cplus://'.
Returns:
Type | Description |
---|---|
str
|
Server Layer UUID |
__eq__
Uses BaseModelComponent equality test rather than what the dataclass default implementation will provide.
Source code in src/cplus_plugin/models/base.py
__post_init__
is_default_layer
Check if layer is a default layer
Returns:
Type | Description |
---|---|
bool
|
True if layer comes from server API |
is_valid
Checks if the corresponding map layer is valid.
Returns:
Type | Description |
---|---|
bool
|
True if the map layer is valid, else False if map layer is invalid or of None type. |
Source code in src/cplus_plugin/models/base.py
to_map_layer
Constructs a map layer from the specified path.
It will first check if the layer property has been set else try to construct the layer from the path else return None.
Returns:
Type | Description |
---|---|
QgsMapLayer
|
Map layer corresponding to the set layer property or specified path. |
Source code in src/cplus_plugin/models/base.py
update_layer_type
Update the layer type if either the layer or path properties have been set.
Source code in src/cplus_plugin/models/base.py
LayerType
ModelComponentType
Bases: Enum
Type of model component i.e. NCS pathway or activity.
from_string
staticmethod
Creates an enum from the corresponding string equivalent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
str_enum |
str
|
String representing the model component type. |
required |
Returns:
Type | Description |
---|---|
ModelComponentType
|
Component type enum corresponding to the given string else unknown if not found. |
Source code in src/cplus_plugin/models/base.py
NcsPathway
dataclass
NcsPathway(uuid, name, description, path='', layer_type=LayerType.UNDEFINED, user_defined=False, carbon_paths=list())
Bases: LayerModelComponent
Contains information about an NCS pathway layer.
__eq__
Test equality of NcsPathway object with another NcsPathway object using the attributes.
Excludes testing the map layer for equality.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
NcsPathway
|
NcsPathway object to compare with this object. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if all the attribute values match, else False. |
Source code in src/cplus_plugin/models/base.py
add_carbon_path
Add a carbon layer path.
Checks if the path has already been defined or if it exists in the file system.
Returns:
Type | Description |
---|---|
bool
|
True if the carbon layer path was successfully added, else False if the path has already been defined or does not exist in the file system. |
Source code in src/cplus_plugin/models/base.py
carbon_layers
Returns the list of carbon layers whose path is defined under
the :py:attr:~carbon_paths
attribute.
The caller should check the validity of the layers or use
:py:meth:~is_carbon_valid
function.
Returns:
Type | Description |
---|---|
list
|
Carbon layers for the NCS pathway or an empty list if the path is not defined. |
Source code in src/cplus_plugin/models/base.py
is_carbon_valid
Checks if the carbon layers are valid.
Returns:
Type | Description |
---|---|
bool
|
True if all carbon layers are valid, else False if even one is invalid. If there are no carbon layers defined, it will always return True. |
Source code in src/cplus_plugin/models/base.py
is_valid
Additional check to include validity of carbon layers.
Source code in src/cplus_plugin/models/base.py
PRIORITY_GROUP
PriorityLayer
dataclass
PriorityLayer(uuid, name, description, groups, selected=False, path='', type=PriorityLayerType.DEFAULT)
Bases: BaseModelComponent
Base class for model components storing priority weighting layers.
layer_uuid
property
Return Layer UUID for default layer.
Default layer's path will start with 'cplus://'.
Returns:
Type | Description |
---|---|
str
|
Server Layer UUID |
__eq__
Uses BaseModelComponent equality test rather than what the dataclass default implementation will provide.
Source code in src/cplus_plugin/models/base.py
is_default_layer
Check if layer is a default layer
Returns:
Type | Description |
---|---|
bool
|
True if layer comes from server API |
PriorityLayerType
Scenario
dataclass
ScenarioResult
dataclass
ScenarioResult(scenario, created_date=datetime.datetime.now(), analysis_output=None, output_layer_name='', scenario_directory='')
Scenario result details.