Move units to GlobalMediumManager

Signed-off-by: Merlijn van Deen <m.vandeen@fugro.com>
This commit is contained in:
Merlijn van Deen 2024-10-08 16:55:35 +02:00
parent bb7314f453
commit e7cd4fa317
10 changed files with 116 additions and 22 deletions

View File

@ -200,6 +200,50 @@ public class GlobalMedium {
return zString; return zString;
} }
/**
* Get a string description of the dB reference for a power spectral density.
* @param currentMedium - the current medium.
* @return string of dB reference
*/
public static String getdBPSDString(SoundMedium currentMedium) {
String zString;
switch (currentMedium) {
case Air:
zString = "dB re 400\u00B5Pa\u00B2/Hz";
break;
case Water:
zString = "dB re 1\u00B5Pa\u00B2/Hz";
break;
default:
zString = "dB re 1\u00B5Pa\u00B2/Hz";
break;
}
return zString;
}
/**
* Get a string description of the dB reference for a sound exposure level.
* @param currentMedium - the current medium.
* @return string of dB reference
*/
public static String getdBSELString(SoundMedium currentMedium) {
String zString;
switch (currentMedium) {
case Air:
zString = "dB re 400\u00B5Pa\u00B2s";
break;
case Water:
zString = "dB re 1\u00B5Pa\u00B2s";
break;
default:
zString = "dB re 1\u00B5Pa\u00B2s";
break;
}
return zString;
}
/** /**
* Get the z coefficient value for displays. Height are always stored so * Get the z coefficient value for displays. Height are always stored so
* that +z points up (i.e. -g). In display height is input as depth as so must * that +z points up (i.e. -g). In display height is input as depth as so must

View File

@ -136,6 +136,21 @@ public class GlobalMediumManager implements PamSettings {
return GlobalMedium.getdBRefString(globalMediumParams.currentMedium); return GlobalMedium.getdBRefString(globalMediumParams.currentMedium);
} }
/**
* Get the string for the default dB reference unit for power spectral density e.g. dB re 1uPa^2/Hz.
* @return the string for dB values.
*/
public String getdBPSDString() {
return GlobalMedium.getdBPSDString(globalMediumParams.currentMedium);
}
/**
* Get the string for the default dB reference unit for power spectral density e.g. dB re 1uPa^2/Hz.
* @return the string for dB values.
*/
public String getdBSELString() {
return GlobalMedium.getdBSELString(globalMediumParams.currentMedium);
}
/** /**
* Get the height coefficient value for displays. Heights are always stored so * Get the height coefficient value for displays. Heights are always stored so

View File

@ -0,0 +1,4 @@
package PamController.test;
public class PamControllerTestHelper {
}

View File

@ -809,7 +809,7 @@ InternalFrameListener, DisplayPanelContainer, SpectrogramParametersUser, PamSett
createColours(); createColours();
timeAxis = new PamAxis(10, 0, imageWidth, 0, 0, timeAxis = new PamAxis(10, 0, imageWidth, 0, 0,
spectrogramParameters.displayLength, true, "seconds", "%3.1f"); spectrogramParameters.displayLength, true, "Time (s)", "%3.1f");
spectrogramAxis.setNorthAxis(timeAxis); spectrogramAxis.setNorthAxis(timeAxis);
if (rangeSpinner != null) { if (rangeSpinner != null) {
@ -817,13 +817,15 @@ InternalFrameListener, DisplayPanelContainer, SpectrogramParametersUser, PamSett
} }
double fScale = 1; double fScale = 1;
String westLabel = "Frequency (Hz)";
if (spectrogramParameters.frequencyLimits[1] > 2000) { if (spectrogramParameters.frequencyLimits[1] > 2000) {
fScale = 1000; fScale = 1000;
westLabel = "Frequency (kHz)";
} }
frequencyAxis = new PamAxis(0, 200, 0, 10, frequencyAxis = new PamAxis(0, 200, 0, 10,
spectrogramParameters.frequencyLimits[0] / fScale, spectrogramParameters.frequencyLimits[0] / fScale,
spectrogramParameters.frequencyLimits[1] / fScale, true, "", spectrogramParameters.frequencyLimits[1] / fScale, true, westLabel,
null); null);
frequencyAxis.setFractionalScale(true); frequencyAxis.setFractionalScale(true);
frequencyAxis.setCrampLabels(true); frequencyAxis.setCrampLabels(true);
@ -1696,9 +1698,11 @@ InternalFrameListener, DisplayPanelContainer, SpectrogramParametersUser, PamSett
// setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 10)); // setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 10));
setLayout(new BorderLayout()); setLayout(new BorderLayout());
add(new AmplitudeBar(), BorderLayout.CENTER); add(new AmplitudeBar(), BorderLayout.CENTER);
String label = String.format("PSD (%s)", PamController.getInstance().getGlobalMediumManager().getdBPSDString());
amplitudeAxis = new PamAxis(0, 200, 0, 10, amplitudeAxis = new PamAxis(0, 200, 0, 10,
spectrogramParameters.amplitudeLimits[0], spectrogramParameters.amplitudeLimits[0],
spectrogramParameters.amplitudeLimits[1], false, "", "%3.0f"); spectrogramParameters.amplitudeLimits[1], false, label, "%3.0f");
setEastAxis(amplitudeAxis); setEastAxis(amplitudeAxis);
} }

View File

@ -136,7 +136,8 @@ public class FFTPluginPanelProvider implements DisplayPanelProvider {
isViewer = PamController.getInstance().getRunMode() == PamController.RUN_PAMVIEW; isViewer = PamController.getInstance().getRunMode() == PamController.RUN_PAMVIEW;
setupPanel(); setupPanel();
westAxis = new PamAxis(0, 0, 1, 1, getScaleMin(), getScaleMax(), true, "PSD (dB re 1µPa²/Hz)", "%.0f"); String label = String.format("PSD (%s)", PamController.getInstance().getGlobalMediumManager().getdBPSDString());
westAxis = new PamAxis(0, 0, 1, 1, getScaleMin(), getScaleMax(), true, label, "%.0f");
westAxis.setInterval(20); westAxis.setInterval(20);
//southAxis = new PamAxis(0, 0, 10, 10, 0, pamFFTProcess.getSampleRate()/2/1000, true, "kHz", "%.0f"); //southAxis = new PamAxis(0, 0, 10, 10, 0, pamFFTProcess.getSampleRate()/2/1000, true, "kHz", "%.0f");
southAxis = new PamAxis(0, 0, 1, 1, 0, fftDataBlock.getSampleRate()/2/1000, false, "kHz", "%.0f"); southAxis = new PamAxis(0, 0, 1, 1, 0, fftDataBlock.getSampleRate()/2/1000, false, "kHz", "%.0f");

View File

@ -10,11 +10,8 @@ import javax.swing.JButton;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
import javax.swing.JPanel; import javax.swing.JPanel;
import PamController.PamControlledUnit; import PamController.*;
import PamController.PamControlledUnitSettings; import PamController.soundMedium.GlobalMediumManager;
import PamController.PamControllerInterface;
import PamController.PamSettingManager;
import PamController.PamSettings;
import PamView.PamTabPanel; import PamView.PamTabPanel;
import noiseOneBand.offline.OneBandSummaryTask; import noiseOneBand.offline.OneBandSummaryTask;
import offlineProcessing.DataCopyTask; import offlineProcessing.DataCopyTask;
@ -22,18 +19,16 @@ import offlineProcessing.OLProcessDialog;
import offlineProcessing.OfflineTaskGroup; import offlineProcessing.OfflineTaskGroup;
public class OneBandControl extends PamControlledUnit implements PamSettings { public class OneBandControl extends PamControlledUnit implements PamSettings {
/**
* The number of measures taken by {@link OneBandControl}.
* See {@link OneBandControl#getMeasurementName(int)} for description and units of each measure.
*/
public static final int NMEASURES = 4; public static final int NMEASURES = 4;
public static final String[] measureNames = {
"RMS (dB re 1µPa)", private final OneBandProcess oneBandProcess;
"0-Peak (dB re 1µPa)", private final OneBandPulseProcess pulseProcess;
"Peak-Peak (dB re 1µPa)",
"Integrated SEL (dB re 1µPa²s)"
};
private OneBandProcess oneBandProcess;
private OneBandPulseProcess pulseProcess;
protected OneBandParameters oneBandParameters = new OneBandParameters(); protected OneBandParameters oneBandParameters = new OneBandParameters();
private OneBandTabPanel dBHtTabPanel; private final OneBandTabPanel dBHtTabPanel;
private OfflineTaskGroup offlineTaskGroup; private OfflineTaskGroup offlineTaskGroup;
private OLProcessDialog olProcessDialog; private OLProcessDialog olProcessDialog;
@ -71,6 +66,32 @@ public class OneBandControl extends PamControlledUnit implements PamSettings {
return dBHtTabPanel; return dBHtTabPanel;
} }
/**
* Gets the measurement name for a given index (0 <= index < {@link OneBandControl#NMEASURES}).
* This requires access to the Global Medium Manager to report on the correct units.
*
* @param index The index of the measure.
* @return The text representation of the relevant measure, including units.
*/
public static String getMeasurementName(int index) {
GlobalMediumManager gmm = PamController.getInstance().getGlobalMediumManager();
String dbRef = gmm.getdBRefString();
String selDbRef = gmm.getdBSELString();
switch (index) {
case 0:
return String.format("RMS (%s)", dbRef);
case 1:
return String.format("0-Peak (%s)", dbRef);
case 2:
return String.format("Peak-Peak (%s)", dbRef);
case 3:
return String.format("Integrated SEL (%s)", selDbRef);
default:
throw new IllegalStateException("Unexpected value: " + index);
}
}
/* (non-Javadoc) /* (non-Javadoc)
* @see PamController.PamControlledUnit#createDetectionMenu(java.awt.Frame) * @see PamController.PamControlledUnit#createDetectionMenu(java.awt.Frame)
*/ */

View File

@ -91,7 +91,7 @@ public class OneBandDisplayDialog extends PamDialog {
for (int i = 0; i < OneBandControl.NMEASURES; i++) { for (int i = 0; i < OneBandControl.NMEASURES; i++) {
c.gridx = 0; c.gridx = 0;
c.gridy++; c.gridy++;
addComponent(symPanel, showMeasure[i] = new JCheckBox("Show " + OneBandControl.measureNames[i]), c); addComponent(symPanel, showMeasure[i] = new JCheckBox("Show " + OneBandControl.getMeasurementName(i)), c);
} }
tabPane.add(symPanel, "Symbols"); tabPane.add(symPanel, "Symbols");

View File

@ -508,7 +508,7 @@ public class OneBandDisplayPanel {
OneBandDisplayParams params = getDisplayParams(panelType); OneBandDisplayParams params = getDisplayParams(panelType);
for (int i = OneBandControl.NMEASURES-1; i >= 0; i--) { for (int i = OneBandControl.NMEASURES-1; i >= 0; i--) {
if ((params.showWhat & 1<<i) != 0) { if ((params.showWhat & 1<<i) != 0) {
keyPanel.add(new SymbolKeyItem(measureSymbols[i], OneBandControl.measureNames[i])); keyPanel.add(new SymbolKeyItem(measureSymbols[i], OneBandControl.getMeasurementName(i)));
} }
} }
if (displayParams.colourByChannel) { if (displayParams.colourByChannel) {

View File

@ -8,6 +8,7 @@ import javax.swing.JPanel;
import javax.swing.JRadioButton; import javax.swing.JRadioButton;
import javax.swing.border.TitledBorder; import javax.swing.border.TitledBorder;
import PamController.soundMedium.GlobalMediumManager;
import PamView.dialog.PamDialog; import PamView.dialog.PamDialog;
import noiseOneBand.OneBandAlarmParameters; import noiseOneBand.OneBandAlarmParameters;
import noiseOneBand.OneBandControl; import noiseOneBand.OneBandControl;
@ -28,7 +29,7 @@ public class OneBandAlarmParamsDialog extends PamDialog {
mainPanel.setBorder(new TitledBorder("Select measure")); mainPanel.setBorder(new TitledBorder("Select measure"));
ButtonGroup bg = new ButtonGroup(); ButtonGroup bg = new ButtonGroup();
for (int i = 0; i < OneBandControl.NMEASURES; i++) { for (int i = 0; i < OneBandControl.NMEASURES; i++) {
measures[i] = new JRadioButton(OneBandControl.measureNames[i]); measures[i] = new JRadioButton(OneBandControl.getMeasurementName(i));
bg.add(measures[i]); bg.add(measures[i]);
mainPanel.add(measures[i]); mainPanel.add(measures[i]);
} }

View File

@ -0,0 +1,4 @@
import static org.junit.jupiter.api.Assertions.*;
class OneBandControlTest {
}