From 0ab49befc13b74a70b9b97c2d3e68a683213c15c Mon Sep 17 00:00:00 2001 From: schlenther Date: Thu, 7 Nov 2024 12:48:11 +0100 Subject: [PATCH 1/2] TODO comment --- .../src/main/java/org/matsim/contrib/noise/Grid.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/contribs/noise/src/main/java/org/matsim/contrib/noise/Grid.java b/contribs/noise/src/main/java/org/matsim/contrib/noise/Grid.java index 6815899be8a..ea63e77e905 100644 --- a/contribs/noise/src/main/java/org/matsim/contrib/noise/Grid.java +++ b/contribs/noise/src/main/java/org/matsim/contrib/noise/Grid.java @@ -271,6 +271,14 @@ private void setActivityCoord2NearestReceiverPointId () { for (Coord coord : consideredActivityCoordsForSpatialFunctionality) { // TODO maybe add a check here so we consider only the rp in the 9 surrounding cells? + + //TODO: ts, nov' 24: this might lead to problems, when we conduct noise analysis only in a (small) focus area of the scenario + // i.e. when the Grid is considerable smaller than the network (e.g. by setting a corresponding shp when run through simwrapper). + // The problem would be that the edge cells are then filled with activities from the outside. Maybe we should only consider activities that are inside the grid (+ maybe a small buffer)!? + // As consideredActivityCoordsForSpatialFunctionality is cleared after running this method, here, we can conduct the filtering, here. + // In other words: activityCoord2receiverPointId is all that needs to be changes in this class. + // However, we then need to account for null values when querying that map from PersonActivityTracker. + ReceiverPoint rp = qTree.getClosest(coord.getX(), coord.getY()); if(rp != null) { if(activityCoord2receiverPointId.put(coord, rp.getId()) != null){ From 2aef5f6e7d1fc88617a71c946bb19a95679642e8 Mon Sep 17 00:00:00 2001 From: schlenther Date: Thu, 7 Nov 2024 17:02:17 +0100 Subject: [PATCH 2/2] compute noise damages only for activities that are inside the specified grid --- .../java/org/matsim/contrib/noise/Grid.java | 33 +++++++++++-------- .../contrib/noise/NoiseContextImpl.java | 4 +-- .../dashboard/NoiseDashboardTests.java | 17 +++++++++- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/contribs/noise/src/main/java/org/matsim/contrib/noise/Grid.java b/contribs/noise/src/main/java/org/matsim/contrib/noise/Grid.java index ea63e77e905..48eb2951430 100644 --- a/contribs/noise/src/main/java/org/matsim/contrib/noise/Grid.java +++ b/contribs/noise/src/main/java/org/matsim/contrib/noise/Grid.java @@ -268,27 +268,32 @@ private void setActivityCoord2NearestReceiverPointId () { counter.printCounter(); counter = new Counter("compute nearest receiver-points #"); + Counter otherCounter = new Counter("activities outside grid #"); for (Coord coord : consideredActivityCoordsForSpatialFunctionality) { // TODO maybe add a check here so we consider only the rp in the 9 surrounding cells? - - //TODO: ts, nov' 24: this might lead to problems, when we conduct noise analysis only in a (small) focus area of the scenario - // i.e. when the Grid is considerable smaller than the network (e.g. by setting a corresponding shp when run through simwrapper). - // The problem would be that the edge cells are then filled with activities from the outside. Maybe we should only consider activities that are inside the grid (+ maybe a small buffer)!? - // As consideredActivityCoordsForSpatialFunctionality is cleared after running this method, here, we can conduct the filtering, here. - // In other words: activityCoord2receiverPointId is all that needs to be changes in this class. - // However, we then need to account for null values when querying that map from PersonActivityTracker. - - ReceiverPoint rp = qTree.getClosest(coord.getX(), coord.getY()); - if(rp != null) { - if(activityCoord2receiverPointId.put(coord, rp.getId()) != null){ - log.warn("this must not happen"); + // ts, nov' 24: ---> might be done by the following filtering (by grid) ?? + + // Filter activity coords that are within the quadTree. + // I do not know, why whe put a buffer around the grid when instantiating the QuadTree, above, but I'll keep it for now + // tschlenther, nov '24 + if (coord.getX() >= xCoordMin && coord.getX() <= xCoordMax && + coord.getY() >= yCoordMin && coord.getY() <= yCoordMax){ + + ReceiverPoint rp = qTree.getClosest(coord.getX(), coord.getY()); + if(rp != null) { + if(activityCoord2receiverPointId.put(coord, rp.getId()) != null){ + log.warn("this must not happen"); + } } - } - counter.incCounter(); + counter.incCounter(); + } else { + otherCounter.incCounter(); + } } counter.printCounter(); + otherCounter.printCounter(); } private void readReceiverPoints(String file, CoordinateTransformation ct) throws IOException { diff --git a/contribs/noise/src/main/java/org/matsim/contrib/noise/NoiseContextImpl.java b/contribs/noise/src/main/java/org/matsim/contrib/noise/NoiseContextImpl.java index d941615320a..bad61d3696c 100644 --- a/contribs/noise/src/main/java/org/matsim/contrib/noise/NoiseContextImpl.java +++ b/contribs/noise/src/main/java/org/matsim/contrib/noise/NoiseContextImpl.java @@ -201,9 +201,9 @@ private void checkConsistency() { || this.grid.getGridParams().getReceiverPointsGridMinX() != 0. || this.grid.getGridParams().getReceiverPointsGridMaxY() != 0. || this.grid.getGridParams().getReceiverPointsGridMinY() != 0.) { - log.warn("In order to keep track of the agent activities, the grid of receiver points should not be limited to a set of predefined coordinates." + log.warn("In order to keep track of ALL the agent activities, the grid of receiver points should not be limited to a set of predefined coordinates." + "For a grid covering all activity locations, set the minimum and maximum x/y parameters to 0.0. " - + "There will be more agents mapped to the receiver points at the edges. Only the inner receiver points should be used for analysis."); + + "Damages will be computed only for activities that are performed within the receiver point grid."); } if (this.grid.getGridParams().getReceiverPointsGridMinX() == 0. && this.grid.getGridParams().getReceiverPointsGridMinY() == 0. && this.grid.getGridParams().getReceiverPointsGridMaxX() == 0. && this.grid.getGridParams().getReceiverPointsGridMaxY() == 0.) { 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 a4ce705e001..178bfa9109f 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 @@ -1,5 +1,6 @@ package org.matsim.simwrapper.dashboard; +import com.opencsv.CSVReader; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -15,6 +16,7 @@ import org.matsim.testcases.MatsimTestUtils; +import java.io.FileReader; import java.net.URL; import java.nio.file.Path; @@ -51,6 +53,19 @@ void generate() { .isDirectoryContaining("glob:**damages_receiverPoint_per_day.avro") .isDirectoryContaining("glob:**noise_stats.csv"); - //TODO check content / values of the files + double totalDamages; + double totalImmissions; + try { + CSVReader reader = new CSVReader(new FileReader(utils.getOutputDirectory() + "analysis/noise/noise_stats.csv")); + reader.skip(1); + totalDamages = Double.parseDouble(reader.readNext()[1]); + totalImmissions = Double.parseDouble(reader.readNext()[1]); + } catch (Exception e) { + throw new RuntimeException(e); + } + + Assertions.assertThat(totalDamages == 3573114.25); + Assertions.assertThat( totalImmissions == 2.688); + } }