Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions plugin/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,7 @@

<test name="${testcase}" todir="${test_report}" if="testcase" />

<batchtest todir="${test_report}" unless="testcase">
<fileset dir="${test_build}">
<include name="**/PluginTest.class" />
</fileset>
</batchtest>
<test name="org.aavso.tools.vstar.external.plugin.AllTests" todir="${test_report}" unless="testcase" />

<classpath refid="test.classpath" />
</junit>
Expand Down Expand Up @@ -199,11 +195,7 @@

<jvmarg value="-ea" />

<batchtest todir="${test_report}" unless="testcase">
<fileset dir="${test_build}">
<include name="**/PluginTest.class" />
</fileset>
</batchtest>
<test name="org.aavso.tools.vstar.external.plugin.AllTests" todir="${test_report}" unless="testcase" />

<classpath refid="test.classpath" />
</junit>
Expand Down
83 changes: 83 additions & 0 deletions plugin/src/org/aavso/tools/vstar/external/lib/FitsTestData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* VStar: a statistical analysis tool for variable star data.
* Copyright (C) 2009 AAVSO (http://www.aavso.org/)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.aavso.tools.vstar.external.lib;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import nom.tam.fits.BinaryTableHDU;
import nom.tam.fits.Fits;
import nom.tam.fits.FitsException;
import nom.tam.fits.ImageHDU;

/**
* Builds minimal in-memory FITS files for plugin self-tests.
*/
public final class FitsTestData {

private FitsTestData() {
}

/**
* Lightkurve-style FITS with Kepler telescope metadata and one valid row.
*/
public static byte[] createLightKurveKeplerFits() throws FitsException, IOException {
return createFits("Kepler", new String[] { "TIME", "FLUX", "FLUX_ERR" },
new Object[] { new double[] { 0.5 }, new float[] { 1000f }, new float[] { 10f } },
null, null);
}

/**
* Kepler/TESS archive-style FITS with PDCSAP columns (corrected flux).
*/
public static byte[] createKeplerArchiveFits() throws FitsException, IOException {
String[] names = { "TIME", "COL1", "COL2", "SAP_FLUX", "SAP_FLUX_ERR", "COL5", "COL6",
"PDCSAP_FLUX", "PDCSAP_FLUX_ERR", "QUALITY" };
Object[] cols = { new double[] { 0.5 }, new float[] { 0f }, new float[] { 0f },
new float[] { 1000f }, new float[] { 10f }, new float[] { 0f }, new float[] { 0f },
new float[] { 1000f }, new float[] { 10f }, new int[] { 0 } };
return createFits("Kepler", names, cols, 2454833, 0.0);
}

private static byte[] createFits(String telescope, String[] columnNames, Object[] columns,
Integer bjdRefInt, Double bjdRefFrac) throws FitsException, IOException {
Fits fits = new Fits();

nom.tam.fits.Data imageData = ImageHDU.encapsulate(new double[1][1]);
ImageHDU image = new ImageHDU(ImageHDU.manufactureHeader(imageData), imageData);
image.getHeader().addValue("TELESCOP", telescope, "");
image.getHeader().addValue("OBJECT", "TEST", "");
fits.addHDU(image);

nom.tam.fits.Data tableData = BinaryTableHDU.encapsulate(columns);
BinaryTableHDU table = new BinaryTableHDU(BinaryTableHDU.manufactureHeader(tableData), tableData);
for (int i = 0; i < columnNames.length; i++) {
table.setColumnName(i, columnNames[i], "");
}
if (bjdRefInt != null && bjdRefFrac != null) {
table.getHeader().addValue("BJDREFI", bjdRefInt.longValue(), "");
table.getHeader().addValue("BJDREFF", bjdRefFrac.doubleValue(), "");
}
fits.addHDU(table);

ByteArrayOutputStream out = new ByteArrayOutputStream();
fits.write(new DataOutputStream(out));
return out.toByteArray();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@

import java.awt.Color;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -56,6 +58,7 @@
import org.aavso.tools.vstar.exception.ObservationValidationError;
import org.aavso.tools.vstar.input.AbstractObservationRetriever;
import org.aavso.tools.vstar.plugin.ObservationSourcePluginBase;
import org.aavso.tools.vstar.util.Tolerance;

public abstract class GaiaObSourceBase extends ObservationSourcePluginBase {

Expand Down Expand Up @@ -782,4 +785,75 @@ public String getSourceType() {
}
}

@Override
public Boolean test() {
setTestMode(true);
paramIgnoreFlags = true;
paramGaiaRelease = GaiaRelease.DR2;

boolean success = true;
try {
success &= runGaiaFileTest(false);
success &= runGaiaFileTest(true);
} catch (Exception e) {
success = false;
} finally {
setTestMode(false);
}
return success;
}

private boolean runGaiaFileTest(boolean transform) throws Exception {
paramTransform = transform;

String header = "source_id,transit_id,band,time,mag,flux,flux_error,flux_over_error,rejected_by_photometry,rejected_by_variability,other_flags,solution_id\n";
String[] lines;
if (transform) {
lines = new String[] {
header,
"1951343009975999744,1,BP,1000.0,11.0,1000.0,10.0,,FALSE,FALSE,0,1\n",
"1951343009975999744,1,G,1000.0,10.0,1000.0,10.0,,FALSE,FALSE,0,1\n",
"1951343009975999744,1,RP,1000.0,12.0,1000.0,10.0,,FALSE,FALSE,0,1\n" };
} else {
lines = new String[] {
header,
"1951343009975999744,1,G,1000.0,10.0,1000.0,10.0,,FALSE,FALSE,0,1\n" };
}

StringBuffer content = new StringBuffer();
for (String line : lines) {
content.append(line);
}
InputStream in = new ByteArrayInputStream(content.toString().getBytes());
List<InputStream> streams = new ArrayList<InputStream>();
streams.add(in);
setInputInfo(streams, "Gaia test");

GAIADR2FormatRetriever retriever = new GAIADR2FormatRetriever(transform, true, GaiaRelease.DR2);
retriever.getNumberOfRecords();
retriever.retrieveObservations();

List<ValidObservation> gaiaObs = retriever.getValidObservations();
if (!transform) {
boolean success = 1 == gaiaObs.size();
ValidObservation ob = gaiaObs.get(0);
success &= gaiaGseries == ob.getBand();
success &= Tolerance.areClose(2456197.5, ob.getJD(), 1e-6, true);
success &= Tolerance.areClose(10.0, ob.getMag(), 1e-6, true);
success &= "GaiaDR2 1951343009975999744".equals(ob.getName());
success &= JDflavour.BJD == ob.getJDflavour();
return success;
}

boolean success = 3 == gaiaObs.size();
success &= SeriesType.Johnson_V == gaiaObs.get(0).getBand();
success &= SeriesType.Cousins_R == gaiaObs.get(1).getBand();
success &= SeriesType.Cousins_I == gaiaObs.get(2).getBand();
for (ValidObservation ob : gaiaObs) {
success &= ob.isTransformed();
success &= Tolerance.areClose(2456197.5, ob.getJD(), 1e-6, true);
}
return success;
}

}
49 changes: 49 additions & 0 deletions plugin/src/org/aavso/tools/vstar/external/lib/ZTFObSourceBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@

import java.awt.Color;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Locale;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -42,6 +45,7 @@
import org.aavso.tools.vstar.exception.ObservationValidationError;
import org.aavso.tools.vstar.input.AbstractObservationRetriever;
import org.aavso.tools.vstar.plugin.ObservationSourcePluginBase;
import org.aavso.tools.vstar.util.Tolerance;

/**
*
Expand Down Expand Up @@ -321,4 +325,49 @@ public String getSourceType() {
}
}

@Override
public Boolean test() {
setTestMode(true);

String[] lines = {
"oid\thjd\tmag\tmagerr\tcatflags\tfiltercode\texptime\tairmass\n",
"12345\t2458000.5\t12.5\t0.01\t0\tzg\t30\t1.2\n" };

boolean success = true;

try {
StringBuffer content = new StringBuffer();
for (String line : lines) {
content.append(line);
}
InputStream in = new ByteArrayInputStream(content.toString().getBytes());
List<InputStream> streams = new ArrayList<InputStream>();
streams.add(in);
setInputInfo(streams, "ZTF test");

ZTFFormatRetriever retriever = new ZTFFormatRetriever();
retriever.getNumberOfRecords();
retriever.retrieveObservations();

List<ValidObservation> ztfObs = retriever.getValidObservations();
success &= 1 == ztfObs.size();

ValidObservation ob = ztfObs.get(0);
success &= "12345".equals(ob.getName());
success &= Tolerance.areClose(2458000.5, ob.getJD(), 1e-6, true);
success &= Tolerance.areClose(12.5, ob.getMag(), 1e-6, true);
success &= Tolerance.areClose(0.01, ob.getMagnitude().getUncertainty(), 1e-6, true);
success &= ztfgSeries == ob.getBand();
success &= JDflavour.HJD == ob.getJDflavour();
success &= String.format(Locale.ENGLISH, "ZTF object %s", "12345")
.equals(retriever.getSourceName());
} catch (Exception e) {
success = false;
} finally {
setTestMode(false);
}

return success;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -884,4 +884,42 @@ private boolean isNullOrEmpty(String s) {
}

}

@Override
public Boolean test() {
setTestMode(true);
String[] lines = {
"#FIELDS=time,mag,magerr\n",
"#DELIM=comma\n",
"#DATE=JD\n",
"2450000,5.0,0.01\n" };

boolean success = true;
try {
StringBuffer content = new StringBuffer();
for (String line : lines) {
content.append(line);
}
java.io.InputStream in = new java.io.ByteArrayInputStream(content.toString().getBytes());
java.util.List<java.io.InputStream> streams = new java.util.ArrayList<java.io.InputStream>();
streams.add(in);
setInputInfo(streams, "flex test");

AbstractObservationRetriever retriever = getObservationRetriever();
retriever.getNumberOfRecords();
retriever.retrieveObservations();

success &= 1 == retriever.getValidObservations().size();
ValidObservation ob = retriever.getValidObservations().get(0);
success &= 2450000 == ob.getJD();
success &= 5.0 == ob.getMag();
success &= 0.01 == ob.getMagnitude().getUncertainty();
success &= JDflavour.JD == ob.getJDflavour();
} catch (Exception e) {
success = false;
} finally {
setTestMode(false);
}
return success;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.aavso.tools.vstar.input.AbstractObservationRetriever;
import org.aavso.tools.vstar.plugin.InputType;
import org.aavso.tools.vstar.plugin.ObservationSourcePluginBase;
import org.aavso.tools.vstar.util.Tolerance;
//12/02/2018 C. Kotnik added name to observations so they can be
//saved and reloaded from a file.
/**
Expand Down Expand Up @@ -209,4 +210,24 @@ private String getNextLine(BufferedReader reader, int lineNum) {
return line;
}
}

@Override
public Boolean test() {
setTestMode(true);
try {
String[] lines = { "JD\n", "10000|10.0|0|0\n" };
AbstractObservationRetriever retriever = getTestRetriever(lines, "HIP test");
if (retriever.getValidObservations().size() != 1) {
return false;
}
ValidObservation ob = retriever.getValidObservations().get(0);
// Epoch field is HT1-style offset: sample 10000 -> BJD 2450000 with this reader
return Tolerance.areClose(2450000.0, ob.getJD(), 1e-6, true)
&& Tolerance.areClose(10.0, ob.getMag(), 1e-6, true);
} catch (Exception e) {
return false;
} finally {
setTestMode(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
*/
package org.aavso.tools.vstar.external.plugin;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;

import org.aavso.tools.vstar.data.Magnitude;
import org.aavso.tools.vstar.data.ValidObservation;
import org.aavso.tools.vstar.data.ValidObservation.JDflavour;
import org.aavso.tools.vstar.plugin.CustomFilterPluginBase;
Expand Down Expand Up @@ -55,4 +58,34 @@ public String getDocName() {
return "https://github.com/AAVSO/VStar/wiki/Custom-Filter-Plug%E2%80%90ins#julian-date-observations-filter";
}

@Override
public Boolean test() {
setTestMode(true);

List<ValidObservation> obs = new ArrayList<ValidObservation>();

ValidObservation jdOb = new ValidObservation();
jdOb.setJD(2450000);
jdOb.setMagnitude(new Magnitude(5, 0));
jdOb.setJDflavour(JDflavour.JD);
obs.add(jdOb);

ValidObservation bjdOb = new ValidObservation();
bjdOb.setJD(2450001);
bjdOb.setMagnitude(new Magnitude(6, 0));
bjdOb.setJDflavour(JDflavour.BJD);
obs.add(bjdOb);

filteredObs = new LinkedHashSet<ValidObservation>();
Pair<String, String> idPair = filter(obs);

boolean success = filteredObs.size() == 1;
success &= filteredObs.contains(jdOb);
success &= "Julian Date Observations".equals(idPair.first);
success &= "Julian Date Observations".equals(idPair.second);

setTestMode(false);
return success;
}

}
Loading
Loading