Skip to content

Commit 80deb24

Browse files
committed
ADD2/2: CreateNewDatasetFromImage
1 parent 513f062 commit 80deb24

File tree

1 file changed

+191
-0
lines changed

1 file changed

+191
-0
lines changed
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
package cz.it4i.fiji.legacy;
2+
3+
import com.fasterxml.jackson.core.JsonProcessingException;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
6+
import java.util.ArrayList;
7+
import java.util.Arrays;
8+
import java.util.Collections;
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
import java.util.concurrent.ExecutionException;
12+
import java.util.concurrent.Future;
13+
14+
import cz.it4i.fiji.legacy.util.Imglib2Types;
15+
import net.imagej.Dataset;
16+
import net.imagej.ImgPlus;
17+
import net.imglib2.type.numeric.RealType;
18+
import org.scijava.ItemIO;
19+
import org.scijava.ItemVisibility;
20+
import org.scijava.command.Command;
21+
import org.scijava.command.CommandInfo;
22+
import org.scijava.command.CommandModule;
23+
import org.scijava.command.CommandService;
24+
import org.scijava.log.LogLevel;
25+
import org.scijava.log.LogService;
26+
import org.scijava.log.Logger;
27+
import org.scijava.plugin.Parameter;
28+
import org.scijava.plugin.Plugin;
29+
30+
import cz.it4i.fiji.legacy.util.GuiResolutionLevelParams;
31+
import cz.it4i.fiji.rest.util.DatasetInfo;
32+
33+
@Plugin(type = Command.class, headless = true, menuPath = "Plugins>HPC DataStore>Create>Create new dataset from current image")
34+
public class CreateNewDatasetFromImage implements Command {
35+
@Parameter(label = "URL of a DatasetsRegisterService:", persistKey = "datasetserverurl")
36+
public String url = "someHostname:9080";
37+
38+
@Parameter(label="Dataset label:")
39+
public String label = "provide some nickname of this dataset";
40+
41+
@Parameter(label="Voxel type:", visibility = ItemVisibility.MESSAGE, required = false, persist = false)
42+
String voxelType;
43+
44+
int fullResSizeX;
45+
int fullResSizeY;
46+
int fullResSizeZ;
47+
48+
void readParams() {
49+
voxelType = Imglib2Types.getTypeHandler(refDatasetImg.getType()).httpType;
50+
fullResSizeX = (int)refDatasetImg.dimension(0);
51+
fullResSizeY = (int)refDatasetImg.dimension(1);
52+
fullResSizeZ = refDatasetImg.numDimensions() > 2 ? (int)refDatasetImg.dimension(2) : 1;
53+
54+
final ImgPlus<?> ip = refDatasetImg.getImgPlus();
55+
res_unit = ip.axis(0).unit();
56+
res_x = ip.axis(0).calibratedValue(1);
57+
res_y = ip.axis(1).calibratedValue(1);
58+
if (refDatasetImg.numDimensions() > 2)
59+
res_z = ip.axis(2).calibratedValue(1);
60+
}
61+
62+
@Parameter(label = "Total number of time points:", min = "1")
63+
public int timepoints = 1;
64+
@Parameter(label = "Total number of channels:", min = "1")
65+
public int channels = 1;
66+
@Parameter(label = "Total number of view angles:", min = "1")
67+
public int angles = 1;
68+
69+
@Parameter(label = "Physical dimension of one voxel in x:", min = "0", initializer = "readParams")
70+
public double res_x;
71+
@Parameter(label = "Physical dimension of one voxel in y:", min = "0")
72+
public double res_y;
73+
@Parameter(label = "Physical dimension of one voxel in z:", min = "0")
74+
public double res_z;
75+
@Parameter(label = "Physical unit of the voxel dimension:", description = "microns")
76+
public String res_unit;
77+
78+
@Parameter(label = "Time period between successive time points:", min = "0")
79+
public double time_res = 1.0;
80+
@Parameter(label = "Unit of the time period:", description = "seconds")
81+
public String time_unit = "seconds";
82+
83+
@Parameter(label = "Resolution among the channels:")
84+
public double channel_res = 1.0;
85+
@Parameter(label = "Unit of channels' resolution:", description = "channel")
86+
public String channel_unit = "channel";
87+
88+
@Parameter(label = "Resolution among the angles:")
89+
public double angle_res = 1.0;
90+
@Parameter(label = "Unit of angles' resolution:", description = "deg")
91+
public String angle_unit = "deg";
92+
93+
@Parameter(label = "Number of resolution levels:", min = "1",
94+
description = "There will always be the full-resolution level [1,1,1] plus additional lower-resolution ones.")
95+
public int numberOfAllResLevels = 1;
96+
97+
@Parameter(label = "Compression of the stored data:", choices = { "none", "gzip" })
98+
public String compression = "gzip";
99+
100+
@Parameter
101+
public Dataset refDatasetImg;
102+
103+
@Parameter
104+
public CommandService cs;
105+
106+
@Parameter
107+
public LogService mainLogger;
108+
protected Logger myLogger;
109+
110+
@Parameter(label = "Report corresponding macro command:", required = false)
111+
public boolean showRunCmd = false;
112+
113+
@Parameter(type = ItemIO.OUTPUT, label="UUID of the created dataset:")
114+
public String newDatasetUUID;
115+
@Parameter(type = ItemIO.OUTPUT, label="Label of the created dataset:")
116+
public String newDatasetLabel;
117+
118+
@Override
119+
public void run() {
120+
//logging facility
121+
myLogger = mainLogger.subLogger("HPC CreateDataset", LogLevel.INFO);
122+
123+
DatasetInfo di = new DatasetInfo();
124+
di.voxelType = this.voxelType;
125+
di.dimensions = Arrays.asList(fullResSizeX,fullResSizeY,fullResSizeZ);
126+
di.timepoints = this.timepoints;
127+
di.channels = this.channels;
128+
di.angles = this.angles;
129+
130+
di.voxelUnit = res_unit;
131+
di.voxelResolution = Arrays.asList(res_x,res_y,res_z);
132+
133+
di.timepointResolution = new DatasetInfo.ResolutionWithOwnUnit(time_res, time_unit);
134+
di.channelResolution = new DatasetInfo.ResolutionWithOwnUnit(channel_res, channel_unit);
135+
di.angleResolution = new DatasetInfo.ResolutionWithOwnUnit(angle_res, angle_unit);
136+
137+
di.compression = this.compression.equals("none") ? "raw" : this.compression;
138+
139+
di.versions = Collections.emptyList();
140+
di.resolutionLevels = new ArrayList<>(numberOfAllResLevels);
141+
di.label = label;
142+
143+
final CommandInfo rldlg_ci = new CommandInfo(GuiResolutionLevelParams.class);
144+
final Map<String,Object> rldlg_presets = new HashMap<>(4);
145+
try {
146+
for (int levelCnt = 1; levelCnt <= numberOfAllResLevels; ++levelCnt) {
147+
rldlg_presets.put("resLevelNumber", levelCnt);
148+
if (levelCnt == 1) {
149+
rldlg_presets.put("down_x", 1);
150+
rldlg_presets.put("down_y", 1);
151+
rldlg_presets.put("down_z", 1);
152+
}
153+
154+
final Future<CommandModule> rldlg_result = cs.run(rldlg_ci, true, rldlg_presets);
155+
final GuiResolutionLevelParams rldlg_obj = (GuiResolutionLevelParams)rldlg_result.get().getCommand();
156+
if (!rldlg_obj.userClickedOK) return; //stops the whole thing!
157+
158+
di.resolutionLevels.add(new DatasetInfo.ResolutionLevel(
159+
rldlg_obj.down_x,rldlg_obj.down_y,rldlg_obj.down_z,
160+
rldlg_obj.block_x,rldlg_obj.block_y,rldlg_obj.block_z ));
161+
162+
if (levelCnt == 1) {
163+
rldlg_presets.remove("down_x");
164+
rldlg_presets.remove("down_y");
165+
rldlg_presets.remove("down_z");
166+
}
167+
}
168+
169+
//finish it up with the resolutions...
170+
for (DatasetInfo.ResolutionLevel l : di.resolutionLevels)
171+
l.setDimensions(di.dimensions);
172+
173+
myLogger.info("============ collected this params: ===============");
174+
myLogger.info(di);
175+
176+
final String json = new ObjectMapper().writeValueAsString(di);
177+
myLogger.info("CREATED JSON:\n"+json);
178+
179+
final Future<CommandModule> subcall = cs.run(CreateNewDatasetFromJSON.class, true,
180+
"url",url, "json",json, "showRunCmd",showRunCmd);
181+
newDatasetUUID = (String)subcall.get().getOutput("newDatasetUUID");
182+
newDatasetLabel = di.getLabel();
183+
} catch (ExecutionException e) {
184+
e.printStackTrace();
185+
} catch (InterruptedException e) {
186+
//dialog interrupted, do nothing special...
187+
} catch (JsonProcessingException e) {
188+
myLogger.error("Error converting dataset description into JSON:"+e.getMessage());
189+
}
190+
}
191+
}

0 commit comments

Comments
 (0)