Predicted origins of a group output values

27 views
Skip to first unread message

sarapweaver

unread,
May 23, 2021, 9:51:35 AM5/23/21
to IsoriX
Hi Everyone!
Thanks for adding me to this group. I am a bat ecologist using deuterium to predict origins of bats killed at wind turbines in the U.S. I have calibrated the model with known bat samples and was able to predict origins for a large group (n=246). Now I'd like to view the spatial data associated with each individual bat and want to know if there is a way to output the entire group to a spreadsheet such as with the writexl package? My goal is to explore the maximum and minimum predicted latitudes and longitudes. Thanks!

Sara

Alexandre Courtiol

unread,
May 23, 2021, 12:59:08 PM5/23/21
to iso...@googlegroups.com
Hi Sara,
just to clarify, you want to extract the ranges of the non excluded areas (i.e. p-value of assignment > 0.05) for each sample to assign, is this correct?


--
You received this message because you are subscribed to the Google Groups "IsoriX" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isorix+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/isorix/510cab60-a752-4954-ab31-078a5a4baf59n%40googlegroups.com.


--

sarapweaver

unread,
May 23, 2021, 1:03:00 PM5/23/21
to IsoriX
Yes, this is correct!

Alexandre Courtiol

unread,
May 23, 2021, 4:26:46 PM5/23/21
to iso...@googlegroups.com, Sara Weaver
Re Sara, 

To extract all the ranges of assignment I think you can do as follows.
I have built the code around the example present in the documentation of IsoriX (?isofind) and I used the package raster to manipulate the data produced by isofind().
We could also use the package sf, but I wanted to keep it simple and short.

library(IsoriX)

## Same as example from ?isofind

GNIPDataDEagg <- prepsources(data = GNIPDataDE)

GermanFit <- isofit(data = GNIPDataDEagg,
                    mean_model_fix = list(elev = TRUE, lat_abs = TRUE))

GermanScape <- isoscape(raster = ElevRasterDE,
                        isofit = GermanFit)

CalibAlien <- calibfit(data = CalibDataAlien,
                       isofit = GermanFit)

AssignmentDry <- isofind(data = AssignDataAlien,
                         isoscape = GermanScape,
                         calibfit = CalibAlien)

## Custom code for extracting the range for each assigned Aliens (or Bats :-)

library(raster)

results <- data.frame(Bat = names(AssignmentDry$sample$pv), long_min = NA, long_max = NA, lat_min = NA, lat_max = NA)

get_range <- function(rasterBrick, layer_n) {
  coord <- apply(coordinates(rasterBrick[[layer_n]])[values(rasterBrick[[layer_n]]) > 0.05, ], 2, range)
  c("long_min" = coord[[1]], "long_max" = coord[[2]], "lat_min" = coord[[3]], "lat_max" = coord[[4]])
}

for (layer_n in seq_len(nlayers(AssignmentDry$sample$pv))) {
  results[layer_n, c("long_min", "long_max", "lat_min", "lat_max")] <- get_range(AssignmentDry$sample$pv, layer_n)
  }

results

#Bat long_min long_max  lat_min  lat_max
#1   Alien_1 5.541527 15.45819 47.04153 55.45819
#2   Alien_2 5.541527 15.45819 47.04153 55.45819
#3   Alien_3 5.541527 15.45819 47.04153 55.45819
#4   Alien_4 5.541527 15.45819 47.04153 55.45819
#5   Alien_5 5.541527 15.45819 47.04153 55.45819
#6   Alien_6 5.541527 15.45819 47.04153 55.45819
#7   Alien_7 5.541527 15.45819 47.04153 55.45819
#8   Alien_8 5.541527 15.45819 47.04153 55.45819
#9   Alien_9 5.541527 11.87486 48.62486 55.45819
#10 Alien_10 5.541527 15.45819 47.04153 55.45819

Once you have obtained such a table (with your own results), it should be straightforward to export as csv, xls or whatever tabulated format you want since it is a data frame.
If you need, I could show you how to do that, but this has nothing to do with IsoriX :-)

I hope that will work for you, please let us know either way.
Best,

Alex



sarapweaver

unread,
May 26, 2021, 9:36:04 AM5/26/21
to IsoriX
Thanks, Alex! I'll try this today and let you know how it goes. :)

sarapweaver

unread,
May 26, 2021, 9:48:52 AM5/26/21
to IsoriX
It worked beautifully!

Alexandre Courtiol

unread,
May 26, 2021, 10:26:02 AM5/26/21
to iso...@googlegroups.com
Glad to hear that :-)

Reply all
Reply to author
Forward
0 new messages