IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17935


Ignore:
Timestamp:
Jun 5, 2008, 3:29:09 AM (18 years ago)
Author:
eugene
Message:

added forced photometry code; compiles, not tested

Location:
branches/eam_branch_20080511/ppSim/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080511/ppSim/src/ppSimCreate.c

    r17818 r17935  
    2929  // generate the fpa structure used by the output camera (determined from INPUT or specified)
    3030  assert (config->camera);
    31   fpa = pmFPAConstruct(config->camera); // FPA to contain the observation
     31  fpa = pmFPAConstruct(config->camera, config->cameraName); // FPA to contain the observation
    3232  if (!fpa) {
    3333    psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to construct an FPA from camera configuration.");
  • branches/eam_branch_20080511/ppSim/src/ppSimInsertStars.c

    r17850 r17935  
    114114        source->errMag = sqrt(Area*PS_SQR(roughNoise) + flux) / flux;
    115115
    116         // XXX add the sources to a source array
    117 
    118116        // insert the source flux in the image
    119117        pmSourceAddWithOffset (source, PM_MODEL_OP_FULL, 0xff, dX, dY);
    120118        pmSourceAddWithOffset (source, PM_MODEL_OP_FULL | PM_MODEL_OP_NOISE, 0xff, dX, dY);
    121         psArrayAdd (sources, 100,source);
    122         psFree(source);                 // Drop reference
    123119
    124120        // Blow away the image parts of the source, which makes the memory explode
     
    130126        RESET(source->psfFlux);
    131127        RESET(source->blends);
     128
     129        // add the sources to the source array
     130        psArrayAdd (sources, 100,source);
     131        psFree(source);                 // Drop reference
    132132    }
    133133
  • branches/eam_branch_20080511/ppSim/src/ppSimLoadForceSources.c

    r17930 r17935  
    11# include "ppSim.h"
     2
     3// Reset a pointer: free and set to NULL
     4#define RESET(PTR) \
     5    psFree(PTR); \
     6    PTR = NULL;
    27
    38psArray *ppSimLoadForceSources(pmConfig *config, const pmFPAview *view) {
    49
    5     psArray *result = psArrayAlloc(0);
    6     return result;
     10    bool status;
    711
    8 # if (0)
     12    pmFPAfile *outFile = psMetadataLookupPtr(NULL, config->files, "PPSIM.OUTPUT");
     13    psAssert(outFile, "missing PPSIM.OUTPUT");
     14    psAssert(outFile->fpa, "missing fpr for PPSIM.OUTPUT");
    915
    10     // de-activate all files except PSASTRO.REFSTARS
    11     pmFPAfileActivate (config->files, false, NULL);
    12     pmFPAfileActivate (config->files, true, "PSASTRO.OUT.REFSTARS");
     16    pmChip *outChip = pmFPAviewThisChip (view, outFile->fpa);
     17    pmPSF *psf = psMetadataLookupPtr (&status, outChip->analysis, "PSPHOT.PSF");
     18    assert (psf);
    1319
    14     readout = pmFPAviewThisReadout (view, fpa);
    15     if (! readout->data_exists) { continue; }
     20    psArray *spots = psMetadataLookupPtr(&status, outFile->fpa->analysis, "FORCED.SPOTS");
     21    PS_ASSERT_PTR_NON_NULL (spots, NULL);
    1622
    17                 // read WCS data from the corresponding header
    18                 pmHDU *hdu = pmFPAviewThisHDU (view, fpa);
     23    // in this program, we are looping over the output image, rather than the input as in ppImage
     24    pmFPAfile *srcFile = psMetadataLookupPtr(NULL, config->files, "PPSIM.REAL.SOURCES");
     25    psAssert(srcFile, "missing PPSIM.REAL.SOURCES");
    1926
    20                 int Nx = psMetadataLookupS32 (&status, hdu->header, "NAXIS1");
    21                 int Ny = psMetadataLookupS32 (&status, hdu->header, "NAXIS2");
     27    pmFPA     *fpa     = srcFile->fpa;
     28    pmChip    *chip    = pmFPAviewThisChip (view, fpa);
     29    // pmCell    *cell    = pmFPAviewThisCell (view, fpa);
     30    pmReadout *readout = pmFPAviewThisReadout (view, fpa);
    2231
    23                 float minX = -fieldPadding*Nx;
    24                 float maxX = (1+fieldPadding)*Nx;
    25                 float minY = -fieldPadding*Ny;
    26                 float maxY = (1+fieldPadding)*Ny;
     32    // XXX we should have only one cell and readout per chip, right?
    2733
    28                 // the refstars is a subset within range of this chip
    29                 psArray *refstars = psArrayAllocEmpty (100);
     34    // read WCS from existing output from psphot & psastro
     35    // XXX can we be more flexible?  ie, use the header of PPSIM.CHIP?
     36    bool bilevelAstrometry = false;
     37    status = psastroAstromGuessSetFPA (fpa, &bilevelAstrometry);
     38    psAssert (status, "failed to set astrometry");
    3039
    31                 // select the reference objects within range of this readout
    32                 // project the reference objects to this chip
    33                 for (int i = 0; i < refs->n; i++) {
    34                     pmAstromObj *ref = pmAstromObjCopy(refs->data[index->data.S32[i]]);
     40    // the pixel scale is only used to set the focal-plane coordinate system
     41    // setting this value to 1 makes this system have the units of pixels
     42    float pixelScale = 1.0;
     43    status = psastroAstromGuessSetChip (fpa, chip, view, pixelScale, bilevelAstrometry);
     44    psAssert (status, "failed to set astrometry");
    3545
    36                     psProject (ref->TP, ref->sky, fpa->toSky);
    37                     psPlaneTransformApply (ref->FP, fpa->fromTPA, ref->TP);
    38                     psPlaneTransformApply (ref->chip, chip->fromFPA, ref->FP);
     46    float minX = 0.0;
     47    float maxX = readout->image->numCols;
     48    float minY = 0.0;
     49    float maxY = readout->image->numRows;
    3950
    40                     // limit the X,Y range of the refs to the selected chip
    41                     if (ref->chip->x < minX) goto skip;
    42                     if (ref->chip->x > maxX) goto skip;
    43                     if (ref->chip->y < minY) goto skip;
    44                     if (ref->chip->y > maxY) goto skip;
     51    // the sources is a subset within range of this chip
     52    psArray *sources = psArrayAllocEmpty (100);
    4553
    46                     psArrayAdd (refstars, 100, ref);
    47                 skip:
    48                     psFree (ref);
     54    // Select the spots within range of this readout.  Project the spots to this chip
     55    for (int i = 0; i < spots->n; i++) {
     56        pmAstromObj *obj = spots->data[i];
    4957
    50                     if (nMax && (refstars->n >= nMax)) break;
    51                 }
    52                 psTrace ("psastro", 4, "Added %ld refstars\n", refstars->n);
     58        psProject (obj->TP, obj->sky, fpa->toSky);
     59        psPlaneTransformApply (obj->FP, fpa->fromTPA, obj->TP);
     60        psPlaneTransformApply (obj->chip, chip->fromFPA, obj->FP);
    5361
    54                 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSASTRO.REFSTARS", PS_DATA_ARRAY, "astrometry matches", refstars);
    55                 psFree (refstars);
     62        // limit the X,Y range of the objs to the selected chip
     63        if (obj->chip->x < minX) continue;
     64        if (obj->chip->x > maxX) continue;
     65        if (obj->chip->y < minY) continue;
     66        if (obj->chip->y > maxY) continue;
    5667
    57                 if (matchLumFunc) {
    58                     // in this case, no PSASTRO.REFSTARS is added to readout->analysis
    59                     if (!psastroRefstarSubset (readout)) {
    60                         psError(PSASTRO_ERR_DATA, false, "Can't determine an appropriate refstar subset\n");
    61                         psFree (index);
    62                         psFree (view);
    63                         return false;
    64                     }
    65                 }
    66             }
    67         }
    68         if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
     68        // convert the pmAstromObj to pmSource
     69
     70        // instantiate a model for the PSF at this location, Io = 1.0
     71        pmModel *model = pmModelFromPSFforXY (psf, obj->chip->x, obj->chip->y, 1.0);
     72
     73        // XXX let the flux limit be a user-defined number of sky sigmas (not just 1.0)
     74        // XXX use a fixed radius??
     75        // float radius = model->modelRadius (model->params, roughNoise);
     76        // radius = PS_MAX (radius, 1.0);
     77        float radius = 5.0;
     78
     79        // construct a source, with model flux pixels set, based on the model
     80        pmSource *source = pmSourceFromModel (model, readout, radius, PM_SOURCE_TYPE_STAR);
     81
     82        // XXX set the mag & err values (should this be done in pmSourceFromModel?)
     83        // XXX i should be applying the gain and the correct effective area
     84        // psEllipseAxes axes = pmPSF_ModelToAxes (model->params->data.F32, 20.0);
     85        // psF64 Area = 2.0 * M_PI * axes.major * axes.minor;
     86
     87        // these are not really needed since we will be fitting for them
     88        source->psfMag = NAN;
     89        source->errMag = NAN;
     90
     91        // insert the source flux in the image
     92        // XXX not sure the offset is really 0,0
     93        pmSourceAddWithOffset (source, PM_MODEL_OP_FULL, 0xff, 0.0, 0.0);
     94        pmSourceAddWithOffset (source, PM_MODEL_OP_FULL | PM_MODEL_OP_NOISE, 0xff, 0.0, 0.0);
     95
     96        // Blow away the image parts of the source, which makes the memory explode
     97        RESET(source->pixels);
     98        RESET(source->weight);
     99        RESET(source->maskObj);
     100        RESET(source->maskView);
     101        RESET(source->modelFlux);
     102        RESET(source->psfFlux);
     103        RESET(source->blends);
     104
     105        psArrayAdd (sources, 100, source);
     106        psFree(source);                 // Drop local reference
    69107    }
    70     if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
     108    psTrace ("psastro", 4, "Added %ld sources\n", sources->n);
    71109
    72     // activate all files except PSASTRO.OUTPUT
    73 
    74     pmFPAfileActivate (config->files, true, NULL);
    75     pmFPAfileActivate (config->files, false, "PSASTRO.OUT.REFSTARS");
    76 # endif
    77 
    78     return NULL;
     110    return sources;
    79111}
  • branches/eam_branch_20080511/ppSim/src/ppSimLoadSpots.c

    r17930 r17935  
    11# include "ppSim.h"
    22
    3 // need to specify an alternative CATDIR for the force positions
    4 bool ppSimLoadSpots (psArray *spots, pmFPA *fpa, pmConfig *config) {
     3// Load the relevant forced-photometry positions for this field.  This function does not determine
     4// the pixel coordinates, merely the celestial coordinates for sources in the general vicinity.  The
     5// sources are saved on the fpa->analysis metadata as FORCED.SPOTS.  We always create an entry; it
     6// will be empty if no sources were selected or forced photometry is not desired.
     7bool ppSimLoadSpots (pmFPA *fpa, pmConfig *config) {
    58
    69    bool status;
     10
     11    psArray *spots = psArrayAllocEmpty (1);
     12    psMetadataAddPtr (fpa->analysis, PS_LIST_TAIL, "FORCED.SPOTS", PS_META_REPLACE, "forced photometry positions", spots);
     13    psFree (spots); // free the extra (local) reference; a copy remains on fpa->analysis
    714
    815    psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe
     
    1522    if (!astroRecipe) {
    1623        psError(PSASTRO_ERR_CONFIG, false, "Can't find recipe %s", PSASTRO_RECIPE);
    17         return NULL;
     24        return false;
    1825    }
    1926
     
    2229    float scale   = psMetadataLookupF32(NULL, recipe, "PIXEL.SCALE") * M_PI / 3600.0 / 180.0; // Plate scale (radians/pixel)
    2330
     31    char *catdir = psMetadataLookupStr(NULL, recipe, "FORCED.CATDIR");
     32    char *photcode = psMetadataLookupStr(NULL, recipe, "FORCED.PHOTCODE");
     33    float MAGmax = 100.0;
     34
    2435    // Size of FPA
    2536    psRegion *bounds = ppSimFPABounds (fpa);
     
    2738    psFree(bounds);
    2839
    29     float x0fpa = 0.5*(bounds->x0 + bounds->x1);
    30     float y0fpa = 0.5*(bounds->y0 + bounds->y1);
     40    // modify the PSASTRO recipe to use the values desired for FORCED.PHOT.  we can use a view on
     41    // the PSASTRO recipe because we are not calling psastro elsewhere in this program.  XXX need to
     42    // use the WCS to define the overlap region
     43    psMetadataAddStr(astroRecipe, PS_LIST_TAIL, "DVO.CATDIR",  PS_META_REPLACE, "", catdir);
     44    psMetadataAddF32(astroRecipe, PS_LIST_TAIL, "RA_MIN",  PS_META_REPLACE, "", ra0 - radius);
     45    psMetadataAddF32(astroRecipe, PS_LIST_TAIL, "RA_MAX",  PS_META_REPLACE, "", ra0 + radius);
     46    psMetadataAddF32(astroRecipe, PS_LIST_TAIL, "DEC_MIN", PS_META_REPLACE, "", dec0 - radius);
     47    psMetadataAddF32(astroRecipe, PS_LIST_TAIL, "DEC_MAX", PS_META_REPLACE, "", dec0 + radius);
     48   
     49    // XXX these two values are somewhat bogus: can we have psastroLoadRefstars optionally ignore photcode and MAGmax?
     50    psMetadataAddStr(astroRecipe, PS_LIST_TAIL, "DVO.GETSTAR.PHOTCODE",  PS_META_REPLACE, "", photcode);
     51    psMetadataAddF32(astroRecipe, PS_LIST_TAIL, "DVO.GETSTAR.MAG.MAX",  PS_META_REPLACE, "", MAGmax);
    3152
    32     // XXX need to use the WCS to define the overlap region
    33     psMetadataAdd(astroRecipe, PS_LIST_TAIL, "RA_MIN",  PS_DATA_F32 | PS_META_REPLACE, "", ra0 - radius);
    34     psMetadataAdd(astroRecipe, PS_LIST_TAIL, "RA_MAX",  PS_DATA_F32 | PS_META_REPLACE, "", ra0 + radius);
    35     psMetadataAdd(astroRecipe, PS_LIST_TAIL, "DEC_MIN", PS_DATA_F32 | PS_META_REPLACE, "", dec0 - radius);
    36     psMetadataAdd(astroRecipe, PS_LIST_TAIL, "DEC_MAX", PS_DATA_F32 | PS_META_REPLACE, "", dec0 + radius);
    3753    psArray *refStars = psastroLoadRefstars(config);
    3854    if (!refStars || refStars->n == 0) {
    3955        psError(PS_ERR_UNKNOWN, false, "Unable to find reference stars.");
    4056        psFree(refStars);
    41         return NULL;
     57        return false;
    4258    }
    4359    psLogMsg("ppSim", PS_LOG_INFO, "Adding %ld reference stars", refStars->n);
    4460
    4561    // convert the pmAstromObj sources to the storage format used by the CMF files
    46 
    47     long oldSize = spots->n;
    48     spots = psArrayRealloc (spots, oldSize + refStars->n);
    49 
    50     // Conversion loop
     62    psArrayRealloc (spots, refStars->n);
    5163    for (long i = 0; i < refStars->n; i++) {
    5264        ppSimStar *spot = ppSimStarAlloc ();
     
    6274        // spot->y = sin(pa) * xi + cos(pa) * eta + y0fpa;
    6375
    64         spots->data[oldSize + i] = star;
     76        spots->data[i] = spot;
    6577
    6678        psTrace("ppSim", 10, "Adding catalogue star: %.1f,%.1f --> %.2f\n", spot->x, spot->y, ref->Mag);
    6779    }
    6880
    69     // XXX these need to be saved on PSPHOT.INPUT.CMF
    7081    return true;
    7182}
  • branches/eam_branch_20080511/ppSim/src/ppSimLoop.c

    r17930 r17935  
    2727    int binning = psMetadataLookupS32(NULL, recipe, "BINNING"); // Binning in x and y
    2828
    29     psArray *spots = psArrayAllocEmpty (1);
    3029    psArray *stars = psArrayAllocEmpty (1);
    3130    psArray *galaxies = psArrayAllocEmpty (1);
    3231    if (type == PPSIM_TYPE_OBJECT) {
    33         // Load forced-photometry positions
    34         if (!ppSimLoadSpots (spots, fpa, config)) ESCAPE (PS_ERR_UNKNOWN, "failed to load forced-photometry spots");
     32        // Load forced-photometry positions (these are placed on fpa->analysis for use in ppSimPhotomReadout)
     33        if (!ppSimLoadSpots (fpa, config)) ESCAPE (PS_ERR_UNKNOWN, "failed to load forced-photometry spots");
    3534
    3635        // Load catalogue stars
  • branches/eam_branch_20080511/ppSim/src/ppSimPhotomReadout.c

    r17901 r17935  
    3737    }
    3838
     39# if 0   
    3940    // set the photcode for this image
    4041    if (!psphotAddPhotcode (recipe, config, view, "PPSIM.CHIP")) {
     
    4243        return false;
    4344    }
     45# endif
    4446
    4547    // find the currently selected readout.
     
    119121    psFree (sources); // only frees the merged references
    120122
    121     // linear fit to real + forced sources
    122     sources = ppSimMergeSources (realSources, forceSources);
    123     psphotFitSourcesLinear (readout, sources, recipe, psf, FALSE); // XXX option to NOT subtract
    124     psphotReplaceAllSources (sources, recipe);
    125     psFree (sources); // only frees the merged references
     123    // linear fit to real + forced sources (if any were selected)
     124    if (forceSources->n) {
     125      sources = ppSimMergeSources (realSources, forceSources);
     126      psphotFitSourcesLinear (readout, sources, recipe, psf, FALSE); // XXX option to NOT subtract
     127      psphotReplaceAllSources (sources, recipe);
     128      psFree (sources); // only frees the merged references
     129    }
    126130
    127131    // XXX do we need to measure aperture photometry corrections?
     
    157161    psMetadataAdd (fakeReadout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY, "fake photometry ", fakeSources);
    158162
    159     // psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PPSIM.FORCE.SOURCES", PS_DATA_ARRAY, "forced photometry ", forceSources);
     163    psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PPSIM.FORCE.SOURCES", PS_DATA_ARRAY, "forced photometry ", forceSources);
    160164    psFree (forceSources);
    161165    return true;
Note: See TracChangeset for help on using the changeset viewer.