- Timestamp:
- Oct 21, 2010, 2:45:13 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20100823/ippToPsps/src/ippToPspsBatchStack.c
r27686 r29515 9 9 #include "ippToPsps.h" 10 10 #include "ippToPspsConfig.h" 11 #include "ippToPspsStackEnums.h" 12 11 13 12 14 /** … … 15 17 int ippToPsps_batchStack(IppToPsps *this) { 16 18 17 // char extensionName[20];18 uint32_t skycell = 0; // TODO19 int status = 0; 20 fitsfile *fitsIn; 19 21 20 for (uint16_t i = 0; i<this->numOfInputFiles; i++) {22 if (fits_open_file(&fitsIn, this->inputFiles[0], READONLY, &status)) { 21 23 22 skycell = i; // TODO 24 fits_report_error(stderr, status); 25 return PS_EXIT_SYS_ERROR; 26 } 27 28 long removeList[MAXDETECT]; 29 float instMag[MAXDETECT]; 30 float floatnull = -999.0; 31 int anynull = 0; 32 33 // get primary header and pull stuff out for later 34 int nKeys = 0; 35 fits_get_hdrspace(fitsIn, &nKeys, NULL, &status); 36 float exposureTime; status=0; fits_read_key(fitsIn, TFLOAT, "EXPTIME", &exposureTime, NULL, &status); 37 char filterType[20]; status=0; fits_read_key(fitsIn, TSTRING, "FPA.FILTERID", filterType, NULL, &status); 23 38 24 39 40 char** assocDate = (char**)calloc(MAXDETECT, sizeof(char**)); 41 for (uint32_t i=0; i<MAXDETECT;i++) assocDate[i] = (char*)calloc(20,sizeof(char)); 42 int8_t filterIDs[MAXDETECT], surveyIDs[MAXDETECT]; 43 44 45 // write StackMeta 46 ippToPspsConfig_writeTable(this->config, fitsIn, this->fitsOut, 1, "StackMeta", true); 47 fits_write_col(this->fitsOut, TLONG, STACKMETA_SKYCELLID, 1, 1, 1, &this->id, &status); 48 49 int8_t filterID = -1; 50 if (!ippToPspsConfig_getFilterId(this->config, filterType, &filterID)) {return PS_EXIT_DATA_ERROR;} 51 fits_write_col(this->fitsOut, TBYTE, STACKMETA_FILTERID, 1, 1, 1, &filterID, &status); 52 53 fits_write_col(this->fitsOut, TBYTE, STACKMETA_SURVEYID, 1, 1, 1, &this->surveyID, &status); 54 55 56 // psf detections 57 char extensionName[15]; 58 sprintf(extensionName, "SkyChip.psf"); 59 if (fits_movnam_hdu(fitsIn, BINARY_TBL, extensionName, 0, &status)) { 60 psError(PS_ERR_IO, false, "Can't move to extension: %s\n", extensionName); 61 25 62 } 63 else { 64 65 // some stuff is the same for all detections so we can populate here 66 for (long s = 0; s<MAXDETECT; s++) { 67 68 filterIDs[s] = filterID; 69 surveyIDs[s] = this->surveyID; 70 strcpy(assocDate[s], this->todaysDate); 71 } 72 73 74 long nDet = 0; 75 if (fits_get_num_rows(fitsIn, &nDet, &status)) { 76 fits_report_error(stderr, status); 77 } 78 79 int instMagNum; 80 status=0;fits_get_colnum(fitsIn, CASESEN, "PSF_INST_MAG", &instMagNum, &status); 81 if (status) psError(PS_ERR_IO, false, "Unable to read col num for PSF_INST_MAG"); 82 fits_read_col(fitsIn, TFLOAT, instMagNum, 1, 1, nDet, &floatnull, instMag, &anynull, &status); 83 84 85 printf("Looping through %ld psf detections\n", nDet); 86 float mag; 87 long unmatched = 0, totalDetections = 0, numOfDuplicates = 0, numInvalidFlux = 0, numDetectionsOut = 0; 88 89 for (long s = 0; s<nDet; s++) { 90 91 // TODO implement this match in DVO 92 if (1) { 93 94 mag = instMag[s]; 95 if (!isfinite(mag) || mag < -998.0) { 96 97 removeList[numOfDuplicates+numInvalidFlux] = s+1; 98 numInvalidFlux++; 99 } 100 101 totalDetections++; 102 } 103 else { 104 105 unmatched++; 106 continue; 107 } 108 } 109 110 numDetectionsOut = totalDetections - numInvalidFlux; 111 112 if (numDetectionsOut > 0) { 113 114 ippToPspsConfig_writeTable(this->config, fitsIn, this->fitsOut, nDet, "StackDetection", false); 115 fits_write_col(this->fitsOut, TLONG, STACKDETECTION_SKYCELLID, 1, 1, 1, &this->id, &status); 116 fits_write_col(this->fitsOut, TBYTE, STACKDETECTION_FILTERID, 1, 1, nDet, filterIDs, &status); 117 fits_write_col(this->fitsOut, TBYTE, STACKDETECTION_SURVEYID, 1, 1, nDet, surveyIDs, &status); 118 fits_write_col(this->fitsOut, TSTRING, STACKDETECTION_ASSOCDATE, 1, 1, nDet, assocDate, &status); 119 120 if (numInvalidFlux) fits_delete_rowlist(this->fitsOut, removeList, numInvalidFlux, &status); 121 122 } 123 psLogMsg("ippToPsps", PS_LOG_INFO, 124 "+---------------+---------+----------+------------------+---------------+--------------+\n" 125 "| Extension | Rows in | Rows out | Missing from DVO | Duplicate IDs | Invalid Flux |\n" 126 "| %12s | %5ld | %5ld | %5ld | %5ld | %5ld |\n", 127 extensionName, nDet, numDetectionsOut, unmatched, numOfDuplicates, numInvalidFlux); 128 129 } 130 131 132 133 // extended source 134 sprintf(extensionName, "SkyChip.xsrc"); 135 if (fits_movnam_hdu(fitsIn, BINARY_TBL, extensionName, 0, &status)) { 136 psError(PS_ERR_IO, false, "Can't move to extension: %s\n", extensionName); 137 138 } 139 else { 140 141 long nDet = 0; 142 if (fits_get_num_rows(fitsIn, &nDet, &status)) { 143 fits_report_error(stderr, status); 144 } 145 146 printf("Looping through %ld extended source detections\n", nDet); 147 for (long s = 0; s<nDet; s++) { 148 149 150 151 } 152 153 ippToPspsConfig_writeTable(this->config, fitsIn, this->fitsOut, nDet, "StackApFlx", false); 154 fits_write_col(this->fitsOut, TBYTE, STACKAPFLX_FILTERID, 1, 1, nDet, filterIDs, &status); 155 fits_write_col(this->fitsOut, TBYTE, STACKAPFLX_SURVEYID, 1, 1, nDet, surveyIDs, &status); 156 } 157 158 status=0; 159 if (fits_close_file(fitsIn, &status)) fits_report_error(stderr, status); 160 26 161 27 162 return PS_EXIT_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.
