Changeset 31083 for branches/eam_branches/ipp-20110213/ippToPsps/src
- Timestamp:
- Mar 30, 2011, 9:36:02 AM (15 years ago)
- Location:
- branches/eam_branches/ipp-20110213/ippToPsps/src
- Files:
-
- 2 deleted
- 10 edited
- 8 copied
-
. (modified) (1 prop)
-
Batch.c (modified) (19 diffs)
-
Batch.h (modified) (6 diffs)
-
Config.c (deleted)
-
Config.h (deleted)
-
DetectionBatch.c (modified) (23 diffs)
-
DetectionBatch.h (modified) (1 diff)
-
Fits.c (copied) (copied from trunk/ippToPsps/src/Fits.c )
-
Fits.h (copied) (copied from trunk/ippToPsps/src/Fits.h )
-
FitsGenerator.c (copied) (copied from trunk/ippToPsps/src/FitsGenerator.c )
-
FitsGenerator.h (copied) (copied from trunk/ippToPsps/src/FitsGenerator.h )
-
InitBatch.c (modified) (5 diffs)
-
InitBatch.h (modified) (1 diff)
-
InitData.c (copied) (copied from trunk/ippToPsps/src/InitData.c )
-
InitData.h (copied) (copied from trunk/ippToPsps/src/InitData.h )
-
Logger.c (copied) (copied from trunk/ippToPsps/src/Logger.c )
-
Logger.h (copied) (copied from trunk/ippToPsps/src/Logger.h )
-
Makefile.am (modified) (3 diffs)
-
StackBatch.c (modified) (8 diffs)
-
StackBatch.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20110213/ippToPsps/src
- Property svn:ignore
-
old new 9 9 config.h.in 10 10 stamp-h1 11 ippToPspsVersionDefinitions.h 11 VersionDefinitions.h 12 detectionbatch 13 initbatch 14 stackbatch 15
-
- Property svn:ignore
-
branches/eam_branches/ipp-20110213/ippToPsps/src/Batch.c
r30191 r31083 18 18 #include <pslib.h> 19 19 #include <psmodules.h> 20 20 21 #include "Batch.h" 21 22 … … 62 63 if (this->exitCode != PS_EXIT_SUCCESS) { 63 64 64 psError(PS_ERR_UNKNOWN, false, "Failed, so deleting %s", this->fitsOutPath); 65 66 // if process failed, we need to delete that FITS file 67 if (remove(this->fitsOutPath) == -1) { 68 69 psError(PS_ERR_UNKNOWN, false, "Unable to delete %s", this->fitsOutPath); 70 } 65 this->logger->print(this->logger, MSG_ERROR, "Batch", "Failed, so deleting fits file\n"); 66 this->fitsOut->delete(this->fitsOut); 71 67 } 72 // ...otherwise, close file 73 else { 74 75 int status = 0; 76 if (fits_close_file(this->fitsOut, &status)) { 77 78 psError(PS_ERR_IO, false, "Unable to close FITS file %s", this->fitsOutPath); 79 fits_report_error(stderr, status); 80 } 81 } 68 69 this->fitsOut->destroy(this->fitsOut); 82 70 } 83 71 … … 99 87 if (this->dvoConfig != NULL) dvoConfigFree(this->dvoConfig); 100 88 101 ippToPspsConfig_Destructor(this->config); 89 // destroy objects 90 this->fitsGenerator->destroy(this->fitsGenerator); 91 this->initData->destroy(this->initData); 102 92 103 93 pmConfigDone(); … … 115 105 if (file == NULL) { 116 106 117 psError(PS_ERR_UNKNOWN, false, "Unable to open file at %s", this->fitsInPath);107 this->logger->print(this->logger, MSG_ERROR, "Batch", "Unable to open file at %s\n", this->fitsInPath); 118 108 return false; 119 109 } … … 123 113 while (fgets(line, 1000, file) != NULL) this->numOfInputFiles++; 124 114 125 printf ("Number of input files %d\n", this->numOfInputFiles); 115 this->logger->print(this->logger, MSG_INFO, "Batch", 116 "%d input file%s found\n", this->numOfInputFiles, (this->numOfInputFiles > 1) ? "s" : ""); 126 117 127 118 if (this->numOfInputFiles < 1) return false; … … 151 142 Sets-up and reads command-line arguments 152 143 */ 153 static bool parseArguments(Batch* this, int argc, char **argv ) {144 static bool parseArguments(Batch* this, int argc, char **argv, char* configsDir, char* fitsOutFile) { 154 145 155 146 // first deal with DVO database … … 166 157 if (!this->pmconfig) { 167 158 168 psError(PS_ERR_UNKNOWN, false, "Unable to read configuration.");159 this->logger->print(this->logger, MSG_ERROR, "Batch", "Unable to read configuration\n"); 169 160 this->exitCode = PS_EXIT_CONFIG_ERROR; 170 161 return false; … … 178 169 haveSurveyType = false; 179 170 171 char fitsOutPath[1000]; 172 char configsBaseDir[1000]; 173 180 174 // decode arguments 181 175 int32_t optind = 1; … … 193 187 else if(strcmp(sw, "-output") == 0 ) { 194 188 optind++; if( optind > ( argc-1 ) ) break; 195 strcpy( this->fitsOutPath, argv[optind]);189 strcpy(fitsOutPath, argv[optind]); 196 190 haveFitsOutPath = true; 197 191 } … … 203 197 else if(strcmp(sw, "-config") == 0 ) { 204 198 optind++; if( optind > ( argc-1 ) ) break; 205 strcpy( this->configsDir, argv[optind]);199 strcpy(configsBaseDir, argv[optind]); 206 200 haveConfig = true; 207 201 } … … 211 205 haveSurveyType = true; 212 206 } 207 else if(strcmp(sw, "-test") == 0 ) { 208 this->testMode = true; 209 } 213 210 } 214 211 … … 216 213 } 217 214 218 219 // setup command line arguments 220 //psMetadataAddStr(this->arguments, PS_LIST_TAIL, "-survey", 0, "Survey type", NULL); 221 222 223 // now check rest of arguments 224 //if (argc < 2 || !psArgumentParse(this->arguments, &argc, argv)) { 225 226 // usage(this, argv[0]); 227 //this->exitCode = PS_EXIT_CONFIG_ERROR; 228 //return false; 229 // } 230 231 //this->surveyType = psMemIncrRefCounter(psMetadataLookupStr(NULL, this->arguments, "-survey")); 232 215 // check we have some input paths 233 216 if (haveFitsInPath && !readInputFilePaths(this)) { 234 217 … … 237 220 } 238 221 239 return true; 240 } 241 242 /** 243 Initialises file paths, creates FITS file etc 244 */ 245 bool init(Batch* this) { 246 247 // create a config object 248 this->config = ippToPspsConfig_Constructor(this->configsDir); 249 if (this->config == NULL) { 222 // create an InitData object and get survey ID 223 this->initData = new_InitData(configsBaseDir, this->logger); 224 if (strlen(this->surveyType) > 0 && 225 !this->initData->getSurveyId(this->initData, this->surveyType, &this->surveyID)) { 250 226 251 227 this->exitCode = PS_EXIT_CONFIG_ERROR; … … 253 229 } 254 230 255 // get survey ID using config object 256 if (strlen(this->surveyType) > 0 && !ippToPspsConfig_getSurveyId(this->config, this->surveyType, &this->surveyID)) { 257 258 this->exitCode = PS_EXIT_CONFIG_ERROR; 259 return false; 260 } 231 // create a FitsGenerator object 232 strcat(configsBaseDir, configsDir); 233 this->fitsGenerator = new_FitsGenerator(this->logger, configsBaseDir); 234 261 235 // create full FITS out path 262 sprintf (this->fitsOutPath, "%s/%s", this->fitsOutPath, this->fitsOutFile);236 sprintf(fitsOutPath, "%s/%s", fitsOutPath, fitsOutFile); 263 237 264 238 // create an output FITS file 265 int status=0; 266 if (fits_create_file(&this->fitsOut, this->fitsOutPath, &status)) { 267 fits_report_error(stderr, status); 268 psError(PS_ERR_IO, false, "Unable to create file at: '%s'", this->fitsOutPath); 269 this->exitCode = PS_EXIT_SYS_ERROR; 270 this->fitsOut = NULL; 271 return false; 272 } 239 this->fitsOut = new_Fits(fitsOutPath, this->logger); 240 if (this->fitsOut->getFilePtr(this->fitsOut) == NULL) return false; 273 241 274 242 // create XML document for results … … 278 246 xmlNodePtr rootNode = xmlNewNode(NULL, BAD_CAST "ippToPsps_Results"); 279 247 xmlDocSetRootElement(this->resultsXmlDoc, rootNode); 280 xmlNewChild(rootNode, NULL, BAD_CAST "filename", BAD_CAST this->fitsOutFile);248 xmlNewChild(rootNode, NULL, BAD_CAST "filename", BAD_CAST fitsOutFile); 281 249 } 282 250 … … 289 257 static void print(Batch* this) { 290 258 291 printf("\n"); 292 printf("* surveyType : '%s'\n", this->surveyType); 293 printf("* surveyID : %d\n", this->surveyID); 294 printf("* resultsPath : '%s'\n", this->resultsPath); 295 printf("* numOfInputFiles : %d\n", this->numOfInputFiles); 296 printf("* fitsInPath : '%s'\n", this->fitsInPath); 297 printf("* fitsOutFile : '%s'\n", this->fitsOutFile); 298 printf("* fitsOutPath : '%s'\n", this->fitsOutPath); 299 printf("* configsDir : '%s'\n", this->configsDir); 259 this->logger->print(this->logger, MSG_INFO, "Batch", "\n"); 260 this->logger->print(this->logger, MSG_INFO, "Batch", " Class fields:\n"); 261 this->logger->print(this->logger, MSG_INFO, "Batch", "surveyType : %s\n", this->surveyType); 262 this->logger->print(this->logger, MSG_INFO, "Batch", "surveyID : %d\n", this->surveyID); 263 this->logger->print(this->logger, MSG_INFO, "Batch", "resultsPath : %s\n", this->resultsPath); 264 this->logger->print(this->logger, MSG_INFO, "Batch", "numOfInputFiles : %d\n", this->numOfInputFiles); 265 this->logger->print(this->logger, MSG_INFO, "Batch", "fitsInPath : %s\n", this->fitsInPath); 266 this->logger->print(this->logger, MSG_INFO, "Batch", "testMode : %s\n", this->testMode ? "yes" : "no"); 300 267 } 301 268 … … 342 309 Constructor. Takes a Batch object and initialises it. 343 310 */ 344 bool new_Batch(Batch *this) { 345 311 bool new_Batch(Logger* logger, Batch *this) { 312 313 this->logger = logger; 346 314 this->surveyID = -1; 347 315 this->resultsXmlDoc = NULL; … … 349 317 this->inputFiles = NULL; 350 318 this->fitsOut = NULL; 351 this-> config= NULL;319 this->fitsGenerator = NULL; 352 320 this->pmconfig = NULL; 353 321 this->exitCode = PS_EXIT_SUCCESS; 354 322 this->testMode = false; 323 324 // set up function pointers 355 325 this->parseArguments = parseArguments; 356 this->init = init;357 326 this->print = print; 358 this->destroy = destroy;359 360 327 this->gotResultsPath = gotResultsPath; 361 328 this->gotFitsInPath = gotFitsInPath; … … 363 330 this->gotConfig = gotConfig; 364 331 this->gotSurveyType = gotSurveyType; 332 this->destroy = destroy; 365 333 366 334 assert(this); -
branches/eam_branches/ipp-20110213/ippToPsps/src/Batch.h
r30812 r31083 1 /** @file ippToPsps.h1 /** @file Batch.h 2 2 * 3 3 * @brief Batch … … 6 6 * 7 7 * @author IfA 8 * Copyright 20 09Institute for Astronomy, University of Hawaii8 * Copyright 2011 Institute for Astronomy, University of Hawaii 9 9 */ 10 10 … … 12 12 #define IPPTOPSPS_BATCH_H 13 13 14 #include <libxml/parser.h> 15 #include <libxml/tree.h> 16 14 17 #include <psmodules.h> 15 18 #include <dvo_util.h> 16 #include "Config.h" 17 #include <libxml/parser.h> 18 #include <libxml/tree.h> 19 20 #include "FitsGenerator.h" 21 #include "Fits.h" 22 #include "InitData.h" 23 #include "Logger.h" 19 24 20 25 /** … … 25 30 - StackBatch 26 31 27 All subclasses need to implement the run() method and may need to imple nent print() and/or init()32 All subclasses need to implement the run() method and may need to implement print() 28 33 */ 29 34 typedef struct Batch { 30 35 31 36 // fields 32 char surveyType[10]; // the survey type, eg 3PI, MD01, STS, SSS33 int8_t surveyID; // survey ID34 char fitsInPath[1000]; // path to FITS input35 char resultsPath[1000]; // path to results file36 xmlDocPtr resultsXmlDoc; // pointer to XML document for results37 uint16_t numOfInputFiles; // number of input files38 char** inputFiles; // array of input file names39 char fitsOutFile[100]; // FITS output filename40 char fitsOutPath[1000]; // path to FITS output41 fitsfile *fitsOut; // output FITS file42 char configsDir[500]; // path to IPP/PSPS mapping file43 pmConfig* pmconfig; // pmConfig44 dvoConfig* dvoConfig; // dvo database45 IppToPspsConfig* config; // config structure46 char todaysDate[20]; // today's date47 int exitCode; // ps exit code37 char surveyType[10]; // the survey type, eg 3PI, MD01, STS, SSS 38 int8_t surveyID; // survey ID 39 char fitsInPath[1000]; // path to FITS input 40 char resultsPath[1000]; // path to results file 41 xmlDocPtr resultsXmlDoc; // pointer to XML document for results 42 uint16_t numOfInputFiles; // number of input files 43 char** inputFiles; // array of input file names 44 Fits *fitsOut; // output FITS file 45 pmConfig* pmconfig; // pmConfig 46 dvoConfig* dvoConfig; // dvo database 47 FitsGenerator* fitsGenerator; // FitsGenerator object 48 InitData* initData; // InitData object 49 char todaysDate[20]; // today's date 50 int exitCode; // ps exit code 51 bool testMode; // test mode boolean 52 Logger* logger; // Logger object 48 53 49 54 // methods 50 55 bool (*parseArguments)(); 51 bool (*init)();52 56 int (*run)(); 53 57 void (*print)(); … … 57 61 bool (*gotConfig)(); 58 62 bool (*gotSurveyType)(); 63 64 // destructor 59 65 void (*destroy)(); 60 66 … … 62 68 63 69 // public functions 64 bool new_Batch( Batch *this);70 bool new_Batch(Logger* logger, Batch *this); 65 71 66 72 void ippToPsps_VersionPrint(void); -
branches/eam_branches/ipp-20110213/ippToPsps/src/DetectionBatch.c
r30193 r31083 1 1 #include "DetectionBatch.h" 2 2 #include "DetectionBatchEnums.h" 3 4 #include "Fits.h" 5 3 6 4 7 /** … … 18 21 19 22 /** 23 Writes results to XML file 24 */ 25 static bool writeResults(DetectionBatch* this, long minObjID, long maxObjID, long totalDetectionsOut) { 26 27 if (!this->base.resultsXmlDoc) return false; 28 29 xmlNodePtr rootNode = xmlDocGetRootElement(this->base.resultsXmlDoc); 30 char tmp[100]; 31 sprintf(tmp, "%ld", minObjID); 32 xmlNewChild(rootNode, NULL, BAD_CAST "minObjID", BAD_CAST tmp); 33 sprintf(tmp, "%ld", maxObjID); 34 xmlNewChild(rootNode, NULL, BAD_CAST "maxObjID", BAD_CAST tmp); 35 sprintf(tmp, "%ld", totalDetectionsOut); 36 xmlNewChild(rootNode, NULL, BAD_CAST "totalDetections", BAD_CAST tmp); 37 38 return true; 39 } 40 41 /** 20 42 Does the work. Loops through the provided smf files, tallies the contents with the DVO database already connected to and generates a new FITS file of the fomat required by PSPS (i.e. a binary table per PSPS database table) 21 43 */ … … 24 46 if (this->base.exitCode != PS_EXIT_SUCCESS) return this->base.exitCode; 25 47 26 int status = 0; 27 fitsfile *fitsIn; 28 29 if (fits_open_file(&fitsIn, this->base.inputFiles[0], READONLY, &status)) { 30 31 fits_report_error(stderr, status); 32 return PS_EXIT_SYS_ERROR; 33 } 34 35 // get primary header and pull stuff out for later 36 int nKeys; 37 fits_get_hdrspace(fitsIn, &nKeys, NULL, &status); 38 39 float zptObs, exposureTime; 40 char filterType[20]; 41 double obsTime; 42 double expStart; 43 double expTime; 44 status=0; fits_read_key(fitsIn, TFLOAT, "ZPT_OBS", &zptObs, NULL, &status); 45 status=0; fits_read_key(fitsIn, TFLOAT, "EXPREQ", &exposureTime, NULL, &status); 46 status=0; fits_read_key(fitsIn, TSTRING, "FILTERID", filterType, NULL, &status); 47 status=0; fits_read_key(fitsIn, TDOUBLE, "MJD-OBS", &expStart, NULL, &status); 48 status=0; fits_read_key(fitsIn, TDOUBLE, "EXPTIME", &expTime, NULL, &status); 49 obsTime = expStart + (expTime/172800.0); // exp start plus half exp time (converted from secs to days) 50 51 ippToPspsConfig_writeTable(this->base.config, fitsIn, this->base.fitsOut, 1, "FrameMeta", true); 48 // open input FITS file 49 Fits* fitsIn = existing_Fits(this->base.inputFiles[0], this->base.logger); 50 if (fitsIn->getFilePtr(fitsIn) == NULL) return PS_EXIT_SYS_ERROR; 51 52 // read some header values 53 float zptObs; fitsIn->getHeaderKeyValue(fitsIn, TFLOAT, "ZPT_OBS", &zptObs); 54 float exposureTime; fitsIn->getHeaderKeyValue(fitsIn, TFLOAT, "EXPREQ", &exposureTime); 55 char filterType[20]; fitsIn->getHeaderKeyValue(fitsIn, TSTRING, "FILTERID", filterType); 56 double expStart; fitsIn->getHeaderKeyValue(fitsIn, TDOUBLE, "MJD-OBS", &expStart); 57 double expTime; fitsIn->getHeaderKeyValue(fitsIn, TDOUBLE, "EXPTIME", &expTime); 58 double obsTime = expStart + (expTime/172800.0); // exp start plus half exp time (converted from secs to days) 59 60 61 this->base.fitsGenerator->createAndPopulateTable(this->base.fitsGenerator, fitsIn, this->base.fitsOut, 1, "FrameMeta", true); 52 62 53 63 // FrameMeta values 54 fits_write_col(this->base.fitsOut, TLONG, FRAMEMETA_FRAMEID, 1, 1, 1, &this->expId, &status);55 fits_write_col(this->base.fitsOut, TSTRING, FRAMEMETA_FRAMENAME, 1, 1, 1, &(this->expName), &status);56 fits_write_col(this->base.fitsOut, TBYTE, FRAMEMETA_SURVEYID, 1, 1, 1, &this->base.surveyID, &status);57 58 64 int8_t filterID = -1; 59 if (! ippToPspsConfig_getFilterId(this->base.config, filterType, &filterID)) {65 if (!this->base.initData->getFilterId(this->base.initData, filterType, &filterID)) { 60 66 61 67 this->base.exitCode = PS_EXIT_DATA_ERROR; 62 68 return this->base.exitCode; 63 69 } 64 65 fits_write_col(this->base.fitsOut, TBYTE, FRAMEMETA_FILTERID, 1, 1, 1, &filterID, &status); 70 this->base.fitsOut->writeColumn(this->base.fitsOut, TBYTE, FRAMEMETA_FILTERID, 1, 1, 1, &filterID); 71 this->base.fitsOut->writeColumn(this->base.fitsOut, TLONG, FRAMEMETA_FRAMEID, 1, 1, 1, &this->expId); 72 this->base.fitsOut->writeColumn(this->base.fitsOut, TSTRING, FRAMEMETA_FRAMENAME, 1, 1, 1, &(this->expName)); 73 this->base.fitsOut->writeColumn(this->base.fitsOut, TBYTE, FRAMEMETA_SURVEYID, 1, 1, 1, &this->base.surveyID); 74 66 75 67 76 int16_t cameraID = 1; // TODO 68 fits_write_col(this->base.fitsOut, TSHORT, FRAMEMETA_CAMERAID, 1, 1, 1, &cameraID, &status);69 70 77 int16_t cameraConfigID = 1; // TODO 71 fits_write_col(this->base.fitsOut, TSHORT, FRAMEMETA_CAMERACONFIGID, 1, 1, 1, &cameraConfigID, &status);72 73 78 int16_t telescopeID = 1; // TODO 74 fits_write_col(this->base.fitsOut, TSHORT, FRAMEMETA_TELESCOPEID, 1, 1, 1, &telescopeID, &status); 79 this->base.fitsOut->writeColumn(this->base.fitsOut, TSHORT, FRAMEMETA_CAMERAID, 1, 1, 1, &cameraID); 80 this->base.fitsOut->writeColumn(this->base.fitsOut, TSHORT, FRAMEMETA_CAMERACONFIGID, 1, 1, 1, &cameraConfigID); 81 this->base.fitsOut->writeColumn(this->base.fitsOut, TSHORT, FRAMEMETA_TELESCOPEID, 1, 1, 1, &telescopeID); 75 82 76 83 // stuff to keep from psf.hdr header … … 88 95 uint32_t s,d, invalidDvoRows, nChipDetectionsOut = 0; 89 96 90 long longnull = -999;91 float floatnull = -999.0;92 int anynull = 0;93 94 97 char ccdNumber[3], extensionName[15]; 95 // for storing FITS column data 98 // for storing FITS column data - do this once, to avoid expension free/calloc for each chip 96 99 long* ippIDet = (long*)calloc(this->MAXDETECT, sizeof(long)); 97 100 float* instMag = (float*)calloc(this->MAXDETECT, sizeof(float)); … … 110 113 int8_t* filterIDs = (int8_t*)calloc(this->MAXDETECT, sizeof(int8_t)); 111 114 int8_t* surveyIDs = (int8_t*)calloc(this->MAXDETECT, sizeof(int8_t)); 112 113 115 char** assocDate = (char**)calloc(this->MAXDETECT, sizeof(char*)); 114 116 for (uint32_t i=0; i<this->MAXDETECT;i++) assocDate[i] = (char*)malloc(20*sizeof(char)); … … 119 121 filterIDs[s] = filterID; 120 122 surveyIDs[s] = this->base.surveyID; 121 strcpy(assocDate[s], this->base.todaysDate); 123 124 // if running in test mode, don't use today's date 125 if (this->base.testMode) strcpy(assocDate[s], "2010-01-01"); 126 else strcpy(assocDate[s], this->base.todaysDate); 122 127 } 123 128 … … 133 138 int ippIDetNum, instMagNum, instMagErrNum, peakMagNum; 134 139 bool error = false; 135 136 // loop round all 60 chips 137 for (int x=0; x<8; x++) { 138 for (int y=0; y<8; y++) { 140 int startX, stopX, startY, stopY; 141 142 // in test mode, only run for chip 33 143 if (this->base.testMode) { 144 145 startX = 3; 146 stopX = 4; 147 startY = 3; 148 stopY = 4; 149 } 150 // in 'normal' mode, run for all chips 151 else { 152 153 startX = 0; 154 stopX = 8; 155 startY = 0; 156 stopY = 8; 157 } 158 159 this->base.logger->print(this->base.logger, MSG_INFO, "DetectionBatch", 160 "+-----------+---------+----------+----------------+--------------+--------------+\n"); 161 this->base.logger->print(this->base.logger, MSG_INFO, "DetectionBatch", 162 "| Extension | Rows in | Rows out | Duplicate IDs | Invalid Flux | Bogus det ID |\n"); 163 164 // loop round chips 165 for (int x=startX; x<stopX; x++) { 166 for (int y=startY; y<stopY; y++) { 139 167 140 168 // dodge the corners … … 146 174 sprintf(ccdNumber, "%d%d", x, y); 147 175 148 // check we canmove to detections table in smf176 // check we CAN move to detections table in smf 149 177 sprintf(extensionName, "XY%s.psf", ccdNumber); 150 status=0; 151 if (fits_movnam_hdu(fitsIn, BINARY_TBL, extensionName, 0, &status)) { 152 psError(PS_ERR_IO, false, "Can't move to extension: %s skipping this chip\n", extensionName); 153 continue; 154 } 178 if (!fitsIn->moveToBinaryTable(fitsIn, extensionName)) continue; 155 179 156 180 // move to header extension 157 181 sprintf(extensionName, "XY%s.hdr", ccdNumber); 158 status=0; 159 if (fits_movnam_hdu(fitsIn, IMAGE_HDU, extensionName, 0, &status)) { 160 psError(PS_ERR_IO, false, "Can't move to extension: %s skipping this chip\n", extensionName); 161 continue; 162 } 182 if (!fitsIn->moveToHeader(fitsIn, extensionName)) continue; 163 183 164 184 // stuff to save from psf.hdr 165 status=0; fits_read_key(fitsIn, TFLOAT, "FWHM_MAJ", &fwhmMaj, NULL, &status);166 status=0; fits_read_key(fitsIn, TFLOAT, "FWHM_MIN", &fwhmMin, NULL, &status);167 status=0; fits_read_key(fitsIn, TFLOAT, "IQ_FW1", &momentMaj, NULL, &status);168 status=0; fits_read_key(fitsIn, TFLOAT, "IQ_FW2", &momentMin, NULL, &status);169 status=0; fits_read_key(fitsIn, TLONG, "IMAGEID", &imageId, NULL, &status);170 status=0; fits_read_key(fitsIn, TLONG, "SOURCEID", &sourceId, NULL, &status);171 status=0; fits_read_key(fitsIn, TLONG, "NASTRO", &numPhotoRef, NULL, &status);185 fitsIn->getHeaderKeyValue(fitsIn, TFLOAT, "FWHM_MAJ", &fwhmMaj); 186 fitsIn->getHeaderKeyValue(fitsIn, TFLOAT, "FWHM_MIN", &fwhmMin); 187 fitsIn->getHeaderKeyValue(fitsIn, TFLOAT, "IQ_FW1", &momentMaj); 188 fitsIn->getHeaderKeyValue(fitsIn, TFLOAT, "IQ_FW2", &momentMin); 189 fitsIn->getHeaderKeyValue(fitsIn, TLONG, "IMAGEID", &imageId); 190 fitsIn->getHeaderKeyValue(fitsIn, TLONG, "SOURCEID", &sourceId); 191 fitsIn->getHeaderKeyValue(fitsIn, TLONG, "NASTRO", &numPhotoRef); 172 192 totalNumPhotoRef += numPhotoRef; // total up for storing in FrameMeta 193 173 194 // access DVO database 174 195 skylist = dvoSkyListByExternID(this->base.dvoConfig, sourceId, imageId, &image); 175 196 if (skylist == NULL) { 176 psError(PS_ERR_IO, false,197 this->base.logger->print(this->base.logger, MSG_ERROR, "DetectionBatch", 177 198 "DVO: can't find SkyList for sourceId='%d' imageId='%d' (CCD = XY%s): skipping this chip\n", 178 199 sourceId, imageId, ccdNumber); … … 189 210 if (numDvoDetections > this->MAXDETECT ) { 190 211 191 psError(PS_ERR_IO, false, 192 " Number of detections (%d) exceeds max limit (%ld)\n", 212 this->base.logger->print(this->base.logger, MSG_ERROR, "DetectionBatch", "Number of detections (%d) exceeds max limit (%ld)\n", 193 213 numDvoDetections, this->MAXDETECT); 194 214 error = true; … … 197 217 198 218 // create ImageMeta 199 ippToPspsConfig_writeTable(this->base.config, fitsIn, this->base.fitsOut, 1, "ImageMeta", true);219 this->base.fitsGenerator->createAndPopulateTable(this->base.fitsGenerator, fitsIn, this->base.fitsOut, 1, "ImageMeta", true); 200 220 psfFwhm = (fwhmMaj+fwhmMin)/2; 201 221 momentFwhm = (momentMaj+momentMin)/2; 202 222 imageFlags = (uint64_t)image->flags; 203 fits_write_col(this->base.fitsOut, TLONGLONG, IMAGEMETA_IMAGEID, 1, 1, 1, &pspsImageId, &status);204 fits_write_col(this->base.fitsOut, TLONG, IMAGEMETA_FRAMEID, 1, 1, 1, &this->expId, &status);205 fits_write_col(this->base.fitsOut, TSHORT, IMAGEMETA_CCDID, 1, 1, 1, &image->ccdnum, &status);206 fits_write_col(this->base.fitsOut, TLONG, IMAGEMETA_PHOTOCALID, 1, 1, 1, &image->photcode, &status);207 fits_write_col(this->base.fitsOut, TBYTE, IMAGEMETA_FILTERID, 1, 1, 1, &filterID, &status);208 fits_write_col(this->base.fitsOut, TFLOAT, IMAGEMETA_PHOTOSCAT, 1, 1, 1, &zptObs, &status);209 fits_write_col(this->base.fitsOut, TFLOAT, IMAGEMETA_PSFFWHM, 1, 1, 1, &psfFwhm, &status);210 fits_write_col(this->base.fitsOut, TFLOAT, IMAGEMETA_MOMENTFWHM, 1, 1, 1, &momentFwhm, &status);211 fits_write_col(this->base.fitsOut, TFLOAT, IMAGEMETA_PHOTOZERO, 1, 1, 1, &zptObs, &status);212 fits_write_col(this->base.fitsOut, TLONGLONG, IMAGEMETA_QAFLAGS, 1, 1, 1, &imageFlags, &status);223 this->base.fitsOut->writeColumn(this->base.fitsOut, TLONGLONG, IMAGEMETA_IMAGEID, 1, 1, 1, &pspsImageId); 224 this->base.fitsOut->writeColumn(this->base.fitsOut, TLONG, IMAGEMETA_FRAMEID, 1, 1, 1, &this->expId); 225 this->base.fitsOut->writeColumn(this->base.fitsOut, TSHORT, IMAGEMETA_CCDID, 1, 1, 1, &image->ccdnum); 226 this->base.fitsOut->writeColumn(this->base.fitsOut, TLONG, IMAGEMETA_PHOTOCALID, 1, 1, 1, &image->photcode); 227 this->base.fitsOut->writeColumn(this->base.fitsOut, TBYTE, IMAGEMETA_FILTERID, 1, 1, 1, &filterID); 228 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, IMAGEMETA_PHOTOSCAT, 1, 1, 1, &zptObs); 229 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, IMAGEMETA_PSFFWHM, 1, 1, 1, &psfFwhm); 230 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, IMAGEMETA_MOMENTFWHM, 1, 1, 1, &momentFwhm); 231 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, IMAGEMETA_PHOTOZERO, 1, 1, 1, &zptObs); 232 this->base.fitsOut->writeColumn(this->base.fitsOut, TLONGLONG, IMAGEMETA_QAFLAGS, 1, 1, 1, &imageFlags); 213 233 214 234 // now move BACK to detections table in smf 215 235 sprintf(extensionName, "XY%s.psf", ccdNumber); 216 status=0; 217 if (fits_movnam_hdu(fitsIn, BINARY_TBL, extensionName, 0, &status)) { 218 psError(PS_ERR_IO, false, "Can't move to extension: %s skipping\n", extensionName); 219 continue; 220 } 221 222 // keep a running count of 'images' we find in order to write total to FrameMeta at the end 236 long nChipDetectionsIn = 0; 237 if (!fitsIn->moveToBinaryTableAndCountRows(fitsIn, extensionName, &nChipDetectionsIn)) continue; 238 239 // keep a running count of 'images' we find in order to write total into FrameMeta at the end 223 240 nOta++; 224 225 long nChipDetectionsIn = 0;226 if (fits_get_num_rows(fitsIn, &nChipDetectionsIn, &status)) {227 fits_report_error(stderr, status);228 }229 241 230 242 // loop round detections to populate some extra stuff 231 243 s = d = nChipDetectionsOut = invalidDvoRows = 0; 232 244 233 // determine column numbers for certain IPP detection columns 245 // determine column numbers for certain IPP detection columns - do this only once to save time 234 246 if (firstTimeIn) { 235 247 236 status=0;fits_get_colnum(fitsIn, CASESEN, "IPP_IDET", &ippIDetNum, &status); 237 if (status) psError(PS_ERR_IO, false, "Unable to read col num for IPP_IDET"); 238 status=0;fits_get_colnum(fitsIn, CASESEN, "PSF_INST_MAG", &instMagNum, &status); 239 if (status) psError(PS_ERR_IO, false, "Unable to read col num for PSF_INST_MAG"); 240 status=0;fits_get_colnum(fitsIn, CASESEN, "PSF_INST_MAG_SIG", &instMagErrNum, &status); 241 if (status) psError(PS_ERR_IO, false, "Unable to read col num for PSF_INST_MAG_SIG"); 242 status=0;fits_get_colnum(fitsIn, CASESEN, "PEAK_FLUX_AS_MAG", &peakMagNum, &status); 243 if (status) psError(PS_ERR_IO, false, "Unable to read col num for PEAK_FLUX_AS_MAG"); 248 fitsIn->getColumnNumber(fitsIn, "IPP_IDET", &ippIDetNum); 249 fitsIn->getColumnNumber(fitsIn, "PSF_INST_MAG", &instMagNum); 250 fitsIn->getColumnNumber(fitsIn, "PSF_INST_MAG_SIG", &instMagErrNum); 251 fitsIn->getColumnNumber(fitsIn, "PEAK_FLUX_AS_MAG", &peakMagNum); 244 252 245 253 firstTimeIn=false; 246 254 } 247 255 248 anynull = 0;249 fits _read_col(fitsIn, TLONG, ippIDetNum, 1, 1, nChipDetectionsIn, &longnull, ippIDet, &anynull, &status);250 fits _read_col(fitsIn, TFLOAT, instMagNum, 1, 1, nChipDetectionsIn, &floatnull, instMag, &anynull, &status);251 fits _read_col(fitsIn, TFLOAT, instMagErrNum, 1, 1, nChipDetectionsIn, &floatnull, instMagErr, &anynull, &status);252 fits _read_col(fitsIn, TFLOAT, peakMagNum, 1, 1, nChipDetectionsIn, &floatnull, peakMag, &anynull, &status);256 //anynull = 0; 257 fitsIn->readColumn(fitsIn, TLONG, ippIDetNum, 1, 1, nChipDetectionsIn, ippIDet); 258 fitsIn->readColumn(fitsIn, TFLOAT, instMagNum, 1, 1, nChipDetectionsIn, instMag); 259 fitsIn->readColumn(fitsIn, TFLOAT, instMagErrNum, 1, 1, nChipDetectionsIn, instMagErr); 260 fitsIn->readColumn(fitsIn, TFLOAT, peakMagNum, 1, 1, nChipDetectionsIn, peakMag); 253 261 254 262 // DVO detections are ordered by IPP_IDET, which increments from 0 in SMF table … … 260 268 // loop through all detections in smf file extension for this chip. 261 269 // there are three ways for a detection to be ommitted from the final FITS output: 270 // 262 271 // 1. it has a duplicate obj ID to a previous detection 263 272 // 2. it has an invalid detection ID (< 0 or > max DVO det ID) … … 312 321 313 322 // check for invalid flux values, and skip them 314 if ( !peakFluxOk || !instFluxOk) {323 if (!peakFluxOk || !instFluxOk) { 315 324 removeList[numOfDuplicates+numInvalidFlux+numOfInvalidIppIDet] = s+1; 316 325 numInvalidFlux++; … … 327 336 328 337 // write number of rows (detections) to ImageMeta 329 fits_write_col(this->base.fitsOut, TLONG, IMAGEMETA_NDETECT, 1, 1, 1, &nChipDetectionsOut, &status);338 this->base.fitsOut->writeColumn(this->base.fitsOut, TLONG, IMAGEMETA_NDETECT, 1, 1, 1, &nChipDetectionsOut); 330 339 331 340 int totalRemove = numOfDuplicates+numInvalidFlux+numOfInvalidIppIDet; … … 335 344 336 345 // detections 337 ippToPspsConfig_writeTable(this->base.config, fitsIn, this->base.fitsOut, nChipDetectionsIn, "Detection", false); 338 fits_write_col(this->base.fitsOut, TLONGLONG, DETECTION_OBJID, 1, 1, nChipDetectionsIn, objID, &status); 339 fits_write_col(this->base.fitsOut, TLONGLONG, DETECTION_DETECTID, 1, 1, nChipDetectionsIn, detectID, &status); 340 fits_write_col(this->base.fitsOut, TLONGLONG, DETECTION_IPPOBJID, 1, 1, nChipDetectionsIn, ippObjID, &status); 341 fits_write_col(this->base.fitsOut, TLONGLONG, DETECTION_IPPDETECTID, 1, 1, nChipDetectionsIn, ippDetectID, &status); 342 fits_write_col(this->base.fitsOut, TBYTE, DETECTION_FILTERID, 1, 1, nChipDetectionsIn, filterIDs, &status); 343 fits_write_col(this->base.fitsOut, TBYTE, DETECTION_SURVEYID, 1, 1, nChipDetectionsIn, surveyIDs, &status); 344 fits_write_col(this->base.fitsOut, TLONGLONG, DETECTION_IMAGEID, 1, 1, nChipDetectionsIn, imageID, &status); 345 fits_write_col(this->base.fitsOut, TDOUBLE, DETECTION_OBSTIME, 1, 1, nChipDetectionsIn, obsTimes, &status); 346 fits_write_col(this->base.fitsOut, TFLOAT, DETECTION_INSTFLUX, 1, 1, nChipDetectionsIn, instFlux, &status); 347 fits_write_col(this->base.fitsOut, TFLOAT, DETECTION_INSTFLUXERR, 1, 1, nChipDetectionsIn, instFluxErr, &status); 348 fits_write_col(this->base.fitsOut, TFLOAT, DETECTION_PEAKADU, 1, 1, nChipDetectionsIn, peakFlux, &status); 349 fits_write_col(this->base.fitsOut, TSTRING, DETECTION_ASSOCDATE, 1, 1, nChipDetectionsIn, assocDate, &status); 350 fits_write_col(this->base.fitsOut, TLONGLONG, DETECTION_INFOFLAG, 1, 1, nChipDetectionsIn, flags, &status); 351 if (numOfDuplicates||numInvalidFlux||numOfInvalidIppIDet) 352 fits_delete_rowlist(this->base.fitsOut, removeList, totalRemove, &status); 346 this->base.fitsGenerator->createAndPopulateTable(this->base.fitsGenerator, fitsIn, this->base.fitsOut, nChipDetectionsIn, "Detection", false); 347 this->base.fitsOut->writeColumn(this->base.fitsOut, TLONGLONG, DETECTION_OBJID, 1, 1, nChipDetectionsIn, objID); 348 this->base.fitsOut->writeColumn(this->base.fitsOut, TLONGLONG, DETECTION_DETECTID, 1, 1, nChipDetectionsIn, detectID); 349 this->base.fitsOut->writeColumn(this->base.fitsOut, TLONGLONG, DETECTION_IPPOBJID, 1, 1, nChipDetectionsIn, ippObjID); 350 this->base.fitsOut->writeColumn(this->base.fitsOut, TLONGLONG, DETECTION_IPPDETECTID, 1, 1, nChipDetectionsIn, ippDetectID); 351 this->base.fitsOut->writeColumn(this->base.fitsOut, TBYTE, DETECTION_FILTERID, 1, 1, nChipDetectionsIn, filterIDs); 352 this->base.fitsOut->writeColumn(this->base.fitsOut, TBYTE, DETECTION_SURVEYID, 1, 1, nChipDetectionsIn, surveyIDs); 353 this->base.fitsOut->writeColumn(this->base.fitsOut, TLONGLONG, DETECTION_IMAGEID, 1, 1, nChipDetectionsIn, imageID); 354 this->base.fitsOut->writeColumn(this->base.fitsOut, TDOUBLE, DETECTION_OBSTIME, 1, 1, nChipDetectionsIn, obsTimes); 355 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, DETECTION_INSTFLUX, 1, 1, nChipDetectionsIn, instFlux); 356 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, DETECTION_INSTFLUXERR, 1, 1, nChipDetectionsIn, instFluxErr); 357 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, DETECTION_PEAKADU, 1, 1, nChipDetectionsIn, peakFlux); 358 this->base.fitsOut->writeColumn(this->base.fitsOut, TSTRING, DETECTION_ASSOCDATE, 1, 1, nChipDetectionsIn, assocDate); 359 this->base.fitsOut->writeColumn(this->base.fitsOut, TLONGLONG, DETECTION_INFOFLAG, 1, 1, nChipDetectionsIn, flags); 360 if (numOfDuplicates||numInvalidFlux||numOfInvalidIppIDet) this->base.fitsOut->deleteRows(this->base.fitsOut, removeList, totalRemove); 353 361 354 362 // skinny object 355 ippToPspsConfig_writeTable(this->base.config, fitsIn, this->base.fitsOut, nChipDetectionsIn, "SkinnyObject", false); 356 fits_write_col(this->base.fitsOut, TLONGLONG, SKINNYOBJECT_OBJID, 1, 1, nChipDetectionsIn, objID, &status); 357 fits_write_col(this->base.fitsOut, TLONGLONG, SKINNYOBJECT_IPPOBJID, 1, 1, nChipDetectionsIn, ippObjID, &status); 358 fits_write_col(this->base.fitsOut, TBYTE, SKINNYOBJECT_SURVEYID, 1, 1, nChipDetectionsIn, surveyIDs, &status); 359 if (numOfDuplicates||numInvalidFlux||numOfInvalidIppIDet) 360 fits_delete_rowlist(this->base.fitsOut, removeList, totalRemove, &status); 363 this->base.fitsGenerator->createAndPopulateTable(this->base.fitsGenerator, fitsIn, this->base.fitsOut, nChipDetectionsIn, "SkinnyObject", false); 364 this->base.fitsOut->writeColumn(this->base.fitsOut, TLONGLONG, SKINNYOBJECT_OBJID, 1, 1, nChipDetectionsIn, objID); 365 this->base.fitsOut->writeColumn(this->base.fitsOut, TLONGLONG, SKINNYOBJECT_IPPOBJID, 1, 1, nChipDetectionsIn, ippObjID); 366 this->base.fitsOut->writeColumn(this->base.fitsOut, TBYTE, SKINNYOBJECT_SURVEYID, 1, 1, nChipDetectionsIn, surveyIDs); 367 if (numOfDuplicates||numInvalidFlux||numOfInvalidIppIDet) this->base.fitsOut->deleteRows(this->base.fitsOut, removeList, totalRemove); 361 368 362 369 // object calibration color 363 ippToPspsConfig_writeTable(this->base.config, fitsIn, this->base.fitsOut, nChipDetectionsIn, "ObjectCalColor", false); 364 fits_write_col(this->base.fitsOut, TLONGLONG, OBJECTCALCOLOR_OBJID, 1, 1, nChipDetectionsIn, objID, &status); 365 fits_write_col(this->base.fitsOut, TLONGLONG, OBJECTCALCOLOR_IPPOBJID, 1, 1, nChipDetectionsIn, ippObjID, &status); 366 fits_write_col(this->base.fitsOut, TBYTE, OBJECTCALCOLOR_FILTERID, 1, 1, nChipDetectionsIn, filterIDs, &status); 367 if (numOfDuplicates||numInvalidFlux||numOfInvalidIppIDet) 368 fits_delete_rowlist(this->base.fitsOut, removeList, totalRemove, &status); 370 this->base.fitsGenerator->createAndPopulateTable(this->base.fitsGenerator, fitsIn, this->base.fitsOut, nChipDetectionsIn, "ObjectCalColor", false); 371 this->base.fitsOut->writeColumn(this->base.fitsOut, TLONGLONG, OBJECTCALCOLOR_OBJID, 1, 1, nChipDetectionsIn, objID); 372 this->base.fitsOut->writeColumn(this->base.fitsOut, TLONGLONG, OBJECTCALCOLOR_IPPOBJID, 1, 1, nChipDetectionsIn, ippObjID); 373 this->base.fitsOut->writeColumn(this->base.fitsOut, TBYTE, OBJECTCALCOLOR_FILTERID, 1, 1, nChipDetectionsIn, filterIDs); 374 if (numOfDuplicates||numInvalidFlux||numOfInvalidIppIDet) this->base.fitsOut->deleteRows(this->base.fitsOut, removeList, totalRemove); 369 375 } 370 376 371 psLogMsg("ippToPsps", PS_LOG_INFO, 372 "+-----------+---------+----------+----------------+--------------+--------------+\n" 373 "| Extension | Rows in | Rows out | Duplicate IDs | Invalid Flux | Bogus det ID |\n" 377 this->base.logger->print(this->base.logger, MSG_INFO, "DetectionBatch", 374 378 "| %s | %5ld | %5d | %5d | %5d | %5d |\n", 375 379 extensionName, nChipDetectionsIn, nChipDetectionsOut, numOfDuplicates, numInvalidFlux, numOfInvalidIppIDet); … … 384 388 } 385 389 386 psLogMsg("ippToPsps", PS_LOG_INFO, "Total detections for this exposure = %ld\n", totalDetectionsOut); 390 this->base.logger->print(this->base.logger, MSG_INFO, "DetectionBatch", 391 "+-----------+---------+----------+----------------+--------------+--------------+\n"); 392 393 this->base.logger->print(this->base.logger, MSG_INFO, "DetectionBatch", "Total detections for this exposure = %ld\n", totalDetectionsOut); 387 394 388 395 // free-up memory … … 408 415 409 416 // write number of images we have found into FrameMeta table 410 status=0; 411 if (fits_movnam_hdu(this->base.fitsOut, BINARY_TBL, "FrameMeta", 0, &status)) 412 psError(PS_ERR_IO, false, "Can't move back to FrameMeta extension to write number of OTAs\n"); 413 else { 414 fits_write_col(this->base.fitsOut, TSHORT, FRAMEMETA_NOTA, 1, 1, 1, &nOta, &status); 415 fits_write_col(this->base.fitsOut, TSHORT, FRAMEMETA_NUMPHOTOREF, 1, 1, 1, &totalNumPhotoRef, &status); 416 } 417 status=0; 418 if (fits_close_file(fitsIn, &status)) fits_report_error(stderr, status); 419 // write results 420 if (this->base.resultsXmlDoc) { 421 422 xmlNodePtr rootNode = xmlDocGetRootElement(this->base.resultsXmlDoc); 423 char tmp[100]; 424 sprintf(tmp, "%ld", minObjID); 425 xmlNewChild(rootNode, NULL, BAD_CAST "minObjID", BAD_CAST tmp); 426 sprintf(tmp, "%ld", maxObjID); 427 xmlNewChild(rootNode, NULL, BAD_CAST "maxObjID", BAD_CAST tmp); 428 sprintf(tmp, "%ld", totalDetectionsOut); 429 xmlNewChild(rootNode, NULL, BAD_CAST "totalDetections", BAD_CAST tmp); 430 } 431 432 psLogMsg("ippToPsps", PS_LOG_INFO, "Data written for a total of %d chips/OTAs", nOta); 417 if (this->base.fitsOut->moveToBinaryTable(this->base.fitsOut, "FrameMeta")) { 418 419 this->base.fitsOut->writeColumn(this->base.fitsOut, TSHORT, FRAMEMETA_NOTA, 1, 1, 1, &nOta); 420 this->base.fitsOut->writeColumn(this->base.fitsOut, TSHORT, FRAMEMETA_NUMPHOTOREF, 1, 1, 1, &totalNumPhotoRef); 421 } 422 423 fitsIn->destroy(fitsIn); 424 425 writeResults(this, minObjID, maxObjID, totalDetectionsOut); 426 427 this->base.logger->print(this->base.logger, MSG_INFO, "DetectionBatch", "Data written for a total of %d chips/OTAs\n", nOta); 433 428 434 429 if (error || nOta < 1) this->base.exitCode = PS_EXIT_DATA_ERROR; … … 438 433 } 439 434 440 441 435 /** 442 436 Print-out this class. Calls base-calls print method first. … … 446 440 this->base.print(&this->base); 447 441 448 printf("*exp ID : %d\n", this->expId);449 printf("* exp name : '%s'\n", this->expName ? this->expName : "undef");450 printf("\n");442 this->base.logger->print(this->base.logger, MSG_INFO, "DetectionBatch", "exp ID : %d\n", this->expId); 443 this->base.logger->print(this->base.logger, MSG_INFO, "DetectionBatch", "exp name : %s\n", this->expName ? this->expName : "undef"); 444 this->base.logger->print(this->base.logger, MSG_INFO, "DetectionBatch", "\n"); 451 445 } 452 446 … … 480 474 } 481 475 482 this->base.parseArguments(&this->base, argc, argv); 476 char fitsOutFile[40]; 477 sprintf(fitsOutFile, "%08d.FITS", this->expId); 478 this->base.parseArguments(&this->base, argc, argv, "/detection", fitsOutFile); 483 479 484 480 if ( … … 491 487 !haveExpName) { 492 488 493 printf("\n* ERROR with supplied arguments:");489 this->base.logger->print(this->base.logger, MSG_ERROR, "DetectionBatch", "Problem with supplied arguments\n"); 494 490 this->print(this); 495 491 this->base.exitCode = PS_EXIT_CONFIG_ERROR; … … 503 499 Constructor. Returns a new DetectionBatch object. 504 500 */ 505 DetectionBatch* new_DetectionBatch(int *argc, char **argv) { 506 501 DetectionBatch* new_DetectionBatch(Logger* logger, int *argc, char **argv) { 502 503 logger->print(logger, MSG_DEBUG, "DetectionBatch", "Constructor\n"); 507 504 DetectionBatch *this = (DetectionBatch*)calloc(1, sizeof(DetectionBatch)); 508 505 509 506 // call base-class constructor 510 if (!new_Batch(&this->base)) { 511 512 psError(PS_ERR_IO, false, "Unable to create Batch base-class object"); 513 return this; 514 } 507 new_Batch(logger, &this->base); 515 508 516 509 this->MAXDETECT = 200000; 517 510 511 // method pointers 518 512 this->print = print; 519 513 this->destroy = destroy; … … 522 516 this->expName = (char*)calloc(100, sizeof(char)); 523 517 524 if (!parseArguments(this, *argc, argv)) { return this; } 525 526 strcat(this->base.configsDir, "/detection"); 527 sprintf(this->base.fitsOutFile, "%08d.FITS", this->expId); 528 529 this->base.init(&this->base); 518 parseArguments(this, *argc, argv); 519 520 this->print(this); 530 521 531 522 return this; … … 537 528 int main(int argc, char **argv) { 538 529 539 psTimerStart("detectionbatch");540 541 ippToPsps_VersionPrint();542 543 int exitCode;544 545 DetectionBatch* detectionBatch = new_DetectionBatch( &argc, argv);530 // ippToPsps_VersionPrint(); 531 532 Logger* logger = new_Logger(NULL, false); 533 // Logger* logger = new_Logger("./detBatchLog.txt", false); 534 logger->print(logger, MSG_INFO, "main", "Creating new detection batch\n"); 535 536 DetectionBatch* detectionBatch = new_DetectionBatch(logger, &argc, argv); 546 537 detectionBatch->base.run(detectionBatch); 547 exitCode = detectionBatch->base.exitCode;538 int exitCode = detectionBatch->base.exitCode; 548 539 549 540 detectionBatch->destroy(detectionBatch); 550 541 551 double secs = psTimerMark("ippToPsps");552 553 psLogMsg("detectionbatch", 3, "detectionbatch completed %ssuccessfully, with exit code %d, in %.1f %s\n",554 (exitCode == PS_EXIT_SUCCESS) ? "" : "un",555 exitCode,556 (secs<60.0) ? secs : (secs/60.0),557 (secs<60.0) ? "sec(s)" : "min(s)");558 559 542 // tidy up 560 psTimerStop();561 543 psLibFinalize(); 544 logger->destroy(logger); 562 545 563 546 return exitCode; -
branches/eam_branches/ipp-20110213/ippToPsps/src/DetectionBatch.h
r30190 r31083 31 31 } DetectionBatch; 32 32 33 DetectionBatch *new_DetectionBatch( int *argc, char **argv);33 DetectionBatch *new_DetectionBatch(Logger* logger, int *argc, char **argv); 34 34 35 35 # endif // IPPTOPSPS_DETECTIONBATCH_H -
branches/eam_branches/ipp-20110213/ippToPsps/src/InitBatch.c
r30147 r31083 18 18 if (this->base.exitCode != PS_EXIT_SUCCESS) return this->base.exitCode; 19 19 20 if (! ippToPspsConfig_populateFromFile(this->base.config, this->base.fitsOut))20 if (!this->base.fitsGenerator->populateFromFile(this->base.fitsGenerator, this->base.fitsOut)) 21 21 this->base.exitCode = PS_EXIT_CONFIG_ERROR; 22 22 else this->base.exitCode = PS_EXIT_SUCCESS; … … 34 34 35 35 /** 36 Reads command-line arguments. Calls base-calls print method first.36 Reads command-line arguments. 37 37 */ 38 38 static bool parseArguments(InitBatch* this, int argc, char **argv) { 39 39 40 this->base.parseArguments(&this->base, argc, argv );40 this->base.parseArguments(&this->base, argc, argv, "/init", "00000000.FITS"); 41 41 42 42 if ( … … 44 44 !this->base.gotConfig() ) { 45 45 46 printf("\n* ERROR with supplied arguments:"); 47 this->print(this); 46 this->base.logger->print(this->base.logger, MSG_ERROR, "InitBatch", "Problem with supplied arguments\n"); 48 47 this->base.exitCode = PS_EXIT_CONFIG_ERROR; 49 48 return false; 50 49 } 51 52 50 53 51 return true; … … 57 55 Constructor 58 56 */ 59 InitBatch* new_InitBatch( int *argc, char **argv) {57 InitBatch* new_InitBatch(Logger* logger, int *argc, char **argv) { 60 58 59 logger->print(logger, MSG_DEBUG, "InitBatch", "Constructor\n"); 61 60 InitBatch *this = (InitBatch*)calloc(1, sizeof(InitBatch)); 62 61 63 62 // call base-class constructor 64 if (!new_Batch(&this->base)) {63 new_Batch(logger, &this->base); 65 64 66 psError(PS_ERR_IO, false, "Unable to create Batch base-class object"); 67 return this; 68 } 69 65 // method pointers 70 66 this->print = print; 71 67 this->destroy = destroy; 72 68 this->base.run = run; 73 69 74 if (!parseArguments(this, *argc, argv)) { return this; }70 parseArguments(this, *argc, argv); 75 71 76 strcat(this->base.configsDir, "/init"); 77 sprintf(this->base.fitsOutFile, "00000000.FITS"); 78 79 this->base.init(&this->base); 72 this->print(this); 80 73 81 74 return this; … … 87 80 int main(int argc, char **argv) { 88 81 89 psTimerStart("initbatch");82 // ippToPsps_VersionPrint(); 90 83 91 ippToPsps_VersionPrint(); 84 Logger* logger = new_Logger(NULL, false); 85 logger->print(logger, MSG_INFO, "main", "Creating new initialization batch\n"); 92 86 93 int exitCode; 94 95 InitBatch* initBatch = new_InitBatch(&argc, argv); 87 InitBatch* initBatch = new_InitBatch(logger, &argc, argv); 96 88 initBatch->base.run(initBatch); 97 exitCode = initBatch->base.exitCode;89 int exitCode = initBatch->base.exitCode; 98 90 99 91 initBatch->destroy(initBatch); 100 92 101 double secs = psTimerMark("initbatch");102 103 psLogMsg("initbatch", 3, "initbatch completed %ssuccessfully, with exit code %d, in %.1f %s\n",104 (exitCode == PS_EXIT_SUCCESS) ? "" : "un",105 exitCode,106 (secs<60.0) ? secs : (secs/60.0),107 (secs<60.0) ? "sec(s)" : "min(s)");108 109 93 // tidy up 110 psTimerStop();111 94 psLibFinalize(); 95 logger->destroy(logger); 112 96 113 97 return exitCode; -
branches/eam_branches/ipp-20110213/ippToPsps/src/InitBatch.h
r30147 r31083 24 24 // methods 25 25 void (*print)(); 26 27 // destructor 26 28 void (*destroy)(); 27 29 28 30 } InitBatch; 29 31 30 InitBatch *new_InitBatch(int *argc, char **argv); 32 // constructor 33 InitBatch *new_InitBatch(Logger *logger, int *argc, char **argv); 31 34 32 35 # endif // IPPTOPSPS_INITBATCH_H -
branches/eam_branches/ipp-20110213/ippToPsps/src/Makefile.am
r30147 r31083 31 31 Batch.c \ 32 32 Version.c \ 33 Config.c 33 Fits.c \ 34 InitData.c \ 35 Logger.c \ 36 FitsGenerator.c 34 37 35 38 # detectionbatch … … 40 43 Batch.c \ 41 44 Version.c \ 42 Config.c 45 Fits.c \ 46 InitData.c \ 47 Logger.c \ 48 FitsGenerator.c 43 49 44 50 # stackbatch … … 49 55 Batch.c \ 50 56 Version.c \ 51 Config.c 57 Fits.c \ 58 InitData.c \ 59 Logger.c \ 60 FitsGenerator.c 52 61 53 62 clean-local: -
branches/eam_branches/ipp-20110213/ippToPsps/src/StackBatch.c
r30147 r31083 1 1 #include "StackBatch.h" 2 2 #include "StackBatchEnums.h" 3 4 #include "Fits.h" 3 5 4 6 /** … … 13 15 14 16 /** 15 Does the work. 16 */ 17 static int run(StackBatch* this) { 18 19 if (this->base.exitCode != PS_EXIT_SUCCESS) return this->base.exitCode; 20 21 int status = 0; 22 fitsfile *fitsIn; 23 24 if (fits_open_file(&fitsIn, this->base.inputFiles[0], READONLY, &status)) { 25 26 fits_report_error(stderr, status); 27 return PS_EXIT_SYS_ERROR; 28 } 29 30 31 // get primary header and pull stuff out for later 32 int nKeys = 0; 33 fits_get_hdrspace(fitsIn, &nKeys, NULL, &status); 34 float exposureTime; status=0; fits_read_key(fitsIn, TFLOAT, "EXPTIME", &exposureTime, NULL, &status); 35 char filterType[20]; status=0; fits_read_key(fitsIn, TSTRING, "FILTER", filterType, NULL, &status); 36 37 17 Creates the StackDetection table 18 */ 19 static bool createStackDetectionTable( 20 StackBatch* this, 21 Fits* fitsIn, 22 int8_t* filterIDs, 23 int8_t* surveyIDs, 24 long* skycellIDs, 25 float exposureTime 26 ) { 27 28 char extensionName[25]; 29 sprintf(extensionName, "SkyChip.psf"); 30 long nDet = 0; 31 if (!fitsIn->moveToBinaryTableAndCountRows(fitsIn, extensionName, &nDet)) return false; 32 33 34 // allocate stuff 38 35 char** assocDate = (char**)calloc(this->MAXDETECT, sizeof(char**)); 39 36 for (uint32_t i=0; i<this->MAXDETECT;i++) assocDate[i] = (char*)calloc(20,sizeof(char)); 40 41 42 43 // write StackMeta44 ippToPspsConfig_writeTable(this->base.config, fitsIn, this->base.fitsOut, 1, "StackMeta", true);45 fits_write_col(this->base.fitsOut, TLONG, STACKMETA_SKYCELLID, 1, 1, 1, &this->skycellId, &status);46 47 int8_t filterID = -1;48 if (!ippToPspsConfig_getFilterId(this->base.config, filterType, &filterID)) {49 50 // this->base.exitCode = PS_EXIT_DATA_ERROR;51 // return this->base.exitCode; TODO52 }53 54 37 long* removeList = (long*)calloc(this->MAXDETECT, sizeof(long)); 55 38 float* instMag = (float*)calloc(this->MAXDETECT, sizeof(float)); 56 int8_t* filterIDs = (int8_t*)calloc(this->MAXDETECT, sizeof(int8_t)); 57 int8_t* surveyIDs = (int8_t*)calloc(this->MAXDETECT, sizeof(int8_t)); 58 float floatnull = -999.0; 59 int anynull = 0; 60 61 fits_write_col(this->base.fitsOut, TBYTE, STACKMETA_FILTERID, 1, 1, 1, &filterID, &status); 62 63 fits_write_col(this->base.fitsOut, TBYTE, STACKMETA_SURVEYID, 1, 1, 1, &this->base.surveyID, &status); 64 65 66 // psf detections 67 char extensionName[15]; 68 sprintf(extensionName, "Chip.psf"); 69 if (fits_movnam_hdu(fitsIn, BINARY_TBL, extensionName, 0, &status)) { 70 psError(PS_ERR_IO, false, "Can't move to extension: %s\n", extensionName); 71 72 } 73 else { 74 75 // some stuff is the same for all detections so we can populate here 76 for (long s = 0; s<this->MAXDETECT; s++) { 77 78 filterIDs[s] = filterID; 79 surveyIDs[s] = this->base.surveyID; 80 strcpy(assocDate[s], this->base.todaysDate); 39 float* peakMag = (float*)calloc(this->MAXDETECT, sizeof(float)); 40 float* peakFlux = (float*)calloc(this->MAXDETECT, sizeof(float)); 41 int* flags1 = (int*)calloc(this->MAXDETECT, sizeof(int)); 42 int* flags2 = (int*)calloc(this->MAXDETECT, sizeof(int)); 43 uint64_t* infoFlags = (uint64_t*)calloc(this->MAXDETECT, sizeof(uint64_t)); 44 45 bool peakFluxOk; 46 47 // some stuff is the same for all detections so we can populate here 48 for (long s = 0; s<this->MAXDETECT; s++) { 49 50 // if running in test mode, don't use today's date 51 if (this->base.testMode) strcpy(assocDate[s], "2010-01-01"); 52 else strcpy(assocDate[s], this->base.todaysDate); 53 } 54 55 fitsIn->readColumnUsingName(fitsIn, TFLOAT, "PSF_INST_MAG", 1, 1, nDet, instMag); 56 fitsIn->readColumnUsingName(fitsIn, TFLOAT, "PEAK_FLUX_AS_MAG", 1, 1, nDet, peakMag); 57 fitsIn->readColumnUsingName(fitsIn, TLONG, "FLAGS", 1, 1, nDet, flags1); 58 fitsIn->readColumnUsingName(fitsIn, TLONG, "FLAGS2", 1, 1, nDet, flags2); 59 60 this->base.logger->print(this->base.logger, MSG_INFO, "StackBatch", 61 "Looping through %ld psf detection rows from '%s'\n", nDet, extensionName); 62 float mag; 63 long unmatched = 0, totalDetections = 0, numOfDuplicates = 0, numInvalidFlux = 0, numDetectionsOut = 0; 64 65 this->base.logger->print(this->base.logger, MSG_INFO, "StackBatch", 66 "+---------------+---------+----------+------------------+---------------+--------------+\n"); 67 this->base.logger->print(this->base.logger, MSG_INFO, "StackBatch", 68 "| Extension | Rows in | Rows out | Missing from DVO | Duplicate IDs | Invalid Flux |\n"); 69 70 for (long s=0; s<nDet; s++) { 71 72 // TODO implement this match in DVO 73 if (1) { 74 75 //infoFlags[s] = ((uint64_t)flags1[s] << 32) | (uint64_t)flags2[s]; TODO implement after schema change to make infoFlag 64-bit 76 infoFlags[s] = (uint64_t)flags1[s]; 77 78 peakFluxOk = getFlux(exposureTime, peakMag[s], &peakFlux[s], 0.0, NULL); 79 80 mag = instMag[s]; 81 if (!peakFluxOk || !isfinite(mag) || mag < -998.0) { 82 83 removeList[numOfDuplicates+numInvalidFlux] = s+1; 84 numInvalidFlux++; 85 } 86 87 totalDetections++; 81 88 } 82 83 84 long nDet = 0; 85 if (fits_get_num_rows(fitsIn, &nDet, &status)) { 86 fits_report_error(stderr, status); 89 else { 90 91 unmatched++; 92 continue; 87 93 } 88 89 int instMagNum; 90 status=0;fits_get_colnum(fitsIn, CASESEN, "PSF_INST_MAG", &instMagNum, &status); 91 if (status) psError(PS_ERR_IO, false, "Unable to read col num for PSF_INST_MAG"); 92 fits_read_col(fitsIn, TFLOAT, instMagNum, 1, 1, nDet, &floatnull, instMag, &anynull, &status); 93 94 95 printf("Looping through %ld psf detections\n", nDet); 96 float mag; 97 long unmatched = 0, totalDetections = 0, numOfDuplicates = 0, numInvalidFlux = 0, numDetectionsOut = 0; 98 99 for (long s = 0; s<nDet; s++) { 100 101 // TODO implement this match in DVO 102 if (1) { 103 104 mag = instMag[s]; 105 if (!isfinite(mag) || mag < -998.0) { 106 107 removeList[numOfDuplicates+numInvalidFlux] = s+1; 108 numInvalidFlux++; 109 } 110 111 totalDetections++; 112 } 113 else { 114 115 unmatched++; 116 continue; 117 } 118 } 119 120 numDetectionsOut = totalDetections - numInvalidFlux; 121 122 if (numDetectionsOut > 0) { 123 124 ippToPspsConfig_writeTable(this->base.config, fitsIn, this->base.fitsOut, nDet, "StackDetection", false); 125 fits_write_col(this->base.fitsOut, TLONG, STACKDETECTION_SKYCELLID, 1, 1, 1, &this->skycellId, &status); 126 fits_write_col(this->base.fitsOut, TBYTE, STACKDETECTION_FILTERID, 1, 1, nDet, filterIDs, &status); 127 fits_write_col(this->base.fitsOut, TBYTE, STACKDETECTION_SURVEYID, 1, 1, nDet, surveyIDs, &status); 128 fits_write_col(this->base.fitsOut, TSTRING, STACKDETECTION_ASSOCDATE, 1, 1, nDet, assocDate, &status); 129 130 if (numInvalidFlux) fits_delete_rowlist(this->base.fitsOut, removeList, numInvalidFlux, &status); 131 132 } 133 psLogMsg("ippToPsps", PS_LOG_INFO, 134 "+---------------+---------+----------+------------------+---------------+--------------+\n" 135 "| Extension | Rows in | Rows out | Missing from DVO | Duplicate IDs | Invalid Flux |\n" 136 "| %12s | %5ld | %5ld | %5ld | %5ld | %5ld |\n", 137 extensionName, nDet, numDetectionsOut, unmatched, numOfDuplicates, numInvalidFlux); 138 139 } 140 141 142 143 // extended source 144 sprintf(extensionName, "Chip.xsrc"); 145 if (fits_movnam_hdu(fitsIn, BINARY_TBL, extensionName, 0, &status)) { 146 psError(PS_ERR_IO, false, "Can't move to extension: %s\n", extensionName); 147 148 } 149 else { 150 151 int colNum; 152 int type; 153 long repeat; 154 155 ippToPspsConfig_getFitsColumnMeta( 156 "PROF_FLUX", 157 &colNum, 158 &type, 159 &repeat, 160 fitsIn); 161 printf("PROF_FILL = %d %d %ld\n", colNum, type, repeat); 162 float* vector = calloc(repeat, sizeof(float)); 163 164 ippToPspsConfig_getColumnVector( 165 colNum, 166 1, 167 type, 168 repeat, 169 vector, 170 fitsIn); 171 172 173 174 free(vector); 175 176 long nDet = 0; 177 if (fits_get_num_rows(fitsIn, &nDet, &status)) { 178 fits_report_error(stderr, status); 179 } 180 181 printf("Looping through %ld extended source detections\n", nDet); 182 for (long s = 0; s<nDet; s++) { 183 184 185 186 } 187 188 ippToPspsConfig_writeTable(this->base.config, fitsIn, this->base.fitsOut, nDet, "StackApFlx", false); 189 fits_write_col(this->base.fitsOut, TBYTE, STACKAPFLX_FILTERID, 1, 1, nDet, filterIDs, &status); 190 fits_write_col(this->base.fitsOut, TBYTE, STACKAPFLX_SURVEYID, 1, 1, nDet, surveyIDs, &status); 191 } 94 } 95 96 numDetectionsOut = totalDetections - numInvalidFlux; 97 if (numDetectionsOut > 0) { 98 99 this->base.fitsGenerator->createAndPopulateTable(this->base.fitsGenerator, fitsIn, this->base.fitsOut, nDet, "StackDetection", false); 100 this->base.fitsOut->writeColumn(this->base.fitsOut, TLONG, STACKDETECTION_SKYCELLID, 1, 1, nDet, skycellIDs); 101 this->base.fitsOut->writeColumn(this->base.fitsOut, TBYTE, STACKDETECTION_FILTERID, 1, 1, nDet, filterIDs); 102 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKDETECTION_PEAKFLUX, 1, 1, nDet, peakFlux); 103 this->base.fitsOut->writeColumn(this->base.fitsOut, TBYTE, STACKDETECTION_SURVEYID, 1, 1, nDet, surveyIDs); 104 this->base.fitsOut->writeColumn(this->base.fitsOut, TSTRING, STACKDETECTION_ASSOCDATE, 1, 1, nDet, assocDate); 105 this->base.fitsOut->writeColumn(this->base.fitsOut, TLONGLONG, STACKDETECTION_INFOFLAG, 1, 1, nDet, flags1); 106 107 if (numInvalidFlux) this->base.fitsOut->deleteRows(this->base.fitsOut, removeList, numInvalidFlux); 108 109 } 110 111 this->base.logger->print(this->base.logger, MSG_INFO, "StackBatch", 112 "| %12s | %5ld | %5ld | %5ld | %5ld | %5ld |\n", 113 extensionName, nDet, numDetectionsOut, unmatched, numOfDuplicates, numInvalidFlux); 114 this->base.logger->print(this->base.logger, MSG_INFO, "StackBatch", 115 "+---------------+---------+----------+------------------+---------------+--------------+\n"); 192 116 193 117 … … 195 119 free(removeList); 196 120 free(instMag); 121 free(flags1); 122 free(flags2); 123 free(infoFlags); 124 for (uint32_t i=0; i<this->MAXDETECT;i++) free(assocDate[i]); 125 free(assocDate); 126 127 return true; 128 } 129 /** 130 Structure to encapsulate block of flux values for StackApFlx table 131 */ 132 typedef struct { 133 134 float* flx; 135 float* flxErr; 136 float* flxStd; 137 float* flxFill; 138 139 } StackApFlxFluxes; 140 141 /** 142 Creates the StackApFlx table for extended source attributes 143 */ 144 static bool createStackApFlxTable( 145 StackBatch* this, 146 Fits* fitsIn, 147 int8_t* filterIDs, 148 int8_t* surveyIDs 149 ) { 150 151 long nDet = 0; 152 char extensionName[15]; 153 sprintf(extensionName, "SkyChip.xrad"); 154 if (!fitsIn->moveToBinaryTableAndCountRows(fitsIn, extensionName, &nDet)) return false; 155 156 157 int aperFluxColNum, aperFluxErrColNum, aperFluxStDevColNum, aperFluxFillColNum; 158 int type; // all the same type 159 long repeat; 160 161 fitsIn->getColumnMeta(fitsIn, "APER_FLUX", &aperFluxColNum, &type, &repeat); 162 fitsIn->getColumnMeta(fitsIn, "APER_FLUX_ERR", &aperFluxErrColNum, &type, &repeat); 163 fitsIn->getColumnMeta(fitsIn, "APER_FLUX_STDEV", &aperFluxStDevColNum, &type, &repeat); 164 fitsIn->getColumnMeta(fitsIn, "APER_FILL", &aperFluxFillColNum, &type, &repeat); 165 float* vector = calloc(repeat, sizeof(float)); 166 167 // we store 10 different flux values 168 StackApFlxFluxes* stackApFlxFluxes = (StackApFlxFluxes*)calloc(11, sizeof(StackApFlxFluxes)); 169 for (long i=0; i<11; i++) { 170 171 stackApFlxFluxes[i].flx = (float*)calloc(nDet, sizeof(float)); 172 stackApFlxFluxes[i].flxErr = (float*)calloc(nDet, sizeof(float)); 173 stackApFlxFluxes[i].flxStd = (float*)calloc(nDet, sizeof(float)); 174 stackApFlxFluxes[i].flxFill = (float*)calloc(nDet, sizeof(float)); 175 } 176 177 this->base.logger->print(this->base.logger, MSG_INFO, "StackBatch", 178 "Looping through %ld extended source detections from extension '%s'\n", nDet, extensionName); 179 for (long s=0; s<nDet; s++) { 180 181 fitsIn->getColumnVector(fitsIn, aperFluxColNum,s, type, repeat, vector); 182 for (int i=0; i<repeat; i++) stackApFlxFluxes[i].flx[s] = vector[i]; 183 184 fitsIn->getColumnVector(fitsIn, aperFluxErrColNum,s, type, repeat, vector); 185 for (int i=0; i<repeat; i++) stackApFlxFluxes[i].flxErr[s] = vector[i]; 186 187 fitsIn->getColumnVector(fitsIn, aperFluxStDevColNum,s, type, repeat, vector); 188 for (int i=0; i<repeat; i++) stackApFlxFluxes[i].flxStd[s] = vector[i]; 189 190 fitsIn->getColumnVector(fitsIn, aperFluxFillColNum,s, type, repeat, vector); 191 for (int i=0; i<repeat; i++) stackApFlxFluxes[i].flxFill[s] = vector[i]; 192 193 } 194 195 free(vector); 196 197 //int status = 0; 198 this->base.fitsGenerator->createAndPopulateTable(this->base.fitsGenerator, fitsIn, this->base.fitsOut, nDet, "StackApFlx", false); 199 this->base.fitsOut->writeColumn(this->base.fitsOut, TBYTE, STACKAPFLX_FILTERID, 1, 1, nDet, filterIDs); 200 this->base.fitsOut->writeColumn(this->base.fitsOut, TBYTE, STACKAPFLX_SURVEYID, 1, 1, nDet, surveyIDs); 201 202 // R1->r10 flux values 203 // 1 204 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR1, 1, 1, nDet, stackApFlxFluxes[0].flx); 205 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR1ERR, 1, 1, nDet, stackApFlxFluxes[0].flxErr); 206 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR1STD, 1, 1, nDet, stackApFlxFluxes[0].flxStd); 207 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR1FILL, 1, 1, nDet, stackApFlxFluxes[0].flxFill); 208 // 2 209 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR2, 1, 1, nDet, stackApFlxFluxes[1].flx); 210 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR2ERR, 1, 1, nDet, stackApFlxFluxes[1].flxErr); 211 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR2STD, 1, 1, nDet, stackApFlxFluxes[1].flxStd); 212 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR2FILL, 1, 1, nDet, stackApFlxFluxes[1].flxFill); 213 // 3 214 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR3, 1, 1, nDet, stackApFlxFluxes[2].flx); 215 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR3ERR, 1, 1, nDet, stackApFlxFluxes[2].flxErr); 216 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR3STD, 1, 1, nDet, stackApFlxFluxes[2].flxStd); 217 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR3FILL, 1, 1, nDet, stackApFlxFluxes[2].flxFill); 218 // 4 219 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR4, 1, 1, nDet, stackApFlxFluxes[3].flx); 220 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR4ERR, 1, 1, nDet, stackApFlxFluxes[3].flxErr); 221 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR4STD, 1, 1, nDet, stackApFlxFluxes[3].flxStd); 222 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR4FILL, 1, 1, nDet, stackApFlxFluxes[3].flxFill); 223 // 5 224 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR5, 1, 1, nDet, stackApFlxFluxes[4].flx); 225 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR5ERR, 1, 1, nDet, stackApFlxFluxes[4].flxErr); 226 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR5STD, 1, 1, nDet, stackApFlxFluxes[4].flxStd); 227 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR5FILL, 1, 1, nDet, stackApFlxFluxes[4].flxFill); 228 // 6 229 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR6, 1, 1, nDet, stackApFlxFluxes[5].flx); 230 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR6ERR, 1, 1, nDet, stackApFlxFluxes[5].flxErr); 231 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR6STD, 1, 1, nDet, stackApFlxFluxes[5].flxStd); 232 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR6FILL, 1, 1, nDet, stackApFlxFluxes[5].flxFill); 233 // 7 234 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR7, 1, 1, nDet, stackApFlxFluxes[6].flx); 235 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR7ERR, 1, 1, nDet, stackApFlxFluxes[6].flxErr); 236 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR7STD, 1, 1, nDet, stackApFlxFluxes[6].flxStd); 237 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR7FILL, 1, 1, nDet, stackApFlxFluxes[6].flxFill); 238 // 8 239 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR8, 1, 1, nDet, stackApFlxFluxes[7].flx); 240 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR8ERR, 1, 1, nDet, stackApFlxFluxes[7].flxErr); 241 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR8STD, 1, 1, nDet, stackApFlxFluxes[7].flxStd); 242 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR8FILL, 1, 1, nDet, stackApFlxFluxes[7].flxFill); 243 // 9 244 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR9, 1, 1, nDet, stackApFlxFluxes[8].flx); 245 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR9ERR, 1, 1, nDet, stackApFlxFluxes[8].flxErr); 246 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR9STD, 1, 1, nDet, stackApFlxFluxes[8].flxStd); 247 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR9FILL, 1, 1, nDet, stackApFlxFluxes[8].flxFill); 248 // 10 249 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR10, 1, 1, nDet, stackApFlxFluxes[9].flx); 250 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR10ERR, 1, 1, nDet, stackApFlxFluxes[9].flxErr); 251 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR10STD, 1, 1, nDet, stackApFlxFluxes[9].flxStd); 252 this->base.fitsOut->writeColumn(this->base.fitsOut, TFLOAT, STACKAPFLX_FLXR10FILL, 1, 1, nDet, stackApFlxFluxes[9].flxFill); 253 254 for (long i=0; i<11; i++) { 255 256 free(stackApFlxFluxes[i].flx); 257 free(stackApFlxFluxes[i].flxErr); 258 free(stackApFlxFluxes[i].flxStd); 259 free(stackApFlxFluxes[i].flxFill); 260 } 261 262 free(stackApFlxFluxes); 263 264 return true; 265 } 266 267 /** 268 Creates the StackModelFit table 269 */ 270 static bool createStackModelFitTable( 271 StackBatch* this, 272 Fits *fitsIn, 273 int8_t* filterIDs, 274 int8_t* surveyIDs) { 275 276 long nDet = 0; 277 char extensionName[40]; 278 sprintf(extensionName, "SkyChip.xfit"); 279 if (!fitsIn->moveToBinaryTableAndCountRows(fitsIn, extensionName, &nDet)) return false; 280 281 long* ippIdets = (long*)calloc(this->MAXDETECT, sizeof(long)); 282 char** modelTypes = (char**)calloc(this->MAXDETECT, sizeof(char**)); 283 for (uint32_t i=0; i<this->MAXDETECT;i++) modelTypes[i] = (char*)calloc(20,sizeof(char)); 284 285 // read whole columns 286 fitsIn->readColumnUsingName(fitsIn, TLONG, "IPP_IDET", 1, 1, nDet, ippIdets); 287 fitsIn->readColumnUsingName(fitsIn, TSTRING, "MODEL_TYPE", 1, 1, nDet, modelTypes); 288 289 this->base.logger->print(this->base.logger, MSG_INFO, "StackBatch", 290 "Looping through %ld model fit rows from '%s'\n", nDet, extensionName); 291 for (long i = 0; i<nDet; i++) { 292 293 printf("IPP_IDET %ld model %s\n", ippIdets[i], modelTypes[i]); 294 295 } 296 297 this->base.fitsGenerator->createAndPopulateTable(this->base.fitsGenerator, fitsIn, this->base.fitsOut, nDet, "StackModelFit", false); 298 this->base.fitsOut->writeColumn(this->base.fitsOut, TBYTE, STACKMODELFIT_FILTERID, 1, 1, nDet, filterIDs); 299 this->base.fitsOut->writeColumn(this->base.fitsOut, TBYTE, STACKMODELFIT_SURVEYID, 1, 1, nDet, surveyIDs); 300 301 // free up 302 free(ippIdets); 303 for (uint32_t i=0; i<this->MAXDETECT;i++) free(modelTypes[i]); 304 free(modelTypes); 305 306 return true; 307 } 308 309 /** 310 Creates the StackToImage table 311 */ 312 static bool createStackToImageTable( 313 StackBatch* this, 314 Fits* fitsIn 315 ) { 316 317 this->base.fitsGenerator->createAndPopulateTable(this->base.fitsGenerator, fitsIn, this->base.fitsOut, 3/*TODO*/, "StackToImage", false); 318 319 return true; 320 } 321 322 /** 323 Does the work. Writes all extensions to new FITS file. 324 */ 325 static int run(StackBatch* this) { 326 327 if (this->base.exitCode != PS_EXIT_SUCCESS) return this->base.exitCode; 328 329 // open input FITS file 330 Fits* fitsIn = existing_Fits(this->base.inputFiles[0], this->base.logger); 331 if (fitsIn->getFilePtr(fitsIn) == NULL) return PS_EXIT_SYS_ERROR; 332 333 // get primary header and pull stuff out for later 334 float exposureTime; fitsIn->getHeaderKeyValue(fitsIn, TFLOAT, "EXPTIME", &exposureTime); 335 char filterType[20]; fitsIn->getHeaderKeyValue(fitsIn, TSTRING, "FILTER", filterType); 336 337 int8_t filterID = -1; 338 if (!this->base.initData->getFilterId(this->base.initData, filterType, &filterID)) { 339 340 // this->base.exitCode = PS_EXIT_DATA_ERROR; 341 // return this->base.exitCode; TODO 342 } 343 344 exposureTime = 60.0;// TODO 345 filterID = 3; // TODO 346 347 // write StackMeta 348 this->base.fitsGenerator->createAndPopulateTable(this->base.fitsGenerator, fitsIn, this->base.fitsOut, 1, "StackMeta", true); 349 this->base.fitsOut->writeColumn(this->base.fitsOut, TLONG, STACKMETA_SKYCELLID, 1, 1, 1, &this->skycellId); 350 this->base.fitsOut->writeColumn(this->base.fitsOut, TBYTE, STACKMETA_FILTERID, 1, 1, 1, &filterID); 351 this->base.fitsOut->writeColumn(this->base.fitsOut, TBYTE, STACKMETA_SURVEYID, 1, 1, 1, &this->base.surveyID); 352 353 // allocate stuff for other extensions 354 int8_t* filterIDs = (int8_t*)calloc(this->MAXDETECT, sizeof(int8_t)); 355 int8_t* surveyIDs = (int8_t*)calloc(this->MAXDETECT, sizeof(int8_t)); 356 long* skycellIDs = (long*)calloc(this->MAXDETECT, sizeof(long)); 357 358 // some stuff is the same for all detections so we can populate here 359 for (long s = 0; s<this->MAXDETECT; s++) { 360 361 skycellIDs[s] = this->skycellId; 362 filterIDs[s] = filterID; 363 surveyIDs[s] = this->base.surveyID; 364 } 365 366 // create all extensions 367 createStackDetectionTable(this, fitsIn, filterIDs, surveyIDs, skycellIDs, exposureTime); 368 createStackApFlxTable(this, fitsIn, filterIDs, surveyIDs); 369 createStackModelFitTable(this, fitsIn, filterIDs, surveyIDs); 370 createStackToImageTable(this, fitsIn); 371 372 // free stuff up 197 373 free(filterIDs); 198 374 free(surveyIDs); 199 200 status=0; 201 if (fits_close_file(fitsIn, &status)) fits_report_error(stderr, status); 202 375 free(skycellIDs); 376 fitsIn->destroy(fitsIn); 203 377 204 378 return this->base.exitCode; 205 379 } 206 380 207 208 381 /** 209 382 Print-out this class. Calls base-calls print method first. … … 213 386 this->base.print(&this->base); 214 387 215 printf("*skycell ID : %d\n", this->skycellId);216 printf("\n");388 this->base.logger->print(this->base.logger, MSG_INFO, "StackBatch", "skycell ID : %d\n", this->skycellId); 389 this->base.logger->print(this->base.logger, MSG_INFO, "StackBatch", "\n"); 217 390 } 218 391 … … 240 413 } 241 414 242 this->base.parseArguments(&this->base, argc, argv); 415 char fitsOutFile[40]; 416 sprintf(fitsOutFile, "%08d.FITS", this->skycellId); 417 this->base.parseArguments(&this->base, argc, argv, "/stack", fitsOutFile); 243 418 244 419 if ( … … 262 437 Constructor 263 438 */ 264 StackBatch* new_StackBatch(int *argc, char **argv) { 265 439 StackBatch* new_StackBatch(Logger* logger, int *argc, char **argv) { 440 441 logger->print(logger, MSG_DEBUG, "StackBatch", "Constructor\n"); 266 442 StackBatch *this = (StackBatch*)calloc(1, sizeof(StackBatch)); 267 443 268 444 // call base-class constructor 269 if (!new_Batch(&this->base)) { 270 271 psError(PS_ERR_IO, false, "Unable to create Batch base-class object"); 272 return this; 273 } 445 new_Batch(logger, &this->base); 274 446 275 447 this->MAXDETECT = 150000; 276 448 449 // method pointers 277 450 this->print = print; 278 451 this->destroy = destroy; 279 452 this->base.run = run; 280 453 281 if (!parseArguments(this, *argc, argv)) { return this; } 282 283 strcat(this->base.configsDir, "/stack"); 284 sprintf(this->base.fitsOutFile, "%08d.FITS", this->skycellId); 285 286 this->base.init(&this->base); 454 parseArguments(this, *argc, argv); 455 456 this->print(this); 287 457 288 458 return this; … … 294 464 int main(int argc, char **argv) { 295 465 296 psTimerStart("stackbatch"); 297 298 ippToPsps_VersionPrint(); 299 300 int exitCode; 301 302 StackBatch* stackBatch = new_StackBatch(&argc, argv); 466 // ippToPsps_VersionPrint(); 467 468 Logger* logger = new_Logger(NULL, false); 469 logger->print(logger, MSG_INFO, "main", "Creating new stack batch\n"); 470 471 StackBatch* stackBatch = new_StackBatch(logger, &argc, argv); 303 472 stackBatch->base.run(stackBatch); 304 exitCode = stackBatch->base.exitCode;473 int exitCode = stackBatch->base.exitCode; 305 474 306 475 stackBatch->destroy(stackBatch); 307 476 308 double secs = psTimerMark("stackbatch");309 310 psLogMsg("stackbatch", 3, "stackbatch completed %ssuccessfully, with exit code %d, in %.1f %s\n",311 (exitCode == PS_EXIT_SUCCESS) ? "" : "un",312 exitCode,313 (secs<60.0) ? secs : (secs/60.0),314 (secs<60.0) ? "sec(s)" : "min(s)");315 316 477 // tidy up 317 psTimerStop();478 logger->destroy(logger); 318 479 psLibFinalize(); 319 480 … … 321 482 } 322 483 323 324 -
branches/eam_branches/ipp-20110213/ippToPsps/src/StackBatch.h
r30147 r31083 30 30 } StackBatch; 31 31 32 StackBatch *new_StackBatch( int *argc, char **argv);32 StackBatch *new_StackBatch(Logger* logger, int *argc, char **argv); 33 33 34 34 # endif // IPPTOPSPS_STACKBATCH_H
Note:
See TracChangeset
for help on using the changeset viewer.
