Skip to content

Commit 7864a17

Browse files
committed
update with params
1 parent f1c6c5b commit 7864a17

File tree

4 files changed

+169
-81
lines changed

4 files changed

+169
-81
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252
<!-- MainClass in mainfest make a executable jar -->
253253
<archive>
254254
<manifest>
255-
<mainClass>net.preibisch.fusiontask.task.MainJob</mainClass>
255+
<mainClass>net.preibisch.fusiontask.task.FusionV2</mainClass>
256256
</manifest>
257257
</archive>
258258

src/net/preibisch/fusiontask/task/Fusion.java

Lines changed: 0 additions & 77 deletions
This file was deleted.

src/net/preibisch/fusiontask/task/MainJob.java renamed to src/net/preibisch/fusiontask/task/FusionV1.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import picocli.CommandLine;
3030
import picocli.CommandLine.Option;
3131

32-
public class MainJob implements Callable<Void> {
32+
public class FusionV1 implements Callable<Void> {
3333
@Option(names = { "-t", "--task" }, required = false, description = "The path of the Data")
3434
private String task;
3535

@@ -50,7 +50,7 @@ public class MainJob implements Callable<Void> {
5050
@Option(names = { "-id" }, required = false, description = "The id of block")
5151
private Integer id;
5252

53-
public MainJob() {
53+
public FusionV1() {
5454
// TODO Auto-generated constructor stub
5555
}
5656

@@ -166,6 +166,6 @@ public static void main(String[] args) {
166166
// /Users/Marwan/Desktop/Task/output.n5 -m
167167
// /Users/Marwan/Desktop/Task/metadata.json -id 1";
168168
// System.out.println(String.join(" ", args));
169-
CommandLine.call(new MainJob(), args);
169+
CommandLine.call(new FusionV1(), args);
170170
}
171171
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
package net.preibisch.fusiontask.task;
2+
3+
import java.io.IOException;
4+
import java.util.List;
5+
import java.util.concurrent.Callable;
6+
7+
import org.janelia.saalfeldlab.n5.N5FSWriter;
8+
import org.janelia.saalfeldlab.n5.N5Writer;
9+
import org.janelia.saalfeldlab.n5.RawCompression;
10+
import org.janelia.saalfeldlab.n5.imglib2.N5Utils;
11+
12+
import com.google.gson.JsonIOException;
13+
import com.google.gson.JsonSyntaxException;
14+
15+
import mpicbg.spim.data.SpimDataException;
16+
import mpicbg.spim.data.sequence.ViewId;
17+
import net.imglib2.RandomAccessibleInterval;
18+
import net.imglib2.type.numeric.real.FloatType;
19+
import net.preibisch.distribution.algorithm.blockmanager.block.BasicBlockInfo;
20+
import net.preibisch.distribution.algorithm.clustering.kafka.KafkaManager;
21+
import net.preibisch.distribution.algorithm.clustering.kafka.KafkaProperties;
22+
import net.preibisch.distribution.algorithm.clustering.scripting.TaskType;
23+
import net.preibisch.distribution.algorithm.controllers.items.BlocksMetaData;
24+
import net.preibisch.distribution.algorithm.task.FusionParams;
25+
import net.preibisch.distribution.io.img.XMLFile;
26+
import net.preibisch.distribution.io.img.n5.N5File;
27+
import net.preibisch.distribution.tools.Tools;
28+
import net.preibisch.mvrecon.fiji.spimdata.boundingbox.BoundingBox;
29+
import picocli.CommandLine;
30+
import picocli.CommandLine.Option;
31+
32+
public class FusionV2 implements Callable<Void> {
33+
@Option(names = { "-t", "--task" }, required = false, description = "The path of the Data")
34+
private String task;
35+
36+
@Option(names = { "-o", "--output" }, required = false, description = "The path of the Data")
37+
private String output;
38+
39+
@Option(names = { "-i", "--input" }, required = false, description = "The path of the Data")
40+
private String input;
41+
42+
@Option(names = { "-m", "--meta" }, required = false, description = "The path of the MetaData file")
43+
private String metadataPath;
44+
45+
@Option(names = { "-p", "--param" }, required = false, description = "The path of the MetaData file")
46+
private String paramPath;
47+
48+
@Option(names = { "-v","-view" }, required = false, description = "The id of block")
49+
private int view;
50+
@Option(names = { "-id" }, required = false, description = "The id of block")
51+
private Integer id;
52+
53+
public FusionV2() {
54+
// TODO Auto-generated constructor stub
55+
}
56+
57+
@Override
58+
public Void call() throws Exception {
59+
try {
60+
61+
try {
62+
id = id - 1;
63+
} catch (Exception e) {
64+
KafkaManager.error(-1, e.toString());
65+
System.out.println("Error id");
66+
throw new Exception("Specify id!");
67+
}
68+
TaskType type = TaskType.of(task);
69+
switch (type) {
70+
case PREPARE:
71+
generateN5(input, metadataPath,paramPath, output, id,view);
72+
return null;
73+
case PROCESS:
74+
blockTask(input, metadataPath, paramPath, output, id,view);
75+
return null;
76+
77+
default:
78+
KafkaManager.error(id, "Specify task");
79+
System.out.println("Error");
80+
throw new Exception("Specify task!");
81+
}
82+
} catch (Exception e) {
83+
KafkaManager.error(id, e.toString());
84+
System.out.println("Error");
85+
throw new Exception("Specify task!");
86+
}
87+
// MyLogger.log.info("Block " + id + " saved !");
88+
}
89+
90+
public static void blockTask(String inputPath, String metadataPath, String paramPath, String outputPath, int id,int view) {
91+
try {
92+
KafkaManager.log(id, "Start process");
93+
// XMLFile inputFile = XMLFile.XMLFile(inputPath);
94+
BlocksMetaData md = BlocksMetaData.fromJson(metadataPath);
95+
FusionParams params = FusionParams.fromJson(paramPath);
96+
String jobId = md.getJobId();
97+
KafkaProperties.setJobId(jobId);
98+
KafkaManager.log(id, "Got metadata !");
99+
BasicBlockInfo binfo = md.getBlocksInfo().get(id);
100+
KafkaManager.log(id, "Got block info !");
101+
// BoundingBox bb = new BoundingBox(Util.long2int(binfo.getMin()), Util.long2int(binfo.getMax()));
102+
KafkaManager.log(id, "Bounding box created: " + params.getBb().toString());
103+
List<ViewId> viewIds = params.getViewIds().get(view);
104+
KafkaManager.log(id, "Got view ids ");
105+
106+
XMLFile inputFile = XMLFile.XMLFile(inputPath, params.getBb(), params.getDownsampling(), viewIds);
107+
108+
KafkaManager.log(id, "Input loaded. ");
109+
// XMLFile inputFile = XMLFile.XMLFile(inputPath);
110+
RandomAccessibleInterval<FloatType> block = inputFile.fuse(params.getBb(),view);
111+
112+
KafkaManager.log(id, "Got block. ");
113+
N5File outputFile = N5File.open(outputPath);
114+
outputFile.saveBlock(block, binfo.getGridOffset());
115+
KafkaManager.log(id, "Task finished " + id);
116+
KafkaManager.done(id, "Task finished " + id);
117+
} catch (SpimDataException | IOException e) {
118+
KafkaManager.error(id, e.toString());
119+
e.printStackTrace();
120+
}
121+
}
122+
123+
public static void generateN5(String inputPath, String metadataPath,String paramPath, String outputPath, int id,int view) {
124+
try {
125+
KafkaManager.log(id, "Start generate n5");
126+
BlocksMetaData md = BlocksMetaData.fromJson(metadataPath);
127+
FusionParams params = FusionParams.fromJson(paramPath);
128+
BoundingBox bb = new BoundingBox(params.getBb());
129+
long[] dims = bb.getDimensions((int)params.getDownsampling());
130+
int blockUnit = md.getBlockUnit();
131+
N5File outputFile = new N5File(outputPath, dims, blockUnit);
132+
outputFile.create();
133+
KafkaManager.log(id, "N5 Generated");
134+
KafkaManager.done(id, "N5 Generated");
135+
} catch (JsonSyntaxException | JsonIOException | IOException e) {
136+
137+
KafkaManager.error(id, e.toString());
138+
e.printStackTrace();
139+
}
140+
}
141+
142+
public static void generateN5fromXML(String inputPath, String metadataPath, String outputPath, int id) {
143+
try {
144+
System.out.println("Start generating output");
145+
XMLFile inputFile = XMLFile.XMLFile(inputPath);
146+
RandomAccessibleInterval<FloatType> virtual = inputFile.fuse();
147+
String dataset = "/volumes/raw";
148+
N5Writer writer = new N5FSWriter(outputPath);
149+
BlocksMetaData md = BlocksMetaData.fromJson(metadataPath);
150+
// long[] dims = md.getDimensions();
151+
int blockUnit = md.getBlockUnit();
152+
int[] blocks = Tools.array(blockUnit, virtual.numDimensions());
153+
154+
N5Utils.save(virtual, writer, dataset, blocks, new RawCompression());
155+
System.out.println("Ouptut generated");
156+
} catch (SpimDataException | IOException e1) {
157+
// TODO Auto-generated catch block
158+
e1.printStackTrace();
159+
}
160+
}
161+
162+
public static void main(String[] args) {
163+
CommandLine.call(new FusionV2(), args);
164+
}
165+
}

0 commit comments

Comments
 (0)