Skip to content

Commit

Permalink
Add a test to verify coefficient mapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
timronan committed Feb 12, 2020
1 parent ce83f96 commit b731efd
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions src/test/java/edu/iris/dmc/station/mapper/CoefficientsMapperTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package edu.iris.dmc.station.mapper;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.EOFException;
import java.io.File;
import java.math.BigDecimal;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

import org.junit.Test;

import edu.iris.dmc.IrisUtil;
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.Response;
import edu.iris.dmc.fdsn.station.model.Station;
import edu.iris.dmc.seed.BlocketteFactory;
import edu.iris.dmc.seed.Volume;
import edu.iris.dmc.seed.control.station.B050;
import edu.iris.dmc.seed.control.station.B052;
import edu.iris.dmc.seed.control.station.B053;
import edu.iris.dmc.seed.control.station.B054;
import edu.iris.dmc.station.converter.SeedToXmlDocumentConverter;
import edu.iris.dmc.station.converter.XmlToSeedDocumentConverterTest;

public class CoefficientsMapperTest {


@SuppressWarnings("null")
@Test
public void normilization_frequency() throws Exception {
File source = new File(
XmlToSeedDocumentConverterTest.class.getClassLoader().getResource("UW.LON.dataless.20200204125001").getFile());

Volume original = IrisUtil.readSeed(source);
B054 coeff = null;
B050 datasta = original.getB050s().get(0);
List <B052> datachan = datasta.getB052s();
try {
for (int i2=0; i2 < datachan.size(); i2++) {
// if(datachan.get(i2).getResponseStages().get(0).getBlockettes().get(0)==null) {

//}else {
// pzlist.add(i2, (B053) datachan.get(i2).getResponseStages().get(0).getBlockettes().get(0));
// }
if(datachan.get(i2).getChannelCode().matches("SNE")) {
coeff = (B054) datachan.get(i2).getResponseStages().get(2).getBlockettes().get(0);
System.out.println(coeff.getNumerators());
}
}

}catch (Exception e) {
/* This is a generic Exception handler which means it can handle
* all the exceptions. This will execute if the exception is not
* handled by previous catch blocks.
*/
System.out.println("Exception occurred first loop");
}
FDSNStationXML document = SeedToXmlDocumentConverter.getInstance().convert(original);



JAXBContext jContext = JAXBContext.newInstance(FDSNStationXML.class);
//creating the marshaller object
Marshaller marshallObj = jContext.createMarshaller();
//setting the property to show xml format output
marshallObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

Network net = document.getNetwork().get(0);
Station sta = net.getStations().get(0);
Response res = null;

///TODO FInd the null pointer and remove it.
List<Channel> cha = sta.getChannels();
System.out.println(cha.size());
int n=0;
try {
for (int i=0; i < cha.size(); i++) {
if(cha.get(i).getCode().matches("SNE")) {
res = cha.get(i).getResponse();

}
}
}catch (Exception e) {
/* This is a generic Exception handler which means it can handle
* all the exceptions. This will execute if the exception is not
* handled by previous catch blocks.
*/
System.out.println("Exception occurred second loop");
}
//assertEquals(res.getStage().get(1).getCoefficients().getDenominator().get(0).getValue(), coeff.getDenominators().get(0).getValue(), 0.1);
assertEquals(res.getStage().get(2).getCoefficients().getNumerator().get(0).getValue(), coeff.getNumerators().get(0).getValue(), 0.0001);
assertEquals(res.getStage().get(2).getCoefficients().getNumerator().get(0).getPlusError(), coeff.getNumerators().get(0).getError(), 0.00001);


}
}

0 comments on commit b731efd

Please sign in to comment.