|
7 | 7 | import org.junit.After; |
8 | 8 | import org.junit.Before; |
9 | 9 | import org.junit.Test; |
| 10 | +import org.opensha.commons.param.ParameterAPI; |
| 11 | +import org.opensha.commons.param.event.ParameterChangeEvent; |
10 | 12 | import org.opensha.commons.param.event.ParameterChangeWarningEvent; |
11 | 13 | import org.opensha.commons.param.event.ParameterChangeWarningListener; |
| 14 | +import org.opensha.sha.earthquake.EqkRupture; |
12 | 15 | import org.opensha.sha.imr.attenRelImpl.Campbell_2003_SHARE_AttenRel; |
13 | 16 | import org.opensha.sha.imr.attenRelImpl.constants.AdjustFactorsSHARE; |
| 17 | +import org.opensha.sha.imr.param.EqkRuptureParams.MagParam; |
14 | 18 | import org.opensha.sha.imr.param.OtherParams.StdDevTypeParam; |
15 | 19 |
|
16 | 20 | /** |
@@ -150,4 +154,43 @@ private void validateStdDev(String stdDevType, double[][] table) { |
150 | 154 | @Override |
151 | 155 | public void parameterChangeWarning(ParameterChangeWarningEvent event) { |
152 | 156 | } |
| 157 | + |
| 158 | + /** |
| 159 | + * This test was added to address |
| 160 | + * https://bugs.launchpad.net/openquake/+bug/942484. |
| 161 | + * |
| 162 | + * The wrong variable was being passed to getStdDev(int, double, String). |
| 163 | + * The 'rake' was being passed instead of 'mag'. |
| 164 | + */ |
| 165 | + @Test |
| 166 | + public void testGetStdDev() { |
| 167 | + |
| 168 | + // Test data was sampled from test_data/Ca03_SIGMcorr.txt |
| 169 | + double mag = 5.0; |
| 170 | + final double [] expectedStdevs = { |
| 171 | + 0.6, 0.6, 0.6, 0.623, |
| 172 | + 0.633, 0.64, 0.649, 0.658, |
| 173 | + 0.662, 0.686, 0.702, 0.7135, |
| 174 | + 0.7135, 0.714, 0.7215, 0.731}; |
| 175 | + |
| 176 | + // First, set the stddev type and mag values: |
| 177 | + ParameterAPI magParam = ca03AttenRel.getParameter(MagParam.NAME); |
| 178 | + ParameterChangeEvent magParamChange = new ParameterChangeEvent( |
| 179 | + magParam, MagParam.NAME, null, mag); |
| 180 | + |
| 181 | + ParameterAPI stddevParam = ca03AttenRel.getParameter(StdDevTypeParam.NAME); |
| 182 | + ParameterChangeEvent stddevParamChange = new ParameterChangeEvent( |
| 183 | + stddevParam, StdDevTypeParam.NAME, null, StdDevTypeParam.STD_DEV_TYPE_TOTAL); |
| 184 | + ca03AttenRel.parameterChange(magParamChange); |
| 185 | + ca03AttenRel.parameterChange(stddevParamChange); |
| 186 | + |
| 187 | + // Sanity check: make sure |
| 188 | + // expecteStddevs and AFrock_CAMPBELL2003 (periods) have the same length. |
| 189 | + assertEquals(expectedStdevs.length, AdjustFactorsSHARE.sig_AFrock_CAMBPELL2003.length); |
| 190 | + |
| 191 | + for (int iper = 0; iper < AdjustFactorsSHARE.sig_AFrock_CAMBPELL2003.length; iper++) { |
| 192 | + ca03AttenRel.setIper(iper); |
| 193 | + assertEquals(expectedStdevs[iper], ca03AttenRel.getStdDev() / AdjustFactorsSHARE.sig_AFrock_CAMBPELL2003[iper], 0.0009); |
| 194 | + } |
| 195 | + } |
153 | 196 | } |
0 commit comments