Skip to content

Commit

Permalink
more tests for illegal phase names, checks to block bad phases like S…
Browse files Browse the repository at this point in the history
…cScS
  • Loading branch information
crotwell committed Jan 6, 2021
1 parent 0985943 commit b534c8e
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 13 deletions.
77 changes: 69 additions & 8 deletions src/main/java/edu/sc/seis/TauP/SeismicPhase.java
Original file line number Diff line number Diff line change
Expand Up @@ -890,10 +890,43 @@ protected void addToBranch(TauModel tMod,
isPWave)
.getMinTurnRayParam());
} else {
throw new TauModelException("Illegal endAction: endAction="
throw new TauModelException(getName()+": Illegal endAction: endAction="
+ endAction);
}
SeismicPhaseSegment segment = new SeismicPhaseSegment(tMod, startBranch, endBranch, isPWave, endAction, isDownGoing, currLeg);
if (segmentList.size() > 0) {
SeismicPhaseSegment prevSegment = segmentList.get(segmentList.size()-1);
if (isDownGoing) {
if (prevSegment.endBranch > startBranch) {
throw new TauModelException(getName()+": Segment is downgoing, but we are already below the start: "+currLeg);
}
if (prevSegment.endAction == REFLECT_TOPSIDE) {
throw new TauModelException(getName()+": Segment is downgoing, but previous action was to reflect up: "+currLeg);
}
if (prevSegment.endAction == TURN) {
throw new TauModelException(getName()+": Segment is downgoing, but previous action was to turn: "+currLeg);
}
if (prevSegment.endAction == TRANSUP) {
throw new TauModelException(getName()+": Segment is downgoing, but previous action was to transmit up: "+currLeg);
}
if (prevSegment.endBranch == startBranch && prevSegment.isDownGoing == false && prevSegment.endAction != REFLECT_UNDERSIDE) {
throw new TauModelException(getName()+": Segment "+currLeg+" is downgoing, but previous action was not to reflect underside: "+currLeg+" "+endActionString(prevSegment.endAction));
}
} else {
if (prevSegment.endBranch < startBranch) {
throw new TauModelException(getName()+": Segment is upgoing, but we are already above the start: "+currLeg);
}
if (prevSegment.endAction == REFLECT_UNDERSIDE) {
throw new TauModelException(getName()+": Segment is upgoing, but previous action was to underside reflect down: "+currLeg);
}
if (prevSegment.endAction == TRANSDOWN) {
throw new TauModelException(getName()+": Segment is upgoing, but previous action was to trans down: "+currLeg);
}
if (prevSegment.endBranch == startBranch && prevSegment.isDownGoing == true && ! ( prevSegment.endAction == TURN || prevSegment.endAction == REFLECT_TOPSIDE)) {
throw new TauModelException(getName()+": Segment is upgoing, but previous action was not to reflect topside: "+currLeg+" "+endActionString(prevSegment.endAction));
}
}
}
segmentList.add(segment);
if(isDownGoing) {
if (startBranch > endBranch) {
Expand Down Expand Up @@ -1198,7 +1231,33 @@ protected void parseName(TauModel tMod) throws TauModelException {
isPWave,
endAction,
currLeg);
} else if(nextLeg.startsWith("v")) {
} else if(nextLeg.equals("m")) {
endAction = TRANSDOWN;
addToBranch(tMod,
currBranch,
tMod.getMohoBranch() - 1,
isPWave,
endAction,
currLeg);
} else if( isLegDepth) {
disconBranch = closestBranchToDepth(tMod, nextLeg);
endAction = TRANSDOWN;
addToBranch(tMod,
currBranch,
disconBranch - 1,
isPWave,
endAction,
currLeg);
} else if(nextLeg.equals("c") || nextLeg.equals("i")) {
disconBranch = closestBranchToDepth(tMod, nextLeg);
endAction = REFLECT_TOPSIDE;
addToBranch(tMod,
currBranch,
disconBranch - 1,
isPWave,
endAction,
currLeg);
} else if(nextLeg.startsWith("v") ) {
disconBranch = closestBranchToDepth(tMod,
nextLeg.substring(1));
if(currBranch <= disconBranch - 1) {
Expand Down Expand Up @@ -1355,7 +1414,8 @@ protected void parseName(TauModel tMod) throws TauModelException {
currLeg);
} else if(prevLeg.startsWith("^") || prevLeg.equals("P")
|| prevLeg.equals("S") || prevLeg.equals("p")
|| prevLeg.equals("s") || prevLeg.equals("START")) {
|| prevLeg.equals("s") || prevLeg.equals("m")
|| prevLeg.equals("START")) {
endAction = TURN;
addToBranch(tMod,
currBranch,
Expand Down Expand Up @@ -2820,12 +2880,12 @@ public static String phaseValidate(ArrayList<String> legs) {
} else {
nextToken = "";
}
/* Check for 2 reflections with no leg between them. */
/* Check for 2 reflections/depths with no leg between them. */
if(currToken.startsWith("^") || currToken.startsWith("v")
|| currToken.equals("m") || currToken.equals("c")
|| currToken.equals("m") || currToken.equals("c")
|| currToken.equals("i")) {
if(prevIsReflect) {
return "Two reflections with no leg in between: "
return "Two reflections or depths with no leg in between: "
+ prevToken + ", " + currToken;
} else {
prevIsReflect = true;
Expand All @@ -2842,8 +2902,9 @@ public static String phaseValidate(ArrayList<String> legs) {
&& ! ( currToken.equals("END")
|| currToken.equals("Pdiff") || currToken.equals("Sdiff")
|| currToken.equals("P") || currToken.equals("S")
|| currToken.equals("K") || currToken.startsWith("v"))) {
return "'Ped' or 'Sed' can only be before Pdiff,P,S,Sdiff,K or second to last token immediately before END or ";
|| currToken.equals("K") || currToken.startsWith("v")
|| currToken.equals("c") || currToken.equals("m") )) {
return "'Ped' or 'Sed' can only be before Pdiff,P,S,Sdiff,K,c,v,m or second to last token immediately before END or ";
}

// Cannot have K before P,S and followed by another K as P,S leg must turn to get back to CMB
Expand Down
36 changes: 31 additions & 5 deletions src/test/java/edu/sc/seis/TauP/IllegalPhasesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,59 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;


class IllegalPhasesTest {

String[] illegalPhases = { "PDDDDD", "PKIKPKIKP", "PPPdiff", "PKIKIKP", "SIKS", "SKIS" };
List<String> otherLegalPhases = Arrays.asList(new String[] { "PmPv410P", "ScSScSScSScS", "PedKP", "PedcS", "PmP^410P" });

String[] illegalPhases = { "null", "ScScS", "PDDDDD", "PKIKPKIKP", "PPPdiff",
"PKIKIKP", "SIKS", "SKIS", "Pcv410S", "Pmv410P", "Pcv410P", "Pm^410P" };

// phases that are kind of wrong, but are handled by simply no arrivals, eg no ray params actually work,
// rather than being so bad as to cause an exception
String[] noArrivalPhases = { "PnPdiff" };
String[] noArrivalPhases = { "PnPdiff", "scS" };

// similar, but due to source being in mantle (below moho), these should have not ray params that
// can generate arrivals
String[] mantleSourceNoArrivalPhases = { "Pn", "Pvmp", "Sn", "Svms" };
String[] mantleSourceNoArrivalPhases = { "Pn", "Pvmp", "Sn", "Svms", "PmPv410P", "PmP^410P" };

@Test
void checkIllegalPhasesTest() throws TauModelException {
boolean DEBUG = true;
String modelName = "iasp91";
TauModel tMod = TauModelLoader.load(modelName);
float receiverDepth = 100;
for (String phaseName : illegalPhases) {
Exception exception = assertThrows(TauModelException.class, () -> {
SeismicPhase phase = new SeismicPhase(phaseName, tMod, receiverDepth);
SeismicPhase phase = new SeismicPhase(phaseName, tMod, receiverDepth, DEBUG);
}, phaseName+" shouldn't pass validation.");
}
}

@Test
void checkLegalPhasesTest() throws TauModelException {
boolean DEBUG = true;
String modelName = "iasp91";
TauModel tMod = TauModelLoader.load(modelName);
float receiverDepth = 100;
List<String> legalPhases = TauP_Time.getPhaseNames("ttall");
legalPhases.addAll(otherLegalPhases);
for (String phaseName : legalPhases) {
try {
SeismicPhase phase = new SeismicPhase(phaseName, tMod, receiverDepth, DEBUG);
} catch(TauModelException ex) {
System.err.println("Working on phase: "+phaseName);
throw ex;
}
}
}

@Test
void checkNoArrivalPhasesTest() throws TauModelException {
Expand All @@ -51,7 +77,7 @@ void checkNoArrivalMantleSourcePhasesTest() throws TauModelException {
double receiverDepth = 0;
for (String phaseName : mantleSourceNoArrivalPhases) {
SeismicPhase phase = new SeismicPhase(phaseName, tModDepth, receiverDepth);
assertFalse(phase.phasesExistsInModel(), phaseName+" shouldn't have arrivals for mantle source, "+sourceDepth);
assertFalse(phase.phasesExistsInModel(), phaseName+" shouldn't have arrivals for mantle source, "+sourceDepth+" phase: "+phase);
}
}

Expand Down

0 comments on commit b534c8e

Please sign in to comment.