Skip to content

Commit

Permalink
Added support for setting the moment error range in the spectra ratio…
Browse files Browse the repository at this point in the history
… inversion by using the --ratio-inversion.moment-error-range flag
  • Loading branch information
justinbarno committed May 11, 2023
1 parent 6538b88 commit 49bac4e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -320,15 +324,15 @@ public Future<Result<SpectraRatiosReport>> makeSpectraRatioMeasurements(boolean
private Map<EventPair, SpectraRatioPairInversionResult> invertEventRatioPairs(Map<EventPair, Map<Station, Map<FrequencyBand, SpectraRatioPairDetails>>> 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<EventPair, SpectraRatioPairInversionResult> inversionResults = inversion.cmaesRegressionPerPair(ratioData);
return inversionResults;
}

private Map<EventPair, SpectraRatioPairInversionResultJoint> invertEventRatios(Map<EventPair, Map<Station, Map<FrequencyBand, SpectraRatioPairDetails>>> 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<EventPair, SpectraRatioPairInversionResultJoint> inversionResults = inversion.cmaesRegressionJoint(ratioData);
return inversionResults;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<EventPair, List<MomentCornerEstimate>> gridSearchPerPair(Map<EventPair, Map<Station, Map<FrequencyBand, SpectraRatioPairDetails>>> ratioData) {
Expand Down Expand Up @@ -115,6 +116,8 @@ public Map<EventPair, List<MomentCornerEstimate>> gridSearchPerPair(Map<EventPai

if (lowTestMomentEventA == null) {
lowTestMomentEventA = DEFAULT_LOW_MOMENT;
}
if (highTestMomentEventA == null) {
highTestMomentEventA = DEFAULT_HIGH_MOMENT;
}

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

if (lowTestMomentEventB == null) {
lowTestMomentEventB = DEFAULT_LOW_MOMENT;
}
if (highTestMomentEventB == null) {
highTestMomentEventB = DEFAULT_HIGH_MOMENT;
}

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

return estimatedMomentCorners;

}

public Map<EventPair, SpectraRatioPairInversionResult> cmaesRegressionPerPair(Map<EventPair, Map<Station, Map<FrequencyBand, SpectraRatioPairDetails>>> ratioData) {
Expand All @@ -187,31 +193,35 @@ public Map<EventPair, SpectraRatioPairInversionResult> 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;
}

fitMoment = fitMwService.findByEventId(eventPair.getX().getEventId());
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;
}

Expand Down Expand Up @@ -352,31 +362,35 @@ public Map<EventPair, SpectraRatioPairInversionResultJoint> 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;
}

fitMoment = fitMwService.findByEventId(eventPair.getX().getEventId());
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;
}

Expand Down

0 comments on commit 49bac4e

Please sign in to comment.