Skip to content

Commit

Permalink
additional validation for geo_scores_for_taxa endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
pleary committed Sep 19, 2024
1 parent ff1c190 commit 191089b
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/inat_inferrer.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,15 +426,23 @@ def aggregate_results(self, leaf_scores, debug=False,
return all_node_scores

def h3_04_geo_results_for_taxon_and_cell(self, taxon_id, lat, lng):
if lat is None or lng is None:
return None
try:
lat_float = float(lat)
lng_float = float(lng)
except ValueError:
return None

try:
taxon = self.taxonomy.df.loc[taxon_id]
except:
except KeyError:
return None
# print(f"taxon `{taxon_id}` does not exist in the taxonomy")
# raise e
if pd.isna(taxon["leaf_class_id"]):

if pd.isna(taxon["leaf_class_id"]) or pd.isna(taxon["geo_threshold"]):
return None
h3_cell = h3.geo_to_h3(float(lat), float(lng), 4)

h3_cell = h3.geo_to_h3(lat_float, lng_float, 4)
return float(self.geo_elevation_model.eval_one_class_elevation_from_features(
[self.geo_model_features[self.geo_elevation_cell_indices[h3_cell]]],
int(taxon["leaf_class_id"])
Expand Down

0 comments on commit 191089b

Please sign in to comment.