use of au.gov.amsa.util.rx.OperatorWriteBytes 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());
}
}
use of au.gov.amsa.util.rx.OperatorWriteBytes in project risky by amsa-code.
the class BinaryCellValuesObservableTest method testSavingCellValuesToBinaryFileAndReadingBackAgain.
@Test
public void testSavingCellValuesToBinaryFileAndReadingBackAgain() {
Options options = Options.builder().cellSizeDegrees(1.2).build();
CellValue cv = new CellValue(-20, 123, 0.01);
String filename = Observable.just(cv).lift(new OperatorCellValuesToBytes(options)).lift(new OperatorWriteBytes()).toBlocking().first();
assertNotNull(filename);
File file = new File(filename);
assertTrue(file.exists());
System.out.println(filename);
Observable<?> o = BinaryCellValuesObservable.readValues(file);
List<?> list = o.toList().toBlocking().single();
assertEquals(1.2, (Double) list.get(0), 0.00001);
assertTrue(list.get(1) instanceof CellValue);
CellValue v = (CellValue) list.get(1);
assertEquals(-20, v.getCentreLat(), PRECISION);
assertEquals(123, v.getCentreLon(), PRECISION);
assertEquals(0.01, v.getValue(), PRECISION);
assertEquals(2, list.size());
}
Aggregations