Skip to content

Commit a9c716e

Browse files
committed
Small fixes, unify style for script arguments
1 parent 6aba946 commit a9c716e

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

flamingo_tools/segmentation/unet_prediction.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def calc_mean_and_std(input_path: str, input_key: str, output_folder: str) -> No
295295
mean, std = parallel.mean_and_std(
296296
input_, block_shape=tuple([2 * i for i in chunks]), n_threads=n_threads, verbose=True, mask=image_mask
297297
)
298-
ddict = {"mean": mean, "std": std}
298+
ddict = {"mean": float(mean), "std": float(std)}
299299
with open(json_file, "w") as f:
300300
json.dump(ddict, f)
301301

@@ -369,9 +369,9 @@ def run_unet_prediction_preprocess_slurm(
369369
)
370370

371371
if not os.path.isdir(os.path.join(output_folder, "mask.zarr")):
372-
find_mask(input_path, input_key, output_folder, s3=s3)
372+
find_mask(input_path, input_key, output_folder)
373373

374-
calc_mean_and_std(input_path, input_key, output_folder, s3=s3)
374+
calc_mean_and_std(input_path, input_key, output_folder)
375375

376376

377377
def run_unet_prediction_slurm(
@@ -420,7 +420,7 @@ def run_unet_prediction_slurm(
420420
raise ValueError("The SLURM_ARRAY_TASK_ID is not set. Ensure that you are using the '-a' option with SBATCH.")
421421

422422
if not os.path.isdir(os.path.join(output_folder, "mask.zarr")):
423-
find_mask(input_path, input_key, output_folder, s3=s3)
423+
find_mask(input_path, input_key, output_folder)
424424

425425
# get pre-computed mean and standard deviation of full volume from JSON file
426426
if os.path.isfile(os.path.join(output_folder, "mean_std.json")):

scripts/convert_tif_to_n5.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ def main(input_path: str, output_path: str = None) -> None:
1919
if input_path.split(".")[-1] not in ["TIFF", "TIF", "tiff", "tif"]:
2020
sys.exit("Input file must be in tif format.")
2121

22-
basename = "".join(input_path.split("/")[-1].split(".")[:-1])
23-
input_dir = input_path.split(basename)[0]
24-
input_dir = os.path.abspath(input_dir)
22+
basename = ".".join(input_path.split("/")[-1].split(".")[:-1])
23+
input_dir = os.path.abspath(input_path).split(basename)[0]
2524

2625
if output_path is None:
2726
output_path = os.path.join(input_dir, basename + ".n5")

scripts/resize_wrongly_scaled_cochleas.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
def main(
1616
input_path: str,
17-
output_folder: str,
17+
output_dir: str = None,
1818
scale: float = 0.38,
1919
input_key: str = "setup0/timepoint0/s0",
2020
interpolation_order: int = 3
@@ -23,7 +23,7 @@ def main(
2323
2424
Args:
2525
input_path: Input path to tif file or n5 folder.
26-
output_folder: Output folder for rescaled data in n5 format.
26+
output_dir: Output folder for rescaled data in n5 format.
2727
scale: Scale of output data.
2828
input_key: The key / internal path of the image data.
2929
interpolation_order: Interpolation order for resizing function.
@@ -36,8 +36,13 @@ def main(
3636
input_chunks = input_.chunks
3737

3838
abs_path = os.path.abspath(input_path)
39-
basename = "".join(os.path.basename(abs_path).split(".")[:-1])
40-
output_path = os.path.join(output_folder, basename + "_resized.n5")
39+
basename = ".".join(os.path.basename(abs_path).split(".")[:-1])
40+
input_dir = os.path.abspath(input_path).split(basename)[0]
41+
42+
if output_dir is None:
43+
output_path = os.path.join(input_dir, basename + "_resized.n5")
44+
else:
45+
output_path = os.path.abspath(output_dir)
4146

4247
shape = input_.shape
4348
ndim = len(shape)
@@ -78,15 +83,14 @@ def copy_chunk(block_index):
7883
parser = argparse.ArgumentParser(
7984
description="Script for resizing microscoopy data in n5 format.")
8085

81-
parser.add_argument("input_file", type=str, required=True, help="Input tif file or n5 folder.")
82-
parser.add_argument(
83-
"output_folder", type=str, help="Output folder. Default resized output is '<basename>_resized.n5'."
84-
)
86+
parser.add_argument("-i", "--input", required=True, type=str, help="Input tif file or n5 folder.")
87+
parser.add_argument("-o", "--output", type=str,
88+
help="Output n5 folder. Default resized output is '<basename>_resized.n5'.")
8589

8690
parser.add_argument("-s", "--scale", type=float, default=0.38, help="Scale of input. Re-scaled to 1.")
8791
parser.add_argument("-k", "--input_key", type=str, default="setup0/timepoint0/s0", help="Input key for n5 file.")
88-
parser.add_argument("-i", "--interpolation_order", type=float, default=3, help="Interpolation order.")
92+
parser.add_argument("--interpolation_order", type=float, default=3, help="Interpolation order.")
8993

9094
args = parser.parse_args()
9195

92-
main(args.input_file, args.output_folder, args.scale, args.input_key, args.interpolation_order)
96+
main(args.input, args.output, args.scale, args.input_key, args.interpolation_order)

0 commit comments

Comments
 (0)