Skip to content

Commit

Permalink
use frequency prepend string on output
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-f committed Feb 6, 2025
1 parent 63bcac1 commit f3be62d
Show file tree
Hide file tree
Showing 10 changed files with 238 additions and 264 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
*/
public class NoiseMapByReceiverMaker extends GridMapMaker {
private final String receiverTableName;
private PropagationProcessDataFactory propagationProcessDataFactory = new DefaultTableLoader();
private TableLoader tableLoader = new DefaultTableLoader();
/** Tell table writer thread to empty current stacks then stop waiting for new data */
public AtomicBoolean exitWhenDone = new AtomicBoolean(false);
/** If true, all processing are aborted and all threads will be shutdown */
Expand Down Expand Up @@ -162,17 +162,17 @@ public void setComputeRaysOutFactory(IComputeRaysOutFactory computeRaysOutFactor

/**
* Do not call this method after {@link #initialize(Connection, ProgressVisitor)} has been called
* @param propagationProcessDataFactory Object that generate scene for each sub-cell using database data
* @param tableLoader Object that generate scene for each sub-cell using database data
*/
public void setPropagationProcessDataFactory(PropagationProcessDataFactory propagationProcessDataFactory) {
this.propagationProcessDataFactory = propagationProcessDataFactory;
public void setPropagationProcessDataFactory(TableLoader tableLoader) {
this.tableLoader = tableLoader;
}

/**
* @return Object that generate scene for each sub-cell using database data
*/
public PropagationProcessDataFactory getPropagationProcessDataFactory() {
return propagationProcessDataFactory;
public TableLoader getPropagationProcessDataFactory() {
return tableLoader;
}

public int getThreadCount() {
Expand Down Expand Up @@ -204,7 +204,7 @@ public SceneWithEmission prepareCell(Connection connection, CellIndex cellIndex,
roundWKTWriter.write(geometryFactory.toGeometry(cellEnvelope)));
}

return propagationProcessDataFactory.create(connection, cellIndex, skipReceivers);
return tableLoader.create(connection, cellIndex, skipReceivers);
}

/**
Expand Down Expand Up @@ -312,6 +312,13 @@ public CutPlaneVisitorFactory evaluateCell(Connection connection, CellIndex cell
return computeRaysOut;
}

/**
* @return Class used to load tables for input data
*/
public TableLoader getTableLoader() {
return tableLoader;
}

/**
* Initializes the noise map computation process.
* @param connection Active connection
Expand All @@ -321,7 +328,7 @@ public CutPlaneVisitorFactory evaluateCell(Connection connection, CellIndex cell
@Override
public void initialize(Connection connection, ProgressVisitor progression) throws SQLException {
super.initialize(connection, progression);
propagationProcessDataFactory.initialize(connection, this);
tableLoader.initialize(connection, this);
computeRaysOutFactory.initialize(connection, this);
}

Expand Down Expand Up @@ -356,7 +363,7 @@ public void run(Connection connection, ProgressVisitor progressLogger) throws SQ
/**
* A factory interface for initializing input propagation process data for noise map computation.
*/
public interface PropagationProcessDataFactory {
public interface TableLoader {

/**
* Called only once when the settings are set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import org.noise_planet.noisemodelling.emission.directivity.OmnidirectionalDirection;
import org.noise_planet.noisemodelling.emission.directivity.cnossos.RailwayCnossosDirectivitySphere;
import org.noise_planet.noisemodelling.emission.railway.cnossos.RailWayCnossosParameters;
import org.noise_planet.noisemodelling.jdbc.EmissionTableGenerator;
import org.noise_planet.noisemodelling.jdbc.NoiseMapByReceiverMaker;
import org.noise_planet.noisemodelling.jdbc.NoiseMapDatabaseParameters;
import org.noise_planet.noisemodelling.jdbc.utils.CellIndex;
import org.noise_planet.noisemodelling.pathfinder.profilebuilder.Building;
import org.noise_planet.noisemodelling.pathfinder.profilebuilder.ProfileBuilder;
Expand All @@ -40,7 +40,7 @@
/**
* Default implementation for initializing input propagation process data for noise map computation.
*/
public class DefaultTableLoader implements NoiseMapByReceiverMaker.PropagationProcessDataFactory {
public class DefaultTableLoader implements NoiseMapByReceiverMaker.TableLoader {
protected static final Logger LOGGER = LoggerFactory.getLogger(DefaultTableLoader.class);
NoiseMapByReceiverMaker noiseMapByReceiverMaker;
// Soil areas are split by the provided size in order to reduce the propagation time
Expand Down Expand Up @@ -83,21 +83,65 @@ public void insertTrainDirectivity() {
@Override
public void initialize(Connection connection, NoiseMapByReceiverMaker noiseMapByReceiverMaker) throws SQLException {
this.noiseMapByReceiverMaker = noiseMapByReceiverMaker;
if(noiseMapByReceiverMaker.getSceneInputSettings().inputMode == SceneDatabaseInputSettings.INPUT_MODE.INPUT_MODE_LW) {
SceneDatabaseInputSettings inputSettings = noiseMapByReceiverMaker.getSceneInputSettings();
if(inputSettings.inputMode == SceneDatabaseInputSettings.INPUT_MODE.INPUT_MODE_GUESS) {
// Check fields to find appropriate expected data
inputSettings.inputMode = SceneDatabaseInputSettings.INPUT_MODE.INPUT_MODE_ATTENUATION;
if(!inputSettings.sourcesEmissionTableName.isEmpty()) {
List<String> sourceFields = JDBCUtilities.getColumnNames(connection, noiseMapByReceiverMaker.getSourcesEmissionTableName());
if(sourceFields.contains("LV_SPD")) {
inputSettings.inputMode = SceneDatabaseInputSettings.INPUT_MODE.INPUT_MODE_TRAFFIC_FLOW;
} else {
inputSettings.inputMode = SceneDatabaseInputSettings.INPUT_MODE.INPUT_MODE_LW;
}
} else {
List<String> sourceFields = JDBCUtilities.getColumnNames(connection, noiseMapByReceiverMaker.getSourcesTableName());
for (EmissionTableGenerator.STANDARD_PERIOD period : EmissionTableGenerator.STANDARD_PERIOD.values()) {
String periodFieldName = EmissionTableGenerator.STANDARD_PERIOD_VALUE[period.ordinal()];
List<Integer> frequencyValues = readFrequenciesFromLwTable(
noiseMapByReceiverMaker.getLwFrequencyPrepend()+
periodFieldName, sourceFields);
if(!frequencyValues.isEmpty()) {
inputSettings.inputMode = SceneDatabaseInputSettings.INPUT_MODE.INPUT_MODE_LW_DEN;
break;
} else {
if(sourceFields.contains("LV_SPD_" + periodFieldName)) {
inputSettings.inputMode = SceneDatabaseInputSettings.INPUT_MODE.INPUT_MODE_TRAFFIC_FLOW_DEN;
break;
}
}
}
}
}

if(inputSettings.inputMode == SceneDatabaseInputSettings.INPUT_MODE.INPUT_MODE_LW) {
// Load expected frequencies used for computation
// Fetch source fields
List<String> sourceField = JDBCUtilities.getColumnNames(connection, noiseMapByReceiverMaker.getSourcesEmissionTableName());
List<Integer> frequencyValues = readFrequenciesFromLwTable(noiseMapByReceiverMaker, sourceField);
List<Integer> frequencyValues = readFrequenciesFromLwTable(noiseMapByReceiverMaker.getLwFrequencyPrepend(), sourceField);
if(frequencyValues.isEmpty()) {
throw new SQLException("Source emission table "+ noiseMapByReceiverMaker.getSourcesTableName()+" does not contains any frequency bands");
}
frequencyArray = new ArrayList<>(frequencyValues);
exactFrequencyArray = new ArrayList<>();
aWeightingArray = new ArrayList<>();
ProfileBuilder.initializeFrequencyArrayFromReference(frequencyValues, exactFrequencyArray, aWeightingArray);
ProfileBuilder.initializeFrequencyArrayFromReference(frequencyArray, exactFrequencyArray, aWeightingArray);
} else if (inputSettings.inputMode == SceneDatabaseInputSettings.INPUT_MODE.INPUT_MODE_LW_DEN) {
List<String> sourceFields = JDBCUtilities.getColumnNames(connection, noiseMapByReceiverMaker.getSourcesTableName());
Set<Integer> frequencySet = new HashSet<>();
for (EmissionTableGenerator.STANDARD_PERIOD period : EmissionTableGenerator.STANDARD_PERIOD.values()) {
String periodFieldName = EmissionTableGenerator.STANDARD_PERIOD_VALUE[period.ordinal()];
frequencySet.addAll(readFrequenciesFromLwTable(noiseMapByReceiverMaker.getLwFrequencyPrepend()+periodFieldName, sourceFields));
}
frequencyArray = new ArrayList<>(frequencySet);
exactFrequencyArray = new ArrayList<>();
aWeightingArray = new ArrayList<>();
ProfileBuilder.initializeFrequencyArrayFromReference(frequencyArray, exactFrequencyArray, aWeightingArray);
}
}

private List<Integer> readFrequenciesFromLwTable(NoiseMapByReceiverMaker noiseMapByReceiverMaker, List<String> sourceField) throws SQLException {
private static List<Integer> readFrequenciesFromLwTable(String frequencyPrepend, List<String> sourceField) throws SQLException {
List<Integer> frequencyValues = new ArrayList<>();
String frequencyPrepend = noiseMapByReceiverMaker.getLwFrequencyPrepend();
for (String fieldName : sourceField) {
if (fieldName.toUpperCase(Locale.ROOT).startsWith(frequencyPrepend)) {
try {
Expand All @@ -111,9 +155,6 @@ private List<Integer> readFrequenciesFromLwTable(NoiseMapByReceiverMaker noiseMa
}
}
}
if(frequencyValues.isEmpty()) {
throw new SQLException("Source emission table "+ noiseMapByReceiverMaker.getSourcesTableName()+" does not contains any frequency bands");
}
return frequencyValues;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@
*/
package org.noise_planet.noisemodelling.jdbc.input;

import org.h2gis.api.ProgressVisitor;

import java.sql.Connection;

/**
* SceneWithEmission will read table according to this settings
*/
public class SceneDatabaseInputSettings {
public enum INPUT_MODE {
/** Guess input mode at {@link org.noise_planet.noisemodelling.jdbc.NoiseMapByReceiverMaker.TableLoader#initialize(Connection, ProgressVisitor)} step */
INPUT_MODE_GUESS,
/** Read traffic from geometry source table */
INPUT_MODE_TRAFFIC_FLOW_DEN,
/** Read source emission noise level limited to DEN periods from source geometry table */
Expand All @@ -24,7 +30,7 @@ public enum INPUT_MODE {
/** Compute only attenuation */
INPUT_MODE_ATTENUATION }

INPUT_MODE inputMode = INPUT_MODE.INPUT_MODE_ATTENUATION;
INPUT_MODE inputMode = INPUT_MODE.INPUT_MODE_GUESS;
String sourcesEmissionTableName = "";
String sourceEmissionPrimaryKeyField = "IDSOURCE";
/** Cnossos coefficient version (1 = 2015, 2 = 2020) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void processStack(String tableName, ConcurrentLinkedDeque<ReceiverNoiseLevel> st
query.append(", ?"); // THE_GEOM
}
if (!databaseParameters.computeLAEQOnly) {
query.append(", ?".repeat(aWeightingArray.length)); // freq value
query.append(", ?".repeat(aWeightingArray.length)); // freq value LWXX
query.append(", ?, ?);"); // laeq, leq
}else{
query.append(", ?);"); // laeq, leq
Expand Down Expand Up @@ -300,7 +300,7 @@ private String forgeCreateTable(String tableName) {
sb.append(");");
} else {
for (int idfreq = 0; idfreq < aWeightingArray.length; idfreq++) {
sb.append(", HZ");
sb.append(", " + noiseMapByReceiverMaker.getLwFrequencyPrepend());
sb.append(frequencyArray.get(idfreq));
sb.append(" REAL");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private static String createSource(Geometry source, double lvl, Orientation sour
values.append(" DIR_ID");
AttenuationCnossosParameters data = new AttenuationCnossosParameters(false);
for(String period : new String[] {"D", "E", "N"}) {
for (int freq : data.freq_lvl) {
for (int freq : data.getFrequencies()) {
String fieldName = "LW" + period + freq;
sb.append(", ");
sb.append(fieldName);
Expand Down Expand Up @@ -171,7 +171,7 @@ public void testPointDirectivity() throws Exception {

NoiseMapDatabaseParameters parameters = noiseMapByReceiverMaker.getNoiseMapDatabaseParameters();

try(ResultSet rs = st.executeQuery("SELECT HZ63 FROM " + parameters.receiversLevelTable + " WHERE PERIOD='DEN' ORDER BY IDRECEIVER")) {
try(ResultSet rs = st.executeQuery("SELECT LW63 FROM " + parameters.receiversLevelTable + " WHERE PERIOD='DEN' ORDER BY IDRECEIVER")) {
assertTrue(rs.next());
assertEquals(73.3, rs.getDouble(1), 0.1);
assertTrue(rs.next());
Expand Down Expand Up @@ -226,7 +226,7 @@ public void testLineDirectivity() throws Exception {

NoiseMapDatabaseParameters parameters = noiseMapByReceiverMaker.getNoiseMapDatabaseParameters();

try(ResultSet rs = st.executeQuery("SELECT IDRECEIVER, HZ63 FROM " + parameters.receiversLevelTable + " WHERE PERIOD='DEN' ORDER BY IDRECEIVER")) {
try(ResultSet rs = st.executeQuery("SELECT IDRECEIVER, LW63 FROM " + parameters.receiversLevelTable + " WHERE PERIOD='DEN' ORDER BY IDRECEIVER")) {
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
assertEquals(68.3, rs.getDouble(2), 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@
import java.util.*;

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

/**
* Test class evaluation and testing attenuation values.
Expand Down
Loading

0 comments on commit f3be62d

Please sign in to comment.