Skip to content

Commit

Permalink
issue with lden. we cant create a lden source, as attenuation depend …
Browse files Browse the repository at this point in the history
…on each period. i have to reword that special part.
  • Loading branch information
nicolas-f committed Feb 5, 2025
1 parent b955939 commit 6586051
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 172 deletions.
1 change: 0 additions & 1 deletion noisemodelling-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.noise_planet.noisemodelling.pathfinder.profilebuilder.ProfileBuilder;
import org.noise_planet.noisemodelling.pathfinder.profilebuilder.Wall;
import org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions;
import org.noise_planet.noisemodelling.propagation.cnossos.AttenuationCnossosParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -34,12 +35,15 @@
public class DefaultTableLoader implements NoiseMapByReceiverMaker.PropagationProcessDataFactory {
protected static final Logger LOGGER = LoggerFactory.getLogger(DefaultTableLoader.class);
NoiseMapByReceiverMaker noiseMapByReceiverMaker;
NoiseMapDatabaseParameters noiseMapDatabaseParameters = new NoiseMapDatabaseParameters();
// Soil areas are split by the provided size in order to reduce the propagation time
protected double groundSurfaceSplitSideLength = 200;
public List<Integer> frequencyArray = Arrays.asList(AcousticIndicatorsFunctions.asOctaveBands(ProfileBuilder.DEFAULT_FREQUENCIES_THIRD_OCTAVE));
public List<Double> exactFrequencyArray = Arrays.asList(AcousticIndicatorsFunctions.asOctaveBands(ProfileBuilder.DEFAULT_FREQUENCIES_EXACT_THIRD_OCTAVE));
public List<Double> aWeightingArray = Arrays.asList(AcousticIndicatorsFunctions.asOctaveBands(ProfileBuilder.DEFAULT_FREQUENCIES_A_WEIGHTING_THIRD_OCTAVE));
/**
* Define attenuation settings to apply for each period
*/
public Map<String, AttenuationCnossosParameters> cnossosParametersPerPeriod = new HashMap<>();

public static final int DEFAULT_FETCH_SIZE = 300;
protected int fetchSize = DEFAULT_FETCH_SIZE;
Expand Down Expand Up @@ -124,6 +128,7 @@ public SceneWithEmission create(Connection connection, CellIndex cellIndex,
profileBuilder.setFrequencyArray(frequencyArray);
SceneWithEmission scene = new SceneWithEmission(profileBuilder, noiseMapByReceiverMaker.getSceneInputSettings());
scene.setDirectionAttributes(directionAttributes);
scene.cnossosParametersPerPeriod = cnossosParametersPerPeriod;

// //////////////////////////////////////////////////////
// feed freeFieldFinder for fast intersection query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public PathSearchStrategy onNewCutPlane(CutProfile cutProfile) {
}
} else {
// Apply period attenuation to emission for each time period covered by the source emission
double[] defaultAttenuation = new double[0];
if(scene.wjSources.containsKey(sourcePk)) {
ArrayList<SceneWithEmission.PeriodEmission> emissions = scene.wjSources.get(sourcePk);
double[] minimalPowerForAllPeriods = new double[0];
Expand All @@ -193,9 +194,12 @@ public PathSearchStrategy onNewCutPlane(CutProfile cutProfile) {
attenuation = dBToW(processAndStoreAttenuation(scene.cnossosParametersPerPeriod.get(period),
cnossosPath, period));
} else {
// None ? ok fallback to default settings
attenuation = dBToW(processAndStoreAttenuation(scene.defaultCnossosParameters,
cnossosPath, ""));
if(defaultAttenuation.length == 0) {
// None ? ok fallback to default settings
defaultAttenuation = dBToW(processAndStoreAttenuation(scene.defaultCnossosParameters,
cnossosPath, ""));
}
attenuation = defaultAttenuation;
}
double[] levels = multiplicationArray(attenuation, periodEmission.emission);
ReceiverNoiseLevel receiverNoiseLevel =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@

package org.noise_planet.noisemodelling.jdbc.output;

import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.LineString;
import org.locationtech.jts.geom.PrecisionModel;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import org.locationtech.jts.geom.*;
import org.noise_planet.noisemodelling.jdbc.NoiseMapByReceiverMaker;
import org.noise_planet.noisemodelling.jdbc.NoiseMapDatabaseParameters;
import org.noise_planet.noisemodelling.jdbc.input.DefaultTableLoader;
import org.noise_planet.noisemodelling.jdbc.input.SceneWithEmission;
import org.noise_planet.noisemodelling.jdbc.utils.StringPreparedStatements;
import org.noise_planet.noisemodelling.pathfinder.profilebuilder.CutProfile;
import org.noise_planet.noisemodelling.pathfinder.profilebuilder.ProfileBuilder;
import org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions;
import org.noise_planet.noisemodelling.pathfinder.utils.geometry.CoordinateMixin;
import org.noise_planet.noisemodelling.pathfinder.utils.geometry.LineSegmentMixin;
import org.noise_planet.noisemodelling.propagation.ReceiverNoiseLevel;
import org.noise_planet.noisemodelling.propagation.cnossos.CnossosPath;
import org.slf4j.Logger;
Expand Down Expand Up @@ -54,6 +58,7 @@ public class NoiseMapWriter implements Callable<Boolean> {
NoiseMapDatabaseParameters databaseParameters;
ResultsCache resultsCache;
Writer writer;
ObjectWriter jsonWriter;
int srid;
public List<Integer> frequencyArray = Arrays.asList(AcousticIndicatorsFunctions.asOctaveBands(ProfileBuilder.DEFAULT_FREQUENCIES_THIRD_OCTAVE));
public double[] aWeightingArray = Arrays.stream(
Expand All @@ -80,6 +85,21 @@ public NoiseMapWriter(Connection connection, NoiseMapByReceiverMaker noiseMapByR
}
this.exitWhenDone = exitWhenDone;
this.aborted = aborted;
if(databaseParameters.exportCnossosPathWithAttenuation) {
ObjectMapper mapper = new ObjectMapper();
mapper.addMixIn(Coordinate.class, CoordinateMixin.class);
mapper.addMixIn(LineSegment.class, LineSegmentMixin.class);
jsonWriter = mapper.writer();
}
}

public String propagationPathAsJSON(CnossosPath path) throws JsonProcessingException {
return jsonWriter.writeValueAsString(path);
}

public static CnossosPath jsonToPropagationPath(String json) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(json, CnossosPath.class);
}

/**
Expand All @@ -88,20 +108,28 @@ public NoiseMapWriter(Connection connection, NoiseMapByReceiverMaker noiseMapByR
* @throws SQLException if an SQL exception occurs while executing the INSERT query
*/
void processRaysStack(ConcurrentLinkedDeque<CnossosPath> stack) throws SQLException {
boolean exportPeriod = !noiseMapByReceiverMaker.getSceneInputSettings().getInputMode().
equals(SceneWithEmission.SceneDatabaseInputSettings.INPUT_MODE.INPUT_MODE_ATTENUATION);
StringBuilder query = new StringBuilder("INSERT INTO " + databaseParameters.raysTable +
"(the_geom , IDRECEIVER , IDSOURCE");
if(databaseParameters.exportCnossosPathWithAttenuation) {
query.append(", GEOJSON");
query.append(", PATH");
}
if(databaseParameters.exportAttenuationMatrix) {
query.append(", LEQ, PERIOD");
query.append(", LEQ");
}
if(exportPeriod) {
query.append(", PERIOD");
}
query.append(") VALUES (?, ?, ?");
if(databaseParameters.exportCnossosPathWithAttenuation) {
query.append(", ?");
}
if(databaseParameters.exportAttenuationMatrix) {
query.append(", ?, ?");
query.append(", ?");
}
if(exportPeriod) {
query.append(", ?");
}
query.append(");");
// PK, GEOM, ID_RECEIVER, ID_SOURCE
Expand All @@ -122,17 +150,19 @@ void processRaysStack(ConcurrentLinkedDeque<CnossosPath> stack) throws SQLExcept
ps.setLong(parameterIndex++, row.getCutProfile().getReceiver().receiverPk);
ps.setLong(parameterIndex++, row.getCutProfile().getSource().sourcePk);
if(databaseParameters.exportCnossosPathWithAttenuation) {
String geojson = "";
String json = "";
try {
geojson = row.profileAsJSON(databaseParameters.geojsonColumnSizeLimit);
json = propagationPathAsJSON(row);
} catch (IOException ex) {
//ignore
}
ps.setString(parameterIndex++, geojson);
ps.setString(parameterIndex++, json);
}
if(databaseParameters.exportAttenuationMatrix) {
double globalValue = sumDbArray(row.aGlobal);
ps.setDouble(parameterIndex++, globalValue);
}
if(exportPeriod) {
ps.setString(parameterIndex++, row.getTimePeriod());
}
ps.addBatch();
Expand Down Expand Up @@ -324,6 +354,8 @@ private void processQuery(String query) throws SQLException, IOException {
*/
public void init() throws SQLException, IOException {
if(databaseParameters.getExportRaysMethod() == NoiseMapDatabaseParameters.ExportRaysMethods.TO_RAYS_TABLE) {
boolean exportPeriod = !noiseMapByReceiverMaker.getSceneInputSettings().getInputMode().
equals(SceneWithEmission.SceneDatabaseInputSettings.INPUT_MODE.INPUT_MODE_ATTENUATION);
if(databaseParameters.dropResultsTable) {
String q = String.format("DROP TABLE IF EXISTS %s;", databaseParameters.raysTable);
processQuery(q);
Expand All @@ -333,10 +365,13 @@ public void init() throws SQLException, IOException {
sb.append(srid);
sb.append("), IDRECEIVER bigint NOT NULL, IDSOURCE bigint NOT NULL");
if(databaseParameters.exportCnossosPathWithAttenuation) {
sb.append(", GEOJSON VARCHAR");
sb.append(", PATH VARCHAR");
}
if(databaseParameters.exportAttenuationMatrix) {
sb.append(", LEQ DOUBLE, PERIOD VARCHAR");
sb.append(", LEQ DOUBLE");
}
if(exportPeriod) {
sb.append(", PERIOD VARCHAR");
}
sb.append(");");
processQuery(sb.toString());
Expand Down
Loading

0 comments on commit 6586051

Please sign in to comment.