IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 21, 2014, 5:42:34 AM (12 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ps2-tc3-20130727
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ps2-tc3-20130727

  • branches/eam_branches/ps2-tc3-20130727/psModules

    • Property svn:mergeinfo deleted
  • branches/eam_branches/ps2-tc3-20130727/psModules/src/objects

    • Property svn:ignore
      •  

        old new  
        1212pmSourceIO_CMF_PS1_V1.v1.c
        1313pmSourceIO_CMF_PS1_V4.c
         14pmSourceIO_CMF_PS1_V5.c
        1415pmSourceIO_CMF_PS1_SV1.c
        1516pmSourceIO_CMF_PS1_SV2.c
  • branches/eam_branches/ps2-tc3-20130727/psModules/src/objects/pmSourceIO.c

    r35610 r36680  
    4747#include "pmSourceDiffStats.h"
    4848#include "pmSourceSatstar.h"
     49#include "pmSourceLensing.h"
    4950#include "pmSource.h"
    5051#include "pmSourceFitModel.h"
     
    6162static bool pmReadoutReadXFIT(pmFPAfile *file, pmReadout *readout, char * exttype, psMetadata *hduHeader, psString xfitname, psArray *sources, long *sourceIndex);
    6263static bool pmReadoutReadXRAD(pmFPAfile *file, pmReadout *readout, char * exttype, psMetadata *hduHeader, psString xfitname, psArray *sources, long *sourceIndex);
     64static bool pmReadoutReadXGAL(pmFPAfile *file, pmReadout *readout, char * exttype, psMetadata *hduHeader, psString xfitname, psArray *sources, long *sourceIndex);
    6365
    6466// lookup the EXTNAME values used for table data and image header segments
     
    6971                        psString *xfitname,    // Extension name for extended fitted measurements
    7072                        psString *xradname,    // Extension name for radial apertures
     73                        psString *xgalname,    // Extension name for galaxy shapes
    7174                        const pmFPAfile *file, // File of interest
    7275                        const pmFPAview *view  // View to level of interest
     
    140143        }
    141144        *xradname = pmFPAfileNameFromRule (rule, file, view);
     145    }
     146
     147    // EXTNAME for radial apertures
     148    if (xgalname) {
     149        const char *rule = psMetadataLookupStr(&status, menu, "CMF.XGAL");
     150        if (!rule) {
     151            psError(PS_ERR_UNKNOWN, true, "missing entry for CMF.XGAL in EXTNAME.RULES in camera.config");
     152            return false;
     153        }
     154        *xgalname = pmFPAfileNameFromRule (rule, file, view);
    142155    }
    143156
     
    362375            status &= pmSourcesWrite_##TYPE##_XRAD (file->fits, readout, sources, file->header, xradname, recipe); \
    363376        }                                                               \
     377        if (xgalname) {                                                 \
     378            status &= pmSourcesWrite_##TYPE##_XGAL (file->fits, readout, sources, xgalname, recipe); \
     379        }                                                               \
    364380    }
    365381
     
    464480        }
    465481
    466         // if this is not TRUE, the output files only contain the psf measurements.
    467         bool XSRC_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_ANALYSIS");
     482        // if none of these are TRUE, the output files only contain the psf measurements.
     483        bool doPetrosian = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_PETROSIAN");
     484        bool doAnnuli    = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_ANNULI");
     485        bool XSRC_OUTPUT = doPetrosian || doAnnuli;
    468486        bool XFIT_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_FITS");
    469487        bool XRAD_OUTPUT = psMetadataLookupBool(&status, recipe, "RADIAL_APERTURES");
     488        bool XGAL_OUTPUT = psMetadataLookupBool(&status, recipe, "GALAXY_SHAPES");
    470489
    471490        // define the EXTNAME values for the different data segments:
     
    476495        psString xfitname = NULL;
    477496        psString xradname = NULL;
     497        psString xgalname = NULL;
    478498        if (!pmSourceIOextnames(&headname, &dataname, &deteffname,
    479499                                XSRC_OUTPUT ? &xsrcname : NULL,
    480500                                XFIT_OUTPUT ? &xfitname : NULL,
    481501                                XRAD_OUTPUT ? &xradname : NULL,
     502                                XGAL_OUTPUT ? &xgalname : NULL,
    482503                                file, view)) {
    483504            return false;
     
    563584                psMetadataAddStr (outhead, PS_LIST_TAIL, "XRADNAME", PS_META_REPLACE, "name of XRAD table extension", xradname);
    564585            }
     586            if (xgalname) {
     587                psMetadataAddStr (outhead, PS_LIST_TAIL, "XGALNAME", PS_META_REPLACE, "name of XGAL table extension", xgalname);
     588            }
    565589
    566590            // these are case-sensitive since the EXTYPE is case-sensitive
     
    574598            PM_SOURCES_WRITE("PS1_V3",    CMF_PS1_V3);
    575599            PM_SOURCES_WRITE("PS1_V4",    CMF_PS1_V4);
     600            PM_SOURCES_WRITE("PS1_V5",    CMF_PS1_V5);
    576601            PM_SOURCES_WRITE("PS1_SV1",   CMF_PS1_SV1);
    577602            PM_SOURCES_WRITE("PS1_SV2",   CMF_PS1_SV2);
     
    609634        psFree (xfitname);
    610635        psFree (xradname);
     636        psFree (xgalname);
    611637        psFree (deteffname);
    612638
     
    620646        psFree (xfitname);
    621647        psFree (xradname);
     648        psFree (xgalname);
    622649        psFree (deteffname);
    623650        return false;
    624651
     652      case PM_FPA_FILE_CFF: {
     653        // determine the output table format
     654        psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PSPHOT");
     655        if (!status) {
     656            psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data");
     657            return false;
     658        }
     659
     660        hdu = pmFPAviewThisHDU (view, fpa);
     661        pmConfigConformHeader(hdu->header, file->format);
     662        psFitsWriteBlank (file->fits, hdu->header, NULL);
     663        file->header = hdu->header;
     664        file->wrote_phu = true;
     665        if (!pmSourcesWrite_CFF(readout, file->fits, sources, hdu->header, recipe)) {
     666            psError(PS_ERR_UNKNOWN, false, "failed to write CFF");
     667            return false;
     668        }
     669        break;
     670      }
     671       
    625672      default:
    626673        fprintf (stderr, "warning: type mismatch\n");
     
    914961    psArray *sources = NULL;
    915962    pmHDU *hdu;
     963
     964    // define the EXTNAME values for the different data segments:
     965    psString headname = NULL;
     966    psString dataname = NULL;
     967    psString deteffname = NULL;
     968    psString xsrcname = NULL;
     969    psString xfitname = NULL;
     970    psString xradname = NULL;
     971    psString xgalname = NULL;
     972
     973    psMetadata *tableHeader = NULL;
     974    char *xtension = NULL;
    916975
    917976    switch (file->type) {
     
    9631022        hdu = pmFPAviewThisHDU (view, file->fpa);
    9641023
    965         // define the EXTNAME values for the different data segments:
    966         psString headname = NULL;
    967         psString dataname = NULL;
    968         psString deteffname = NULL;
    969         psString xsrcname = NULL;
    970         psString xfitname = NULL;
    971         psString xradname = NULL;
    972 
    9731024        // determine the output table format. Assume if we need to output extendend source
    9741025        // parameters that they may exist in the input.
     
    9811032        }
    9821033
    983         // if this is not TRUE, the output files only contain the psf measurements.
    984         bool XSRC_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_ANALYSIS");
     1034        // if none of these are TRUE, we only read the psf measurements
     1035        // XXX: shouldn't we look for these extensions and read the regardless of the recipe values?
     1036        bool doPetrosian = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_PETROSIAN");
     1037        bool doAnnuli    = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_ANNULI");
     1038        bool XSRC_OUTPUT = doPetrosian || doAnnuli;
    9851039        bool XFIT_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_FITS");
    9861040        bool XRAD_OUTPUT = psMetadataLookupBool(&status, recipe, "RADIAL_APERTURES");
     1041        bool XGAL_OUTPUT = psMetadataLookupBool(&status, recipe, "GALAXY_SHAPES");
    9871042
    9881043        if (!pmSourceIOextnames(&headname, &dataname, &deteffname,
     
    9901045                XFIT_OUTPUT ? &xfitname : NULL,
    9911046                XRAD_OUTPUT ? &xradname : NULL,
     1047                XGAL_OUTPUT ? &xgalname : NULL,
    9921048                file, view)) {
    9931049            return false;
     
    10331089        }
    10341090
    1035         psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header
     1091        tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header
    10361092        if (!tableHeader) psAbort("cannot read table header");
    10371093
    1038         char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION");
     1094        xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION");
    10391095        if (!xtension) psAbort("cannot read table type");
    10401096        if (strcmp (xtension, "BINTABLE")) {
     
    10621118            PM_SOURCES_READ_PSF("PS1_V3",    CMF_PS1_V3);
    10631119            PM_SOURCES_READ_PSF("PS1_V4",    CMF_PS1_V4);
     1120            PM_SOURCES_READ_PSF("PS1_V5",    CMF_PS1_V5);
    10641121            PM_SOURCES_READ_PSF("PS1_SV1",   CMF_PS1_SV1);
    10651122            PM_SOURCES_READ_PSF("PS1_SV2",   CMF_PS1_SV2);
     
    10691126
    10701127            long *sourceIndex = NULL;
    1071             if (XSRC_OUTPUT || XFIT_OUTPUT || XRAD_OUTPUT) {
     1128            if (XSRC_OUTPUT || XFIT_OUTPUT || XRAD_OUTPUT || XGAL_OUTPUT) {
     1129                // Build sourceIndex. Lookup table from source->seq to index in sources array.
     1130                // Consists of an array of length max(source->seq) + 1.
     1131
     1132                // find maximum sequence number
    10721133                long seq_max = -1;
    10731134                for (long i = sources->n -1; i >= 0; i--) {
     
    10821143                    }
    10831144                }
     1145                // allocate and initialize the index
    10841146                sourceIndex = psAlloc((seq_max + 1) * sizeof(long));
    10851147                for (long i = 0; i < seq_max; i++) {
    10861148                    sourceIndex[i] = -1;
    10871149                }
     1150                // populate the index
    10881151                for (long i = 0; i < sources->n; i++) {
    10891152                    pmSource *source = sources->data[i];
     
    11121175                psFree(xradname);
    11131176            }
     1177            if (XGAL_OUTPUT && xgalname) {
     1178                // a cmf file may have an XGAL extension, but it is not required
     1179                if (!pmReadoutReadXGAL(file, readout, exttype, hdu->header, xgalname, sources, sourceIndex)) {
     1180                    // do anything?
     1181                }
     1182                psFree(xgalname);
     1183            }
    11141184            psFree(sourceIndex);
    11151185
     
    11321202        break;
    11331203
     1204      case PM_FPA_FILE_CFF:
     1205        // read in header, if not yet loaded
     1206        hdu = pmFPAviewThisHDU (view, file->fpa);
     1207
     1208        // look these up in the camera config?
     1209        // headrule = {CHIP.NAME}.hdr
     1210        // datarule = {CHIP.NAME}.cff
     1211
     1212        // define the EXTNAME values for the different data segments:
     1213        headname = pmFPAfileNameFromRule("{CHIP.NAME}.hdr", file, view);
     1214        dataname = pmFPAfileNameFromRule("{CHIP.NAME}.cff", file, view);
     1215
     1216        // advance to the IMAGE HEADER extension
     1217        if (hdu->header == NULL) {
     1218            // if the IMAGE header does not exist, we have no data for this view
     1219            if (!psFitsMoveExtNameClean (file->fits, headname)) {
     1220                readout->data_exists = false;
     1221                psFree (headname);
     1222                psFree (dataname);
     1223                return true;
     1224            }
     1225            hdu->header = psFitsReadHeader (NULL, file->fits);
     1226        }
     1227
     1228        // advance to the table data extension
     1229        // since we have read the IMAGE header, the TABLE header should exist
     1230        if (!psFitsMoveExtName (file->fits, dataname)) {
     1231            psAbort("cannot find data extension %s in %s", dataname, file->filename);
     1232        }
     1233
     1234        tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header
     1235        if (!tableHeader) psAbort("cannot read table header");
     1236
     1237        // verify this is a binary table
     1238        char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION");
     1239        if (!xtension) psAbort("cannot read table type");
     1240        if (strcmp (xtension, "BINTABLE")) {
     1241            psWarning ("no binary table in extension %s, skipping\n", dataname);
     1242            psFree(tableHeader);
     1243            return false;
     1244        }
     1245
     1246        sources = pmSourcesRead_CFF(file->fits, hdu->header);
     1247
     1248        psTrace("psModules.objects", 6, "read CMF table from %s : %s : %s", file->filename, headname, dataname);
     1249        psFree (headname);
     1250        psFree (dataname);
     1251        psFree (tableHeader);
     1252        break;
     1253
    11341254      default:
    11351255        fprintf (stderr, "warning: type mismatch\n");
     
    12721392        PM_SOURCES_READ_XSRC("PS1_V3",    CMF_PS1_V3);
    12731393        PM_SOURCES_READ_XSRC("PS1_V4",    CMF_PS1_V4);
     1394        PM_SOURCES_READ_XSRC("PS1_V5",    CMF_PS1_V5);
    12741395        PM_SOURCES_READ_XSRC("PS1_SV1",   CMF_PS1_SV1);
    12751396        PM_SOURCES_READ_XSRC("PS1_SV2",   CMF_PS1_SV2);
     
    13111432        PM_SOURCES_READ_XFIT("PS1_V3",    CMF_PS1_V3);
    13121433        PM_SOURCES_READ_XFIT("PS1_V4",    CMF_PS1_V4);
     1434        PM_SOURCES_READ_XFIT("PS1_V5",    CMF_PS1_V5);
    13131435        PM_SOURCES_READ_XFIT("PS1_SV1",   CMF_PS1_SV1);
    13141436        PM_SOURCES_READ_XFIT("PS1_SV2",   CMF_PS1_SV2);
     
    13491471        PM_SOURCES_READ_XRAD("PS1_V3",    CMF_PS1_V3);
    13501472        PM_SOURCES_READ_XRAD("PS1_V4",    CMF_PS1_V4);
     1473        PM_SOURCES_READ_XRAD("PS1_V5",    CMF_PS1_V5);
    13511474        PM_SOURCES_READ_XRAD("PS1_SV1",   CMF_PS1_SV1);
    13521475        PM_SOURCES_READ_XRAD("PS1_SV2",   CMF_PS1_SV2);
     
    13581481    return status;
    13591482}
     1483static bool pmReadoutReadXGAL(pmFPAfile *file, pmReadout *readout, char *exttype, psMetadata *hduHeader, psString xgalname, psArray *sources, long *sourceIndex)
     1484{
     1485    if (!psFitsMoveExtNameClean (file->fits, xgalname)) {
     1486        psTrace ("pmFPAfile", 1, "cannot find xgal extension %s in %s, skipping", xgalname, file->filename);
     1487        return false;
     1488    }
     1489
     1490    psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header
     1491    if (!tableHeader) psAbort("cannot read table header");
     1492
     1493    char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION");
     1494    if (!xtension) psAbort("cannot read table type");
     1495    if (strcmp (xtension, "BINTABLE")) {
     1496        psFree(tableHeader);
     1497        psWarning ("no binary table in extension %s, skipping\n", xgalname);
     1498        return false;
     1499    }
     1500
     1501# define PM_SOURCES_READ_XGAL(NAME,TYPE)                                \
     1502    if (!strcmp (exttype, NAME)) {                                      \
     1503        status = pmSourcesRead_##TYPE##_XGAL(file->fits, readout, hduHeader, tableHeader, sources, sourceIndex); \
     1504    }                                                                   
     1505
     1506    bool status = false;
     1507    if (file->type == PM_FPA_FILE_CMF) {
     1508        PM_SOURCES_READ_XGAL("PS1_V1",    CMF_PS1_V1);
     1509        PM_SOURCES_READ_XGAL("PS1_V2",    CMF_PS1_V2);
     1510        PM_SOURCES_READ_XGAL("PS1_V3",    CMF_PS1_V3);
     1511        PM_SOURCES_READ_XGAL("PS1_V4",    CMF_PS1_V4);
     1512        PM_SOURCES_READ_XGAL("PS1_V5",    CMF_PS1_V5);
     1513        PM_SOURCES_READ_XGAL("PS1_SV1",   CMF_PS1_SV1);
     1514        PM_SOURCES_READ_XGAL("PS1_SV2",   CMF_PS1_SV2);
     1515        PM_SOURCES_READ_XGAL("PS1_DV1",   CMF_PS1_DV1);
     1516        PM_SOURCES_READ_XGAL("PS1_DV2",   CMF_PS1_DV2);
     1517        PM_SOURCES_READ_XGAL("PS1_DV3",   CMF_PS1_DV3);
     1518    }
     1519    psFree(tableHeader);
     1520    return status;
     1521}
Note: See TracChangeset for help on using the changeset viewer.