palaeoverse / rphylopic

Get Silhouettes of Organisms from PhyloPic
https://rphylopic.palaeoverse.org
GNU General Public License v3.0
90 stars 9 forks source link

libpng errors #22

Closed mcsiple closed 5 years ago

mcsiple commented 5 years ago

Hi! I am looking for a couple images to include in ggplot2 plots, and am getting libpng errors when I call image_data(). I'm guessing these are just listed image files that aren't available in PNG format but it would be cool to know (via error message, perhaps?) what to do next. Here is an example:

library(rphylopic)
harborseal <- name_search(text = "Phoca vitulina", options = "namebankID")[[1]] 
id <- harborseal$uid[1]
img <- image_data(id, size = "64")[[1]]

The error returned by the final line is this: Error in png::readPNG(res$content) : libpng error: Not a PNG file

Two questions: 1) If uids without PNG files are included in search results from name_search(), is there a way to flag the ones that don't have PNG files available? and 2) If this is an error on my part, can you help me figure out how to find ones that have png files?

As a side note, it would also be cool to have a display option, like RColorBrewer::display.brewer.pal() but for the set of images available for a taxon. If you don't have this already, I would be happy to contribute this code once I understand the package a little better...

Session Info ```r - Session info --------------------------------------------------------------------------------------------------------- R version 3.6.1 (2019-07-05) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS Mojave 10.14.6 Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib Random number generation: RNG: Mersenne-Twister Normal: Inversion Sample: Rounding locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] rphylopic_0.2.0 scales_1.0.0 gridExtra_2.3 RColorBrewer_1.1-2 RCurl_1.95-4.12 [6] bitops_1.0-6 beyonce_0.1 mvcwt_1.3.1 biwavelet_0.20.17 DescTools_0.99.28 [11] fractal_2.0-4 ifultools_2.0-5 splus2R_1.2-2 taxize_0.9.8 forcats_0.4.0 [16] stringr_1.4.0 dplyr_0.8.3 purrr_0.3.2 readr_1.3.1 tidyr_0.8.3 [21] tibble_2.1.3 ggplot2_3.2.0 tidyverse_1.2.1 reshape2_1.4.3 loaded via a namespace (and not attached): [1] httr_1.4.0 maps_3.3.0 jsonlite_1.6 foreach_1.4.4 bold_0.9.0 [6] here_0.1 dotCall64_1.0-0 modelr_0.1.4 assertthat_0.2.1 expm_0.999-4 [11] cellranger_1.1.0 yaml_2.2.0 pillar_1.4.2 backports_1.1.4 lattice_0.20-38 [16] glue_1.3.1 digest_0.6.20 sapa_2.0-2 rvest_0.3.4 colorspace_1.4-1 [21] Matrix_1.2-17 plyr_1.8.4 pkgconfig_2.0.2 httpcode_0.2.0 broom_0.5.2 [26] haven_2.1.1 mvtnorm_1.0-11 manipulate_1.0.1 generics_0.0.2 withr_2.1.2 [31] lazyeval_0.2.2 cli_1.1.0 magrittr_1.5 crayon_1.3.4 readxl_1.3.1 [36] nlme_3.1-140 MASS_7.3-51.4 xml2_1.2.0 foreign_0.8-71 tools_3.6.1 [41] data.table_1.12.2 hms_0.5.0 gridBase_0.4-7 munsell_0.5.0 wmtsa_2.0-3 [46] compiler_3.6.1 rlang_0.4.0 grid_3.6.1 iterators_1.0.10 rstudioapi_0.10 [51] spam_2.2-2 labeling_0.3 boot_1.3-22 gtable_0.3.0 codetools_0.2-16 [56] reshape_0.8.8 curl_3.3 R6_2.4.0 zoo_1.8-6 lubridate_1.7.4 [61] zeallot_0.1.0 rprojroot_1.3-2 ape_5.3 stringi_1.4.3 parallel_3.6.1 [66] crul_0.8.4 Rcpp_1.0.1 png_0.1-7 fields_9.8-3 vctrs_0.2.0 [71] scatterplot3d_0.3-41 tidyselect_0.2.5 ```
sckott commented 5 years ago

thanks @mcsiple ! Can you redo your session info after loading rphylopic?

sckott commented 5 years ago

As a side note ...

can you open a new issue for this? seems different enough, and i need a bit more explanation for me to understand

sckott commented 5 years ago

there is a new API for phylopic #23 - so things may change soon...

Having said that, based on current setup ... i think you want the following workflow:

# a name UID, e.g., from name_search() call
id <- "f3254fbd-284f-46c1-ae0f-685549a6a373" 
# then use name_images(): you want an id in the "same" slot
z <- name_images(uuid = id) 
# then use image_data with the resulting uid
png <- image_data(z$same[[1]]$uid, size = "64")

However, with your taxon of interest, there seems to be no images:

harborseal <- name_search(text = "Phoca vitulina", options = "namebankID", verbose = TRUE)[[1]]
res <- lapply(harborseal$uid, name_images)
lapply(res, "[[", "same")
mcsiple commented 5 years ago

Thank you @sckott ! That is indeed the code I wanted. And I edited the session info.

Essentially I was looking for a way to quickly check whether any of the names in harborseal were tied to images. I will copy-paste the issue above as a new issue (although I consider more a "potential new frill" than a problem with the package in its current form).

sckott commented 5 years ago

(turns out the new API is not ready yet, maybe in a few months or so; for now we'll work with the current API)

glad that code works!