- Timestamp:
- Jul 30, 2010, 9:31:50 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20100621/ippToPsps/src/ippToPspsBatchTest.c
r27809 r28794 13 13 #include "fitsio.h" 14 14 15 // Gets flux from magnitude 16 static __inline bool ippToPsps_getFlux(const float zeroPoint, const float exposureTime, const float magnitude, float* flux) { 17 18 // use uncalibrated instrumental flux 15 // Gets uncalibrated instrumental flux from magnitude 16 static __inline bool ippToPsps_getFlux(const float exposureTime, const float magnitude, float* flux, const float magnitudeErr, float* fluxErr) { 17 19 18 *flux = powf(10.0, -0.4*magnitude) / exposureTime; 20 21 // use calibrated flux in Janskys, where 3631 Jy is the zero point flux for the filter: constant over all filters because we're using AB magnitudes 22 //float flux = 3631 * powf(10.0, -0.4*(magnitude + zeroPoint)) / exposureTime; 23 24 // printf("mag=%f\texpTime=%f\tzeroPoint=%f\tflux=%f\n", magnitude, exposureTime, zeroPoint, flux); 25 return (!isfinite(*flux) || *flux < 0.000001) ? false : true; 19 if (!isfinite(*flux) || *flux < 0.000001) return false; 20 if (fluxErr) *fluxErr = fabsf((magnitudeErr * *flux)/1.085736); 21 // if (fluxErr) printf("Mag = %03.03f, Flux = %03.03f, Mag err = %03.03f, Flux Err = %03.03f\n", magnitude, *flux, magnitudeErr, *fluxErr); 22 23 return true; 26 24 } 27 25 … … 29 27 \brief test data for checking PSPS values correspond with IPP 30 28 31 */29 */ 32 30 int ippToPsps_batchTest(IppToPsps *this) { 33 31 … … 53 51 status=0; fits_read_key(fitsIn, TFLOAT, "EXPREQ", &exposureTime, NULL, &status); 54 52 status=0; fits_read_key(fitsIn, TSTRING, "FILTERID", filterType, NULL, &status); 55 56 ippToPspsConfig_writeTable(this->config, fitsIn, this->fitsOut, 1, "FrameMeta", true);53 54 // ippToPspsConfig_writeTable(this->config, fitsIn, this->fitsOut, 1, "FrameMeta", true); 57 55 58 56 // FrameMeta values 59 fits_write_col(this->fitsOut, TLONG, FRAMEMETA_FRAMEID, 1, 1, 1, &this->expId, &status);57 // fits_write_col(this->fitsOut, TLONG, FRAMEMETA_FRAMEID, 1, 1, 1, &this->expId, &status); 60 58 61 59 int8_t filterID = -1; 62 60 ippToPspsConfig_getFilterId(this->config, filterType, &filterID); 63 fits_write_col(this->fitsOut, TBYTE, FRAMEMETA_FILTERID, 1, 1, 1, &filterID, &status);61 // fits_write_col(this->fitsOut, TBYTE, FRAMEMETA_FILTERID, 1, 1, 1, &filterID, &status); 64 62 65 63 // stuff to keep from psf.hdr header … … 107 105 float instMagErr[MAXDETECT]; 108 106 float peakMag[MAXDETECT]; 107 uint64_t flags[MAXDETECT]; 109 108 long objID[MAXDETECT]; 110 109 long detectID[MAXDETECT]; … … 130 129 long maxObjID = LONG_MIN; 131 130 long minObjID = LONG_MAX; 131 uint64_t imageFlags; 132 132 short nOta = 0; 133 133 long i; … … 138 138 long removeList[MAXDETECT]; 139 139 long thisObjId; 140 bool firstTimeIn = true, peakFluxOk, instFluxOk; 141 int ippIDetNum, instMagNum, instMagErrNum, peakMagNum; 140 142 141 143 // loop round all 60 chips 142 for (int x= 3; x<4; x++) {143 for (int y= 3; y<4; y++) {144 for (int x=0; x<8; x++) { 145 for (int y=0; y<8; y++) { 144 146 145 147 // dodge the corners … … 194 196 195 197 // create ImageMeta 196 ippToPspsConfig_writeTable(this->config, fitsIn, this->fitsOut, 1, "ImageMeta", true);198 // ippToPspsConfig_writeTable(this->config, fitsIn, this->fitsOut, 1, "ImageMeta", true); 197 199 psfFwhm = (fwhmMaj+fwhmMin)/2; 198 200 momentFwhm = (momentMaj+momentMin)/2; 199 fits_write_col(this->fitsOut, TLONG, IMAGEMETA_PHOTOCALID, 1, 1, 1, &pImage->photcode, &status); 200 fits_write_col(this->fitsOut, TBYTE, IMAGEMETA_FILTERID, 1, 1, 1, &filterID, &status); 201 fits_write_col(this->fitsOut, TFLOAT, IMAGEMETA_PHOTOSCAT, 1, 1, 1, &zptObs, &status); 202 fits_write_col(this->fitsOut, TFLOAT, IMAGEMETA_PSFFWHM, 1, 1, 1, &psfFwhm, &status); 203 fits_write_col(this->fitsOut, TFLOAT, IMAGEMETA_PHOTOZERO, 1, 1, 1, &zptObs, &status); 201 imageFlags = (uint64_t)pImage->flags; 202 // fits_write_col(this->fitsOut, TLONG, IMAGEMETA_PHOTOCALID, 1, 1, 1, &pImage->photcode, &status); 203 // fits_write_col(this->fitsOut, TBYTE, IMAGEMETA_FILTERID, 1, 1, 1, &filterID, &status); 204 // fits_write_col(this->fitsOut, TFLOAT, IMAGEMETA_PHOTOSCAT, 1, 1, 1, &zptObs, &status); 205 // fits_write_col(this->fitsOut, TFLOAT, IMAGEMETA_PSFFWHM, 1, 1, 1, &psfFwhm, &status); 206 // fits_write_col(this->fitsOut, TFLOAT, IMAGEMETA_PHOTOZERO, 1, 1, 1, &zptObs, &status); 207 // fits_write_col(this->fitsOut, TLONGLONG, IMAGEMETA_QAFLAGS, 1, 1, 1, &imageFlags, &status); 204 208 205 209 // now move BACK to detections table in smf … … 222 226 s = d = totalDetections = invalidDvoRows = smfJumps = unmatched = 0; 223 227 228 // determine column numbers for certain IPP detection columns 229 if (firstTimeIn) { 230 231 status=0;fits_get_colnum(fitsIn, CASESEN, "IPP_IDET", &ippIDetNum, &status); 232 if (status) psError(PS_ERR_IO, false, "Unable to read col num for IPP_IDET"); 233 status=0;fits_get_colnum(fitsIn, CASESEN, "PSF_INST_MAG", &instMagNum, &status); 234 if (status) psError(PS_ERR_IO, false, "Unable to read col num for PSF_INST_MAG"); 235 status=0;fits_get_colnum(fitsIn, CASESEN, "PSF_INST_MAG_SIG", &instMagErrNum, &status); 236 if (status) psError(PS_ERR_IO, false, "Unable to read col num for PSF_INST_MAG_SIG"); 237 status=0;fits_get_colnum(fitsIn, CASESEN, "PEAK_FLUX_AS_MAG", &peakMagNum, &status); 238 if (status) psError(PS_ERR_IO, false, "Unable to read col num for PEAK_FLUX_AS_MAG"); 239 240 firstTimeIn=false; 241 } 242 224 243 anynull = 0; 225 fits_read_col(fitsIn, TLONG, 1, 1, 1, nDet, &longnull, ippIDet, &anynull, &status);226 fits_read_col(fitsIn, TFLOAT, 8, 1, 1, nDet, &floatnull, instMag, &anynull, &status);227 fits_read_col(fitsIn, TFLOAT, 9, 1, 1, nDet, &floatnull, instMagErr, &anynull, &status);228 fits_read_col(fitsIn, TFLOAT, 12, 1, 1, nDet, &floatnull, peakMag, &anynull, &status);244 fits_read_col(fitsIn, TLONG, ippIDetNum, 1, 1, nDet, &longnull, ippIDet, &anynull, &status); 245 fits_read_col(fitsIn, TFLOAT, instMagNum, 1, 1, nDet, &floatnull, instMag, &anynull, &status); 246 fits_read_col(fitsIn, TFLOAT, instMagErrNum, 1, 1, nDet, &floatnull, instMagErr, &anynull, &status); 247 fits_read_col(fitsIn, TFLOAT, peakMagNum, 1, 1, nDet, &floatnull, peakMag, &anynull, &status); 229 248 230 249 // DVO detections are ordered by IPP_IDET, which increments from 0 in SMF table … … 262 281 ippObjID[s] = (uint64_t)dvoDetections[d].ave.catID*1000000000 + (uint64_t)dvoDetections[d].ave.objID; 263 282 ippDetectID[s] = dvoDetections[d].meas.detID; 283 flags[s] = ((uint64_t)dvoDetections[d].meas.dbFlags << 32) | (uint64_t)dvoDetections[d].meas.photFlags; 264 284 imageID[s] = pspsImageId; 265 285 obsTimes[s] = obsTime; 266 286 267 ippToPsps_getFlux(zeroPoint, exposureTime, instMagErr[s], &instFluxErr[s]); 287 peakFluxOk = ippToPsps_getFlux(exposureTime, peakMag[s], &peakFlux[s], 0.0, NULL); 288 instFluxOk = ippToPsps_getFlux(exposureTime, instMag[s], &instFlux[s], instMagErr[s], &instFluxErr[s]); 268 289 269 290 // check for invalid flux values (if not already labelled as a duplicate) 270 if ((!ippToPsps_getFlux(zeroPoint, exposureTime, peakMag[s], &peakFlux[s]) || 271 !ippToPsps_getFlux(zeroPoint, exposureTime, instMag[s], &instFlux[s])) && !isDuplicate) { 291 if ( (!peakFluxOk || !instFluxOk) && !isDuplicate) { 272 292 removeList[numOfDuplicates+numInvalidFlux] = s+1; 273 293 numInvalidFlux++; … … 292 312 // write number of rows (detections) to ImageMeta 293 313 numDetectionsOut = totalDetections - numOfDuplicates - numInvalidFlux; 294 fits_write_col(this->fitsOut, TLONG, IMAGEMETA_NDETECT, 1, 1, 1, &numDetectionsOut, &status);314 // fits_write_col(this->fitsOut, TLONG, IMAGEMETA_NDETECT, 1, 1, 1, &numDetectionsOut, &status); 295 315 296 316 // detections … … 301 321 fits_write_col(this->fitsOut, TLONGLONG, DETECTION_IPPDETECTID, 1, 1, nDet, ippDetectID, &status); 302 322 fits_write_col(this->fitsOut, TBYTE, DETECTION_FILTERID, 1, 1, nDet, filterIDs, &status); 323 fits_write_col(this->fitsOut, TLONGLONG, DETECTION_IMAGEID, 1, 1, nDet, imageID, &status); 303 324 fits_write_col(this->fitsOut, TFLOAT, DETECTION_INSTFLUX, 1, 1, nDet, instFlux, &status); 304 fits_write_col(this->fitsOut, TFLOAT, DETECTION_INSTFLUXERR, 1, 1, nDet, instFluxErr, &status); 305 fits_write_col(this->fitsOut, TFLOAT, DETECTION_PEAKADU, 1, 1, nDet, peakFlux, &status); 325 //fits_write_col(this->fitsOut, TFLOAT, DETECTION_INSTFLUXERR, 1, 1, nDet, instFluxErr, &status); 326 //fits_write_col(this->fitsOut, TFLOAT, DETECTION_PEAKADU, 1, 1, nDet, peakFlux, &status); 327 fits_write_col(this->fitsOut, TLONGLONG, DETECTION_INFOFLAG, 1, 1, nDet, flags, &status); 306 328 if (numOfDuplicates||numInvalidFlux) fits_delete_rowlist(this->fitsOut, removeList, numOfDuplicates+numInvalidFlux, &status); 307 329 … … 323 345 // write number of images we have found into FrameMeta table 324 346 status=0; 325 if (fits_movnam_hdu(this->fitsOut, BINARY_TBL, "FrameMeta", 0, &status))326 psError(PS_ERR_IO, false, "Can't move back to FrameMeta extension to write number of OTAs\n");327 else328 fits_write_col(this->fitsOut, TSHORT, FRAMEMETA_NOTA, 1, 1, 1, &nOta, &status);347 //if (fits_movnam_hdu(this->fitsOut, BINARY_TBL, "FrameMeta", 0, &status)) 348 // psError(PS_ERR_IO, false, "Can't move back to FrameMeta extension to write number of OTAs\n"); 349 //else 350 // fits_write_col(this->fitsOut, TSHORT, FRAMEMETA_NOTA, 1, 1, 1, &nOta, &status); 329 351 330 352 status=0; 331 353 if (fits_close_file(fitsIn, &status)) fits_report_error(stderr, status); 332 354 333 // write results334 if (this->resultsFile) {335 336 if (fprintf(this->resultsFile, "%ld\n", minObjID) < 1 )337 psError(PS_ERR_IO, false, "Unable to write min Object ID to'%s'\n", this->resultsPath);338 if (fprintf(this->resultsFile, "%ld\n", maxObjID) < 1 )339 psError(PS_ERR_IO, false, "Unable to write max Object ID to'%s'\n", this->resultsPath);340 }341 342 355 psLogMsg("ippToPsps", PS_LOG_INFO, "Data written for a total of %d chips/OTAs", nOta); 343 356
Note:
See TracChangeset
for help on using the changeset viewer.
