IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 27978


Ignore:
Timestamp:
May 17, 2010, 12:20:57 PM (16 years ago)
Author:
Paul Price
Message:

Adding support for Magic clusters list: file stars with un-commented 'RA DEC', so need to parse it a bit differently. Also hard-coded the units of the streaks and clusters (radians for streaks, degrees for clusters).

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

Legend:

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

    r27609 r27978  
    1717    psString radecName;                 // Filename with sky coordinates
    1818    psString streaksName;               // Filename with streaks (sky coordinates)
     19    psString clustersName;              // Filename with clusters (sky coordinates)
    1920    pmConfig *config;                   // Configuration
    2021    bool radians;                       // RA,Dec are in radians?
  • trunk/ppViz/src/ppCoord/ppCoordArguments.c

    r27609 r27978  
    5252    psMetadataAddStr(arguments, PS_LIST_TAIL, "-radec", 0, "Filename with RA,Dec (default decimal degrees)", NULL);
    5353    psMetadataAddStr(arguments, PS_LIST_TAIL, "-streaks", 0, "Filename with streaks", NULL);
     54    psMetadataAddStr(arguments, PS_LIST_TAIL, "-clusters", 0, "Filename with clusters", NULL);
    5455    psMetadataAddBool(arguments, PS_LIST_TAIL, "-radians", 0, "RA,Dec in radians?", NULL);
    5556    psMetadataAddBool(arguments, PS_LIST_TAIL, "-all", 0, "Output all coordinates?", NULL);
     
    6768    data->radecName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-radec"));
    6869    data->streaksName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-streaks"));
     70    data->clustersName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-clusters"));
    6971    data->radians = psMetadataLookupBool(NULL, arguments, "-radians");
    7072    data->all = psMetadataLookupBool(NULL, arguments, "-all");
  • trunk/ppViz/src/ppCoord/ppCoordLoop.c

    r27618 r27978  
    8080        NULL; // File with raw image
    8181
    82     psArray *pixels = NULL, *radec = NULL, *streaks = NULL; // Array of vectors with coordinates
    83     psArray *radecOut = NULL, *streaksOut = NULL;           // Output for sky coordinates
     82    psArray *pixels = NULL, *radec = NULL, *streaks = NULL, *clusters = NULL; // Array of coordinate vectors
     83    psArray *radecOut = NULL, *streaksOut = NULL, *clustersOut = NULL;        // Output for sky coordinates
    8484    if (data->pixelsName) {
    8585        pixels = psVectorsReadFromFile(data->pixelsName, "%f %f");
     
    145145        psVectorInit(streaksOut->data[6], NAN);
    146146        psVectorInit(streaksOut->data[7], NAN);
     147    }
     148
     149    if (data->clustersName) {
     150        psString file = psSlurpFilename(data->clustersName); // Contents of clusters file
     151        if (!file) {
     152            psError(psErrorCodeLast(), false, "Unable to read clusters file %s", data->clustersName);
     153            return false;
     154        }
     155        psArray *lines = psStringSplitArray(file, "\n", false); // Lines of clusters
     156        psFree(file);
     157
     158        int num = lines->n - 1;         // Number of clusters
     159        clusters = psArrayAlloc(2);
     160        psVector *ra = clusters->data[0] = psVectorAlloc(num, PS_TYPE_F64);
     161        psVector *dec = clusters->data[1] = psVectorAlloc(num, PS_TYPE_F64);
     162
     163        // Skip the first line
     164        for (int i = 1; i < lines->n; i++) {
     165            const char *line = lines->data[i]; // Line of interest
     166            if (!sscanf(line, "%lf %lf", &ra->data.F64[i-1], &dec->data.F64[i-1]) != 2) {
     167                psError(PS_ERR_IO, true, "Unable to read line %d of %s", i, data->clustersName);
     168                return false;
     169            }
     170        }
     171        psFree(lines);
     172
     173        clustersOut = psArrayAlloc(4);
     174        clustersOut->data[0] = psArrayAlloc(num);
     175        clustersOut->data[1] = psVectorAlloc(num, PS_TYPE_F32);
     176        clustersOut->data[2] = psVectorAlloc(num, PS_TYPE_F32);
     177        clustersOut->data[3] = psArrayAlloc(num);
     178        psVectorInit(clustersOut->data[1], NAN);
     179        psVectorInit(clustersOut->data[2], NAN);
    147180    }
    148181
     
    369402                float x1, y1;   // Coordinates of point 1
    370403                coordSky2Chip(&x1, &y1, ra1->data.F64[i], dec1->data.F64[i],
    371                               data->radians, astromFile->fpa, chip);
     404                              true, astromFile->fpa, chip);
    372405                if ((x1 >= 0 && x1 < numCols && y1 >= 0 && y1 < numRows)) {
    373406                    if (rawChip) {
     
    384417                float x2, y2;   // Coordinates of point 2
    385418                coordSky2Chip(&x2, &y2, ra2->data.F64[i], dec2->data.F64[i],
    386                               data->radians, astromFile->fpa, chip);
     419                              true, astromFile->fpa, chip);
    387420                if ((x2 >= 0 && x2 < numCols && y2 >= 0 && y2 < numRows)) {
    388421                    if (rawChip) {
     
    396429                    yPix2->data.F32[i] = y2;
    397430                }
     431            }
     432        }
     433
     434        if (clusters) {
     435            psVector *ra = clusters->data[0], *dec = clusters->data[1]; // Pixel coordinates
     436            long num = ra->n;                                     // Number of coordinates
     437
     438            int numCols = psMetadataLookupS32(NULL, hdu->header, "IMNAXIS1"); // Number of columns
     439            int numRows = psMetadataLookupS32(NULL, hdu->header, "IMNAXIS2"); // Number of rows
     440            if (numCols <= 0 || numRows <= 0) {
     441                psError(psErrorCodeLast(), false, "Unable to read size of chip.");
     442                return false;
     443            }
     444
     445            psArray *chipPix = clustersOut->data[0]; // Chip for pixels
     446            psVector *xPix = clustersOut->data[1];   // x coordinate for pixels
     447            psVector *yPix = clustersOut->data[2];   // y coordinate for pixels
     448            psArray *cellPix = clustersOut->data[3]; // Cell for pixels
     449
     450            for (long i = 0; i < num; i++) {
     451                float x, y;             // Pixel coordinates
     452                coordSky2Chip(&x, &y, ra->data.F64[i], dec->data.F64[i],
     453                                false, astromFile->fpa, chip);
     454                if ((x < 0 || x > numCols || y < 0 || y > numRows)) {
     455                    // Not on this chip
     456                    continue;
     457                }
     458
     459                if (rawChip) {
     460                    psString cellName = NULL; // Name of cell
     461                    coordChip2Cell(&cellName, &x, &y, x, y, cellNames, cellBounds,
     462                                   cellX0, cellY0, cellParityX, cellParityY, cellBinX, cellBinY);
     463                    cellPix->data[i] = cellName;
     464                }
     465
     466                chipPix->data[i] = psStringCopy(chipName);
     467                xPix->data.F32[i] = x;
     468                yPix->data.F32[i] = y;
    398469            }
    399470        }
     
    482553                        data->ds9color);
    483554            } else {
    484                 fprintf(stdout, "%.10lf %.10lf %.10lf %.10lf --> %.3f %.3f %s%s%s %.3f %.3f %s%s%s\n",
     555                fprintf(stdout, "Streak %.10lf %.10lf %.10lf %.10lf --> %.3f %.3f %s%s%s %.3f %.3f %s%s%s\n",
    485556                        ra1->data.F64[i], dec1->data.F64[i],
    486557                        ra2->data.F64[i], dec2->data.F64[i],
     
    498569    }
    499570
     571    if (clustersOut) {
     572        psArray *chipPix = clustersOut->data[0]; // Chip for pixels
     573        psVector *xPix = clustersOut->data[1];   // x coordinate for pixels
     574        psVector *yPix = clustersOut->data[2];   // y coordinate for pixels
     575        psArray *cellPix = clustersOut->data[3]; // Cell for pixels
     576        psVector *ra = clusters->data[0];        // RA coordinate
     577        psVector *dec = clusters->data[1];       // Dec coordinate
     578
     579        for (long i = 0; i < chipPix->n; i++) {
     580            const char *chipName = chipPix->data[i]; // Name of chip
     581            const char *cellName = cellPix->data[i]; // Name of cell, or NULL
     582            if (!data->all && (!isfinite(xPix->data.F32[i]) || !isfinite(yPix->data.F32[i]) ||
     583                               !chipName || (rawFile && !cellName))) {
     584                continue;
     585            }
     586            if (!rawFile && data->ds9) {
     587                // Region file is only appropriate if we're not mapping all the way back to cell coordinates
     588                fprintf(data->ds9, "image;circle(%f,%f,%f) # color=%s\n",
     589                        xPix->data.F32[i], yPix->data.F32[i], data->ds9radius, data->ds9color);
     590            } else {
     591                fprintf(stdout, "Cluster %.10lf %.10lf --> %.3f %.3f %s%s%s\n",
     592                        ra->data.F64[i], dec->data.F64[i], xPix->data.F32[i], yPix->data.F32[i],
     593                        chipName ? chipName : "UNKNOWN",
     594                        rawFile ? " " : "",
     595                        rawFile && cellName ? cellName : (rawFile ? "UNKNOWN" : ""));
     596            }
     597        }
     598    }
     599
    500600    psFree(pixels);
    501601    psFree(radec);
     
    503603    psFree(streaks);
    504604    psFree(streaksOut);
     605    psFree(clusters);
     606    psFree(clustersOut);
    505607
    506608    return true;
Note: See TracChangeset for help on using the changeset viewer.