python - Numpy - Regrid with Averaging redux -


i'm trying implement similar answered in this post regridding in python. question in post involved regridding array such output cell contain average of input cells contributed it. catch each input cell (i think) contributes 1 output cell - is, there's no real way account case input cell overlaps 2 output cells.

i'm wondering if there's way generalize method account cell overlap - if, example, have 2 input bins span 0 1 , 1 2 , output cell spans 0.75 2, want take sort of weighted average calculate value in output cell recognizes input cell spanned 1 2 should contribute 4x more output cell 1 spanned 0 1.

this isn't interpolation, per se, pretty every method i've seen attempting similar uses it. problem straight interpolating with, eg, np.interp routine ignores of points if more 1 input cell contributes output cell.

i'm not quite you're looking for, working on similar right now. have 2 uniform finite difference grids, , need map information 1 onto other , again. code suits needs. function, x_to_x, creates matrix, m, such can take dot product of m data on grid , produce data on grid b.

def x_to_x(xa, da, xb, db):     = np.tile(xa, (np.size(xb), 1))     b = np.tile(xb, (np.size(xa), 1)).t     a_l = - da / 2     a_r = + da / 2     b_l = b - db / 2     b_r = b + db / 2     x_l = np.maximum(a_l, b_l)     x_r = np.minimum(a_r, b_r)     return np.maximum(x_r - x_l, 0.) / db 

if have non-uniform grid, da , db adapted being scalars like, eg, da = np.hstack(a[1:] - a[:-1], a[-1] - a[-2]).


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -