IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 20, 2010, 2:30:45 PM (16 years ago)
Author:
watersc1
Message:

Attempting to bring branch in sync with trunk

Location:
branches/czw_branch/20101203
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20101203

  • branches/czw_branch/20101203/psModules/src/camera/pmFPAFlags.c

    r15477 r30118  
    4949}
    5050
     51bool pmReadoutSetFileStatus(pmReadout *readout, bool status)
     52{
     53    PS_ASSERT_PTR_NON_NULL(readout, false);
     54
     55    readout->file_exists = status;
     56    return true;
     57}
     58
     59bool pmFPAviewSetFileStatus (pmFPA *fpa, const pmFPAview *view, bool status) {
     60
     61    PS_ASSERT_PTR_NON_NULL(fpa, false);
     62    PS_ASSERT_PTR_NON_NULL(view, false);
     63
     64    if (view->chip == -1) {
     65        bool set = pmFPASetFileStatus (fpa, status);
     66        return set;
     67    }
     68
     69    if (view->chip >= fpa->chips->n) {
     70        psError(PS_ERR_IO, true, "Requested chip == %d >= fpa->chips->n == %ld", view->chip, fpa->chips->n);
     71        return false;
     72    }
     73    pmChip *chip = fpa->chips->data[view->chip];
     74
     75    if (view->cell == -1) {
     76        bool set = pmChipSetFileStatus (chip, status);
     77        return set;
     78    }
     79
     80    if (view->cell >= chip->cells->n) {
     81        psError(PS_ERR_IO, true, "Requested cell == %d >= chip->cells->n == %ld", view->cell, chip->cells->n);
     82        return false;
     83    }
     84    pmCell *cell = chip->cells->data[view->cell];
     85
     86    if (view->readout == -1) {
     87        bool set = pmCellSetFileStatus (cell, status);
     88        return set;
     89    }
     90
     91    if (view->readout >= cell->readouts->n) {
     92        psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouds->n == %ld", view->readout, cell->readouts->n);
     93        return false;
     94    }
     95    pmReadout *readout = cell->readouts->data[view->readout];
     96
     97    bool set = pmReadoutSetFileStatus (readout, status);
     98    return set;
     99}
     100
    51101bool pmFPACheckFileStatus(const pmFPA *fpa)
    52102{
     
    125175    for (int i = 0; i < cell->readouts->n; i++) {
    126176        pmReadout *readout = cell->readouts->data[i];
    127         readout->data_exists = status;
    128     }
    129     return true;
     177        pmReadoutSetDataStatus(readout, status);
     178    }
     179    return true;
     180}
     181
     182bool pmReadoutSetDataStatus (pmReadout *readout, bool status)
     183{
     184    PS_ASSERT_PTR_NON_NULL(readout, false);
     185
     186    readout->data_exists = status;
     187    return true;
     188}
     189
     190bool pmFPAviewSetDataStatus (pmFPA *fpa, const pmFPAview *view, bool status) {
     191
     192    PS_ASSERT_PTR_NON_NULL(fpa, false);
     193    PS_ASSERT_PTR_NON_NULL(view, false);
     194
     195    if (view->chip == -1) {
     196        bool set = pmFPASetDataStatus (fpa, status);
     197        return set;
     198    }
     199
     200    if (view->chip >= fpa->chips->n) {
     201        psError(PS_ERR_IO, true, "Requested chip == %d >= fpa->chips->n == %ld", view->chip, fpa->chips->n);
     202        return false;
     203    }
     204    pmChip *chip = fpa->chips->data[view->chip];
     205
     206    if (view->cell == -1) {
     207        bool set = pmChipSetDataStatus (chip, status);
     208        return set;
     209    }
     210
     211    if (view->cell >= chip->cells->n) {
     212        psError(PS_ERR_IO, true, "Requested cell == %d >= chip->cells->n == %ld", view->cell, chip->cells->n);
     213        return false;
     214    }
     215    pmCell *cell = chip->cells->data[view->cell];
     216
     217    if (view->readout == -1) {
     218        bool set = pmCellSetDataStatus (cell, status);
     219        return set;
     220    }
     221
     222    if (view->readout >= cell->readouts->n) {
     223        psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouds->n == %ld", view->readout, cell->readouts->n);
     224        return false;
     225    }
     226    pmReadout *readout = cell->readouts->data[view->readout];
     227
     228    bool set = pmReadoutSetDataStatus (readout, status);
     229    return set;
    130230}
    131231
  • branches/czw_branch/20101203/psModules/src/camera/pmFPAFlags.h

    r13190 r30118  
    3434                        );
    3535
     36bool pmReadoutSetFileStatus(pmReadout *readout, bool status);
     37
     38bool pmFPAviewSetFileStatus (pmFPA *fpa, const pmFPAview *view, bool status);
     39
    3640// Functions to check the file_exists flags
    3741
     
    6569                        );
    6670
     71bool pmReadoutSetDataStatus (pmReadout *readout, bool status);
     72
     73bool pmFPAviewSetDataStatus (pmFPA *fpa, const pmFPAview *view, bool status);
    6774
    6875// Functions the check the data_exists flags
  • branches/czw_branch/20101203/psModules/src/camera/pmFPAfile.c

    r29833 r30118  
    3636        return;
    3737    }
    38     psTrace ("pmFPAfileFree", 5, "freeing %s %ld\n", file->name,(psU64) file->fits);
     38    psTrace ("pmFPAfileFree", 5, "freeing %s %p\n", file->name, file->fits);
    3939    psAssert(!fpaFileFreeStrict || file->fits == NULL, "File %s wasn't closed.", file->name);
    4040
  • branches/czw_branch/20101203/psModules/src/camera/pmFPAfileIO.c

    r29833 r30118  
    135135    PS_ASSERT_PTR_NON_NULL(view, false);
    136136
    137     // an internal file should not be sent here (should not be left on config->files)
    138     PS_ASSERT(file->mode != PM_FPA_MODE_INTERNAL, false);
    139 
    140137    // skip the following states
    141138    if (file->state & PM_FPA_STATE_INACTIVE) {
     
    143140        return true;
    144141    }
     142
     143    // an active internal file should not be sent here (should not be left on config->files)
     144    PS_ASSERT(file->mode != PM_FPA_MODE_INTERNAL, false);
     145
    145146    if (file->mode != PM_FPA_MODE_READ) {
    146147        psTrace("psModules.camera", 6, "skip read for %s, mode is not READ", file->name);
     
    258259        return true;
    259260    }
     261
     262    // an active internal file should not be returned to here
     263    PS_ASSERT(file->mode != PM_FPA_MODE_INTERNAL, false);
     264
    260265    if (file->mode != PM_FPA_MODE_WRITE) {
    261266        psTrace("psModules.camera", 6, "skip create for non-write file %s", file->name);
    262267        return true;
    263268    }
    264 
    265     // an internal file should not be returned to here
    266     PS_ASSERT(file->mode != PM_FPA_MODE_INTERNAL, false);
    267269
    268270    // get the current level
     
    335337    }
    336338
     339    // an ACTIVE internal file should not be sent here
     340    PS_ASSERT(file->mode != PM_FPA_MODE_INTERNAL, false);
     341
    337342    if (file->mode != PM_FPA_MODE_WRITE) {
    338343        psTrace("psModules.camera", 6, "skip write for %s, mode is not WRITE", file->name);
    339344        return true;
    340     }
    341 
    342     // an internal file should not be returned to here
    343     if (file->mode == PM_FPA_MODE_INTERNAL) {
    344         psError(PS_ERR_IO, true, "File is mode PM_FPA_MODE_INTERNAL");
    345         return false;
    346345    }
    347346
     
    523522    PS_ASSERT_PTR_NON_NULL(view, false);
    524523
    525     // an internal file should not be sent here (should not be left on config->files)
    526     PS_ASSERT(file->mode != PM_FPA_MODE_INTERNAL, false);
    527 
    528524    // skip the following states
    529525    if (file->state & PM_FPA_STATE_INACTIVE) {
     
    531527        return true;
    532528    }
     529
    533530    if (file->state == PM_FPA_STATE_CLOSED) {
    534531        psTrace("psModules.camera", 6, "skip close for %s, files is closed", file->name);
    535532        return true;
    536533    }
     534
     535    // an active internal file should not be sent here (should not be left on config->files)
     536    PS_ASSERT(file->mode != PM_FPA_MODE_INTERNAL, false);
    537537
    538538    // is current level == open level?
     
    596596    PS_ASSERT_PTR_NON_NULL(view, false);
    597597
    598     // an internal file should not be sent here (should not be left on config->files)
    599     PS_ASSERT(file->mode != PM_FPA_MODE_INTERNAL, false);
    600 
    601598    if (file->state & PM_FPA_STATE_INACTIVE) {
    602599        psTrace("psModules.camera", 6, "skip free for %s, files is inactive", file->name);
    603600        return true;
    604601    }
     602
     603    // an active internal file should not be sent here (should not be left on config->files)
     604    PS_ASSERT(file->mode != PM_FPA_MODE_INTERNAL, false);
    605605
    606606    // get the current level
     
    746746    }
    747747
    748     // these are programming errors
     748    // an ACTIVE internal file should not be sent here
    749749    PS_ASSERT(file->mode != PM_FPA_MODE_NONE, false);
    750750    PS_ASSERT(file->mode != PM_FPA_MODE_INTERNAL, false);
  • branches/czw_branch/20101203/psModules/src/concepts/pmConceptsAverage.c

    r29603 r30118  
    136136    return average;
    137137}
     138float medianWithDropouts (psList *sources, char *name) {
     139
     140    bool status;
     141
     142    psListIterator *sourcesIter = psListIteratorAlloc(sources, PS_LIST_HEAD, false); // Iterator for sources
     143    pmCell *cell = NULL;                // Source cell from iteration
     144
     145    psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN);
     146    psVector *values = psVectorAlloc(sources->n, PS_TYPE_F32);
     147    int nvalues = 0;
     148    while ((cell = psListGetAndIncrement(sourcesIter))) {
     149        if (!cell) {
     150            continue;
     151        }
     152
     153        float value = psMetadataLookupF32(&status, cell->concepts, name);
     154        if (!status) continue;
     155        if (!isfinite(value)) continue;
     156
     157        values->data.F32[nvalues++] = value;
     158    }
     159    psFree (sourcesIter);
     160    if (!nvalues) {
     161        psWarning("no valid values found for %s\n", name);
     162        psFree(values);
     163        psFree(stats);
     164        return INFINITY;
     165    }
     166    if (!(values = psVectorRealloc(values, nvalues))) {
     167        psWarning("failed to reallocate values vector for %s\n", name);
     168        psFree(stats);
     169        return INFINITY;
     170    }
     171    if (!psVectorStats(stats, values, NULL, NULL, 0)) {
     172        psWarning("psVectorStats failed for %s\n", name);
     173        psFree(values);
     174        psFree(stats);
     175        return INFINITY;
     176    }
     177
     178    psF32 median = psStatsGetValue(stats, PS_STAT_SAMPLE_MEDIAN);
     179
     180    psFree(values);
     181    psFree(stats);
     182
     183    return median;
     184}
    138185
    139186// Set a variety of concepts in a cell by averaging over several
     
    145192    PS_ASSERT_INT_POSITIVE(sources->n, false);
    146193
    147     float saturation = INFINITY;        // Saturation level
    148194    float bad        = -INFINITY;       // Bad level
    149195    double time      = 0.0;             // Time of observation
     
    158204    float exposure  = averageWithDropouts (sources, "CELL.EXPOSURE");
    159205    float darktime  = averageWithDropouts (sources, "CELL.DARKTIME");
     206    float saturation = medianWithDropouts(sources, "CELL.SATURATION");
    160207
    161208    // other concepts are a bit more "special"
     
    221268        }
    222269
    223         float cellSaturation = psMetadataLookupF32(NULL, cell->concepts, "CELL.SATURATION");
    224         if (cellSaturation > 10000) {
    225             // do not allow invalid values to polute this calculation
    226             // XXX really need to do this on the basis of the fraction of the cell that contributes..
    227             // if a cell is completely masked, it should not be included.
    228             if (cellSaturation < saturation) {
    229                 saturation = cellSaturation;
    230             }
    231         }
    232270        float cellBad = psMetadataLookupF32(NULL, cell->concepts, "CELL.BAD");
    233271        if (cellBad > bad) {
  • branches/czw_branch/20101203/psModules/src/config/pmConfigDump.c

    r27147 r30118  
    150150    }
    151151
    152     if (!psMetadataConfigWrite(config->user, resolved)) {
     152    // check for Metadata compression options:
     153    char *compressMode = NULL;
     154    bool status = false;
     155    if (config->camera) {
     156        compressMode = psMetadataLookupStr(&status, config->camera, "METADATA.COMPRESSION");
     157    }
     158
     159    if (!psMetadataConfigWrite(config->user, resolved, compressMode)) {
    153160        psError(psErrorCodeLast(), false, "Unable to dump configuration to %s", filename);
    154161        psFree(resolved);
  • branches/czw_branch/20101203/psModules/src/detrend/pmNonLinear.c

    r29833 r30118  
    332332        return(0.0);
    333333    }
    334 /*     if (flux > correction_fluxes->data.F32[bin]) { */
    335 /*      return(0.0); */
    336 /*     } */
    337334 
    338335    for (int i = 0; i < correction_fluxes->n - 1; i++) {
     
    347344    }
    348345
    349 /*   PS_BIN_FOR_VALUE(bin,correction_fluxes,flux); */
    350 /*   if ((bin < 0)||(bin > correction_fluxes->n)) { */
    351 /*     return(1.0); */
    352 /*   } */
    353  
    354 /*   PS_BIN_INTERPOLATE(result,correction_fluxes,correction_factors,bin,flux); */
    355346    if (!isfinite(result)) {
    356347        result = 0.0;
    357348    }
    358 /*     if (result <= 0) { */
    359 /*      result = 1.0; */
    360 /*     } */
    361349    return(result);
    362350}
     
    372360        return(0.0);
    373361    }
    374 /*     if (flux > correction_fluxes->data.F32[bin]) { */
    375 /*      return(0.0); */
    376 /*     } */
    377362
    378363    for (int i = 0; i < correction_fluxes->n - 1; i++) {
     
    389374    }
    390375
    391 /*   PS_BIN_FOR_VALUE(bin,correction_fluxes,flux); */
    392 /*   if ((bin < 0)||(bin > correction_fluxes->n)) { */
    393 /*     return(1.0); */
    394 /*   } */
    395  
    396 /*   PS_BIN_INTERPOLATE(result,correction_fluxes,correction_factors,bin,flux); */
    397376    if (!isfinite(result)) {
    398377        result = 0.0;
    399378    }
    400 /*     if (result <= 0) { */
    401 /*      result = 1.0; */
    402 /*     } */
    403379    return(result);
    404380}
    405 
    406  
    407  
  • branches/czw_branch/20101203/psModules/src/objects

  • branches/czw_branch/20101203/psModules/src/objects/pmPSF_IO.c

    r29004 r30118  
    6262#include "pmSourceIO.h"
    6363
     64bool pmPSFmodelReadPSFClump (psMetadata *analysis, psMetadata *header);
     65
    6466bool pmPSFmodelCheckDataStatusForView (const pmFPAview *view, const pmFPAfile *file)
    6567{
     
    851853
    852854    // read the psf clump data for each region
     855    status = false;
    853856    if (roAnalysis) {
    854         int nRegions = psMetadataLookupS32 (&status, header, "PSF_CLN");
    855         if (!status) {
    856             // read old-style psf clump data
    857 
    858             char regionName[64];
    859             snprintf (regionName, 64, "PSF.CLUMP.REGION.000");
    860             psMetadataAddS32 (roAnalysis, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", 1);
    861 
    862             psMetadata *regionMD = psMetadataLookupPtr (&status, roAnalysis, regionName);
    863             if (!regionMD) {
    864                 regionMD = psMetadataAlloc();
    865                 psMetadataAddMetadata (roAnalysis, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD);
    866                 psFree (regionMD);
    867             }
    868 
    869             // psf clump data
    870             pmPSFClump psfClump;
    871 
    872             psfClump.X  = psMetadataLookupF32 (&status, header, "PSF_CLX" );  assert(status);
    873             psfClump.Y  = psMetadataLookupF32 (&status, header, "PSF_CLY" );  assert(status);
    874             psfClump.dX = psMetadataLookupF32 (&status, header, "PSF_CLDX");  assert(status);
    875             psfClump.dY = psMetadataLookupF32 (&status, header, "PSF_CLDY");  assert(status);
    876 
    877             psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X",  PS_META_REPLACE, "psf clump center", psfClump.X);
    878             psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y",  PS_META_REPLACE, "psf clump center", psfClump.Y);
    879             psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);
    880             psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);
    881         } else {
    882             psMetadataAddS32 (roAnalysis, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", nRegions);
    883 
    884             for (int i = 0; i < nRegions; i++) {
    885                 char key[10];
    886                 char regionName[64];
    887                 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", i);
    888 
    889                 psMetadata *regionMD = psMetadataLookupPtr (&status, roAnalysis, regionName);
    890                 if (!regionMD) {
    891                     regionMD = psMetadataAlloc();
    892                     psMetadataAddMetadata (roAnalysis, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD);
    893                     psFree (regionMD);
    894                 }
    895 
    896                 // psf clump data
    897                 pmPSFClump psfClump;
    898 
    899                 snprintf (key, 9, "CLX_%03d", i);
    900                 psfClump.X  = psMetadataLookupF32 (&status, header, key);  assert(status);
    901                 snprintf (key, 9, "CLY_%03d", i);
    902                 psfClump.Y  = psMetadataLookupF32 (&status, header, key);  assert(status);
    903                 snprintf (key, 9, "CLDX_%03d", i);
    904                 psfClump.dX = psMetadataLookupF32 (&status, header, key);  assert(status);
    905                 snprintf (key, 9, "CLDY_%03d", i);
    906                 psfClump.dY = psMetadataLookupF32 (&status, header, key);  assert(status);
    907 
    908                 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X",  PS_META_REPLACE, "psf clump center", psfClump.X);
    909                 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y",  PS_META_REPLACE, "psf clump center", psfClump.Y);
    910                 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);
    911                 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);
    912             }
    913         }
     857        status = pmPSFmodelReadPSFClump (roAnalysis, header);
     858        if (!status) {
     859            psMetadataAddS32 (roAnalysis, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", 0);
     860        }
     861    }
     862    if (!roAnalysis || !status) {
     863        psWarning ("no PSF.CLUMP data available for PSF model");
    914864    }
    915865
     
    11231073}
    11241074
    1125 // XXX pmPSF to/from Metadata functions were defined for 1.22 and earlier, but were dropped
     1075bool pmPSFmodelReadPSFClump (psMetadata *analysis, psMetadata *header) {
     1076
     1077    bool status = false;;
     1078
     1079    int nRegions = psMetadataLookupS32 (&status, header, "PSF_CLN");
     1080    if (!status) {
     1081        // read old-style psf clump data
     1082
     1083        char regionName[64];
     1084        snprintf (regionName, 64, "PSF.CLUMP.REGION.000");
     1085        psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName);
     1086
     1087        if (!regionMD) {
     1088            regionMD = psMetadataAlloc();
     1089            psMetadataAddMetadata (analysis, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD);
     1090            psFree (regionMD);
     1091        }
     1092
     1093        // psf clump data
     1094        pmPSFClump psfClump;
     1095        psfClump.X  = psMetadataLookupF32 (&status, header, "PSF_CLX" );  if (!status) return false;
     1096        psfClump.Y  = psMetadataLookupF32 (&status, header, "PSF_CLY" );  if (!status) return false;
     1097        psfClump.dX = psMetadataLookupF32 (&status, header, "PSF_CLDX");  if (!status) return false;
     1098        psfClump.dY = psMetadataLookupF32 (&status, header, "PSF_CLDY");  if (!status) return false;
     1099
     1100        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X",  PS_META_REPLACE, "psf clump center", psfClump.X);
     1101        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y",  PS_META_REPLACE, "psf clump center", psfClump.Y);
     1102        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);
     1103        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);
     1104        psMetadataAddS32 (analysis, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", 1);
     1105    } else {
     1106        for (int i = 0; i < nRegions; i++) {
     1107            char key[10];
     1108            char regionName[64];
     1109            snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", i);
     1110
     1111            psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName);
     1112            if (!regionMD) {
     1113                regionMD = psMetadataAlloc();
     1114                psMetadataAddMetadata (analysis, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD);
     1115                psFree (regionMD);
     1116            }
     1117
     1118            // psf clump data
     1119            pmPSFClump psfClump;
     1120
     1121            snprintf (key, 9, "CLX_%03d", i);
     1122            psfClump.X  = psMetadataLookupF32 (&status, header, key);  if (!status) return false;
     1123            snprintf (key, 9, "CLY_%03d", i);
     1124            psfClump.Y  = psMetadataLookupF32 (&status, header, key);  if (!status) return false;
     1125            snprintf (key, 9, "CLDX_%03d", i);
     1126            psfClump.dX = psMetadataLookupF32 (&status, header, key);  if (!status) return false;
     1127            snprintf (key, 9, "CLDY_%03d", i);
     1128            psfClump.dY = psMetadataLookupF32 (&status, header, key);  if (!status) return false;
     1129
     1130            psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X",  PS_META_REPLACE, "psf clump center", psfClump.X);
     1131            psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y",  PS_META_REPLACE, "psf clump center", psfClump.Y);
     1132            psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);
     1133            psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);
     1134        }
     1135        psMetadataAddS32 (analysis, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", nRegions);
     1136    }
     1137    return true;
     1138}
  • branches/czw_branch/20101203/psModules/src/objects/pmPSFtry.h

    r25754 r30118  
    100100bool pmPSFtryFitEXT (pmPSFtry *psfTry, pmPSFOptions *options, psImageMaskType maskVal, psImageMaskType markVal);
    101101
    102 bool pmPSFtryMakePSF (pmPSFtry *psfTry);
     102bool pmPSFtryMakePSF (bool *pGoodFit, pmPSFtry *psfTry);
    103103
    104104bool pmPSFtryFitPSF (pmPSFtry *psfTry, pmPSFOptions *options, psImageMaskType maskVal, psImageMaskType markVal);
     
    123123);
    124124
    125 bool pmPSFFitShapeParams (pmPSF *psf, psArray *sources, psVector *x, psVector *y, psVector *srcMask);
     125bool pmPSFFitShapeParams (bool *pGoodFit, pmPSF *psf, psArray *sources, psVector *x, psVector *y, psVector *srcMask);
    126126
    127127float psVectorSystematicError (psVector *residuals, psVector *errors, float clipFraction);
  • branches/czw_branch/20101203/psModules/src/objects/pmPSFtryMakePSF.c

    r29004 r30118  
    5050Note: some of the array entries may be NULL (failed fits); ignore them.
    5151 *****************************************************************************/
    52 bool pmPSFtryMakePSF (pmPSFtry *psfTry)
     52bool pmPSFtryMakePSF (bool *pGoodFit, pmPSFtry *psfTry)
    5353{
    5454    PS_ASSERT_PTR_NON_NULL(psfTry, false);
     
    7474
    7575    // fit the shape parameters (SXX, SYY, SXY) as a function of position
    76     if (!pmPSFFitShapeParams (psf, psfTry->sources, x, y, srcMask)) {
     76    if (!pmPSFFitShapeParams (pGoodFit, psf, psfTry->sources, x, y, srcMask)) {
    7777        psFree(x);
    7878        psFree(y);
    7979        return false;
     80    }
     81    if (!*pGoodFit) {
     82        psWarning ("poor fit to PSF shape parameters for trend order %d, %d, skipping\n", psf->trendNx, psf->trendNy);
     83        psFree(x);
     84        psFree(y);
     85        return true;
    8086    }
    8187
     
    115121        // the mask is carried from previous steps and updated with this operation
    116122        // the weight is either the flux error or NULL, depending on 'psf->poissonErrorParams'
    117         if (!pmTrend2DFit (trend, srcMask, 0xff, x, y, z, NULL)) {
     123        if (!pmTrend2DFit (pGoodFit, trend, srcMask, 0xff, x, y, z, NULL)) {
    118124            psError(PS_ERR_UNKNOWN, false, "failed to build psf model for parameter %d", i);
    119125            psFree(x);
     
    122128            return false;
    123129        }
     130        if (!*pGoodFit) {
     131            // if we do not get a good fit (but do not actually hit an error),
     132            // tell the calling program to try something else
     133            psWarning ("poor fit to PSF parameter %d for trend order %d, %d, skipping\n", i, psf->trendNx, psf->trendNy);
     134            psFree(x);
     135            psFree(y);
     136            psFree(z);
     137            return true;
     138        }
    124139        if (trend->mode == PM_TREND_MAP) {
    125140            // p_psImagePrint (2, trend->map->map, "param N Before"); // XXX TEST:
     
    139154
    140155            pmModel *modelPSF = pmModelFromPSF (source->modelEXT, psf);
     156            if (!modelPSF) {
     157                fprintf(f, "modelPSF is NULL\n");
     158                break;
     159            }
     160            if (!source->modelEXT) {
     161                fprintf(f, "source->modelEXT is NULL\n");
     162                break;
     163            }
    141164
    142165            fprintf (f, "%f %f : ", source->modelEXT->params->data.F32[PM_PAR_XPOS], source->modelEXT->params->data.F32[PM_PAR_YPOS]);
     
    163186
    164187// fit the shape parameters using the supplied order (pmPSF->trendNx,trendNy)
    165 bool pmPSFFitShapeParams (pmPSF *psf, psArray *sources, psVector *x, psVector *y, psVector *srcMask) {
     188bool pmPSFFitShapeParams (bool *pGoodFit, pmPSF *psf, psArray *sources, psVector *x, psVector *y, psVector *srcMask) {
    166189
    167190    // we are doing a robust fit.  after each pass, we drop points which are more deviant than
     
    219242        trend = psf->params->data[PM_PAR_E0];
    220243        trend->stats->clipIter = 1; // in allocation, this value is set to the value of nIter, but we should use 1 here
    221         status &= pmTrend2DFit (trend, srcMask, 0xff, x, y, e0, NULL);
     244        status &= pmTrend2DFit (pGoodFit, trend, srcMask, 0xff, x, y, e0, NULL);
     245        if (!*pGoodFit) {
     246            psFree (e0);
     247            psFree (e1);
     248            psFree (e2);
     249            return true;
     250        }
    222251        mean = psStatsGetValue (trend->stats, meanOption);
    223252        stdev = psStatsGetValue (trend->stats, stdevOption);
     
    228257        trend = psf->params->data[PM_PAR_E1];
    229258        trend->stats->clipIter = 1; // in allocation, this value is set to the value of nIter, but we should use 1 here
    230         status &= pmTrend2DFit (trend, srcMask, 0xff, x, y, e1, NULL);
     259        status &= pmTrend2DFit (pGoodFit, trend, srcMask, 0xff, x, y, e1, NULL);
     260        if (!*pGoodFit) {
     261            psFree (e0);
     262            psFree (e1);
     263            psFree (e2);
     264            return true;
     265        }
    231266        mean = psStatsGetValue (trend->stats, meanOption);
    232267        stdev = psStatsGetValue (trend->stats, stdevOption);
     
    237272        trend = psf->params->data[PM_PAR_E2];
    238273        trend->stats->clipIter = 1; // in allocation, this value is set to the value of nIter, but we should use 1 here
    239         status &= pmTrend2DFit (trend, srcMask, 0xff, x, y, e2, NULL);
     274        status &= pmTrend2DFit (pGoodFit, trend, srcMask, 0xff, x, y, e2, NULL);
     275        if (!*pGoodFit) {
     276            psFree (e0);
     277            psFree (e1);
     278            psFree (e2);
     279            return true;
     280        }
    240281        mean = psStatsGetValue (trend->stats, meanOption);
    241282        stdev = psStatsGetValue (trend->stats, stdevOption);
     
    246287        if (!status) {
    247288            psError (PS_ERR_UNKNOWN, true, "failed to fit PSF shape params");
     289            psFree (e0);
     290            psFree (e1);
     291            psFree (e2);
    248292            return false;
    249293        }
  • branches/czw_branch/20101203/psModules/src/objects/pmPSFtryModel.c

    r29004 r30118  
    136136
    137137        // stage 2: construct a psf (pmPSF) from this collection of model fits, including the 2D variation
    138         if (!pmPSFtryMakePSF (psfTry)) {
     138        bool goodFit = false;
     139        if (!pmPSFtryMakePSF (&goodFit, psfTry)) {
    139140            psError(PS_ERR_UNKNOWN, false, "failed to construct a psf model from collection of sources");
    140141            psFree(psfTry);
    141142            return NULL;
    142143        }
     144        if (!goodFit) {
     145            psWarning ("poor psf fit for order %d, skipping\n", i);
     146            continue;
     147        }
    143148
    144149        // stage 3: refit with fixed shape parameters, measure pmPSFtry->metric
     
    169174    }
    170175    psFree (srcMask);
     176
     177    if (!minPSF) {
     178        psError(PS_ERR_UNKNOWN, false, "failed to construct a valid psf model from the sources");
     179        psFree(psfTry);
     180        return NULL;
     181    }
    171182
    172183    // keep the ones matching the min systematic error:
  • branches/czw_branch/20101203/psModules/src/objects/pmSource.c

    r29546 r30118  
    189189    // pixels.  Modifying these pixels (ie, subtracting the model) will affect the pixels seen
    190190    // by all copies.
    191     source->pixels   = psImageCopyView(NULL, in->pixels);
    192     source->variance   = psImageCopyView(NULL, in->variance);
     191    source->pixels   = in->pixels   ? psImageCopyView(NULL, in->pixels)   : NULL;
     192    source->variance = in->variance ? psImageCopyView(NULL, in->variance) : NULL;
    193193    source->maskView = in->maskView ? psImageCopyView(NULL, in->maskView) : NULL;
    194194
  • branches/czw_branch/20101203/psModules/src/objects/pmSourcePhotometry.c

    r29546 r30118  
    107107    // XXX handle negative flux, low-significance
    108108    if (model->dparams->data.F32[PM_PAR_I0] > 0) {
    109         SN = model->params->data.F32[PM_PAR_I0] / model->dparams->data.F32[PM_PAR_I0];
     109        SN = fabs(model->params->data.F32[PM_PAR_I0] / model->dparams->data.F32[PM_PAR_I0]);
    110110        source->errMag = 1.0 / SN;
    111111    } else {
     
    331331    }
    332332    if (apFluxOut) *apFluxOut = apFlux;
    333     if (apFluxErr) *apFluxErr = sqrt(apFluxVar);
     333    if (apFluxErr) *apFluxErr = sqrt(fabs(apFluxVar));
    334334
    335335    if (apFlux <= 0) {
  • branches/czw_branch/20101203/psModules/src/objects/pmTrend2D.c

    r25754 r30118  
    179179}
    180180
    181 bool pmTrend2DFit(pmTrend2D *trend, psVector *mask, psVectorMaskType maskVal, const psVector *x,
     181bool pmTrend2DFit(bool *pGoodFit, pmTrend2D *trend, psVector *mask, psVectorMaskType maskVal, const psVector *x,
    182182                  const psVector *y, const psVector *f, const psVector *df)
    183183{
     
    188188    PS_ASSERT_VECTOR_NON_NULL(f, false);
    189189
    190     bool status;
     190    bool status = false;
     191    *pGoodFit = false;
     192    // for the psImageMap fit, it is possible to have valid data but no valid solution for
     193    // example, an isolated cell may not be reached from other cells, making the solution
     194    // degenerate.  psImageMapFit should probably handle this case, but until it does, we allow
     195    // it to fail on the result, but not yield an error (pGoodFit = false).
     196    // psVectorClipFitPolynomial2D can not fail in this way (really?), so pGoodFit is always
     197    // true
     198
    191199    switch (trend->mode) {
    192200      case PM_TREND_POLY_ORD:
     
    196204        // of points in the image, and potentially based on the fractional range of the
    197205        // data?
     206        *pGoodFit = true;
    198207        break;
    199208
     
    201210        // XXX supply fraction from trend elements
    202211        // XXX need to add the API which adjusts the scale
    203         status = psImageMapClipFit(trend->map, trend->stats, mask, maskVal, x, y, f, df);
     212        status = psImageMapClipFit(pGoodFit, trend->map, trend->stats, mask, maskVal, x, y, f, df);
    204213        break;
    205214
  • branches/czw_branch/20101203/psModules/src/objects/pmTrend2D.h

    r29004 r30118  
    7676    );
    7777
    78 bool pmTrend2DFit(pmTrend2D *trend,
     78bool pmTrend2DFit(bool *goodFit,
     79                  pmTrend2D *trend,
    7980                  psVector *mask,       // Warning: mask is modified!
    8081                  psVectorMaskType maskVal,
Note: See TracChangeset for help on using the changeset viewer.