IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 25930


Ignore:
Timestamp:
Oct 22, 2009, 4:54:27 PM (17 years ago)
Author:
watersc1
Message:

Updated fringe fitting code.

Corrected Bool->S32 bug for BTOOLAPP header concept.

Location:
trunk
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppImage/src/Makefile.am

    r25299 r25930  
    4141        ppImageDetrendFringe.c \
    4242        ppImageDetrendFree.c \
     43        ppImageDetrendPattern.c \
    4344        ppImageRebinReadout.c \
    4445        ppImageMosaic.c \
  • trunk/ppImage/src/ppImage.h

    r25875 r25930  
    159159bool ppImageBurntoolMask(pmConfig *config, ppImageOptions *options, pmFPAview *view, pmReadout *mask);
    160160
     161bool ppImageDetrendPatternApply(pmConfig *config, pmChip *chip, const pmFPAview *inputView, const ppImageOptions *options);
     162
    161163// Record which detrend file was used for the detrending
    162164bool ppImageDetrendRecord(
  • trunk/ppImage/src/ppImageDetrendFringe.c

    r24911 r25930  
    8484    psArray *cells = chip->cells;       // Component cells
    8585    psArray *fringes = psArrayAlloc(cells->n); // Fringes, to return
     86    int video_cell_zero = 0;
     87   
    8688    for (int i = 0; i < cells->n; i++) {
    8789        fringes->data[i] = NULL;
     
    8991        pmCell *cell = cells->data[i];  // Cell of interest
    9092
     93        psTrace("psModules.detrend",7,"Readouts: Cell %d chip: %ld\n",i,cell->readouts->n);
    9194        // XXX for now, skip the video cells (cell->readouts->n > 1)
    92         if (cell->readouts->n > 1) {
    93             psWarning ("Skipping Video Cell (%d) for ppImageDetrendFringe.c:getFringes", i);
    94             continue;
    95         }
    96 
     95        // CZW: This mess creates a fake set of fringe stats by stealing the previous one.
     96        // We let the fitting code know that this is all lies by scaling the weights by a crazy amount.
     97
     98        if ( (cell->readouts->n > 1) ) {
     99          psTrace("psModules.detrend",7,"Should be skipping scichip: %d\n",i);
     100          psWarning ("Skipping Video Cell (%d) for ppImageDetrendFringe.c:getFringes", i);
     101
     102          if (i == 0) {
     103            video_cell_zero = 1;
     104          }
     105          else {
     106            pmFringeStats *prevFringe = fringes->data[i-1];
     107            pmFringeStats *fringe     = pmFringeStatsAlloc(prevFringe->regions);
     108            for (int j = 0; j < fringe->regions->nRequested; j++) {
     109              fringe->f->data.F32[j] = prevFringe->f->data.F32[j];
     110              fringe->df->data.F32[j] = prevFringe->df->data.F32[j] / 1e6;
     111            }
     112            fringes->data[i] = fringe;
     113          }
     114           
     115          continue;
     116        }
     117       
    97118        fringes->data[i] = psMemIncrRefCounter(psMetadataLookupPtr(NULL, cell->analysis, source));
    98119    }
    99120
     121    if (video_cell_zero == 1) {
     122      pmFringeStats *prevFringe = fringes->data[1];
     123      pmFringeStats *fringe     = pmFringeStatsAlloc(prevFringe->regions);
     124      for (int j = 0; j < fringe->regions->nRequested; j++) {
     125        fringe->f->data.F32[j] = NAN;
     126        fringe->df->data.F32[j] = 1.0;
     127      }
     128      fringes->data[0] = fringe;
     129    }
     130   
    100131    return fringes;
    101132}
     
    112143    psArray *science = NULL;
    113144    if (isResidual) {
    114         science = getFringes(scienceChip, "FRINGE.RESIDUALS"); // Fringe residuals on science chip
     145        science = getFringes(scienceChip,  "FRINGE.RESIDUALS"); // Fringe residuals on science chip
    115146    } else {
    116147        science = getFringes(scienceChip, "FRINGE.MEASUREMENTS"); // Fringe measurements on science chip
     
    124155    psArray *references = getFringes(refChip, "FRINGE.MEASUREMENTS"); // Fringe measurements on reference chip
    125156    int numRefs = ((psArray*)references->data[0])->n; // Number of reference fringes
    126     psArray *referencesCat = psArrayAlloc(numRefs); // Reference fringes
    127     for (int i = 0; i < numRefs; i++) { // Iterate over fringes
    128         psArray *refs = psArrayAlloc(references->n); // Array of fringes for each cell
    129         for (int j = 0; j < references->n; j++) { // Iterate over cells
    130             psArray *ref = references->data[j]; // Array of references for this cell
     157    psArray *referencesCat = psArrayAlloc(numRefs);   // Reference fringes
     158    for (int i = 0; i < numRefs; i++) {               // Iterate over fringes
     159        psArray *refs = psArrayAlloc(references->n);  // Array of fringes for each cell
     160        for (int j = 0; j < references->n; j++) {     // Iterate over cells
     161            psArray *ref = references->data[j];       // Array of references for this cell
     162           
    131163            refs->data[j] = psMemIncrRefCounter(ref->data[i]);
    132164        }
    133         referencesCat->data[i] = pmFringeStatsConcatenate(refs, NULL, NULL);
     165        referencesCat->data[i] = pmFringeStatsConcatenate(refs, NULL, NULL);
    134166        psFree(refs);
    135167    }
  • trunk/ppImage/src/ppImageDetrendReadout.c

    r25299 r25930  
    128128    }
    129129
    130     // Pattern noise correction
    131     if (options->doPattern) {
    132         if (!pmPatternRow(input, options->patternOrder, options->patternIter, options->patternRej,
    133                           options->patternThresh, options->patternMean, options->patternStdev,
    134                           options->maskValue, options->darkMask)) {
    135             psFree(detview);
    136             return false;
    137         }
    138     }
     130/*     // Pattern noise correction */
     131/*     if (options->doPattern) { */
     132/*         if (!pmPatternRow(input, options->patternOrder, options->patternIter, options->patternRej, */
     133/*                           options->patternThresh, options->patternMean, options->patternStdev, */
     134/*                           options->maskValue, options->darkMask)) { */
     135/*             psFree(detview); */
     136/*             return false; */
     137/*         } */
     138/*     } */
    139139
    140140    // Normalization by a single (known) constant
  • trunk/ppImage/src/ppImageLoop.c

    r25875 r25930  
    163163        }
    164164
     165        // Apply the pattern noise correction
     166        if (options->doPattern) {
     167          if (!ppImageDetrendPatternApply(config,chip,view,options)) {
     168            ESCAPE("Unable to apply pattern corrections");
     169          }
     170        }
     171       
    165172        // measure various pixel-based statistics for this image
    166173        if (!ppImagePixelStats(config, stats, options, view)) {
  • trunk/ppImage/src/ppImageOptions.c

    r25324 r25930  
    249249
    250250    options->burntoolTrails = psMetadataLookupS32(&status, recipe, "BURNTOOL.TRAILS");
    251     fprintf(stderr,"TRAILS: %d %d %d\n",options->burntoolTrails,psMetadataLookupS32(&status,recipe,"BURNTOOL.TRAILS"),status);
     251    psTrace("psModules.detrend", 7, "burntoolTrails: %d BURNTOOL.TRAILS: %d Status: %d\n",
     252            options->burntoolTrails,psMetadataLookupS32(&status,recipe,"BURNTOOL.TRAILS"),status);
    252253    if (!status) {
    253254      psWarning("BURNTOOL.TRAILS not found in recipe: setting to default value.\n");
  • trunk/psModules/src/concepts/pmConcepts.c

    r25882 r25930  
    249249CONCEPT_REGISTER_FUNCTION(S32, Enum, -1); // For enums: set default to -1
    250250CONCEPT_REGISTER_FUNCTION(S32, S32, 0); // For values: set default to 0
     251//CONCEPT_REGISTER_FUNCTION(Bool, Bool, NULL); // For values: set default to 0
    251252
    252253static void conceptRegisterTime(const char *name, /* Name of concept */ \
     
    333334        conceptRegisterF32("FPA.TELTEMP.EXTRA", "Telescope Temperatures: extra", p_pmConceptParse_TELTEMPS, NULL, NULL, false, PM_FPA_LEVEL_FPA);
    334335        conceptRegisterF32("FPA.PON.TIME", "Power On Time", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
    335         conceptRegisterS32("FPA.BURNTOOL.APPLIED", "Status of burntool processing", p_pmConceptParse_BTOOLAPP,NULL,NULL,false,PM_FPA_LEVEL_FPA);
     336        conceptRegisterS32("FPA.BURNTOOL.APPLIED", "Status of burntool processing", p_pmConceptParse_BTOOLAPP,p_pmConceptFormat_BTOOLAPP,NULL,false,PM_FPA_LEVEL_FPA);
     337        //      conceptRegisterBool("FPA.BURNTOOL.APPLIED", "Status of burntool processing", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
    336338        conceptRegisterF32("FPA.EXPOSURE", "Exposure time (sec)", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
    337339    }
  • trunk/psModules/src/concepts/pmConceptsRead.c

    r25425 r25930  
    4747    case PS_DATA_F64:
    4848        return psMetadataItemAllocF64(pattern->name, pattern->comment, psMetadataItemParseF64(concept));
     49    case PS_DATA_BOOL:
     50      return psMetadataItemAllocBool(pattern->name, pattern->comment, psMetadataItemParseBool(concept));
    4951    default:
    5052        psWarning("Concept %s (%s) is not of a standard type (%x)\n",
  • trunk/psModules/src/concepts/pmConceptsStandard.c

    r25882 r25930  
    753753    psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Type for %s (%x) is not BOOL\n",
    754754            concept->name, concept->type);
    755     return NULL;
     755    if (concept->type != PS_DATA_S32) {
     756      psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Wasn't the type I'd guessed either.\n");
     757      return NULL;
     758    }
     759    psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Looks like an S32 value? (%d)\n",
     760            concept->data.S32);
     761
     762    if (concept->data.S32 == 0) {
     763      bt_status = 1;
     764    }
     765    else if (concept->data.S32 == 1) {
     766      bt_status = -2;
     767    }
    756768  }
    757769
     
    765777  return psMetadataItemAllocS32(concept->name, concept->comment, bt_status);
    766778
     779psMetadataItem *p_pmConceptFormat_BTOOLAPP(const psMetadataItem *concept,
     780                                           pmConceptSource source,
     781                                           const psMetadata *cameraFormat,
     782                                           const pmFPA *fpa,
     783                                           const pmChip *chip,
     784                                           const pmCell *cell)
     785{
     786  assert(concept);
     787
     788  if (concept->type != PS_DATA_S32) {
     789    return NULL;
     790  }
     791
     792  if (concept->data.S32 == 0) {
     793    return NULL;
     794  }
     795  else if (concept->data.S32 == -2) {
     796    return psMetadataItemAllocBool(concept->name,concept->comment,true);
     797  }
     798  else if (concept->data.S32 == 1) {
     799    return psMetadataItemAllocBool(concept->name,concept->comment,false);
     800  }
     801  else {
     802    return NULL;
     803  }
     804
     805
     806
    767807
    768808// Get the current value of a concept
  • trunk/psModules/src/concepts/pmConceptsStandard.h

    r25882 r25930  
    146146    const pmCell *cell ///< Cell for concept, or NULL
    147147    );
     148psMetadataItem *p_pmConceptFormat_BTOOLAPP(
     149    const psMetadataItem *concept, ///< Concept to format
     150    pmConceptSource source, ///< Source for concept
     151    const psMetadata *cameraFormat, ///< Camera format definition
     152    const pmFPA *fpa, ///< FPA for concept, or NULL
     153    const pmChip *chip, ///< Chip for concept, or NULL
     154    const pmCell *cell ///< Cell for concept, or NULL
     155    );
    148156
    149157
  • trunk/psModules/src/detrend/pmFringeStats.c

    r24912 r25930  
    1111#include "pmFPA.h"
    1212#include "pmFringeStats.h"
     13
     14#include "psPolynomialMD.h"
     15#include "psMinimizePolyFit.h"
     16#include "psVector.h"
     17
    1318
    1419// Future optimisations for speed:
     
    331336        dfPt[i] = 1.0 / medianSd->sampleStdev;
    332337
    333         psTrace("psModules.detrend", 7, "[%d:%d,%d:%d]: %f %f\n", (int)region.x0, (int)region.x1,
    334                 (int)region.y0, (int)region.y1, fPt[i], dfPt[i]);
     338        psTrace("psModules.detrend", 7, "[%d:%d,%d:%d]: %f %f : %s\n", (int)region.x0, (int)region.x1,
     339                (int)region.y0, (int)region.y1, fPt[i], dfPt[i], readout->parent->hdu->extname);
    335340    }
    336341    psFree(sky);
     
    840845            }
    841846        }
    842         B->data.F64[i] = vector;
     847        B->data.F64[i] = vector;
    843848    }
    844849
     
    966971            }
    967972        }
     973       
    968974    }
    969975
     
    988994                psTrace("psModules.detrend", 9, "Masking region %d because not finite in fringe %d.\n", j, i);
    989995            }
    990         }
    991     }
    992 
     996            else if (fabs(fringe->f->data.F32[j]) > 0.1) {
     997              mask->data.PS_TYPE_VECTOR_MASK_DATA[j] = 1;
     998              psTrace("psModules.detrend", 9, "Masking region %d because too large fringe %d.\n", j, i);
     999            }
     1000            // Mask bad points in the science data as well.
     1001            if ((i == 0) && (!isfinite(science->f->data.F32[j]))) {
     1002                mask->data.PS_TYPE_VECTOR_MASK_DATA[j] = 1;
     1003                psTrace("psModules.detrend", 9, "Masking region %d because not finite in science fringe %d.\n", j, i);
     1004            }         
     1005            psTrace("psModules.detrend", 7, "F %f %f %f %d\n",
     1006                    fringe->f->data.F32[j], science->f->data.F32[j],
     1007                    1 / science->df->data.F32[j],(int) mask->data.PS_TYPE_VECTOR_MASK_DATA[j]);
     1008        }
     1009    }
     1010   
     1011/*     // Begin switch from old outlier removal and fitting code. */
     1012
     1013    psPolynomial1D *poly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, 1);
     1014
     1015    pmFringeStats *fringe = fringes->data[0];
     1016    psVector *errors = psVectorAlloc(science->df->n,PS_TYPE_F32);
     1017    for (int j = 0; j < errors->n; j++) {
     1018      errors->data.F32[j] = 1 / science->df->data.F32[j];
     1019    }
     1020    psVectorFitPolynomial1D(poly,mask,0xff,science->f,errors,fringe->f);
     1021
     1022    for (int i = 0; i <= poly->nX; i++) {
     1023      scale->coeff->data.F32[i] = poly->coeff[i];
     1024      psTrace("psModules.detrend",7,"COEFFS: %d %g %g %g\n",i,scale->coeff->data.F32[i],poly->coeff[i],poly->coeffErr[i]);
     1025    }
     1026
     1027    psFree(poly);
     1028    //    psFree(fringe);
     1029    psFree(errors);
     1030
     1031    psFree(median);
     1032    psFree(diff);
     1033    return scale;
     1034    // End switch from old code.
     1035   
     1036
     1037   
    9931038# if (0)
    9941039    // Write fringe data to file for a test
     
    10191064        }
    10201065        scale->coeff->data.F32[0] -= median->sampleMedian;
    1021         scale->coeff->data.F32[i] = 0.0;
     1066        if (i != 0) {
     1067          scale->coeff->data.F32[i] = 0.0;
     1068        }
    10221069    }
    10231070    psFree(median);
     
    10511098
    10521099    return scale;
     1100    //# endif
    10531101}
    10541102
Note: See TracChangeset for help on using the changeset viewer.