Skip to content

How can I do a convolution/rolling() based on physical dimensions (rather than window size)? #8361

Answered by tomchor
tomchor asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for the clarifications! The code is now working properly, and I included a couple of bells and whistles. I haven't pursued any optimization yet, but I know what to try now based on opt_einsum (although I'm not sure I can apply that effectively since the proper way to do things is to use integrate()).

Here's a snippet with an example:

import numpy as np
import xarray as xr

N = 100
x = np.logspace(0, 2, N)-1
da = xr.DataArray(np.vstack([np.sin(2*np.pi*x/30)]*N),
                  dims=["y", "x"], coords=dict(x=x, y=x)).chunk(x=1, y=1)

def filter(da, filter_size, dim="x", kernel="gaussian", min_distance=0):
    x2 = da[dim].rename({ dim : "x2"})

    if kernel == "tophat":
        aux 

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@tomchor
Comment options

@dcherian
Comment options

@tomchor
Comment options

Answer selected by dcherian
@dcherian
Comment options

@tomchor
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants