Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ pandas-stubs
types-requests
yirgacheffe[dev]
aoh[dev]
snakefmt

# This is pinned because it changes so often and is a major
# cause of red-herring CI failures
snakefmt==2.0.3
6 changes: 3 additions & 3 deletions workflow/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ rule life:

rule summaries:
"""
Target: generate species richness and endemism maps.
NOT included in 'all' — run explicitly with: snakemake summaries
"""
Target: generate species richness and endemism maps.
NOT included in 'all' — run explicitly with: snakemake summaries
"""
input:
DATADIR / "summaries" / "species_richness.tif",
DATADIR / "summaries" / "endemism.tif",
Expand Down
40 changes: 20 additions & 20 deletions workflow/rules/aoh.smk
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ from pathlib import Path

rule aoh_version_sentinel:
"""
Track the aoh package version. AOH rules depend on this to trigger
rebuilds when the package updates.
"""
Track the aoh package version. AOH rules depend on this to trigger
rebuilds when the package updates.
"""
output:
sentinel=DATADIR / ".sentinels" / "aoh_version.txt",
run:
Expand Down Expand Up @@ -68,14 +68,14 @@ def aoh_species_inputs(wildcards):

rule generate_aoh:
"""
Generate Area of Habitat raster for a single species in a given scenario.
Generate Area of Habitat raster for a single species in a given scenario.

Parallelizable: run with `snakemake --cores N` to process multiple species
concurrently. Uses --force-habitat and --pixel-area flags (no mask).
Parallelizable: run with `snakemake --cores N` to process multiple species
concurrently. Uses --force-habitat and --pixel-area flags (no mask).

For current/scenario AOHs: uses current/ era species data.
For pnv AOHs: uses historic/ era species data.
"""
For current/scenario AOHs: uses current/ era species data.
For pnv AOHs: uses historic/ era species data.
"""
input:
unpack(aoh_species_inputs),
output:
Expand Down Expand Up @@ -114,12 +114,12 @@ For pnv AOHs: uses historic/ era species data.

rule aggregate_aohs_per_taxa:
"""
Checkpoint that ensures all AOHs for a taxa/scenario are generated.
Creates a sentinel file when complete.
Checkpoint that ensures all AOHs for a taxa/scenario are generated.
Creates a sentinel file when complete.

This is a checkpoint so downstream rules (delta P) can re-evaluate the DAG
after AOHs are created.
"""
This is a checkpoint so downstream rules (delta P) can re-evaluate the DAG
after AOHs are created.
"""
input:
metadata=get_all_aoh_metadata_for_taxa_scenario,
version_sentinel=DATADIR / ".sentinels" / "aoh_version.txt",
Expand All @@ -139,10 +139,10 @@ after AOHs are created.

rule collate_aoh_data:
"""
Collate metadata from all AOH JSON files for a scenario into a single CSV.
Collate metadata from all AOH JSON files for a scenario into a single CSV.

Used by validation (current scenario) and for downstream analysis.
"""
Used by validation (current scenario) and for downstream analysis.
"""
input:
sentinels=lambda wildcards: expand(
str(DATADIR / "aohs" / "{scenario}" / "{taxa}" / ".complete"),
Expand Down Expand Up @@ -173,10 +173,10 @@ Used by validation (current scenario) and for downstream analysis.

rule footprint_of_humanity:
"""
Compute the footprint of humanity metric for a given scenario.
Compute the footprint of humanity metric for a given scenario.

Compares current AOH data against PNV and the scenario CSVs.
"""
Compares current AOH data against PNV and the scenario CSVs.
"""
input:
pnv_csv=DATADIR / "aohs" / "pnv.csv",
scenario_csv=DATADIR / "aohs" / "{scenario}.csv",
Expand Down
30 changes: 15 additions & 15 deletions workflow/rules/delta_p.smk
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ from types import SimpleNamespace

rule calculate_delta_p:
"""
Calculate the change in probability of persistence for a single species
under a given scenario.
Calculate the change in probability of persistence for a single species
under a given scenario.

species_id wildcard is of the form T{taxon_id}A{assessment_id}_{SEASON},
e.g. T22685505A261477056_RESIDENT.
"""
species_id wildcard is of the form T{taxon_id}A{assessment_id}_{SEASON},
e.g. T22685505A261477056_RESIDENT.
"""
input:
current_sentinel=DATADIR / "aohs" / "current" / "{taxa}" / ".complete",
scenario_sentinel=DATADIR / "aohs" / "{scenario}" / "{taxa}" / ".complete",
Expand Down Expand Up @@ -69,9 +69,9 @@ e.g. T22685505A261477056_RESIDENT.

rule raster_sum_per_taxa:
"""
Sum all per-species delta P rasters for a taxa into a single raster.
Implicitly waits for all calculate_delta_p jobs via direct tif dependencies.
"""
Sum all per-species delta P rasters for a taxa into a single raster.
Implicitly waits for all calculate_delta_p jobs via direct tif dependencies.
"""
input:
rasters=get_delta_p_sentinels_for_taxa_scenario,
output:
Expand Down Expand Up @@ -105,9 +105,9 @@ def get_all_delta_p_tifs_for_scenario(wildcards):

rule species_totals:
"""
Count the number of species per taxa used in the delta P calculation.
Used by delta_p_scaled for normalisation.
"""
Count the number of species per taxa used in the delta P calculation.
Used by delta_p_scaled for normalisation.
"""
input:
rasters=get_all_delta_p_tifs_for_scenario,
output:
Expand All @@ -127,11 +127,11 @@ Used by delta_p_scaled for normalisation.

rule delta_p_scaled:
"""
Generate the final scaled delta P map for a scenario.
Generate the final scaled delta P map for a scenario.

Combines per-taxa delta P sums with the habitat difference map and
species totals to produce the final normalised LIFE output.
"""
Combines per-taxa delta P sums with the habitat difference map and
species totals to produce the final normalised LIFE output.
"""
input:
taxa_rasters=expand(
str(DATADIR / "deltap_sum" / "{{scenario}}" / CURVE / "{taxa}.tif"),
Expand Down
66 changes: 33 additions & 33 deletions workflow/rules/habitat.smk
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ from pathlib import Path

rule gaez_download:
"""
Fetch the compressed GAEZ data.
"""
Fetch the compressed GAEZ data.
"""
output:
archive=DATADIR / "food" / "LR.zip",
log:
Expand Down Expand Up @@ -123,9 +123,9 @@ rule hyde_expand_land_usage_raster:

rule modify_hyde_pixel_scale:
"""
Fix the pixel scale value in the HYDE data — the rounding is not precise
enough to align with the GAEZ data.
"""
Fix the pixel scale value in the HYDE data — the rounding is not precise
enough to align with the GAEZ data.
"""
input:
raw_hyde_raster=DATADIR / "food" / "grazing2017AD.asc",
output:
Expand All @@ -139,9 +139,9 @@ enough to align with the GAEZ data.

rule add_hyde_projection_info:
"""
The HYDE data ships without a projection, so add one so that
the rest of the workflow can mix it with projected raster data.
"""
The HYDE data ships without a projection, so add one so that
the rest of the workflow can mix it with projected raster data.
"""
output:
hyde_projection_file=DATADIR / "food" / "modified_grazing2017AD.prj",
params:
Expand All @@ -157,8 +157,8 @@ the rest of the workflow can mix it with projected raster data.
# =============================================================================
rule combine_gaez_hyde:
"""
Combine the GAEZ and Hyde data, adjusting for overflow in cells.
"""
Combine the GAEZ and Hyde data, adjusting for overflow in cells.
"""
input:
hyde_projection_file=DATADIR / "food" / "modified_grazing2017AD.prj",
hyde_raster=DATADIR / "food" / "modified_grazing2017AD.asc",
Expand All @@ -179,10 +179,10 @@ Combine the GAEZ and Hyde data, adjusting for overflow in cells.

rule pnv_100m:
"""
Rescale the PNV map to 100m resolution.
Yirgacheffe can rescale dynamically, but pre-scaling is faster at the cost
of some extra disk space.
"""
Rescale the PNV map to 100m resolution.
Yirgacheffe can rescale dynamically, but pre-scaling is faster at the cost
of some extra disk space.
"""
input:
pnv=DATADIR / "habitat" / "pnv_raw.tif",
output:
Expand Down Expand Up @@ -211,9 +211,9 @@ of some extra disk space.

rule current_raws:
"""
Build the LIFE current map, which is Jung with updates applied
and restricted to L1 to match the PNV map restrictions.
"""
Build the LIFE current map, which is Jung with updates applied
and restricted to L1 to match the PNV map restrictions.
"""
input:
updates_sentinel=DATADIR / "habitat" / ".downloaded_updates",
habitat=DATADIR / "100m" / "jung_l2_raw.tif",
Expand All @@ -230,12 +230,12 @@ and restricted to L1 to match the PNV map restrictions.

rule build_food_map:
"""
Build the food-enhanced current habitat map at 100m resolution by combining
the Jung current map with GAEZ/HYDE crop and pasture fractions.
Build the food-enhanced current habitat map at 100m resolution by combining
the Jung current map with GAEZ/HYDE crop and pasture fractions.

PRECIOUS: Only rebuilds if the sentinel is explicitly deleted.
This is the most expensive step in the pipeline.
"""
PRECIOUS: Only rebuilds if the sentinel is explicitly deleted.
This is the most expensive step in the pipeline.
"""
input:
jung=ancient(DATADIR / "100m" / "jung_current" / ".sentinel"),
pnv=ancient(DATADIR / "100m" / "pnv.tif"),
Expand All @@ -260,11 +260,11 @@ This is the most expensive step in the pipeline.

rule warp_current:
"""
Warp the food-enhanced current map from 100m to the target pixel scale
(5 arc-seconds, ~1.67km at the equator).
Warp the food-enhanced current map from 100m to the target pixel scale
(5 arc-seconds, ~1.67km at the equator).

PRECIOUS: Only rebuilds if the sentinel is explicitly deleted.
"""
PRECIOUS: Only rebuilds if the sentinel is explicitly deleted.
"""
input:
sentinel=ancient(DATADIR / "100m" / "current" / ".sentinel"),
output:
Expand Down Expand Up @@ -305,9 +305,9 @@ PRECIOUS: Only rebuilds if the sentinel is explicitly deleted.

rule land_cover_area:
"""
Compare total land cover area between jung_current and current maps.
Produces a CSV with land cover class as rows and source map as columns.
"""
Compare total land cover area between jung_current and current maps.
Produces a CSV with land cover class as rows and source map as columns.
"""
input:
jung_current_sentinel=DATADIR / "100m" / "jung_current" / ".sentinel",
current_sentinel=DATADIR / "100m" / "current" / ".sentinel",
Expand All @@ -330,11 +330,11 @@ Produces a CSV with land cover class as rows and source map as columns.

rule pnv_processed:
"""
Process the PNV map into per-class fractional rasters at the target pixel scale
using aoh-habitat-process.
Process the PNV map into per-class fractional rasters at the target pixel scale
using aoh-habitat-process.

PRECIOUS: Only rebuilds if the sentinel is explicitly deleted.
"""
PRECIOUS: Only rebuilds if the sentinel is explicitly deleted.
"""
input:
pnv=ancient(DATADIR / "habitat" / "pnv_raw.tif"),
output:
Expand Down
32 changes: 16 additions & 16 deletions workflow/rules/prepare.smk
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ from pathlib import Path

rule convert_crosswalk:
"""
Generate a crosswalk between IUCN Habitat classes and Jung raster pixel values.
"""
Generate a crosswalk between IUCN Habitat classes and Jung raster pixel values.
"""
output:
crosswalk=DATADIR / "crosswalk.csv",
script:
Expand All @@ -33,8 +33,8 @@ Generate a crosswalk between IUCN Habitat classes and Jung raster pixel values.

rule jung_habitat_map:
"""
Fetch the Jung L2 habitat map from Zenodo.
"""
Fetch the Jung L2 habitat map from Zenodo.
"""
output:
habitat=DATADIR / "100m" / "jung_l2_raw.tif",
log:
Expand All @@ -55,8 +55,8 @@ Fetch the Jung L2 habitat map from Zenodo.

rule jung_habitat_updates:
"""
Fetch the Jung habitat map update masks from Zenodo.
"""
Fetch the Jung habitat map update masks from Zenodo.
"""
output:
sentinel=DATADIR / "habitat" / ".downloaded_updates",
log:
Expand Down Expand Up @@ -84,8 +84,8 @@ Fetch the Jung habitat map update masks from Zenodo.

rule jung_pnv_map:
"""
Fetch the Jung PNV map from Zenodo.
"""
Fetch the Jung PNV map from Zenodo.
"""
output:
habitat=DATADIR / "habitat" / "pnv_raw.tif",
log:
Expand All @@ -111,8 +111,8 @@ Fetch the Jung PNV map from Zenodo.

rule download_elevation:
"""
Download raw elevation DEM from Zenodo.
"""
Download raw elevation DEM from Zenodo.
"""
output:
elevation=DATADIR / "elevation.tif",
log:
Expand All @@ -131,9 +131,9 @@ Download raw elevation DEM from Zenodo.

rule elevation_max:
"""
Warp elevation to target projection and scale using max resampling.
Precious: only runs if output doesn't exist.
"""
Warp elevation to target projection and scale using max resampling.
Precious: only runs if output doesn't exist.
"""
input:
elevation=ancient(DATADIR / "elevation.tif"),
output:
Expand All @@ -160,9 +160,9 @@ Precious: only runs if output doesn't exist.

rule elevation_min:
"""
Warp elevation to target projection and scale using min resampling.
Precious: only runs if output doesn't exist.
"""
Warp elevation to target projection and scale using min resampling.
Precious: only runs if output doesn't exist.
"""
input:
elevation=ancient(DATADIR / "elevation.tif"),
output:
Expand Down
Loading
Loading