# 
# RiskScape™ Copyright New Zealand Institute for Earth Science Limited
# (Earth Sciences New Zealand) is distributed for research purposes only
# under the terms of AGPLv3.
# 
# RiskScape™ Copyright 2025 New Zealand Institute for Earth Science
# Limited (Earth Sciences New Zealand). All rights reserved. Source code
# available under the AGPLv3.
# 
# This program is free software: you can redistribute it and/or modify it under
#  the terms of the GNU Affero General Public License as published by the Free
#  Software Foundation, either version 3 of the License, or (at your option) any
#  later version.
# 
# This program is distributed for RESEARCH PURPOSES ONLY, in the hope that it will
# be useful for research and education initiatives.
# 
# If you are not a researcher, or you are a researcher who wishes to use this
# program on terms other than AGPLv3 (including those who wish to restrict the
# distribution of any source code created using this program), please contact:
# https://riskscape.org.nz
# 
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Affero General Public License for more details.  You should have received a copy
# of the GNU Affero General Public License along with this program.  If not, see
# <http://www.gnu.org/licenses/>.
# 
# By way of summary only, under the AGPLv3:
#     • Permissions of this strongest copyleft license are conditioned
#       on making available complete source code of licensed works and
#       modifications, which include larger works using a licensed work,
#       under the same license.
#     • Copyright and license notices must be preserved.
#     • Contributors provide an express grant of patent rights.
#     • When a modified version is used to provide a service over a
#       network, the complete source code of the modified version must be made
#       available.
# 
[project]
import = wizard-project.ini

# these parameters customize Platform UI widgets, e.g. description is the help text
[parameter exposure]
properties = bookmark, type: Building
description = Select a vector layer containing buildings that may be exposed to the hazard. \
    This data must contain attributes for 'Cons_Frame' (text) and 'Use_Cat' (text). \
    The values for the 'Cons_Frame' attribute should be one of: \
    Masonry, Steel, Reinforced Concrete, or Timber (the default, for unknown/unrecognized values).
choices = "Building outlines SE Upolu": 'Buildings_SE_Upolu.gpkg'

[parameter hazard]
properties = bookmark
description = Select a raster layer that contains the hazard information, i.e. inundation depth.
choices = "2009 SPT 10m grid": 'MaxEnv_All_Scenarios_10m.tif'
choices = "2009 SPT 50m grid": 'MaxEnv_All_Scenarios_50m.tif'

[parameter region]
properties = bookmark, type: Region
description = Select a vector layer containing the regional boundaries of interest. \
    These regional areas will be used to aggregate and report the model results
choices = "Samoa constituencies": 'Samoa_constituencies.gpkg'

[model Total-exposed]
description = Determines how many buildings are exposed to inundation. \
    Results can be broken down by region, use category, etc
framework = pipeline
location = regional-exposure-pipeline.txt
param.exposure_layer = 'Buildings_SE_Upolu.gpkg'
param.exposure_layer.template = exposure
param.use_types = ['']
param.use_types.label = Use category
param.use_types.choices = "All Buildings": ''
param.use_types.choices = "Residential": 'Residential'
param.use_types.choices = "Commercial": 'Commercial'
param.use_types.choices = "Community": 'Community'
param.use_types.choices = "Education": 'Education'
param.use_types.choices = "Fale": 'Fale'
param.use_types.choices = "Hotel": 'Hotel'
param.use_types.choices = "Industrial": 'Industrial'
param.use_types.choices = "Outbuilding": 'Outbuilding'
param.use_types.choices = "Religious": 'Religious'
param.use_types.description = Select the buildings to include in the model by use category. \
    You can select multiple use categories. \
    Any buildings that do not fall into one of the specified use categories will be excluded from the model.
param.hazard_layer = 'MaxEnv_All_Scenarios_10m.tif'
param.hazard_layer.template = hazard
param.min_depth = 0.0
param.min_depth.label = Min depth (m)
param.min_depth.description = \
    The minimum depth that must be exceeded before a building will be considered 'exposed' to the tsunami.
param.area_layer = 'Samoa_constituencies.gpkg'
param.area_layer.template = region
param.aggregate_by = area.Region
param.aggregate_by.label = Aggregate results by
param.aggregate_by.choices = "Region": area.Region
param.aggregate_by.choices = "Construction type": exposure.Cons_Frame
param.aggregate_by.choices = "Use Category": exposure.Use_Cat
param.aggregate_by.choices = "Nationally": 'Total'
param.aggregate_by.description = This changes how results are aggregated for the 'summary' results file. \
    By default, the results are reported with a breakdown by region. \
    Selecting 'Nationally' will instead give a single total value for all of Samoa. \
    Selecting 'Use Category' or 'Construction type' will give a breakdown based on the building's details
param.depths = [1, 2, 3]
param.depths.label = Bands for reporting inundation depth (m)
param.depths.description = This controls the 'Depth' breakdown in the 'summary' results file. \
    This gives you an indication of the different inundation depths that buildings were exposed to.

[model Building-damage]
description = Determines a damage state for buildings based on inundation
framework = pipeline
location = building-damage-pipeline.txt
param.exposure_layer = 'Buildings_SE_Upolu.gpkg'
param.exposure_layer.template = exposure
param.hazard_layer = 'MaxEnv_All_Scenarios_10m.tif'
param.hazard_layer.template = hazard
param.area_layer = 'Samoa_constituencies.gpkg'
param.area_layer.template = region

[type Building]
type.Cons_Frame = text
type.Use_Cat = text
type.the_geom = geometry

[type Region]
type.Region = text
type.the_geom = geometry

[type damage_states]
type.DS_1 = floating
type.DS_2 = floating
type.DS_3 = floating
type.DS_4 = floating
type.DS_5 = floating

[function Samoa_Building_Fragility]
description = Samoa tsunami fragility functions for buildings
location = functions/Samoa_Building_Fragility.py
argument-types = [building: struct(Cons_Frame: text), hazard: nullable(floating)]
return-type = damage_states
framework = cpython

[function Building_Damage_State]
description = Randomly assigns a damage state to a building based on the Samoa_Building_Fragility logic
location = functions/Building_Damage_State.py
argument-types = [building: struct(Cons_Frame: text), hazard: nullable(floating)]
return-type = text
framework = cpython

[model Geoprocessing-Exposed-Road-km]
description = Cuts the roads into 10m segments in order to determine the total exposed km of roads
framework = pipeline
location = exposed-road-km-pipeline.txt
param.input_exposures_layer = Roads SE Upolu (exposure-layer)
param.input_exposures_layer.properties = bookmark
param.input_exposures_cut_distance = 50
param.input_exposures_cut_distance.properties = min: 5
param.input_exposures_filter_expression = ''
param.input_exposures_filter_expression.choices = "All roads": ''
param.input_exposures_filter_expression.choices = "Primary roads": 'primary'
param.input_exposures_filter_expression.choices = "Residential roads": 'residential'
param.input_hazards_layer = SPT inundation 50m grid (hazard-layer)
param.input_hazards_layer.properties = bookmark
param.input_hazards_layer.choices = 'SPT inundation 50m grid (hazard-layer)'
param.input_hazards_layer.choices = 'SPT inundation 10m grid (hazard-layer)'
param.input_area_layer = Samoa constituencies (area-layer)
param.input_area_layer.properties = bookmark
param.sample_hazards_buffer = 0
param.sample_areas_buffer = 1000
param.min_depth = 0.01
param.min_depth.label = Min inundation_depth (m)
param.group_results_by = area.Region
param.group_results_by.choices = Region: area.Region
param.group_results_by.choices = "Road type": exposure.Road_type
param.group_results_by.choices = Total: 'Total'


