Carbon Calculation Utilities¶
Contains functions for carbon calculations.
BasePathwaysCarbonCalculator ¶
Base class for carbon calculators for NCS pathways.
This class encapsulates the common logic for preparing the NCS pathways.
Source code in src/cplus_plugin/lib/carbon.py
activity
property
¶
Gets the activity used to calculate carbon values.
Returns:
| Type | Description |
|---|---|
Activity
|
The activity for calculating carbon values. |
calculation_type
property
¶
Returns the type of calculation being performed. Should be overridden by subclasses.
Returns:
| Type | Description |
|---|---|
str
|
The calculation type name. |
pathway_type
property
¶
Returns the NCS pathway type used in the carbon calculation. Needs to be overridden in subclasses.
Returns:
| Type | Description |
|---|---|
|
NCS pathway type to be applied in the calculation. |
get_pathways ¶
Returns NCS pathways based on the type defined in subclass implementations.
Returns:
| Type | Description |
|---|---|
List[NcsPathway]
|
NCS pathways of the type defined in the subclass. If the type of the NCS pathway in the activity is not defined, then it will be excluded from the list. |
Source code in src/cplus_plugin/lib/carbon.py
run ¶
Calculates carbon value for the referenced activity.
Subclasses need to implement this function.
Returns:
| Type | Description |
|---|---|
float
|
The total carbon value. |
Source code in src/cplus_plugin/lib/carbon.py
BaseProtectPathwaysCarbonCalculator ¶
Bases: BasePathwaysCarbonCalculator
Base class for carbon calculators that process protect pathways.
This class encapsulates the common logic for preparing and processing protect NCS pathways before calculating carbon values.
Source code in src/cplus_plugin/lib/carbon.py
pathway_type
property
¶
Returns the NCS protect pathway type used in the carbon calculation.
Returns:
| Type | Description |
|---|---|
|
NCS protect pathway type applied in the calculation. |
run ¶
Calculates the total carbon value for the referenced activity.
Returns:
| Type | Description |
|---|---|
float
|
The total carbon value. If there are no protect NCS pathways, returns 0.0. If errors occur, returns -1.0. |
Source code in src/cplus_plugin/lib/carbon.py
CarbonImpactManageCalculator ¶
Bases: CarbonImpactPathwayCalculator
Class for carbon impact calculation for manage NCS pathways.
Source code in src/cplus_plugin/lib/carbon.py
pathway_type
property
¶
Returns the NCS manage pathway type used in the carbon calculation.
Returns:
| Type | Description |
|---|---|
|
NCS manage pathway type applied in the calculation. |
CarbonImpactPathwayCalculator ¶
Bases: BasePathwaysCarbonCalculator
Generic calculator for NCS pathway area-based carbon impact calculations.
Subclasses only need to override pathway_type and calculation_type.
Source code in src/cplus_plugin/lib/carbon.py
run ¶
Calculates the carbon impact for the configured pathway_type.
Returns:
| Type | Description |
|---|---|
float
|
The total carbon impact value. If there are no matching pathways, returns 0.0. If errors occur, returns -1.0. |
Source code in src/cplus_plugin/lib/carbon.py
CarbonImpactProtectCalculator ¶
Bases: BaseProtectPathwaysCarbonCalculator
Calculates the carbon impact of protect NCS pathways in an activity using the biomass reference layer.
It specifically searches for protect pathways in the activity. If there are no protect pathways is found, it will return 0. This is designed to be called within a QgsExpressionFunction.
Source code in src/cplus_plugin/lib/carbon.py
CarbonImpactRestoreCalculator ¶
Bases: CarbonImpactPathwayCalculator
Class for carbon impact calculation for restore NCS pathways.
This class differs from CarbonImpactManageCalculator only in the pathway_type it returns (NcsPathwayType.RESTORE), reusing the generic pathway calculation logic provided by CarbonImpactPathwayCalculator.
Source code in src/cplus_plugin/lib/carbon.py
pathway_type
property
¶
Returns the NCS restore pathway type used in the carbon calculation.
Returns:
| Type | Description |
|---|---|
|
NCS restore pathway type applied in the calculation. |
IrrecoverableCarbonCalculator ¶
Bases: BaseProtectPathwaysCarbonCalculator
Calculates the total irrecoverable carbon of an activity using the mean-based reference carbon layer.
It specifically searches for protect pathways in the activity. If there are no protect pathways is found, it will return 0. This is designed to be called within a QgsExpressionFunction.
Source code in src/cplus_plugin/lib/carbon.py
NcsPathwayCarbonInfo
dataclass
¶
Container for NcsPathway layer and corresponding carbon impact value.
calculate_activity_naturebase_carbon_impact ¶
Calculates the carbon mitigation impact of an activity from Naturbase pathway.
It sums the carbon mitigation values across each NCS Naturebase pathway that constitutes the activity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
activity |
Activity
|
The specific activity. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Returns the total carbon impact of the activity, or -1.0 if the activity does not exist or lacks Naturebase pathways. |
Source code in src/cplus_plugin/lib/carbon.py
calculate_irrecoverable_carbon_from_mean ¶
Calculates the total irrecoverable carbon in tonnes for protect NCS pathways using the reference layer defined in settings that is based on the mean value per hectare.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ncs_pathways_layer |
QgsRasterLayer
|
Layer containing an aggregate of protect NCS pathways. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The total irrecoverable carbon for protect NCS pathways. If there are any errors, returns -1.0. If no pathways found, returns 0.0. |
Source code in src/cplus_plugin/lib/carbon.py
calculate_pathway_carbon_by_area ¶
Calculates the carbon impact in tonnes for NCS pathways by multiplying the area of the NCS pathway layers with the user-defined carbon impact rate for the specific NCS pathway.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ncs_pathways_carbon_info |
List[NcsPathwayCarbonInfo]
|
Container for pathway rasters and their corresponding carbon impact values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The total carbon impact for NCS pathways. If no pathways found, returns 0.0. |
Source code in src/cplus_plugin/lib/carbon.py
calculate_stored_carbon ¶
Calculates the total stored carbon in tonnes for protect NCS pathways by summing pixel values from the biomass reference layer defined in settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ncs_pathways_layer |
QgsRasterLayer
|
Layer containing an aggregate of protect NCS pathways. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The total stored carbon for protect NCS pathways. If there are any errors, returns -1.0. If no pathways found, returns 0.0. |