Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce DashboardUtils ... #3501

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public List<Dashboard> 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());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,48 @@
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;

/**
* 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"));
Expand All @@ -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");
});

Expand All @@ -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");
});

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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");
});


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading