Skip to content

Commit

Permalink
Add condition that compares instrument code to input and output units…
Browse files Browse the repository at this point in the history
…. Addresses issue #96.
  • Loading branch information
timronan committed Apr 10, 2020
1 parent 14d82eb commit 34cb074
Show file tree
Hide file tree
Showing 5 changed files with 784 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/main/java/edu/iris/dmc/station/RuleEngineRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import edu.iris.dmc.station.conditions.EpochOverlapCondition;
import edu.iris.dmc.station.conditions.EpochRangeCondition;
import edu.iris.dmc.station.conditions.FrequencyCondition;
import edu.iris.dmc.station.conditions.InstrumentCodeUnitsCondition;
import edu.iris.dmc.station.conditions.LocationCodeCondition;
import edu.iris.dmc.station.conditions.MissingDecimationCondition;
import edu.iris.dmc.station.conditions.OrientationCondition;
Expand Down Expand Up @@ -116,7 +117,7 @@ private void defaultStationRules(Set<Integer> set) {
}
if (!set.contains(221)) {
add(212, new EpochRangeCondition(true,
"Station:Epoch must encompass all subordinate Channel:Epoch"),
"Station:Epoch must encompass all subordinate Channel:Epoch."),
Station.class);
}

Expand Down Expand Up @@ -212,6 +213,11 @@ private void defaultResponseRules(Set<Integer> s) {
"Stage:ResponseList cannot be the only stage included in a response.",
new ChannelCodeRestriction(), new ChannelTypeRestriction()), Response.class);
}
if (!s.contains(406)) {
add(406, new InstrumentCodeUnitsCondition(true,
" IF Channel:Code[2] == (H | L | M | N) then Stage[1]:InputUnit must equal *m/s* AND Stage[Last]:OutputUnits must equal count* | Warning |"),
Response.class);
}
if (!s.contains(410)) {
add(410, new EmptySensitivityCondition(true, "If InstrumentSensitivity is included then InstrumentSensitivity:Value must be assigned a double > 0.0 ",
new ChannelCodeRestriction(), new ChannelTypeRestriction(), new ResponsePolynomialRestriction()),
Expand Down
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();
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ public void pass() throws Exception {

Network n = theDocument.getNetwork().get(0);
Station s = n.getStations().get(0);
Channel c = s.getChannels().get(0);


EpochRangeCondition condition = new EpochRangeCondition(true, "");
AzimuthDipCondition condition = new AzimuthDipCondition(true, "");

Message result = condition.evaluate(s);
Message result = condition.evaluate(c);
assertTrue(result instanceof edu.iris.dmc.station.rules.Success);
}

Expand Down
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);
}

}
}

Loading

0 comments on commit 34cb074

Please sign in to comment.