IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 29298


Ignore:
Timestamp:
Oct 1, 2010, 2:12:29 PM (16 years ago)
Author:
rhenders
Message:

First pass at populating stacks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/src/ippToPspsBatchStack.c

    r27686 r29298  
    99#include "ippToPsps.h"
    1010#include "ippToPspsConfig.h"
     11#include "ippToPspsStackEnums.h"
     12
    1113
    1214/**
     
    1517int ippToPsps_batchStack(IppToPsps *this) {
    1618
    17 //    char extensionName[20];
    18     uint32_t skycell = 0; // TODO
    1919
    20     for (uint16_t i = 0; i<this->numOfInputFiles; i++) {
     20    int status = 0;
     21    fitsfile *fitsIn;
    2122
    22         skycell = i; // TODO
     23    if (fits_open_file(&fitsIn, this->inputFiles[0], READONLY, &status)) {
     24
     25        fits_report_error(stderr, status);
     26        return PS_EXIT_SYS_ERROR;
     27    }
     28
     29    long removeList[MAXDETECT];
     30    float instMag[MAXDETECT];
     31    float floatnull = -999.0;
     32    int anynull = 0;
     33
     34    // get primary header and pull stuff out for later
     35    int nKeys = 0;
     36    fits_get_hdrspace(fitsIn, &nKeys, NULL, &status);
     37    float exposureTime; status=0; fits_read_key(fitsIn, TFLOAT, "EXPTIME", &exposureTime, NULL, &status);
     38    char filterType[20]; status=0; fits_read_key(fitsIn, TSTRING, "FPA.FILTERID", filterType, NULL, &status);
    2339
    2440
     41    // write StackMeta
     42    ippToPspsConfig_writeTable(this->config, fitsIn, this->fitsOut, 1, "StackMeta", true);
     43
     44    int8_t filterID = -1;
     45    if (!ippToPspsConfig_getFilterId(this->config, filterType, &filterID)) {return PS_EXIT_DATA_ERROR;}
     46    fits_write_col(this->fitsOut, TBYTE, STACKMETA_FILTERID, 1, 1, 1, &filterID, &status);
     47
     48    // psf detections
     49    char extensionName[15];
     50    sprintf(extensionName, "SkyChip.psf");
     51    if (fits_movnam_hdu(fitsIn, BINARY_TBL, extensionName, 0, &status)) {
     52        psError(PS_ERR_IO, false, "Can't move to extension: %s\n", extensionName);
     53       
    2554    }
     55    else {
     56   
     57        long nDet = 0;
     58        if (fits_get_num_rows(fitsIn, &nDet, &status)) {
     59            fits_report_error(stderr, status);
     60        }
     61
     62        int instMagNum;
     63        status=0;fits_get_colnum(fitsIn, CASESEN, "PSF_INST_MAG", &instMagNum, &status);
     64        if (status) psError(PS_ERR_IO, false, "Unable to read col num for PSF_INST_MAG");
     65        fits_read_col(fitsIn, TFLOAT, instMagNum, 1, 1, nDet, &floatnull, instMag, &anynull, &status);
     66
     67
     68        printf("Looping through %ld psf detections\n", nDet);
     69        float mag;
     70        long unmatched = 0, totalDetections = 0, numOfDuplicates = 0, numInvalidFlux = 0, numDetectionsOut = 0;
     71
     72        for (long s = 0; s<nDet; s++) {
     73
     74            // TODO implement this match in DVO
     75            if (1) {
     76
     77                mag = instMag[s];
     78                if (!isfinite(mag) || mag < -998.0) {
     79
     80                    removeList[numOfDuplicates+numInvalidFlux] = s+1;
     81                    numInvalidFlux++;
     82                }
     83
     84                totalDetections++;
     85            }
     86            else {
     87
     88                unmatched++;
     89                continue;
     90            }
     91        }
     92
     93        numDetectionsOut = totalDetections - numInvalidFlux;
     94
     95        if (numDetectionsOut > 0) {
     96
     97            ippToPspsConfig_writeTable(this->config, fitsIn, this->fitsOut, nDet, "StackDetection", false);
     98            if (numInvalidFlux) fits_delete_rowlist(this->fitsOut, removeList, numInvalidFlux, &status);
     99
     100        }
     101        psLogMsg("ippToPsps", PS_LOG_INFO,
     102                "+---------------+---------+----------+------------------+---------------+--------------+\n"
     103                "|   Extension   | Rows in | Rows out | Missing from DVO | Duplicate IDs | Invalid Flux |\n"
     104                "|  %12s |  %5ld  |   %5ld  |      %5ld       |    %5ld      |    %5ld     |\n",
     105                extensionName, nDet, numDetectionsOut, unmatched, numOfDuplicates, numInvalidFlux);
     106
     107    }
     108
     109
     110
     111    // extended source
     112    sprintf(extensionName, "SkyChip.xsrc");
     113    if (fits_movnam_hdu(fitsIn, BINARY_TBL, extensionName, 0, &status)) {
     114        psError(PS_ERR_IO, false, "Can't move to extension: %s\n", extensionName);
     115
     116    }
     117    else {
     118
     119        long nDet = 0;
     120        if (fits_get_num_rows(fitsIn, &nDet, &status)) {
     121            fits_report_error(stderr, status);
     122        }
     123
     124        printf("Looping through %ld extended source detections\n", nDet);
     125        for (long s = 0; s<nDet; s++) {
     126
     127
     128
     129        }
     130
     131
     132
     133        ippToPspsConfig_writeTable(this->config, fitsIn, this->fitsOut, nDet, "StackApFlx", false);
     134    }
     135
     136    status=0;
     137    if (fits_close_file(fitsIn, &status)) fits_report_error(stderr, status);
     138
    26139
    27140    return PS_EXIT_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.