Skip to content

Commit

Permalink
Merge pull request #26 from dbouget/space_fix
Browse files Browse the repository at this point in the history
Handling spaces in filenames
  • Loading branch information
andreped authored Sep 11, 2024
2 parents 6e2d0c3 + e5cdf5e commit de92c1f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 3 additions & 2 deletions vsi2tif/src/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def cellsens2raw(

cmd = (
f"{bfconvert} -tilex {tz} -tiley {tz} -nogroup -no-upgrade -overwrite -bigtiff -series {plane} "
f"-compression {compression} {input_path} {output_path}"
f'-compression {compression} "{input_path}" "{output_path}"'
)
try:
run_wrapper(cmd=cmd, verbose=verbose, max_mem=max_mem)
Expand All @@ -37,7 +37,8 @@ def raw2tif(input_path: str, output_path: str, compression: str = "jpeg", qualit
os.makedirs("/".join(output_path.split("/")[:-1]), exist_ok=True)

cmd = (
f"vips tiffsave {input_path} {output_path} --bigtiff --tile --pyramid --compression={compression} --Q={quality}"
f'vips tiffsave "{input_path}" "{output_path}" --bigtiff --tile --pyramid --compression={compression}'
f" --Q={quality}"
)
try:
run_wrapper(cmd=cmd, verbose=verbose)
Expand Down
8 changes: 7 additions & 1 deletion vsi2tif/src/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def cellsens2tif_batch(
quality: int = 85,
max_mem: int = 32,
verbose: int = 1,
remove_name_spaces=False,
) -> None:
# create directory if it does not exist
os.makedirs(output_path, exist_ok=True)
Expand All @@ -48,7 +49,12 @@ def cellsens2tif_batch(
# perform conversion in separate processes
for root, file in tqdm(paths):
curr_input_path = os.path.join(root, file)
curr_output_path = (output_path + "/" + curr_input_path.split(input_path)[-1]).replace(".vsi", ".tif")
if remove_name_spaces:
curr_output_path = (
(output_path + "/" + curr_input_path.split(input_path)[-1]).replace(" ", "_").replace(".vsi", ".tif")
)
else:
curr_output_path = (output_path + "/" + curr_input_path.split(input_path)[-1]).replace(".vsi", ".tif")

try:
cellsens2tif(
Expand Down
4 changes: 4 additions & 0 deletions vsi2tif/vsi2tif.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def main():
parser.add_argument("-q", "--quality", help="compression quality used with JPEG compression", default=85)
parser.add_argument("-m", "--max-mem", help="set maximum memory in the java vm", default=32)
parser.add_argument("-v", "--verbose", help="set verbosity level", default=1, type=int)
parser.add_argument(
"--remove-name-spaces", help="replace spaces in filename with underscores in batch mode", action="store_true"
)
argv = parser.parse_args()

if argv.verbose not in list(range(6)):
Expand Down Expand Up @@ -54,6 +57,7 @@ def main():
argv.quality,
argv.max_mem,
argv.verbose,
argv.remove_name_spaces,
)


Expand Down

0 comments on commit de92c1f

Please sign in to comment.