Skip to content

Commit

Permalink
Command fluidimage-mean
Browse files Browse the repository at this point in the history
  • Loading branch information
paugier committed May 23, 2024
1 parent 2ab1049 commit 9c9213b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ fluidimage-monitor = "fluidimage.gui.monitor:main"
fluidimviewer = "fluidimage.gui.imviewer:main"
fluidimviewer-pg = "fluidimage.gui.pg_main:main"
fluidpivviewer = "fluidimage.gui.piv_viewer:main"
fluidimage-mean = "fluidimage.topologies.mean:main"

[project.optional-dependencies]
pims = ["pims"]
Expand Down
64 changes: 62 additions & 2 deletions src/fluidimage/topologies/mean.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
"""

import argparse
import os
from pathlib import Path

import h5py
import numpy as np

import fluidimage
from fluiddyn.io.image import imsave
from fluiddyn.util.serieofarrays import SerieOfArraysFromFiles
from fluidimage import ParamContainer
Expand Down Expand Up @@ -151,10 +154,67 @@ def final_seq_work(self):

assert len(queue_tmp_arrays) == 1
arr, num_images = queue_tmp_arrays[0]
self.result = arr / num_images
self.result = (arr / num_images).astype(np.uint8)
self.results.append(num_images)

self.path_result = self.path_dir_result.with_name(
self.path_dir_result.name + ".tiff"
self.path_dir_result.name + ".png"
)
imsave(self.path_result, self.result)


def parse_args():
"""Parse the arguments of the command line"""

parser = argparse.ArgumentParser(
description=TopologyMeanImage.__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument(
"path",
help="Path file or directory.",
type=str,
nargs="?",
default=os.getcwd(),
)
parser.add_argument("-v", "--verbose", help="verbose mode", action="count")
parser.add_argument(
"-V",
"--version",
help="Print fluidimage version and exit",
action="count",
)

parser.add_argument(
"-np",
"--nb-max-workers",
help="Maximum number of workers/processes.",
type=int,
default=None,
)

parser.add_argument(
"--executor",
help="Name of the executor.",
type=str,
default=None,
)

return parser.parse_args()


Topology = TopologyMeanImage


def main():
"""Main function for fluidimage-mean"""
args = parse_args()

if args.version:
print(f"fluidimage {fluidimage.__version__}")
return

params = Topology.create_default_params()
params.images.path = str(args.path)
topology = Topology(params)
topology.compute(args.executor, nb_max_workers=args.nb_max_workers)

0 comments on commit 9c9213b

Please sign in to comment.