prioritizr / aoh

Create Area of Habitat Data
https://prioritizr.github.io/aoh
9 stars 1 forks source link

Species AOH data - calculated with gaps #45

Closed suuf closed 1 year ago

suuf commented 1 year ago

Hello!

Apologies if this is the wrong place to be posting!

I am trying to calculate the AOH data for some species via create_spp_aoh_data(), and for some reason 2 species appear with missing data, as shown in Screenshot 1. If I attempt to import the rasters there is also an error, as shown in Screenshot 2.

Screenshot 1: screenshot

Screenshot 2: screenshot2

Also, if I attempt to calculate AOH for only one of the Bufotes species on their own, I get the error "length(x) not greater than 0", as shown in Screenshot 3.

Screenshot 3: screenshot_lengthX

jeffreyhanson commented 1 year ago

Hi @suuf,

Yeah, this is definitely the right place to ask this question!

It looks like aoh is having trouble finding habitat data for some of the species. Since aoh uses the rredlist package to query the IUCN Red List, we can see that asking for the habitat data using the ID doesn't return any data (e.g. for B. boulengeri):

rredlist::rl_habitats(id=153568)

However, if we use the species name directly, then we do get the habitat data:

rredlist::rl_habitats(name="Bufotes boulengeri")

So, this suggests to me that either (1) there's something wrong with the API, or (2) the id_no for some of your species don't work. I do know that the IUCN will sometimes change species' IDs between different versions of the red list (e.g. species X might have ID Y in version 2022-1, but get changed to ID Z in version 2022-2). How does that sound?

To fix this, I would suggest checking that your spatial data is from the latest version of the red list (so that you can be sure the IDs for the species are correct). If that doesn't work, you could try using rredlist::rl_habitats() to manually assemble the habitat data using the species' names, and then use that as an argument for create_spp_info_data() (i.e. the spp_habitat_data parameter). What do you think?

suuf commented 1 year ago

Thanks for the reply @jeffreyhanson 🙂

Downloading the most recent IUCN spatial ranges has given me the most recent species IDs and has fixed the problem (as I am using the latest version of the IUCN API) - thank you!

I cannot believe IUCN is changing some species IDs with each version 🤯 Maybe it'd be best to rely on species scientific names - but at the same time the fact that there's an endpoint within the IUCN API using species IDs would make this very counter intuitive.

jeffreyhanson commented 1 year ago

Awesome - great to hear its all working now!

Yeah, I like the idea of using the species scientific names because that would avoid issues with changing IDs. However, I worry that this might cause issues where two different species (i.e., found in different classes) have the same genus and species name, which would cause incorrect results.