From 3d73ccc970d6136c565badce91d68f6e8b731640 Mon Sep 17 00:00:00 2001 From: schlenther Date: Tue, 1 Oct 2024 17:17:26 +0200 Subject: [PATCH] introduce DashboardUtils for some standardization --- .../CreateSingleSimWrapperDashboard.java | 4 +- .../org/matsim/simwrapper/DashboardUtils.java | 23 ++++++++ .../simwrapper/DefaultDashboardProvider.java | 4 +- .../dashboard/EmissionsDashboard.java | 45 +++++++--------- .../simwrapper/dashboard/NoiseDashboard.java | 52 +++++-------------- .../dashboard/EmissionsDashboardTest.java | 2 +- .../dashboard/NoiseDashboardTests.java | 2 +- 7 files changed, 61 insertions(+), 71 deletions(-) create mode 100644 contribs/simwrapper/src/main/java/org/matsim/simwrapper/DashboardUtils.java diff --git a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/CreateSingleSimWrapperDashboard.java b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/CreateSingleSimWrapperDashboard.java index fce848736a6..cbffd5a84a6 100644 --- a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/CreateSingleSimWrapperDashboard.java +++ b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/CreateSingleSimWrapperDashboard.java @@ -97,10 +97,10 @@ public Integer call() throws Exception { //add dashboard switch (dashboardType) { case noise -> { - sw.addDashboard(new NoiseDashboard()); + sw.addDashboard(new NoiseDashboard(config.global().getCoordinateSystem())); } case emissions -> { - sw.addDashboard(new EmissionsDashboard()); + sw.addDashboard(new EmissionsDashboard(config.global().getCoordinateSystem())); } case traffic -> { sw.addDashboard(new TrafficDashboard()); diff --git a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/DashboardUtils.java b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/DashboardUtils.java new file mode 100644 index 00000000000..600bb0cf298 --- /dev/null +++ b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/DashboardUtils.java @@ -0,0 +1,23 @@ +package org.matsim.simwrapper; + +import org.matsim.simwrapper.viz.GridMap; + +public class DashboardUtils { + 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 static void setGridMapStandards(GridMap viz, Data data, String crs) { + viz.height = 12.0; + viz.cellSize = 100; + viz.opacity = 0.1; + viz.maxHeight = 15; + viz.projection = crs; + 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/contribs/simwrapper/src/main/java/org/matsim/simwrapper/DefaultDashboardProvider.java b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/DefaultDashboardProvider.java index 9a6f00f9520..a01674f4856 100644 --- a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/DefaultDashboardProvider.java +++ b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/DefaultDashboardProvider.java @@ -31,11 +31,11 @@ public List getDashboards(Config config, SimWrapper simWrapper) { } if (ConfigUtils.hasModule(config, EmissionsConfigGroup.class)) { - result.add(new EmissionsDashboard()); + result.add(new EmissionsDashboard(config.global().getCoordinateSystem())); } if (ConfigUtils.hasModule(config, NoiseConfigGroup.class)) { - result.add(new NoiseDashboard()); + result.add(new NoiseDashboard(config.global().getCoordinateSystem())); } result.add(new StuckAgentDashboard()); diff --git a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/EmissionsDashboard.java b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/EmissionsDashboard.java index a7487fd625b..69471e57815 100644 --- a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/EmissionsDashboard.java +++ b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/EmissionsDashboard.java @@ -1,14 +1,12 @@ package org.matsim.simwrapper.dashboard; import org.matsim.application.analysis.emissions.AirPollutionAnalysis; -import org.matsim.application.analysis.noise.NoiseAnalysis; import org.matsim.application.prepare.network.CreateAvroNetwork; -import org.matsim.application.prepare.network.CreateGeoJsonNetwork; import org.matsim.simwrapper.Dashboard; +import org.matsim.simwrapper.DashboardUtils; 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.MapPlot; import org.matsim.simwrapper.viz.Table; @@ -16,27 +14,35 @@ * Shows emission in the scenario. */ public class EmissionsDashboard implements Dashboard { + + private final String coordinateSystem; + + /** + * Best provide the crs from {@link org.matsim.core.config.groups.GlobalConfigGroup} + * @param coordinateSystem + */ + public EmissionsDashboard(String coordinateSystem) { + this.coordinateSystem = coordinateSystem; + } + @Override public void configure(Header header, Layout layout) { - header.title = "Emissions"; - header.description = "Shows the emissions footprint and spatial distribution. Shown values are already upscaled from simulated sample size."; - + header.title = "Air Pollution"; + header.description = "Shows the air pollution footprint and its spatial distribution. Shown values are already upscaled from simulated sample size."; layout.row("links") .el(Table.class, (viz, data) -> { - - viz.title = "Emissions"; + viz.title = "Total Emission"; viz.description = "by pollutant"; viz.dataset = data.compute(AirPollutionAnalysis.class, "emissions_total.csv"); viz.enableFilter = false; viz.showAllRows = true; - viz.width = 1d; }) .el(MapPlot.class, (viz, data) -> { - viz.title = "Emissions per Link per Meter"; + viz.title = "Emission per Link per Meter"; viz.description = "Displays the emissions for each link per meter."; viz.height = 12.; viz.addDataset("emissions_per_link_per_m", data.compute(AirPollutionAnalysis.class, "emissions_per_link_per_m.csv")); @@ -57,14 +63,7 @@ public void configure(Header header, Layout layout) { viz.title = "CO₂ Emissions"; viz.unit = "CO₂ [g]"; viz.description = "per day"; - viz.height = 12.; - viz.cellSize = 100; - viz.opacity = 0.2; - viz.maxHeight = 100; - viz.projection = "EPSG:25832"; - viz.zoom = data.context().mapZoomLevel; - viz.center = data.context().getCenter(); - viz.setColorRamp("greenRed", 10, false); + DashboardUtils.setGridMapStandards(viz, data, this.coordinateSystem); viz.file = data.computeWithPlaceholder(AirPollutionAnalysis.class, "emissions_grid_per_day.%s", "avro"); }); @@ -73,15 +72,7 @@ public void configure(Header header, Layout layout) { viz.title = "CO₂ Emissions"; viz.unit = "CO₂ [g]"; viz.description = "per hour"; - viz.height = 12.; - viz.cellSize = 100; - viz.opacity = 0.2; - viz.maxHeight = 100; - viz.projection = "EPSG:25832"; - viz.zoom = data.context().mapZoomLevel; - viz.center = data.context().getCenter(); - - viz.setColorRamp("greenRed", 10, false); + DashboardUtils.setGridMapStandards(viz, data, this.coordinateSystem); viz.file = data.computeWithPlaceholder(AirPollutionAnalysis.class, "emissions_grid_per_hour.%s", "avro"); }); diff --git a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/NoiseDashboard.java b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/NoiseDashboard.java index 48f173a8adb..c345d0da7fe 100644 --- a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/NoiseDashboard.java +++ b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/NoiseDashboard.java @@ -1,11 +1,8 @@ package org.matsim.simwrapper.dashboard; import org.matsim.application.analysis.noise.NoiseAnalysis; -import org.matsim.application.analysis.population.StuckAgentAnalysis; import org.matsim.application.prepare.network.CreateAvroNetwork; -import org.matsim.simwrapper.Dashboard; -import org.matsim.simwrapper.Header; -import org.matsim.simwrapper.Layout; +import org.matsim.simwrapper.*; import org.matsim.simwrapper.viz.ColorScheme; import org.matsim.simwrapper.viz.GridMap; import org.matsim.simwrapper.viz.MapPlot; @@ -19,13 +16,14 @@ public class NoiseDashboard implements Dashboard { private double minDb = 40; private double maxDb = 80; + private final String coordinateSystem; + /** - * Set the min and max values for the noise map. + * Best provide the crs from {@link org.matsim.core.config.groups.GlobalConfigGroup} + * @param coordinateSystem for the {@link GridMap} */ - public NoiseDashboard withMinMaxDb(double minDb, double maxDb) { - this.minDb = minDb; - this.maxDb = maxDb; - return this; + public NoiseDashboard(String coordinateSystem) { + this.coordinateSystem = coordinateSystem; } @Override @@ -64,52 +62,30 @@ 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.1; - viz.maxHeight = 40; - viz.center = data.context().getCenter(); - viz.zoom = data.context().mapZoomLevel; - viz.setColorRamp(new double[]{30, 40, 50, 60, 70}, new String[]{"#1175b3", "#95c7df", "#dfdb95", "#dfb095", "#f4a986", "#cc0c27"}); + DashboardUtils.setGridMapStandards(viz, data, this.coordinateSystem); viz.file = data.computeWithPlaceholder(NoiseAnalysis.class, "immission_per_day.%s", "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.center = data.context().getCenter(); - viz.zoom = data.context().mapZoomLevel; - viz.setColorRamp(new double[]{30, 40, 50, 60, 70}, new String[]{"#1175b3", "#95c7df", "#dfdb95", "#dfb095", "#f4a986", "#cc0c27"}); + DashboardUtils.setGridMapStandards(viz, data, this.coordinateSystem); viz.file = data.computeWithPlaceholder(NoiseAnalysis.class, "immission_per_hour.%s", "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.setColorRamp(ColorScheme.Oranges); + DashboardUtils.setGridMapStandards(viz, data, this.coordinateSystem); viz.file = data.computeWithPlaceholder(NoiseAnalysis.class, "damages_receiverPoint_per_day.%s", "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.center = data.context().getCenter(); - viz.zoom = data.context().mapZoomLevel; -// viz.setColorRamp(new double[]{30, 40, 50, 60, 70}, new String[]{"#1175b3", "#95c7df", "#dfdb95", "#dfb095", "#f4a986", "#cc0c27"}); - viz.setColorRamp(ColorScheme.Oranges); + DashboardUtils.setGridMapStandards(viz, data, this.coordinateSystem); viz.file = data.computeWithPlaceholder(NoiseAnalysis.class, "damages_receiverPoint_per_hour.%s", "avro"); }); + + } + } diff --git a/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/EmissionsDashboardTest.java b/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/EmissionsDashboardTest.java index 3eb8a85e3f4..822a7b467a5 100644 --- a/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/EmissionsDashboardTest.java +++ b/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/EmissionsDashboardTest.java @@ -57,7 +57,7 @@ void generate() { emissionsConfig.setDetailedVsAverageLookupBehavior(EmissionsConfigGroup.DetailedVsAverageLookupBehavior.tryDetailedThenTechnologyAverageThenAverageTable); SimWrapper sw = SimWrapper.create() - .addDashboard(new EmissionsDashboard()); + .addDashboard(new EmissionsDashboard(config.global().getCoordinateSystem())); Controler controler = MATSimApplication.prepare(new TestScenario(sw), config); diff --git a/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/NoiseDashboardTests.java b/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/NoiseDashboardTests.java index fdc846cdff5..a4ce705e001 100644 --- a/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/NoiseDashboardTests.java +++ b/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/NoiseDashboardTests.java @@ -38,7 +38,7 @@ void generate() { simWrapperConfigGroup.defaultParams().shp = IOUtils.extendUrl(kelheim, "area/area.shp").toString(); - SimWrapper sw = SimWrapper.create(config).addDashboard(new NoiseDashboard()); + SimWrapper sw = SimWrapper.create(config).addDashboard(new NoiseDashboard(config.global().getCoordinateSystem())); Controler controler = MATSimApplication.prepare(new TestScenario(sw), config); controler.run();