Skip to content

Commit 4557532

Browse files
v1.1.0 about to be released - small fixes
1 parent 8456130 commit 4557532

1 file changed

Lines changed: 29 additions & 23 deletions

File tree

src/main/java/de/labathome/cli/IrbCli.java

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
import picocli.CommandLine.Option;
2323
import picocli.CommandLine.Parameters;
2424

25-
@Command(name = "irb", version = "irb 1.0.3", description = "Process *.irb files")
25+
@Command(name = "irb", version = "irb 1.1.0", description = "Process *.irb files")
2626
public class IrbCli implements Callable<Integer> {
2727

2828
@Parameters(index = "0", description = "The *.irb file to read.")
2929
private String filename;
3030

31-
@Option(names = {"-h", "--headless"}, description = "Save the image to disk instead of displaying it.")
31+
@Option(names = {"--headless"}, description = "Skip GUI plot using JyPlot and just dump image data to disk.")
3232
private boolean runHeadless;
3333

3434
public Integer call() throws Exception {
@@ -67,6 +67,7 @@ public Integer call() throws Exception {
6767
} catch (Exception e) {
6868
e.printStackTrace();
6969
}
70+
7071
if (!runHeadless) {
7172
// try to plot using JyPlot
7273
try {
@@ -94,8 +95,8 @@ public Integer call() throws Exception {
9495
if (irbFile.frames != null) {
9596
// have video frames -> dump them now
9697

97-
// parallelize over frames to get going...
98-
final int numThreads = 4;
98+
// parallelize over frames to speed up export
99+
final int numThreads = Runtime.getRuntime().availableProcessors();
99100
ExecutorService service = Executors.newFixedThreadPool(numThreads);
100101

101102
for (int frameIdx = 0; frameIdx < irbFile.frames.size(); ++frameIdx) {
@@ -112,25 +113,30 @@ public Integer call() throws Exception {
112113
final int finalImageIdx = imageIdx;
113114

114115
service.execute(() -> {
115-
System.out.printf("exporting %4d/%4d %4d/%4d...\n", finalFrameIdx+1, irbFile.frames.size(), finalImageIdx+1, frame.images.size());
116-
117-
// image.exportImageData(String.format(filename + ".img_%04d_%04d.dat", finalFrameIdx, finalImageIdx));
118-
// image.exportMetaData(String.format(filename + ".meta_%04d_%04d.json", finalFrameIdx, finalImageIdx));
119-
// ArrayToPNG.dumpAsPng(image.getCelsiusImage(), filename + String.format(".img_%04d_%04d.png", finalFrameIdx, finalImageIdx));
120-
121-
if (!runHeadless) {
122-
JyPlot plt = new JyPlot();
123-
124-
plt.figure();
125-
plt.imshow(image.getCelsiusImage(), "cmap=plt.get_cmap('jet')");
126-
// plt.imshow(image.getCelsiusImage(), "cmap=plt.get_cmap('gist_ncar')");
127-
// plt.imshow(image.getCelsiusImage(), "cmap=plt.get_cmap('nipy_spectral')");
128-
plt.colorbar();
129-
plt.title(String.format("frame %d, image %d", finalFrameIdx, finalImageIdx));
130-
plt.savefig(filename + String.format(".plot_%04d_%04d.png", finalFrameIdx, finalImageIdx));
131-
132-
plt.exec();
133-
}
116+
try {
117+
System.out.printf("exporting frame %4d/%4d...\n", finalFrameIdx+1, irbFile.frames.size());
118+
119+
image.exportImageData(String.format(filename + ".img_%04d_%04d.dat", finalFrameIdx, finalImageIdx));
120+
image.exportMetaData(String.format(filename + ".meta_%04d_%04d.json", finalFrameIdx, finalImageIdx));
121+
ArrayToPNG.dumpAsPng(image.getCelsiusImage(), filename + String.format(".img_%04d_%04d.png", finalFrameIdx, finalImageIdx));
122+
123+
if (!runHeadless) {
124+
JyPlot plt = new JyPlot();
125+
126+
plt.figure();
127+
plt.imshow(image.getCelsiusImage(), "cmap=plt.get_cmap('jet')");
128+
// plt.imshow(image.getCelsiusImage(), "cmap=plt.get_cmap('gist_ncar')");
129+
// plt.imshow(image.getCelsiusImage(), "cmap=plt.get_cmap('nipy_spectral')");
130+
plt.colorbar();
131+
plt.title(String.format("frame %d, image %d", finalFrameIdx, finalImageIdx));
132+
plt.savefig(filename + String.format(".plot_%04d_%04d.png", finalFrameIdx, finalImageIdx));
133+
134+
plt.exec();
135+
}
136+
} catch (Exception e) {
137+
// no chance to see if something within threads goes wrong, if not explicitly caught here...
138+
e.printStackTrace();
139+
}
134140
});
135141
}
136142
}

0 commit comments

Comments
 (0)