Skip to content

Commit

Permalink
Merge pull request #3398 from matsim-org/noiseAnalysis
Browse files Browse the repository at this point in the history
NoiseAnalysis: set the scale factor for according to sample size
  • Loading branch information
tschlenther authored Aug 7, 2024
2 parents a382078 + 63713ba commit 12b08e1
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.matsim.application.analysis.noise;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.locationtech.jts.geom.Envelope;
import org.matsim.api.core.v01.Coord;
import org.matsim.api.core.v01.Scenario;
Expand All @@ -8,6 +10,7 @@
import org.matsim.application.MATSimAppCommand;
import org.matsim.application.options.InputOptions;
import org.matsim.application.options.OutputOptions;
import org.matsim.application.options.SampleOptions;
import org.matsim.application.options.ShpOptions;
import org.matsim.contrib.noise.NoiseConfigGroup;
import org.matsim.contrib.noise.NoiseOfflineCalculation;
Expand Down Expand Up @@ -38,6 +41,8 @@
)
public class NoiseAnalysis implements MATSimAppCommand {

private static final Logger log = LogManager.getLogger(NoiseAnalysis.class);

@CommandLine.Mixin
private final InputOptions input = InputOptions.ofCommand(NoiseAnalysis.class);
@CommandLine.Mixin
Expand All @@ -46,6 +51,9 @@ public class NoiseAnalysis implements MATSimAppCommand {
@CommandLine.Mixin
private final ShpOptions shp = new ShpOptions();

@CommandLine.Mixin
private final SampleOptions sampleOptions = new SampleOptions();

@CommandLine.Option(names = "--consider-activities", split = ",", description = "Considered activities for noise calculation." +
" Use asterisk ('*') for acttype prefixes, if all such acts shall be considered.", defaultValue = "h,w,home*,work*")
private Set<String> considerActivities;
Expand Down Expand Up @@ -89,6 +97,16 @@ public Integer call() throws Exception {
noiseParameters.setNoiseBarriersFilePath(noiseBarrierFile);
}

if(! sampleOptions.isSet() && noiseParameters.getScaleFactor() == 1d){
log.warn("You didn't provide the simulation sample size via command line option --sample-size! This means, noise damages are not scaled!!!");
} else if (noiseParameters.getScaleFactor() == 1d){
if (sampleOptions.getSample() == 1d){
log.warn("Be aware that the noise output is not scaled. This might be unintended. If so, assure to provide the sample size via command line option --sample-size, in the SimWrapperConfigGroup," +
"or provide the scaleFactor (the inverse of the sample size) in the NoiseConfigGroup!!!");
}
noiseParameters.setScaleFactor(sampleOptions.getUpscaleFactor());
}

Scenario scenario = ScenarioUtils.loadScenario(config);

String outputFilePath = output.getPath().getParent() == null ? "." : output.getPath().getParent().toString();
Expand Down Expand Up @@ -120,6 +138,7 @@ private Config prepareConfig() {
config.facilities().setInputFile(null);
config.eventsManager().setNumberOfThreads(null);
config.eventsManager().setEstimatedNumberOfEvents(null);
//ts, aug '24: not sure if and why we need to set 1 thread
config.global().setNumberOfThreads(1);

return config;
Expand Down

0 comments on commit 12b08e1

Please sign in to comment.