IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 25, 2008, 3:04:38 PM (18 years ago)
Author:
Paul Price
Message:

Propagate more source characteristics, esp the mode (specifies CR/EXT).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pswarp/src/pswarpTransformSources.c

    r18839 r19200  
    2424    psArray *outSources = psMemIncrRefCounter(psMetadataLookupPtr(&mdok, output->analysis, "PSPHOT.SOURCES")); // Target sources
    2525    if (!outSources) {
    26         outSources = psArrayAllocEmpty(SOURCE_ARRAY_BUFFER);
    27         psMetadataAddPtr(output->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY,
    28                         "Warped sources", outSources);
     26        outSources = psArrayAllocEmpty(SOURCE_ARRAY_BUFFER);
     27        psMetadataAddPtr(output->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY,
     28                        "Warped sources", outSources);
    2929    }
    3030
     
    3333    // this does not cost us so much time.
    3434    for (int i = 0; i < inSources->n; i++) {
    35         pmSource *source = inSources->data[i]; // Source of interest
    36         pmModel *model = source->modelPSF; // Model for this source
    37         float xIn, yIn;             // Coordinates of source
    38         xIn = model->params->data.F32[PM_PAR_XPOS] - input->image->col0;
    39         yIn = model->params->data.F32[PM_PAR_YPOS] - input->image->row0;
     35        pmSource *source = inSources->data[i]; // Source of interest
     36        pmModel *model = source->modelPSF; // Model for this source
     37        float xIn, yIn;             // Coordinates of source
     38        xIn = model->params->data.F32[PM_PAR_XPOS] - input->image->col0;
     39        yIn = model->params->data.F32[PM_PAR_YPOS] - input->image->row0;
    4040
    41         int xGrid, yGrid;           // Grid coordinates for local map
    42         if (!pswarpMapGridSetGrid(sourceGrid, xIn + 0.5, yIn + 0.5, &xGrid, &yGrid)) {
    43             psError(PS_ERR_UNKNOWN, false, "Unable to get grid coordinates for source at %f,%f\n",
    44                     xIn, yIn);
    45             psFree(outSources);
    46             psFree(sourceGrid);
    47             return false;
    48         }
    49         if (xGrid < 0 || xGrid >= sourceGrid->nXpts || yGrid < 0 || yGrid >= sourceGrid->nYpts) {
    50             // It's not even on the grid
    51             // XXX how can this happen?
    52             continue;
    53         }
     41        int xGrid, yGrid;           // Grid coordinates for local map
     42        if (!pswarpMapGridSetGrid(sourceGrid, xIn + 0.5, yIn + 0.5, &xGrid, &yGrid)) {
     43            psError(PS_ERR_UNKNOWN, false, "Unable to get grid coordinates for source at %f,%f\n",
     44                    xIn, yIn);
     45            psFree(outSources);
     46            psFree(sourceGrid);
     47            return false;
     48        }
     49        if (xGrid < 0 || xGrid >= sourceGrid->nXpts || yGrid < 0 || yGrid >= sourceGrid->nYpts) {
     50            // It's not even on the grid
     51            // XXX how can this happen?
     52            continue;
     53        }
    5454
    55         pswarpMap *map = sourceGrid->maps[xGrid][yGrid]; // Locally linear transformation
    56         double xOut, yOut;          // Output coordinates
    57         if (!pswarpMapApply(&xOut, &yOut, map, xIn + 0.5, yIn + 0.5)) {
    58             psError(PS_ERR_UNKNOWN, false, "Unable to transform coordinates for source at %f,%f\n",
    59                     xIn, yIn);
    60             psFree(outSources);
    61             psFree(sourceGrid);
    62             return false;
    63         }
    64         xOut += output->image->col0 - 0.5;
    65         yOut += output->image->row0 - 0.5;
    66         if (xOut < minX || xOut > maxX || yOut < minY || yOut > maxY) {
    67             // It's not in the output image
    68             continue;
    69         }
     55        pswarpMap *map = sourceGrid->maps[xGrid][yGrid]; // Locally linear transformation
     56        double xOut, yOut;          // Output coordinates
     57        if (!pswarpMapApply(&xOut, &yOut, map, xIn + 0.5, yIn + 0.5)) {
     58            psError(PS_ERR_UNKNOWN, false, "Unable to transform coordinates for source at %f,%f\n",
     59                    xIn, yIn);
     60            psFree(outSources);
     61            psFree(sourceGrid);
     62            return false;
     63        }
     64        xOut += output->image->col0 - 0.5;
     65        yOut += output->image->row0 - 0.5;
     66        if (xOut < minX || xOut > maxX || yOut < minY || yOut > maxY) {
     67            // It's not in the output image
     68            continue;
     69        }
    7070
    71         // Generate the new source in the output frame
    72         pmSource *new = pmSourceAlloc(); // New source
    73         new->peak = pmPeakAlloc(xOut, yOut, source->peak->flux, PM_PEAK_LONE);
    74         new->peak->flux = source->peak->flux;
    75         new->type = PM_SOURCE_TYPE_STAR;
    76         new->psfMag = source->psfMag;
    77         new->errMag = source->errMag;
    78         new->sky = source->sky;
    79         new->skyErr = source->skyErr;
    80         new->pixWeight = source->pixWeight;
    81         new->modelPSF = pmModelAlloc(source->modelPSF->type);
     71        // Generate the new source in the output frame
     72        //
     73        // Magnitudes will be off if there's any change in scale, but for our purposes (mainly x,y and
     74        // relative flux) that's OK.
     75        pmSource *new = pmSourceAlloc(); // New source
     76        new->peak = pmPeakAlloc(xOut, yOut, source->peak->flux, PM_PEAK_LONE);
     77        new->peak->flux = source->peak->flux;
     78        new->type = source->type;
     79        new->mode = source->mode;
     80        new->psfMag = source->psfMag;
     81        new->extMag = source->extMag;
     82        new->errMag = source->errMag;
     83        new->apMag = source->apMag;
     84        new->pixWeight = source->pixWeight;
     85        new->psfChisq = source->psfChisq;
     86        new->crNsigma = source->crNsigma;
     87        new->extNsigma = source->extNsigma;
     88        new->sky = source->sky;
     89        new->skyErr = source->skyErr;
     90
     91        new->modelPSF = pmModelAlloc(source->modelPSF->type);
    8292
    8393#if 0
    84         // XXX Note that this will not set the correct axes
    85         pmPSF_AxesToModel(new->modelPSF->params->data.F32,
    86                           pmPSF_ModelToAxes(source->modelPSF->params->data.F32, 20.0));
     94        // XXX Note that this will not set the correct axes
     95        pmPSF_AxesToModel(new->modelPSF->params->data.F32,
     96                          pmPSF_ModelToAxes(source->modelPSF->params->data.F32, 20.0));
    8797#endif
    8898
    89         // Propagate the position erorrs
    90         float dxIn, dyIn;           // Errors in input coordinates
    91         dxIn = model->dparams->data.F32[PM_PAR_XPOS];
    92         dyIn = model->dparams->data.F32[PM_PAR_YPOS];
     99        // Propagate the position erorrs
     100        float dxIn, dyIn;           // Errors in input coordinates
     101        dxIn = model->dparams->data.F32[PM_PAR_XPOS];
     102        dyIn = model->dparams->data.F32[PM_PAR_YPOS];
    93103
    94         float dxOut, dyOut;         // Errors in output coordinates
    95         dxOut = sqrt(PS_SQR(map->Xx * dxIn) + PS_SQR(map->Xy * dyIn));
    96         dyOut = sqrt(PS_SQR(map->Yx * dxIn) + PS_SQR(map->Yy * dyIn));
     104        float dxOut, dyOut;         // Errors in output coordinates
     105        dxOut = sqrt(PS_SQR(map->Xx * dxIn) + PS_SQR(map->Xy * dyIn));
     106        dyOut = sqrt(PS_SQR(map->Yx * dxIn) + PS_SQR(map->Yy * dyIn));
    97107
    98         new->modelPSF->params->data.F32[PM_PAR_XPOS] = xOut;
    99         new->modelPSF->params->data.F32[PM_PAR_YPOS] = yOut;
    100         new->modelPSF->dparams->data.F32[PM_PAR_XPOS] = dxOut;
    101         new->modelPSF->dparams->data.F32[PM_PAR_YPOS] = dyOut;
     108        new->modelPSF->params->data.F32[PM_PAR_XPOS] = xOut;
     109        new->modelPSF->params->data.F32[PM_PAR_YPOS] = yOut;
     110        new->modelPSF->dparams->data.F32[PM_PAR_XPOS] = dxOut;
     111        new->modelPSF->dparams->data.F32[PM_PAR_YPOS] = dyOut;
    102112
    103         psArrayAdd(outSources, SOURCE_ARRAY_BUFFER, new);
    104         psFree(new);                // Drop reference
     113        psArrayAdd(outSources, SOURCE_ARRAY_BUFFER, new);
     114        psFree(new);                // Drop reference
    105115    }
    106116    psFree(sourceGrid);
Note: See TracChangeset for help on using the changeset viewer.