Skip to content

Commit 05551cb

Browse files
authored
Add Podman functionality where we have Docker functionality (#274)
* Draft 1 of Podman * First draft of changes for ilastik * update docstring
1 parent 9036c78 commit 05551cb

File tree

2 files changed

+41
-33
lines changed

2 files changed

+41
-33
lines changed

active_plugins/runcellpose.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@
6161
You can run this module using Cellpose installed to the same Python environment as CellProfiler.
6262
See our documentation at https://plugins.cellprofiler.org/runcellpose.html for more information on installation.
6363
64-
Alternatively, you can run this module using Cellpose in a Docker that the module will automatically download for you so you do not have to perform any installation yourself.
64+
Alternatively, you can run this module using Cellpose in a Docker or Podman container that the module will automatically download for you so you do not have to perform any installation yourself.
6565
6666
On the first time loading into CellProfiler, Cellpose will need to download some model files from the internet. This
6767
may take some time. If you want to use a GPU to run the model, you'll need a compatible version of PyTorch and a
6868
supported GPU. Instructions are avaiable at this link: {CUDA_LINK}
6969
70-
Note that RunCellpose supports the Cellpose 3 functionality of using image restoration models to improve the input images before segmentation for both Docker and Python methods.
70+
Note that RunCellpose supports the Cellpose 3 functionality of using image restoration models to improve the input images before segmentation for both container and Python methods.
7171
However, it only supports saving out or visualizing the intermediate restored images when using the Python method.
7272
7373
Stringer, C., Wang, T., Michaelos, M. et al. Cellpose: a generalist algorithm for cellular segmentation. Nat Methods 18, 100–106 (2021). {Cellpose_link}
@@ -137,19 +137,20 @@ def create_settings(self):
137137
text="Rescale images before running Cellpose",
138138
value=True,
139139
doc="""\
140-
Reminds the user that the normalization step will be performed to ensure suimilar segmentation behaviour in the RunCellpose
140+
Reminds the user that the normalization step will be performed to ensure similar segmentation behaviour in the RunCellpose
141141
module and the Cellpose app.
142142
"""
143143
)
144144

145145

146146
self.docker_or_python = Choice(
147-
text="Run CellPose in docker or local python environment",
148-
choices=["Docker", "Python"],
147+
text="Run CellPose in a Docker/Podman container or local python environment",
148+
choices=["Docker", "Podman", "Python"],
149149
value="Docker",
150150
doc="""\
151151
If Docker is selected, ensure that Docker Desktop is open and running on your
152-
computer. On first run of the RunCellpose plugin, the Docker container will be
152+
computer; likewise for Podman, ensure Podman Desktop is running. On first run
153+
of the RunCellpose plugin, the Docker container will be
153154
downloaded. However, this slow downloading process will only have to happen
154155
once.
155156
@@ -539,7 +540,7 @@ def visible_settings(self):
539540
if self.cellpose_version.value == 'omnipose':
540541
vis_settings += [self.omni]
541542

542-
if self.docker_or_python.value == "Docker":
543+
if self.docker_or_python.value in ["Docker","Podman"]:
543544
if self.cellpose_version.value == 'omnipose':
544545
vis_settings += [self.docker_image_omnipose]
545546
elif self.cellpose_version.value == 'v2':
@@ -936,9 +937,12 @@ def run(self, workspace):
936937
if self.remove_edge_masks:
937938
y_data = utils.remove_edge_masks(y_data)
938939

939-
elif self.docker_or_python.value == "Docker":
940-
# Define how to call docker
941-
docker_path = "docker" if sys.platform.lower().startswith("win") else "/usr/local/bin/docker"
940+
else:
941+
if self.docker_or_python.value == "Docker":
942+
# Define how to call docker
943+
docker_path = "docker" if sys.platform.lower().startswith("win") else "/usr/local/bin/docker"
944+
else:
945+
docker_path = "podman" if sys.platform.lower().startswith("win") else "/opt/podman/bin/podman"
942946
# Create a UUID for this run
943947
unique_name = str(uuid.uuid4())
944948
# Directory that will be used to pass images to the docker container
@@ -1021,7 +1025,7 @@ def run(self, workspace):
10211025
workspace.display_data.denoised_image = denoised_image
10221026

10231027
if self.save_probabilities.value:
1024-
if self.docker_or_python.value == "Docker":
1028+
if self.docker_or_python.value in ["Docker", "Podman"]:
10251029
# get rid of extra dimension
10261030
prob_map = numpy.squeeze(flows[1], axis=0) # ranges 0-255
10271031
else:

active_plugins/runilastik.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,13 @@ def create_settings(self):
8282
super(Runilastik, self).create_settings()
8383

8484
self.docker_or_local = Choice(
85-
text="Run ilastik in docker or local environment",
86-
choices=["Docker", "Local"],
85+
text="Run ilastik in a container (Docker or Podman) or local environment",
86+
choices=["Docker", "Podman", "Local"],
8787
value="Docker",
8888
doc="""\
8989
If Docker is selected, ensure that Docker Desktop is open and running on your
90-
computer. On first run of the Runilastik plugin, the Docker container will be
90+
computer; likewise for Podman, ensure Podman Desktop is running. On first run
91+
of the Runilastik plugin, the Docker container will be
9192
downloaded. However, this slow downloading process will only have to happen
9293
once.
9394
@@ -165,7 +166,7 @@ def settings(self):
165166
def visible_settings(self):
166167

167168
vis_settings = [self.docker_or_local]
168-
if self.docker_or_local.value == "Docker":
169+
if self.docker_or_local.value in ["Docker","Podman"]:
169170
vis_settings += [self.docker_choice]
170171

171172
if self.docker_choice == "select your own":
@@ -225,9 +226,27 @@ def run(self, workspace):
225226

226227
fout.close()
227228

228-
if self.docker_or_local.value == "Docker":
229-
# Define how to call docker
230-
docker_path = "docker" if sys.platform.lower().startswith("win") else "/usr/local/bin/docker"
229+
if self.docker_or_local.value == "Local":
230+
231+
if self.executable.value[-4:] == ".app":
232+
executable = os.path.join(self.executable.value, "Contents/MacOS/ilastik")
233+
else:
234+
executable = self.executable.value
235+
236+
fout_name = fout.name
237+
fin_name = fin.name
238+
239+
cmd = [
240+
executable,
241+
"--headless",
242+
"--project", self.project_file.value]
243+
244+
else:
245+
if self.docker_or_local.value == "Docker":
246+
# Define how to call docker
247+
docker_path = "docker" if sys.platform.lower().startswith("win") else "/usr/local/bin/docker"
248+
else:
249+
docker_path = "podman" if sys.platform.lower().startswith("win") else "/opt/podman/bin/podman"
231250
# The project file is stored in a directory which can be pointed to the docker
232251
model_file = self.project_file.value
233252
model_directory = os.path.dirname(os.path.abspath(model_file))
@@ -250,21 +269,6 @@ def run(self, workspace):
250269
"--project", f"/model/{os.path.basename(model_file)}"
251270
]
252271

253-
if self.docker_or_local.value == "Local":
254-
255-
if self.executable.value[-4:] == ".app":
256-
executable = os.path.join(self.executable.value, "Contents/MacOS/ilastik")
257-
else:
258-
executable = self.executable.value
259-
260-
fout_name = fout.name
261-
fin_name = fin.name
262-
263-
cmd = [
264-
executable,
265-
"--headless",
266-
"--project", self.project_file.value]
267-
268272
cmd += ["--output_format", "hdf5"]
269273

270274

0 commit comments

Comments
 (0)