Skip to content

Commit

Permalink
CCT 1.0.5: Bugfixes and performance improvements from feedback on use…
Browse files Browse the repository at this point in the history
…rs of REST clients.
  • Loading branch information
justinbarno committed Aug 14, 2019
1 parent e2562df commit b45fa48
Show file tree
Hide file tree
Showing 48 changed files with 647 additions and 349 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ We don't presently deploy versioned artifacts into a public repository like the
#### **As a single runnable JAR**

```shell
java -jar coda-calibration/calibration-standalone/target/calibration-standalone-1.0.4-runnable.jar
java -jar coda-calibration/calibration-standalone/target/calibration-standalone-1.0.5-runnable.jar
```

#### **GUI alone**

```shell
java -jar coda-calibration/calibration-gui/target/calibration-gui-1.0.4-runnable.jar
java -jar coda-calibration/calibration-gui/target/calibration-gui-1.0.5-runnable.jar
```
#### **Calibration REST service alone**

```shell
java -jar coda-calibration/calibration-service/application/target/application-1.0.4-runnable.jar
java -jar coda-calibration/calibration-service/application/target/application-1.0.5-runnable.jar
```

#### A note about HTTPS
Expand Down
2 changes: 1 addition & 1 deletion calibration-gui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>gov.llnl.gnem.apps.coda.calibration</groupId>
<artifactId>coda-calibration</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.5</version>
</parent>

<artifactId>calibration-gui</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* Copyright (c) 2018, Lawrence Livermore National Security, LLC. Produced at the Lawrence Livermore National Laboratory
* CODE-743439.
* All rights reserved.
* This file is part of CCT. For details, see https://github.com/LLNL/coda-calibration-tool.
*
* This file is part of CCT. For details, see https://github.com/LLNL/coda-calibration-tool.
*
* Licensed under the Apache License, Version 2.0 (the “Licensee”); you may not use this file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the license.
*
* This work was performed under the auspices of the U.S. Department of Energy
Expand Down Expand Up @@ -150,7 +150,7 @@ public void setWaveform(Waveform waveform, SyntheticCoda synth) {
// waveform so we need to check that
for (WaveformPick pick : picks) {
double pickTime;
//"'Bad' pick, plot it at begin time
//"'Bad' pick, plot it at begin time
if (pick.getPickTimeSecFromOrigin() < 0) {
pickTime = new TimeT(waveform.getBeginTime()).getEpochTime();
} else {
Expand Down Expand Up @@ -271,17 +271,20 @@ private void plotSynthetic(Waveform waveform, SyntheticCoda synth, final TimeT b
if (startTime.lt(endTime)) {
interpolatedSeries.cut(startTime, endTime);
synthSeriesBeforeEndMarker.cut(startTime, endTime);
synthSeriesRemaining.cutBefore(endTime);

TimeSeries diffSeis = interpolatedSeries.subtract(synthSeriesBeforeEndMarker);
int synthStartTimeShift = (int) (startTime.subtractD(beginTime) + 0.5);
int remainingStartTimeShift = (int) (endTime.subtractD(beginTime) + 0.5);
double median = diffSeis.getMedian();

subplot.DeletePlotObject(legendRef);
subplot.AddPlotObject(createLegend(labelText + "Shift: " + dfmt4.format(median)));
subplot.AddPlotObject(createLine(synthStartTimeShift, median, synthSeriesBeforeEndMarker, Color.GREEN), PLOT_ORDERING.MODEL_FIT.getZOrder());
subplot.AddPlotObject(createLine(remainingStartTimeShift, median, synthSeriesRemaining, Color.GREEN, 3, PenStyle.DASH), PLOT_ORDERING.MODEL_FIT.getZOrder());

if (endTime.lt(synthSeriesRemaining.getEndtime())) {
synthSeriesRemaining.cutBefore(endTime);
int remainingStartTimeShift = (int) (endTime.subtractD(beginTime) + 0.5);
subplot.AddPlotObject(createLine(remainingStartTimeShift, median, synthSeriesRemaining, Color.GREEN, 3, PenStyle.DASH), PLOT_ORDERING.MODEL_FIT.getZOrder());
}
repaint();
}
}
Expand Down Expand Up @@ -336,7 +339,7 @@ private PlotObject createRectangle(int timeStart, int timeEnd, int heightMin, in

/*
* (non-Javadoc)
*
*
* @see
* llnl.gnem.core.gui.waveform.WaveformPlot#handlePickMovedState(java.lang.
* Object)T
Expand Down
2 changes: 1 addition & 1 deletion calibration-service/calibration-application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>gov.llnl.gnem.apps.coda.calibration</groupId>
<artifactId>calibration-service</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.5</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion calibration-service/calibration-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>gov.llnl.gnem.apps.coda.calibration</groupId>
<artifactId>calibration-service</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.5</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion calibration-service/calibration-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>gov.llnl.gnem.apps.coda.calibration</groupId>
<artifactId>calibration-service</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.5</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion calibration-service/calibration-repository/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>gov.llnl.gnem.apps.coda.calibration</groupId>
<artifactId>calibration-service</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.5</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion calibration-service/calibration-service-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>gov.llnl.gnem.apps.coda.calibration</groupId>
<artifactId>calibration-service</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.5</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion calibration-service/calibration-service-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>gov.llnl.gnem.apps.coda.calibration</groupId>
<artifactId>calibration-service</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.5</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.Set;
import java.util.stream.IntStream;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.math3.analysis.MultivariateFunction;
import org.apache.commons.math3.exception.TooManyEvaluationsException;
import org.apache.commons.math3.optim.ConvergenceChecker;
Expand All @@ -37,7 +36,7 @@
import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction;
import org.apache.commons.math3.optim.nonlinear.scalar.noderiv.CMAESOptimizer;
import org.apache.commons.math3.random.MersenneTwister;
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
import org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -348,7 +347,7 @@ public double costFunction(Map<Event, Map<Station, SpectraMeasurement>> evidStaD
Event evid = evidEntry.getKey();
Map<Station, SpectraMeasurement> stationMapData = evidEntry.getValue();

List<Double> dataVec = new ArrayList<>(optimizationParams.length);
DoubleArrayList dataVec = new DoubleArrayList(stationMapData.size());
for (Entry<Station, SpectraMeasurement> entry : stationMapData.entrySet()) {
double del = distanceMap.get(evid).get(entry.getKey());
double site = optimizationParams[stationIdxMap.get(entry.getKey())];
Expand All @@ -367,7 +366,7 @@ public double costFunction(Map<Event, Map<Station, SpectraMeasurement>> evidStaD

if (dataVec.size() > 1) {
double huberDel = .5d;
double median = new DescriptiveStatistics(ArrayUtils.toPrimitive(dataVec.toArray(new Double[0]))).getPercentile(50d);
double median = dataVec.median();
for (Entry<Station, SpectraMeasurement> entry1 : stationMapData.entrySet()) {
double diff = Math.abs(localDataMap.get(evid).get(entry1.getKey()) - median);
cost = cost + (Math.pow(huberDel, 2.0) + (Math.sqrt(1d + Math.pow(diff / huberDel, 2.0)) - 1d));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -159,6 +160,14 @@ public EnvelopeFit fitCodaCMAES(final float[] segment) {
return fit;
}

private PointValuePair bestByFunction(MultivariateFunction prediction, Function<Integer, PointValuePair> mapper) {
return IntStream.range(0, 1 + ITER_COUNT)
.parallel()
.mapToObj(mapper::apply)
.reduce((left, right) -> left.getValue() < right.getValue() ? left : right)
.orElseGet(() -> new PointValuePair(new double[4], Double.MAX_VALUE));
}

public double[] gridSearchCodaVApacheCMAES(List<Entry<Double, Double>> velocityDistancePairs) {
return gridSearchCodaVApacheCMAES(velocityDistancePairs, YVV_MIN, YVV_MAX, 0, V_DIST_MAX);
}
Expand Down Expand Up @@ -192,23 +201,14 @@ public double[] gridSearchCodaVApacheCMAES(final List<Entry<Double, Double>> vel
return sum;
};

PointValuePair bestResult = optimizeCMAES(
Function<Integer, PointValuePair> mapper = (i) -> optimizeCMAES(
prediction,
new InitialGuess(new double[] { ThreadLocalRandom.current().nextDouble(minP1, maxP1), ThreadLocalRandom.current().nextDouble(minP2, maxP2),
ThreadLocalRandom.current().nextDouble(minP3, maxP3) }),
new CMAESOptimizer.Sigma(new double[] { 1, 75, 100 }),
new SimpleBounds(new double[] { minP1, minP2, minP3 }, new double[] { maxP1, maxP2, maxP3 }));
for (int i = 1; i < ITER_COUNT; i++) {
PointValuePair result = optimizeCMAES(
prediction,
new InitialGuess(new double[] { ThreadLocalRandom.current().nextDouble(minP1, maxP1), ThreadLocalRandom.current().nextDouble(minP2, maxP2),
ThreadLocalRandom.current().nextDouble(minP3, maxP3) }),
new CMAESOptimizer.Sigma(new double[] { 1, 75, 100 }),
new SimpleBounds(new double[] { minP1, minP2, minP3 }, new double[] { maxP1, maxP2, maxP3 }));
if (result.getValue() < bestResult.getValue()) {
bestResult = result;
}
}

PointValuePair bestResult = bestByFunction(prediction, mapper);

double[] curve = new double[4];
curve[0] = bestResult.getPoint()[0] / V0_REG;
Expand Down Expand Up @@ -256,25 +256,15 @@ public double[] gridSearchCodaBApacheCMAES(final List<Entry<Double, Double>> bet
return sum;
};

PointValuePair bestResult = optimizeCMAES(
Function<Integer, PointValuePair> mapper = (i) -> optimizeCMAES(
prediction,
new InitialGuess(new double[] { ThreadLocalRandom.current().nextDouble(minP1, maxP1), ThreadLocalRandom.current().nextDouble(minP2, maxP2),
ThreadLocalRandom.current().nextDouble(minP3, maxP3) }),
new CMAESOptimizer.Sigma(new double[] { .05, 0.5, 750 }),
50,
new SimpleBounds(new double[] { minP1, minP2, minP3 }, new double[] { maxP1, maxP2, maxP3 }));
for (int i = 1; i < ITER_COUNT; i++) {
PointValuePair result = optimizeCMAES(
prediction,
new InitialGuess(new double[] { ThreadLocalRandom.current().nextDouble(minP1, maxP1), ThreadLocalRandom.current().nextDouble(minP2, maxP2),
ThreadLocalRandom.current().nextDouble(minP3, maxP3) }),
new CMAESOptimizer.Sigma(new double[] { .05, 0.5, 750 }),
50,
new SimpleBounds(new double[] { minP1, minP2, minP3 }, new double[] { maxP1, maxP2, maxP3 }));
if (result.getValue() < bestResult.getValue()) {
bestResult = result;
}
}

PointValuePair bestResult = bestByFunction(prediction, mapper);

double[] curve = new double[4];
curve[0] = bestResult.getPoint()[0] / B0_REG;
Expand Down Expand Up @@ -338,27 +328,15 @@ public double[] gridSearchCodaGApacheCMAES(final List<Entry<Double, Double>> gam

ConvergenceChecker<PointValuePair> convergenceChecker = new SimplePointChecker<>(0.005, 0.005, 100000);

PointValuePair bestResult = optimizeCMAES(
Function<Integer, PointValuePair> mapper = (i) -> optimizeCMAES(
prediction,
new InitialGuess(new double[] { ThreadLocalRandom.current().nextDouble(minP1, maxP1), minP2, minP3 }),
new CMAESOptimizer.Sigma(new double[] { 1, 50, 50 }),
convergenceChecker,
50,
new SimpleBounds(new double[] { minP1, minP2, minP3 }, new double[] { maxP1, maxP2, maxP3 }));
for (int i = 1; i < ITER_COUNT; i++) {

PointValuePair result = optimizeCMAES(
prediction,
new InitialGuess(new double[] { ThreadLocalRandom.current().nextDouble(minP1, maxP1), ThreadLocalRandom.current().nextDouble(minP2, maxP2),
ThreadLocalRandom.current().nextDouble(minP3, maxP3) }),
new CMAESOptimizer.Sigma(new double[] { 1, 50, 50 }),
convergenceChecker,
50,
new SimpleBounds(new double[] { minP1, minP2, minP3 }, new double[] { maxP1, maxP2, maxP3 }));
if (result.getValue() < bestResult.getValue()) {
bestResult = result;
}
}

PointValuePair bestResult = bestByFunction(prediction, mapper);

double[] curve = new double[4];
curve[0] = bestResult.getPoint()[0] / G0_REG;
Expand Down
2 changes: 1 addition & 1 deletion calibration-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>gov.llnl.gnem.apps.coda.calibration</groupId>
<artifactId>coda-calibration</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.5</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion calibration-standalone/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>gov.llnl.gnem.apps.coda.calibration</groupId>
<artifactId>coda-calibration</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.5</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion common-gui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>gov.llnl.gnem.apps.coda.calibration</groupId>
<artifactId>coda-calibration</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.5</version>
</parent>

<groupId>gov.llnl.gnem.apps.coda.common</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* Copyright (c) 2018, Lawrence Livermore National Security, LLC. Produced at the Lawrence Livermore National Laboratory
* CODE-743439.
* All rights reserved.
* This file is part of CCT. For details, see https://github.com/LLNL/coda-calibration-tool.
*
* This file is part of CCT. For details, see https://github.com/LLNL/coda-calibration-tool.
*
* Licensed under the Apache License, Version 2.0 (the “Licensee”); you may not use this file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the license.
*
* This work was performed under the auspices of the U.S. Department of Energy
Expand Down Expand Up @@ -42,8 +42,6 @@
@Component
public class SacExporter {
private static final String SEP = "_";
private final NumberFormat dfmt4 = NumberFormatFactory.fourDecimalOneLeadingZero();

private static final Logger log = LoggerFactory.getLogger(SacExporter.class);

public Result<String> writeWaveformToDirectory(File exportDirectory, Waveform w) {
Expand Down Expand Up @@ -104,24 +102,23 @@ public Result<String> writeWaveformToDirectory(File exportDirectory, Waveform w)
}
os.flush();

return new Result<String>(true, filename);
return new Result<>(true, filename);
}
} catch (IOException e) {
log.error(e.getMessage(), e);
return new Result<String>(false, e.toString()).setErrors(Collections.singletonList(e));
return new Result<>(false, e.toString()).setErrors(Collections.singletonList(e));
}
}

String message = "Waveform is missing required information or is malformed; waveform: " + w;
log.error(message);
return new Result<String>(false, message);
return new Result<>(false, message);
}

private boolean waveformFullySpecified(Waveform w) {
return w != null
&& w.getLowFrequency() != null
&& w.getHighFrequency() != null
&& present(w.getSegmentType())
&& w.getSampleRate() != null
&& w.getBeginTime() != null
&& w.getEndTime() != null
Expand All @@ -136,6 +133,7 @@ && present(w.getStream().getChannelName())

public String getFileName(Waveform w) {
if (waveformFullySpecified(w)) {
NumberFormat dfmt4 = NumberFormatFactory.fourDecimalOneLeadingZero();
Stream stream = w.getStream();
Event ev = w.getEvent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* Copyright (c) 2018, Lawrence Livermore National Security, LLC. Produced at the Lawrence Livermore National Laboratory
* CODE-743439.
* All rights reserved.
* This file is part of CCT. For details, see https://github.com/LLNL/coda-calibration-tool.
*
* This file is part of CCT. For details, see https://github.com/LLNL/coda-calibration-tool.
*
* Licensed under the Apache License, Version 2.0 (the “Licensee”); you may not use this file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the license.
*
* This work was performed under the auspices of the U.S. Department of Energy
Expand Down Expand Up @@ -209,7 +209,7 @@ public Result<Waveform> convertSacFileToWaveform(File file) {
double[] segment = new double[rawVals.length];
try {
IntStream.range(0, rawVals.length).forEach(index -> {
segment[index] = Double.valueOf(rawVals[index]);
segment[index] = rawVals[index];
if (!Double.isFinite(segment[index])) {
throw new LightweightIllegalStateException("Invalid data in segment for file: " + fileName);
}
Expand Down
Loading

0 comments on commit b45fa48

Please sign in to comment.