Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Andrew Marx
    @andrewmarx
    First post
    Alex Baecher
    @slamander

    Hey Andrew!

    I really love your package, SAMC. After using the package with a dataset of Burmese pythons and USGS landcover data, I've run into an issue when using the samc::mortality function that previously wasn't occurring. When I calculate long-term mortality using the mortality function without setting the time = argument, my R session crashes... When I run the function with the built-in data there is no problem. I've tried resampling the data to many different resolutions, but nothing helps. Do you have any idea why this wasn't an issue before, when using the very same data? I can upload my data and script to google drive if needed.

    Best,

    -Alex.

    Andrew Marx
    @andrewmarx
    If you're using v1.2.0, there was a bug that causes landscape data without missing values to crash. I submitted an update to CRAN a week ago, and the new Windows builds just became available sometime this morning or late last night. Try updating to v1.2.1 and let me know if that fixes it.
    Alex Baecher
    @slamander
    @andrewmarx
    Thanks for getting back so quickly!
    I downloaded the new version, but still had crashes. This made me look more closely at the code and I believe the issue was may have been caused by improperly masking my landscape vs occupancy layer... Everything seems to be working just fine now!
    One more question: do occupancy layers need to have NAs in the same pixel locations as resistance/absorption data layers?
    -Alex.
    Andrew Marx
    @andrewmarx
    @slamander Yes, they do need NAs in the same locations. However, there shouldn't be any crashes if there are issues with the rasters; the package should printing out an error message explaining what's wrong. It's entirely possible I haven't anticipated all scenarios, so if you are able to upload a minimal crashing example in a zip file as a github issue, I'd appreciate it. To keep things small, you could crop or rescale the raster data as long as it still causes crashes
    Alex Baecher
    @slamander
    @andrewmarx Interesting... So I understand, I had forgotten to mask the occupancy layer and therefore it had greater dimensions than the landscape layer. Would, for example, samc::mortality, print a specific error message for this instead of crashing? Likewise, would inconsistent NAs in the occupancy and landscape layers also print an error instead of crashing?
    Andrew Marx
    @andrewmarx
    @slamander andrewmarx/samc#11
    Andrew Marx
    @andrewmarx
    @slamander if you're referring to raster::mask(), it shouldn't actually be changing the extents of the raster. You can actually check this using raster::extent(). If there is a mismatch between the extents you should get a message saying so. Same for nrow() and ncol(); mask() shouldn't change these values, and the package should give you a message if there is a mismatch there as well
    @slamander Basically, at this point, I'm missing an argument in one of my functions that causes the NA check to not work correctly. If there is a mismatch in NA locations, it can lead to illegal linear algebra combinations, which may be the cause of your crashes. If you could send me an example dataset and code to my ufl email so I can make sure there isn't anything else going on, I'd appreciate it.
    Alex Baecher
    @slamander
    Thanks, @andrewmarx, for getting back to me about my issue. I see now that raster::mask() shouldn't affect the dimensions and that NAs were likely my problem, as I didn't force NAs from my landscape layers to my occupancy layer. Once my current job is done (~4 hrs), I'll try to recreate the issue and send you the code. My rasters are rather large, so I'll resample them and send you a link to a google drive folder?
    Andrew Marx
    @andrewmarx
    @slamander google drive would be great
    Alex Baecher
    @slamander
    @andrewmarx
    Hey Andrew, I finally got an example to you for a crash issue I'm having--sent to your UFL address. I couldn't reproduce my original problem, but--more along with my luck--I stumbled into another.
    Alex Baecher
    @slamander

    @andrewmarx Hey again! Hope you're doing well. I see you've incorporated multiple absorbing states into the package! This is great news. I'm currently trying to use multiple absorbing states for the python project we used in the IALE workshop. But, I'm curious about the error I'm receiving. When I follow your "multiple absorption" example, I'm able to add the two complimentary layers as samc_obj$abs_states. But, when I create my own samc object using the data from the workshop, if I try to add complementary layers as $abs_states, I receive the following error:

    Error in .local(x, ...) : 
      unused arguments (xmn = 0.5, xmx = 628.5, ymn = 0.5, ymx = 472.5, crs = NA)

    The original absorption layer I passed samc to create the object was just a raster addition of two layers, and when I attempted to create the $abs_states tab, I just added them as a list--just like your example. I've used check() and all.equal() to make sure the complimentary layers are meeting the criteria indicated in your example. Unfortunately, I don't have the ability to make this a minimally repeatable example, so I'll have to push this into a GH repo if you'd like to see the code.

    Andrew Marx
    @andrewmarx
    Use raster::stack() to group raster layers. list() is for when the data is in matrices. Essentially, they get processed differently and it's assumed the contents of a list() need to be converted to rasters. If the contents are already a raster, then the conversion throws this error. Rob has run into this as well because I need to make it clearer in that tutorial.
    @slamander
    Alex Baecher
    @slamander
    @andrewmarx Thanks--I should have known that list() was for matrices! Good to know. Hope you are doing well!
    Alex Baecher
    @slamander

    @andrewmarx One more question! Rob had provided a function for calculating net flow from samc visitation:

    visitationNet <- function(samc, visitation, origin, dest){
      require(Matrix)
      Q <- samc@p[-nrow(samc@p), -nrow(samc@p)]                   #get Q only from samc object
      nNet <- abs(skewpart(visitation*Q))                         #get difference in rates for links using origin row of fundamental
      visitNet <- pmax(rowSums(nNet),colSums(nNet))               #get max of rowSums / colSums for nodes
      visitNet[c(origin, dest)] <- 2 * visitNet[c(origin, dest)]  #set origin/dest = 1
      return(visitNet)
    }

    But the @p slot is no longer existent. Should I be using the @data@q slot instead? I tried to modify the function to use that slot, but errors were returned.

    Alex Baecher
    @slamander

    The code I'm attempting to run is here:

    visit_samc_lox_dest_net <- visitationNet(samc = samc_lox_dest, 
                                             visitation = samc::visitation(samc = samc_lox_dest, origin = origin_ever), 
                                             origin = origin_ever, dest = origin_lox)

    The error it throws is this:

    Error in visitationNet(samc = samc_lox_dest, visitation = samc::visitation(samc = samc_lox_dest,  : 
      no slot of name "p" for this object of class "samc"

    How can I get Q from a p matrix now, with the new updates?

    Alex Baecher
    @slamander
    @andrewmarx Sorry for the many messages! I found the information in your news section (now the p matrix can be accessed with samc_obj$p_matrix. Hope you had a nice thanksgiving!
    Andrew Marx
    @andrewmarx
    @slamander Sorry, I didn't see your 2nd message on the 22nd. Glad you managed to figure it out. FYI, Github now has a discussions feature, so in the future I want to try and have questions posted there instead where I'm more likely to see it: https://github.com/andrewmarx/samc/discussions