Skip to content

Commit

Permalink
Break merging early for merge_datasets (#220)
Browse files Browse the repository at this point in the history
* weighted average

* allow breaking early
  • Loading branch information
JoranAngevaare authored Feb 24, 2025
1 parent b4abcba commit 9aa191b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion optim_esm_tools/analyze/merge_candidate_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def merge_datasets(self):
pbar.display()
self.log.info(pbar)
doc = self._group_to_first(candidates)

if not self.pass_criteria(**doc['stats']):
self.log.info(
f'Discarding group {doc["merged"]} because {doc["stats"]} does not pass',
Expand All @@ -230,6 +231,10 @@ def merge_datasets(self):
)
groups.append(doc)
candidates = [c for i, c in enumerate(candidates) if i not in doc['merged']]

if doc.get('force_break', False):
self.log.warning('Breaking forcefully')
candidates = []
pbar.n = pbar.total
pbar.close()
pbar.display()
Expand Down Expand Up @@ -268,7 +273,8 @@ def _group_to_first(
self.log.info(
f"Exhausted passing regions, so next candidates are ignored ({len(candidates)-1} remaining)",
)
return dict(stats=first_doc, ds=candidates[0], merged=[0])
# We are going to pass one additional argument that allows us to break the overencompasing loop
return dict(stats=first_doc, ds=candidates[0], merged=[0], force_break=True)
while something_merged:
something_merged = False
for i, ds_alt in global_masks.items():
Expand Down

0 comments on commit 9aa191b

Please sign in to comment.