IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36582


Ignore:
Timestamp:
Mar 11, 2014, 3:46:50 PM (12 years ago)
Author:
watersc1
Message:

Debuggable complete version of ppBackgroundStack. It doesn't seem to work, as I'm losing my data structures somehow.

Location:
trunk/ppBackground/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppBackground/src/ppBackground.c

    r28280 r36582  
    1818    ppBackgroundErrorRegister();
    1919
     20    printf("Initializing data\n");
    2021    ppBackgroundData *data = ppBackgroundDataInit(&argc, argv);
    2122    if (!data) {
    2223        goto DIE;
    2324    }
    24 
     25    printf("Reading Arguments\n");
    2526    if (!ppBackgroundArguments(data, argc, argv)) {
    2627        goto DIE;
    2728    }
    28 
     29    printf("Setting up Camera\n");
    2930    if (!ppBackgroundCamera(data)) {
    3031        goto DIE;
    3132    }
    3233
     34    printf("Looping over data!\n");
    3335    if (!ppBackgroundLoop(data)) {
    3436        goto DIE;
  • trunk/ppBackground/src/ppBackgroundStack.c

    r36580 r36582  
    1818    ppBackgroundErrorRegister();
    1919
     20    printf("Data init\n");
    2021    ppBackgroundStackData *data = ppBackgroundStackDataInit(&argc, argv);
    2122    if (!data) {
    2223        goto DIE;
    2324    }
    24 
     25    printf("Read arguments\n");
    2526    if (!ppBackgroundStackArguments(data, argc, argv)) {
    2627        goto DIE;
    2728    }
    2829
     30    printf("Setup camera\n");
    2931    if (!ppBackgroundStackCamera(data)) {
    3032        goto DIE;
    3133    }
    3234
     35    printf("Do Loop\n");
    3336    if (!ppBackgroundStackLoop(data)) {
    3437        goto DIE;
  • trunk/ppBackground/src/ppBackgroundStack.h

    r36580 r36582  
    2323  psF32 dec_min;
    2424  psF32 dec_max;
    25  
     25
     26  psArray *stack_data;
    2627  psArray *stacks;        // List of stacks to be corrected.
    2728  psString outRoot;       // Output root name
  • trunk/ppBackground/src/ppBackgroundStackCamera.c

    r36580 r36582  
    3636    psString stackName = data->stacks->data[0];
    3737    fileArguments("IMAGE", stackName, "Input image", data->config);
    38     pmFPAfile *stack = pmFPAfileDefineFromArgs(&status, data->config, "PPBACKGROUND.STACK",
    39                                                "IMAGE");
     38    psFree(stackName);
     39    pmFPAfile *stack = pmFPAfileDefineFromArgs(&status, data->config,
     40                                               "PPBACKGROUND.STACK", "IMAGE");
    4041    if (!status || !stack) {
    4142      psError(psErrorCodeLast(), false, "Failed to build file from PPBACKGROUND.STACK");
     
    4344    }
    4445
     46    if (!pmAstromReadBilevelMosaic(stack->fpa,stack->fpa->hdu->header)) {
     47      psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for input stack.");
     48      return false;
     49    }
     50    psArrayAdd(data->stack_data,data->stack_data->n,psMemIncrRefCounter(stack));
     51   
    4552    // Read over the input background models.   
    4653    psMetadataIterator *iter = psMetadataIteratorAlloc(data->contents, PS_LIST_HEAD, NULL); // Iterator
    4754    psMetadataItem *item; // Item from iteration
    48     //    int i = 0;
     55    int i = 0;
    4956    while ((item = psMetadataGetAndIncrement(iter))) {
     57      i++;
    5058      if (item->type != PS_DATA_METADATA) {
    5159        psError(PPBACKGROUND_ERR_ARGUMENTS, true,
     
    5866
    5967      psString smfFileName = psMetadataLookupStr(NULL, input, "astrom");
    60 
     68      psMetadata *modelContent = psMetadataLookupMetadata(NULL, input, "models");
    6169      // Read the smf file from this item
    6270      fileArguments("astrom",smfFileName,"",config);
     
    6876        return NULL;
    6977      }
    70      
     78      printf("CZW: Item %d\n",i);
    7179      // find the FPA phu
    7280      bool bilevelAstrometry = false;
     
    9199        }
    92100        const char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME"); // Name of chip
    93 /*      if (data->chipName && strcmp(chipName, data->chipName) != 0) { */
    94 /*        continue; */
    95 /*      } */
    96101        if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
    97102          psError(psErrorCodeLast(), false, "Error loading data from files.");
    98103          return false;
    99104        }
    100 
    101105        if (chip->cells->n != 1) {
    102106          psWarning("More than one cell present for chip %d", view->chip);
    103107        }
     108
    104109        // read WCS data from the corresponding header
    105110        pmHDU *hdu = pmFPAviewThisHDU (view, smfFile->fpa);
     
    124129
    125130        // FIX Load model data for this chip
    126         psString modelFileName = psMetadataLookupStr(NULL, input, chipName);
     131        psString modelFileName = pmConfigConvertFilename(psMetadataLookupStr(NULL, modelContent, chipName),
     132                                                         config, PM_FPA_MODE_READ, false);
    127133        psFits *modelFits = psFitsOpen(modelFileName,"r");
    128         int nC, nR;
    129         psElemType *type;
    130         psRegion region;
    131         psFitsImageSize(&nC,&nR,type,modelFits,region);
    132         psImage *image = psFitsReadImage(modelFits,region,0);
     134        psImage *image = psFitsReadImage(modelFits,psRegionSet(0,0,0,0),0);
    133135        psMetadata *header = psFitsReadHeader(NULL,modelFits);
    134 
     136       
    135137        // Allocate the data structures for this chip
    136138        psImage *raim = psImageAlloc(image->numCols,image->numRows,PS_TYPE_F32);
     
    177179
    178180        // Attach vectors to teh structure of the chip
    179         psMetadataAddPtr(chip->analysis,PS_LIST_TAIL,"bkg image", PS_DATA_UNKNOWN | PS_META_REPLACE, "ota space X vector", image);
    180         psMetadataAddPtr(chip->analysis,PS_LIST_TAIL,"bkg ra", PS_DATA_UNKNOWN | PS_META_REPLACE, "ota space X vector", raim);
    181         psMetadataAddPtr(chip->analysis,PS_LIST_TAIL,"bkg dec", PS_DATA_UNKNOWN | PS_META_REPLACE, "ota space X vector", decim);
    182         psMetadataAddPtr(chip->analysis,PS_LIST_TAIL,"bkg calibrated data", PS_DATA_UNKNOWN | PS_META_REPLACE, "ota space corrected data", model);
     181        psMetadataAddImage(chip->analysis,PS_LIST_TAIL,
     182                           "bkg image", 0,
     183                           "ota space X vector", image);
     184        psMetadataAddImage(chip->analysis,PS_LIST_TAIL,
     185                           "bkg ra", 0,
     186                           "ota space ra vector", raim);
     187        psMetadataAddImage(chip->analysis,PS_LIST_TAIL,
     188                           "bkg dec", 0,
     189                           "ota space dec vector", decim);
     190        psMetadataAddImage(chip->analysis,PS_LIST_TAIL,
     191                           "bkg calibrated data", 0,
     192                           "ota space corrected data", model);
    183193
    184194        // Define default background model parameters, using the assumption:
    185195        // observed = camera + offset + scale * astrophysical
    186         psMetadataAddF32(chip->analysis,PS_LIST_TAIL,"bkg offset", PS_META_REPLACE, "background offset for this exposure/ota pair", 0.0);
    187         psMetadataAddF32(chip->analysis,PS_LIST_TAIL,"bkg scale", PS_META_REPLACE, "background scale parameter for this exposure/ota pair", 1.0);
     196        psMetadataAddF32(chip->analysis,PS_LIST_TAIL,
     197                         "bkg offset", PS_META_REPLACE,
     198                         "background offset for this exposure/ota pair", 0.0);
     199        psMetadataAddF32(chip->analysis,PS_LIST_TAIL,
     200                         "bkg scale", PS_META_REPLACE,
     201                         "background scale parameter for this exposure/ota pair", 1.0);
    188202        // FIX Free model data for this chip
     203        psFree(modelFileName);
     204        psFree(modelFits);
    189205        psFree(header);
    190         psFree(modelFits);
    191         psFree(modelFileName);
    192 
     206        psFree(pix);
     207        psFree(fp);
     208        psFree(tp);
     209        psFree(sky);
     210        psFree(image);
     211        psFree(raim);
     212        psFree(decim);
     213        psFree(model);
    193214
    194215        // Check to see if we've loaded or allocated an OTA solution container for this chip
     
    197218          if (data->fit_OTAS) { // We are fitting OTAs, so allocate a new image
    198219            psImage *solution = psImageAlloc(image->numCols,image->numRows,PS_TYPE_F32);
    199             psMetadataAddPtr(data->OTA_solutions,PS_LIST_TAIL, chipName, PS_DATA_UNKNOWN | PS_META_REPLACE, "OTA solution element", solution);
     220            psMetadataAddPtr(data->OTA_solutions,PS_LIST_TAIL,
     221                             chipName, PS_DATA_UNKNOWN | PS_META_REPLACE,
     222                             "OTA solution element", solution);
    200223          }
    201224          else { // We are not fitting OTAs, so read the one that should be saved on OTApath.
     
    203226            psStringAppend(&solutionFileName, ".%s.fits",chipName);
    204227            psFits *solutionFits = psFitsOpen(solutionFileName,"r");
    205             psImage *solution = psFitsReadImage(solutionFits,region,0);
    206             psMetadataAddPtr(data->OTA_solutions,PS_LIST_TAIL, chipName, PS_DATA_UNKNOWN | PS_META_REPLACE, "OTA solution element", solution);
     228            psImage *solution = psFitsReadImage(solutionFits,psRegionSet(0,0,0,0),0);
     229            psMetadataAddImage(data->OTA_solutions,PS_LIST_TAIL,
     230                               chipName, 0,
     231                               "OTA solution element", solution);
     232            psFree(solutionFits);
     233            psFree(solutionFileName);
     234            psFree(solution);
    207235          }
    208236        }
     
    210238        // FIX Hopefully this isn't going to destroy everything.
    211239        // Chip
    212         if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
    213           psError(psErrorCodeLast(), false, "Error saving data to files.");
    214           return false;
    215         }
     240/*      if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { */
     241/*        psError(psErrorCodeLast(), false, "Error saving data to files."); */
     242/*        return false; */
     243/*      } */
    216244      }
    217245      // FPA
    218       if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
    219         psError(psErrorCodeLast(), false, "Error saving data to files.");
    220         return false;
    221       }
     246/*       if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { */
     247/*      psError(psErrorCodeLast(), false, "Error saving data to files."); */
     248/*      return false; */
     249/*       } */
    222250
    223251      // Add this smf to the smf array.
    224252      psArrayAdd(data->smfs,data->smfs->n,psMemIncrRefCounter(smfFile));
     253      psFree(smfFile);
    225254    }
    226255
  • trunk/ppBackground/src/ppBackgroundStackData.c

    r36580 r36582  
    2121  psFree(data->modelMap);
    2222
     23
     24  psFree(data->stack_data);
    2325  psFree(data->stacks);
    2426  psFree(data->outRoot);
     
    4547    data->dec_min  = 1e9;
    4648    data->dec_max  = -1e9;
    47    
     49
     50    data->stack_data = psArrayAlloc(0);
    4851    data->stacks = psArrayAlloc(0);
    4952    data->outRoot = NULL;
  • trunk/ppBackground/src/ppBackgroundStackLoop.c

    r36580 r36582  
    1313    )
    1414{
    15   //    pmConfig *config = data->config;                                        // Configuration data
     15  pmConfig *config = data->config;                                        // Configuration data
    1616    int i;
    1717    //
     
    6363    // Loop over the input images, and apply the models to construct the restored versions.
    6464
    65     for (i = 0; i < data->stacks->n; i++) {
     65    for (i = 0; i < data->stack_data->n; i++) {
     66      pmFPAfile *stack = data->stack_data->data[i];
     67      pmFPAview *view = pmFPAviewAlloc(0);
    6668      // Define output image
    67       // Calculate model for each pixel of output
    68       // Close output image
     69      pmFPAfile *stack_model = pmFPAfileDefineOutput(config,stack->fpa,"PPBACKGROUND.STACK.MODEL");
     70
     71      if (!stack_model) {
     72        psError(psErrorCodeLast(), false, "Unable to generate output model");
     73        return (false);
     74      }
     75     
     76      pmFPAfile *stack_corr  = pmFPAfileDefineOutput(config,stack->fpa,"PPBACKGROUND.STACK.OUTPUT");
     77      if (!stack_corr) {
     78        psError(psErrorCodeLast(), false, "Unable to generate output result");
     79        return (false);
     80      }
     81      stack_model->save = true;
     82      stack_corr->save = true;
     83
     84      // Iterate over the images.
     85      pmChip *chip;
     86      while ((chip = pmFPAviewNextChip(view, stack->fpa, 1))) {
     87        if (!chip->process || !chip->file_exists) {
     88          continue;
     89        }
     90
     91        if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
     92          psError(psErrorCodeLast(), false, "load failure for Chip");
     93          return(false);
     94        }
     95
     96        pmCell *cell;
     97       
     98        while ((cell = pmFPAviewNextCell(view, stack->fpa, 1)) != NULL) {
     99          psLogMsg ("ppImageLoop", 5, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     100          if (!cell->process || !cell->file_exists) {
     101            continue;
     102          }
     103          if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
     104            psError(psErrorCodeLast(), false, "load failure for Cell");
     105            return(false);
     106          }
     107          if (cell->readouts->n > 1) {
     108            psWarning ("Skipping Video Cell for ppImageDetrendReadout");
     109            continue;
     110          }
     111
     112          // process each of the readouts
     113          pmReadout *readout;         // Readout from cell
     114          while ((readout = pmFPAviewNextReadout (view, stack->fpa, 1)) != NULL) {
     115            if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
     116                psError(psErrorCodeLast(), false, "load failure for Readout");
     117                return(false);
     118            }
     119            if (!readout->data_exists) {
     120              continue;
     121            }
     122
     123            pmReadout *model = pmFPAfileThisReadout(config->files,view,"PPBACKGROUND.STACK.MODEL");
     124            pmReadout *corr  = pmFPAfileThisReadout(config->files,view,"PPBACKGROUND.STACK.OUTPUT");
     125
     126            psPlane *pix = psPlaneAlloc();   // Pixel coordinates on chip
     127            psPlane *fp = psPlaneAlloc();    // Focal plane coordinates
     128            psPlane *tp = psPlaneAlloc();    // Tangent plane coordinates
     129           
     130            int x,y;
     131            for (y = 0; y < readout->image->numRows; y++) {
     132              for (x = 0; x < readout->image->numCols; x++) {
     133                // Calculate model for each pixel of output
     134                psPlaneTransformApply(fp, chip->toFPA, pix);
     135                psPlaneTransformApply(tp, stack->fpa->toTPA, fp);
     136               
     137                model->image->data.F32[y][x] = psImageMapEval(data->modelMap,tp->x,tp->y);
     138                corr->image->data.F32[y][x] = readout->image->data.F32[y][x] + model->image->data.F32[y][x];
     139              }
     140            }
     141            psFree(pix);
     142            psFree(fp);
     143            psFree(tp);
     144          } // Close readout
     145
     146          // Close output image
     147          // Close cells (XXX shouldn't pmFPAfileClose iterate down as needed?)
     148          view->cell = -1;
     149          while ((cell = pmFPAviewNextCell(view, stack->fpa, 1)) != NULL) {
     150            if (!cell->process || !cell->file_exists) {
     151              continue;
     152            }
     153            if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
     154                psError(psErrorCodeLast(), false, "save failure for Cell");
     155                return(false);
     156            }
     157          }
     158        } // Close Cell
     159       
     160        // Close chip
     161        if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
     162          psError(psErrorCodeLast(), false, "save failure for Chip");
     163          return(false);
     164        }
     165      } // Close chip.
     166      // Output and Close FPA
     167      if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
     168        psError(psErrorCodeLast(), false, "save failure for FPA");
     169        return(false);
     170      }
     171      psFree(view);
    69172    }     
    70 
     173               
     174   
    71175    return(true);
    72176}
Note: See TracChangeset for help on using the changeset viewer.