IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2010, 8:41:49 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/tap_branches
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/tap_branches

  • branches/tap_branches/psModules

  • branches/tap_branches/psModules/src/objects/pmSourceIO.c

    r25754 r27838  
    4040#include "pmPSF.h"
    4141#include "pmModel.h"
     42#include "pmDetections.h"
    4243#include "pmSource.h"
    4344#include "pmModelClass.h"
     
    342343    pmHDU *hdu;
    343344    psMetadata *updates;
    344     psMetadata *outhead;
    345 
    346     char *exttype  = NULL;
    347345
    348346    // if sources is NULL, write out an empty table
    349     // input / output sources are stored on the readout->analysis as "PSPHOT.SOURCES" -- a better name might be something like PM_SOURCE_DATA
    350     psArray *sources = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.SOURCES");
     347    // input / output sources are stored on the readout->analysis as "PSPHOT.DETECTIONS"
     348
     349    psArray *sources = NULL;
     350    pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
     351    if (detections) {
     352        sources = detections->allSources;
     353    }
    351354    if (!sources) {
     355        detections = pmDetectionsAlloc();
    352356        sources = psArrayAlloc(0);
    353         psMetadataAddArray(readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_META_REPLACE, "Blank array of sources", sources);
    354         psFree(sources); // Held onto by the metadata, so we can continue to use
     357        detections->allSources = sources;
     358        psMetadataAddPtr(readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_DATA_UNKNOWN | PS_META_REPLACE, "Blank array of sources", detections);
     359        psFree(detections); // Held onto by the metadata, so we can continue to use
    355360    }
    356361
     
    368373        break;
    369374
    370       case PM_FPA_FILE_CMP:
    371         // a SPLIT format : only one header and object table per file
    372         hdu = pmFPAviewThisHDU (view, fpa);
    373         if (!hdu) {
    374             psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find HDU to write sources.");
    375             return false;
    376         }
    377 
    378         // copy the header to an output header, add the output header data
    379         outhead = psMetadataCopy (NULL, hdu->header);
    380 
    381         // copy over the entries saved by PSPHOT
    382         updates = psMetadataLookupPtr (NULL, readout->analysis, "PSPHOT.HEADER");
    383         if (updates) {
    384             psMetadataCopy (outhead, updates);
    385         }
    386 
    387         // copy over the entries saved by PSASTRO
    388         updates = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.HEADER");
    389         if (updates) {
    390             psMetadataCopy (outhead, updates);
    391         }
    392 
    393         bool status = pmSourcesWriteCMP (sources, file->filename, outhead);
    394         psFree (outhead);
    395 
    396         if (!status) {
    397             psError(PS_ERR_IO, false, "Failed to write CMP file\n");
    398             return false;
    399         }
    400         break;
    401 
    402       case PM_FPA_FILE_CMF:
     375      case PM_FPA_FILE_CMP: {
     376          // a SPLIT format : only one header and object table per file
     377          hdu = pmFPAviewThisHDU (view, fpa);
     378          if (!hdu) {
     379              psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find HDU to write sources.");
     380              return false;
     381          }
     382
     383          // copy the header to an output header, add the output header data
     384          psMetadata *outhead = psMetadataCopy (NULL, hdu->header);
     385
     386          // copy over the entries saved by PSPHOT
     387          updates = psMetadataLookupPtr (NULL, readout->analysis, "PSPHOT.HEADER");
     388          if (updates) {
     389              psMetadataCopy (outhead, updates);
     390          }
     391
     392          // copy over the entries saved by PSASTRO
     393          updates = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.HEADER");
     394          if (updates) {
     395              psMetadataCopy (outhead, updates);
     396          }
     397
     398          bool status = pmSourcesWriteCMP (sources, file->filename, outhead);
     399          psFree (outhead);
     400
     401          if (!status) {
     402              psError(PS_ERR_IO, false, "Failed to write CMP file\n");
     403              return false;
     404          }
     405          break;
     406      }
     407
     408      case PM_FPA_FILE_CMF:
    403409        // write a header? (only if this is the first readout for cell)
    404410        //   note that the file->header is set to track the last hdu->header written
     
    415421        psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PSPHOT");
    416422        if (!status) {
    417           psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data");
    418           return false;
     423            psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data");
     424            return false;
    419425        }
    420426
     
    429435        psString xsrcname = NULL;
    430436        psString xfitname = NULL;
    431         if (!sourceExtensions(&headname, &dataname, &deteffname, XSRC_OUTPUT ? &xsrcname : NULL,
    432                               XFIT_OUTPUT ? &xfitname : NULL, file, view)) {
     437        if (!sourceExtensions(&headname, &dataname, &deteffname,
     438                              XSRC_OUTPUT ? &xsrcname : NULL,
     439                              XFIT_OUTPUT ? &xfitname : NULL,
     440                              file, view)) {
    433441            return false;
    434442        }
     
    489497        }
    490498
    491         // write out the TABLE data segment
     499        // write out the Object TABLE data segment(s)
    492500        {
    493501            // create a header to hold the output data
    494             outhead = psMetadataAlloc ();
    495 
    496             exttype = psMemIncrRefCounter (psMetadataLookupStr(&status, recipe, "OUTPUT.FORMAT"));
     502            psMetadata *outhead = psMetadataAlloc ();
     503           
     504            char *exttype = psMemIncrRefCounter (psMetadataLookupStr(&status, recipe, "OUTPUT.FORMAT"));
    497505            if (!exttype) {
    498506                exttype = psStringCopy ("SMPDATA");
     
    502510            psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTHEAD", PS_META_REPLACE, "name of image extension w/", headname);
    503511            psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTTYPE", PS_META_REPLACE, "extension type", exttype);
    504             psFree (exttype);
    505512
    506513            // if we request XSRC output, add the XSRC name to this header
    507514            if (xsrcname) {
    508               psMetadataAddStr (outhead, PS_LIST_TAIL, "XSRCNAME", PS_META_REPLACE, "name of XSRC table extension", xsrcname);
     515                psMetadataAddStr (outhead, PS_LIST_TAIL, "XSRCNAME", PS_META_REPLACE, "name of XSRC table extension", xsrcname);
    509516            }
    510517            if (xfitname) {
    511               psMetadataAddStr (outhead, PS_LIST_TAIL, "XFITNAME", PS_META_REPLACE, "name of XFIT table extension", xfitname);
     518                psMetadataAddStr (outhead, PS_LIST_TAIL, "XFITNAME", PS_META_REPLACE, "name of XFIT table extension", xfitname);
    512519            }
    513520
     
    532539                status &= pmSourcesWrite_CMF_PS1_V2 (file->fits, readout, sources, file->header, outhead, dataname);
    533540            }
    534 
    535             if (deteffname) {
    536                 status &= pmReadoutWriteDetEff(file->fits, readout, outhead, deteffname);
     541            if (!strcmp (exttype, "PS1_DV1")) {
     542                status &= pmSourcesWrite_CMF_PS1_DV1 (file->fits, readout, sources, file->header, outhead, dataname);
    537543            }
    538544
    539545            if (xsrcname) {
    540               if (!strcmp (exttype, "PS1_DEV_1")) {
    541                   status &= pmSourcesWrite_PS1_DEV_1_XSRC (file->fits, sources, xsrcname, recipe);
    542               }
    543               if (!strcmp (exttype, "PS1_CAL_0")) {
    544                   status &= pmSourcesWrite_PS1_CAL_0_XSRC (file->fits, readout, sources, file->header, xsrcname, recipe);
    545               }
    546               if (!strcmp (exttype, "PS1_V1")) {
    547                   status &= pmSourcesWrite_CMF_PS1_V1_XSRC (file->fits, sources, xsrcname, recipe);
    548               }
    549               if (!strcmp (exttype, "PS1_V2")) {
    550                   status &= pmSourcesWrite_CMF_PS1_V2_XSRC (file->fits, sources, xsrcname, recipe);
    551               }
     546                if (!strcmp (exttype, "PS1_DEV_1")) {
     547                    status &= pmSourcesWrite_PS1_DEV_1_XSRC (file->fits, sources, xsrcname, recipe);
     548                }
     549                if (!strcmp (exttype, "PS1_CAL_0")) {
     550                    status &= pmSourcesWrite_PS1_CAL_0_XSRC (file->fits, readout, sources, file->header, xsrcname, recipe);
     551                }
     552                if (!strcmp (exttype, "PS1_V1")) {
     553                    status &= pmSourcesWrite_CMF_PS1_V1_XSRC (file->fits, readout, sources, file->header, xsrcname, recipe);
     554                }
     555                if (!strcmp (exttype, "PS1_V2")) {
     556                    status &= pmSourcesWrite_CMF_PS1_V2_XSRC (file->fits, readout, sources, file->header, xsrcname, recipe);
     557                }
     558                if (!strcmp (exttype, "PS1_DV1")) {
     559                    status &= pmSourcesWrite_CMF_PS1_DV1_XSRC (file->fits, readout, sources, file->header, xsrcname, recipe);
     560                }
    552561            }
    553562            if (xfitname) {
    554               if (!strcmp (exttype, "PS1_DEV_1")) {
    555                   status &= pmSourcesWrite_PS1_DEV_1_XFIT (file->fits, sources, xfitname);
    556               }
    557               if (!strcmp (exttype, "PS1_CAL_0")) {
    558                   status &= pmSourcesWrite_PS1_CAL_0_XFIT (file->fits, readout, sources, file->header, xfitname);
    559               }
    560               if (!strcmp (exttype, "PS1_V1")) {
    561                   status &= pmSourcesWrite_CMF_PS1_V1_XFIT (file->fits, sources, xfitname);
    562               }
    563               if (!strcmp (exttype, "PS1_V2")) {
    564                   status &= pmSourcesWrite_CMF_PS1_V2_XFIT (file->fits, sources, xfitname);
    565               }
    566             }
     563                if (!strcmp (exttype, "PS1_DEV_1")) {
     564                    status &= pmSourcesWrite_PS1_DEV_1_XFIT (file->fits, sources, xfitname);
     565                }
     566                if (!strcmp (exttype, "PS1_CAL_0")) {
     567                    status &= pmSourcesWrite_PS1_CAL_0_XFIT (file->fits, readout, sources, file->header, xfitname);
     568                }
     569                if (!strcmp (exttype, "PS1_V1")) {
     570                    status &= pmSourcesWrite_CMF_PS1_V1_XFIT (file->fits, readout, sources, xfitname);
     571                }
     572                if (!strcmp (exttype, "PS1_V2")) {
     573                    status &= pmSourcesWrite_CMF_PS1_V2_XFIT (file->fits, readout, sources, xfitname);
     574                }
     575                if (!strcmp (exttype, "PS1_DV1")) {
     576                    status &= pmSourcesWrite_CMF_PS1_DV1_XFIT (file->fits, readout, sources, xfitname);
     577                }
     578            }
     579            psFree (outhead);
     580            psFree (exttype);
     581
    567582            if (!status) {
    568583                psError(PS_ERR_IO, false, "writing CMF data to %s with format %s\n", file->filename, exttype);
    569                 psFree (headname);
    570                 psFree (dataname);
    571                 psFree (xsrcname);
    572                 psFree (xfitname);
    573                 psFree (outhead);
    574                 psFree (deteffname);
    575                 return false;
    576             }
    577         }
     584                goto escape;
     585            }
     586        }
     587
     588
     589        // write out the detection efficiency TABLE segments
     590        if (deteffname) {
     591            // create a header to hold the output data
     592            psMetadata *outhead = psMetadataAlloc ();
     593            psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTHEAD", PS_META_REPLACE, "name of image extension w/", headname);
     594            psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTTYPE", PS_META_REPLACE, "extension type", "DETEFF");
     595
     596            status = pmReadoutWriteDetEff(file->fits, readout, outhead, deteffname);
     597            psFree (outhead);
     598
     599            if (!status) {
     600                psError(PS_ERR_IO, false, "writing DETEFF data to %s\n", file->filename);
     601                goto escape;
     602            }
     603        }
     604        psFree (headname);
     605        psFree (dataname);
     606        psFree (xsrcname);
     607        psFree (xfitname);
     608        psFree (deteffname);
    578609
    579610        psTrace ("pmFPAfile", 5, "wrote ext data %s (type: %d)\n", file->filename, file->type);
    580 
    581         psFree (headname);
    582         psFree (dataname);
    583         psFree (xsrcname);
    584         psFree (xfitname);
    585         psFree (outhead);
     611        break;
     612
     613      escape:
     614        psFree (headname);
     615        psFree (dataname);
     616        psFree (xsrcname);
     617        psFree (xfitname);
    586618        psFree (deteffname);
    587         break;
     619        return false;
    588620
    589621      default:
     
    592624    }
    593625    return true;
     626
    594627}
    595628// a MEF CMF file has: PHU, CELL-HEAD, TABLE, CELL-HEAD, TABLE, TABLE, TABLE...
     
    936969        if (hdu->header == NULL) {
    937970            // if the IMAGE header does not exist, we have no data for this view
    938             if (!psFitsMoveExtName (file->fits, headname)) {
     971            if (!psFitsMoveExtNameClean (file->fits, headname)) {
    939972                readout->data_exists = false;
    940973                psFree (headname);
     
    964997        if (!tableHeader) psAbort("cannot read table header");
    965998
     999        char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION");
     1000        if (!xtension) psAbort("cannot read table type");
     1001        if (strcmp (xtension, "BINTABLE")) {
     1002            psWarning ("no binary table in extension %s, skipping\n", dataname);
     1003            return false;
     1004        }
     1005
    9661006        char *exttype = psMetadataLookupStr (NULL, tableHeader, "EXTTYPE");
    9671007        if (!exttype) psAbort("cannot read table type");
     
    9831023            if (!strcmp (exttype, "PS1_V2")) {
    9841024                sources = pmSourcesRead_CMF_PS1_V2 (file->fits, hdu->header);
     1025            }
     1026            if (!strcmp (exttype, "PS1_DV1")) {
     1027                sources = pmSourcesRead_CMF_PS1_DV1 (file->fits, hdu->header);
    9851028            }
    9861029
     
    10081051    }
    10091052    readout->data_exists = true;
    1010     status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY, "input sources", sources);
    1011     psFree (sources);
     1053
     1054    pmDetections *detections = pmDetectionsAlloc();
     1055    detections->allSources = sources;
     1056    status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_DATA_ARRAY, "input sources", detections);
     1057    psFree (detections);
    10121058    return true;
    10131059}
     
    11011147    bool status;
    11021148
    1103     // select the psf of interest
    1104     pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.SOURCES");
    1105     if (!psf) return false;
    1106     return true;
    1107 }
    1108 
    1109 
     1149    // select the detections of interest
     1150    pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
     1151    if (!detections) return false;
     1152    if (!detections->allSources) return false;
     1153    return true;
     1154}
     1155
     1156
Note: See TracChangeset for help on using the changeset viewer.