disentangle

This commit is contained in:
2024-08-20 22:11:16 +02:00
parent d3ac74835e
commit 547b2b7fb1

View File

@ -5,11 +5,16 @@ from .thresh import threshold
def calc_force_send(results, data, pixel_mask_pf, image, aggregator): def calc_force_send(results, data, pixel_mask_pf, image, aggregator):
force_send_visualisation = False data = calc_data(results, data, pixel_mask_pf, image, aggregator)
force_send_visualisation = calc_aggregation_ready(results, data, aggregator)
if data.dtype == np.uint16:
return data, force_send_visualisation return data, force_send_visualisation
def calc_data(results, data, pixel_mask_pf, image, aggregator):
if data.dtype == np.uint16:
return data
apply_aggregation = results.get("apply_aggregation", False) apply_aggregation = results.get("apply_aggregation", False)
apply_threshold = results.get("apply_threshold", False) apply_threshold = results.get("apply_threshold", False)
@ -18,15 +23,15 @@ def calc_force_send(results, data, pixel_mask_pf, image, aggregator):
if not apply_aggregation and not apply_threshold: if not apply_aggregation and not apply_threshold:
data = image data = image
return data, force_send_visualisation return data
calc_apply_threshold(results, data) # changes data in place calc_apply_threshold(results, data) # changes data in place
data, force_send_visualisation = calc_apply_aggregation(results, data, aggregator) data = calc_apply_aggregation(results, data, aggregator)
calc_mask_pixels(data, pixel_mask_pf) # changes data in place calc_mask_pixels(data, pixel_mask_pf) # changes data in place
return data, force_send_visualisation return data
@ -48,14 +53,12 @@ def calc_apply_threshold(results, data):
def calc_apply_aggregation(results, data, aggregator): def calc_apply_aggregation(results, data, aggregator):
force_send_visualisation = False
apply_aggregation = results.get("apply_aggregation", False) apply_aggregation = results.get("apply_aggregation", False)
if not apply_aggregation: if not apply_aggregation:
return data, force_send_visualisation return data
if "aggregation_max" not in results: if "aggregation_max" not in results:
return data, force_send_visualisation return data
aggregator += data aggregator += data
@ -65,11 +68,33 @@ def calc_apply_aggregation(results, data, aggregator):
results["aggregated_images"] = n_aggregated_images results["aggregated_images"] = n_aggregated_images
results["worker"] = 1 #TODO: keep this for backwards compatibility? results["worker"] = 1 #TODO: keep this for backwards compatibility?
return data
def calc_aggregation_ready(results, data, aggregator):
if data.dtype == np.uint16:
return False
apply_aggregation = results.get("apply_aggregation", False)
apply_threshold = results.get("apply_threshold", False)
if not apply_aggregation and not apply_threshold:
return False
if not apply_aggregation:
return False
if "aggregation_max" not in results:
return False
n_aggregated_images = aggregator.counter
if n_aggregated_images >= results["aggregation_max"]: if n_aggregated_images >= results["aggregation_max"]:
force_send_visualisation = True
aggregator.reset() aggregator.reset()
return True
return data, force_send_visualisation return False