andrew-plowright / ForestTools

Detect and segment individual tree from remotely sensed data
66 stars 21 forks source link

Why drop sp_summarize() ??? #31

Closed DeltaForest-DP closed 8 months ago

DeltaForest-DP commented 8 months ago

Hi. I just had to update R and my packages and now the tree counting script I wrote using ForestTools says "could not find function "sp_summarize". This was an important piece; why remove it? Struggling with where I can find a similar algorithm... :(

Doug P.

andrew-plowright commented 8 months ago

Hi Doug

The geospatial library underlying, sp, is now deprecated. There are also better existing libraries that accomplish the same thing as sp_summarize, so I don't think it was adding any value.

I wrote a short guide demonstrating how to reproduce the results from sp_summarize while using the more recent sf library that is compatible with the newer version of ForestTools.

https://github.com/andrew-plowright/ForestTools/blob/master/guides/spatial_statistics.md

Let me know if that works for you. The guide currently explains how to summarize statistics by polygon, but I can add a section on how to grid statistics too.

Andrew

DeltaForest-DP commented 8 months ago

OK thanks Andrew, I’ll follow up on the link. In the meantime, I copied my old version overtop the new and my script now works fine (something I’ll keep in mind to do in the future). That’s my only complaint about R - packages change and then your legacy scripts crap out when you run them, forcing you to spend valuable, frustrating hours making the fixes. Otherwise I absolutely love R.

Its funny that you say “better libraries” - I’m running this on 10’s of thousands of hectares on a 20-m grid and sp_summarize completes tree counts at this resolution in seconds - that’s good enough for me! Thanks for getting back to me so quickly; and thanks for your good work!

Doug


DeltaForest Ltd. Doug Pitt, HBScF, PhD @.*** 788 Pine Shores Rd. Goulais River, ON P0S 1E0 705-989-6034


On Jan 19, 2024, at 3:12 PM, Andrew Plowright @.***> wrote:

Hi Doug

The geospatial library underlying, sp, is now deprecated. There are also better existing libraries that accomplish the same thing as sp_summarize, so I don't think it was adding any value.

I wrote a short guide demonstrating how to reproduce the results from sp_summarize while using the more recent sf library that is compatible with the newer version of ForestTools.

https://github.com/andrew-plowright/ForestTools/blob/master/guides/spatial_statistics.md

Let me know if that works for you. The guide currently explains how to summarize statistics by polygon, but I can add a section on how to grid statistics too.

Andrew

— Reply to this email directly, view it on GitHub https://github.com/andrew-plowright/ForestTools/issues/31#issuecomment-1901043998, or unsubscribe https://github.com/notifications/unsubscribe-auth/A4J4NVC357CB7V5ZW6565PLYPLHUDAVCNFSM6AAAAABCAZK3ZKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMBRGA2DGOJZHA. You are receiving this because you authored the thread.

andrew-plowright commented 8 months ago

I hear you. Managing legacy scripts can be a pain. If it's a mission-critical script, you can always consider containerizing it to protect against updated packages causing backwards incompatibility.

As for sp_summarise, the code's function is still available here. One of its dependency libraries, APfun, is also deprecated and no longer available anywhere. If you still have that installed, the script will still work, but you won't be able to get it set up on a different machine.

Also note that newer versions of ForestTools output the newer sf class instead of SpatialPointsDataFrame class from the deprecated sp. It's easy enough to convert them, though (see example below).

library(ForestTools)
library(sf)

# Use vwf to get treetops
ttops <- vwf(chm, function(x){x * 0.06 + 0.5}, minHeight=1.5)

# Convert from sf to sp
ttops_sp <- as_Spatial(ttops)

# Compute stats
sp_summarise(ttops_sp , areas = cut_blocks, variables = "height")

I'll close the issue for now, but let me know if you run into any trouble.

Andrew