Skip to content

Commit

Permalink
parse old style lw source table option
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-f committed Feb 4, 2025
1 parent 0921596 commit 6be0780
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
import org.locationtech.jts.operation.buffer.BufferParameters;
import org.locationtech.jts.simplify.TopologyPreservingSimplifier;
import org.noise_planet.noisemodelling.jdbc.input.DefaultTableLoader;
import org.noise_planet.noisemodelling.jdbc.input.SceneWithEmission;
import org.noise_planet.noisemodelling.pathfinder.delaunay.Triangle;
import org.noise_planet.noisemodelling.pathfinder.path.Scene;
import org.noise_planet.noisemodelling.pathfinder.delaunay.LayerDelaunay;
import org.noise_planet.noisemodelling.pathfinder.delaunay.LayerDelaunayError;
import org.noise_planet.noisemodelling.pathfinder.delaunay.LayerTinfour;
Expand All @@ -47,7 +45,7 @@
* @author Nicolas Fortin
* @author SU Qi
*/
public class DelaunayReceiversMaker extends NoiseMapLoader {
public class DelaunayReceiversMaker extends GridMapMaker {
private static final int BATCH_MAX_SIZE = 100;
private Logger logger = LoggerFactory.getLogger(DelaunayReceiversMaker.class);
private double roadWidth = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public enum STANDARD_PERIOD {DAY, EVENING, NIGHT, DAY_EVENING_NIGHT}
public static final double DAY_RATIO = 12. / 24.;
public static final double EVENING_RATIO = 4. / 24. * dBToW(5.0);
public static final double NIGHT_RATIO = 8. / 24. * dBToW(10.0);
public static final double[] RATIOS = new double[] {DAY_RATIO, EVENING_RATIO, NIGHT_RATIO};

/**
* Cache table fields in upper case in Map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,26 @@
package org.noise_planet.noisemodelling.jdbc;

import org.h2gis.api.ProgressVisitor;
import org.h2gis.utilities.JDBCUtilities;
import org.h2gis.utilities.SpatialResultSet;
import org.h2gis.utilities.TableLocation;
import org.h2gis.utilities.dbtypes.DBTypes;
import org.h2gis.utilities.dbtypes.DBUtils;
import org.locationtech.jts.geom.*;
import org.locationtech.jts.geom.prep.PreparedPolygon;
import org.locationtech.jts.io.WKTWriter;
import org.noise_planet.noisemodelling.emission.directivity.DirectivityRecord;
import org.noise_planet.noisemodelling.emission.directivity.DiscreteDirectivitySphere;
import org.noise_planet.noisemodelling.jdbc.input.DefaultTableLoader;
import org.noise_planet.noisemodelling.jdbc.input.SceneWithEmission;
import org.noise_planet.noisemodelling.jdbc.utils.CellIndex;
import org.noise_planet.noisemodelling.pathfinder.profilebuilder.Building;
import org.noise_planet.noisemodelling.pathfinder.path.Scene;
import org.noise_planet.noisemodelling.pathfinder.profilebuilder.ProfileBuilder;
import org.noise_planet.noisemodelling.pathfinder.profilebuilder.Wall;
import org.noise_planet.noisemodelling.pathfinder.profilebuilder.WallAbsorption;
import org.noise_planet.noisemodelling.propagation.cnossos.AttenuationCnossosParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.sql.*;
import java.util.*;

import static org.h2gis.utilities.GeometryTableUtilities.getGeometryColumnNames;
import static org.h2gis.utilities.GeometryTableUtilities.getSRID;
/**
* Common attributes for propagation of sound sources.
* Common attributes and functions across DelaunayGrid and NoiseMap receiver computation
* @author Nicolas Fortin
*/
public abstract class NoiseMapLoader {
public abstract class GridMapMaker {
// When computing cell size, try to keep propagation distance away from the cell
// inferior to this ratio (in comparison with cell width)
Logger logger = LoggerFactory.getLogger(NoiseMapLoader.class);
private static final int DEFAULT_FETCH_SIZE = 300;
protected static final double MINIMAL_BUFFER_RATIO = 0.3;
protected DefaultTableLoader.BuildingTableParameters buildingTableParameters = new DefaultTableLoader.BuildingTableParameters();
protected final String sourcesTableName;
Expand Down Expand Up @@ -79,7 +62,7 @@ public abstract class NoiseMapLoader {
protected int gridDim = 0;
protected Envelope mainEnvelope = new Envelope();

public NoiseMapLoader(String buildingsTableName, String sourcesTableName) {
public GridMapMaker(String buildingsTableName, String sourcesTableName) {
this.buildingTableParameters.buildingsTableName = buildingsTableName;
this.sourcesTableName = sourcesTableName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.noise_planet.noisemodelling.jdbc.input.SceneWithEmission;
import org.noise_planet.noisemodelling.jdbc.output.DefaultCutPlaneProcessing;
import org.noise_planet.noisemodelling.jdbc.utils.CellIndex;
import org.noise_planet.noisemodelling.pathfinder.CutPlaneVisitor;
import org.noise_planet.noisemodelling.pathfinder.CutPlaneVisitorFactory;
import org.noise_planet.noisemodelling.pathfinder.PathFinder;
import org.noise_planet.noisemodelling.pathfinder.utils.profiler.ProfilerThread;
Expand All @@ -41,7 +40,7 @@
* Compute noise propagation at specified receiver points.
* @author Nicolas Fortin
*/
public class NoiseMapByReceiverMaker extends NoiseMapLoader {
public class NoiseMapByReceiverMaker extends GridMapMaker {
private final String receiverTableName;
private PropagationProcessDataFactory propagationProcessDataFactory = new DefaultTableLoader();
/** Tell table writer thread to empty current stacks then stop waiting for new data */
Expand Down Expand Up @@ -325,6 +324,34 @@ public void initialize(Connection connection, ProgressVisitor progression) throw
computeRaysOutFactory.initialize(connection, this);
}

/**
* Run NoiseModelling with provided parameters, return when computation is done
*/
public void run(Connection connection, ProgressVisitor progressLogger) throws SQLException {
initialize(connection, progressLogger);

// Set of already processed receivers
Set<Long> receivers = new HashSet<>();

// Fetch cell identifiers with receivers
Map<CellIndex, Integer> cells = searchPopulatedCells(connection);
ProgressVisitor progressVisitor = progressLogger.subProcess(cells.size());

try {
computeRaysOutFactory.start(progressLogger);
for (CellIndex cellIndex : new TreeSet<>(cells.keySet())) {
// Run ray propagation
try {
evaluateCell(connection, cellIndex, progressVisitor, receivers);
} catch (IOException ex) {
throw new SQLException(ex);
}
}
} finally {
computeRaysOutFactory.stop();
}
}

/**
* A factory interface for initializing input propagation process data for noise map computation.
*/
Expand Down Expand Up @@ -362,6 +389,19 @@ public interface IComputeRaysOutFactory {
*/
void initialize(Connection connection, NoiseMapByReceiverMaker noiseMapByReceiverMaker) throws SQLException;

/**
* Called before the first sub cell is being computed
* @param progressLogger Main progression information, this method will not update the progression
* @throws SQLException
*/
void start(ProgressVisitor progressLogger) throws SQLException;

/**
* Called when all sub-cells have been processed
* @throws SQLException
*/
void stop() throws SQLException;

/**
* Creates an object that computes paths out for noise map computation.
* @param cellData the scene data for the current computation cell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
package org.noise_planet.noisemodelling.jdbc;


import org.noise_planet.noisemodelling.pathfinder.PathFinder;

import java.io.File;

/**
Expand All @@ -24,6 +22,15 @@ public class NoiseMapDatabaseParameters {
public NoiseMapDatabaseParameters() {
}

/**
* Path to write the computation time and other statistics in a csv file
*/
public File CSVProfilerOutputPath = null;
/**
* Create a new csv line after this time in seconds
*/
public int CSVProfilerWriteInterval = 60;

public boolean exportProfileInRays = false;
public boolean keepAbsorption = false; // in rays, keep store detailed absorption data
public int maximumRaysOutputCount = 0; // if export rays, do not keep more than this number of rays (0 infinite)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.sql.SQLException;
import java.util.*;

import static org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions.sumArray;

/**
* Add emission information for each source in the computation scene
* This is input data, not thread safe, never update anything here during propagation
Expand Down Expand Up @@ -51,6 +53,7 @@ int updatePowerSpectrumSet(double[] wj) {
public void processTrafficFlowDEN(Long pk, SpatialResultSet rs) throws SQLException {
// Source table PK, GEOM, LV_D, LV_E, LV_N ...
double[][] lw = EmissionTableGenerator.computeLw(rs, sceneDatabaseInputSettings.coefficientVersion, sourceFieldsCache);
// Will generate D E N and DEN emission
for (EmissionTableGenerator.STANDARD_PERIOD period : EmissionTableGenerator.STANDARD_PERIOD.values()) {
addSourceEmission(pk, EmissionTableGenerator.STANDARD_PERIOD_VALUE[period.ordinal()], lw[period.ordinal()]);
}
Expand Down Expand Up @@ -97,9 +100,31 @@ public void processEmission(Long pk, ResultSet rs) throws SQLException {
@Override
public void addSource(Long pk, Geometry geom, SpatialResultSet rs) throws SQLException {
super.addSource(pk, geom, rs);
if (Objects.requireNonNull(sceneDatabaseInputSettings.inputMode) == SceneDatabaseInputSettings.INPUT_MODE.INPUT_MODE_TRAFFIC_FLOW_DEN) {
processTrafficFlowDEN(pk, rs);
switch (Objects.requireNonNull(sceneDatabaseInputSettings.inputMode)) {
case INPUT_MODE_TRAFFIC_FLOW_DEN:
processTrafficFlowDEN(pk, rs);
break;
case INPUT_MODE_LW_DEN:
processEmissionDEN(pk, rs);
break;
}
}

private void processEmissionDEN(Long pk, SpatialResultSet rs) throws SQLException {
List<Integer> frequencyArray = profileBuilder.frequencyArray;
double[] lden = new double[0];
for (EmissionTableGenerator.STANDARD_PERIOD period :
Arrays.copyOfRange(EmissionTableGenerator.STANDARD_PERIOD.values(),0,3)) {
double[] lw = new double[profileBuilder.frequencyArray.size()];
String periodFieldName = EmissionTableGenerator.STANDARD_PERIOD_VALUE[period.ordinal()];
for (int i = 0, frequencyArraySize = frequencyArray.size(); i < frequencyArraySize; i++) {
Integer frequency = frequencyArray.get(i);
lw[i] = AcousticIndicatorsFunctions.dBToW(rs.getDouble(sceneDatabaseInputSettings.lwFrequencyPrepend + periodFieldName + frequency));
}
addSourceEmission(pk, periodFieldName, lw);
lden = sumArray(lden, AcousticIndicatorsFunctions.multiplicationArray(lw, EmissionTableGenerator.RATIOS[period.ordinal()]));
}
addSourceEmission(pk, EmissionTableGenerator.STANDARD_PERIOD_VALUE[3], lden);
}

public void addSourceEmission(Long pk, ResultSet rs) throws SQLException {
Expand Down Expand Up @@ -148,6 +173,8 @@ public static class SceneDatabaseInputSettings {
public enum INPUT_MODE {
/** Read traffic from geometry source table */
INPUT_MODE_TRAFFIC_FLOW_DEN,
/** Read source emission noise level limited to DEN periods from source geometry table */
INPUT_MODE_LW_DEN,
/** Read traffic from emission source table for each period */
INPUT_MODE_TRAFFIC_FLOW,
/** Read source emission noise level from source emission table for each period */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package org.noise_planet.noisemodelling.jdbc.output;

import org.h2gis.api.ProgressVisitor;
import org.noise_planet.noisemodelling.jdbc.NoiseMapByReceiverMaker;
import org.noise_planet.noisemodelling.jdbc.NoiseMapDatabaseParameters;
import org.noise_planet.noisemodelling.jdbc.input.SceneWithEmission;
import org.noise_planet.noisemodelling.pathfinder.CutPlaneVisitor;
import org.noise_planet.noisemodelling.pathfinder.CutPlaneVisitorFactory;
import org.noise_planet.noisemodelling.pathfinder.utils.profiler.JVMMemoryMetric;
import org.noise_planet.noisemodelling.pathfinder.utils.profiler.ProfilerThread;
import org.noise_planet.noisemodelling.pathfinder.utils.profiler.ProgressMetric;
import org.noise_planet.noisemodelling.pathfinder.utils.profiler.ReceiverStatsMetric;

import java.sql.Connection;
import java.sql.SQLException;
Expand All @@ -15,6 +19,7 @@ public class DefaultCutPlaneProcessing implements NoiseMapByReceiverMaker.ICompu
final NoiseMapDatabaseParameters noiseMapDatabaseParameters;
NoiseMapWriter noiseMapWriter;
Thread tableWriterThread;
ProfilerThread profilerThread;
Connection connection;
// Process status
AtomicBoolean exitWhenDone;
Expand Down Expand Up @@ -52,11 +57,22 @@ public void initialize(Connection connection, NoiseMapByReceiverMaker noiseMapBy
* Start creating and filling database tables.
* This method is blocked until the computation is completed or if there is an issue
*/
public void start() {
@Override
public void start(ProgressVisitor progressLogger) {
noiseMapWriter = new NoiseMapWriter(connection, noiseMapByReceiverMaker, resultsCache, exitWhenDone, aborted);
exitWhenDone.set(false);
tableWriterThread = new Thread(noiseMapWriter);
tableWriterThread.start();
if(noiseMapDatabaseParameters.CSVProfilerOutputPath != null) {
profilerThread = new ProfilerThread(noiseMapDatabaseParameters.CSVProfilerOutputPath);
profilerThread.addMetric(resultsCache);
profilerThread.addMetric(new ProgressMetric(progressLogger));
profilerThread.addMetric(new JVMMemoryMetric());
profilerThread.addMetric(new ReceiverStatsMetric());
profilerThread.setWriteInterval(noiseMapDatabaseParameters.CSVProfilerWriteInterval);
profilerThread.setFlushInterval(noiseMapDatabaseParameters.CSVProfilerWriteInterval);
new Thread(profilerThread).start();
}
while (!noiseMapWriter.started && !aborted.get()) {
try {
Thread.sleep(150);
Expand All @@ -71,6 +87,7 @@ public void start() {
* Write the last results and stop the sql writing thread
* This method is blocked until the data is written or if there is an issue
*/
@Override
public void stop() {
exitWhenDone.set(true);
while (tableWriterThread != null && tableWriterThread.isAlive()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public NoiseMapWriter(Connection connection, NoiseMapByReceiverMaker noiseMapByR
aWeightingArray.stream().mapToDouble(value -> value).toArray();
frequencyArray = ((DefaultTableLoader)noiseMapByReceiverMaker.getPropagationProcessDataFactory()).frequencyArray;
}
this.exitWhenDone = exitWhenDone;
this.aborted = aborted;
}

/**
Expand Down
Loading

0 comments on commit 6be0780

Please sign in to comment.