Giter VIP home page Giter VIP logo

Comments (4)

dfriend21 avatar dfriend21 commented on July 3, 2024 1

Thanks for posting and for the code! Honestly I hadn't given data type conversions much thought before now, but that's something I should definitely add - I'll make an issue for it so that I remember to add it at some point. It'd definitely be nice to have a function that just converts it to an sf object.

I've fiddled around with your code - I'm not all that familiar with sf or wk, but I was able to modify your code to use data.table to create the rectangles, and it seems to run considerably faster:

library(soilDB)
library(sf)
library(wk)
library(data.table)
library(quadtree)

# make a bounding box and assign a CRS (4326: GCS, WGS84)
a.CA <- st_bbox(
  c(xmin = -2280334, xmax = -2065433, ymin = 1755361, ymax = 1970262), 
  crs = st_crs(5070)
)

# convert bbox to sf geometry
a.CA <- st_as_sfc(a.CA)

pH_3060cm <- ISSR800.wcs(aoi = a.CA, var = 'ph_3060cm')
plot(pH_3060cm, axes = FALSE, xlab = '', ylab = '')

qt <- quadtree(pH_3060cm, split_threshold = 0.25, split_method = "sd", adj_type = "resample",  resample_n_side = 128)

dt <- data.table(as_data_frame(qt))
cr <- st_crs(5070)
bbs_list <- dt[, list(bb = st_as_sf(rct(xmin, ymin, xmax, ymax, cr)))]$bb

bbs <- st_as_sf(bbs_list)
plot(bbs)

I ran a quick benchmark on it, and it was taking 163ms on my machine. So give that a shot and see if it works for you.

from quadtree.

dylanbeaudette avatar dylanbeaudette commented on July 3, 2024

Thanks! Your code is much faster / elegant that the hack I posted. It scales nicely too. Just tried all of the lower '48. About 5 seconds from start to finish!

image

What do you think about splitting categorical rasters based on Shannon entropy?

from quadtree.

dfriend21 avatar dfriend21 commented on July 3, 2024

That's not something I'm very familiar with... looks like it's an index for the variation in categorical data - is that correct? So the idea would be to split a quadrant if the variation is above some threshold - otherwise you'd assign the most common category to the cell? Am I interpreting that correctly?

It'd definitely be nice to add more support for categorical data. My use case for creating the package was entirely with continuous rasters, so I didn't give any thought to categorical data when writing the code. If that's something you think would be a useful addition I could certainly add an option for splitting based on the Shannon entropy - I don't think it'd be too difficult. That being said, I don't have a plethora of spare time these days (and won't for the next several months) so I can't guarantee that I'd get to it in a timely fashion - but I can certainly add it to the to-do.

For what it's worth, you should be able create a custom function that implements the Shannon entropy. You can write functions to define your own rules for splitting cells - see this section of the "Creating Quadtrees" vignette. You'd also need to write a custom "combine" function as well to pick the most common category.

from quadtree.

dfriend21 avatar dfriend21 commented on July 3, 2024

Functionality added in PR #17

from quadtree.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.