Repository navigation
Open
Description
If I want to run a script, then I need to know the environment.
#@script(env="/Users/username/.local/share/appose/fiji-cellpose/pixi.toml")
import cellpose
from cellpose import models
import numpy
#@Img image
#@output Img masks
#@output Img flows
print(image.shape)
print(numpy.sum(image))
model = models.CellposeModel(gpu=True)
masks, flows, _ = model.eval(image, z_axis=0, do_3D=False, normalize=True, diameter=150)
flows = flows[0]
flows = numpy.rollaxis(flows, -1)
This works, but I know the existence of the pixi.toml. I could also build an environment using the following java program.
import org.apposed.appose.*;
import java.util.*;
public class ApposeBuilder{
//Toml to create a cellpose environment.
static final String toml = """
[workspace]
authors = [
"Smith, MB",
]
channels = ["conda-forge"]
name = "example-appose"
platforms = ["osx-arm64", "win-64", "linux-64", "osx-64"]
version = "0.1.0"
[dependencies]
python = ">3.10.3"
[pypi-dependencies]
cellpose = ">=4"
appose = ">=0.10.1"
""";
final static String command = """
import cellpose, sys, pathlib
ex = pathlib.Path(sys.executable)
#I could use this value with "wrap"
env = ex.parent.parent
#I can use this value with script parameter.
toml = env.parent.parent.parent / "pixi.toml"
"%s"%(toml, )
""";
public static void main(String[] args) throws Exception{
try( Service python = Appose.pixi().content(toml).build().python() ){
Map<String, Object> inputs = new HashMap<>();
Service.Task task = python.task(command, inputs);
task.start();
task.waitFor();
System.out.println(task.result());
}
}
}If I run that java program, then I will have a python environment with cellpose, and I know the location of the the pixi.toml that I need to point the script engine at. It would be nice if there was a consistent, platform independent way of naming/referencing an environment.
Metadata
Metadata
Assignees
Labels
No labels
Activity