IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 14, 2014, 2:28:47 PM (12 years ago)
Author:
bills
Message:

Iniital implementation of the full force stages to the pipeline.
Maginitude and galactic coordinate limits on extended source fits

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/psModules

  • trunk/psModules/src/objects/pmSourceIO_CMF.c.in

    r36375 r36441  
    708708            return false;
    709709        }
    710         // Find the source with this sequence number.
    711         // XXX: I am assuming that sources is sorted in order of seq
     710        // Find the source with this sequence number using the sourceIndex.
    712711        long seq = psMetadataLookupU32 (&status, row, "IPP_IDET");
    713         pmSource *source = NULL;
    714 #ifndef ASSUME_SORTED
    715         long j = seq < sources->n ? seq : sources->n - 1;
    716         for (; j >= 0; j--) {
    717             source = sources->data[j];
    718             if (source->seq == seq) {
    719                 break;
    720             }
    721         }
    722 #else
    723712        long j = sourceIndex[seq];
    724713        psAssert(j >= 0 && j < sources->n, "invalid sourceIndex");
    725         source = sources->data[j];
    726 #endif
     714        pmSource *source = sources->data[j];
    727715        if (!source) {
    728716            psError(PS_ERR_UNKNOWN, false, "Failed to find source for row %ld sequence number %ld\n", i, seq);
     
    793781    // create a header to hold the output data
    794782    psMetadata *outhead = psMetadataAlloc ();
     783
     784    pmModelClassWriteHeader(outhead);
    795785
    796786    // write the links to the image header
     
    10341024        return false;
    10351025    }
     1026    // set up the lookup table to translate between input model types and output model types
     1027    // if not defined it is assumed that the tables are the same
     1028    pmModelClassReadHeader(tableHeader);
    10361029
    10371030    for (long i = 0; i < numSources; i++) {
     
    10421035            return false;
    10431036        }
    1044         // Find the source with this sequence number.
    1045         // XXX: I am assuming that sources is sorted in order of seq.
    10461037        long seq = psMetadataLookupU32 (&status, row, "IPP_IDET");
    1047         long j = seq < sources->n ? seq : sources->n - 1;
    1048         pmSource *source = NULL;
    1049         for (; j >= 0; j--) {
    1050             source = sources->data[j];
    1051             if (source->seq == seq) {
    1052                 break;
    1053             }
    1054         }
     1038        long j = sourceIndex[seq];
     1039        psAssert(j >= 0 && j < sources->n, "invalid sourceIndex");
     1040        pmSource *source = sources->data[j];
    10551041        if (!source) {
    10561042            psError(PS_ERR_UNKNOWN, false, "Failed to find source for row %ld sequence number %ld\n", i, seq);
     
    10951081        // in the psf table.
    10961082        psS32 extModelType = psMetadataLookupS32(&status, row, "EXT_MODEL_TYPE");
    1097         if (!status) {
     1083        if (status) {
     1084            // translate between the type value in xfit and values used by this program
     1085            extModelType = pmModelClassGetLocalType(extModelType);
     1086        } else {
    10981087            // older cmfs don't have this column
    10991088            extModelType = -1;
    1100         }
     1089        } 
    11011090
    11021091        psEllipseAxes axes;
     
    13391328            return false;
    13401329        }
    1341         // Find the source with this sequence number.
    1342         // XXX: I am assuming that sources is sorted in order of seq.
    13431330        long seq = psMetadataLookupU32 (&status, row, "IPP_IDET");
    1344         long j = seq < sources->n ? seq : sources->n - 1;
    1345         pmSource *source = NULL;
    1346         for (; j >= 0; j--) {
    1347             source = sources->data[j];
    1348             if (source->seq == seq) {
    1349                 break;
    1350             }
    1351         }
     1331        long j = sourceIndex[seq];
     1332        psAssert(j >= 0 && j < sources->n, "invalid sourceIndex");
     1333        pmSource *source = sources->data[j];
    13521334        if (!source) {
    13531335            psError(PS_ERR_UNKNOWN, false, "Failed to find source for row %ld sequence number %ld\n", i, seq);
     
    14071389
    14081390// XXX where should I record the number of columns??
    1409 bool pmSourcesWrite_CMF_@CMFMODE@_XGAL (psFits *fits, psArray *sources, char *extname, psMetadata *recipe)
     1391bool pmSourcesWrite_CMF_@CMFMODE@_XGAL (psFits *fits, pmReadout *readout, psArray *sources, char *extname, psMetadata *recipe)
    14101392{
    14111393    bool status = false;
     
    14221404    // write the links to the image header
    14231405    psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTNAME", PS_META_REPLACE, "galaxy table extension", extname);
     1406
     1407    psMetadataAddStr (outhead, PS_LIST_TAIL, "HI", PS_META_REPLACE, "does this get through?", "THERE");
    14241408
    14251409    // let's write these out in S/N order
     
    14911475}
    14921476
     1477bool pmSourcesRead_CMF_@CMFMODE@_XGAL(psFits *fits, pmReadout *readout, psMetadata *hduHeader, psMetadata *tableHeader, psArray *sources, long *sourceIndex)
     1478{
     1479    PS_ASSERT_PTR_NON_NULL(fits, false);
     1480    PS_ASSERT_PTR_NON_NULL(sources, false);
     1481
     1482    bool status;
     1483    long numSources = psFitsTableSize(fits); // Number of sources in table
     1484    if (numSources == 0) {
     1485        psError(psErrorCodeLast(), false, "XGAL Table contains no entries\n");
     1486        return false;
     1487    }
     1488
     1489    for (long i = 0; i < numSources; i++) {
     1490        psMetadata *row = psFitsReadTableRow(fits, i); // Table row
     1491        if (!row) {
     1492            psError(psErrorCodeLast(), false, "Unable to read row %ld of sources", i);
     1493            psFree(row);
     1494            return false;
     1495        }
     1496        // Find the source with this sequence number.
     1497        // XXX: I am assuming that sources is sorted in order of seq
     1498        long seq = psMetadataLookupU32 (&status, row, "IPP_IDET");
     1499        long j = sourceIndex[seq];
     1500        psAssert(j >= 0 && j < sources->n, "invalid sourceIndex");
     1501
     1502        pmSource *source = sources->data[j];
     1503        if (!source) {
     1504            psError(PS_ERR_UNKNOWN, false, "Failed to find source for row %ld sequence number %ld\n", i, seq);
     1505            psFree(row);
     1506            return false;
     1507        }
     1508
     1509        psVector *Flux  = psMetadataLookupVector(&status, row, "GAL_FLUX");
     1510        psVector *dFlux = psMetadataLookupVector(&status, row, "GAL_FLUX_ERR");
     1511        psVector *chisq = psMetadataLookupVector(&status, row, "GAL_CHISQ");
     1512
     1513        if (Flux && Flux->n > 0) {
     1514            psFree(source->galaxyFits);
     1515            source->galaxyFits = pmSourceGalaxyFitsAlloc();
     1516            source->galaxyFits->nPix = psMetadataLookupF32(&status, row, "NPIX");
     1517
     1518            psFree(source->galaxyFits->Flux);
     1519            source->galaxyFits->Flux  = psMemIncrRefCounter(Flux);
     1520            psFree(source->galaxyFits->dFlux);
     1521            source->galaxyFits->dFlux = psMemIncrRefCounter(dFlux);
     1522            psFree(source->galaxyFits->chisq);
     1523            source->galaxyFits->chisq = psMemIncrRefCounter(chisq);
     1524        }
     1525
     1526        psFree(row);
     1527    }
     1528
     1529    return true;
     1530}
Note: See TracChangeset for help on using the changeset viewer.