ropensci / rfishbase

R interface to the fishbase.org database
https://docs.ropensci.org/rfishbase
111 stars 40 forks source link

Distribution function: Latitude and Longitude range fields #97

Closed amroco closed 7 years ago

amroco commented 8 years ago

Hi there, I am having trouble getting the Latitude and longitude values for a list of fish species via the distribution function, using the following code:

res <- list()
for (i in seq_along(fish_list)) {
  cat(i, sep = "\n")
  res[[i]] <- distribution(fish_list[i], fields= c("NorthernLatitude", 
                                              "NorthernLatitudeNS", 
                                              "SouthernLatitude", 
                                              "SouthernLatitudeNS"))
}

fish_list_lat = dplyr::bind_rows(res)
Error: 
Error in distribution(fish_list, fields = c("NorthernLatitude", "NorthernLatitudeNS",  : 
  unused argument (fields = c("NorthernLatitude", "NorthernLatitudeNS", "SouthernLatitude", "SouthernLatitudeNS"))

This code works for getting the "DepthRangeShallow" and "DepthRangeDeep" for the same species list using the "Species" function so I'm not sure why it isn't working for me now.

Thanks, A

sckott commented 8 years ago

Thanks very much for your report. we'll have a look

sckott commented 8 years ago

distribution() fxn right now doesn't accept the fields parameter

sckott commented 8 years ago

looks like we can add in fields param to allow it's use - should merge some PRs first though #95 #96

amroco commented 8 years ago

Thanks for getting on to this so quickly : )

sckott commented 8 years ago

@amroco okay, try it again after reinstalling like devtools::install_github("ropensci/rfishbase")

amroco commented 8 years ago

So, for depth, querying the Species function for "DepthRangeShallow" and "DepthRangeDeep" the code still works, however I have begun to get the following error message:

Warning in load_taxa(server = server) : Did not recognize API, assuming it is fishbase

However when I rerun the code for lat and long above, I get this error message:

Warning in load_taxa() : Did not recognize API, assuming it is fishbase Error in named(list(...)) : could not find function "verbose"

Summary: not working, but new error message (I have loaded R.utils package)

Thanks for your help, A

sckott commented 8 years ago

@amroco okay, reinstall again, should fix 2nd error

the first one Did not recognize API, assuming it is fishbase is just a warning i think, and can be ignored I believe.

amroco commented 8 years ago

Working, awesome Thanks : )

sckott commented 8 years ago

great :)

sckott commented 7 years ago

@amroco did you reopen because something is not working?

amroco commented 7 years ago

Hi, something has changed with the latitude and longitude query result using the same code as above, instead of getting the single value for latN or latS such as for Astroscopus sexspinosus: 22°S - 41°S,

This query now returns a list of FAO areas, and those corresponding latitude limits when I query a list of species, so:

 AreaCode, SpecCode,  Status, FAO, NorthernLatitude, NorthernLatitudeNS, SouthernLatitude, SouthernLatitudeNS,
     <int>    <int>   <chr>                    <chr>            <int>              <chr>            <int>              <chr>
1       41    14115 endemic      Atlantic, Southwest                5                  N               60                  S
2       77     8255  native Pacific, Eastern Central               40                  N               25                  S

As a result there may be more than one lat N and lat S for a single species, I was really just hoping to get those single values displayed on the page under the Distribution heading

amroco commented 7 years ago

So it looks like the distribution function is not providing these fields any more: "NorthernLatitude", "NorthernLatitudeNS", "SouthernLatitude", "SouthernLatitudeNS"

Apparently this stuff is in 'countrysubref':

list_fields("NorthernLatitude")
# A tibble: 2 × 2
     table_name        column_name
          <chr>              <chr>
1 countrysubref   NorthernLatitude
2 countrysubref NorthernLatitudeNS

but replacing 'distribution' with 'countrysubref' is not getting me what I am after either.

So something has changed that makes the original code defunct, and I am not sure how to find what that code was getting me. Also, is there the opposite of list_fields, so instead of finding the table a field is in I can find the fields in a table? This might help if the field name has changed and now calling NorthernLatitude does not give the single, northernmost latitude of that species visible under the Distribution heading on the Summary page. Thanks, so much.

sckott commented 7 years ago

Also, is there the opposite of list_fields, so instead of finding the table a field is in I can find the fields in a table?

you can just use list_fields() without passing in anything, I think

sckott commented 7 years ago

@amroco what version of rfishbase are you using? the below e.g,. works the same with current CRAN version of dev version on github:

distribution("Astroscopus sexspinosus", fields= c("NorthernLatitude", 
     "NorthernLatitudeNS", 
     "SouthernLatitude", 
     "SouthernLatitudeNS"))
#> # A tibble: 1 × 8
#>   AreaCode SpecCode  Status                 FAO NorthernLatitude NorthernLatitudeNS SouthernLatitude SouthernLatitudeNS
#>      <int>    <int>   <chr>               <chr>            <int>              <chr>            <int>              <chr>
#> 1       41    14115 endemic Atlantic, Southwest                5                  N               60                  S

is that not what you want? countrysubref() is another option e.g,

countrysubref("Astroscopus sexspinosus", fields = c('CountrySub', 'NorthernLatitude', 'NorthernLatitudeNS', 'SouthernLatitude', 'SouthernLatitudeNS'))
#> # A tibble: 200 × 6
#>    CSub_Code                   CountrySub NorthernLatitude NorthernLatitudeNS SouthernLatitude
#>        <lgl>                        <chr>            <int>              <chr>            <int>
#> 1         NA Australian Capital Territory               35                  S               36
#> 2         NA              New South Wales               28                  S               37
#> 3         NA           Northern Territory               11                  S               26
#> 4         NA                   Queensland                9                  S               29
#> 5         NA              South Australia               26                  S               38
#> 6         NA                     Tasmania               39                  S               44
#> 7         NA                     Victoria               34                  S               39
#> 8         NA            Western Australia               13                  S               35
#> 9         NA                         Acre               NA               <NA>               NA
#> 10        NA                      Alagoas               NA               <NA>               NA
#> # ... with 190 more rows, and 1 more variables: SouthernLatitudeNS <chr>
amroco commented 7 years ago

Ok, this is where I installed from (as per the tutorial), and using distribution (what you have is what I am after), I am still getting: `

fish_list_lat = dplyr::bind_rows(res) head(fish_list_lat) A tibble: 6 × 8 AreaCode SpecCode Status FAO NorthernLatitude NorthernLatitudeNS SouthernLatitude SouthernLatitudeNS

1 41 14115 endemic Atlantic, Southwest 5 N 60 S 2 77 8255 native Pacific, Eastern Central 40 N 25 S 3 87 8255 native Pacific, Southeast 5 N 60 S 4 47 8068 native Atlantic, Southeast 6 S 50 S 5 51 8068 native Indian Ocean, Western 30 N 45 S `

After deleting rfishbase from my files, I have also tried installing the package using: devtools::install_github("ropensci/rfishbase", force = TRUE)

Then deleting it and installing from the tools tab.

Same result :/. Definitely at my end, but I am not sure how to solve my version.

sckott commented 7 years ago

hmm, so we are getting the same thing then yes?

amroco commented 7 years ago

yeah, the same thing : (

sckott commented 7 years ago

I am not sure how to solve my version.

does this mean something is wrong?

amroco commented 7 years ago

Aw man. I see what is going on here. The latitudinal limits I want are not under the distribution tab on the FishBase page, but under Environment/Climate/Range. Even though the code above did work for me some months ago. Anyway for Astroscopus sexspinosus, the latitude limits are 22°S - 41°S.

So I need to find how to access the Environment/Climate/Range table. Or looking for something which looks like it can get me this information.

Using list_fields() empty gets me:

> list_fields() Error in list_fields() : argument "fields" is missing, with no default

sckott commented 7 years ago

right, that lat long info is in Env... we have little insight into how the database tables map to what's on the fishbase pages, so it's hard to say how we can get at that info. will have a look


for list fields, try out

library(jsonlite)
fromJSON('https://fishbase.ropensci.org/listfields')

then parse from there to get what you need

sckott commented 7 years ago

@cboettig do you happen to know where the data in this bit

screen shot 2016-12-08 at 1 05 25 pm

of this page http://www.fishbase.org/summary/Astroscopus-sexspinosus.html

can be found in our API

cboettig commented 7 years ago

@amroco @sckott Looks like it is from the Stocks Table, try:

rfishbase::stocks("Astroscopus sexspinosus") %>% select(Northernmost, NorthSouthN, Southermost, NorthSouthS, Easternmost, WestEastE, Westernmost, WestEastW)

Luckily in this example there is only one stock. For some species there may be multiple stocks occurring in multiple geographically distinct regions, so it's not really clear what a single lat-long bounding box would mean in such case anyhow.

The atrociously inconsistent naming of latitude variables makes it hard to find these things with list_fields(). For instance, there's also lat-long ranges in ecosystem table too (though these cover the whole ecosystem named, which is clearly not what you want), and these use an entirely different naming convention for the bounds:

 rfishbase::ecosystem("Astroscopus sexspinosus") %>% select(sciname, Stockcode, NorthernLat, NrangeNS, SouthernLat, SrangeNS, EasternLat, ErangeEW, WesternLat, WrangeEW)
amroco commented 7 years ago

Thank you so much for your help guys! Where there are multiple stocks I can filter the extremes and end up with what we need for the model, so this works.

sckott commented 7 years ago

great!