From 34cb074f4ba0d1567b50c04a74419a352d74b221 Mon Sep 17 00:00:00 2001 From: timronan Date: Fri, 10 Apr 2020 12:17:24 -0700 Subject: [PATCH] Add condition that compares instrument code to input and output units. Addresses issue #96. --- .../iris/dmc/station/RuleEngineRegistry.java | 8 +- .../InstrumentCodeUnitsCondition.java | 85 +++ .../station/conditions/Condition320Test.java | 6 +- .../station/conditions/Condition406Test.java | 65 ++ src/test/resources/F1_406.xml | 623 ++++++++++++++++++ 5 files changed, 784 insertions(+), 3 deletions(-) create mode 100644 src/main/java/edu/iris/dmc/station/conditions/InstrumentCodeUnitsCondition.java create mode 100644 src/test/java/edu/iris/dmc/station/conditions/Condition406Test.java create mode 100644 src/test/resources/F1_406.xml diff --git a/src/main/java/edu/iris/dmc/station/RuleEngineRegistry.java b/src/main/java/edu/iris/dmc/station/RuleEngineRegistry.java index d08e0f8..ddca823 100644 --- a/src/main/java/edu/iris/dmc/station/RuleEngineRegistry.java +++ b/src/main/java/edu/iris/dmc/station/RuleEngineRegistry.java @@ -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; @@ -116,7 +117,7 @@ private void defaultStationRules(Set 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); } @@ -212,6 +213,11 @@ private void defaultResponseRules(Set 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()), diff --git a/src/main/java/edu/iris/dmc/station/conditions/InstrumentCodeUnitsCondition.java b/src/main/java/edu/iris/dmc/station/conditions/InstrumentCodeUnitsCondition.java new file mode 100644 index 0000000..8cf82d7 --- /dev/null +++ b/src/main/java/edu/iris/dmc/station/conditions/InstrumentCodeUnitsCondition.java @@ -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(); + } + +} + + diff --git a/src/test/java/edu/iris/dmc/station/conditions/Condition320Test.java b/src/test/java/edu/iris/dmc/station/conditions/Condition320Test.java index 7ee973f..1063eb0 100644 --- a/src/test/java/edu/iris/dmc/station/conditions/Condition320Test.java +++ b/src/test/java/edu/iris/dmc/station/conditions/Condition320Test.java @@ -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); } diff --git a/src/test/java/edu/iris/dmc/station/conditions/Condition406Test.java b/src/test/java/edu/iris/dmc/station/conditions/Condition406Test.java new file mode 100644 index 0000000..5d89a1a --- /dev/null +++ b/src/test/java/edu/iris/dmc/station/conditions/Condition406Test.java @@ -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); + } + + } +} + diff --git a/src/test/resources/F1_406.xml b/src/test/resources/F1_406.xml new file mode 100644 index 0000000..a003a25 --- /dev/null +++ b/src/test/resources/F1_406.xml @@ -0,0 +1,623 @@ + + + + IRIS-DMC + IRIS-DMC + IRIS WEB SERVICE: fdsnws-station | version: 1.1.33 + http://service.iris.edu/fdsnws/station/1/query?net=QI&sta=VPASS&cha=BDF&starttime=2018-08-06T00:00:01&level=response&format=xml&includecomments=true&nodata=404 + 2018-08-06T20:17:16 + + [IRIS DMC] Station XML Validator Passing Test File + 1 + 1 + + 47.66157 + -122.31332 + 225.879999 + + Synthetic Test File, IRIS DMC, USA, 218 2018, Tim Ronan + + 2018-08-06T00:00:00 + 1 + 1 + + 47.66157 + -122.31332 + 225.879999 + 0 + 0 + CONTINUOUS + GEOPHYSICAL + 2E01 + 0E00 + + V + Volts + + + GEM (Infrasound), 0.2-50 Hz, 0.4 V/Pa-null + + + + 2.44648E5 + 1E0 + + PA + No Abbreviation Referenced + + + COUNTS + Digital Counts + + + + + + PA + No Abbreviation Referenced + + + V + Volts + + LAPLACE (RADIANS/SECOND) + 314.1 + 1.00000 + + 0.00000 + 0.00000 + + + 0.00000 + 0.00000 + + + -0.170000 + 0.00000 + + + 0.00000 + 0.00000 + + + -314.000 + 0.00000 + + + -0.188000 + 0.00000 + + + -0.0440000 + 0.00000 + + + + 0.4 + 1.0 + + + + + 1.0 + 1.0 + + + + + + V + Volts + + + COUNTS + Digital Counts + + DIGITAL + 1.00000 + + + 512000.0 + 1 + 0 + 0.0 + 0.0 + + + 611621.0 + 1.0 + + + + + + COUNTS + Digital Counts + + + COUNTS + Digital Counts + + DIGITAL + 0.0000305176 + 0.000152588 + 0.000457764 + 0.00106812 + 0.00213623 + 0.00384521 + 0.00640869 + 0.0100708 + 0.0149536 + 0.0210571 + 0.0282593 + 0.0363159 + 0.0448608 + 0.0534058 + 0.0613403 + 0.0679321 + 0.0726318 + 0.0750732 + 0.0750732 + 0.0726318 + 0.0679321 + 0.0613403 + 0.0534058 + 0.0448608 + 0.0363159 + 0.0282593 + 0.0210571 + 0.0149536 + 0.0100708 + 0.00640869 + 0.00384521 + 0.00213623 + 0.00106812 + 0.000457764 + 0.000152588 + 0.0000305176 + + + 512000.0 + 8 + 0 + 3.418E-5 + 3.418E-5 + + + 1.0 + 1.0 + + + + + + COUNTS + Digital Counts + + + COUNTS + Digital Counts + + DIGITAL + 0.0312500 + 0.156250 + 0.312500 + 0.312500 + 0.156250 + 0.0312500 + + + 64000.0 + 2 + 0 + 3.9063E-5 + 3.9063E-5 + + + 1.0 + 1.0 + + + + + + COUNTS + Digital Counts + + + COUNTS + Digital Counts + + DIGITAL + 0.0156250 + 0.0937500 + 0.234375 + 0.312500 + 0.234375 + 0.0937500 + 0.0156250 + + + 32000.0 + 2 + 0 + 9.375E-5 + 9.375E-5 + + + 1.0 + 1.0 + + + + + + COUNTS + Digital Counts + + + COUNTS + Digital Counts + + DIGITAL + 0.00160000 + 0.00640000 + 0.0160000 + 0.0320000 + 0.0560000 + 0.0832000 + 0.108800 + 0.128000 + 0.136000 + 0.128000 + 0.108800 + 0.0832000 + 0.0560000 + 0.0320000 + 0.0160000 + 0.00640000 + 0.00160000 + + + 16000.0 + 5 + 0 + 5.0E-4 + 5.0E-4 + + + 1.0 + 1.0 + + + + + + COUNTS + Digital Counts + + + COUNTS + Digital Counts + + DIGITAL + 0.00160000 + 0.00640000 + 0.0160000 + 0.0320000 + 0.0560000 + 0.0832000 + 0.108800 + 0.128000 + 0.136000 + 0.128000 + 0.108800 + 0.0832000 + 0.0560000 + 0.0320000 + 0.0160000 + 0.00640000 + 0.00160000 + + + 3200.0 + 5 + 0 + 0.0025 + 0.0025 + + + 1.0 + 1.0 + + + + + + COUNTS + Digital Counts + + + COUNTS + Digital Counts + + DIGITAL + 0.0312500 + 0.156250 + 0.312500 + 0.312500 + 0.156250 + 0.0312500 + + + 640.0 + 2 + 0 + 0.0039062 + 0.0039062 + + + 1.0 + 1.0 + + + + + + COUNTS + Digital Counts + + + COUNTS + Digital Counts + + DIGITAL + 0.0156250 + 0.0937500 + 0.234375 + 0.312500 + 0.234375 + 0.0937500 + 0.0156250 + + + 320.0 + 2 + 0 + 0.009375 + 0.009375 + + + 1.0 + 1.0 + + + + + + COUNTS + Digital Counts + + + COUNTS + Digital Counts + + DIGITAL + 0.0000142825 + 0.0000487602 + 0.0000981347 + 0.000131000 + 0.00000934250 + -0.000371601 + -0.00101838 + -0.00172427 + -0.00178938 + -0.000497840 + 0.00249391 + 0.00662629 + 0.00961284 + 0.00850723 + 0.00102035 + -0.0127048 + -0.0277493 + -0.0356507 + -0.0269602 + 0.00484878 + 0.0580113 + 0.122066 + 0.180265 + 0.214714 + 0.214714 + 0.180265 + 0.122066 + 0.0580113 + 0.00484878 + -0.0269602 + -0.0356507 + -0.0277493 + -0.0127048 + 0.00102035 + 0.00850723 + 0.00961284 + 0.00662629 + 0.00249391 + -0.000497840 + -0.00178938 + -0.00172427 + -0.00101838 + -0.000371601 + 0.00000934250 + 0.000131000 + 0.0000981347 + 0.0000487602 + 0.0000142825 + + + 160.0 + 4 + 0 + 0.14688 + 0.14688 + + + 1.0 + 1.0 + + + + + + COUNTS + Digital Counts + + + m/s + Digital Counts + + DIGITAL + 0.00000 + -0.00000341752 + -0.0000178578 + -0.0000418767 + -0.0000474602 + 0.00000163656 + 0.0000859675 + 0.000110275 + 0.0000140070 + -0.0000980010 + -0.0000453905 + 0.000143680 + 0.000182139 + -0.0000701795 + -0.000279563 + -0.0000484710 + 0.000373328 + 0.000285676 + -0.000343437 + -0.000562736 + 0.000169962 + 0.000842347 + 0.000211212 + -0.000994499 + -0.000768220 + 0.000911179 + 0.00143478 + -0.000471474 + -0.00204921 + -0.000372799 + 0.00240642 + 0.00158944 + -0.00226673 + -0.00301565 + 0.00142968 + 0.00436788 + 0.000213523 + -0.00525571 + -0.00260752 + 0.00524705 + 0.00549470 + -0.00394666 + -0.00839709 + 0.00109986 + 0.0106478 + 0.00331466 + -0.0114571 + -0.00900786 + 0.0100128 + 0.0153434 + -0.00558380 + -0.0213365 + -0.00240468 + 0.0256716 + 0.0143909 + -0.0266602 + -0.0309250 + 0.0219005 + 0.0536113 + -0.00660299 + -0.0892570 + -0.0368818 + 0.186535 + 0.403778 + 0.403778 + 0.186535 + -0.0368818 + -0.0892570 + -0.00660299 + 0.0536113 + 0.0219005 + -0.0309250 + -0.0266602 + 0.0143909 + 0.0256716 + -0.00240468 + -0.0213365 + -0.00558380 + 0.0153434 + 0.0100128 + -0.00900786 + -0.0114571 + 0.00331466 + 0.0106478 + 0.00109986 + -0.00839709 + -0.00394666 + 0.00549470 + 0.00524705 + -0.00260752 + -0.00525571 + 0.000213523 + 0.00436788 + 0.00142968 + -0.00301565 + -0.00226673 + 0.00158944 + 0.00240642 + -0.000372799 + -0.00204921 + -0.000471474 + 0.00143478 + 0.000911179 + -0.000768220 + -0.000994499 + 0.000211212 + 0.000842347 + 0.000169962 + -0.000562736 + -0.000343437 + 0.000285676 + 0.000373328 + -0.0000484710 + -0.000279563 + -0.0000701795 + 0.000182139 + 0.000143680 + -0.0000453905 + -0.0000980010 + 0.0000140070 + 0.000110275 + 0.0000859675 + 0.00000163656 + -0.0000474602 + -0.0000418767 + -0.0000178578 + -0.00000341752 + 0.00000 + + + 40.0 + 2 + 0 + 1.5875 + 1.5875 + + + 1.0 + 1.0 + + + + + + +