-
Notifications
You must be signed in to change notification settings - Fork 86
Add annulus focal kernel #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add annulus focal kernel #126
Conversation
Thinking the kernel should be "pure" and not include the focal point. Will push a change. |
Thanks for the PR, I would love to have some tests with this annulus kernel. With the The ongoing stuff with focal is to allow some other kernel shapes (eg: cone, wedge) and also custom kernel. We'd better supply kernel value to a function instead of creating them inside the function, I believe. So basically, the interface should look be something like this: def _validate_kernel_shape(custom_kernel, shape, radius, outer_radius, inner_radius, ...):
if (shape == 'circle' and radius is valid):
if custom_kernelis not None or outer_radius is not None or inner_radius is not None:
raise ValueError("""circular kernel must be specified by shape='circle' and a valid `radius`, recieved: ...""")
# check other kernel shapes
....
def create_kernel(cellsize_x, cellsize_y, custom_kernel, shape, radius, outer_radius, inner_radius):
_validate_kernel_shape()
if shape == 'circle':
kernel = _gen_circular_kernel(cellsize_x, cellsize_y, radius)
elif shape == 'annulus':
kernel = _gen_annulus_kernel(cellsize_x, cellsize_y, outer_radius, inner_radius)
....
return kernel
def apply(raster, kernel, func):
.... |
Thanks, will make these changes. Would it make sense to extend the kernel by passing |
@chase-dwelle with the expansion of kernel shapes, I'm thinking that we can provide a bunch of functions that explicitly tell the shape in their names instead of having 1 function with a long list of args. def circular_kernel(cellsize_x, cellsize_y, radius):
# first validate args
# create and return 2d array of kernel
def annulus_kernel(cellsize_x, cellsize_y, outer_radius, inner_radius):
# first validate args
# create and return 2d array of kernel
def custom_kernel(kernel_values):
... How do you think? |
Anyway, these are some next steps. We're happy to have this PR merged once having tests updated. |
Added some tests for the kernels and made kernels a required argument to be passed to functions. The data flows go: This adds a couple more steps, but also is more straightforward from a code readability standpoint (in my opinion). I think it might be reasonable to refactor kernel construction to a |
@chase-dwelle hey the PR looks good and we'll merge it now. The data flow sounds good. Next step is to remove the function We should still have kernel functions in focal in my opinion since it's only used for focal stats currently. |
Addresses #125, #124
Using the circle kernel to extend to an annulus kernel. Implementation excludes the cells on the bound of the inner radius of the annulus.
Also implements the ability to return the raw z-scores from
hotspots
.