use of au.gov.amsa.geo.distance.DistanceTravelledCalculator.CalculationResult in project risky by amsa-code.
the class DistanceTravelledMovieMaker method saveImageWithTimeRange.
private static void saveImageWithTimeRange(Options options, final Observable<File> files, long startTime, long finishTime, String filename) {
Options op = options.buildFrom().startTime(of(startTime)).finishTime(of(finishTime)).build();
CalculationResult result = calculateTrafficDensity(op, files);
saveAsPng(Renderer.createImage(op, 2, 1600, result), new File(filename));
}
use of au.gov.amsa.geo.distance.DistanceTravelledCalculator.CalculationResult in project risky by amsa-code.
the class DistanceTravelledMain method calculateTrafficDensity.
private static void calculateTrafficDensity(String directory, Options options, boolean gui, Map<Integer, Info> shipInfo, Func1<Info, Boolean> shipSelector, String name) {
System.out.println("-----------------------------------------------------");
System.out.println("------ " + name);
System.out.println("-----------------------------------------------------");
final Observable<File> files = Util.getFiles(directory, ".*\\.track").filter(file -> {
String s = file.getName();
String mmsiString = s.substring(0, s.indexOf(".track"));
long mmsi = Long.parseLong(mmsiString);
Info info = shipInfo.get(mmsi);
return shipSelector.call(info);
});
CalculationResult result = DistanceTravelledCalculator.calculateTrafficDensity(options, files, 1, 1);
if (gui) {
DisplayPanel.displayGui(files, options, result);
}
String filename = result.getCells().lift(new OperatorCellValuesToBytes(options)).lift(new OperatorWriteBytes()).toBlocking().single();
log.info("result saved to file " + filename);
CalculationResult resultFromFile = new CalculationResult(BinaryCellValuesObservable.readValues(new File(filename)).skip(1).cast(CellValue.class), result.getMetrics());
boolean produceImage = false;
boolean produceDensitiesText = false;
boolean produceDensitiesNetcdf = true;
File outputDirectory = new File("/media/an/traffic-density/netcdf");
if (produceImage) {
// 8:5 is ok ratio
saveAsPng(Renderer.createImage(options, 2, 12800, resultFromFile), new File(outputDirectory, name + "-map.png"));
}
if (produceDensitiesText) {
DistanceTravelledCalculator.saveCalculationResultAsText(options, result, new File(outputDirectory, name + "-densities.txt").getAbsolutePath());
}
if (produceDensitiesNetcdf) {
DistanceTravelledCalculator.saveCalculationResultAsNetcdf(options, result, new File(outputDirectory, name + "-densities.nc").getAbsolutePath());
}
}
Aggregations