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

noise: filter activities spatially #3549

Merged
merged 3 commits into from
Nov 7, 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
25 changes: 19 additions & 6 deletions contribs/noise/src/main/java/org/matsim/contrib/noise/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,19 +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?
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,6 +16,7 @@
import org.matsim.testcases.MatsimTestUtils;


import java.io.FileReader;
import java.net.URL;
import java.nio.file.Path;

Expand Down Expand Up @@ -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);

}
}
Loading