Skip to content

Commit 49bac4e

Browse files
committed
Added support for setting the moment error range in the spectra ratio inversion by using the --ratio-inversion.moment-error-range flag
1 parent 6538b88 commit 49bac4e

File tree

2 files changed

+38
-20
lines changed

2 files changed

+38
-20
lines changed

calibration-service/calibration-service-impl/src/main/java/gov/llnl/gnem/apps/coda/calibration/service/impl/SpectraRatioServiceImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.slf4j.LoggerFactory;
4040
import org.springframework.beans.factory.annotation.Autowired;
4141
import org.springframework.beans.factory.annotation.Qualifier;
42+
import org.springframework.beans.factory.annotation.Value;
4243
import org.springframework.stereotype.Service;
4344
import org.springframework.transaction.annotation.Transactional;
4445

@@ -98,6 +99,9 @@
9899
@Transactional
99100
public class SpectraRatioServiceImpl implements SpectraRatioPairDetailsService {
100101

102+
@Value(value = "${ratio-inversion.moment-error-range:0.1}")
103+
private double momentErrorRange;
104+
101105
private Logger log = LoggerFactory.getLogger(SpectraRatioServiceImpl.class);
102106

103107
private SpectraRatioPairDetailsRepository spectraRatioPairDetailsRepository;
@@ -320,15 +324,15 @@ public Future<Result<SpectraRatiosReport>> makeSpectraRatioMeasurements(boolean
320324
private Map<EventPair, SpectraRatioPairInversionResult> invertEventRatioPairs(Map<EventPair, Map<Station, Map<FrequencyBand, SpectraRatioPairDetails>>> ratioData) {
321325
final MdacParametersFI mdacFiEntry = new MdacParametersFI(mdacFiService.findFirst());
322326
final MdacParametersPS psRows = mdacPsService.findMatchingPhase(PICK_TYPES.LG.getPhase());
323-
SpectraRatioInversionCalculator inversion = new SpectraRatioInversionCalculator(mdacService, mdacFiEntry, psRows, fitMwService, refMwService);
327+
SpectraRatioInversionCalculator inversion = new SpectraRatioInversionCalculator(mdacService, mdacFiEntry, psRows, fitMwService, refMwService, momentErrorRange);
324328
Map<EventPair, SpectraRatioPairInversionResult> inversionResults = inversion.cmaesRegressionPerPair(ratioData);
325329
return inversionResults;
326330
}
327331

328332
private Map<EventPair, SpectraRatioPairInversionResultJoint> invertEventRatios(Map<EventPair, Map<Station, Map<FrequencyBand, SpectraRatioPairDetails>>> ratioData) {
329333
final MdacParametersFI mdacFiEntry = new MdacParametersFI(mdacFiService.findFirst());
330334
final MdacParametersPS psRows = mdacPsService.findMatchingPhase(PICK_TYPES.LG.getPhase());
331-
SpectraRatioInversionCalculator inversion = new SpectraRatioInversionCalculator(mdacService, mdacFiEntry, psRows, fitMwService, refMwService);
335+
SpectraRatioInversionCalculator inversion = new SpectraRatioInversionCalculator(mdacService, mdacFiEntry, psRows, fitMwService, refMwService, momentErrorRange);
332336
Map<EventPair, SpectraRatioPairInversionResultJoint> inversionResults = inversion.cmaesRegressionJoint(ratioData);
333337
return inversionResults;
334338
}

calibration-service/calibration-service-impl/src/main/java/gov/llnl/gnem/apps/coda/calibration/service/impl/processing/SpectraRatioInversionCalculator.java

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class SpectraRatioInversionCalculator {
6565

6666
private static final int PARAM_COUNT = 2;
6767

68-
private final double DEFAULT_MOMENT_ERROR = 1.0;
68+
private double momentErrorRange;
6969
private final double DEFAULT_LOW_MOMENT = 1.0;
7070
private final double DEFAULT_HIGH_MOMENT = 25.0;
7171
private final double testMomentIncrement = 0.25;
@@ -79,11 +79,12 @@ public class SpectraRatioInversionCalculator {
7979
private MdacCalculator mdacCalculator;
8080

8181
public SpectraRatioInversionCalculator(MdacCalculatorService mdacService, MdacParametersFI mdacFiEntry, MdacParametersPS psRows, MeasuredMwsService fitMwService,
82-
ReferenceMwParametersService refMwService) {
82+
ReferenceMwParametersService refMwService, double momentErrorRange) {
8383
this.fitMwService = fitMwService;
8484
this.refMwService = refMwService;
8585
//We just want the K constant for the given MDAC model so no need for a real moment here
8686
this.mdacCalculator = mdacService.getMdacCalculator(psRows, mdacFiEntry, DEFAULT_HIGH_MOMENT);
87+
this.momentErrorRange = momentErrorRange;
8788
}
8889

8990
public Map<EventPair, List<MomentCornerEstimate>> gridSearchPerPair(Map<EventPair, Map<Station, Map<FrequencyBand, SpectraRatioPairDetails>>> ratioData) {
@@ -115,6 +116,8 @@ public Map<EventPair, List<MomentCornerEstimate>> gridSearchPerPair(Map<EventPai
115116

116117
if (lowTestMomentEventA == null) {
117118
lowTestMomentEventA = DEFAULT_LOW_MOMENT;
119+
}
120+
if (highTestMomentEventA == null) {
118121
highTestMomentEventA = DEFAULT_HIGH_MOMENT;
119122
}
120123

@@ -131,6 +134,8 @@ public Map<EventPair, List<MomentCornerEstimate>> gridSearchPerPair(Map<EventPai
131134

132135
if (lowTestMomentEventB == null) {
133136
lowTestMomentEventB = DEFAULT_LOW_MOMENT;
137+
}
138+
if (highTestMomentEventB == null) {
134139
highTestMomentEventB = DEFAULT_HIGH_MOMENT;
135140
}
136141

@@ -168,6 +173,7 @@ public Map<EventPair, List<MomentCornerEstimate>> gridSearchPerPair(Map<EventPai
168173
});
169174

170175
return estimatedMomentCorners;
176+
171177
}
172178

173179
public Map<EventPair, SpectraRatioPairInversionResult> cmaesRegressionPerPair(Map<EventPair, Map<Station, Map<FrequencyBand, SpectraRatioPairDetails>>> ratioData) {
@@ -187,31 +193,35 @@ public Map<EventPair, SpectraRatioPairInversionResult> cmaesRegressionPerPair(Ma
187193
ReferenceMwParameters refMoment = refMwService.findByEventId(eventPair.getY().getEventId());
188194

189195
if (fitMoment != null) {
190-
lowTestMomentEventA = MdacCalculator.mwToLogM0(fitMoment.getMw()) - DEFAULT_MOMENT_ERROR;
191-
highTestMomentEventA = MdacCalculator.mwToLogM0(fitMoment.getMw()) + DEFAULT_MOMENT_ERROR;
196+
lowTestMomentEventA = MdacCalculator.mwToLogM0(fitMoment.getMw()) - momentErrorRange;
197+
highTestMomentEventA = MdacCalculator.mwToLogM0(fitMoment.getMw()) + momentErrorRange;
192198
} else if (refMoment != null) {
193-
lowTestMomentEventA = MdacCalculator.mwToLogM0(refMoment.getRefMw()) - DEFAULT_MOMENT_ERROR;
194-
highTestMomentEventA = MdacCalculator.mwToLogM0(refMoment.getRefMw()) + DEFAULT_MOMENT_ERROR;
199+
lowTestMomentEventA = MdacCalculator.mwToLogM0(refMoment.getRefMw()) - momentErrorRange;
200+
highTestMomentEventA = MdacCalculator.mwToLogM0(refMoment.getRefMw()) + momentErrorRange;
195201
}
196202

197203
if (lowTestMomentEventA == null) {
198204
lowTestMomentEventA = DEFAULT_LOW_MOMENT;
205+
}
206+
if (highTestMomentEventA == null) {
199207
highTestMomentEventA = DEFAULT_HIGH_MOMENT;
200208
}
201209

202210
fitMoment = fitMwService.findByEventId(eventPair.getX().getEventId());
203211
refMoment = refMwService.findByEventId(eventPair.getX().getEventId());
204212

205213
if (fitMoment != null) {
206-
lowTestMomentEventB = MdacCalculator.mwToLogM0(fitMoment.getMw()) - DEFAULT_MOMENT_ERROR;
207-
highTestMomentEventB = MdacCalculator.mwToLogM0(fitMoment.getMw()) + DEFAULT_MOMENT_ERROR;
214+
lowTestMomentEventB = MdacCalculator.mwToLogM0(fitMoment.getMw()) - momentErrorRange;
215+
highTestMomentEventB = MdacCalculator.mwToLogM0(fitMoment.getMw()) + momentErrorRange;
208216
} else if (refMoment != null) {
209-
lowTestMomentEventB = MdacCalculator.mwToLogM0(refMoment.getRefMw()) - DEFAULT_MOMENT_ERROR;
210-
highTestMomentEventB = MdacCalculator.mwToLogM0(refMoment.getRefMw()) + DEFAULT_MOMENT_ERROR;
217+
lowTestMomentEventB = MdacCalculator.mwToLogM0(refMoment.getRefMw()) - momentErrorRange;
218+
highTestMomentEventB = MdacCalculator.mwToLogM0(refMoment.getRefMw()) + momentErrorRange;
211219
}
212220

213221
if (lowTestMomentEventB == null) {
214222
lowTestMomentEventB = DEFAULT_LOW_MOMENT;
223+
}
224+
if (highTestMomentEventB == null) {
215225
highTestMomentEventB = DEFAULT_HIGH_MOMENT;
216226
}
217227

@@ -352,31 +362,35 @@ public Map<EventPair, SpectraRatioPairInversionResultJoint> cmaesRegressionJoint
352362
ReferenceMwParameters refMoment = refMwService.findByEventId(eventPair.getY().getEventId());
353363

354364
if (fitMoment != null) {
355-
lowTestMomentEventA = MdacCalculator.mwToLogM0(fitMoment.getMw()) - DEFAULT_MOMENT_ERROR;
356-
highTestMomentEventA = MdacCalculator.mwToLogM0(fitMoment.getMw()) + DEFAULT_MOMENT_ERROR;
365+
lowTestMomentEventA = MdacCalculator.mwToLogM0(fitMoment.getMw()) - momentErrorRange;
366+
highTestMomentEventA = MdacCalculator.mwToLogM0(fitMoment.getMw()) + momentErrorRange;
357367
} else if (refMoment != null) {
358-
lowTestMomentEventA = MdacCalculator.mwToLogM0(refMoment.getRefMw()) - DEFAULT_MOMENT_ERROR;
359-
highTestMomentEventA = MdacCalculator.mwToLogM0(refMoment.getRefMw()) + DEFAULT_MOMENT_ERROR;
368+
lowTestMomentEventA = MdacCalculator.mwToLogM0(refMoment.getRefMw()) - momentErrorRange;
369+
highTestMomentEventA = MdacCalculator.mwToLogM0(refMoment.getRefMw()) + momentErrorRange;
360370
}
361371

362372
if (lowTestMomentEventA == null) {
363373
lowTestMomentEventA = DEFAULT_LOW_MOMENT;
374+
}
375+
if (highTestMomentEventA == null) {
364376
highTestMomentEventA = DEFAULT_HIGH_MOMENT;
365377
}
366378

367379
fitMoment = fitMwService.findByEventId(eventPair.getX().getEventId());
368380
refMoment = refMwService.findByEventId(eventPair.getX().getEventId());
369381

370382
if (fitMoment != null) {
371-
lowTestMomentEventB = MdacCalculator.mwToLogM0(fitMoment.getMw()) - DEFAULT_MOMENT_ERROR;
372-
highTestMomentEventB = MdacCalculator.mwToLogM0(fitMoment.getMw()) + DEFAULT_MOMENT_ERROR;
383+
lowTestMomentEventB = MdacCalculator.mwToLogM0(fitMoment.getMw()) - momentErrorRange;
384+
highTestMomentEventB = MdacCalculator.mwToLogM0(fitMoment.getMw()) + momentErrorRange;
373385
} else if (refMoment != null) {
374-
lowTestMomentEventB = MdacCalculator.mwToLogM0(refMoment.getRefMw()) - DEFAULT_MOMENT_ERROR;
375-
highTestMomentEventB = MdacCalculator.mwToLogM0(refMoment.getRefMw()) + DEFAULT_MOMENT_ERROR;
386+
lowTestMomentEventB = MdacCalculator.mwToLogM0(refMoment.getRefMw()) - momentErrorRange;
387+
highTestMomentEventB = MdacCalculator.mwToLogM0(refMoment.getRefMw()) + momentErrorRange;
376388
}
377389

378390
if (lowTestMomentEventB == null) {
379391
lowTestMomentEventB = DEFAULT_LOW_MOMENT;
392+
}
393+
if (highTestMomentEventB == null) {
380394
highTestMomentEventB = DEFAULT_HIGH_MOMENT;
381395
}
382396

0 commit comments

Comments
 (0)