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
30 changes: 16 additions & 14 deletions utils/aoh_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import argparse
import os
from pathlib import Path

import pandas as pd

Expand All @@ -10,25 +11,24 @@ def aoh_generator(
data_dir: str,
output_csv_path: str
):
taxas = os.listdir(input_dir)
taxa_dirs = Path(input_dir).glob("[!.]*")
data_dir = Path(data_dir)

res = []
for taxa in taxas:
for taxa_dir_path in taxa_dirs:
for scenario in ['current',]:
source = 'historic' if scenario == 'pnv' else 'current'
taxa_path = os.path.join(input_dir, taxa, source)
speciess = os.listdir(taxa_path)
for species in speciess:
if not species.endswith("geojson"):
continue
taxa_path = taxa_dir_path / source
species_paths = taxa_path.glob("*.geojson")
for species_path in species_paths:
res.append([
os.path.join(os.path.join(data_dir, "habitat_layers"), scenario),
os.path.join(data_dir, "elevation", "elevation-max-1k.tif"),
os.path.join(data_dir, "elevation", "elevation-min-1k.tif"),
os.path.join(data_dir, "crosswalk.csv"),
os.path.join(os.path.join(data_dir, "species-info/"), taxa, source, species),
os.path.join(os.path.join(data_dir, "masks", "terrestrial_mask.tif")),
os.path.join(os.path.join(data_dir, "aohs/"), scenario, taxa)
data_dir / "habitat_layers" / scenario,
data_dir / "elevation" / "elevation-max-1k.tif",
data_dir / "elevation" / "elevation-min-1k.tif",
data_dir / "crosswalk.csv",
species_path,
data_dir / "masks" / "terrestrial_mask.tif",
data_dir / "aohs" / scenario / taxa_dir_path.name,
])

df = pd.DataFrame(res, columns=[
Expand All @@ -40,6 +40,8 @@ def aoh_generator(
'--area',
'--output'
])
output_dir, _ = os.path.split(output_csv_path)
os.makedirs(output_dir, exist_ok=True)
df.to_csv(output_csv_path, index=False)


Expand Down
24 changes: 14 additions & 10 deletions utils/threats_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import argparse
import os
from pathlib import Path

import pandas as pd

Expand All @@ -10,29 +11,32 @@ def threats_generator(
data_dir: str,
output_csv_path: str
):
taxas = os.listdir(input_dir)
taxa_dirs = Path(input_dir).glob("[!.]*")
data_dir = Path(data_dir)

res = []
for taxa in taxas:
for taxa_dir_path in taxa_dirs:
for scenario in ['current',]:
source = 'historic' if scenario == 'pnv' else 'current'
taxa_path = os.path.join(input_dir, taxa, source)
species_infos = os.listdir(taxa_path)
for species_info_path in species_infos:
taxon_id, _ = os.path.splitext(species_info_path)
aoh_path = os.path.join(data_dir, "aohs", source, taxa, f"{taxon_id}_all.tif")
if os.path.exists(aoh_path):
taxa_path = taxa_dir_path / source
species_paths = taxa_path.glob("*.geojson")
for species_path in species_paths:
taxon_id = species_path.stem
aoh_path = data_dir / "aohs" / source / taxa_dir_path.name / f"{taxon_id}_all.tif"
if aoh_path.exists():
res.append([
os.path.join(data_dir, "species-info", taxa, source, species_info_path),
species_path,
aoh_path,
os.path.join(data_dir, "threat_rasters", taxa)
data_dir / "threat_rasters" / taxa_dir_path.name,
])

df = pd.DataFrame(res, columns=[
'--speciesdata',
'--aoh',
'--output'
])
output_dir, _ = os.path.split(output_csv_path)
os.makedirs(output_dir, exist_ok=True)
df.to_csv(output_csv_path, index=False)

def main() -> None:
Expand Down