From 49bac4e5641d5d988d7ffc9cf9caf7c8aa80a612 Mon Sep 17 00:00:00 2001 From: Justin Barno Date: Thu, 11 May 2023 08:29:59 -0700 Subject: [PATCH] Added support for setting the moment error range in the spectra ratio inversion by using the --ratio-inversion.moment-error-range flag --- .../service/impl/SpectraRatioServiceImpl.java | 8 ++- .../SpectraRatioInversionCalculator.java | 50 ++++++++++++------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/calibration-service/calibration-service-impl/src/main/java/gov/llnl/gnem/apps/coda/calibration/service/impl/SpectraRatioServiceImpl.java b/calibration-service/calibration-service-impl/src/main/java/gov/llnl/gnem/apps/coda/calibration/service/impl/SpectraRatioServiceImpl.java index 216b3260..b34c7cf7 100644 --- a/calibration-service/calibration-service-impl/src/main/java/gov/llnl/gnem/apps/coda/calibration/service/impl/SpectraRatioServiceImpl.java +++ b/calibration-service/calibration-service-impl/src/main/java/gov/llnl/gnem/apps/coda/calibration/service/impl/SpectraRatioServiceImpl.java @@ -39,6 +39,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -98,6 +99,9 @@ @Transactional public class SpectraRatioServiceImpl implements SpectraRatioPairDetailsService { + @Value(value = "${ratio-inversion.moment-error-range:0.1}") + private double momentErrorRange; + private Logger log = LoggerFactory.getLogger(SpectraRatioServiceImpl.class); private SpectraRatioPairDetailsRepository spectraRatioPairDetailsRepository; @@ -320,7 +324,7 @@ public Future> makeSpectraRatioMeasurements(boolean private Map invertEventRatioPairs(Map>> ratioData) { final MdacParametersFI mdacFiEntry = new MdacParametersFI(mdacFiService.findFirst()); final MdacParametersPS psRows = mdacPsService.findMatchingPhase(PICK_TYPES.LG.getPhase()); - SpectraRatioInversionCalculator inversion = new SpectraRatioInversionCalculator(mdacService, mdacFiEntry, psRows, fitMwService, refMwService); + SpectraRatioInversionCalculator inversion = new SpectraRatioInversionCalculator(mdacService, mdacFiEntry, psRows, fitMwService, refMwService, momentErrorRange); Map inversionResults = inversion.cmaesRegressionPerPair(ratioData); return inversionResults; } @@ -328,7 +332,7 @@ private Map invertEventRatioPairs(Ma private Map invertEventRatios(Map>> ratioData) { final MdacParametersFI mdacFiEntry = new MdacParametersFI(mdacFiService.findFirst()); final MdacParametersPS psRows = mdacPsService.findMatchingPhase(PICK_TYPES.LG.getPhase()); - SpectraRatioInversionCalculator inversion = new SpectraRatioInversionCalculator(mdacService, mdacFiEntry, psRows, fitMwService, refMwService); + SpectraRatioInversionCalculator inversion = new SpectraRatioInversionCalculator(mdacService, mdacFiEntry, psRows, fitMwService, refMwService, momentErrorRange); Map inversionResults = inversion.cmaesRegressionJoint(ratioData); return inversionResults; } diff --git a/calibration-service/calibration-service-impl/src/main/java/gov/llnl/gnem/apps/coda/calibration/service/impl/processing/SpectraRatioInversionCalculator.java b/calibration-service/calibration-service-impl/src/main/java/gov/llnl/gnem/apps/coda/calibration/service/impl/processing/SpectraRatioInversionCalculator.java index 9f0d1b6c..d5c46b2f 100644 --- a/calibration-service/calibration-service-impl/src/main/java/gov/llnl/gnem/apps/coda/calibration/service/impl/processing/SpectraRatioInversionCalculator.java +++ b/calibration-service/calibration-service-impl/src/main/java/gov/llnl/gnem/apps/coda/calibration/service/impl/processing/SpectraRatioInversionCalculator.java @@ -65,7 +65,7 @@ public class SpectraRatioInversionCalculator { private static final int PARAM_COUNT = 2; - private final double DEFAULT_MOMENT_ERROR = 1.0; + private double momentErrorRange; private final double DEFAULT_LOW_MOMENT = 1.0; private final double DEFAULT_HIGH_MOMENT = 25.0; private final double testMomentIncrement = 0.25; @@ -79,11 +79,12 @@ public class SpectraRatioInversionCalculator { private MdacCalculator mdacCalculator; public SpectraRatioInversionCalculator(MdacCalculatorService mdacService, MdacParametersFI mdacFiEntry, MdacParametersPS psRows, MeasuredMwsService fitMwService, - ReferenceMwParametersService refMwService) { + ReferenceMwParametersService refMwService, double momentErrorRange) { this.fitMwService = fitMwService; this.refMwService = refMwService; //We just want the K constant for the given MDAC model so no need for a real moment here this.mdacCalculator = mdacService.getMdacCalculator(psRows, mdacFiEntry, DEFAULT_HIGH_MOMENT); + this.momentErrorRange = momentErrorRange; } public Map> gridSearchPerPair(Map>> ratioData) { @@ -115,6 +116,8 @@ public Map> gridSearchPerPair(Map> gridSearchPerPair(Map> gridSearchPerPair(Map cmaesRegressionPerPair(Map>> ratioData) { @@ -187,15 +193,17 @@ public Map cmaesRegressionPerPair(Ma ReferenceMwParameters refMoment = refMwService.findByEventId(eventPair.getY().getEventId()); if (fitMoment != null) { - lowTestMomentEventA = MdacCalculator.mwToLogM0(fitMoment.getMw()) - DEFAULT_MOMENT_ERROR; - highTestMomentEventA = MdacCalculator.mwToLogM0(fitMoment.getMw()) + DEFAULT_MOMENT_ERROR; + lowTestMomentEventA = MdacCalculator.mwToLogM0(fitMoment.getMw()) - momentErrorRange; + highTestMomentEventA = MdacCalculator.mwToLogM0(fitMoment.getMw()) + momentErrorRange; } else if (refMoment != null) { - lowTestMomentEventA = MdacCalculator.mwToLogM0(refMoment.getRefMw()) - DEFAULT_MOMENT_ERROR; - highTestMomentEventA = MdacCalculator.mwToLogM0(refMoment.getRefMw()) + DEFAULT_MOMENT_ERROR; + lowTestMomentEventA = MdacCalculator.mwToLogM0(refMoment.getRefMw()) - momentErrorRange; + highTestMomentEventA = MdacCalculator.mwToLogM0(refMoment.getRefMw()) + momentErrorRange; } if (lowTestMomentEventA == null) { lowTestMomentEventA = DEFAULT_LOW_MOMENT; + } + if (highTestMomentEventA == null) { highTestMomentEventA = DEFAULT_HIGH_MOMENT; } @@ -203,15 +211,17 @@ public Map cmaesRegressionPerPair(Ma refMoment = refMwService.findByEventId(eventPair.getX().getEventId()); if (fitMoment != null) { - lowTestMomentEventB = MdacCalculator.mwToLogM0(fitMoment.getMw()) - DEFAULT_MOMENT_ERROR; - highTestMomentEventB = MdacCalculator.mwToLogM0(fitMoment.getMw()) + DEFAULT_MOMENT_ERROR; + lowTestMomentEventB = MdacCalculator.mwToLogM0(fitMoment.getMw()) - momentErrorRange; + highTestMomentEventB = MdacCalculator.mwToLogM0(fitMoment.getMw()) + momentErrorRange; } else if (refMoment != null) { - lowTestMomentEventB = MdacCalculator.mwToLogM0(refMoment.getRefMw()) - DEFAULT_MOMENT_ERROR; - highTestMomentEventB = MdacCalculator.mwToLogM0(refMoment.getRefMw()) + DEFAULT_MOMENT_ERROR; + lowTestMomentEventB = MdacCalculator.mwToLogM0(refMoment.getRefMw()) - momentErrorRange; + highTestMomentEventB = MdacCalculator.mwToLogM0(refMoment.getRefMw()) + momentErrorRange; } if (lowTestMomentEventB == null) { lowTestMomentEventB = DEFAULT_LOW_MOMENT; + } + if (highTestMomentEventB == null) { highTestMomentEventB = DEFAULT_HIGH_MOMENT; } @@ -352,15 +362,17 @@ public Map cmaesRegressionJoint ReferenceMwParameters refMoment = refMwService.findByEventId(eventPair.getY().getEventId()); if (fitMoment != null) { - lowTestMomentEventA = MdacCalculator.mwToLogM0(fitMoment.getMw()) - DEFAULT_MOMENT_ERROR; - highTestMomentEventA = MdacCalculator.mwToLogM0(fitMoment.getMw()) + DEFAULT_MOMENT_ERROR; + lowTestMomentEventA = MdacCalculator.mwToLogM0(fitMoment.getMw()) - momentErrorRange; + highTestMomentEventA = MdacCalculator.mwToLogM0(fitMoment.getMw()) + momentErrorRange; } else if (refMoment != null) { - lowTestMomentEventA = MdacCalculator.mwToLogM0(refMoment.getRefMw()) - DEFAULT_MOMENT_ERROR; - highTestMomentEventA = MdacCalculator.mwToLogM0(refMoment.getRefMw()) + DEFAULT_MOMENT_ERROR; + lowTestMomentEventA = MdacCalculator.mwToLogM0(refMoment.getRefMw()) - momentErrorRange; + highTestMomentEventA = MdacCalculator.mwToLogM0(refMoment.getRefMw()) + momentErrorRange; } if (lowTestMomentEventA == null) { lowTestMomentEventA = DEFAULT_LOW_MOMENT; + } + if (highTestMomentEventA == null) { highTestMomentEventA = DEFAULT_HIGH_MOMENT; } @@ -368,15 +380,17 @@ public Map cmaesRegressionJoint refMoment = refMwService.findByEventId(eventPair.getX().getEventId()); if (fitMoment != null) { - lowTestMomentEventB = MdacCalculator.mwToLogM0(fitMoment.getMw()) - DEFAULT_MOMENT_ERROR; - highTestMomentEventB = MdacCalculator.mwToLogM0(fitMoment.getMw()) + DEFAULT_MOMENT_ERROR; + lowTestMomentEventB = MdacCalculator.mwToLogM0(fitMoment.getMw()) - momentErrorRange; + highTestMomentEventB = MdacCalculator.mwToLogM0(fitMoment.getMw()) + momentErrorRange; } else if (refMoment != null) { - lowTestMomentEventB = MdacCalculator.mwToLogM0(refMoment.getRefMw()) - DEFAULT_MOMENT_ERROR; - highTestMomentEventB = MdacCalculator.mwToLogM0(refMoment.getRefMw()) + DEFAULT_MOMENT_ERROR; + lowTestMomentEventB = MdacCalculator.mwToLogM0(refMoment.getRefMw()) - momentErrorRange; + highTestMomentEventB = MdacCalculator.mwToLogM0(refMoment.getRefMw()) + momentErrorRange; } if (lowTestMomentEventB == null) { lowTestMomentEventB = DEFAULT_LOW_MOMENT; + } + if (highTestMomentEventB == null) { highTestMomentEventB = DEFAULT_HIGH_MOMENT; }