IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 42507


Ignore:
Timestamp:
Aug 16, 2023, 10:31:04 AM (3 years ago)
Author:
eugene
Message:

add test code to examine the PSF residual inputs

Location:
branches/eam_branches/ipp-20230313/psphot/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20230313/psphot/src/psphotArguments.c

    r36375 r42507  
    9797}
    9898
     99void psphotSaveConfig (pmConfig *config);
     100
    99101pmConfig *psphotArguments(int argc, char **argv) {
    100102
     
    244246    psMetadataAddStr (config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "", argv[1]);
    245247
     248    // save a copy for deep retrieval
     249    psphotSaveConfig (config);
     250
    246251    psTrace("psphot", 1, "Done with psphotArguments...\n");
    247252    return (config);
  • branches/eam_branches/ipp-20230313/psphot/src/psphotFullForceArguments.c

    r37941 r42507  
    33static void usage(const char *program, psMetadata *arg, pmConfig *config, int exitCode);
    44static void writeHelpInfo(const char* program, pmConfig* config, FILE* ofile);
     5void psphotSaveConfig (pmConfig *config);
    56
    67pmConfig *psphotFullForceArguments(int argc, char **argv) {
     
    111112    // output position is fixed
    112113    psMetadataAddStr (config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "", argv[1]);
     114
     115    psphotSaveConfig (config);
    113116
    114117    psTrace("psphot", 1, "Done with psphotFullForceArguments...\n");
  • branches/eam_branches/ipp-20230313/psphot/src/psphotFullForceReadout.c

    r37542 r42507  
    106106    psphotKronFlux (config, view, filerule);
    107107
     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
    108127    psphotChipParams (config, view, filerule);
    109128
  • branches/eam_branches/ipp-20230313/psphot/src/psphotMakeResiduals.c

    r35559 r42507  
    11# include "psphotInternal.h"
     2pmConfig *psphotGetConfig ();
     3bool _psphotSaveCube (char *basename, char *extname, psArray *cube);
    24
    35# define RESIDUAL_SOFTENING 0.005
     
    9395    psVector *yC = psVectorAllocEmpty (100, PS_TYPE_F32);
    9496
     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
    95105    // build (DATA - MODEL) [an image] for each psf star
    96106    psArray *input = psArrayAllocEmpty (100);
     
    108118        psImage *mask     = psImageCopy (NULL, source->maskView ? source->maskView : source->maskObj,  PS_TYPE_IMAGE_MASK);
    109119        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
    110127        pmModelSub (image, mask, model, PM_MODEL_OP_FUNC, maskVal);
    111128
     
    114131        psBinaryOp (image, image, "/", psScalarAlloc(Io, PS_TYPE_F32));
    115132        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
    116139
    117140        // we interpolate the image and variance - include the mask or not?
     
    141164    pmResiduals *resid = pmResidualsAlloc (xSize, ySize, xBin, yBin);
    142165    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
    143194
    144195    // x(resid) = (x(image) - Xo)*xBin + xCenter
     
    194245                    nGoodPixel ++;
    195246                }
     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
    196253            }
     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            }
    197258
    198259            // skip pixels with insufficient data
     
    220281            }
    221282
     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
    222287            // mark input pixels which are more than N sigma from the median
    223288            int nKeep = 0;
     
    233298                if (!fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i]) nKeep++;
    234299            }
     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            }
    235304
    236305            if (SPATIAL_ORDER == 0) {
     
    242311                }
    243312
     313                // XXX this test should go at the top of the loop
    244314                float radius = hypot((ox - 0.5*resid->Ro->numCols), (oy - 0.5*resid->Ro->numRows));
    245315                if (radius > radiusMax) {
     
    304374                float dRo = sqrt(A->data.F32[0][0]);
    305375
     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
    306380                if (fabs(resid->Ro->data.F32[oy][ox]) < pixelSN*dRo/sqrt(nKeep)) {
    307381                  resid->mask->data.PM_TYPE_RESID_MASK_DATA[oy][ox] = 1;
     
    313387        }
    314388    }
     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
    315428
    316429    psFree (A);
     
    343456    return (resid != NULL) ? true : false;
    344457}
     458
     459bool _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  
    11# include "psphotInternal.h"
     2
     3pmConfig *staticConfig = NULL;
     4
     5void psphotSaveConfig (pmConfig *config) {
     6  staticConfig = config;
     7}
     8
     9pmConfig *psphotGetConfig () {
     10  return staticConfig;
     11}
    212
    313// convert filerule to filerule.NUM and look up in the config->arguments metadata
Note: See TracChangeset for help on using the changeset viewer.