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

Insulation score should weight by # of NaNs in each diagonal #459

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions cooltools/api/insulation.py
Expand Up @@ -115,7 +115,12 @@ def insul_diamond(

i = diag_pixels.bin1_id.values - lo_bin_id
j = diag_pixels.bin2_id.values - lo_bin_id

####
# Weight each bin by the fraction of NaNs at each diagonal
diag_pixels['distance_from_diag'] = (diag_pixels['bin1_id'] - diag_pixels['bin2_id']).abs()
diag_pixels['valid_pixel_mask'] = ~diag_pixels["balanced"].isnull().values
diag_weighting_factor = diag_pixels.groupby(['bin1_id', 'distance_from_diag'])['valid_pixel_mask'].mean()
####
for i_shift in range(0, window):
for j_shift in range(0, window):
if i_shift + j_shift < ignore_diags:
Expand All @@ -132,9 +137,10 @@ def insul_diamond(
)

if clr_weight_name:
### Weight sum_balanced by the number of non-Nans in diagonal
sum_balanced += np.bincount(
i[mask & valid_pixel_mask] + i_shift,
diag_pixels["balanced"].values[mask & valid_pixel_mask],
diag_pixels["balanced"].values[mask & valid_pixel_mask] / diag_weighting_factor.loc[[i, i_shift + j_shift]],
minlength=N,
)

Expand Down