-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add condition that compares instrument code to input and output units…
…. Addresses issue #96.
- Loading branch information
timronan
committed
Apr 10, 2020
1 parent
14d82eb
commit 34cb074
Showing
5 changed files
with
784 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/main/java/edu/iris/dmc/station/conditions/InstrumentCodeUnitsCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package edu.iris.dmc.station.conditions; | ||
|
||
import edu.iris.dmc.fdsn.station.model.Azimuth; | ||
import edu.iris.dmc.fdsn.station.model.Channel; | ||
import edu.iris.dmc.fdsn.station.model.Dip; | ||
import edu.iris.dmc.fdsn.station.model.Network; | ||
import edu.iris.dmc.fdsn.station.model.ResponseStage; | ||
import edu.iris.dmc.fdsn.station.model.Station; | ||
import edu.iris.dmc.seed.control.station.Stage; | ||
import edu.iris.dmc.station.rules.Message; | ||
import edu.iris.dmc.station.rules.Result; | ||
|
||
public class InstrumentCodeUnitsCondition extends AbstractCondition { | ||
|
||
public InstrumentCodeUnitsCondition(boolean required, String description) { | ||
super(required, description); | ||
|
||
} | ||
|
||
@Override | ||
public Message evaluate(Network network) { | ||
throw new IllegalArgumentException("Not supported!"); | ||
} | ||
|
||
@Override | ||
public Message evaluate(Station station) { | ||
throw new IllegalArgumentException("Not supported!"); | ||
} | ||
|
||
@Override | ||
public Message evaluate(Channel channel) { | ||
String inputUnit =""; | ||
String code = channel.getCode(); | ||
ResponseStage stage1 = channel.getResponse().getStage().get(0); | ||
if(stage1.getCoefficients() != null) { | ||
inputUnit = stage1.getCoefficients().getInputUnits().getName(); | ||
}else if(stage1.getPolesZeros() != null){ | ||
inputUnit = stage1.getPolesZeros().getInputUnits().getName(); | ||
}else if(stage1.getResponseList() != null){ | ||
inputUnit = stage1.getResponseList().getInputUnits().getName(); | ||
}else if(stage1.getFIR()!=null) { | ||
inputUnit = stage1.getFIR().getInputUnits().getName(); | ||
}else if(stage1.getPolynomial()!= null){ | ||
inputUnit = stage1.getPolynomial().getInputUnits().getName(); | ||
}else { | ||
return Result.success(); | ||
} | ||
|
||
int lastindex = channel.getResponse().getStage().size()-1; | ||
ResponseStage stagelast = channel.getResponse().getStage().get(lastindex); | ||
String outputUnit =""; | ||
if(stagelast.getCoefficients() != null) { | ||
outputUnit = stagelast.getCoefficients().getOutputUnits().getName(); | ||
}else if(stagelast.getPolesZeros() != null){ | ||
outputUnit = stagelast.getPolesZeros().getOutputUnits().getName(); | ||
}else if(stagelast.getResponseList() != null){ | ||
outputUnit = stagelast.getResponseList().getOutputUnits().getName(); | ||
}else if(stagelast.getFIR()!=null) { | ||
outputUnit = stagelast.getFIR().getOutputUnits().getName(); | ||
}else if(stagelast.getPolynomial()!= null){ | ||
outputUnit = stagelast.getPolynomial().getOutputUnits().getName(); | ||
}else { | ||
return Result.success(); | ||
} | ||
|
||
|
||
try { | ||
if("HLMN".indexOf(code.charAt(1)) >=0 | "hlmn".indexOf(code.charAt(1)) >=0) { | ||
if(!inputUnit.toLowerCase().contains("m/s")) { | ||
return Result.warning("Instument code " +code.charAt(1)+" should have stage 1 input units similar to *m/s*."); | ||
} | ||
if(!outputUnit.toLowerCase().contains("count")) { | ||
return Result.warning("Instument code " +code.charAt(1)+ " should have stage last output units similar to count*."); | ||
} | ||
|
||
} | ||
}catch(Exception e) { | ||
|
||
} | ||
return Result.success(); | ||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/test/java/edu/iris/dmc/station/conditions/Condition406Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package edu.iris.dmc.station.conditions; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.InputStream; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import edu.iris.dmc.DocumentMarshaller; | ||
import edu.iris.dmc.fdsn.station.model.Channel; | ||
import edu.iris.dmc.fdsn.station.model.FDSNStationXML; | ||
import edu.iris.dmc.fdsn.station.model.Network; | ||
import edu.iris.dmc.fdsn.station.model.Station; | ||
import edu.iris.dmc.station.RuleEngineServiceTest; | ||
import edu.iris.dmc.station.conditions.EpochRangeCondition; | ||
import edu.iris.dmc.station.conditions.StartTimeCondition; | ||
import edu.iris.dmc.station.rules.Message; | ||
|
||
public class Condition406Test { | ||
|
||
private FDSNStationXML theDocument; | ||
|
||
@BeforeEach | ||
public void init() throws Exception { | ||
|
||
} | ||
|
||
@Test | ||
public void azimuthfail() throws Exception { | ||
try (InputStream is = RuleEngineServiceTest.class.getClassLoader().getResourceAsStream("F1_406.xml")) { | ||
theDocument = DocumentMarshaller.unmarshal(is); | ||
|
||
Network n = theDocument.getNetwork().get(0); | ||
Station s = n.getStations().get(0); | ||
Channel c = s.getChannels().get(0); | ||
|
||
InstrumentCodeUnitsCondition condition = new InstrumentCodeUnitsCondition(true, ""); | ||
Message result = condition.evaluate(c); | ||
System.out.println(result); | ||
assertTrue(result instanceof edu.iris.dmc.station.rules.Warning); | ||
} | ||
|
||
} | ||
|
||
|
||
@Test | ||
public void pass() throws Exception { | ||
try (InputStream is = RuleEngineServiceTest.class.getClassLoader().getResourceAsStream("pass.xml")) { | ||
theDocument = DocumentMarshaller.unmarshal(is); | ||
|
||
Network n = theDocument.getNetwork().get(0); | ||
Station s = n.getStations().get(0); | ||
Channel c = s.getChannels().get(0); | ||
|
||
|
||
InstrumentCodeUnitsCondition condition = new InstrumentCodeUnitsCondition(true, ""); | ||
|
||
Message result = condition.evaluate(c); | ||
assertTrue(result instanceof edu.iris.dmc.station.rules.Success); | ||
} | ||
|
||
} | ||
} | ||
|
Oops, something went wrong.