- Timestamp:
- Sep 25, 2012, 10:05:21 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsWrite.c
r34284 r34466 38 38 39 39 // Get these header words from the first input non null input 40 // but for SEEING which is the median of the (non-NULL) detections 41 // seeings 40 42 ppMopsDetections *det = NULL; 41 for (int d = 0; d < detections->n && det == NULL; d++) { 42 det = detections->data[d]; 43 int validSeeingCount = 0; 44 for (int d = 0; d < detections->n; d++) { 45 if (detections->data[d] != NULL) { 46 if (det == NULL) { 47 det = detections->data[d]; 48 } 49 if (isfinite(((ppMopsDetections*) detections->data[d])->seeing)) { 50 validSeeingCount += 1; 51 } 52 } 43 53 } 44 54 if (det != NULL) { 55 //Get the SEEING median 56 psVector* seeingValues = psVectorAlloc(validSeeingCount, PS_TYPE_F32); 57 psVectorInit(seeingValues, NAN); 58 validSeeingCount = 0; 59 for (int d = 0; d < detections->n; d++) { 60 if ( (detections->data[d] != NULL) && (isfinite(((ppMopsDetections*) detections->data[d])->seeing)) ){ 61 seeingValues->data.F32[validSeeingCount++] = ((ppMopsDetections*) detections->data[d])->seeing; 62 } 63 } 64 psStats *seeingStats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN); 65 psVectorStats(seeingStats, seeingValues, NULL, NULL, 0); 45 66 psMetadataAddF64(header, PS_LIST_TAIL, "MJD-OBS", 0, "MJD of exposure midpoint", det->mjd); 46 67 psMetadataAddStr(header, PS_LIST_TAIL, "RA", 0, "Right Ascension of boresight", det->raBoresight); … … 52 73 psMetadataAddStr(header, PS_LIST_TAIL, "FILTER", 0, "Filter name", det->filter); 53 74 psMetadataAddF32(header, PS_LIST_TAIL, "AIRMASS", 0, "Airmass of exposure", det->airmass); 54 psMetadataAddF32(header, PS_LIST_TAIL, "SEEING", 0, "Mean seeing", det->seeing);75 psMetadataAddF32(header, PS_LIST_TAIL, "SEEING", 0, "Mean seeing", seeingStats->sampleMedian); 55 76 } else { 56 77 psWarning("no inputs with surviving detections. output header will be incomplete"); … … 112 133 // Write data of version 2 (see ICD) 113 134 psMetadataAdd (row, PS_LIST_TAIL, "IPP_IDET", PS_DATA_U32, "IPP detection identifier index", 114 NAN);135 NAN); 115 136 psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_FLUX", PS_DATA_F32, "PSF fit instrumental magnitude", 116 NAN);137 NAN); 117 138 psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_FLUX_SIG",PS_DATA_F32, "Sigma of PSF instrumental magnitude", 118 NAN);139 NAN); 119 140 psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG", PS_DATA_F32, "magnitude in standard aperture", 120 NAN);141 NAN); 121 142 psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RAW", PS_DATA_F32, "magnitude in real aperture", 122 NAN);143 NAN); 123 144 psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RADIUS", PS_DATA_F32, "radius used for aperture mags", 124 NAN);145 NAN); 125 146 psMetadataAdd (row, PS_LIST_TAIL, "AP_FLUX", PS_DATA_F32, "instrumental flux in standard aperture", 126 NAN);147 NAN); 127 148 psMetadataAdd (row, PS_LIST_TAIL, "AP_FLUX_SIG", PS_DATA_F32, "aperture flux error", 128 NAN);149 NAN); 129 150 psMetadataAdd (row, PS_LIST_TAIL, "PEAK_FLUX_AS_MAG", PS_DATA_F32, "Peak flux expressed as magnitude", 130 NAN);151 NAN); 131 152 psMetadataAdd (row, PS_LIST_TAIL, "CAL_PSF_MAG", PS_DATA_F32, "PSF Magnitude using supplied calibration", 132 NAN);153 NAN); 133 154 psMetadataAdd (row, PS_LIST_TAIL, "CAL_PSF_MAG_SIG", PS_DATA_F32, "measured scatter of zero point calibration", 134 NAN);155 NAN); 135 156 psMetadataAdd (row, PS_LIST_TAIL, "SKY", PS_DATA_F32, "Sky level", 136 NAN);157 NAN); 137 158 psMetadataAdd (row, PS_LIST_TAIL, "SKY_SIGMA", PS_DATA_F32, "Sigma of sky level", 138 NAN);159 NAN); 139 160 psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF_PERFECT", PS_DATA_F32, "PSF coverage/quality factor (poor)", 140 NAN);161 NAN); 141 162 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_R1", PS_DATA_F32, "first radial moment", 142 NAN);163 NAN); 143 164 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_RH", PS_DATA_F32, "half radial moment", 144 NAN);165 NAN); 145 166 psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX", PS_DATA_F32, "Kron Flux (in 2.5 R1)", 146 NAN);167 NAN); 147 168 psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_ERR", PS_DATA_F32, "Kron Flux Error", 148 NAN);149 psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_INNER", PS_DATA_F32, "Kron Flux (in 1.0 R1)", 150 NAN);169 NAN); 170 psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_INNER", PS_DATA_F32, "Kron Flux (in 1.0 R1)", 171 NAN); 151 172 psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_OUTER", PS_DATA_F32, "Kron Flux (in 4.0 R1)", 152 NAN);173 NAN); 153 174 psMetadataAdd (row, PS_LIST_TAIL, "DIFF_R_P", PS_DATA_F32, "distance to positive match source", 154 NAN);175 NAN); 155 176 psMetadataAdd (row, PS_LIST_TAIL, "DIFF_SN_P", PS_DATA_F32, "signal-to-noise of pos match src", 156 NAN);177 NAN); 157 178 psMetadataAdd (row, PS_LIST_TAIL, "DIFF_R_M", PS_DATA_F32, "distance to negative match source", 158 NAN);179 NAN); 159 180 psMetadataAdd (row, PS_LIST_TAIL, "DIFF_SN_M", PS_DATA_F32, "signal-to-noise of neg match src", 160 NAN);181 NAN); 161 182 psMetadataAdd (row, PS_LIST_TAIL, "FLAGS2", PS_DATA_U32, "psphot analysis flags (group 2)", 162 0);163 psMetadataAdd (row, PS_LIST_TAIL, "N_FRAMES", PS_DATA_U16, "Number of frames overlapping source center", 164 0);165 psMetadataAdd (row, PS_LIST_TAIL, "PADDING", PS_DATA_S16, "padding", 166 0);183 0); 184 psMetadataAdd (row, PS_LIST_TAIL, "N_FRAMES", PS_DATA_U16, "Number of frames overlapping source center", 185 0); 186 psMetadataAdd (row, PS_LIST_TAIL, "PADDING", PS_DATA_S16, "padding", 187 0); 167 188 if (args->version == 3) { 168 // TODO: Write data of version 3 (see ICD)189 // TODO: Write data of version 3 (see ICD) 169 190 } 170 191 } … … 179 200 } else { 180 201 181 #define addColumn(_outName, _inName, _convertTo32) \202 #define addColumn(_outName, _inName, _convertTo32) \ 182 203 if (!addOutputColumn(table, detections, total, _outName, _inName, _convertTo32)) { \ 183 204 psError(PS_ERR_UNKNOWN, false, "Failed to add column %s", _outName); \ 184 return false; \205 return false; \ 185 206 } 186 207 … … 198 219 addColumn("EXT_SIGNIFICANCE", "EXT_NSIGMA", 0); 199 220 addColumn("PSF_MAJOR", NULL, 0); 200 addColumn("PSF_MINOR", NULL, 0); 201 addColumn("PSF_THETA", NULL, 0); 202 addColumn("PSF_QUALITY", "PSF_QF", 0); 203 addColumn("PSF_NPIX", NULL, 1); 221 addColumn("PSF_MINOR", NULL, 0); 222 addColumn("PSF_THETA", NULL, 0); 223 addColumn("PSF_QUALITY", "PSF_QF", 0); 224 addColumn("PSF_NPIX", NULL, 1); 204 225 addColumn("MOMENTS_XX", NULL, 0); 205 226 addColumn("MOMENTS_XY", NULL, 0); … … 287 308 ppMopsDetections *det = detections->data[i]; 288 309 if (!det || det->num == 0) { 289 // no detections survived for this input290 continue;310 // no detections survived for this input 311 continue; 291 312 } 292 313 psVector *in = NULL; 293 314 in = psMetadataLookupVector(NULL, det->table, inColumnName); 294 315 if (!in) { 295 psError(PS_ERR_PROGRAMMING, true, "failed to find input column: %s (convertTo32 is true)", inColumnName);296 return false;316 psError(PS_ERR_PROGRAMMING, true, "failed to find input column: %s (convertTo32 is true)", inColumnName); 317 return false; 297 318 } 298 319 if (in->type.type != PS_TYPE_S64 && in->type.type != PS_TYPE_U64) { 299 psError(PS_ERR_PROGRAMMING, true, "input column to convert is not S64 or U64: %s %d",300 inColumnName, in->type.type);301 return false;320 psError(PS_ERR_PROGRAMMING, true, "input column to convert is not S64 or U64: %s %d", 321 inColumnName, in->type.type); 322 return false; 302 323 } 303 324 if (out == NULL) { 304 // First time through set up the output vector and the copy parameters305 if (in->type.type == PS_TYPE_S64) {306 out = psVectorAlloc(outputSize, PS_TYPE_S32);307 } else {308 out = psVectorAlloc(outputSize, PS_TYPE_U32);309 }325 // First time through set up the output vector and the copy parameters 326 if (in->type.type == PS_TYPE_S64) { 327 out = psVectorAlloc(outputSize, PS_TYPE_S32); 328 } else { 329 out = psVectorAlloc(outputSize, PS_TYPE_U32); 330 } 310 331 } 311 332 for (long d=0; d < det->num; d++) { 312 if (in->type.type == PS_TYPE_S64) {313 out->data.S32[next++] = in->data.S64[d];314 } else {315 out->data.U32[next++] = in->data.U64[d];316 }333 if (in->type.type == PS_TYPE_S64) { 334 out->data.S32[next++] = in->data.S64[d]; 335 } else { 336 out->data.U32[next++] = in->data.U64[d]; 337 } 317 338 } 318 339 } … … 323 344 ppMopsDetections *det = detections->data[i]; 324 345 if (!det || det->num == 0) { 325 // no detections survived for this input326 continue;346 // no detections survived for this input 347 continue; 327 348 } 328 349 psVector *in = NULL; 329 350 in = psMetadataLookupVector(NULL, det->table, inColumnName); 330 351 if (!in) { 331 psError(PS_ERR_PROGRAMMING, true, "failed to find input column: %s (convertTo32 is false)", inColumnName);332 out = psVectorAlloc(outputSize, PS_TYPE_F32);333 psVectorInit(out, NAN);334 psMetadataAddVector(table, PS_LIST_TAIL, outColumnName, 0, NULL, out);335 return false;352 psError(PS_ERR_PROGRAMMING, true, "failed to find input column: %s (convertTo32 is false)", inColumnName); 353 out = psVectorAlloc(outputSize, PS_TYPE_F32); 354 psVectorInit(out, NAN); 355 psMetadataAddVector(table, PS_LIST_TAIL, outColumnName, 0, NULL, out); 356 return false; 336 357 } 337 358 if (out == NULL) { 338 // First time through set up the output vector and the copy parameters339 out = psVectorAlloc(outputSize, in->type.type);340 next = (void *) out->data.U8;341 switch (in->type.type) {342 case PS_TYPE_S8:343 elementSize = sizeof(psS8);344 break;345 case PS_TYPE_U8:346 elementSize = sizeof(psU8);347 break;348 case PS_TYPE_S16:349 elementSize = sizeof(psS16);350 break;351 case PS_TYPE_U16:352 elementSize = sizeof(psU16);353 break;354 case PS_TYPE_S32:355 elementSize = sizeof(psS32);356 break;357 case PS_TYPE_U32:358 elementSize = sizeof(psU32);359 break;360 case PS_TYPE_S64:361 elementSize = sizeof(psS64);362 break;363 case PS_TYPE_U64:364 elementSize = sizeof(psU64);365 break;366 case PS_TYPE_F32:367 elementSize = sizeof(psF32);368 break;369 case PS_TYPE_F64:370 elementSize = sizeof(psF64);371 break;372 default:373 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Unknown vector type %d", in->type.type);374 return false;375 }376 } 377 // We are doing nasty things here so we can use memcpy. 359 // First time through set up the output vector and the copy parameters 360 out = psVectorAlloc(outputSize, in->type.type); 361 next = (void *) out->data.U8; 362 switch (in->type.type) { 363 case PS_TYPE_S8: 364 elementSize = sizeof(psS8); 365 break; 366 case PS_TYPE_U8: 367 elementSize = sizeof(psU8); 368 break; 369 case PS_TYPE_S16: 370 elementSize = sizeof(psS16); 371 break; 372 case PS_TYPE_U16: 373 elementSize = sizeof(psU16); 374 break; 375 case PS_TYPE_S32: 376 elementSize = sizeof(psS32); 377 break; 378 case PS_TYPE_U32: 379 elementSize = sizeof(psU32); 380 break; 381 case PS_TYPE_S64: 382 elementSize = sizeof(psS64); 383 break; 384 case PS_TYPE_U64: 385 elementSize = sizeof(psU64); 386 break; 387 case PS_TYPE_F32: 388 elementSize = sizeof(psF32); 389 break; 390 case PS_TYPE_F64: 391 elementSize = sizeof(psF64); 392 break; 393 default: 394 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Unknown vector type %d", in->type.type); 395 return false; 396 } 397 } 398 // We are doing nasty things here so we can use memcpy. 378 399 // It would be safer to do a proper loop over the elements. 379 400 long toCopy = det->num * elementSize;
Note:
See TracChangeset
for help on using the changeset viewer.
