IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4129


Ignore:
Timestamp:
Jun 6, 2005, 11:20:45 PM (21 years ago)
Author:
eugene
Message:

further basic concepts

Location:
trunk/psphot
Files:
2 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot

    • Property svn:ignore set to
      bin
  • trunk/psphot/Makefile

    r4114 r4129  
    3232$(SRC)/mark_psf_sources.$(ARCH).o \
    3333$(SRC)/subtract_psf_sources.$(ARCH).o \
     34$(SRC)/mark_psf_source.$(ARCH).o \
     35$(SRC)/subtract_psf_source.$(ARCH).o \
     36$(SRC)/by_SN.$(ARCH).o \
    3437$(SRC)/fit_galaxies.$(ARCH).o \
    35 $(SRC)/subtract_galaxies.$(ARCH).o
     38$(SRC)/subtract_galaxies.$(ARCH).o \
     39$(SRC)/find_defects.$(ARCH).o
    3640
    3741psphot: $(BIN)/psphot.$(ARCH)
  • trunk/psphot/src/apply_psf_model.c

    r4116 r4129  
    2525
    2626    float shapeNsigma = psMetadataLookupF32 (&status, config, "PSF_SHAPE_NSIGMA");
    27     float snFaint     = psMetadataLookupF32 (&status, config, "FAINT_SN_LIM");
     27    // float snFaint     = psMetadataLookupF32 (&status, config, "FAINT_SN_LIM");
    2828
    2929    // set the object surface-brightness limit for fitted pixels
     
    6666        Nfit ++;
    6767
    68         mark_psf_source (source);
     68        mark_psf_source (source, shapeNsigma);
    6969        subtract_psf_source (source);
    7070    }
  • trunk/psphot/src/by_SN.c

    r4115 r4129  
    11# include "psphot.h"
    22
     3// sort by SN (descending)
    34int by_SN (const void **a, const void **b)
    45{
    5     psSource *A = *a;
    6     psSource *B = *b;
     6    psSource *A = *(psSource **)a;
     7    psSource *B = *(psSource **)b;
    78
    89    psF32 fA = (A->moments == NULL) ? 0 : A->moments->SN;
     
    1011
    1112    psF32 diff = fA - fB;
    12     if (diff < FLT_EPSILON) return (-1);
    13     if (diff > FLT_EPSILON) return (+1);
     13    if (diff > FLT_EPSILON) return (-1);
     14    if (diff < FLT_EPSILON) return (+1);
    1415    return (0);
    1516}
  • trunk/psphot/src/choose_psf_model.c

    r4115 r4129  
    2020        psArrayAdd (stars, 200, source);
    2121    }
     22    psTrace (".psphot.pspsf", 3, "selected candidate %d PSF objects\n", stars->n);
    2223
    2324    // define model fit pixels
  • trunk/psphot/src/mark_psf_source.c

    r4116 r4129  
    1414// any object which meets the criterion is marked as
    1515// PS_SOURCE_BRIGHTSTAR
    16 bool mark_psf_source (psArray *sources)
     16bool mark_psf_source (psSource *source, float shapeNsigma)
    1717{
    18     bool  status      = false;
    1918    float dSX, dSY, SX, SY, SN;
    2019    float nSx, nSy;
  • trunk/psphot/src/psPolynomials.c

    r4116 r4129  
    233233    // Build the B and A data structs.
    234234    for (int k = 0; k < x->n; k++) {
    235         if ((mask != NULL) && mask->U8[k]) continue;
     235        if ((mask != NULL) && mask->data.U8[k]) continue;
    236236        xSums = BuildSums1D(xSums, x->data.F64[k], nTerm);
    237237     
     
    325325    // Build the B and A data structs.
    326326    for (int k  = 0; k < x->n; k++) {
    327       if ((mask != NULL) && mask->data.U8[i]) continue;
     327      if ((mask != NULL) && mask->data.U8[k]) continue;
    328328        Sums = BuildSums2D(Sums, x->data.F64[k], y->data.F64[k], nXterm, nYterm);
    329329     
  • trunk/psphot/src/psUtils.c

    r4114 r4129  
    261261}
    262262   
     263bool psImageInit (psImage *image,...) {
     264
     265  va_list argp;
     266  psU8  vU8;
     267  psF32 vF32;
     268  psF64 vF64;
     269
     270  if (image == NULL) return (false);
     271
     272  va_start (argp, image);
     273
     274  switch (image->type.type) {
     275    case PS_TYPE_U8:
     276      vU8 = va_arg (argp, psU32);
     277
     278      for (int iy = 0; iy < image->numRows; iy++) {
     279        for (int ix = 0; ix < image->numCols; ix++) {
     280          image->data.U8[iy][ix] = vU8;
     281        }
     282      }
     283      break;
     284
     285    case PS_TYPE_F32:
     286      vF32 = va_arg (argp, psF64);
     287     
     288      for (int iy = 0; iy < image->numRows; iy++) {
     289        for (int ix = 0; ix < image->numCols; ix++) {
     290          image->data.F32[iy][ix] = vF32;
     291        }
     292      }
     293      return (true);
     294
     295    case PS_TYPE_F64:
     296      vF64 = va_arg (argp, psF64);
     297
     298      for (int iy = 0; iy < image->numRows; iy++) {
     299        for (int ix = 0; ix < image->numCols; ix++) {
     300          image->data.F64[iy][ix] = vF64;
     301        }
     302      }
     303      return (true);
     304
     305    default:
     306      psAbort ("psphot.psUtils", "datatype %d not defined in psImageInit\n", image->type);
     307      return (false);
     308  }
     309  return (false);
     310}           
  • trunk/psphot/src/psphot.c

    r4115 r4129  
    11# include "psphot.h"
     2void dump_image (psImage *image, char *filename);
    23
    34int main (int argc, char **argv) {
     
    3334    psf = choose_psf_model (image, config, sources);
    3435
     36    psImage *zap = psImageAlloc (image->numCols, image->numRows, PS_TYPE_F32);
     37    psImageInit (zap, 0);
     38    find_defects (zap, sources, config, psf);
     39    dump_image (zap, argv[2]);
     40    exit (0);
     41
    3542    // test PSF on all except SATURATE and DEFECT (artifacts)
    3643    apply_psf_model (image, config, sources, psf, sky);
     
    4451    // subtract_galaxies (sources, config);
    4552 
    46     // write out subtracted image
    47     unlink (argv[2]);
    48     psFits *fits = psFitsAlloc (argv[2]);
    49     psFitsWriteImage (fits, NULL, image, 0, NULL);
    50     psFree (fits);
    51 
     53    dump_image (image, argv[2]);
    5254    DumpModelPSF (sources, "sources.dat");
    5355    exit (0);
     
    5961    exit (2);
    6062}
     63
     64void dump_image (psImage *image, char *filename) {
     65
     66    unlink (filename);
     67    psFits *fits = psFitsAlloc (filename);
     68    psFitsWriteImage (fits, NULL, image, 0, NULL);
     69    psFree (fits);
     70    return;
     71}
     72
  • trunk/psphot/src/psphot.h

    r4115 r4129  
    2121psF64 psTimerMark (char *name);
    2222
     23bool psImageInit (psImage *image,...);
    2324void psImageSmooth (psImage *image, float sigma, float Nsigma);
    2425psRegion *psRegionForImage (psRegion *out, psImage *image, psRegion *in);
     
    4041psF32 Polynomial2DEval(const psPolynomial2D* myPoly, psF32 x, psF32 y);
    4142psImage *psBuildSums2D(psImage* sums,psF64 x,psF64 y,psS32 nXterm, psS32 nYterm);
    42 psPolynomial1D* VectorFitPolynomial1DOrd_EAM(psPolynomial1D* myPoly, const psVector* x, const psVector* y, const psVector* yErr);
    43 psPolynomial2D* VectorFitPolynomial2DOrd_EAM(psPolynomial2D* myPoly, const psVector* x, const psVector* y, const psVector* z, const psVector* zErr);
     43psPolynomial1D* VectorFitPolynomial1DOrd_EAM(psPolynomial1D* myPoly, psVector* mask, const psVector* x, const psVector* y, const psVector* yErr);
     44psPolynomial2D* VectorFitPolynomial2DOrd_EAM(psPolynomial2D* myPoly, psVector* mask, const psVector* x, const psVector* y, const psVector* z, const psVector* zErr);
    4445psPolynomial2D* Polynomial2DAlloc(psS32 nXorder, psS32 nYorder, psPolynomialType type);
    4546void psPolynomial2DDump (psPolynomial2D *poly);
    46 psPolynomial2D* RobustFit2D(psPolynomial2D* poly, const psVector* x, const psVector* y, const psVector* z, const psVector* zErr);
     47psPolynomial2D* RobustFit2D_nomask(psPolynomial2D* poly, const psVector* x, const psVector* y, const psVector* z, const psVector* zErr);
     48psPolynomial2D* RobustFit2D(psPolynomial2D* poly, psVector* mask, const psVector* x, const psVector* y, const psVector* z, const psVector* zErr);
    4749psVector *Polynomial2DEvalVector(const psPolynomial2D *myPoly, const psVector *x,const psVector *y);
    4850psVector *psBuildSums1D(psVector* sums, psF64 x,psS32 nTerm);
     
    5860pmPSF_Test *pmPSF_TestModel (psArray *stars, char *modelName);
    5961
    60 bool pmPSFFromModels (pmPSF *psf, psArray *models);
     62bool pmPSFFromModels (pmPSF *psf, psArray *models, psVector *mask);
    6163psModel *psModelFromPSF (psModel *model, pmPSF *psf);
    6264void pmSourceMaskRegion (psSource *source, psRegion *region);
     
    7577bool fit_galaxies (psImage *image, psMetadata *config, psArray *sources);
    7678bool subtract_galaxies (psArray *sources, psMetadata *config);
     79
     80int by_SN (const void **a, const void **b);
     81bool subtract_psf_source (psSource *source);
     82bool mark_psf_source (psSource *source, float shapeNsigma);
     83bool find_defects (psImage *zapmask, psArray *sources, psMetadata *config, pmPSF *psf);
  • trunk/psphot/src/pspsf.c

    r4116 r4129  
    6868    }
    6969    psLogMsg ("psphot.psftest", 4, "fit flt:   %f sec for %d sources\n", psTimerMark ("fit"), sources->n);
     70    psTrace ("psphot.psftest", 3, "keeping %d of %d PSF candidates (FLT)\n", Nflt, sources->n);
    7071    DumpModelFits (test->modelFLT, "modelsFLT.dat");
    7172
    7273    // stage 2: construct a psf (pmPSF) from this collection of model fits
    7374    pmPSFFromModels (test->psf, test->modelFLT, test->mask);
     75   
     76    // count valid sources
     77    int Nkeep = 0;
     78    for (int i = 0; i < sources->n; i++) {
     79      if (test->mask->data.U8[i]) continue;
     80      Nkeep++;
     81    }
     82    psTrace ("psphot.psftest", 3, "keeping %d of %d PSF candidates\n", Nkeep, sources->n);
    7483
    7584    // stage 3: refit with fixed shape parameters
     
    96105    }
    97106    psLogMsg ("psphot.psftest", 4, "fit psf:   %f sec for %d sources\n", psTimerMark ("fit"), sources->n);
     107    psTrace ("psphot.psftest", 3, "keeping %d of %d PSF candidates (PSF)\n", Npsf, sources->n);
    98108    DumpModelFits (test->modelPSF, "modelsPSF.dat");
    99109
     
    152162bool pmPSFFromModels (pmPSF *psf, psArray *models, psVector *mask) {
    153163
    154     int n;
    155 
    156164    // construct the fit vectors from the collection of objects
    157165    // use the mask to ignore missing fits
     
    187195        psf->params->data[i] = RobustFit2D (psf->params->data[i], mask, x, y, z, dz);
    188196        // psPolynomial2DDump (psf->params->data[i]);
     197
     198        // count valid sources
     199        int Nkeep = 0;
     200        for (int j = 0; j < mask->n; j++) {
     201          if (mask->data.U8[j]) continue;
     202          Nkeep++;
     203        }
     204        psTrace ("psphot.psftest", 3, "keeping %d of %d PSF candidates (PSF param %d)\n", Nkeep, mask->n, i);
     205
    189206    }
    190207    return (true);
  • trunk/psphot/src/source_moments.c

    r4114 r4129  
    1818    psRegion *keep = psRegionAlloc (XBORDER, -XBORDER, YBORDER, -YBORDER);
    1919    keep           = psRegionForImage (keep, image, keep);
    20     peaks          = pmPeaksSubset (allpeaks, 100000, keep);
    21 
    2220    // I need to exclude the saturated objects here, but include them again later...?
    2321    peaks          = pmPeaksSubset (allpeaks, 100000, keep);
  • trunk/psphot/src/subtract_galaxies.c

    r4114 r4129  
    55bool subtract_galaxies (psArray *sources, psMetadata *config)
    66{
    7     bool  status;
    8 
    97    for (int i = 0; i < sources->n; i++) {
    108        psSource *source = sources->data[i];
  • trunk/psphot/src/subtract_psf_source.c

    r4116 r4129  
    44// need to control application of this with some thresholding
    55
    6 bool subtract_psf_sources (psSource *source)
     6bool subtract_psf_source (psSource *source)
    77{
    88  float sky;
    9   psSource *source = sources->data[i];
    109
    1110  // non-stellar sources are ignored
     
    1514  psModel *model = source->modelPSF;
    1615  if (model == NULL) {
    17     psLogMsg ("psphot.subtract_psf_source", "missing model for %f, %f\n", source->moments->x, source->moments->y);
     16    psLogMsg ("psphot.subtract_psf_source", 2, "missing model for %f, %f\n", source->moments->x, source->moments->y);
    1817    return (false);
    1918  }         
  • trunk/psphot/src/test_psf_scatter.c

    r4115 r4129  
    7070    snBin ->n = bin;
    7171
     72    // XXX these APIs should get changed
    7273    psPolynomial1D *dsxLine = psPolynomial1DAlloc (2, PS_POLYNOMIAL_ORD);
    73     psVectorFitPolynomial1D (dsxLine, NULL, snBin, dsxBin, NULL);
     74    psVectorFitPolynomial1D (dsxLine, snBin, dsxBin, NULL);
    7475    psPolynomial1D *dsyLine = psPolynomial1DAlloc (2, PS_POLYNOMIAL_ORD);
    75     psVectorFitPolynomial1D (dsyLine, NULL, snBin, dsyBin, NULL);
     76    psVectorFitPolynomial1D (dsyLine, snBin, dsyBin, NULL);
    7677    // these should have a slope of 1.0
    7778    psPolynomial1DDump (dsxLine);
Note: See TracChangeset for help on using the changeset viewer.