Skip to content

Commit

Permalink
Complete unit test for regression
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-f committed Dec 4, 2024
1 parent 4062964 commit 77ab3c0
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import java.sql.SQLException;
import java.util.*;

import static org.noise_planet.noisemodelling.pathfinder.utils.Utils.dbaToW;
import static org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions.dbaToW;

/**
* Read source database and compute the sound emission spectrum of roads sources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ public void setPropagationProcessDataFactory(PropagationProcessDataFactory propa
this.propagationProcessDataFactory = propagationProcessDataFactory;
}

/*public int getThreadCount() {
public int getThreadCount() {
return threadCount;
}*/
}

public void setThreadCount(int threadCount) {
this.threadCount = threadCount;
Expand Down Expand Up @@ -322,7 +322,7 @@ public void initialize(Connection connection, ProgressVisitor progression) throw
}

/**
* A factory interface for creating propagation process data for noise map computation.v
* A factory interface for creating propagation process data for noise map computation.
*/
public interface PropagationProcessDataFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

import org.noise_planet.noisemodelling.pathfinder.IComputePathsOut;
import org.noise_planet.noisemodelling.pathfinder.cnossos.CnossosPath;
import org.noise_planet.noisemodelling.pathfinder.utils.Utils;
import org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions;
import org.noise_planet.noisemodelling.propagation.Attenuation;
import org.noise_planet.noisemodelling.propagation.AttenuationVisitor;

import java.util.*;
import java.util.concurrent.ConcurrentLinkedDeque;

import static org.noise_planet.noisemodelling.pathfinder.utils.Utils.*;
import static org.noise_planet.noisemodelling.pathfinder.utils.Utils.wToDba;
import static org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions.*;
import static org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions.wToDba;


public class NoiseMapInStack implements IComputePathsOut {
Expand Down Expand Up @@ -107,7 +107,7 @@ public double[] addPropagationPaths(long sourceId, double sourceLi, long receive
globalLevel = lDENAttenuationVisitor[timePeriod.ordinal()].addPropagationPaths(sourceId, sourceLi,
receiverId, Collections.singletonList(pathParameters));
} else {
globalLevel = Utils.sumDbArray(globalLevel, lDENAttenuationVisitor[timePeriod.ordinal()].addPropagationPaths(sourceId, sourceLi,
globalLevel = AcousticIndicatorsFunctions.sumDbArray(globalLevel, lDENAttenuationVisitor[timePeriod.ordinal()].addPropagationPaths(sourceId, sourceLi,
receiverId, Collections.singletonList(pathParameters)));
}
pathParameters.setTimePeriod(timePeriod.name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public abstract class NoiseMapLoader {
protected GeometryFactory geometryFactory;
protected int parallelComputationCount = 0;
// Initialised attributes
/**
* Side computation cell count (same on X and Y)
*/
protected int gridDim = 0;
protected Envelope mainEnvelope = new Envelope();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

import static org.noise_planet.noisemodelling.jdbc.NoiseMapMaker.BATCH_MAX_SIZE;
import static org.noise_planet.noisemodelling.jdbc.NoiseMapMaker.WRITER_CACHE;
import static org.noise_planet.noisemodelling.pathfinder.utils.Utils.*;
import static org.noise_planet.noisemodelling.pathfinder.utils.Utils.dbaToW;
import static org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions.*;
import static org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions.dbaToW;


public class NoiseMapWriter implements Runnable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@
import org.noise_planet.noisemodelling.pathfinder.profilebuilder.ProfileBuilder;
import org.noise_planet.noisemodelling.pathfinder.profilebuilder.ProfileBuilderDecorator;
import org.noise_planet.noisemodelling.pathfinder.profilebuilder.WallAbsorption;
import org.noise_planet.noisemodelling.pathfinder.utils.Utils;
import org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions;
import org.noise_planet.noisemodelling.pathfinder.utils.geometry.Orientation;
import org.noise_planet.noisemodelling.pathfinder.utils.geometry.QueryRTree;
import org.noise_planet.noisemodelling.propagation.cnossos.AttenuationCnossosParameters;
import org.noise_planet.noisemodelling.propagation.Attenuation;
import org.noise_planet.noisemodelling.propagation.cnossos.AttenuationCnossos;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.exc.StreamWriteException;

import java.io.*;
import java.util.*;
Expand All @@ -42,22 +41,21 @@
import static java.lang.Double.NaN;
import static org.junit.jupiter.api.Assertions.*;
import static org.noise_planet.noisemodelling.jdbc.Utils.*;
import static org.noise_planet.noisemodelling.pathfinder.utils.Utils.*;
import static org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions.*;

/**
* Test class evaluation and testing attenuation values.
*/
public class AttenuationCnossosTest {

private final static Logger LOGGER = LoggerFactory.getLogger(AttenuationCnossosTest.class);
private static final int [] frequencies = new int[]{63,125,250,500,1000,2000,4000,8000};
private static final double ERROR_EPSILON_HIGHEST = 1e5;
private static final double ERROR_EPSILON_VERY_HIGH = 15;
private static final double ERROR_EPSILON_HIGH = 3;
private static final double ERROR_EPSILON_MEDIUM = 1;
private static final double ERROR_EPSILON_LOW = 0.5;
private static final double ERROR_EPSILON_VERY_LOW = 0.1;
private static final double ERROR_EPSILON_LOWEST = 0.02;
public static final double ERROR_EPSILON_HIGHEST = 1e5;
public static final double ERROR_EPSILON_VERY_HIGH = 15;
public static final double ERROR_EPSILON_HIGH = 3;
public static final double ERROR_EPSILON_MEDIUM = 1;
public static final double ERROR_EPSILON_LOW = 0.5;
public static final double ERROR_EPSILON_VERY_LOW = 0.1;
public static final double ERROR_EPSILON_LOWEST = 0.02;

private static final double[] HOM_WIND_ROSE = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
private static final double[] FAV_WIND_ROSE = new double[]{1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
Expand Down Expand Up @@ -7449,7 +7447,7 @@ public void TestFavorableConditionAttenuationRose() {
int maxPowerReceiverIndex = -1;
double maxGlobalValue = Double.NEGATIVE_INFINITY;
for (Attenuation.SourceReceiverAttenuation v : propDataOut.getVerticesSoundLevel()) {
double globalValue = Utils.sumDbArray(v.value);
double globalValue = AcousticIndicatorsFunctions.sumDbArray(v.value);
if (globalValue > maxGlobalValue) {
maxGlobalValue = globalValue;
maxPowerReceiverIndex = (int) v.receiverId;
Expand Down Expand Up @@ -7689,10 +7687,10 @@ public void testReflexionConvergence() {
Arrays.fill(sourcePower, 70.0);
for(CnossosPath proPath : propDataOut.getPropagationPaths()) {
double[] attenuationGlobal = proPath.aGlobal;
double[] contributionPower = Utils.sumArray(attenuationGlobal, sourcePower);
receiverPower = Utils.sumDbArray(receiverPower, contributionPower);
double[] contributionPower = AcousticIndicatorsFunctions.sumArray(attenuationGlobal, sourcePower);
receiverPower = AcousticIndicatorsFunctions.sumDbArray(receiverPower, contributionPower);
}
double globalPowerAtReceiver = Utils.wToDba(Utils.sumArray(Utils.dbaToW(receiverPower)));
double globalPowerAtReceiver = AcousticIndicatorsFunctions.wToDba(AcousticIndicatorsFunctions.sumArray(AcousticIndicatorsFunctions.dbaToW(receiverPower)));
if(i == 0) {
firstPowerAtReceiver = globalPowerAtReceiver;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
package org.noise_planet.noisemodelling.jdbc;

import org.checkerframework.checker.units.qual.A;
import org.h2gis.api.EmptyProgressVisitor;
import org.h2gis.api.ProgressVisitor;
import org.h2gis.functions.factory.H2GISDBFactory;
import org.h2gis.functions.io.geojson.GeoJsonRead;
import org.h2gis.functions.io.shp.SHPRead;
import org.h2gis.utilities.JDBCUtilities;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.noise_planet.noisemodelling.jdbc.utils.CellIndex;
import org.noise_planet.noisemodelling.pathfinder.IComputePathsOut;
import org.noise_planet.noisemodelling.pathfinder.cnossos.CnossosPath;
import org.noise_planet.noisemodelling.pathfinder.path.Scene;
import org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions;
import org.noise_planet.noisemodelling.pathfinder.utils.profiler.RootProgressVisitor;
import org.noise_planet.noisemodelling.propagation.Attenuation;

import java.net.URL;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.Statement;
import java.util.*;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.*;
import static org.noise_planet.noisemodelling.jdbc.Utils.getRunScriptRes;

public class RegressionTest {
Expand All @@ -44,7 +37,7 @@ public void tearDown() throws Exception {
}

/**
* Got reflection out of bound in this scenario
* Got reflection index out of bound exception in this scenario in the past (source->reflection->h diffraction->receiver)
*/
@Test
public void testScenarioOutOfBoundException() throws Exception {
Expand All @@ -63,19 +56,22 @@ public void testScenarioOutOfBoundException() throws Exception {
// Building height field name
noiseMapByReceiverMaker.setHeightField("HEIGHT");


// Init custom input in order to compute more than just attenuation
// LW_ROADS contain Day Evening Night emission spectrum
NoiseMapParameters noiseMapParameters = new NoiseMapParameters(NoiseMapParameters.INPUT_MODE.INPUT_MODE_LW_DEN);
noiseMapParameters.setExportRaysMethod(NoiseMapParameters.ExportRaysMethods.TO_MEMORY);

noiseMapParameters.setComputeLDay(false);
noiseMapParameters.setComputeLEvening(false);
noiseMapParameters.setComputeLNight(false);
noiseMapParameters.setComputeLDEN(true);
noiseMapParameters.keepAbsorption = true;

NoiseMapMaker tableWriter = new NoiseMapMaker(connection, noiseMapParameters);
NoiseMapMaker noiseMapMaker = new NoiseMapMaker(connection, noiseMapParameters);

noiseMapByReceiverMaker.setPropagationProcessDataFactory(tableWriter);
noiseMapByReceiverMaker.setComputeRaysOutFactory(tableWriter);
noiseMapByReceiverMaker.setPropagationProcessDataFactory(noiseMapMaker);
noiseMapByReceiverMaker.setComputeRaysOutFactory(noiseMapMaker);

RootProgressVisitor progressLogger = new RootProgressVisitor(1, true, 1);

Expand All @@ -90,22 +86,22 @@ public void testScenarioOutOfBoundException() throws Exception {
// Set of already processed receivers
Set<Long> receivers = new HashSet<>();

// Iterate over computation areas
List<IComputePathsOut> paths = new ArrayList<>();
try {
tableWriter.start();
// Fetch cell identifiers with receivers
Map<CellIndex, Integer> cells = noiseMapByReceiverMaker.searchPopulatedCells(connection);
ProgressVisitor progressVisitor = progressLogger.subProcess(cells.size());
for(CellIndex cellIndex : new TreeSet<>(cells.keySet())) {
// Run ray propagation
paths.add(noiseMapByReceiverMaker.evaluateCell(connection, cellIndex.getLatitudeIndex(),
cellIndex.getLongitudeIndex(), progressVisitor, receivers));
}
} finally {
tableWriter.stop();
// Fetch cell identifiers with receivers
Map<CellIndex, Integer> cells = noiseMapByReceiverMaker.searchPopulatedCells(connection);
ProgressVisitor progressVisitor = progressLogger.subProcess(cells.size());
assertEquals(1, cells.size());
for(CellIndex cellIndex : new TreeSet<>(cells.keySet())) {
// Run ray propagation
IComputePathsOut out = noiseMapByReceiverMaker.evaluateCell(connection, cellIndex.getLatitudeIndex(),
cellIndex.getLongitudeIndex(), progressVisitor, receivers);
assertInstanceOf(NoiseMap.class, out);
NoiseMap rout = (NoiseMap) out;
assertEquals(1, rout.attenuatedPaths.lDenLevels.size());
Attenuation.SourceReceiverAttenuation sl = rout.attenuatedPaths.lDenLevels.pop();
assertEquals(36.77, AcousticIndicatorsFunctions.sumDbArray(sl.value), AttenuationCnossosTest.ERROR_EPSILON_LOWEST);
}
assertEquals(1, paths.size());


}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
import java.util.*;

import static org.junit.jupiter.api.Assertions.*;
import static org.noise_planet.noisemodelling.pathfinder.utils.Utils.sumArray;
import static org.noise_planet.noisemodelling.pathfinder.utils.Utils.sumDbArray;
import static org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions.sumArray;
import static org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions.sumDbArray;

public class TimePeriodParametersNoiseMapByReceiverMakerFactoryTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.ArrayList;
import java.util.List;

import static org.noise_planet.noisemodelling.pathfinder.utils.Utils.*;
import static org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions.*;

public class Utils {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.h2gis.api.ProgressVisitor;
import org.locationtech.jts.algorithm.*;
import org.locationtech.jts.geom.*;
import org.locationtech.jts.geom.impl.CoordinateArraySequence;
import org.locationtech.jts.math.Vector2D;
import org.locationtech.jts.math.Vector3D;
import org.locationtech.jts.triangulate.quadedge.Vertex;
Expand All @@ -36,7 +35,6 @@
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
Expand All @@ -49,7 +47,7 @@
import static org.noise_planet.noisemodelling.pathfinder.profilebuilder.ProfileBuilder.IntersectionType.*;
import static org.noise_planet.noisemodelling.pathfinder.utils.geometry.GeometricAttenuation.getADiv;
import static org.noise_planet.noisemodelling.pathfinder.utils.geometry.GeometryUtils.projectPointOnLine;
import static org.noise_planet.noisemodelling.pathfinder.utils.Utils.*;
import static org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions.*;

/**
* @author Nicolas Fortin
Expand Down Expand Up @@ -1177,7 +1175,6 @@ private void updateReflectionPointAttributes(CutPoint reflectionPoint, CutProfil
*
* @param rcvCoord
* @param srcCoord
* @param favorable
* @param orientation
* @param receiverMirrorIndex
* @return propagation path list
Expand Down Expand Up @@ -1267,7 +1264,11 @@ public List<CnossosPath> computeReflexion(Coordinate rcvCoord, Coordinate srcCoo
MirrorReceiver firstPoint = rayPath.get(idPt);
MirrorReceiver secondPoint = rayPath.get(idPt + 1);
cutProfile = data.profileBuilder.getProfile(firstPoint.getReflectionPosition(),
secondPoint.getReflectionPosition(), data.gS, true);
secondPoint.getReflectionPosition(), data.gS, !data.computeVerticalDiffraction);
if(!cutProfile.isFreeField() && !data.computeVerticalDiffraction) {
// (maybe there is a blocking building/dem, and we disabled diffraction)
continue;
}
updateReflectionPointAttributes(cutProfile.getCutPoints().get(0), cutProfile, firstPoint);
if(!cutProfile.isFreeField() && !data.computeVerticalDiffraction) {
// (maybe there is a blocking building/dem, and we disabled diffraction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
package org.noise_planet.noisemodelling.pathfinder.path;

import org.locationtech.jts.geom.Coordinate;
import org.noise_planet.noisemodelling.pathfinder.profilebuilder.CutPoint;
import org.noise_planet.noisemodelling.pathfinder.utils.geometry.Orientation;

import java.io.DataInputStream;
Expand All @@ -22,7 +21,7 @@
import java.util.List;

import static java.lang.Double.isNaN;
import static org.noise_planet.noisemodelling.pathfinder.utils.Utils.sumArray;
import static org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions.sumArray;

public class PointPath {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,8 @@ public CutProfile getProfile(Coordinate sourceCoordinate, Coordinate receiverCoo
if(topoTree != null) {
addTopoCutPts(sourceCoordinate, receiverCoordinate, profile, stopAtObstacleOverSourceReceiver);
if(stopAtObstacleOverSourceReceiver && profile.hasTopographyIntersection) {
return new CutProfile();
profile.setCutPoints(Arrays.asList(profile.getSource(), profile.getReceiver()));
return profile;
}
} else {
profile.getSource().zGround = 0.0;
Expand All @@ -938,7 +939,8 @@ public CutProfile getProfile(Coordinate sourceCoordinate, Coordinate receiverCoo
LineSegment fullLine = new LineSegment(sourceCoordinate, receiverCoordinate);
addGroundBuildingCutPts(fullLine, profile, stopAtObstacleOverSourceReceiver);
if(stopAtObstacleOverSourceReceiver && profile.hasBuildingIntersection) {
return new CutProfile();
profile.setCutPoints(Arrays.asList(profile.getSource(), profile.getReceiver()));
return profile;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.Arrays;
import java.util.Locale;

public class Utils {
public class AcousticIndicatorsFunctions {

/**
* Convert Decbiel to Watt
Expand Down
Loading

0 comments on commit 77ab3c0

Please sign in to comment.