Skip to content

Commit

Permalink
Recyze updates (#523)
Browse files Browse the repository at this point in the history
* Apply proper ome-xml encoding

This avoids errors from tifffile about the imagedescription value, allowing us
to use newer versions of ome-types which are faster and produce nicer output.

* Add parallelization management

* Improve --channels help message

* Bump default roadie version and switch to ghcr
  • Loading branch information
jmuhlich authored Oct 26, 2023
1 parent 94b3c65 commit 7a67ffd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion nextflow.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Execution environment for miscellaneous tasks
params.roadie = 'labsyspharm/roadie:2023-03-08'
params.roadie = 'ghcr.io/labsyspharm/mcmicro:roadie-2023-10-25'

// Platform-specific profiles
profiles {
Expand Down
20 changes: 18 additions & 2 deletions roadie/scripts/recyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def run(self):
self.metadata.images[0].pixels.tiff_data_blocks[0].plane_count = self.num_channels

# Write
tifffile.tiffcomment(self.out_path, to_xml(self.metadata))
tifffile.tiffcomment(self.out_path, to_xml(self.metadata).encode())


if __name__ == '__main__':
Expand All @@ -236,7 +236,14 @@ def run(self):
parser.add_argument('--y2', type=int, required=False, default=None, help="Crop Y2")
parser.add_argument('--w', type=int, required=False, default=None, help="Crop Width")
parser.add_argument('--h', type=int, required=False, default=None, help="Crop Height")
parser.add_argument('--channels', type=int, nargs="+", required=False, default=None, help="Channels")
parser.add_argument(
'--channels', type=int, nargs="+", required=False, default=None, metavar="C",
help="Channels to keep (Default: all)",
)
parser.add_argument(
'--num-threads', type=int, required=False, default=0, metavar="N",
help="Worker thread count (Default: auto-scale based on number of available CPUs)",
)
argument = parser.parse_args()

# Automatically infer the output filename, if not specified
Expand All @@ -256,6 +263,15 @@ def run(self):
stem = os.extsep.join(tokens[0:-1]) + "_crop"
out_path = os.extsep.join([stem, tokens[-1]])

num_threads = argument.num_threads
if num_threads == 0:
if hasattr(os, "sched_getaffinity"):
num_threads = len(os.sched_getaffinity(0))
else:
num_threads = os.cpu_count()
tifffile.TIFF.MAXWORKERS = num_threads
tifffile.TIFF.MAXIOWORKERS = num_threads * 5

writer = PyramidWriter(in_path, out_path, argument.channels, argument.x, argument.y,
argument.x2, argument.y2, argument.w, argument.h)
writer.run()

0 comments on commit 7a67ffd

Please sign in to comment.