Skip to content

Commit

Permalink
Headless (#3)
Browse files Browse the repository at this point in the history
* feat: add headless mode
* bump version to 1.0.2

Co-authored-by: Benjamin Schilling <[email protected]>
Co-authored-by: Jonathan Schilling <[email protected]>
  • Loading branch information
3 people authored Jan 9, 2022
1 parent 0582ba3 commit 2e34043
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 35 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/target/

# output
*.irb
*.dat
*.png
*.json
*Zone.Identifier
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ or as a stand-alone commandline utility.
This is a pure hobby project. No copyright infringements or similar is intended.
Please inform the author about possible legal issues before turning to a lawyer.


## Building

1. Download and install build dependencies
Expand All @@ -22,7 +23,7 @@ Please inform the author about possible legal issues before turning to a lawyer.
> mvn clean package
```

The output will be at `target/irb-1.0.1.jar`.
The output will be at `target/irb-1.0.2.jar`.

## Use as a Maven dependency

Expand All @@ -32,19 +33,31 @@ You can include this project as a dependency in Maven:
<dependency>
<groupId>de.labathome</groupId>
<artifactId>irb</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
</dependency>
```

The ready-to-use jar can also be directly downloaded here:
[irb-1.0.1.jar](https://github.com/jonathanschilling/irb/releases/download/v1.0.1/irb-1.0.1.jar)
[irb-1.0.2.jar](https://github.com/jonathanschilling/irb/releases/download/v1.0.2/irb-1.0.2.jar)

## Command-line Usage

Run-time dependencies:
- Python3 packages
- matplotlib
- Requires libjpeg and zlib development headers for *pillow*
- numpy

Execute the jar with the `*.irb` file as first command line argument:

```bash
> java -jar irb-1.0.1.jar AB020300.irb
> java -jar irb-1.0.2.jar AB020300.irb
```

It can also be run in headless mode, where no attempt will be made to plot the image using JyPlot:

```bash
> java -jar irb-1.0.2.jar --headless AB020300.irb
```

This will generate two text output files and a direct PNG equivalent of the data:
Expand All @@ -57,8 +70,8 @@ This will generate two text output files and a direct PNG equivalent of the data
* `AB020300.irb.meta_0.json` contains the meta-data of the image in the JSON format.
* `AB020300.irb.img_0.png` contains a direct PNG export of the image data
with the temperature in degree Celsius mapped to a `jet`-like colorbar.
Additionally, a direct plot of the image is tried using `JyPlot`.

If not run in headless mode, a direct plot of the image is tried using `JyPlot`.
This requires to have a Python installation with `matplotlib` and `numpy` on your `$PATH`.
A temporary Python script file is created in a folder `PythonScript` in your home directory.
This will be executed by the default `python` command.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>

<artifactId>irb</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<packaging>jar</packaging>

<name>irb</name>
Expand Down
74 changes: 46 additions & 28 deletions src/main/java/de/labathome/IrbFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,68 +114,86 @@ public static void main(String[] args) {
if (args != null && args.length > 0) {

String filename = args[0];
boolean runHeadless = false;
if (args.length > 1){
String headless = args[0];
if (headless.equals("--headless")) {
runHeadless = true;
} else {
System.out.printf("option '%s' not understood\n", args[0]);
}
filename = args[1];
}

try {
System.out.println("Processing file: " + filename);
IrbFile irbFile = IrbFile.fromFile(filename);

System.out.println("number of images: "+irbFile.images.size());

int i=0;
int imageIndex=0;
for (IrbImage image: irbFile.images) {

System.out.println("\n\nimage " + i);
System.out.println("\n\nimage " + imageIndex);
System.out.printf(" env temp: %g °C\n", image.environmentalTemp - IrbImage.CELSIUS_OFFSET);
System.out.printf(" path temp: %g °C\n", image.pathTemperature - IrbImage.CELSIUS_OFFSET);
System.out.printf(" calib range min: %g °C\n", image.calibRangeMin - IrbImage.CELSIUS_OFFSET);
System.out.printf(" calib range max: %g °C\n", image.calibRangeMax - IrbImage.CELSIUS_OFFSET);
System.out.printf(" path temp: %g °C\n", image.pathTemperature - IrbImage.CELSIUS_OFFSET);
System.out.printf(" calib range min: %g °C\n", image.calibRangeMin - IrbImage.CELSIUS_OFFSET);
System.out.printf(" calib range max: %g °C\n", image.calibRangeMax - IrbImage.CELSIUS_OFFSET);
System.out.printf("shot range start err: %g °C\n", image.shotRangeStartErr - IrbImage.CELSIUS_OFFSET);
System.out.printf(" shot range size: %g K\n", image.shotRangeSize);

// try to export data
try {
System.out.print("starting to export to text files... ");
image.exportImageData(String.format(filename+".img_%d.dat", i));
image.exportMetaData(String.format(filename+".meta_%d.json", i));
image.exportImageData(String.format(filename+".img_%d.dat", imageIndex));
image.exportMetaData(String.format(filename+".meta_%d.json", imageIndex));
System.out.println("done");
} catch (Exception e) {
e.printStackTrace();
}

// try to dump image data array as PNG
try {
System.out.print("starting to dump image as PNG... ");
ArrayToPNG.dumpAsPng(image.getCelsiusImage(), String.format(filename+".img_%d.png", i));
ArrayToPNG.dumpAsPng(image.getCelsiusImage(), String.format(filename+".img_%d.png", imageIndex));
System.out.println("done");
} catch (Exception e) {
e.printStackTrace();
}

// try to plot using JyPlot
try {
System.out.print("plot using JyPlot... ");
JyPlot plt = new JyPlot();

plt.figure();
plt.imshow(image.getCelsiusImage(), "cmap=plt.get_cmap('jet')");
// plt.imshow(image.getCelsiusImage(), "cmap=plt.get_cmap('gist_ncar')");
// plt.imshow(image.getCelsiusImage(), "cmap=plt.get_cmap('nipy_spectral')");
plt.colorbar();
plt.title(String.format("image %d", i));

plt.show();
plt.exec();
System.out.println("done");
} catch (Exception e) {
e.printStackTrace();
if(!runHeadless){
// try to plot using JyPlot
try {
System.out.print("starting to plot using JyPlot... ");
JyPlot plt = new JyPlot();

plt.figure();
plt.imshow(image.getCelsiusImage(), "cmap=plt.get_cmap('jet')");
//plt.imshow(image.getCelsiusImage(), "cmap=plt.get_cmap('gist_ncar')");
//plt.imshow(image.getCelsiusImage(), "cmap=plt.get_cmap('nipy_spectral')");
plt.colorbar();
plt.title(String.format("image %d", imageIndex));

plt.show();
plt.exec();

System.out.println("done");
} catch (Exception e) {
e.printStackTrace();
}
}

i++;
System.out.printf("file %d done\n", imageIndex);
imageIndex++;
}

} catch (Exception e) {
e.printStackTrace();
}
} else {
System.out.println("usage: java -jar irb.jar /path/to/image.irb");
System.out.println("usage: java -jar irb.jar [options] /path/to/image.irb");
System.out.println("options:");
System.out.println(" --headless: do not try to display image using JyPlot");
}
}

}

0 comments on commit 2e34043

Please sign in to comment.