Skip to content
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

kring_smoothing is not averaging over its k-ring neighbors #4

Open
gpolov-personal opened this issue Dec 24, 2020 · 0 comments
Open

Comments

@gpolov-personal
Copy link

I understand that the intention of the kring_smoothing function is to assign to each cell the "k-ring moving average" of its k-ring neighbors. If this is the idea (maybe the meaning is different), I think the function is not correct, it is quite similar but not the same.

Currently when you are merging:
.merge(df[[hex_col,metric_col]]).fillna(0)

You are assigning to each of the hexk neighbors of a cell the values of the cell value, so each new hexk cell will have the average of all of the cell for which it is a k-ring neighbor. This causes that new cells that were not present appear after the smoothing (so the metric 'mass' is conservative) because even if not present in the original set, the boundary cells will create new neighbors

As far as I understand, the way to smooth would be to assign to each cell the average of all its k-ring neighbors, like a moving mean but with hexagonal rings. Little modifications has to be made in the merge and group_by. Merging against hexk instead of hex_col (but to avoid the mess of columns names suffixes the trick is to temporarily rename the hex_col to hexk in the original data frame and performing a mean in the group by).
.merge(df.loc[:,[hex_col,metric_col]].rename(columns={hex_col:'hexk'}), how='left').fillna(0)
.groupby([hex_col])[[metric_col]].mean()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant