Skip to content

Commit 18237af

Browse files
committed
davy's bug fixes
1 parent d7ffd75 commit 18237af

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

examples/wrappers/3_alignment_evaluation.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
args_file_path = '/path/to/your/parameter/file.json'
1212

1313
# Load the configuration settings from the specified file.
14-
args.load_config(args_file_path)
14+
args.load_params(args_file_path)
1515

1616
# Step 2: Additional Configuration for Alignment Evaluation
1717
# ================================================
@@ -47,7 +47,10 @@
4747
# Extract the coordinates.
4848
for fov in fovs_to_analyze:
4949
for code in codes_to_analyze:
50-
measure_round_alignment_NCC(args=args,code=code, fov=fov)
50+
try:
51+
measure_round_alignment_NCC(args=args,code=code, fov=fov)
52+
except Exception as e:
53+
print(f"Error measuring alignment for Code {code}, FOV {fov}: {e}")
5154

5255

5356
# Step 4: Alignment Evaluation and Confidence Interval Calculation

exm/align/align_eval.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def plot_alignment_evaluation(args: Args, fov: int, percentile: int = 95, save_f
115115
"""
116116

117117
def load_eval_data(args: Args, fov: int) -> dict:
118-
eval_file = os.path.join(args.processed_data_path, "alignment_evaluation", f"FOV{fov}", f"NCC_fov{fov}.json")
118+
eval_file = os.path.join(args.processed_data_path, "alignment_evaluation", f"FOV{fov}", f"NCC_FOV{fov}.json")
119119
with open(eval_file, 'r') as f:
120120
eval_data = json.load(f)
121121
return eval_data
@@ -189,7 +189,7 @@ def bootstrap_mean_ci(data: np.array, n_bootstrap_samples: int, ci: float) -> (f
189189
return lower_bound, upper_bound
190190

191191
ci_data = {}
192-
eval_file_path = os.path.join(args.processed_data_path, "alignment_evaluation", f"ROI{roi}", f"NCC_ROI{roi}.json")
192+
eval_file_path = os.path.join(args.processed_data_path, "alignment_evaluation", f"FOV{fov}", f"NCC_FOV{fov}.json")
193193

194194
try:
195195
with open(eval_file_path, 'r') as f:
@@ -203,7 +203,7 @@ def bootstrap_mean_ci(data: np.array, n_bootstrap_samples: int, ci: float) -> (f
203203
percentile_value = np.percentile(eval_array, percentile_filter)
204204
eval_filtered = eval_array[eval_array <= percentile_value]
205205

206-
lower_bound, upper_bound = bootstrap_mean_ci(eval_filtered, len(eval_data)//10, ci)
206+
lower_bound, upper_bound = bootstrap_mean_ci(eval_filtered, len(eval_filtered)//10, ci)
207207
ci_data[key] = {
208208
"lower_bound": lower_bound,
209209
"upper_bound": upper_bound

exm/puncta/consolidate.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ def find_matching_points(point_cloud1, point_cloud2, distance_threshold=8):
204204
point_cloud1 = np.asarray([x["position"] for x in reference])
205205
point_cloud2 = np.asarray([x["position"] for x in new])
206206

207+
if len(point_cloud2) == 0 or len(point_cloud1) == 0:
208+
logger.warning(f"Code {code} for FOV {fov} has no puncta.")
209+
continue
210+
207211
pairs = find_matching_points(point_cloud1, point_cloud2)
208212

209213
for pair in pairs:

exm/segmentation/segmentation.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from cellpose import models,utils,plot,io
99

1010

11-
def segment_3d(volume,model,downsample=False,chan=0,chan2=0,flow_threshold=0.4,cellprob_threshold=0,do_3D=True):
11+
def segment_3d(volume,model,downsample=False,chan=0,chan2=0,diameter=30,flow_threshold=0.4,cellprob_threshold=0,do_3D=True):
1212
r"""
1313
Performs 3D segmentation on the given volume using the provided model.
1414
@@ -22,6 +22,8 @@ def segment_3d(volume,model,downsample=False,chan=0,chan2=0,flow_threshold=0.4,c
2222
:type chan: int
2323
:param chan2: The second channel to use for segmentation. Default is 0.
2424
:type chan2: int
25+
:param diameter: Estimated diameter of objects to segment. Set to 0 to auto-estimate. Default is 30.
26+
:type diameter: float
2527
:param flow_threshold: The flow threshold for the segmentation. Default is 0.4.
2628
:type flow_threshold: float
2729
:param cellprob_threshold: The cell probability threshold for the segmentation. Default is 0.
@@ -36,9 +38,10 @@ def segment_3d(volume,model,downsample=False,chan=0,chan2=0,flow_threshold=0.4,c
3638
volume = ndimage.zoom(volume, (1,1,0.25,0.25), order= 1)
3739
masks, flows, styles = model.eval(volume,
3840
channels=[chan, chan2],
39-
diameter=model.diam_labels,
41+
diameter=diameter,
4042
flow_threshold=flow_threshold,
4143
cellprob_threshold=cellprob_threshold,
44+
z_axis=0,
4245
do_3D=do_3D
4346
)
4447
if downsample:

0 commit comments

Comments
 (0)