Search in sources :

Example 1 with CalculationResult

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));
}
Also used : CalculationResult(au.gov.amsa.geo.distance.DistanceTravelledCalculator.CalculationResult) Options(au.gov.amsa.geo.model.Options) File(java.io.File)

Example 2 with CalculationResult

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());
    }
}
Also used : CalculationResult(au.gov.amsa.geo.distance.DistanceTravelledCalculator.CalculationResult) OperatorCellValuesToBytes(au.gov.amsa.geo.OperatorCellValuesToBytes) CellValue(au.gov.amsa.geo.model.CellValue) Info(au.gov.amsa.navigation.ShipStaticData.Info) File(java.io.File) OperatorWriteBytes(au.gov.amsa.util.rx.OperatorWriteBytes)

Aggregations

CalculationResult (au.gov.amsa.geo.distance.DistanceTravelledCalculator.CalculationResult)2 File (java.io.File)2 OperatorCellValuesToBytes (au.gov.amsa.geo.OperatorCellValuesToBytes)1 CellValue (au.gov.amsa.geo.model.CellValue)1 Options (au.gov.amsa.geo.model.Options)1 Info (au.gov.amsa.navigation.ShipStaticData.Info)1 OperatorWriteBytes (au.gov.amsa.util.rx.OperatorWriteBytes)1