IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 8, 2008, 4:03:31 PM (18 years ago)
Author:
eugene
Message:

update from changes on eam_branch_20080511 : adding photometry of fake sources, force photometry; major cleanups

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppSim/src/ppSimLoadSpots.c

    r17628 r18011  
    1 #include "ppSim.h"
     1# include "ppSim.h"
    22
     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.
    37bool ppSimLoadSpots (pmFPA *fpa, pmConfig *config) {
    48
    5     bool mdok;
    6     assert (stars);
     9    bool status;
    710
    8     psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSIM_RECIPE); // Recipe
    911
    10     bool forcedPhot = psMetadataLookupBool(&mdok, recipe, "FORCED.PHOT"); // Density of fakes
    11     if (!forcedPhot) return true;
     12    psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe
    1213
    13     // Read catalogue stars using psastro
    14     // XXX probably need to modify this...
     14    bool forcedPhot = psMetadataLookupBool(&status, recipe, "FORCED.PHOT"); // Density of fakes
     15    if (!forcedPhot) {
     16        psArray *spots = psArrayAllocEmpty (1);
     17        psMetadataAddArray (fpa->analysis, PS_LIST_TAIL, "FORCED.SPOTS", PS_META_REPLACE, "forced photometry positions", spots);
     18        psFree (spots); // free the extra (local) reference; a copy remains on fpa->analysis
     19        return true;
     20    }
     21
     22    // We read the catalogue stars using psastroLoadRefstars
    1523    psMetadata *astroRecipe = psMetadataLookupPtr(NULL, config->recipes, PSASTRO_RECIPE);
    1624    if (!astroRecipe) {
    1725        psError(PSASTRO_ERR_CONFIG, false, "Can't find recipe %s", PSASTRO_RECIPE);
    18         return NULL;
     26        return false;
    1927    }
     28
     29    float ra0     = psMetadataLookupF32(NULL, recipe, "RA");        // Boresight RA (radians)
     30    float dec0    = psMetadataLookupF32(NULL, recipe, "DEC");       // Boresight Dec (radians)
     31    float scale   = psMetadataLookupF32(NULL, recipe, "PIXEL.SCALE") * M_PI / 3600.0 / 180.0; // Plate scale (radians/pixel)
     32
     33    if (isnan(ra0) || isnan(dec0)) {
     34        psError(PS_ERR_UNKNOWN, false, "image boresite coords not defined.");
     35        return false;
     36    }
     37
     38    char *catdir = psMetadataLookupStr(NULL, recipe, "FORCED.CATDIR");
    2039
    2140    // Size of FPA
     
    2443    psFree(bounds);
    2544
    26     float x0fpa = 0.5*(bounds->x0 + bounds->x1);
    27     float y0fpa = 0.5*(bounds->y0 + bounds->y1);
     45    // modify the PSASTRO recipe to use the values desired for FORCED.PHOT.  we can use a view on
     46    // the PSASTRO recipe because we are not calling psastro elsewhere in this program.  XXX need to
     47    // use the WCS to define the overlap region
     48    psMetadataAddStr(astroRecipe, PS_LIST_TAIL, "DVO.CATDIR",  PS_META_REPLACE, "", catdir);
     49    psMetadataAddF32(astroRecipe, PS_LIST_TAIL, "RA_MIN",  PS_META_REPLACE, "", ra0 - radius);
     50    psMetadataAddF32(astroRecipe, PS_LIST_TAIL, "RA_MAX",  PS_META_REPLACE, "", ra0 + radius);
     51    psMetadataAddF32(astroRecipe, PS_LIST_TAIL, "DEC_MIN", PS_META_REPLACE, "", dec0 - radius);
     52    psMetadataAddF32(astroRecipe, PS_LIST_TAIL, "DEC_MAX", PS_META_REPLACE, "", dec0 + radius);
     53   
     54    // tell psastroLoadRefstars to ignore photcode and maglim
     55    psMetadataAddStr(astroRecipe, PS_LIST_TAIL, "DVO.GETSTAR.PHOTCODE",  PS_META_REPLACE, "", "NONE");
     56    psMetadataAddF32(astroRecipe, PS_LIST_TAIL, "DVO.GETSTAR.MAG.MAX",  PS_META_REPLACE, "", NAN);
    2857
    29     // XXX need to use the WCS to define the overlap region
    30     psMetadataAdd(astroRecipe, PS_LIST_TAIL, "RA_MIN",  PS_DATA_F32 | PS_META_REPLACE, "", ra0 - radius);
    31     psMetadataAdd(astroRecipe, PS_LIST_TAIL, "RA_MAX",  PS_DATA_F32 | PS_META_REPLACE, "", ra0 + radius);
    32     psMetadataAdd(astroRecipe, PS_LIST_TAIL, "DEC_MIN", PS_DATA_F32 | PS_META_REPLACE, "", dec0 - radius);
    33     psMetadataAdd(astroRecipe, PS_LIST_TAIL, "DEC_MAX", PS_DATA_F32 | PS_META_REPLACE, "", dec0 + radius);
    34     psArray *refStars = psastroLoadRefstars(config);
    35     if (!refStars || refStars->n == 0) {
     58    // load refstars from the catalog
     59    psArray *spots = psastroLoadRefstars(config);
     60    if (!spots || spots->n == 0) {
    3661        psError(PS_ERR_UNKNOWN, false, "Unable to find reference stars.");
    37         psFree(refStars);
    38         return NULL;
     62        psFree(spots);
     63        return false;
    3964    }
    40     psLogMsg("ppSim", PS_LOG_INFO, "Adding %ld reference stars", refStars->n);
     65    psLogMsg("ppSim", PS_LOG_INFO, "Adding %ld reference stars", spots->n);
    4166
    42     // convert the pmAstromObj sources to the storage format used by the CMF files
     67    psMetadataAddArray (fpa->analysis, PS_LIST_TAIL, "FORCED.SPOTS", PS_META_REPLACE, "forced photometry positions", spots);
     68    psFree (spots); // free the extra (local) reference; a copy remains on fpa->analysis
    4369
    44     long oldSize = stars->n;
    45     stars = psArrayRealloc (stars, refStars->n);
    46 
    47     // Conversion loop
    48     for (long i = 0; i < refStars->n; i++) {
    49         ppSimStar *star = ppSimStarAlloc ();
    50 
    51         pmAstromObj *ref = refStars->data[i]; // Reference star
    52         star->ra  = ref->sky->r; // RA of star
    53         star->dec = ref->sky->d; // Dec of star
    54         star->mag = ref->Mag;       // Magnitude of star
    55 
    56         // Apply rotation, make FPA center of boresite
    57         // convert the ra,dec to x,y using examples in psastro.
    58         // star->x = cos(pa) * xi - sin(pa) * eta + x0fpa;
    59         // star->y = sin(pa) * xi + cos(pa) * eta + y0fpa;
    60 
    61         stars->data[oldSize + i] = star;
    62 
    63         psTrace("ppSim", 10, "Adding catalogue star: %.1f,%.1f --> %.2f\n", star->x, star->y, star->flux);
    64     }
    65 
    66     // XXX these need to be saved on PSPHOT.INPUT.CMF
    6770    return true;
    6871}
Note: See TracChangeset for help on using the changeset viewer.