diff --git a/aoh-calculator b/aoh-calculator index 637c6f9..d56e12f 160000 --- a/aoh-calculator +++ b/aoh-calculator @@ -1 +1 @@ -Subproject commit 637c6f9e5d48710052123316ee0a818a526c9dc0 +Subproject commit d56e12f85255ad5ea14d1105febecd635c2afcee diff --git a/prepare_species/extract_species_data_psql.py b/prepare_species/extract_species_data_psql.py index 8c86668..a673cd1 100644 --- a/prepare_species/extract_species_data_psql.py +++ b/prepare_species/extract_species_data_psql.py @@ -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 @@ -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) @@ -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() diff --git a/scripts/run.sh b/scripts/run.sh index 9587ebf..6bd7b79 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -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