Skip to content

Commit 26a02fa

Browse files
stefanhahmannStefan Hahmann
authored andcommitted
Improve directory size calculation with Unix support and symbolic link handling
2 parents dbd500e + f217738 commit 26a02fa

15 files changed

Lines changed: 1091 additions & 72 deletions

File tree

src/main/java/org/mastodon/mamut/detection/DeepLearningDetector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import net.imglib2.view.IntervalView;
4242
import net.imglib2.view.Views;
4343

44-
import org.mastodon.mamut.util.ApposeProcess;
44+
import org.mastodon.mamut.util.appose.ApposeProcess;
4545
import org.mastodon.mamut.util.ByteFormatter;
4646
import org.mastodon.mamut.detection.util.SpimImageProperties;
4747
import org.mastodon.mamut.model.ModelGraph;

src/main/java/org/mastodon/mamut/detection/Segmentation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
import org.apposed.appose.NDArray;
4343
import org.apposed.appose.Service;
44-
import org.mastodon.mamut.util.ApposeProcess;
44+
import org.mastodon.mamut.util.appose.ApposeProcess;
4545
import org.slf4j.Logger;
4646
import org.slf4j.LoggerFactory;
4747

src/main/java/org/mastodon/mamut/detection/cellpose/Cellpose3.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@
3737
*/
3838
public class Cellpose3 extends Cellpose
3939
{
40+
public static final String ENV_NAME = "cellpose3";
41+
42+
public static final String ENV_FILE_CONTENT = "name: " + ENV_NAME + "\n"
43+
+ "channels:\n"
44+
+ " - nvidia\n"
45+
+ " - pytorch\n"
46+
+ " - conda-forge\n"
47+
+ "channel_priority: strict\n"
48+
+ "dependencies:\n"
49+
+ " - python=3.10\n"
50+
+ " - pip\n"
51+
+ " - pip:\n"
52+
+ " - cellpose==3.1.1.2\n"
53+
+ " - appose==" + APPOSE_PYTHON_VERSION + "\n"
54+
+ " - pytorch\n"
55+
+ " - pytorch-cuda\n"
56+
+ " - numpy\n";
57+
4058
private final ModelType modelType;
4159
private double anisotropy = 1;
4260

@@ -87,21 +105,7 @@ protected String getEvaluateModelCommand()
87105
@Override
88106
protected String generateEnvFileContent()
89107
{
90-
return "name: cellpose3\n"
91-
+ "channels:\n"
92-
+ " - nvidia\n"
93-
+ " - pytorch\n"
94-
+ " - conda-forge\n"
95-
+ "channel_priority: strict\n"
96-
+ "dependencies:\n"
97-
+ " - python=3.10\n"
98-
+ " - pip\n"
99-
+ " - pip:\n"
100-
+ " - cellpose==3.1.1.2\n"
101-
+ getApposePythonVersion()
102-
+ " - pytorch\n"
103-
+ " - pytorch-cuda\n"
104-
+ " - numpy\n";
108+
return ENV_FILE_CONTENT;
105109
}
106110

107111
public enum ModelType

src/main/java/org/mastodon/mamut/detection/cellpose/Cellpose4.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@
3636
*/
3737
public class Cellpose4 extends Cellpose
3838
{
39+
public static final String ENV_NAME = "cellpose4";
40+
41+
public static final String ENV_FILE_CONTENT = "name: " + ENV_NAME + "\n"
42+
+ "channels:\n"
43+
+ " - nvidia\n"
44+
+ " - pytorch\n"
45+
+ " - conda-forge\n"
46+
+ "channel_priority: strict\n"
47+
+ "dependencies:\n"
48+
+ " - python=3.10\n"
49+
+ " - cellpose==4.0.6\n"
50+
+ " - pytorch\n"
51+
+ " - pytorch-cuda\n"
52+
+ " - numpy\n"
53+
+ " - pip\n"
54+
+ " - pip:\n"
55+
+ " - appose==" + APPOSE_PYTHON_VERSION + "\n";
56+
3957
public Cellpose4() throws IOException
4058
{
4159
super();
@@ -66,21 +84,6 @@ protected String getEvaluateModelCommand()
6684
@Override
6785
protected String generateEnvFileContent()
6886
{
69-
return "name: cellpose4\n"
70-
+ "channels:\n"
71-
+ " - nvidia\n"
72-
+ " - pytorch\n"
73-
+ " - conda-forge\n"
74-
+ "channel_priority: strict\n"
75-
+ "dependencies:\n"
76-
+ " - python=3.10\n"
77-
+ " - cellpose==4.0.6\n"
78-
// + getApposeVersion().substring( 2 ) + "\n"
79-
+ " - pytorch\n"
80-
+ " - pytorch-cuda\n"
81-
+ " - numpy\n"
82-
+ " - pip\n"
83-
+ " - pip:\n"
84-
+ " " + getApposePythonVersion() + "\n";
87+
return ENV_FILE_CONTENT;
8588
}
8689
}

src/main/java/org/mastodon/mamut/detection/stardist/StarDist.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@
5757
*/
5858
public class StarDist extends Segmentation
5959
{
60+
public static final String ENV_NAME = "stardist";
61+
62+
public static final String ENV_FILE_CONTENT = "name: " + ENV_NAME + "\n"
63+
+ "channels:\n"
64+
+ " - conda-forge\n"
65+
+ "channel_priority: strict\n"
66+
+ "dependencies:\n"
67+
+ " - python=3.10\n"
68+
+ getCuda()
69+
+ " - numpy<1.24\n"
70+
+ " - pip\n"
71+
+ " - pip:\n"
72+
+ " - numpy<1.24\n"
73+
+ getTensorflow()
74+
+ " - stardist==0.8.5\n"
75+
+ " - appose==" + APPOSE_PYTHON_VERSION + "\n";
76+
6077
private static final Logger logger = LoggerFactory.getLogger( MethodHandles.lookup().lookupClass() );
6178

6279
private final ModelType modelType;
@@ -146,31 +163,18 @@ private static void createConfigFromBioimageio( final ModelDescriptor descriptor
146163
@Override
147164
protected String generateEnvFileContent()
148165
{
149-
return "name: stardist\n"
150-
+ "channels:\n"
151-
+ " - conda-forge\n"
152-
+ "channel_priority: strict\n"
153-
+ "dependencies:\n"
154-
+ " - python=3.10\n"
155-
+ getCuda()
156-
+ " - numpy<1.24\n"
157-
+ " - pip\n"
158-
+ " - pip:\n"
159-
+ " - numpy<1.24\n"
160-
+ getTensorflow()
161-
+ " - stardist==0.8.5\n"
162-
+ getApposePythonVersion();
166+
return ENV_FILE_CONTENT;
163167
}
164168

165-
private String getCuda()
169+
private static String getCuda()
166170
{
167171
if ( System.getProperty( "os.name" ).toLowerCase().contains( "mac" ) )
168172
return "";
169173
return " - cudatoolkit=11.2\n"
170174
+ " - cudnn=8.1.0\n";
171175
}
172176

173-
private String getTensorflow()
177+
private static String getTensorflow()
174178
{
175179
if ( System.getProperty( "os.name" ).toLowerCase().contains( "mac" ) )
176180
return " - tensorflow-macos==2.10\n"

src/main/java/org/mastodon/mamut/linking/trackastra/TrackastraUtils.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,27 @@
1111
import java.util.HashMap;
1212
import java.util.Map;
1313

14+
import org.mastodon.mamut.util.appose.ApposeProcess;
1415
import org.mastodon.tracking.detection.DetectorKeys;
1516

1617
public class TrackastraUtils
1718
{
19+
1820
public static final String TRACKASTRA_VERSION = "0.4.2";
1921

22+
public static final String ENV_NAME = "trackastra";
23+
24+
public static final String ENV_FILE_CONTENT = "name: " + ENV_NAME + "\n"
25+
+ "channels:\n"
26+
+ " - conda-forge\n"
27+
+ "channel_priority: strict\n"
28+
+ "dependencies:\n"
29+
+ " - python=3.10\n"
30+
+ " - pip\n"
31+
+ " - pip:\n"
32+
+ " - appose==" + ApposeProcess.APPOSE_PYTHON_VERSION + "\n"
33+
+ " - trackastra==" + TRACKASTRA_VERSION + "\n";
34+
2035
public static final String KEY_EDGE_THRESHOLD = "trackastraEdgeThreshold";
2136

2237
public static final String KEY_TRACKASTRA_MODE = "trackastraMode";
@@ -46,18 +61,9 @@ private TrackastraUtils()
4661
// prevent instantiation
4762
}
4863

49-
public static String getEnv( final String apposeVersion )
64+
public static String getEnv()
5065
{
51-
return "name: trackastra\n"
52-
+ "channels:\n"
53-
+ " - conda-forge\n"
54-
+ "channel_priority: strict\n"
55-
+ "dependencies:\n"
56-
+ " - python=3.10\n"
57-
+ " - pip\n"
58-
+ " - pip:\n"
59-
+ apposeVersion + "\n"
60-
+ " - trackastra==" + TRACKASTRA_VERSION + "\n";
66+
return ENV_FILE_CONTENT;
6167
}
6268

6369
public static Map< String, Object > getDefaultTrackAstraSettingsMap()

src/main/java/org/mastodon/mamut/linking/trackastra/appose/computation/LinkPrediction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.mastodon.mamut.linking.trackastra.TrackastraUtils;
3030
import org.mastodon.mamut.linking.trackastra.appose.types.RegionProps;
3131
import org.mastodon.mamut.model.Spot;
32-
import org.mastodon.mamut.util.ApposeProcess;
32+
import org.mastodon.mamut.util.appose.ApposeProcess;
3333
import org.mastodon.mamut.util.ResourceUtils;
3434
import org.mastodon.spatial.SpatioTemporalIndex;
3535
import org.mastodon.tracking.linking.EdgeCreator;
@@ -179,7 +179,7 @@ private float getFloat( RandomAccess< ? > ra, int col, int row )
179179
@Override
180180
protected String generateEnvFileContent()
181181
{
182-
return TrackastraUtils.getEnv( getApposePythonVersion() );
182+
return TrackastraUtils.getEnv();
183183
}
184184

185185
@Override

src/main/java/org/mastodon/mamut/linking/trackastra/appose/computation/RegionPropsComputation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import org.mastodon.mamut.linking.trackastra.TrackastraUtils;
3434
import org.mastodon.mamut.linking.trackastra.appose.types.SingleTimepointRegionProps;
3535
import org.mastodon.mamut.model.Spot;
36-
import org.mastodon.mamut.util.ApposeProcess;
36+
import org.mastodon.mamut.util.appose.ApposeProcess;
3737
import org.mastodon.mamut.util.ImgUtils;
3838
import org.mastodon.mamut.util.ResourceUtils;
3939
import org.mastodon.spatial.SpatioTemporalIndex;
@@ -164,7 +164,7 @@ private void formatProgress( final int done, final int todo )
164164
@Override
165165
protected String generateEnvFileContent()
166166
{
167-
return TrackastraUtils.getEnv( getApposePythonVersion() );
167+
return TrackastraUtils.getEnv();
168168
}
169169

170170
@Override
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*-
2+
* #%L
3+
* mastodon-deep-lineage
4+
* %%
5+
* Copyright (C) 2022 - 2025 Stefan Hahmann
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
package org.mastodon.mamut.util.appose;
30+
31+
import static org.mastodon.app.ui.ViewMenuBuilder.item;
32+
import static org.mastodon.app.ui.ViewMenuBuilder.menu;
33+
34+
import java.util.Collections;
35+
import java.util.List;
36+
37+
import javax.swing.SwingUtilities;
38+
39+
import org.mastodon.app.ui.ViewMenuBuilder;
40+
import org.mastodon.mamut.KeyConfigScopes;
41+
import org.mastodon.mamut.ProjectModel;
42+
import org.mastodon.mamut.plugin.MamutPlugin;
43+
import org.mastodon.ui.keymap.KeyConfigContexts;
44+
import org.scijava.AbstractContextual;
45+
import org.scijava.command.CommandService;
46+
import org.scijava.plugin.Parameter;
47+
import org.scijava.plugin.Plugin;
48+
import org.scijava.ui.behaviour.io.gui.CommandDescriptionProvider;
49+
import org.scijava.ui.behaviour.io.gui.CommandDescriptions;
50+
import org.scijava.ui.behaviour.util.AbstractNamedAction;
51+
import org.scijava.ui.behaviour.util.Actions;
52+
import org.scijava.ui.behaviour.util.RunnableAction;
53+
54+
@SuppressWarnings( "unused" )
55+
@Plugin( type = MamutPlugin.class )
56+
public class ApposeEnvsPlugin extends AbstractContextual implements MamutPlugin
57+
{
58+
private static final String COMMAND_NAME = "Python environments for detectors/linkers";
59+
60+
private static final String[] SHORT_CUT = { "ctrl shift P" };
61+
62+
private final AbstractNamedAction action;
63+
64+
@SuppressWarnings( "unused" )
65+
@Parameter
66+
private CommandService commandService;
67+
68+
@SuppressWarnings( "unused" )
69+
public ApposeEnvsPlugin()
70+
{
71+
action = new RunnableAction( COMMAND_NAME, this::open );
72+
}
73+
74+
@Override
75+
public void setAppPluginModel( final ProjectModel projectModel )
76+
{
77+
// Nothing to do
78+
}
79+
80+
@Override
81+
public List< ViewMenuBuilder.MenuItem > getMenuItems()
82+
{
83+
return Collections.singletonList(
84+
menu( "Plugins", menu( "Tracking", item( COMMAND_NAME ) ) ) );
85+
}
86+
87+
@Override
88+
public void installGlobalActions( Actions actions )
89+
{
90+
actions.namedAction( action, SHORT_CUT );
91+
}
92+
93+
private void open()
94+
{
95+
SwingUtilities.invokeLater( () -> {
96+
PythonEnvironmentManagerUI dialog = new PythonEnvironmentManagerUI( null );
97+
dialog.setVisible( true );
98+
} );
99+
}
100+
101+
/*
102+
* Command descriptions for all provided commands
103+
*/
104+
@Plugin( type = CommandDescriptionProvider.class )
105+
public static class Descriptions extends CommandDescriptionProvider
106+
{
107+
public Descriptions()
108+
{
109+
super( KeyConfigScopes.MAMUT, KeyConfigContexts.MASTODON );
110+
}
111+
112+
@Override
113+
public void getCommandDescriptions( final CommandDescriptions descriptions )
114+
{
115+
descriptions.add(
116+
COMMAND_NAME, SHORT_CUT,
117+
"Open the Python environment manager." );
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)