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
2 changes: 1 addition & 1 deletion aoh-calculator
12 changes: 9 additions & 3 deletions prepare_species/extract_species_data_psql.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
LEFT JOIN red_list_category_lookup ON red_list_category_lookup.id = assessments.red_list_category_id
WHERE
assessments.latest = true
AND assessments.sis_taxon_id NOT IN %s
AND assessment_scopes.scope_lookup_id = 15 -- global assessments only
AND taxons.class_name = %s
AND taxons.infra_type is NULL -- no subspecies
Expand Down Expand Up @@ -435,7 +434,7 @@ def extract_data_per_species(
connection = psycopg2.connect(DB_CONFIG)
cursor = connection.cursor()

excludes = []
excludes = tuple([])
if excludes_path is not None:
try:
df = pd.read_csv(excludes_path)
Expand All @@ -449,7 +448,14 @@ def extract_data_per_species(
for era, presence in [("current", (1, 2))]:
era_output_directory_path = os.path.join(output_directory_path, era)

cursor.execute(MAIN_STATEMENT, (excludes, class_name,))
# You can't do NOT IN on an empty list in SQL
if excludes:
exclude_statement = "AND assessments.sis_taxon_id NOT IN %s"
statement = MAIN_STATEMENT + exclude_statement
cursor.execute(statement, (class_name, excludes))
else:
cursor.execute(MAIN_STATEMENT, (class_name,))

# This can be quite big (tens of thousands), but in modern computer term is quite small
# and I need to make a follow on DB query per result.
results = cursor.fetchall()
Expand Down
2 changes: 1 addition & 1 deletion scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ python3 ./prepare_layers/convert_crosswalk.py --original ${PWD}/data/crosswalk_b
# Get species data per taxa from IUCN data
for TAXA in "${TAXALIST[@]}"
do
python3 ./prepare_species/extract_species_data_psql.py --class ${TAXA} --output ${DATADIR}/species-info/${TAXA}/ --projection "ESRI:54009"
python3 ./prepare_species/extract_species_data_psql.py --class ${TAXA} --output ${DATADIR}/species-info/${TAXA}/ --projection "ESRI:54009" --excludes ${DATADIR}/SpeciesList_generalisedRangePolygons.csv
done

if [ -f data/BL_Species_Elevations_2023.csv ]; then
Expand Down