Skip to content

Commit a9780d1

Browse files
Minor updates
1 parent 4566e99 commit a9780d1

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

scripts/export_lower_resolution.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313
# from skimage.segmentation import relabel_sequential
1414

1515

16-
def filter_component(fs, segmentation, cochlea, seg_name, components):
16+
def filter_component(fs, segmentation, cochlea, seg_name, components, min_size):
1717
# First, we download the MoBIE table for this segmentation.
1818
internal_path = os.path.join(BUCKET_NAME, cochlea, "tables", seg_name, "default.tsv")
1919
with fs.open(internal_path, "r") as f:
2020
table = pd.read_csv(f, sep="\t")
2121

2222
# Then we get the ids for the components and us them to filter the segmentation.
2323
component_mask = np.isin(table.component_labels.values, components)
24+
if min_size is not None:
25+
component_mask = np.logical_and(component_mask, table.n_pixels > min_size)
26+
2427
keep_label_ids = table.label_id.values[component_mask].astype("int64")
2528
if max(keep_label_ids) > np.iinfo("uint16").max:
2629
warnings.warn(f"Label ID exceeds maximum of data type 'uint16': {np.iinfo('uint16').max}.")
@@ -155,9 +158,13 @@ def export_lower_resolution(args):
155158
with zarr.open(s3_store, mode="r") as f:
156159
data = f[input_key][:].astype("float32")
157160
print("Data shape", data.shape)
161+
158162
if args.filter_by_components is not None:
159163
print(f"Filtering channel {channel} by components {args.filter_by_components}.")
160-
data = filter_component(fs, data, args.cochlea, channel, args.filter_by_components)
164+
data = filter_component(
165+
fs, data, args.cochlea, channel, args.filter_by_components, min_size=args.min_size
166+
)
167+
161168
if args.filter_cochlea_channels is not None:
162169
us_factor = ds_factor // (2 ** scale)
163170
upscaled_filter = upscale_volume(data, filter_volume, upscale_factor=us_factor)
@@ -183,6 +190,7 @@ def main():
183190
parser.add_argument("--binarize", action="store_true")
184191
parser.add_argument("--filter_cochlea_channels", nargs="+", type=str, default=None)
185192
parser.add_argument("--filter_dilation_iterations", type=int, default=8)
193+
parser.add_argument("--min_size", default=None, type=int)
186194
args = parser.parse_args()
187195

188196
export_lower_resolution(args)

scripts/la-vision/predict_blocks.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212

1313

1414
def _get_files(sgn=True):
15-
input_root = "/mnt/vast-nhr/home/pape41/u12086/Work/my_projects/flamingo-tools/scripts/more-annotations/LA_VISION_M04" # noqa
16-
input_root2 = "/mnt/vast-nhr/home/pape41/u12086/Work/my_projects/flamingo-tools/scripts/more-annotations/LA_VISION_M04_2" # noqa
17-
input_root3 = "/mnt/vast-nhr/home/pape41/u12086/Work/my_projects/flamingo-tools/scripts/more-annotations/LA_VISION_Mar05" # noqa
15+
# root = "/mnt/vast-nhr/home/pape41/u12086/Work/my_projects/flamingo-tools/scripts/more-annotations"
16+
root = "/home/pape/Work/my_projects/flamingo-tools/scripts/more-annotation"
17+
input_root = os.path.join(root, "LA_VISION_M04")
18+
input_root2 = os.path.join(root, "LA_VISION_M04_2")
19+
input_root3 = os.path.join(root, "LA_VISION_Mar05")
1820

1921
input_root_ihc = "/mnt/vast-nhr/home/pape41/u12086/Work/my_projects/flamingo-tools/scripts/more-annotations/LA_VISION_Mar05-ihc" # noqa
2022

scripts/measurements/measure_sgns.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def main():
3434
else:
3535
cochleae = args.cochleae
3636

37+
n_sgns = []
3738
for dataset in cochleae:
3839
if dataset not in project_info["datasets"]:
3940
print("Could not find cochleae", dataset)
@@ -60,11 +61,15 @@ def main():
6061
component_ids, n_per_component = np.unique(
6162
remaining_sgns, return_counts=True
6263
)
63-
print("Number of SGNs (largest component):", max(n_per_component))
64+
n_sgn = max(n_per_component)
65+
print("Number of SGNs (largest component):", n_sgn)
66+
n_sgns.append(n_sgn)
6467
else:
6568
print(source)
6669
print("Number of SGNs (no postprocessing):", len(table))
6770

71+
print("Average number of SGNs:", np.mean(n_sgns), "+-", np.std(n_sgns))
72+
6873

6974
if __name__ == "__main__":
7075
main()

0 commit comments

Comments
 (0)