IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 17, 2014, 12:30:45 PM (12 years ago)
Author:
eugene
Message:

merge changes (from past YEAR) into trunk

Location:
branches/eam_branches/ipp-ops-20130712/psModules
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-ops-20130712/psModules

    • Property svn:mergeinfo deleted
  • branches/eam_branches/ipp-ops-20130712/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
         17pmSourceIO_CMF_PS1_SV3.c
        1618pmSourceIO_CMF_PS1_DV1.c
        1719pmSourceIO_CMF_PS1_DV2.c
        1820pmSourceIO_CMF_PS1_DV3.c
        19 
         21pmSourceIO_CMF_PS1_DV4.c
  • branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO.c

    r35610 r37066  
    4040#include "pmMoments.h"
    4141#include "pmModelFuncs.h"
     42#include "pmModelClass.h"
    4243#include "pmModel.h"
    4344#include "pmModelUtils.h"
    44 #include "pmModelClass.h"
    4545#include "pmSourceMasks.h"
    4646#include "pmSourceExtendedPars.h"
    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
     
    352365# define PM_SOURCES_WRITE(NAME,TYPE)                                    \
    353366    if (!strcmp (exttype, NAME)) {                                      \
    354         status &= pmSourcesWrite_##TYPE(file->fits, readout, sources, file->header, outhead, dataname, recipe); \
     367        status = pmSourcesWrite_##TYPE(file->fits, readout, sources, file->header, outhead, dataname, recipe); \
    355368        if (xsrcname) {                                                 \
    356369            status &= pmSourcesWrite_##TYPE##_XSRC(file->fits, readout, sources, file->header, xsrcname, recipe); \
     
    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
    567             status = true;
     591            status = false;
    568592            PM_SOURCES_WRITE("SMPDATA",   SMPDATA);
    569593            PM_SOURCES_WRITE("PS1_DEV_0", PS1_DEV_0);
     
    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);
     603            PM_SOURCES_WRITE("PS1_SV3",   CMF_PS1_SV3);
    578604            PM_SOURCES_WRITE("PS1_DV1",   CMF_PS1_DV1);
    579605            PM_SOURCES_WRITE("PS1_DV2",   CMF_PS1_DV2);
    580606            PM_SOURCES_WRITE("PS1_DV3",   CMF_PS1_DV3);
     607            PM_SOURCES_WRITE("PS1_DV4",   CMF_PS1_DV4);
    581608
    582609            psFree (outhead);
     
    609636        psFree (xfitname);
    610637        psFree (xradname);
     638        psFree (xgalname);
    611639        psFree (deteffname);
    612640
     
    620648        psFree (xfitname);
    621649        psFree (xradname);
     650        psFree (xgalname);
    622651        psFree (deteffname);
    623652        return false;
    624653
     654      case PM_FPA_FILE_CFF: {
     655        // determine the output table format
     656        psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PSPHOT");
     657        if (!status) {
     658            psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data");
     659            return false;
     660        }
     661
     662        hdu = pmFPAviewThisHDU (view, fpa);
     663        pmConfigConformHeader(hdu->header, file->format);
     664        psFitsWriteBlank (file->fits, hdu->header, NULL);
     665        file->header = hdu->header;
     666        file->wrote_phu = true;
     667        if (!pmSourcesWrite_CFF(readout, file->fits, sources, hdu->header, recipe)) {
     668            psError(PS_ERR_UNKNOWN, false, "failed to write CFF");
     669            return false;
     670        }
     671        break;
     672      }
     673       
    625674      default:
    626675        fprintf (stderr, "warning: type mismatch\n");
     
    914963    psArray *sources = NULL;
    915964    pmHDU *hdu;
     965
     966    // define the EXTNAME values for the different data segments:
     967    psString headname = NULL;
     968    psString dataname = NULL;
     969    psString deteffname = NULL;
     970    psString xsrcname = NULL;
     971    psString xfitname = NULL;
     972    psString xradname = NULL;
     973    psString xgalname = NULL;
     974
     975    psMetadata *tableHeader = NULL;
     976    char *xtension = NULL;
    916977
    917978    switch (file->type) {
     
    9631024        hdu = pmFPAviewThisHDU (view, file->fpa);
    9641025
    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 
    9731026        // determine the output table format. Assume if we need to output extendend source
    9741027        // parameters that they may exist in the input.
     
    9811034        }
    9821035
    983         // if this is not TRUE, the output files only contain the psf measurements.
    984         bool XSRC_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_ANALYSIS");
     1036        // if none of these are TRUE, we only read the psf measurements
     1037        // XXX: shouldn't we look for these extensions and read the regardless of the recipe values?
     1038        bool doPetrosian = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_PETROSIAN");
     1039        bool doAnnuli    = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_ANNULI");
     1040        bool XSRC_OUTPUT = doPetrosian || doAnnuli;
    9851041        bool XFIT_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_FITS");
    9861042        bool XRAD_OUTPUT = psMetadataLookupBool(&status, recipe, "RADIAL_APERTURES");
     1043        bool XGAL_OUTPUT = psMetadataLookupBool(&status, recipe, "GALAXY_SHAPES");
    9871044
    9881045        if (!pmSourceIOextnames(&headname, &dataname, &deteffname,
     
    9901047                XFIT_OUTPUT ? &xfitname : NULL,
    9911048                XRAD_OUTPUT ? &xradname : NULL,
     1049                XGAL_OUTPUT ? &xgalname : NULL,
    9921050                file, view)) {
    9931051            return false;
     
    10331091        }
    10341092
    1035         psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header
     1093        tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header
    10361094        if (!tableHeader) psAbort("cannot read table header");
    10371095
    1038         char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION");
     1096        xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION");
    10391097        if (!xtension) psAbort("cannot read table type");
    10401098        if (strcmp (xtension, "BINTABLE")) {
     
    10621120            PM_SOURCES_READ_PSF("PS1_V3",    CMF_PS1_V3);
    10631121            PM_SOURCES_READ_PSF("PS1_V4",    CMF_PS1_V4);
     1122            PM_SOURCES_READ_PSF("PS1_V5",    CMF_PS1_V5);
    10641123            PM_SOURCES_READ_PSF("PS1_SV1",   CMF_PS1_SV1);
    10651124            PM_SOURCES_READ_PSF("PS1_SV2",   CMF_PS1_SV2);
     1125            PM_SOURCES_READ_PSF("PS1_SV3",   CMF_PS1_SV3);
    10661126            PM_SOURCES_READ_PSF("PS1_DV1",   CMF_PS1_DV1);
    10671127            PM_SOURCES_READ_PSF("PS1_DV2",   CMF_PS1_DV2);
    10681128            PM_SOURCES_READ_PSF("PS1_DV3",   CMF_PS1_DV3);
     1129            PM_SOURCES_READ_PSF("PS1_DV4",   CMF_PS1_DV4);
     1130
     1131            if (!sources) {
     1132                psError(PS_ERR_IO, false, "reading CMF data from %s with format %s\n", file->filename, exttype);
     1133                return false;
     1134            }
    10691135
    10701136            long *sourceIndex = NULL;
    1071             if (XSRC_OUTPUT || XFIT_OUTPUT || XRAD_OUTPUT) {
     1137            if (XSRC_OUTPUT || XFIT_OUTPUT || XRAD_OUTPUT || XGAL_OUTPUT) {
     1138                // Build sourceIndex. Lookup table from source->seq to index in sources array.
     1139                // Consists of an array of length max(source->seq) + 1.
     1140
     1141                // find maximum sequence number
    10721142                long seq_max = -1;
    10731143                for (long i = sources->n -1; i >= 0; i--) {
     
    10821152                    }
    10831153                }
     1154                // allocate and initialize the index
    10841155                sourceIndex = psAlloc((seq_max + 1) * sizeof(long));
    10851156                for (long i = 0; i < seq_max; i++) {
    10861157                    sourceIndex[i] = -1;
    10871158                }
     1159                // populate the index
    10881160                for (long i = 0; i < sources->n; i++) {
    10891161                    pmSource *source = sources->data[i];
     
    11111183                }
    11121184                psFree(xradname);
     1185            }
     1186            if (XGAL_OUTPUT && xgalname) {
     1187                // a cmf file may have an XGAL extension, but it is not required
     1188                if (!pmReadoutReadXGAL(file, readout, exttype, hdu->header, xgalname, sources, sourceIndex)) {
     1189                    // do anything?
     1190                }
     1191                psFree(xgalname);
    11131192            }
    11141193            psFree(sourceIndex);
     
    11321211        break;
    11331212
     1213      case PM_FPA_FILE_CFF: {
     1214        // determine the output table format
     1215        psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PSPHOT");
     1216        if (!status) {
     1217            psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data");
     1218            return false;
     1219        }
     1220        // read in header, if not yet loaded
     1221        hdu = pmFPAviewThisHDU (view, file->fpa);
     1222
     1223        // look these up in the camera config?
     1224        // headrule = {CHIP.NAME}.hdr
     1225        // datarule = {CHIP.NAME}.cff
     1226
     1227        // define the EXTNAME values for the different data segments:
     1228        headname = pmFPAfileNameFromRule("{CHIP.NAME}.hdr", file, view);
     1229        dataname = pmFPAfileNameFromRule("{CHIP.NAME}.cff", file, view);
     1230
     1231        // advance to the IMAGE HEADER extension
     1232        if (hdu->header == NULL) {
     1233            // if the IMAGE header does not exist, we have no data for this view
     1234            if (!psFitsMoveExtNameClean (file->fits, headname)) {
     1235                readout->data_exists = false;
     1236                psFree (headname);
     1237                psFree (dataname);
     1238                return true;
     1239            }
     1240            hdu->header = psFitsReadHeader (NULL, file->fits);
     1241        }
     1242
     1243        // advance to the table data extension
     1244        // since we have read the IMAGE header, the TABLE header should exist
     1245        if (!psFitsMoveExtName (file->fits, dataname)) {
     1246            psAbort("cannot find data extension %s in %s", dataname, file->filename);
     1247        }
     1248
     1249        tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header
     1250        if (!tableHeader) psAbort("cannot read table header");
     1251
     1252        // verify this is a binary table
     1253        char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION");
     1254        if (!xtension) psAbort("cannot read table type");
     1255        if (strcmp (xtension, "BINTABLE")) {
     1256            psWarning ("no binary table in extension %s, skipping\n", dataname);
     1257            psFree(tableHeader);
     1258            return false;
     1259        }
     1260
     1261        sources = pmSourcesRead_CFF(file->fits, hdu->header, recipe);
     1262
     1263        psTrace("psModules.objects", 6, "read CMF table from %s : %s : %s", file->filename, headname, dataname);
     1264        psFree (headname);
     1265        psFree (dataname);
     1266        psFree (tableHeader);
     1267        }
     1268        break;
     1269
    11341270      default:
    11351271        fprintf (stderr, "warning: type mismatch\n");
     
    12721408        PM_SOURCES_READ_XSRC("PS1_V3",    CMF_PS1_V3);
    12731409        PM_SOURCES_READ_XSRC("PS1_V4",    CMF_PS1_V4);
     1410        PM_SOURCES_READ_XSRC("PS1_V5",    CMF_PS1_V5);
    12741411        PM_SOURCES_READ_XSRC("PS1_SV1",   CMF_PS1_SV1);
    12751412        PM_SOURCES_READ_XSRC("PS1_SV2",   CMF_PS1_SV2);
     1413        PM_SOURCES_READ_XSRC("PS1_SV3",   CMF_PS1_SV3);
    12761414        PM_SOURCES_READ_XSRC("PS1_DV1",   CMF_PS1_DV1);
    12771415        PM_SOURCES_READ_XSRC("PS1_DV2",   CMF_PS1_DV2);
    12781416        PM_SOURCES_READ_XSRC("PS1_DV3",   CMF_PS1_DV3);
     1417        PM_SOURCES_READ_XSRC("PS1_DV4",   CMF_PS1_DV4);
    12791418    }
    12801419    psFree(tableHeader);
     
    13111450        PM_SOURCES_READ_XFIT("PS1_V3",    CMF_PS1_V3);
    13121451        PM_SOURCES_READ_XFIT("PS1_V4",    CMF_PS1_V4);
     1452        PM_SOURCES_READ_XFIT("PS1_V5",    CMF_PS1_V5);
    13131453        PM_SOURCES_READ_XFIT("PS1_SV1",   CMF_PS1_SV1);
    13141454        PM_SOURCES_READ_XFIT("PS1_SV2",   CMF_PS1_SV2);
     1455        PM_SOURCES_READ_XFIT("PS1_SV3",   CMF_PS1_SV3);
    13151456        PM_SOURCES_READ_XFIT("PS1_DV1",   CMF_PS1_DV1);
    13161457        PM_SOURCES_READ_XFIT("PS1_DV2",   CMF_PS1_DV2);
    13171458        PM_SOURCES_READ_XFIT("PS1_DV3",   CMF_PS1_DV3);
     1459        PM_SOURCES_READ_XFIT("PS1_DV4",   CMF_PS1_DV4);
    13181460    }
    13191461    psFree(tableHeader);
     
    13491491        PM_SOURCES_READ_XRAD("PS1_V3",    CMF_PS1_V3);
    13501492        PM_SOURCES_READ_XRAD("PS1_V4",    CMF_PS1_V4);
     1493        PM_SOURCES_READ_XRAD("PS1_V5",    CMF_PS1_V5);
    13511494        PM_SOURCES_READ_XRAD("PS1_SV1",   CMF_PS1_SV1);
    13521495        PM_SOURCES_READ_XRAD("PS1_SV2",   CMF_PS1_SV2);
     1496        PM_SOURCES_READ_XRAD("PS1_SV3",   CMF_PS1_SV3);
    13531497        PM_SOURCES_READ_XRAD("PS1_DV1",   CMF_PS1_DV1);
    13541498        PM_SOURCES_READ_XRAD("PS1_DV2",   CMF_PS1_DV2);
    13551499        PM_SOURCES_READ_XRAD("PS1_DV3",   CMF_PS1_DV3);
     1500        PM_SOURCES_READ_XRAD("PS1_DV4",   CMF_PS1_DV4);
    13561501    }
    13571502    psFree(tableHeader);
    13581503    return status;
    13591504}
     1505static bool pmReadoutReadXGAL(pmFPAfile *file, pmReadout *readout, char *exttype, psMetadata *hduHeader, psString xgalname, psArray *sources, long *sourceIndex)
     1506{
     1507    if (!psFitsMoveExtNameClean (file->fits, xgalname)) {
     1508        psTrace ("pmFPAfile", 1, "cannot find xgal extension %s in %s, skipping", xgalname, file->filename);
     1509        return false;
     1510    }
     1511
     1512    psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header
     1513    if (!tableHeader) psAbort("cannot read table header");
     1514
     1515    char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION");
     1516    if (!xtension) psAbort("cannot read table type");
     1517    if (strcmp (xtension, "BINTABLE")) {
     1518        psFree(tableHeader);
     1519        psWarning ("no binary table in extension %s, skipping\n", xgalname);
     1520        return false;
     1521    }
     1522
     1523# define PM_SOURCES_READ_XGAL(NAME,TYPE)                                \
     1524    if (!strcmp (exttype, NAME)) {                                      \
     1525        status = pmSourcesRead_##TYPE##_XGAL(file->fits, readout, hduHeader, tableHeader, sources, sourceIndex); \
     1526    }                                                                   
     1527
     1528    bool status = false;
     1529    if (file->type == PM_FPA_FILE_CMF) {
     1530        PM_SOURCES_READ_XGAL("PS1_V1",    CMF_PS1_V1);
     1531        PM_SOURCES_READ_XGAL("PS1_V2",    CMF_PS1_V2);
     1532        PM_SOURCES_READ_XGAL("PS1_V3",    CMF_PS1_V3);
     1533        PM_SOURCES_READ_XGAL("PS1_V4",    CMF_PS1_V4);
     1534        PM_SOURCES_READ_XGAL("PS1_V5",    CMF_PS1_V5);
     1535        PM_SOURCES_READ_XGAL("PS1_SV1",   CMF_PS1_SV1);
     1536        PM_SOURCES_READ_XGAL("PS1_SV2",   CMF_PS1_SV2);
     1537        PM_SOURCES_READ_XGAL("PS1_SV3",   CMF_PS1_SV3);
     1538        PM_SOURCES_READ_XGAL("PS1_DV1",   CMF_PS1_DV1);
     1539        PM_SOURCES_READ_XGAL("PS1_DV2",   CMF_PS1_DV2);
     1540        PM_SOURCES_READ_XGAL("PS1_DV3",   CMF_PS1_DV3);
     1541        PM_SOURCES_READ_XGAL("PS1_DV4",   CMF_PS1_DV4);
     1542    }
     1543    psFree(tableHeader);
     1544    return status;
     1545}
Note: See TracChangeset for help on using the changeset viewer.