IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 4, 2022, 2:56:53 PM (4 years ago)
Author:
tdeboer
Message:

adding dirty desperate diff functionality

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppViz/src/ppCoord/ppCoordLoop.c

    r41899 r42154  
    7979        NULL; // File with raw image
    8080
    81     psArray *pixels = NULL, *radec = NULL, *streaks = NULL, *clusters = NULL; // Array of coordinate vectors
    82     psArray *radecOut = NULL, *streaksOut = NULL, *clustersOut = NULL;        // Output for sky coordinates
     81    psArray *pixels = NULL, *radec = NULL, *fpas = NULL, *streaks = NULL, *clusters = NULL; // Array of coordinate vectors
     82    psArray *radecOut = NULL,*fpaOut = NULL, *streaksOut = NULL, *clustersOut = NULL;        // Output for sky coordinates
    8383    if (data->pixelsName) {
    8484        pixels = psVectorsReadFromFile(data->pixelsName, "%f %f");
     
    107107        psVectorInit(radecOut->data[1], NAN);
    108108        psVectorInit(radecOut->data[2], NAN);
     109    }
     110
     111    if (data->fpaName) {
     112        fpas = psVectorsReadFromFile(data->fpaName, "%f %f");
     113        if (!fpas || fpas->n != 2) {
     114            psError(psErrorCodeLast(), false, "Unable to read FPA coordinates");
     115            return false;
     116        }
     117        psVector *fpa_x = fpas->data[0];  // FPA x coordinates
     118        long num = fpa_x->n;               // Number of coordinates
     119        fpaOut = psArrayAlloc(6);
     120        fpaOut->data[0] = psArrayAlloc(num);
     121        fpaOut->data[1] = psVectorAlloc(num, PS_TYPE_F32);
     122        fpaOut->data[2] = psVectorAlloc(num, PS_TYPE_F32);
     123        fpaOut->data[3] = psArrayAlloc(num);
     124        fpaOut->data[4] = psVectorAlloc(num, PS_TYPE_F32);
     125        fpaOut->data[5] = psVectorAlloc(num, PS_TYPE_F32);
     126        psVectorInit(fpaOut->data[1], NAN);
     127        psVectorInit(fpaOut->data[2], NAN);
     128        psVectorInit(fpaOut->data[4], NAN);
     129        psVectorInit(fpaOut->data[5], NAN);
    109130    }
    110131
     
    394415                yTP->data.F32[i] = src.tp.y;
    395416            }
     417        }
     418
     419        if (fpas) {
     420            psVector *fpa_x = fpas->data[0], *fpa_y = fpas->data[1]; // FPA coordinates
     421            long num = fpa_x->n;                                     // Number of coordinates
     422
     423            int numCols = psMetadataLookupS32(NULL, hdu->header, "IMNAXIS1"); // Number of columns
     424            int numRows = psMetadataLookupS32(NULL, hdu->header, "IMNAXIS2"); // Number of rows
     425            if (numCols <= 0 || numRows <= 0) {
     426                psError(psErrorCodeLast(), false, "Unable to read size of chip.");
     427                return false;
     428            }
     429
     430            psArray *chipPix = fpaOut->data[0]; // Chip for pixels
     431            psVector *xPix = fpaOut->data[1];   // x coordinate for pixels
     432            psVector *yPix = fpaOut->data[2];   // y coordinate for pixels
     433            psArray *cellPix = fpaOut->data[3]; // Cell for pixels
     434            psVector *xCell = fpaOut->data[4];   // x coordinate for cell
     435            psVector *yCell = fpaOut->data[5];   // y coordinate for cell
     436
     437            psPlane *pix = psPlaneAlloc();   // Pixel coordinates on chip
     438            psPlane *fp = psPlaneAlloc();    // Focal plane coordinates
     439
     440            for (long i = 0; i < num; i++) {
     441                float x, y;             // Pixel coordinates
     442                fp->x = fpa_x->data.F32[i];
     443                fp->y = fpa_y->data.F32[i];
     444
     445                psPlaneTransformApply(pix, chip->fromFPA, fp);
     446                psTrace("ppCoord",2,"fpa2pix tr1: %f %f\n",pix->x,pix->y);
     447
     448                x = pix->x;
     449                y = pix->y;
     450
     451                if ((x < 0 || x > numCols || y < 0 || y > numRows)) {
     452                    // Not on this chip
     453                    continue;
     454                }
     455
     456                chipPix->data[i] = psStringCopy(chipName);
     457                xPix->data.F32[i] = x;
     458                yPix->data.F32[i] = y;
     459
     460                if (rawChip) {
     461                    psString cellName = NULL; // Name of cell
     462                    coordChip2Cell(&cellName, &x, &y, x, y, cellNames, cellBounds,
     463                                   cellX0, cellY0, cellParityX, cellParityY, cellBinX, cellBinY);
     464                    cellPix->data[i] = cellName;
     465                    xCell->data.F32[i] = x;
     466                    yCell->data.F32[i] = y;
     467                }
     468
     469            }
     470            psFree(pix);
     471            psFree(fp);
    396472        }
    397473
     
    556632    }
    557633
     634    if (fpaOut) {
     635        psArray *chipPix = fpaOut->data[0]; // Chip for pixels
     636        psVector *xPix = fpaOut->data[1];   // x coordinate for pixels
     637        psVector *yPix = fpaOut->data[2];   // y coordinate for pixels
     638        psArray *cellPix = fpaOut->data[3]; // Cell for pixels
     639        psVector *xCell = fpaOut->data[4];   // x coordinate for pixels
     640        psVector *yCell = fpaOut->data[5];   // y coordinate for pixels
     641        psVector *fpa_x = fpas->data[0];        // FPA x coordinate
     642        psVector *fpa_y = fpas->data[1];       // FPA y coordinate
     643
     644        for (long i = 0; i < chipPix->n; i++) {
     645            const char *chipName = chipPix->data[i]; // Name of chip
     646            const char *cellName = cellPix->data[i]; // Name of cell, or NULL
     647            if (!data->all && (!isfinite(xPix->data.F32[i]) || !isfinite(yPix->data.F32[i]) ||
     648                               !chipName || (rawFile && !cellName))) {
     649                continue;
     650            }
     651            if (!rawFile && data->ds9) {
     652                // Region file is only appropriate if we're not mapping all the way back to cell coordinates
     653                fprintf(data->ds9, "image;circle(%f,%f,%f) # color=%s\n",
     654                        xPix->data.F32[i], yPix->data.F32[i], data->ds9radius, data->ds9color);
     655            } else if (rawFile) {
     656                fprintf(stdout, "%.3f %.3f --> %.3f %.3f %s %.3f %.3f %s\n",
     657                        fpa_x->data.F32[i], fpa_y->data.F32[i], xPix->data.F32[i], yPix->data.F32[i],
     658                        chipName ? chipName : "UNKNOWN",
     659                        xCell->data.F32[i], yCell->data.F32[i],
     660                        cellName ? cellName : "UNKNOWN");
     661            } else {
     662                fprintf(stdout, "%.3f %.3f --> %.3f %.3f %s\n",
     663                        fpa_x->data.F32[i], fpa_y->data.F32[i], xPix->data.F32[i], yPix->data.F32[i],
     664                        chipName ? chipName : "UNKNOWN");
     665            }
     666        }
     667    }
     668
    558669    if (streaksOut) {
    559670        psArray *chipPix1 = streaksOut->data[0]; // Chip for point 1
Note: See TracChangeset for help on using the changeset viewer.