IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 27, 2014, 4:21:00 PM (12 years ago)
Author:
watersc1
Message:

Working with metadata structures is far easier than pmFPAfiles. First cleanly running-to-completion version. Now to sort out the resolution issues.

File:
1 edited

Legend:

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

    r36582 r36615  
    3333    pmConfig *config = data->config;    // Because I'm reusing code.
    3434    int u,v;
     35    size_t A,P;
     36    double RR = -9999.0 ,DD = -99999.0,rr = 9999.0,dd = 99999.0;
    3537    // FIX Figure out what stacks we have to deal with.
    3638    psString stackName = data->stacks->data[0];
     
    4951    }
    5052    psArrayAdd(data->stack_data,data->stack_data->n,psMemIncrRefCounter(stack));
     53    pmFPAfileActivate(config->files, false, NULL);
     54
     55    // You know what? Let's just fucking lie to config->files.
     56    psMetadata *config_files = config->files;
     57    config->files = NULL;
     58    config->files = psMetadataAlloc();
    5159   
    5260    // Read over the input background models.   
     
    6270        return(false);
    6371      }
    64 
     72     
     73      // Pull out the information for this exposure
    6574      psMetadata *input = item->data.md; // the input metadata of interest
    66 
    6775      psString smfFileName = psMetadataLookupStr(NULL, input, "astrom");
    6876      psMetadata *modelContent = psMetadataLookupMetadata(NULL, input, "models");
     77
     78      // Allocate the model metadata object
     79      psMetadata *Bmodel = psMetadataAlloc();
     80     
    6981      // Read the smf file from this item
    7082      fileArguments("astrom",smfFileName,"",config);
    7183      pmFPAfile *smfFile = pmFPAfileDefineFromArgs(&status, config, "PSWARP.ASTROM","astrom");
    72 
     84     
     85      // taking from pswarpLoadAstrometry.c
     86      smfFile->type = PM_FPA_FILE_WCS;
    7387      // Read the SMF data
    7488      pmFPAview *view = pmFPAviewAlloc(0); // Pointer into FPA hierarchy
     89
    7590      if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
    7691        return NULL;
    7792      }
     93      if (!pmFPAfileRead(smfFile,view,config)) {
     94        psError(PS_ERR_IO, false, "failed READ at FPA %s", smfFile->name);
     95        psFree(view);
     96        return false;
     97      }
     98     
    7899      printf("CZW: Item %d\n",i);
    79100      // find the FPA phu
     
    93114        }
    94115      }
     116
     117      psMemStats(0,&A,&P);
     118      fprintf(stderr,"fpa %ld %ld\n",A,P);
     119
    95120      pmChip *chip;                       // Chip from FPA
    96121      while ((chip = pmFPAviewNextChip(view, smfFile->fpa, 1))) {
     
    106131          psWarning("More than one cell present for chip %d", view->chip);
    107132        }
     133
     134        psMemStats(0,&A,&P);
     135        fprintf(stderr,"chip %ld %ld\n",A,P);
    108136
    109137        // read WCS data from the corresponding header
     
    128156        }
    129157
    130         // FIX Load model data for this chip
     158        // Load model data for this chip
    131159        psString modelFileName = pmConfigConvertFilename(psMetadataLookupStr(NULL, modelContent, chipName),
    132160                                                         config, PM_FPA_MODE_READ, false);
     
    175203            if (tp->y < data->dec_min) { data->dec_min = tp->y; }
    176204            else if (tp->y > data->dec_max) { data->dec_max = tp->y; }
    177           }
    178         }
    179 
     205
     206            if (sky->r < rr) { rr = sky->r; }
     207            else if (sky->r > RR) { RR = sky->r; }
     208            if (sky->r < dd) { dd = sky->d; }
     209            else if (sky->d > DD) { DD = sky->d; }
     210           
     211          }
     212        }
     213
     214        // Allocate the model data for this chip
     215        psMetadata *this_model = psMetadataAlloc();
     216               
    180217        // Attach vectors to teh structure of the chip
    181         psMetadataAddImage(chip->analysis,PS_LIST_TAIL,
     218        psMetadataAddImage(this_model,PS_LIST_TAIL,
    182219                           "bkg image", 0,
    183220                           "ota space X vector", image);
    184         psMetadataAddImage(chip->analysis,PS_LIST_TAIL,
     221        psMetadataAddImage(this_model,PS_LIST_TAIL,
    185222                           "bkg ra", 0,
    186223                           "ota space ra vector", raim);
    187         psMetadataAddImage(chip->analysis,PS_LIST_TAIL,
     224        psMetadataAddImage(this_model,PS_LIST_TAIL,
    188225                           "bkg dec", 0,
    189226                           "ota space dec vector", decim);
    190         psMetadataAddImage(chip->analysis,PS_LIST_TAIL,
     227        psMetadataAddImage(this_model,PS_LIST_TAIL,
    191228                           "bkg calibrated data", 0,
    192229                           "ota space corrected data", model);
     
    194231        // Define default background model parameters, using the assumption:
    195232        // observed = camera + offset + scale * astrophysical
    196         psMetadataAddF32(chip->analysis,PS_LIST_TAIL,
     233        psMetadataAddF32(this_model,PS_LIST_TAIL,
    197234                         "bkg offset", PS_META_REPLACE,
    198235                         "background offset for this exposure/ota pair", 0.0);
    199         psMetadataAddF32(chip->analysis,PS_LIST_TAIL,
     236        psMetadataAddF32(this_model,PS_LIST_TAIL,
    200237                         "bkg scale", PS_META_REPLACE,
    201238                         "background scale parameter for this exposure/ota pair", 1.0);
    202         // FIX Free model data for this chip
     239        // Add this model to the current model
     240        psMetadataAddMetadata(Bmodel,PS_LIST_TAIL,
     241                              chipName, PS_META_REPLACE,
     242                              "model data for this exposure/ota", this_model);
     243        // Free model data for this chip
    203244        psFree(modelFileName);
    204245        psFree(modelFits);
     
    212253        psFree(decim);
    213254        psFree(model);
    214 
     255        psFree(this_model);
     256       
    215257        // Check to see if we've loaded or allocated an OTA solution container for this chip
    216258        if (!psMetadataLookupPtr(NULL,data->OTA_solutions,chipName)) { // No solution metadata entry exists for this chipName
     
    235277          }
    236278        }
    237        
    238         // FIX Hopefully this isn't going to destroy everything.
    239         // Chip
     279
     280       
     281        psMemStats(0,&A,&P);
     282        fprintf(stderr,"chip2 %ld %ld\n",A,P);
     283       
    240284/*      if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { */
    241285/*        psError(psErrorCodeLast(), false, "Error saving data to files."); */
    242286/*        return false; */
    243287/*      } */
    244       }
    245       // FPA
    246 /*       if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { */
    247 /*      psError(psErrorCodeLast(), false, "Error saving data to files."); */
    248 /*      return false; */
    249 /*       } */
    250 
    251       // Add this smf to the smf array.
    252       psArrayAdd(data->smfs,data->smfs->n,psMemIncrRefCounter(smfFile));
    253       psFree(smfFile);
    254     }
    255 
     288      } // end chip loop
     289
     290      // Add the set of models to the datastructure
     291      psMetadataAddMetadata(data->models, PS_LIST_TAIL,
     292                            smfFile->origname, PS_META_REPLACE,
     293                            "model data for this exposure", Bmodel);
     294      psMetadataAddS16(data->models,PS_LIST_TAIL,
     295                       "N", PS_META_REPLACE,
     296                       "counter", i);
     297      // data->models->name->XY__->{image/ra/dec/calibrated/offset/scale}
     298      // data->models->counter->XY__->{image/ra/dec/calibrated/offset/scale}
     299
     300     
     301     
     302      if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
     303        psError(psErrorCodeLast(), false, "Error saving data to files.");
     304        return false;
     305      }
     306      pmFPAfileActivate(config->files, false, NULL);
     307      psFree(modelContent);
     308      //      psFree(smfFile);
     309      psFree(smfFileName);
     310      psFree(view);
     311
     312      psFree(config->files);
     313      config->files = psMetadataAlloc();
     314      //
     315     
     316      //
     317    } // end smf loop
     318
     319    // Unlie now.
     320    psFree(config->files);
     321    config->files = config_files;
     322   
    256323    // Allocate the modelMap for the region we're covering.
    257324
    258325    psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
    259326    psImageBinning *binning = psImageBinningAlloc();
    260     binning->nXruff = 100; // Number of samples
    261     binning->nYruff = 100;
     327    binning->nXruff = 33; // Number of samples
     328    binning->nYruff = 33;
    262329    binning->nXfine = ceil(data->ra_max - data->ra_min) + 1; // This is the range we're looking at
    263330    binning->nYfine = ceil(data->dec_max - data->dec_min) + 1;
    264 
     331    binning->nXskip = floor(data->ra_min);
     332    binning->nYskip = floor(data->dec_min);
     333    psImageBinningSetScale(binning,PS_IMAGE_BINNING_CENTER);
     334    printf("Sizes: sky: %f %f -> %f %f :: tp: %f %f -> %f %f :: map: %d %d\n",
     335           rr,dd,RR,DD,data->ra_min,data->dec_min,data->ra_max,data->dec_max,binning->nXfine,binning->nYfine);
    265336    data->modelMap = psImageMapNoImageAlloc( binning,stats);
    266337   
Note: See TracChangeset for help on using the changeset viewer.