Skip to content

Commit

Permalink
* only dump 4 decimal digits
Browse files Browse the repository at this point in the history
* always set projection per yaml for GridMaps
  • Loading branch information
tschlenther committed Sep 26, 2024
1 parent 24ae7d4 commit bbb5aea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ public Integer call() throws Exception {
}

// write grid mean stats
writeGridFile("mean_emissions_grid_per_day.xyt.csv", meanGridPerDay);
writeGridFile("mean_emissions_grid_per_hour.csv", meanGridPerHour);
writeGridFile("mean_emissions_grid_per_day.xyt.csv", meanGridPerDay, nf);
writeGridFile("mean_emissions_grid_per_hour.csv", meanGridPerHour, nf);

return 0;
}
Expand All @@ -223,15 +223,15 @@ private void getGridData(Table gridTable, Map<Map.Entry<Double, Coord>, List<Dou
}
}

private void writeGridFile(String fileName, Map<Map.Entry<Double, Coord>, Double> values) throws IOException {
private void writeGridFile(String fileName, Map<Map.Entry<Double, Coord>, Double> values, NumberFormat numberFormat) throws IOException {
try (CSVPrinter printer = new CSVPrinter(Files.newBufferedWriter(output.getPath(fileName)), CSVFormat.DEFAULT)) {

//set the projection in the YAML instead, as this is put out with a quote atm...
//printer.printRecord("# EPSG:25832");
printer.printRecord("time", "x", "y", VALUE);

for (Map.Entry<Map.Entry<Double, Coord>, Double> e : values.entrySet()) {
printer.printRecord(e.getKey().getKey(), e.getKey().getValue().getX(), e.getKey().getValue().getY(), e.getValue());
printer.printRecord(e.getKey().getKey(), e.getKey().getValue().getX(), e.getKey().getValue().getY(), numberFormat.format(e.getValue()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,23 +428,25 @@ private void writeTotal(Network network, EmissionsOnLinkEventHandler emissionsEv
//so we need to do some stupid filtering afterwards, which means that we produce and calculate more data than we dump out....
private void writeRaster(Network fullNetwork, Network filteredNetwork, Config config, EmissionsOnLinkEventHandler emissionsEventHandler) {



Map<Pollutant, Raster> rasterMap = FastEmissionGridAnalyzer.processHandlerEmissions(emissionsEventHandler.getLink2pollutants(), fullNetwork, gridSize, 20);

Raster raster = rasterMap.values().stream().findFirst().orElseThrow();

try (CSVPrinter printer = new CSVPrinter(Files.newBufferedWriter(output.getPath("emissions_grid_per_day.xyt.csv")),
CSVFormat.DEFAULT.builder().setCommentMarker('#').build())) {

NumberFormat nf = NumberFormat.getInstance(Locale.US);
nf.setMaximumFractionDigits(4);
nf.setGroupingUsed(false);

String crs = ProjectionUtils.getCRS(fullNetwork);
if (crs == null)
crs = config.network().getInputCRS();
if (crs == null)
crs = config.global().getCoordinateSystem();

// print coordinate system
printer.printComment(crs);
// printer.printComment(crs);

// print header
printer.print("time");
Expand Down Expand Up @@ -478,7 +480,7 @@ private void writeRaster(Network fullNetwork, Network filteredNetwork, Config co
printer.print(coord.getY());

double value = rasterMap.get(Pollutant.CO2_TOTAL).getValueByIndex(xi, yi);
printer.print(value);
printer.print(nf.format(value));

printer.println();
}
Expand Down Expand Up @@ -515,14 +517,18 @@ private void writeTimeDependentRaster(Network fullNetwork, Network filteredNetwo
try (CSVPrinter printer = new CSVPrinter(IOUtils.getBufferedWriter(output.getPath("emissions_grid_per_hour.csv").toString()),
CSVFormat.DEFAULT.builder().setCommentMarker('#').build())) {

NumberFormat nf = NumberFormat.getInstance(Locale.US);
nf.setMaximumFractionDigits(4);
nf.setGroupingUsed(false);

String crs = ProjectionUtils.getCRS(fullNetwork);
if (crs == null)
crs = config.network().getInputCRS();
if (crs == null)
crs = config.global().getCoordinateSystem();

// print coordinate system
printer.printComment(crs);
// print coordinate system
// printer.printComment(crs);

// print header
printer.print("time");
Expand Down Expand Up @@ -560,7 +566,7 @@ private void writeTimeDependentRaster(Network fullNetwork, Network filteredNetwo
printer.print(coord.getX());
printer.print(coord.getY());

printer.print(value);
printer.print(nf.format(value));

printer.println();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public void configure(Header header, Layout layout) {
viz.title = "CO₂ Emissions";
viz.description = "per day. Be aware that CO2 values are provided in the simulation sample size!";
viz.height = 12.0;
viz.projection = "EPSG:25832";
viz.file = data.compute(KelheimOfflineAirPollutionAnalysisByEngineInformation.class, "emissions_grid_per_day.xyt.csv", new String[0]);
viz.setColorRamp(new double[]{30, 40, 50, 60, 70}, new String[]{DARK_BLUE, LIGHT_BLUE, YELLOW, SAND, ORANGE, RED});

Expand All @@ -105,6 +106,7 @@ public void configure(Header header, Layout layout) {
viz.title = "CO₂ Emissions";
viz.description = "per hour. Be aware that CO2 values are provided in the simulation sample size!";
viz.height = 12.;
viz.projection = "EPSG:25832";
viz.file = data.compute(KelheimOfflineAirPollutionAnalysisByEngineInformation.class, "emissions_grid_per_hour.csv");
viz.setColorRamp(new double[]{30, 40, 50, 60, 70}, new String[]{DARK_BLUE, LIGHT_BLUE, YELLOW, SAND, ORANGE, RED});
});
Expand Down

0 comments on commit bbb5aea

Please sign in to comment.