Changeset 28405
- Timestamp:
- Jun 18, 2010, 2:25:38 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 23 edited
-
ppStack/src/ppStackCombineFinal.c (modified) (1 diff)
-
ppStack/src/ppStackCombineInitial.c (modified) (1 diff)
-
ppStack/src/ppStackReject.c (modified) (1 diff)
-
psLib/src/imageops/psImageConvolve.c (modified) (7 diffs)
-
psLib/src/imageops/psImageCovariance.c (modified) (2 diffs)
-
psLib/src/sys/psThread.c (modified) (4 diffs)
-
psLib/src/sys/psThread.h (modified) (3 diffs)
-
psModules/src/camera/pmReadoutFake.c (modified) (1 diff)
-
psModules/src/detrend/pmBias.c (modified) (1 diff)
-
psModules/src/detrend/pmDark.c (modified) (1 diff)
-
psModules/src/detrend/pmFlatField.c (modified) (1 diff)
-
psModules/src/detrend/pmShutterCorrection.c (modified) (3 diffs)
-
psModules/src/imcombine/pmStackReject.c (modified) (1 diff)
-
psModules/src/imcombine/pmSubtraction.c (modified) (1 diff)
-
psModules/src/imcombine/pmSubtractionEquation.c (modified) (1 diff)
-
psModules/src/imcombine/pmSubtractionMatch.c (modified) (1 diff)
-
psphot/src/psphotApResid.c (modified) (14 diffs)
-
psphot/src/psphotBlendFit.c (modified) (7 diffs)
-
psphot/src/psphotGuessModels.c (modified) (2 diffs)
-
psphot/src/psphotMagnitudes.c (modified) (5 diffs)
-
psphot/src/psphotSourceStats.c (modified) (8 diffs)
-
psphot/src/psphotTest.c (modified) (5 diffs)
-
pswarp/src/pswarpTransformReadout.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStack/src/ppStackCombineFinal.c
r28094 r28405 79 79 PS_ARRAY_ADD_SCALAR(job->args, normalise, PS_TYPE_U8); 80 80 if (!psThreadJobAddPending(job)) { 81 psFree(job);82 81 psFree(reject); 83 82 return false; 84 83 } 85 psFree(job);86 84 } 87 85 -
trunk/ppStack/src/ppStackCombineInitial.c
r27427 r28405 50 50 psArrayAdd(job->args, 1, config); 51 51 if (!psThreadJobAddPending(job)) { 52 psFree(job);53 52 return false; 54 53 } 55 psFree(job);56 54 } 57 55 -
trunk/ppStack/src/ppStackReject.c
r28182 r28405 54 54 PS_ARRAY_ADD_SCALAR(job->args, i, PS_TYPE_S32); 55 55 if (!psThreadJobAddPending(job)) { 56 psFree(job);57 56 return false; 58 57 } 59 psFree(job);60 58 } 61 59 if (!psThreadPoolWait(true)) { -
trunk/psLib/src/imageops/psImageConvolve.c
r28136 r28405 864 864 PS_ARRAY_ADD_SCALAR(job->args, stop, PS_TYPE_S32); 865 865 if (!psThreadJobAddPending(job)) { 866 psFree(job);867 866 psFree(gaussNorm); 868 867 psFree(out); 869 868 return NULL; 870 869 } 871 psFree(job);872 870 } 873 871 if (!psThreadPoolWait(true)) { … … 1213 1211 if (!psThreadJobAddPending(job)) { 1214 1212 psError(PS_ERR_UNKNOWN, false, "Unable to smooth image"); 1215 psFree(job);1216 1213 psFree(calculation); 1217 1214 psFree(calcMask); … … 1219 1216 return false; 1220 1217 } 1221 psFree(job);1222 1218 } 1223 1219 // wait here for the threaded jobs to finish (NOP if threading is not active) … … 1261 1257 if (!psThreadJobAddPending(job)) { 1262 1258 psError(PS_ERR_UNKNOWN, false, "Unable to smooth image"); 1263 psFree(job);1264 1259 psFree(calculation); 1265 1260 psFree(calcMask); … … 1267 1262 return false; 1268 1263 } 1269 psFree(job);1270 1264 } 1271 1265 … … 1580 1574 PS_ARRAY_ADD_SCALAR(job->args, 0x00, PS_TYPE_U8); // specify rows 1581 1575 if (!psThreadJobAddPending(job)) { 1582 psFree(job);1583 1576 psFree(conv); 1584 1577 psFree(out); 1585 1578 return NULL; 1586 1579 } 1587 psFree(job);1588 1580 } 1589 1581 if (!psThreadPoolWait(true)) { … … 1617 1609 PS_ARRAY_ADD_SCALAR(job->args, 0xff, PS_TYPE_U8); // specify cols 1618 1610 if (!psThreadJobAddPending(job)) { 1619 psFree(job);1620 1611 psFree(conv); 1621 1612 psFree(out); 1622 1613 return NULL; 1623 1614 } 1624 psFree(job);1625 1615 } 1626 1616 if (!psThreadPoolWait(true)) { -
trunk/psLib/src/imageops/psImageCovariance.c
r28152 r28405 169 169 return NULL; 170 170 } 171 psFree(job);172 171 } else { 173 172 out->kernel[y][x] = imageCovarianceCalculate(covar, kernel, x, y); … … 334 333 return NULL; 335 334 } 336 psFree(job);337 335 } else { 338 336 out->kernel[y][x] = imageCovarianceBin(covar, bin, binVal, x, y); -
trunk/psLib/src/sys/psThread.c
r28402 r28405 99 99 bool psThreadJobAddPending(psThreadJob *job) 100 100 { 101 PS_ASSERT_THREAD_JOB_NON_NULL(job, false); 101 if (!job) { 102 // Asking for a no-op 103 return true; 104 } 102 105 103 106 psThreadTask *task = psHashLookup(tasks, job->type); // Task to execute job … … 114 117 } 115 118 psListAdd(done, PS_LIST_TAIL, job); 116 119 psFree(job); 117 120 return task->function(job); 118 121 } … … 123 126 } 124 127 psListAdd(pending, PS_LIST_TAIL, job); 128 psFree(job); 125 129 psThreadUnlock(); 126 130 … … 279 283 for (int i = 0; i < nThreads; i++) { 280 284 psThread *thread = pool->data[i] = psThreadAlloc(); // Thread for pool 281 if ( !pthread_create(&threads[i], NULL, psThreadLauncher, thread)) {285 if (pthread_create(&threads[i], NULL, psThreadLauncher, thread)) { 282 286 psAbort("Unable to create thread"); 283 287 } -
trunk/psLib/src/sys/psThread.h
r28402 r28405 73 73 74 74 /// Add a pending job to the queue 75 /// 76 /// This function swallows the provided job, so that the user no longer owns it. This is because freeing the 77 /// job is not thread-safe (its reference count is being changed within the threads) so we handle it ourselves 78 /// and absolve the user from all responsibility. If the user stores the job, he should only access it while 79 /// threads are processing in code protected by psThreadLock/psThreadUnlock. 75 80 bool psThreadJobAddPending(psThreadJob *job); 76 81 77 82 /// Get a job off the queue of pending jobs 83 /// 84 /// This function is not thread-safe. Protect with psThreadLock/psThreadUnlock if threads are running. 78 85 psThreadJob *psThreadJobGetPending(void); 79 86 80 87 /// Get a job off the queue of done jobs 88 /// 89 /// This function is not thread-safe. Protect with psThreadLock/psThreadUnlock if threads are running. 81 90 psThreadJob *psThreadJobGetDone(void); 82 91 … … 115 124 bool psThreadPoolFinalize(void); 116 125 117 126 #if 0 118 127 /// Add thread-specific data 119 128 /// … … 134 143 bool psThreadDataRemove(const char *name // Name of data 135 144 ); 136 145 #endif 137 146 138 147 /// @} -
trunk/psModules/src/camera/pmReadoutFake.c
r26651 r28405 303 303 304 304 if (!psThreadJobAddPending(job)) { 305 psFree(job);306 305 psFree(groups); 307 306 return false; 308 307 } 309 psFree(job);310 308 } 311 309 if (!psThreadPoolWait(true)) { -
trunk/psModules/src/detrend/pmBias.c
r21183 r28405 144 144 145 145 if (!psThreadJobAddPending(job)) { 146 psFree(job);147 146 return false; 148 147 } 149 psFree(job);150 148 } else if (!pmBiasSubtractScan(in, sub, scale, xOffset, yOffset, rowStart, rowStop)) { 151 149 psError(PS_ERR_UNKNOWN, false, "Unable to apply bias correction."); -
trunk/psModules/src/detrend/pmDark.c
r27597 r28405 587 587 588 588 if (!psThreadJobAddPending (job)) { 589 psFree(job);590 589 psFree(orders); 591 590 psFree(values); 592 591 return false; 593 592 } 594 psFree(job);595 593 } else if (!pmDarkApplyScan(readout, dark, orders, values, bad, doNorm, norm, rowStart, rowStop)) { 596 594 psError(PS_ERR_UNKNOWN, false, "Unable to apply dark."); -
trunk/psModules/src/detrend/pmFlatField.c
r21533 r28405 150 150 151 151 if (!psThreadJobAddPending(job)) { 152 psFree(job);153 152 return false; 154 153 } 155 psFree(job);156 154 } else if (!pmFlatFieldScan(inImage, inMask, inVar, flatImage, flatMask, badFlat, 157 155 xOffset, yOffset, rowStart, rowStop)) { -
trunk/psModules/src/detrend/pmShutterCorrection.c
r27832 r28405 351 351 psStats *resStats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV); 352 352 if (!psVectorStats (rawStats, counts, NULL, NULL, 0)) { 353 psError(PS_ERR_UNKNOWN, false, "failure to measure stats");354 return NULL;353 psError(PS_ERR_UNKNOWN, false, "failure to measure stats"); 354 return NULL; 355 355 } 356 356 if (!psVectorStats (resStats, resid, NULL, NULL, 0)) { 357 psError(PS_ERR_UNKNOWN, false, "failure to measure stats");358 return NULL;357 psError(PS_ERR_UNKNOWN, false, "failure to measure stats"); 358 return NULL; 359 359 } 360 360 … … 794 794 795 795 if (!psThreadJobAddPending(job)) { 796 psFree(job);797 796 return false; 798 797 } 799 psFree(job);800 798 } else if (!pmShutterCorrectionApplyScan(image, mask, var, shutterImage, exptime, blank, 801 799 rowStart, rowStop)) { … … 1017 1015 1018 1016 if (corr) { 1019 psTrace("psModules.detrend", 5, "Shutter correction fit: scale: %f, offset: %f, offref: %f\n", corr->scale, corr->offset, corr->offref);1020 if (isfinite(corr->offref) && corr->valid) {1021 psTrace("psModules.detrend", 5, "Sample reference value: %f\n", corr->offref);1022 meanRef += corr->offref;1023 numGood++;1024 }1017 psTrace("psModules.detrend", 5, "Shutter correction fit: scale: %f, offset: %f, offref: %f\n", corr->scale, corr->offset, corr->offref); 1018 if (isfinite(corr->offref) && corr->valid) { 1019 psTrace("psModules.detrend", 5, "Sample reference value: %f\n", corr->offref); 1020 meanRef += corr->offref; 1021 numGood++; 1022 } 1025 1023 } else { 1026 psTrace("psModules.detrend", 5, "failed Shutter correction fit\n");1027 }1024 psTrace("psModules.detrend", 5, "failed Shutter correction fit\n"); 1025 } 1028 1026 1029 1027 psFree(corr); -
trunk/psModules/src/imcombine/pmStackReject.c
r27365 r28405 289 289 PS_ARRAY_ADD_SCALAR(args, poorFrac, PS_TYPE_F32); 290 290 if (!psThreadJobAddPending(job)) { 291 psFree(job);292 291 psFree(source); 293 292 psFree(target); 294 293 return NULL; 295 294 } 296 psFree(job);297 295 } else if (!stackRejectGrow(target, source, kernels, numCols, numRows, 298 296 i, xSubMax, j, ySubMax, poorFrac)) { -
trunk/psModules/src/imcombine/pmSubtraction.c
r28150 r28405 1291 1291 1292 1292 if (!psThreadJobAddPending(job)) { 1293 psFree(job);1294 1293 return false; 1295 1294 } 1296 psFree(job);1297 1295 } else { 1298 1296 subtractionConvolvePatch(numCols, numRows, x0, y0, out1, out2, convMask, ro1, ro2, -
trunk/psModules/src/imcombine/pmSubtractionEquation.c
r27335 r28405 860 860 PS_ARRAY_ADD_SCALAR(job->args, mode, PS_TYPE_S32); 861 861 if (!psThreadJobAddPending(job)) { 862 psFree(job);863 862 return false; 864 863 } 865 psFree(job);866 864 } else { 867 865 pmSubtractionCalculateEquationStamp(stamps, kernels, i, mode); -
trunk/psModules/src/imcombine/pmSubtractionMatch.c
r27365 r28405 1060 1060 PS_ARRAY_ADD_SCALAR(job->args, bg2, PS_TYPE_F32); 1061 1061 if (!psThreadJobAddPending(job)) { 1062 psFree(job);1063 1062 return false; 1064 1063 } 1065 psFree(job);1066 1064 } else { 1067 1065 if (!pmSubtractionOrderStamp(ratios, mask, stamps, models, modelSums, i, bg1, bg2)) { -
trunk/psphot/src/psphotApResid.c
r28013 r28405 22 22 // loop over the available readouts 23 23 for (int i = 0; i < num; i++) { 24 if (i == chisqNum) continue; // skip chisq image25 if (!psphotApResidReadout (config, view, filerule, i, recipe)) {24 if (i == chisqNum) continue; // skip chisq image 25 if (!psphotApResidReadout (config, view, filerule, i, recipe)) { 26 26 psError (PSPHOT_ERR_CONFIG, false, "failed to measure aperture residual for %s entry %d", filerule, i); 27 return false;28 }27 return false; 28 } 29 29 } 30 30 return true; … … 56 56 57 57 if (!sources->n) { 58 psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping ap resid");59 return true;58 psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping ap resid"); 59 return true; 60 60 } 61 61 … … 66 66 int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads 67 67 if (!status) { 68 nThreads = 0;68 nThreads = 0; 69 69 } 70 70 … … 128 128 for (int i = 0; i < cellGroups->n; i++) { 129 129 130 psArray *cells = cellGroups->data[i]; 131 132 for (int j = 0; j < cells->n; j++) { 133 134 // allocate a job -- if threads are not defined, this just runs the job 135 psThreadJob *job = psThreadJobAlloc ("PSPHOT_APRESID_MAGS"); 136 137 psArrayAdd(job->args, 1, cells->data[j]); // sources 138 psArrayAdd(job->args, 1, psf); 139 PS_ARRAY_ADD_SCALAR(job->args, photMode, PS_TYPE_S32); 140 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK); 141 PS_ARRAY_ADD_SCALAR(job->args, markVal, PS_TYPE_IMAGE_MASK); 142 143 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nskip 144 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail 145 146 if (!psThreadJobAddPending(job)) { 147 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 148 psFree (job); 149 return false; 150 } 151 psFree(job); 152 } 153 154 // wait for the threads to finish and manage results 155 if (!psThreadPoolWait (false)) { 156 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 157 return false; 158 } 159 160 // we have only supplied one type of job, so we can assume the types here 161 psThreadJob *job = NULL; 162 while ((job = psThreadJobGetDone()) != NULL) { 163 if (job->args->n < 1) { 164 fprintf (stderr, "error with job\n"); 165 } else { 166 psScalar *scalar = NULL; 167 scalar = job->args->data[5]; 168 Nskip += scalar->data.S32; 169 scalar = job->args->data[6]; 170 Nfail += scalar->data.S32; 171 } 172 psFree(job); 173 } 130 psArray *cells = cellGroups->data[i]; 131 132 for (int j = 0; j < cells->n; j++) { 133 134 // allocate a job -- if threads are not defined, this just runs the job 135 psThreadJob *job = psThreadJobAlloc ("PSPHOT_APRESID_MAGS"); 136 137 psArrayAdd(job->args, 1, cells->data[j]); // sources 138 psArrayAdd(job->args, 1, psf); 139 PS_ARRAY_ADD_SCALAR(job->args, photMode, PS_TYPE_S32); 140 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK); 141 PS_ARRAY_ADD_SCALAR(job->args, markVal, PS_TYPE_IMAGE_MASK); 142 143 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nskip 144 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail 145 146 if (!psThreadJobAddPending(job)) { 147 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 148 return false; 149 } 150 } 151 152 // wait for the threads to finish and manage results 153 if (!psThreadPoolWait (false)) { 154 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 155 return false; 156 } 157 158 // we have only supplied one type of job, so we can assume the types here 159 psThreadJob *job = NULL; 160 while ((job = psThreadJobGetDone()) != NULL) { 161 if (job->args->n < 1) { 162 fprintf (stderr, "error with job\n"); 163 } else { 164 psScalar *scalar = NULL; 165 scalar = job->args->data[5]; 166 Nskip += scalar->data.S32; 167 scalar = job->args->data[6]; 168 Nfail += scalar->data.S32; 169 } 170 psFree(job); 171 } 174 172 } 175 173 … … 184 182 Npsf = 0; 185 183 186 # ifdef DEBUG 184 # ifdef DEBUG 187 185 FILE *f = fopen ("apresid.dat", "w"); 188 186 psAssert (f, "failed open"); … … 199 197 if (source->mode & PM_SOURCE_MODE_POOR) SKIPSTAR ("POOR STAR"); 200 198 201 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) SKIPSTAR ("EXTENDED");202 if (source->mode & PM_SOURCE_MODE_CR_LIMIT) SKIPSTAR ("COSMIC RAY");203 if (source->mode & PM_SOURCE_MODE_DEFECT) SKIPSTAR ("DEFECT");204 199 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) SKIPSTAR ("EXTENDED"); 200 if (source->mode & PM_SOURCE_MODE_CR_LIMIT) SKIPSTAR ("COSMIC RAY"); 201 if (source->mode & PM_SOURCE_MODE_DEFECT) SKIPSTAR ("DEFECT"); 202 205 203 if (!isfinite(source->apMag) || !isfinite(source->psfMag)) { 206 204 continue; 207 205 } 208 206 209 // XXX make this user-configurable?210 if (source->errMag > 0.01) continue;207 // XXX make this user-configurable? 208 if (source->errMag > 0.01) continue; 211 209 212 210 // aperture residual for this source … … 221 219 222 220 # ifdef DEBUG 223 fprintf (f, "%6.1f %6.1f : %6.1f %6.1f : %8.3f %8.3f %8.3f : %f : %f %f %f : %f\n",224 source->peak->xf, source->peak->yf, 225 source->modelPSF->params->data.F32[PM_PAR_XPOS], source->modelPSF->params->data.F32[PM_PAR_YPOS], 226 source->psfMag, source->apMag, source->errMag,227 source->modelPSF->params->data.F32[PM_PAR_I0], 228 source->modelPSF->params->data.F32[PM_PAR_SXX], source->modelPSF->params->data.F32[PM_PAR_SXY], source->modelPSF->params->data.F32[PM_PAR_SYY], 229 source->modelPSF->params->data.F32[PM_PAR_7]);221 fprintf (f, "%6.1f %6.1f : %6.1f %6.1f : %8.3f %8.3f %8.3f : %f : %f %f %f : %f\n", 222 source->peak->xf, source->peak->yf, 223 source->modelPSF->params->data.F32[PM_PAR_XPOS], source->modelPSF->params->data.F32[PM_PAR_YPOS], 224 source->psfMag, source->apMag, source->errMag, 225 source->modelPSF->params->data.F32[PM_PAR_I0], 226 source->modelPSF->params->data.F32[PM_PAR_SXX], source->modelPSF->params->data.F32[PM_PAR_SXY], source->modelPSF->params->data.F32[PM_PAR_SYY], 227 source->modelPSF->params->data.F32[PM_PAR_7]); 230 228 # endif 231 if (!isfinite(source->psfMag)) psAbort ("nan in psfMag");232 if (!isfinite(source->errMag)) psAbort ("nan in errMag");233 if (!isfinite(source->apMag)) psAbort ("nan in apMag");234 if (!isfinite(model->params->data.F32[PM_PAR_XPOS])) psAbort ("nan in xPos");235 if (!isfinite(model->params->data.F32[PM_PAR_YPOS])) psAbort ("nan in yPos");229 if (!isfinite(source->psfMag)) psAbort ("nan in psfMag"); 230 if (!isfinite(source->errMag)) psAbort ("nan in errMag"); 231 if (!isfinite(source->apMag)) psAbort ("nan in apMag"); 232 if (!isfinite(model->params->data.F32[PM_PAR_XPOS])) psAbort ("nan in xPos"); 233 if (!isfinite(model->params->data.F32[PM_PAR_YPOS])) psAbort ("nan in yPos"); 236 234 237 235 psVectorAppend (mag, source->psfMag); … … 253 251 if (Npsf < APTREND_NSTAR_MIN) { 254 252 psWarning("Only %d valid aperture residual sources (need %d), giving up", Npsf, APTREND_NSTAR_MIN); 255 goto escape;256 } 257 258 // this is a bit tricky, because we have two cases (MAP vs POLY), and they have a different 259 // definition for 'order' (order_MAP = order_POLY + 1). in addition, we have a 253 goto escape; 254 } 255 256 // this is a bit tricky, because we have two cases (MAP vs POLY), and they have a different 257 // definition for 'order' (order_MAP = order_POLY + 1). in addition, we have a 260 258 // user-specified MAX order, which we should respect, regardless of the mode 261 259 … … 270 268 pmTrend2DMode mode = PM_TREND_MAP; 271 269 if (mode == PM_TREND_MAP) { 272 MaxOrderForStars ++;273 } 270 MaxOrderForStars ++; 271 } 274 272 APTREND_ORDER_MAX = PS_MIN (APTREND_ORDER_MAX, MaxOrderForStars); 275 273 … … 283 281 int NY = readout->image->numRows; 284 282 for (int i = 1; i <= APTREND_ORDER_MAX; i++) { 285 286 int Nx, Ny;287 if (NX > NY) {288 Nx = i;289 Ny = PS_MAX (1, (int)(i * (NY / (float)(NX)) + 0.5));290 } else {291 Ny = i;292 Nx = PS_MAX (1, (int)(i * (NX / (float)(NY)) + 0.5));293 }294 295 float errorFloor;283 284 int Nx, Ny; 285 if (NX > NY) { 286 Nx = i; 287 Ny = PS_MAX (1, (int)(i * (NY / (float)(NX)) + 0.5)); 288 } else { 289 Ny = i; 290 Nx = PS_MAX (1, (int)(i * (NX / (float)(NY)) + 0.5)); 291 } 292 293 float errorFloor; 296 294 pmTrend2D *apTrend = psphotApResidTrend (&errorFloor, readout, Nx, Ny, xPos, yPos, apResid, dMag); 297 if (!apTrend) {298 continue;299 }300 301 // apply ApTrend results302 // float xc = 0.5*readout->image->numCols + readout->image->col0 + 0.5;303 // float yc = 0.5*readout->image->numRows + readout->image->row0 + 0.5;304 // float ApResid = pmTrend2DEval (psf->ApTrend, xc, yc); // ap-fit at chip center305 // if (!isfinite(ApResid)) psAbort("nan apresid @ center");295 if (!apTrend) { 296 continue; 297 } 298 299 // apply ApTrend results 300 // float xc = 0.5*readout->image->numCols + readout->image->col0 + 0.5; 301 // float yc = 0.5*readout->image->numRows + readout->image->row0 + 0.5; 302 // float ApResid = pmTrend2DEval (psf->ApTrend, xc, yc); // ap-fit at chip center 303 // if (!isfinite(ApResid)) psAbort("nan apresid @ center"); 306 304 307 305 // store the minimum errorFloor and best ApTrend to keep 308 306 if (errorFloor < errorFloorMin) { 309 307 errorFloorMin = errorFloor; 310 psFree (psf->ApTrend);311 psf->ApTrend = psMemIncrRefCounter(apTrend);312 } 313 psFree (apTrend);308 psFree (psf->ApTrend); 309 psf->ApTrend = psMemIncrRefCounter(apTrend); 310 } 311 psFree (apTrend); 314 312 } 315 313 if (psf->ApTrend == NULL) { 316 314 psWarning("Failed to find a valid aperture residual value"); 317 goto escape;315 goto escape; 318 316 } 319 317 … … 383 381 if (!pmTrend2DFit (apTrend, mask, 0xff, xPos, yPos, apResid, dMagSoft)) { 384 382 psWarning("Failed to fit trend for %d x %d map", Nx, Ny); 385 psFree (apTrend);386 return NULL;383 psFree (apTrend); 384 return NULL; 387 385 } 388 386 if (apTrend->mode == PM_TREND_MAP) { 389 // p_psImagePrint (2, apTrend->map->map, "ApTrend Before"); // XXX TEST:390 psImageMapRepair (apTrend->map->map);391 // p_psImagePrint (2, apTrend->map->map, "ApTrend After"); // XXX TEST:387 // p_psImagePrint (2, apTrend->map->map, "ApTrend Before"); // XXX TEST: 388 psImageMapRepair (apTrend->map->map); 389 // p_psImagePrint (2, apTrend->map->map, "ApTrend After"); // XXX TEST: 392 390 } 393 391 … … 400 398 if (!isfinite(*apResidSysErr)) { 401 399 psWarning("Failed to find systematic error for %d x %d map", Nx, Ny); 402 psFree (apTrend);403 return NULL;400 psFree (apTrend); 401 return NULL; 404 402 } 405 403 … … 408 406 409 407 if (psTraceGetLevel("psphot") >= 4) { 410 char filename[64];411 snprintf (filename, 64, "apresid.%dx%d.dat", Nx, Ny);408 char filename[64]; 409 snprintf (filename, 64, "apresid.%dx%d.dat", Nx, Ny); 412 410 FILE *dumpFile = fopen (filename, "w"); 413 411 for (int i = 0; i < xPos->n; i++) { … … 457 455 } 458 456 459 // clear the mask bit and set the circular mask pixels460 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));461 psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", markVal);462 463 bool status = pmSourceMagnitudes (source, psf, photMode, maskVal);464 465 // clear the mask bit 466 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));457 // clear the mask bit and set the circular mask pixels 458 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 459 psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", markVal); 460 461 bool status = pmSourceMagnitudes (source, psf, photMode, maskVal); 462 463 // clear the mask bit 464 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 467 465 468 466 // re-subtract the object, leave local sky 469 467 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 470 468 471 if (!status) {472 Nskip ++;473 psTrace ("psphot", 3, "skip : bad source mag");474 continue;475 }476 477 if (!isfinite(source->apMag) || !isfinite(source->psfMag)) {478 Nfail ++;479 psTrace ("psphot", 3, "fail : nan mags : %f %f", source->apMag, source->psfMag);480 continue;481 }482 source->mode |= PM_SOURCE_MODE_AP_MAGS;469 if (!status) { 470 Nskip ++; 471 psTrace ("psphot", 3, "skip : bad source mag"); 472 continue; 473 } 474 475 if (!isfinite(source->apMag) || !isfinite(source->psfMag)) { 476 Nfail ++; 477 psTrace ("psphot", 3, "fail : nan mags : %f %f", source->apMag, source->psfMag); 478 continue; 479 } 480 source->mode |= PM_SOURCE_MODE_AP_MAGS; 483 481 } 484 482 -
trunk/psphot/src/psphotBlendFit.c
r28013 r28405 15 15 // loop over the available readouts 16 16 for (int i = 0; i < num; i++) { 17 if (!psphotBlendFitReadout (config, view, filerule, i, recipe)) {17 if (!psphotBlendFitReadout (config, view, filerule, i, recipe)) { 18 18 psError (PSPHOT_ERR_CONFIG, false, "failed to fit sources (non-linear) for %s entry %d", filerule, i); 19 return false;20 }19 return false; 20 } 21 21 } 22 22 return true; … … 48 48 49 49 if (!sources->n) { 50 psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping blend fit");51 return true;50 psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping blend fit"); 51 return true; 52 52 } 53 53 … … 87 87 sources = psArraySort (sources, pmSourceSortBySN); 88 88 if (!sources->n) { 89 psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping blend");90 return true;89 psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping blend"); 90 return true; 91 91 } 92 92 … … 103 103 for (int j = 0; j < cells->n; j++) { 104 104 105 // allocate a job -- if threads are not defined, this just runs the job 106 psThreadJob *job = psThreadJobAlloc ("PSPHOT_BLEND_FIT"); 107 psArray *newSources = psArrayAllocEmpty(16); 108 109 psArrayAdd(job->args, 1, readout); 110 psArrayAdd(job->args, 1, recipe); 111 psArrayAdd(job->args, 1, cells->data[j]); // sources 112 psArrayAdd(job->args, 1, psf); 113 psArrayAdd(job->args, 1, newSources); // return for new sources 114 psFree (newSources); 115 116 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfit 117 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Npsf 118 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Next 119 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail 120 121 if (!psThreadJobAddPending(job)) { 122 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 123 psFree (job); 124 return NULL; 125 } 126 psFree(job); 105 // allocate a job -- if threads are not defined, this just runs the job 106 psThreadJob *job = psThreadJobAlloc ("PSPHOT_BLEND_FIT"); 107 psArray *newSources = psArrayAllocEmpty(16); 108 109 psArrayAdd(job->args, 1, readout); 110 psArrayAdd(job->args, 1, recipe); 111 psArrayAdd(job->args, 1, cells->data[j]); // sources 112 psArrayAdd(job->args, 1, psf); 113 psArrayAdd(job->args, 1, newSources); // return for new sources 114 psFree (newSources); 115 116 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfit 117 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Npsf 118 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Next 119 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail 120 121 if (!psThreadJobAddPending(job)) { 122 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 123 return NULL; 124 } 127 125 128 126 # if (0) … … 152 150 } 153 151 154 // wait for the threads to finish and manage results155 if (!psThreadPoolWait (false)) {156 psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");157 return NULL;158 }159 160 // we have only supplied one type of job, so we can assume the types here161 psThreadJob *job = NULL;162 while ((job = psThreadJobGetDone()) != NULL) {163 if (job->args->n < 1) {164 fprintf (stderr, "error with job\n");165 } else {166 psScalar *scalar = NULL;167 scalar = job->args->data[5];168 Nfit += scalar->data.S32;169 scalar = job->args->data[6];170 Npsf += scalar->data.S32;171 scalar = job->args->data[7];172 Next += scalar->data.S32;173 scalar = job->args->data[8];174 Nfail += scalar->data.S32;175 176 // add these back onto sources177 psArray *newSources = job->args->data[4];178 for (int j = 0; j < newSources->n; j++) {179 psArrayAdd (sources, 16, newSources->data[j]);180 }181 }182 psFree(job);152 // wait for the threads to finish and manage results 153 if (!psThreadPoolWait (false)) { 154 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 155 return NULL; 156 } 157 158 // we have only supplied one type of job, so we can assume the types here 159 psThreadJob *job = NULL; 160 while ((job = psThreadJobGetDone()) != NULL) { 161 if (job->args->n < 1) { 162 fprintf (stderr, "error with job\n"); 163 } else { 164 psScalar *scalar = NULL; 165 scalar = job->args->data[5]; 166 Nfit += scalar->data.S32; 167 scalar = job->args->data[6]; 168 Npsf += scalar->data.S32; 169 scalar = job->args->data[7]; 170 Next += scalar->data.S32; 171 scalar = job->args->data[8]; 172 Nfail += scalar->data.S32; 173 174 // add these back onto sources 175 psArray *newSources = job->args->data[4]; 176 for (int j = 0; j < newSources->n; j++) { 177 psArrayAdd (sources, 16, newSources->data[j]); 178 } 179 } 180 psFree(job); 183 181 } 184 182 } … … 278 276 psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf); 279 277 Next ++; 280 source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;278 source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT; 281 279 continue; 282 280 } … … 286 284 psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf); 287 285 Npsf ++; 288 source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;286 source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT; 289 287 continue; 290 288 } -
trunk/psphot/src/psphotGuessModels.c
r28013 r28405 21 21 // loop over the available readouts 22 22 for (int i = 0; i < num; i++) { 23 if (i == chisqNum) continue; // skip chisq image23 if (i == chisqNum) continue; // skip chisq image 24 24 if (!psphotGuessModelsReadout (config, view, filerule, i)) { 25 25 psError (PSPHOT_ERR_CONFIG, false, "failed on to guess models for %s entry %d", filerule, i); … … 106 106 if (!psThreadJobAddPending(job)) { 107 107 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 108 psFree (job);109 108 return false; 110 109 } 111 psFree(job);112 110 } 113 111 -
trunk/psphot/src/psphotMagnitudes.c
r28098 r28405 18 18 // loop over the available readouts 19 19 for (int i = 0; i < num; i++) { 20 if (i == chisqNum) continue; // skip chisq image21 22 // find the currently selected readout23 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest24 psAssert (file, "missing file?");25 26 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);27 psAssert (readout, "missing readout?");28 29 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");30 psAssert (detections, "missing detections?");31 32 psArray *sources = detections->allSources;33 psAssert (sources, "missing sources?");34 35 pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");36 psAssert (psf, "missing psf?");37 38 if (!psphotMagnitudesReadout (config, recipe, view, readout, sources, psf)) {20 if (i == chisqNum) continue; // skip chisq image 21 22 // find the currently selected readout 23 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest 24 psAssert (file, "missing file?"); 25 26 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 27 psAssert (readout, "missing readout?"); 28 29 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 30 psAssert (detections, "missing detections?"); 31 32 psArray *sources = detections->allSources; 33 psAssert (sources, "missing sources?"); 34 35 pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF"); 36 psAssert (psf, "missing psf?"); 37 38 if (!psphotMagnitudesReadout (config, recipe, view, readout, sources, psf)) { 39 39 psError (PSPHOT_ERR_CONFIG, false, "failed to measure magnitudes for %s entry %d", filerule, i); 40 return false;41 }40 return false; 41 } 42 42 } 43 43 return true; … … 50 50 51 51 if (!sources->n) { 52 psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping source magnitudes");53 return true;54 } 55 52 psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping source magnitudes"); 53 return true; 54 } 55 56 56 psTimerStart ("psphot.mags"); 57 57 … … 122 122 if (!psThreadJobAddPending(job)) { 123 123 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 124 psFree (job);125 124 return false; 126 125 } 127 psFree(job);128 126 129 127 # if (0) … … 184 182 } 185 183 186 // clear the mask bit and set the circular mask pixels187 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));188 psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", markVal);184 // clear the mask bit and set the circular mask pixels 185 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 186 psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", markVal); 189 187 190 188 status = pmSourceMagnitudes (source, psf, photMode, maskVal); // maskVal includes markVal 191 189 if (status && isfinite(source->apMag)) Nap ++; 192 190 193 // clear the mask bit 194 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));191 // clear the mask bit 192 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 195 193 196 194 // re-subtract the object, leave local sky … … 273 271 if (!psThreadJobAddPending(job)) { 274 272 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 275 psFree (job);276 273 return false; 277 274 } 278 psFree(job);279 280 275 } 281 276 -
trunk/psphot/src/psphotSourceStats.c
r28013 r28405 3 3 // convert detections to sources and measure their basic properties (moments, local sky, sky 4 4 // variance) Note: this function only generates sources for the new peaks (peak->assigned). 5 // The new sources are added to any existing sources on detections->newSources. The sources 5 // The new sources are added to any existing sources on detections->newSources. The sources 6 6 // on detections->allSources are ignored. 7 7 bool psphotSourceStats (pmConfig *config, const pmFPAview *view, const char *filerule, bool setWindow) … … 22 22 // loop over the available readouts 23 23 for (int i = 0; i < num; i++) { 24 // if (i == chisqNum) continue; // skip chisq image24 // if (i == chisqNum) continue; // skip chisq image 25 25 if (!psphotSourceStatsReadout (config, view, filerule, i, recipe, setWindow)) { 26 26 psError (PSPHOT_ERR_CONFIG, false, "failed to find initial detections for %s entry %d", filerule, i); … … 91 91 // generate the array of sources, define the associated pixel 92 92 if (!detections->newSources) { 93 detections->newSources = psArrayAllocEmpty (peaks->n);93 detections->newSources = psArrayAllocEmpty (peaks->n); 94 94 } 95 95 sources = detections->newSources; … … 107 107 // create a new source 108 108 pmSource *source = pmSourceAlloc(); 109 source->imageID = index;109 source->imageID = index; 110 110 111 111 // add the peak … … 184 184 if (!psThreadJobAddPending(job)) { 185 185 psError(PS_ERR_UNKNOWN, false, "Unable to launch thread job PSPHOT_SOURCE_STATS"); 186 psFree (job);187 186 psFree(detections->newSources); 188 187 return false; 189 188 } 190 psFree(job);191 189 } 192 190 … … 194 192 if (!psThreadPoolWait (false)) { 195 193 psError(PS_ERR_UNKNOWN, false, "Failure in thread job PSPHOT_SOURCE_STATS"); 196 psFree(detections->newSources);194 psFree(detections->newSources); 197 195 return false; 198 196 } … … 315 313 if (!psThreadJobAddPending(job)) { 316 314 psError(PS_ERR_UNKNOWN, false, "Unable to launch thread job PSPHOT_SOURCE_STATS"); 317 psFree (job);318 315 return NULL; 319 316 } 320 psFree(job);321 317 } 322 318 … … 380 376 pmSource *source = sources->data[i]; 381 377 382 if (source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED) continue;383 source->tmpFlags |= PM_SOURCE_TMPF_MOMENTS_MEASURED;378 if (source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED) continue; 379 source->tmpFlags |= PM_SOURCE_TMPF_MOMENTS_MEASURED; 384 380 385 381 // skip faint sources for moments measurement -
trunk/psphot/src/psphotTest.c
r24187 r28405 25 25 26 26 bool FillImage_Threaded (psThreadJob *job) { 27 27 28 28 psImage *image = job->args->data[0]; 29 29 int xs = PS_SCALAR_VALUE(job->args->data[1],S32); … … 36 36 psRegion region = psRegionSet (xs, xs + dx, ys, ys + dy); 37 37 for (int i = 0; i < 100; i++) { 38 psImage *subset = psImageSubset (image, region);39 psImageInit (subset, value + i);40 psFree (subset);38 psImage *subset = psImageSubset (image, region); 39 psImageInit (subset, value + i); 40 psFree (subset); 41 41 } 42 42 return true; … … 46 46 47 47 if (argc != 3) { 48 fprintf (stderr, "USAGE: psphotTest (output.fits) (nThreads)\n");49 exit (2);48 fprintf (stderr, "USAGE: psphotTest (output.fits) (nThreads)\n"); 49 exit (2); 50 50 } 51 51 … … 62 62 63 63 for (int ix = 0; ix < 1000; ix += 100) { 64 for (int iy = 0; iy < 1000; iy += 100) {64 for (int iy = 0; iy < 1000; iy += 100) { 65 65 66 // allocate a job -- if threads are not defined, this just runs the job67 psThreadJob *job = psThreadJobAlloc ("FILL_IMAGE");66 // allocate a job -- if threads are not defined, this just runs the job 67 psThreadJob *job = psThreadJobAlloc ("FILL_IMAGE"); 68 68 69 psArrayAdd(job->args, 1, image);70 PS_ARRAY_ADD_SCALAR(job->args, ix, PS_TYPE_S32);71 PS_ARRAY_ADD_SCALAR(job->args, iy, PS_TYPE_S32);72 PS_ARRAY_ADD_SCALAR(job->args, 100, PS_TYPE_S32);73 PS_ARRAY_ADD_SCALAR(job->args, 100, PS_TYPE_S32);74 PS_ARRAY_ADD_SCALAR(job->args, ix + iy, PS_TYPE_S32);69 psArrayAdd(job->args, 1, image); 70 PS_ARRAY_ADD_SCALAR(job->args, ix, PS_TYPE_S32); 71 PS_ARRAY_ADD_SCALAR(job->args, iy, PS_TYPE_S32); 72 PS_ARRAY_ADD_SCALAR(job->args, 100, PS_TYPE_S32); 73 PS_ARRAY_ADD_SCALAR(job->args, 100, PS_TYPE_S32); 74 PS_ARRAY_ADD_SCALAR(job->args, ix + iy, PS_TYPE_S32); 75 75 76 // FillImage (image, ix, iy, 100, 100, ix + iy);76 // FillImage (image, ix, iy, 100, 100, ix + iy); 77 77 78 if (!psThreadJobAddPending(job)) { 79 fprintf (stderr, "failure to run FillImage(1)"); 80 psFree (job); 81 exit (1); 82 } 83 psFree(job); 84 } 78 if (!psThreadJobAddPending(job)) { 79 fprintf (stderr, "failure to run FillImage(1)"); 80 exit (1); 81 } 82 } 85 83 } 86 84 … … 88 86 // wait for the threads to finish and manage results 89 87 if (!psThreadPoolWait (true)) { 90 fprintf (stderr, "failure to run FillImage (2)");91 exit (1);88 fprintf (stderr, "failure to run FillImage (2)"); 89 exit (1); 92 90 } 93 91 -
trunk/pswarp/src/pswarpTransformReadout.c
r28006 r28405 132 132 return false; 133 133 } 134 psFree(job);135 134 psFree(args); 136 135 }
Note:
See TracChangeset
for help on using the changeset viewer.
