double minMagErr = Double.MAX_VALUE;
double maxMagErr = Double.MIN_VALUE;
for (BasicHDU hdu : hdus) {
if (hdu instanceof BinaryTableHDU) {
BinaryTableHDU tableHDU = (BinaryTableHDU) hdu;
for (int row = 0; row < tableHDU.getNRows()
&& !wasInterrupted(); row++) {
try {
int tmid = ((int[]) tableHDU.getElement(row, 0))[0];
float flux = ((float[]) tableHDU.getElement(row, 1))[0];
float fluxErr = ((float[]) tableHDU.getElement(row,
2))[0];
float tamFlux = ((float[]) tableHDU.getElement(row,
3))[0];
float tamFluxErr = ((float[]) tableHDU.getElement(
row, 4))[0];
String imageId = (String) tableHDU.getElement(row,
5);
short ccdX = ((short[]) tableHDU.getElement(row, 6))[0];
short ccdY = ((short[]) tableHDU.getElement(row, 7))[0];
// short flag = ((short[]) tableHDU.getElement(row,
// 8))[0];
if (flux > 1 && flux - fluxErr > 0) {
double hjd = tmid / 86400.0 + jdRef;
double mag = 15.0 - 2.5 * Math.log(flux)
/ Math.log(10.0);
double magErr = 1.086 * fluxErr / flux;
if (magErr < minMagErr) {
minMagErr = magErr;
} else if (magErr > maxMagErr) {
maxMagErr = magErr;
}
ValidObservation ob = new ValidObservation();
ob.setDateInfo(new DateInfo(hjd));
ob.setMagnitude(new Magnitude(mag, magErr));
ob.setBand(superWaspSeries);
ob.setRecordNumber(row);
ob.addDetail("IMAGE_ID", imageId, "Image ID");
ob.addDetail("CCDX", ccdX + "", "CCD X");
ob.addDetail("CCDY", ccdY + "", "CCD Y");
ob.addDetail("FLUX", tamFlux + "", "Flux");
ob.addDetail("FLUXERR", tamFluxErr + "",
"Flux Error");
// ob.addDetail("FLAG", flag + "", "Flag");
obs.add(ob);
}
} catch (Exception e) {
String input = tableHDU.getRow(row).toString();
String error = e.getLocalizedMessage();
InvalidObservation ob = new InvalidObservation(
input, error);
ob.setRecordNumber(row);
addInvalidObservation(ob);