IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 27609


Ignore:
Timestamp:
Apr 5, 2010, 3:30:27 PM (16 years ago)
Author:
Paul Price
Message:

Allow reading of streaks file.

Location:
trunk/ppViz/src/ppCoord
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppViz/src/ppCoord/ppCoord.h

    r27605 r27609  
    1616    psString chipName;                  // Name of chip of interest
    1717    psString radecName;                 // Filename with sky coordinates
     18    psString streaksName;               // Filename with streaks (sky coordinates)
    1819    pmConfig *config;                   // Configuration
    1920    bool radians;                       // RA,Dec are in radians?
  • trunk/ppViz/src/ppCoord/ppCoordArguments.c

    r27606 r27609  
    5151    psMetadataAddStr(arguments, PS_LIST_TAIL, "-chip", 0, "Chip for pixel coordinates", NULL);
    5252    psMetadataAddStr(arguments, PS_LIST_TAIL, "-radec", 0, "Filename with RA,Dec (default decimal degrees)", NULL);
     53    psMetadataAddStr(arguments, PS_LIST_TAIL, "-streaks", 0, "Filename with streaks", NULL);
    5354    psMetadataAddBool(arguments, PS_LIST_TAIL, "-radians", 0, "RA,Dec in radians?", NULL);
    5455    psMetadataAddBool(arguments, PS_LIST_TAIL, "-all", 0, "Output all coordinates?", NULL);
     
    6566    data->chipName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-chip"));
    6667    data->radecName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-radec"));
     68    data->streaksName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-streaks"));
    6769    data->radians = psMetadataLookupBool(NULL, arguments, "-radians");
    6870    data->all = psMetadataLookupBool(NULL, arguments, "-all");
     
    8890    }
    8991
    90     if (!data->pixelsName && !data->radecName) {
     92    if (!data->pixelsName && !data->radecName && !data->streaksName) {
    9193        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Neither -pixels nor -radec provided.");
    9294        return false;
  • trunk/ppViz/src/ppCoord/ppCoordData.c

    r27608 r27609  
    1818    psFree(data->chipName);
    1919    psFree(data->radecName);
     20    psFree(data->streaksName);
    2021    psFree(data->config);
    2122    psFree(data->ds9name);
     
    3839    data->chipName = NULL;
    3940    data->radecName = NULL;
     41    data->streaksName = NULL;
    4042    data->config = NULL;
    4143    data->radians = false;
  • trunk/ppViz/src/ppCoord/ppCoordLoop.c

    r27608 r27609  
    2323        NULL; // File with raw image
    2424
    25     psArray *pixels = NULL, *radec = NULL; // Array of vectors with coordinates
    26     psArray *radecOut = NULL;              // Output for sky coordinates
     25    psArray *pixels = NULL, *radec = NULL, *streaks = NULL; // Array of vectors with coordinates
     26    psArray *radecOut = NULL, *streaksOut = NULL;           // Output for sky coordinates
    2727    if (data->pixelsName) {
    2828        pixels = psVectorsReadFromFile(data->pixelsName, "%f %f");
     
    4747        psVectorInit(radecOut->data[1], NAN);
    4848        psVectorInit(radecOut->data[2], NAN);
     49    }
     50
     51    if (data->streaksName) {
     52        FILE *streaksFile = fopen(data->streaksName, "r"); // File handle for streaks
     53        if (!streaksFile) {
     54            psError(PS_ERR_IO, true, "Unable to open streaks file %s", data->streaksName);
     55            return false;
     56        }
     57        int numStreaks = 0;             // Number of streaks
     58        if (fscanf(streaksFile, "%d", &numStreaks) != 1) {
     59            psError(PS_ERR_IO, true, "Unable to read number of streaks from %s", data->streaksName);
     60            return false;
     61        }
     62
     63        streaks = psArrayAlloc(4);
     64        psVector *ra1 = streaks->data[0] = psVectorAlloc(numStreaks, PS_TYPE_F64);
     65        psVector *dec1 = streaks->data[1] = psVectorAlloc(numStreaks, PS_TYPE_F64);
     66        psVector *ra2 = streaks->data[2] = psVectorAlloc(numStreaks, PS_TYPE_F64);
     67        psVector *dec2 = streaks->data[3] = psVectorAlloc(numStreaks, PS_TYPE_F64);
     68
     69        for (int i = 0; i < numStreaks; i++) {
     70            if (fscanf(streaksFile, "%lf %lf %lf %lf %*d",
     71                       &ra1->data.F64[i], &dec1->data.F64[i], &ra2->data.F64[i], &dec2->data.F64[i]) != 4) {
     72                psError(PS_ERR_IO, true, "Unable to read streak %d of %d from %s",
     73                        i, numStreaks, data->streaksName);
     74                return false;
     75            }
     76        }
     77        streaksOut = psArrayAlloc(4);
     78        streaksOut->data[0] = psVectorAlloc(numStreaks, PS_TYPE_F32);
     79        streaksOut->data[1] = psVectorAlloc(numStreaks, PS_TYPE_F32);
     80        streaksOut->data[2] = psVectorAlloc(numStreaks, PS_TYPE_F32);
     81        streaksOut->data[3] = psVectorAlloc(numStreaks, PS_TYPE_F32);
     82        psVectorInit(streaksOut->data[0], NAN);
     83        psVectorInit(streaksOut->data[1], NAN);
     84        psVectorInit(streaksOut->data[2], NAN);
     85        psVectorInit(streaksOut->data[3], NAN);
    4986    }
    5087
     
    282319        }
    283320
     321        if (streaks && data->chipName && !rawFile) {
     322            psVector *xPix1 = streaksOut->data[0]; // x coordinate for point 1
     323            psVector *yPix1 = streaksOut->data[1]; // y coordinate for point 1
     324            psVector *xPix2 = streaksOut->data[2]; // x coordinate for point 2
     325            psVector *yPix2 = streaksOut->data[3]; // y coordinate for point 2
     326
     327            psVector *ra1 = streaks->data[0]; // RA coordinate for point 1
     328            psVector *dec1 = streaks->data[1]; // Dec coordinate for point 1
     329            psVector *ra2 = streaks->data[2]; // RA coordinate for point 2
     330            psVector *dec2 = streaks->data[3]; // Dec coordinate for point 2
     331
     332            psPlane *pix = psPlaneAlloc();   // Pixel coordinates on chip
     333            psPlane *fp = psPlaneAlloc();    // Focal plane coordinates
     334            psPlane *tp = psPlaneAlloc();    // Tangent plane coordinates
     335            psSphere *sky = psSphereAlloc(); // Sky coordinates
     336            for (long i = 0; i < xPix1->n; i++) {
     337                sky->r = ra1->data.F64[i];
     338                sky->d = dec1->data.F64[i];
     339                psProject(tp, sky, astromFile->fpa->toSky);
     340                psPlaneTransformApply(fp, astromFile->fpa->fromTPA, tp);
     341                psPlaneTransformApply(pix, chip->fromFPA, fp);
     342                xPix1->data.F32[i] = pix->x;
     343                yPix1->data.F32[i] = pix->y;
     344
     345                sky->r = ra2->data.F64[i];
     346                sky->d = dec2->data.F64[i];
     347                psProject(tp, sky, astromFile->fpa->toSky);
     348                psPlaneTransformApply(fp, astromFile->fpa->fromTPA, tp);
     349                psPlaneTransformApply(pix, chip->fromFPA, fp);
     350                xPix2->data.F32[i] = pix->x;
     351                yPix2->data.F32[i] = pix->y;
     352            }
     353        }
     354
    284355        // Chip
    285356        if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
     
    323394    }
    324395
     396    if (streaksOut) {
     397        psVector *xPix1 = streaksOut->data[0]; // x coordinate for point 1
     398        psVector *yPix1 = streaksOut->data[1]; // y coordinate for point 1
     399        psVector *xPix2 = streaksOut->data[2]; // x coordinate for point 2
     400        psVector *yPix2 = streaksOut->data[3]; // y coordinate for point 2
     401
     402        psVector *ra1 = streaks->data[0]; // RA coordinate for point 1
     403        psVector *dec1 = streaks->data[1]; // Dec coordinate for point 1
     404        psVector *ra2 = streaks->data[2]; // RA coordinate for point 2
     405        psVector *dec2 = streaks->data[3]; // Dec coordinate for point 2
     406
     407        for (long i = 0; i < xPix1->n; i++) {
     408            if (data->ds9) {
     409                fprintf(data->ds9, "image;line(%f,%f,%f,%f) # line= 0 0 color=%s\n",
     410                        xPix1->data.F32[i], yPix1->data.F32[i], xPix2->data.F32[i], yPix2->data.F32[i],
     411                        data->ds9color);
     412            } else {
     413                fprintf(stdout, "%.10lf %.10lf %.10lf %.10lf --> %.3f %.3f %.3f %.3f\n",
     414                        ra1->data.F64[i], dec1->data.F64[i],
     415                        ra2->data.F64[i], dec2->data.F64[i],
     416                        xPix1->data.F32[i], yPix1->data.F32[i],
     417                        xPix2->data.F32[i], yPix2->data.F32[i]);
     418            }
     419        }
     420    }
     421
    325422    psFree(pixels);
    326423    psFree(radec);
    327424    psFree(radecOut);
     425    psFree(streaks);
     426    psFree(streaksOut);
    328427
    329428    return true;
Note: See TracChangeset for help on using the changeset viewer.