From 9233116499d2af5e07deb0a2135cd51cc28fcdd6 Mon Sep 17 00:00:00 2001 From: sime94 Date: Thu, 26 Sep 2024 15:42:45 +0200 Subject: [PATCH 1/3] add complete ./test dir to .gitign --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8f27344e..8019eb6f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ # Common files to ignore when working with MATSim output/ scenarios/output -test/output +test/ *.gz *.pbf From 6697326537c015f10a7a00672584dad219ae31e8 Mon Sep 17 00:00:00 2001 From: tschlenther Date: Thu, 26 Sep 2024 16:44:13 +0200 Subject: [PATCH 2/3] package structure + debug dashboard color ramps (#89) * package structure + debug dashboard color ramps * fix typo * fix typo consistently * * use MapPlot instead of Link panel * emissions -> airPollution * delete default for base-run * checkstyle * * only dump 4 decimal digits * always set projection per yaml for GridMaps --------- Co-authored-by: sime94 --- .../postAnalysis/NoiseAverageAnalysis.java | 20 +++---- ...missionsPostProcessingAverageAnalysis.java | 10 ++-- ...rPollutionAnalysisByEngineInformation.java | 22 +++++--- .../AverageKelheimEmissionsDashboard.java | 56 ++++++++++++++----- .../AverageKelheimNoiseDashboard.java | 14 ++--- .../dashboard/CreateAverageDashboards.java | 8 +-- .../dashboard/KelheimDashboardProvider.java | 1 - .../KelheimEmissionsDashboard.java | 21 +++++-- .../dashboard/KelheimSimWrapperRunner.java | 1 - .../matsim/run/MeanNoiseDashboardTest.java | 2 +- 10 files changed, 96 insertions(+), 59 deletions(-) rename src/main/java/org/matsim/analysis/postAnalysis/{ => emissions}/EmissionsPostProcessingAverageAnalysis.java (97%) rename src/main/java/org/matsim/analysis/{ => postAnalysis}/emissions/KelheimOfflineAirPollutionAnalysisByEngineInformation.java (98%) rename src/main/java/org/matsim/{analysis/emissions => dashboard}/KelheimEmissionsDashboard.java (82%) diff --git a/src/main/java/org/matsim/analysis/postAnalysis/NoiseAverageAnalysis.java b/src/main/java/org/matsim/analysis/postAnalysis/NoiseAverageAnalysis.java index 14da560d..2749a67a 100644 --- a/src/main/java/org/matsim/analysis/postAnalysis/NoiseAverageAnalysis.java +++ b/src/main/java/org/matsim/analysis/postAnalysis/NoiseAverageAnalysis.java @@ -57,8 +57,8 @@ public class NoiseAverageAnalysis implements MATSimAppCommand { private static final String ANALYSIS_DIR = "/analysis/noise"; private static final String LINK_ID = "Link Id"; private static final String VALUE = "value"; - private List imissionsPerDay = new ArrayList<>(); - private List imissionsPerHour = new ArrayList<>(); + private List immissionsPerDay = new ArrayList<>(); + private List immissionsPerHour = new ArrayList<>(); private Map> emissionsPerDay = new HashMap<>(); private Map meanEmissionsPerDay = new HashMap<>(); private Map> totalStats = new HashMap<>(); @@ -86,8 +86,8 @@ public Integer call() throws Exception { for (String folder : foldersSeeded) { final Path analysisDir = Path.of(folder + ANALYSIS_DIR); String emissionsCsv = globFile(analysisDir, "*emission_per_day.csv*").toString(); - String imissionsPerDayAvro = globFile(analysisDir, "*immission_per_day.avro*").toString(); - String imissionsPerHourAvro = globFile(analysisDir, "*immission_per_hour.avro*").toString(); + String immissionsPerDayAvro = globFile(analysisDir, "*immission_per_day.avro*").toString(); + String immissionsPerHourAvro = globFile(analysisDir, "*immission_per_hour.avro*").toString(); String totalStatsCsv = globFile(analysisDir, "*noise_stats.csv*").toString(); String damagesPerDayAvro = globFile(analysisDir, "*damages_receiverPoint_per_day.avro*").toString(); String damagesPerHourAvro = globFile(analysisDir, "*damages_receiverPoint_per_hour.avro*").toString(); @@ -105,8 +105,8 @@ public Integer call() throws Exception { .separator(CsvOptions.detectDelimiter(totalStatsCsv)).build()); // read avro files - readAvroFile(imissionsPerDayAvro, imissionsPerDay); - readAvroFile(imissionsPerHourAvro, imissionsPerHour); + readAvroFile(immissionsPerDayAvro, immissionsPerDay); + readAvroFile(immissionsPerHourAvro, immissionsPerHour); readAvroFile(damagesPerDayAvro, damagesPerDay); readAvroFile(damagesPerHourAvro, damagesPerHour); @@ -137,8 +137,8 @@ public Integer call() throws Exception { calcCsvMeans(totalStats, meanTotalStatsPerDay); // calc avro means - XYTData imissionsPerDayMean = calcAvroMeans(imissionsPerDay, "imissions"); - XYTData imissionsPerHourMean = calcAvroMeans(imissionsPerHour, "imissions"); + XYTData immissionsPerDayMean = calcAvroMeans(immissionsPerDay, "immission"); + XYTData immissionsPerHourMean = calcAvroMeans(immissionsPerHour, "immission"); XYTData damagesPerDayMean = calcAvroMeans(damagesPerDay, "damages_receiverPoint"); XYTData damagesPerHourMean = calcAvroMeans(damagesPerHour, "damages_receiverPoint"); @@ -161,8 +161,8 @@ public Integer call() throws Exception { } // write avro mean files - writeAvro(imissionsPerDayMean, new File(output.getPath("mean_immission_per_day.avro").toString())); - writeAvro(imissionsPerHourMean, new File(output.getPath("mean_immission_per_hour.avro").toString())); + writeAvro(immissionsPerDayMean, new File(output.getPath("mean_immission_per_day.avro").toString())); + writeAvro(immissionsPerHourMean, new File(output.getPath("mean_immission_per_hour.avro").toString())); writeAvro(damagesPerDayMean, new File(output.getPath("mean_damages_receiverPoint_per_day.avro").toString())); writeAvro(damagesPerHourMean, new File(output.getPath("mean_damages_receiverPoint_per_hour.avro").toString())); diff --git a/src/main/java/org/matsim/analysis/postAnalysis/EmissionsPostProcessingAverageAnalysis.java b/src/main/java/org/matsim/analysis/postAnalysis/emissions/EmissionsPostProcessingAverageAnalysis.java similarity index 97% rename from src/main/java/org/matsim/analysis/postAnalysis/EmissionsPostProcessingAverageAnalysis.java rename to src/main/java/org/matsim/analysis/postAnalysis/emissions/EmissionsPostProcessingAverageAnalysis.java index 2ed4a589..f07cbd66 100644 --- a/src/main/java/org/matsim/analysis/postAnalysis/EmissionsPostProcessingAverageAnalysis.java +++ b/src/main/java/org/matsim/analysis/postAnalysis/emissions/EmissionsPostProcessingAverageAnalysis.java @@ -1,4 +1,4 @@ -package org.matsim.analysis.postAnalysis; +package org.matsim.analysis.postAnalysis.emissions; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVPrinter; @@ -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; } @@ -223,7 +223,7 @@ private void getGridData(Table gridTable, Map, List, Double> values) throws IOException { + private void writeGridFile(String fileName, Map, 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... @@ -231,7 +231,7 @@ private void writeGridFile(String fileName, Map, Double printer.printRecord("time", "x", "y", VALUE); for (Map.Entry, 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())); } } } diff --git a/src/main/java/org/matsim/analysis/emissions/KelheimOfflineAirPollutionAnalysisByEngineInformation.java b/src/main/java/org/matsim/analysis/postAnalysis/emissions/KelheimOfflineAirPollutionAnalysisByEngineInformation.java similarity index 98% rename from src/main/java/org/matsim/analysis/emissions/KelheimOfflineAirPollutionAnalysisByEngineInformation.java rename to src/main/java/org/matsim/analysis/postAnalysis/emissions/KelheimOfflineAirPollutionAnalysisByEngineInformation.java index 1d0c91c4..2c5ab6c9 100644 --- a/src/main/java/org/matsim/analysis/emissions/KelheimOfflineAirPollutionAnalysisByEngineInformation.java +++ b/src/main/java/org/matsim/analysis/postAnalysis/emissions/KelheimOfflineAirPollutionAnalysisByEngineInformation.java @@ -18,7 +18,7 @@ * * * *********************************************************************** */ -package org.matsim.analysis.emissions; +package org.matsim.analysis.postAnalysis.emissions; import it.unimi.dsi.fastutil.objects.Object2DoubleLinkedOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2DoubleMap; @@ -428,8 +428,6 @@ 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 rasterMap = FastEmissionGridAnalyzer.processHandlerEmissions(emissionsEventHandler.getLink2pollutants(), fullNetwork, gridSize, 20); Raster raster = rasterMap.values().stream().findFirst().orElseThrow(); @@ -437,6 +435,10 @@ private void writeRaster(Network fullNetwork, Network filteredNetwork, Config co 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(); @@ -444,7 +446,7 @@ private void writeRaster(Network fullNetwork, Network filteredNetwork, Config co crs = config.global().getCoordinateSystem(); // print coordinate system - printer.printComment(crs); +// printer.printComment(crs); // print header printer.print("time"); @@ -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(); } @@ -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"); @@ -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(); } diff --git a/src/main/java/org/matsim/dashboard/AverageKelheimEmissionsDashboard.java b/src/main/java/org/matsim/dashboard/AverageKelheimEmissionsDashboard.java index 5cef3004..9ac111d0 100644 --- a/src/main/java/org/matsim/dashboard/AverageKelheimEmissionsDashboard.java +++ b/src/main/java/org/matsim/dashboard/AverageKelheimEmissionsDashboard.java @@ -20,19 +20,18 @@ package org.matsim.dashboard; -import org.matsim.analysis.postAnalysis.EmissionsPostProcessingAverageAnalysis; +import org.matsim.analysis.postAnalysis.emissions.EmissionsPostProcessingAverageAnalysis; import org.matsim.simwrapper.Dashboard; import org.matsim.simwrapper.Data; import org.matsim.simwrapper.Header; import org.matsim.simwrapper.Layout; -import org.matsim.simwrapper.viz.GridMap; -import org.matsim.simwrapper.viz.Links; -import org.matsim.simwrapper.viz.Table; +import org.matsim.simwrapper.viz.*; -import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import static org.matsim.dashboard.AverageKelheimNoiseDashboard.*; + /** * Average emissions dashboard for several runs with the same config but a different random seed. */ @@ -51,10 +50,14 @@ public AverageKelheimEmissionsDashboard(List dirs, Integer noRuns, Strin this.dirs = dirs; this.noRuns = noRuns; - if (!pathToBaseRun.endsWith("/")) { - pathToBaseRun += "/"; + if (pathToBaseRun == null || pathToBaseRun.equals("null")){ + this.pathToCsvBase = null; + } else { + if (!pathToBaseRun.endsWith("/")) { + pathToBaseRun += "/"; + } + this.pathToCsvBase = pathToBaseRun + "analysis/emissions/emissions_per_link_per_m.csv"; } - this.pathToCsvBase = pathToBaseRun + "analysis/emissions/emissions_per_link_per_m.csv"; } private String postProcess(Data data, String outputFile) { @@ -68,8 +71,8 @@ private String postProcess(Data data, String outputFile) { * Produces the dashboard. */ public void configure(Header header, Layout layout) { - header.title = "Average Emissions"; - header.description = "Shows the average emissions footprint and spatial distribution for several simulation runs."; + header.title = "Average Air Pollution"; + header.description = "Shows the average air pollution and spatial distribution for several simulation runs."; String linkDescription = "Displays the emissions for each link per meter. Be aware that emission values are provided in the simulation sample size!"; if (pathToCsvBase != null){ @@ -86,12 +89,16 @@ public void configure(Header header, Layout layout) { viz.showAllRows = true; viz.width = 1.0; }) - .el(Links.class, (viz, data) -> { - viz.title = "Emissions per Link per Meter"; + /* + * Commented out link panel, because the MapPlot can show a legend and seems to be the development head. + * However, it doesn't seem to have the pointer to the base case + */ + /*.el(Links.class, (viz, data) -> { + viz.title = "Emitted Pollutant in Gram per Meter"; viz.description = finalLinkDescription; viz.height = 12.0; viz.datasets.csvFile = postProcess(data, "mean_emissions_per_link_per_m.csv"); - viz.datasets.csvBase = Path.of(this.dirs.get(0)).getParent().relativize(Path.of(pathToCsvBase)).toString(); + viz.datasets.csvBase = pathToCsvBase == null ? "" : Path.of(this.dirs.get(0)).getParent().relativize(Path.of(pathToCsvBase)).toString(); viz.network = new CreateAverageDashboards().copyVizNetwork(dirs, ".avro"); viz.display.color.columnName = "CO2_TOTAL [g/m]"; viz.display.color.dataset = "csvFile"; @@ -99,12 +106,32 @@ public void configure(Header header, Layout layout) { viz.display.width.columnName = "CO2_TOTAL [g/m]"; viz.display.width.dataset = "csvFile"; viz.center = data.context().getCenter(); + viz.width = 1.0; + })*/ + .el(MapPlot.class, (viz, data) -> { + viz.title = "Emitted Pollutant in Gram per Meter"; + viz.description = finalLinkDescription; + viz.height = 12.0; + viz.center = data.context().getCenter(); + viz.zoom = data.context().mapZoomLevel; + viz.setShape(new CreateAverageDashboards().copyVizNetwork(dirs, ".avro"), "id"); + viz.addDataset("emissions_per_m", postProcess(data, "mean_emissions_per_link_per_m.csv")); + viz.display.lineColor.dataset = "emissions_per_m"; + viz.display.lineColor.columnName = "CO2_TOTAL [g/m]"; + viz.display.lineColor.join = "linkId"; + viz.display.lineColor.setColorRamp(ColorScheme.Oranges, 8, false, "35, 45, 55, 65, 75, 85, 95"); + viz.display.lineWidth.dataset = "emissions_per_m"; + viz.display.lineWidth.columnName = "CO2_TOTAL [g/m]"; + viz.display.lineWidth.scaleFactor = 100d; + viz.display.lineWidth.join = "linkId"; viz.width = 3.0; - }); + }); + layout.row("second").el(GridMap.class, (viz, data) -> { viz.title = "CO₂ Emissions"; viz.description = "per day. Be aware that CO2 values are provided in the simulation sample size!"; viz.projection = "EPSG:25832"; + viz.setColorRamp(new double[]{30, 40, 50, 60, 70}, new String[]{DARK_BLUE, LIGHT_BLUE, YELLOW, SAND, ORANGE, RED}); viz.height = 12.0; viz.file = postProcess(data, "mean_emissions_grid_per_day.xyt.csv"); }); @@ -112,6 +139,7 @@ public void configure(Header header, Layout layout) { .el(GridMap.class, (viz, data) -> { viz.title = "CO₂ Emissions"; viz.projection = "EPSG:25832"; + viz.setColorRamp(new double[]{30, 40, 50, 60, 70}, new String[]{DARK_BLUE, LIGHT_BLUE, YELLOW, SAND, ORANGE, RED}); viz.description = "per hour. Be aware that CO2 values are provided in the simulation sample size!"; viz.height = 12.; viz.file = postProcess(data, "mean_emissions_grid_per_hour.csv"); diff --git a/src/main/java/org/matsim/dashboard/AverageKelheimNoiseDashboard.java b/src/main/java/org/matsim/dashboard/AverageKelheimNoiseDashboard.java index 3a24899c..40f34fab 100644 --- a/src/main/java/org/matsim/dashboard/AverageKelheimNoiseDashboard.java +++ b/src/main/java/org/matsim/dashboard/AverageKelheimNoiseDashboard.java @@ -14,7 +14,7 @@ import java.util.List; /** - * Shows emission in the scenario. + * Averages and displays the noise outcome of single runs. */ public class AverageKelheimNoiseDashboard implements Dashboard { @@ -23,12 +23,12 @@ public class AverageKelheimNoiseDashboard implements Dashboard { private final List dirs; private final Integer noRuns; private static final String NOISE = "noise"; - private static final String DARK_BLUE = "#1175b3"; - private static final String LIGHT_BLUE = "#95c7df"; - private static final String ORANGE = "#f4a986"; - private static final String RED = "#cc0c27"; - private static final String SAND = "#dfb095"; - private static final String YELLOW = "#dfdb95"; + static final String DARK_BLUE = "#1175b3"; + static final String LIGHT_BLUE = "#95c7df"; + static final String ORANGE = "#f4a986"; + static final String RED = "#cc0c27"; + static final String SAND = "#dfb095"; + static final String YELLOW = "#dfdb95"; public AverageKelheimNoiseDashboard(List dirs, Integer noRuns) { this.dirs = dirs; diff --git a/src/main/java/org/matsim/dashboard/CreateAverageDashboards.java b/src/main/java/org/matsim/dashboard/CreateAverageDashboards.java index b6dffb39..0b923b48 100644 --- a/src/main/java/org/matsim/dashboard/CreateAverageDashboards.java +++ b/src/main/java/org/matsim/dashboard/CreateAverageDashboards.java @@ -24,18 +24,14 @@ final class CreateAverageDashboards implements MATSimAppCommand { private String inputPath; @CommandLine.Option(names = "--no-runs", defaultValue = "5", description = "Number of simulation runs to be averaged.") private Integer noRuns; - @CommandLine.Option(names = "--base-run", description = "Path to directory base run.", defaultValue = "/net/ils/matsim-kelheim/v3.0-release/output-base/25pct") + @CommandLine.Option(names = "--base-run", description = "Path to directory base run.") private String pathToBaseRun; public static void main(String[] args) { new CreateAverageDashboards().execute(args); } - CreateAverageDashboards() { - - } - - + CreateAverageDashboards() {} @Override public Integer call() throws Exception { diff --git a/src/main/java/org/matsim/dashboard/KelheimDashboardProvider.java b/src/main/java/org/matsim/dashboard/KelheimDashboardProvider.java index 17a1a6c3..16c9b85c 100644 --- a/src/main/java/org/matsim/dashboard/KelheimDashboardProvider.java +++ b/src/main/java/org/matsim/dashboard/KelheimDashboardProvider.java @@ -1,6 +1,5 @@ package org.matsim.dashboard; -import org.matsim.analysis.emissions.KelheimEmissionsDashboard; import org.matsim.core.config.Config; import org.matsim.core.utils.io.IOUtils; import org.matsim.simwrapper.Dashboard; diff --git a/src/main/java/org/matsim/analysis/emissions/KelheimEmissionsDashboard.java b/src/main/java/org/matsim/dashboard/KelheimEmissionsDashboard.java similarity index 82% rename from src/main/java/org/matsim/analysis/emissions/KelheimEmissionsDashboard.java rename to src/main/java/org/matsim/dashboard/KelheimEmissionsDashboard.java index cb7a9a9b..952fd5c5 100644 --- a/src/main/java/org/matsim/analysis/emissions/KelheimEmissionsDashboard.java +++ b/src/main/java/org/matsim/dashboard/KelheimEmissionsDashboard.java @@ -18,8 +18,9 @@ * * * *********************************************************************** */ -package org.matsim.analysis.emissions; +package org.matsim.dashboard; +import org.matsim.analysis.postAnalysis.emissions.KelheimOfflineAirPollutionAnalysisByEngineInformation; import org.matsim.application.prepare.network.CreateGeoJsonNetwork; import org.matsim.simwrapper.Dashboard; import org.matsim.simwrapper.Header; @@ -28,6 +29,9 @@ import org.matsim.simwrapper.viz.Links; import org.matsim.simwrapper.viz.Table; +import static org.matsim.dashboard.AverageKelheimNoiseDashboard.*; +import static org.matsim.dashboard.AverageKelheimNoiseDashboard.RED; + /** * this is basically equivalent to the standard emissions dashboard * but calls the matsim-kelheim-specific emissions analysis class @@ -53,10 +57,10 @@ public KelheimEmissionsDashboard(String pathToBaseRun) { */ public void configure(Header header, Layout layout) { - header.title = "Emissions"; - header.description = "Shows the emissions footprint and spatial distribution."; + header.title = "Air Pollution"; + header.description = "Shows the air pollution and spatial distribution."; - String linkDescription = "Displays the emissions for each link per meter. Be aware that emission values are provided in the simulation sample size!"; + String linkDescription = "Displays the emitted pair pollutants for each link per meter. Be aware that pollutant values are provided in the simulation sample size!"; if (pathToCsvBase != null){ linkDescription += String.format("%n Base is %s", pathToCsvBase); } @@ -64,7 +68,7 @@ public void configure(Header header, Layout layout) { layout.row("links") .el(Table.class, (viz, data) -> { - viz.title = "Emissions"; + viz.title = "Air Pollution"; viz.description = "by pollutant. Total values are scaled from the simulation sample size to 100%."; viz.dataset = data.compute(KelheimOfflineAirPollutionAnalysisByEngineInformation.class, "emissions_total.csv", new String[0]); viz.enableFilter = false; @@ -72,7 +76,7 @@ public void configure(Header header, Layout layout) { viz.width = 1.0; }) .el(Links.class, (viz, data) -> { - viz.title = "Emissions per Link per Meter"; + viz.title = "Emitted Pollutant in Gram per Meter"; viz.description = finalLinkDescription; viz.height = 12.0; viz.datasets.csvFile = data.compute(KelheimOfflineAirPollutionAnalysisByEngineInformation.class, "emissions_per_link_per_m.csv", new String[0]); @@ -92,14 +96,19 @@ 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}); + }); layout.row("third") .el(GridMap.class, (viz, data) -> { 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}); }); } } diff --git a/src/main/java/org/matsim/dashboard/KelheimSimWrapperRunner.java b/src/main/java/org/matsim/dashboard/KelheimSimWrapperRunner.java index b454bc67..01b3c3a6 100644 --- a/src/main/java/org/matsim/dashboard/KelheimSimWrapperRunner.java +++ b/src/main/java/org/matsim/dashboard/KelheimSimWrapperRunner.java @@ -22,7 +22,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.matsim.analysis.emissions.KelheimEmissionsDashboard; import org.matsim.application.ApplicationUtils; import org.matsim.application.MATSimAppCommand; import org.matsim.application.options.ShpOptions; diff --git a/src/test/java/org/matsim/run/MeanNoiseDashboardTest.java b/src/test/java/org/matsim/run/MeanNoiseDashboardTest.java index e3e0c50f..c5c8fca4 100644 --- a/src/test/java/org/matsim/run/MeanNoiseDashboardTest.java +++ b/src/test/java/org/matsim/run/MeanNoiseDashboardTest.java @@ -67,7 +67,7 @@ void runMeanNoiseDashboardTest() throws IOException { timeStamps.add(28800); - immissionData.put("imissions", List.of((float) i)); + immissionData.put("immission", List.of((float) i)); damageData.put("damages_receiverPoint", List.of((float) i)); String seedDir = path + i + "seed/"; From 12642b2f8e317bab40f98fde3e94672858ffbf23 Mon Sep 17 00:00:00 2001 From: schlenther Date: Thu, 26 Sep 2024 16:59:02 +0200 Subject: [PATCH 3/3] reduce code duplication in dashboard classes --- .../AverageKelheimEmissionsDashboard.java | 14 +++--- .../AverageKelheimNoiseDashboard.java | 47 ++++++------------- .../dashboard/KelheimEmissionsDashboard.java | 19 ++++---- 3 files changed, 33 insertions(+), 47 deletions(-) diff --git a/src/main/java/org/matsim/dashboard/AverageKelheimEmissionsDashboard.java b/src/main/java/org/matsim/dashboard/AverageKelheimEmissionsDashboard.java index 9ac111d0..fa369af5 100644 --- a/src/main/java/org/matsim/dashboard/AverageKelheimEmissionsDashboard.java +++ b/src/main/java/org/matsim/dashboard/AverageKelheimEmissionsDashboard.java @@ -130,19 +130,21 @@ public void configure(Header header, Layout layout) { layout.row("second").el(GridMap.class, (viz, data) -> { viz.title = "CO₂ Emissions"; viz.description = "per day. Be aware that CO2 values are provided in the simulation sample size!"; - viz.projection = "EPSG:25832"; - viz.setColorRamp(new double[]{30, 40, 50, 60, 70}, new String[]{DARK_BLUE, LIGHT_BLUE, YELLOW, SAND, ORANGE, RED}); - viz.height = 12.0; + setGridMapStandards(viz); viz.file = postProcess(data, "mean_emissions_grid_per_day.xyt.csv"); }); layout.row("third") .el(GridMap.class, (viz, data) -> { viz.title = "CO₂ Emissions"; - viz.projection = "EPSG:25832"; - viz.setColorRamp(new double[]{30, 40, 50, 60, 70}, new String[]{DARK_BLUE, LIGHT_BLUE, YELLOW, SAND, ORANGE, RED}); viz.description = "per hour. Be aware that CO2 values are provided in the simulation sample size!"; - viz.height = 12.; + setGridMapStandards(viz); viz.file = postProcess(data, "mean_emissions_grid_per_hour.csv"); }); } + + private static void setGridMapStandards(GridMap viz) { + viz.projection = "EPSG:25832"; + viz.setColorRamp(new double[]{30, 40, 50, 60, 70}, new String[]{DARK_BLUE, LIGHT_BLUE, YELLOW, SAND, ORANGE, RED}); + viz.height = 12.0; + } } diff --git a/src/main/java/org/matsim/dashboard/AverageKelheimNoiseDashboard.java b/src/main/java/org/matsim/dashboard/AverageKelheimNoiseDashboard.java index 40f34fab..b4715dd9 100644 --- a/src/main/java/org/matsim/dashboard/AverageKelheimNoiseDashboard.java +++ b/src/main/java/org/matsim/dashboard/AverageKelheimNoiseDashboard.java @@ -78,55 +78,38 @@ public void configure(Header header, Layout layout) { .el(GridMap.class, (viz, data) -> { viz.title = "Noise Immissions (Grid)"; viz.description = "Total Noise Immissions per day"; - viz.height = 12.0; - viz.cellSize = 250; - viz.opacity = 0.2; - viz.maxHeight = 20; - viz.projection = "EPSG:25832"; - viz.center = data.context().getCenter(); - viz.zoom = data.context().mapZoomLevel; - viz.setColorRamp(new double[]{30, 40, 50, 60, 70}, new String[]{DARK_BLUE, LIGHT_BLUE, YELLOW, SAND, ORANGE, RED}); + setGridMapStandards(viz, data); viz.file = postProcess(data, "mean_immission_per_day.avro"); }) .el(GridMap.class, (viz, data) -> { viz.title = "Hourly Noise Immissions (Grid)"; viz.description = "Noise Immissions per hour"; - viz.height = 12.0; - viz.cellSize = 250; - viz.opacity = 0.1; - viz.maxHeight = 40; - viz.projection = "EPSG:25832"; - viz.center = data.context().getCenter(); - viz.zoom = data.context().mapZoomLevel; - viz.setColorRamp(new double[]{30, 40, 50, 60, 70}, new String[]{DARK_BLUE, LIGHT_BLUE, YELLOW, SAND, ORANGE, RED}); + setGridMapStandards(viz, data); viz.file = postProcess(data, "mean_immission_per_hour.avro"); }); layout.row("damages") .el(GridMap.class, (viz, data) -> { viz.title = "Daily Noise Damages (Grid)"; viz.description = "Total Noise Damages per day [€]"; - viz.height = 12.0; - viz.cellSize = 250; - viz.opacity = 0.1; - viz.maxHeight = 40; - viz.center = data.context().getCenter(); - viz.zoom = data.context().mapZoomLevel; - viz.projection = "EPSG:25832"; - viz.setColorRamp(new double[]{30, 40, 50, 60, 70}, new String[]{DARK_BLUE, LIGHT_BLUE, YELLOW, SAND, ORANGE, RED}); + setGridMapStandards(viz, data); viz.file = postProcess(data, "mean_damages_receiverPoint_per_day.avro"); }) .el(GridMap.class, (viz, data) -> { viz.title = "Hourly Noise Damages (Grid)"; viz.description = "Noise Damages per hour [€]"; - viz.height = 12.0; - viz.cellSize = 250; - viz.opacity = 0.2; - viz.maxHeight = 40; - viz.projection = "EPSG:25832"; - viz.center = data.context().getCenter(); - viz.zoom = data.context().mapZoomLevel; - viz.setColorRamp(new double[]{30, 40, 50, 60, 70}, new String[]{DARK_BLUE, LIGHT_BLUE, YELLOW, SAND, ORANGE, RED}); + setGridMapStandards(viz, data); viz.file = postProcess(data, "mean_damages_receiverPoint_per_hour.avro"); }); } + + private static void setGridMapStandards(GridMap viz, Data data) { + viz.height = 12.0; + viz.cellSize = 250; + viz.opacity = 0.1; + viz.maxHeight = 40; + viz.projection = "EPSG:25832"; + viz.center = data.context().getCenter(); + viz.zoom = data.context().mapZoomLevel; + viz.setColorRamp(new double[]{30, 40, 50, 60, 70}, new String[]{DARK_BLUE, LIGHT_BLUE, YELLOW, SAND, ORANGE, RED}); + } } diff --git a/src/main/java/org/matsim/dashboard/KelheimEmissionsDashboard.java b/src/main/java/org/matsim/dashboard/KelheimEmissionsDashboard.java index 952fd5c5..8be29839 100644 --- a/src/main/java/org/matsim/dashboard/KelheimEmissionsDashboard.java +++ b/src/main/java/org/matsim/dashboard/KelheimEmissionsDashboard.java @@ -23,6 +23,7 @@ import org.matsim.analysis.postAnalysis.emissions.KelheimOfflineAirPollutionAnalysisByEngineInformation; import org.matsim.application.prepare.network.CreateGeoJsonNetwork; import org.matsim.simwrapper.Dashboard; +import org.matsim.simwrapper.Data; import org.matsim.simwrapper.Header; import org.matsim.simwrapper.Layout; import org.matsim.simwrapper.viz.GridMap; @@ -30,7 +31,6 @@ import org.matsim.simwrapper.viz.Table; import static org.matsim.dashboard.AverageKelheimNoiseDashboard.*; -import static org.matsim.dashboard.AverageKelheimNoiseDashboard.RED; /** * this is basically equivalent to the standard emissions dashboard @@ -95,20 +95,21 @@ public void configure(Header header, Layout layout) { layout.row("second").el(GridMap.class, (viz, data) -> { 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}); + setGridMapStandards(viz, 12.0, data.compute(KelheimOfflineAirPollutionAnalysisByEngineInformation.class, "emissions_grid_per_day.xyt.csv", new String[0])); }); layout.row("third") .el(GridMap.class, (viz, data) -> { 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}); + setGridMapStandards(viz, 12., data.compute(KelheimOfflineAirPollutionAnalysisByEngineInformation.class, "emissions_grid_per_hour.csv")); }); } + + private static void setGridMapStandards(GridMap viz, double height, String data) { + viz.height = height; + viz.projection = "EPSG:25832"; + viz.file = data; + viz.setColorRamp(new double[]{30, 40, 50, 60, 70}, new String[]{DARK_BLUE, LIGHT_BLUE, YELLOW, SAND, ORANGE, RED}); + } }