Skip to content

Commit

Permalink
weighted average
Browse files Browse the repository at this point in the history
  • Loading branch information
JoranAngevaare committed Feb 24, 2025
1 parent cdfce45 commit 0a776a0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions optim_esm_tools/analyze/region_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,16 +606,20 @@ def find_max_in_equal_area(
continue

da_sel = data.where(da_m)
max_in_sel = float(
da_sel.where(da_m).mean("lat lon".split()).max(),

max_in_sel = oet.analyze.tools._weighted_mean_2d_numba(
da_sel.where(da_m).values,
weights=area.values,
)
if prev_mask is None or target_area > area_m2:
return dict(
area_m2=area_m2,
max_in_sel=max_in_sel,
)
prev_in_sel = float(
da_sel.where(prev_mask).mean("lat lon".split()).max(),

prev_in_sel = oet.analyze.tools._weighted_mean_2d_numba(
da_sel.where(prev_mask).values,
weights=area.values,
)
prev_area = float(area.where(prev_mask).sum())

Expand Down

0 comments on commit 0a776a0

Please sign in to comment.