apcac.indexes#

{Short module description (1-3 sentences)} todo docstring

Features#

todo docstring

  • {feature 1}

  • {feature 2}

  • {feature 3}

  • {etc}

Overview#

todo docstring {Overview description}

Examples#

todo docstring {Examples in rST}

Print a message

# print message
print("Hello world!")
# [Output] >> 'Hello world!'

Functions

compute_index_c(input_ppt, input_pet, ...)

compute_index_e(input_slope, input_k, ...)

compute_index_g(input_q, output_folder)

compute_index_n(input_ppt, input_pet, ...)

compute_index_s(input_sandp, input_socp, ...)

compute_index_t(input_hand, input_twi, ...)

compute_index_v(input_n0, input_n1, t0, t1, ...)

fuzzify(input_file, output_file, low, hi)

get_timestamp()

process_data(input1, input2, output_folder)

Demo for processing data

sample_indexes(output_folder, input_db, ...)

Samples mean values from multiple raster files over a vector layer (e.g., catchments) and merges the results into a GeoDataFrame.

waiter()

apcac.indexes.compute_index_e(input_slope, input_k, output_folder)[source]#
apcac.indexes.compute_index_v(input_n0, input_n1, t0, t1, output_folder)[source]#
apcac.indexes.compute_index_n(input_ppt, input_pet, output_folder)[source]#
apcac.indexes.compute_index_c(input_ppt, input_pet, output_folder)[source]#
apcac.indexes.compute_index_g(input_q, output_folder)[source]#
apcac.indexes.compute_index_s(input_sandp, input_socp, output_folder)[source]#
apcac.indexes.compute_index_t(input_hand, input_twi, output_folder, hand_w=0.5, hand_max=15, twi_max=15)[source]#
apcac.indexes.sample_indexes(output_folder, input_db, raster_files, input_layer='apcac_bho5k', raster_multipliers=None)[source]#

Samples mean values from multiple raster files over a vector layer (e.g., catchments) and merges the results into a GeoDataFrame.

Parameters:
  • output_folder (str) – Path to the directory where temporary and final output files will be stored.

  • input_db (str) – Path to the GeoPackage or database file containing the input vector layer.

  • raster_files (dict) – Dictionary where keys are the desired column names (index names) and values are the full paths to the corresponding raster files.

  • input_layer (str) – Name of the vector layer within the input database to use for zonal statistics. Default value = “apcac_bho5k”

  • raster_multipliers (dict) – [optional] Dictionary where keys are the index names (from raster_files) and values are factors by which the sampled mean values should be divided (e.g., to convert units).

Returns:

The file path to the final GeoPackage file containing the input layer with the new sampled index columns.

Return type:

str

Notes

The process uses QGIS’s native zonal statistics algorithm (native:zonalstatisticsfb) to calculate the mean of each raster within the polygons of the input vector layer.

Script example

import importlib.util as iu

# define the paths to this module
# ----------------------------------------
the_module = "path/to/classes.py"

spec = iu.spec_from_file_location("module", the_module)
module = iu.module_from_spec(spec)
spec.loader.exec_module(module)

# define the paths to input and output folders
# ----------------------------------------
input_dir = "path/to/input_folder"
output_dir = "path/to/output_folder"

# define the path to input database
# ----------------------------------------
input_db = f"{input_dir}/path/to/data.gpkg"

# define the paths to input rasters
# ----------------------------------------
raster_files = {
    # change this paths
    "t": f"{input_dir}/path/to/raster_t.tif",
    "s": f"{input_dir}/path/to/raster_s.tif",
    "g": f"{input_dir}/path/to/raster_g.tif",
    "c": f"{input_dir}/path/to/raster_c.tif",
    "n": f"{input_dir}/path/to/raster_n.tif",
    "v": f"{input_dir}/path/to/raster_v.tif",
    "slope": f"{input_dir}/path/to/raster_slope.tif",
    "uslek": f"{input_dir}/path/to/raster_uslek.tif",
}

# define which index has multipliers (the value is divided)
# ----------------------------------------
raster_multipliers = {
    "t": 1000,
    "s": 100,
    "slope": 100,
    # change and add more if needed
}

# call the function
# ----------------------------------------
module.sample_indexes(
    input_db=input_db,
    raster_files=raster_files,
    output_folder=output_dir,
    raster_multipliers=raster_multipliers,
    input_layer="apcac_bho5k",
)
apcac.indexes.process_data(input1, input2, output_folder)[source]#

Demo for processing data

Parameters:
  • input1 (str) – file path to input data 1

  • input2 (str) – file path to input data 1

  • output_folder (str) – file path to output folder

apcac.indexes.fuzzify(input_file, output_file, low, hi)[source]#
apcac.indexes.waiter()[source]#
apcac.indexes.get_timestamp()[source]#