Changeset 42507
- Timestamp:
- Aug 16, 2023, 10:31:04 AM (3 years ago)
- Location:
- branches/eam_branches/ipp-20230313/psphot/src
- Files:
-
- 5 edited
-
psphotArguments.c (modified) (2 diffs)
-
psphotFullForceArguments.c (modified) (2 diffs)
-
psphotFullForceReadout.c (modified) (1 diff)
-
psphotMakeResiduals.c (modified) (12 diffs)
-
psphotOutput.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20230313/psphot/src/psphotArguments.c
r36375 r42507 97 97 } 98 98 99 void psphotSaveConfig (pmConfig *config); 100 99 101 pmConfig *psphotArguments(int argc, char **argv) { 100 102 … … 244 246 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "", argv[1]); 245 247 248 // save a copy for deep retrieval 249 psphotSaveConfig (config); 250 246 251 psTrace("psphot", 1, "Done with psphotArguments...\n"); 247 252 return (config); -
branches/eam_branches/ipp-20230313/psphot/src/psphotFullForceArguments.c
r37941 r42507 3 3 static void usage(const char *program, psMetadata *arg, pmConfig *config, int exitCode); 4 4 static void writeHelpInfo(const char* program, pmConfig* config, FILE* ofile); 5 void psphotSaveConfig (pmConfig *config); 5 6 6 7 pmConfig *psphotFullForceArguments(int argc, char **argv) { … … 111 112 // output position is fixed 112 113 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "", argv[1]); 114 115 psphotSaveConfig (config); 113 116 114 117 psTrace("psphot", 1, "Done with psphotFullForceArguments...\n"); -
branches/eam_branches/ipp-20230313/psphot/src/psphotFullForceReadout.c
r37542 r42507 106 106 psphotKronFlux (config, view, filerule); 107 107 108 // Option to do the non-linear fitting for the brighter sources 109 if (1) { 110 // identify CRs and extended sources (only unmeasured sources are measured) 111 psphotSourceSize (config, view, filerule, true); // pass 1 (detections->allSources) 112 113 // non-linear PSF and EXT fit to brighter sources 114 // replace model flux, adjust mask as needed, fit, subtract the models (full stamp) 115 // XXX: can leave faulted job in done queue 116 psphotBlendFit (config, view, filerule); // pass 1 (detections->allSources) 117 118 // replace all sources 119 psphotReplaceAllSources (config, view, filerule, false); // pass 1 (detections->allSources) 120 121 // linear fit to include all sources (subtract again) 122 // NOTE : apply to ALL sources (extended + psf) 123 // do NOT skip negative-flux sources (last arg = false) 124 psphotFitSourcesLinear (config, view, filerule, true, false); // pass 2 (detections->allSources) 125 } 126 108 127 psphotChipParams (config, view, filerule); 109 128 -
branches/eam_branches/ipp-20230313/psphot/src/psphotMakeResiduals.c
r35559 r42507 1 1 # include "psphotInternal.h" 2 pmConfig *psphotGetConfig (); 3 bool _psphotSaveCube (char *basename, char *extname, psArray *cube); 2 4 3 5 # define RESIDUAL_SOFTENING 0.005 … … 93 95 psVector *yC = psVectorAllocEmpty (100, PS_TYPE_F32); 94 96 97 # define TESTRESID 1 98 # if (TESTRESID) 99 psArray *sourceRawCube = psArrayAllocEmpty (1); 100 psArray *sourceSigCube = psArrayAllocEmpty (1); 101 psArray *sourceVarCube = psArrayAllocEmpty (1); 102 psArray *sourceMskCube = psArrayAllocEmpty (1); 103 # endif 104 95 105 // build (DATA - MODEL) [an image] for each psf star 96 106 psArray *input = psArrayAllocEmpty (100); … … 108 118 psImage *mask = psImageCopy (NULL, source->maskView ? source->maskView : source->maskObj, PS_TYPE_IMAGE_MASK); 109 119 psImage *variance = psImageCopy (NULL, source->variance ? source->variance : source->pixels, PS_TYPE_F32); 120 121 # if (TESTRESID) 122 psImage *tmpImage = psImageCopy(NULL, image, PS_TYPE_F32); 123 psArrayAdd (sourceRawCube, 1, tmpImage); 124 psFree (tmpImage); 125 # endif 126 110 127 pmModelSub (image, mask, model, PM_MODEL_OP_FUNC, maskVal); 111 128 … … 114 131 psBinaryOp (image, image, "/", psScalarAlloc(Io, PS_TYPE_F32)); 115 132 psBinaryOp (variance, variance, "/", psScalarAlloc(Io*Io, PS_TYPE_F32)); 133 134 # if (TESTRESID) 135 psArrayAdd (sourceSigCube, 1, image); 136 psArrayAdd (sourceVarCube, 1, variance); 137 psArrayAdd (sourceMskCube, 1, mask); 138 # endif 116 139 117 140 // we interpolate the image and variance - include the mask or not? … … 141 164 pmResiduals *resid = pmResidualsAlloc (xSize, ySize, xBin, yBin); 142 165 psImageInit (resid->mask, 0); 166 167 168 # if (TESTRESID) 169 psArray *inputSigCube = psArrayAllocEmpty (1); 170 psArray *inputVarCube = psArrayAllocEmpty (1); 171 psArray *inputMskCube = psArrayAllocEmpty (1); 172 173 // below, we are generating the residual images with interpolation 174 // to save these in an output cube, I need to generate place-holder images here 175 for (int i = 0; i < input->n; i++) { 176 psImage *inputSig = psImageAlloc (resid->Ro->numCols, resid->Ro->numRows, PS_TYPE_F32); 177 psImage *inputVar = psImageAlloc (resid->Ro->numCols, resid->Ro->numRows, PS_TYPE_F32); 178 psImage *inputMsk = psImageAlloc (resid->Ro->numCols, resid->Ro->numRows, PS_TYPE_IMAGE_MASK); 179 180 psImageInit (inputSig, NAN); 181 psImageInit (inputVar, NAN); 182 psImageInit (inputMsk, 0); 183 184 psArrayAdd (inputSigCube, 1, inputSig); 185 psArrayAdd (inputVarCube, 1, inputVar); 186 psArrayAdd (inputMskCube, 1, inputMsk); 187 188 // XXX free these here, right? 189 psFree (inputSig); 190 psFree (inputVar); 191 psFree (inputMsk); 192 } 193 # endif 143 194 144 195 // x(resid) = (x(image) - Xo)*xBin + xCenter … … 194 245 nGoodPixel ++; 195 246 } 247 248 # if (TESTRESID) 249 psImage *inputSig = inputSigCube->data[i]; inputSig->data.F32[oy][ox] = flux; 250 psImage *inputVar = inputVarCube->data[i]; inputVar->data.F32[oy][ox] = flux; 251 psImage *inputMsk = inputMskCube->data[i]; inputMsk->data.PS_TYPE_IMAGE_MASK_DATA[oy][ox] = fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i]; 252 # endif 196 253 } 254 255 if (nGoodPixel < 0.05*input->n) { 256 fprintf (stderr, "warning: %d, %d : residual pixel with few input pixels: %d vs %d\n", ox, oy, nGoodPixel, (int) input->n); 257 } 197 258 198 259 // skip pixels with insufficient data … … 220 281 } 221 282 283 if (fabs(fluxClip->robustMedian) > 1.5) { 284 fprintf (stderr, "warning: %d, %d : residual pixel has funny initial median value: %f\n", ox, oy, fluxClip->robustMedian); 285 } 286 222 287 // mark input pixels which are more than N sigma from the median 223 288 int nKeep = 0; … … 233 298 if (!fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i]) nKeep++; 234 299 } 300 301 if (nKeep < 5) { 302 fprintf (stderr, "warning: %d, %d : residual pixel with few good pixels: %d vs %d\n", ox, oy, nKeep, (int) input->n); 303 } 235 304 236 305 if (SPATIAL_ORDER == 0) { … … 242 311 } 243 312 313 // XXX this test should go at the top of the loop 244 314 float radius = hypot((ox - 0.5*resid->Ro->numCols), (oy - 0.5*resid->Ro->numRows)); 245 315 if (radius > radiusMax) { … … 304 374 float dRo = sqrt(A->data.F32[0][0]); 305 375 376 if (fabs(B->data.F64[0]) > 1.5) { 377 fprintf (stderr, "warning: %d, %d : residual pixel has funny fit value: %f\n", ox, oy, B->data.F64[0]); 378 } 379 306 380 if (fabs(resid->Ro->data.F32[oy][ox]) < pixelSN*dRo/sqrt(nKeep)) { 307 381 resid->mask->data.PM_TYPE_RESID_MASK_DATA[oy][ox] = 1; … … 313 387 } 314 388 } 389 390 # if (TESTRESID) 391 392 pmConfig *config = psphotGetConfig(); 393 char *output = psMetadataLookupStr (&status, config->arguments, "OUTPUT"); 394 395 // XXX // save the star coordinate vectors 396 // XXX 397 // XXX psString filename = NULL; 398 // XXX psStringAppend (&filename, "%s.instar.dat", output); 399 400 char filename[1024]; 401 sprintf (filename, "%s.instar.dat", output); 402 403 FILE *fout = fopen (filename, "w"); 404 for (int i = 0; i < xC->n; i++) { 405 fprintf (fout, "%d %f %f\n", i, xC->data.F32[i], yC->data.F32[i]); 406 } 407 fclose (fout); 408 409 _psphotSaveCube (output, "raw.raw.fits", sourceRawCube); 410 _psphotSaveCube (output, "sig.raw.fits", sourceSigCube); 411 _psphotSaveCube (output, "var.raw.fits", sourceVarCube); 412 _psphotSaveCube (output, "msk.raw.fits", sourceMskCube); 413 414 _psphotSaveCube (output, "sig.fits", inputSigCube); 415 _psphotSaveCube (output, "var.fits", inputVarCube); 416 _psphotSaveCube (output, "msk.fits", inputMskCube); 417 418 psFree (sourceRawCube); 419 psFree (sourceSigCube); 420 psFree (sourceVarCube); 421 psFree (sourceMskCube); 422 423 psFree (inputSigCube); 424 psFree (inputVarCube); 425 psFree (inputMskCube); 426 427 # endif 315 428 316 429 psFree (A); … … 343 456 return (resid != NULL) ? true : false; 344 457 } 458 459 bool _psphotSaveCube (char *basename, char *extname, psArray *cube) { 460 461 psString filename = NULL; 462 psStringAppend (&filename, "%s.%s", basename, extname); 463 464 psFits *fits = psFitsOpen (filename, "w"); 465 if (!psFitsWriteImageCube (fits, NULL, cube, NULL)) { 466 fprintf (stderr, "failed to write the cube %s\n", filename); 467 } 468 psFitsClose (fits); 469 470 psFree (filename); 471 472 return true; 473 } -
branches/eam_branches/ipp-20230313/psphot/src/psphotOutput.c
r37590 r42507 1 1 # include "psphotInternal.h" 2 3 pmConfig *staticConfig = NULL; 4 5 void psphotSaveConfig (pmConfig *config) { 6 staticConfig = config; 7 } 8 9 pmConfig *psphotGetConfig () { 10 return staticConfig; 11 } 2 12 3 13 // convert filerule to filerule.NUM and look up in the config->arguments metadata
Note:
See TracChangeset
for help on using the changeset viewer.
