IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 7, 2014, 6:08:39 PM (12 years ago)
Author:
watersc1
Message:

ppBackgroundStack compiles. I know it's not useful yet, because I haven't implemented the 'apply' and 'save the outputs' parts.

File:
1 edited

Legend:

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

    r36579 r36580  
    3131{
    3232    bool status;                        // Status of file definition
    33 
     33    pmConfig *config = data->config;    // Because I'm reusing code.
     34    int u,v;
     35    // FIX Figure out what stacks we have to deal with.
     36    psString stackName = data->stacks->data[0];
     37    fileArguments("IMAGE", stackName, "Input image", data->config);
     38    pmFPAfile *stack = pmFPAfileDefineFromArgs(&status, data->config, "PPBACKGROUND.STACK",
     39                                               "IMAGE");
     40    if (!status || !stack) {
     41      psError(psErrorCodeLast(), false, "Failed to build file from PPBACKGROUND.STACK");
     42      return false;
     43    }
     44
     45    // Read over the input background models.   
    3446    psMetadataIterator *iter = psMetadataIteratorAlloc(data->contents, PS_LIST_HEAD, NULL); // Iterator
    3547    psMetadataItem *item; // Item from iteration
    36     int i = 0;
     48    //    int i = 0;
    3749    while ((item = psMetadataGetAndIncrement(iter))) {
    3850      if (item->type != PS_DATA_METADATA) {
    39         psError(PPBACKGROUND_ERR_ARGUMENTS, true
     51        psError(PPBACKGROUND_ERR_ARGUMENTS, true,
    4052                "Component %s of the input metadata is not of type METADATA", item->name);
    4153        psFree(iter);
     
    4759      psString smfFileName = psMetadataLookupStr(NULL, input, "astrom");
    4860
    49       // FIX Figure out how to calculate the smf name
    50       // psString cam_file = pmFPAfileNameFromRule("PSASTRO.OUTPUT");
    51       // pmFPAfile *smfFile = pmFPAfileBindFromArgs(&status, NULL, config);
    52       // pmFPAfile *smfFile = pmFPAfileDefineInput(config,
     61      // Read the smf file from this item
    5362      fileArguments("astrom",smfFileName,"",config);
    5463      pmFPAfile *smfFile = pmFPAfileDefineFromArgs(&status, config, "PSWARP.ASTROM","astrom");
    5564
    5665      // Read the SMF data
    57 
    5866      pmFPAview *view = pmFPAviewAlloc(0); // Pointer into FPA hierarchy
    5967      if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
     
    95103        }
    96104        // read WCS data from the corresponding header
    97         pmHDU *hdu = pmFPAviewThisHDU (view, astromFile->fpa);
     105        pmHDU *hdu = pmFPAviewThisHDU (view, smfFile->fpa);
    98106        if (bilevelAstrometry) {
    99107          if (!pmAstromReadBilevelChip (chip, hdu->header)) {
     
    108116          // we use a default FPA pixel scale of 1.0
    109117          psWarning("Reading WCS astrometry for chip %s.", chipName);
    110           if (!pmAstromReadWCS(astromFile->fpa, chip, hdu->header, 1.0)) {
     118          if (!pmAstromReadWCS(smfFile->fpa, chip, hdu->header, 1.0)) {
    111119            psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for input FPA.");
    112120            psFree(view);
     
    116124
    117125        // FIX Load model data for this chip
    118         psString modelFileName = psMetadataLookupStr(NULL, input->models, chipName);
     126        psString modelFileName = psMetadataLookupStr(NULL, input, chipName);
    119127        psFits *modelFits = psFitsOpen(modelFileName,"r");
    120         psImage *image = psFitsReadImage(modelFits,NULL,0);
     128        int nC, nR;
     129        psElemType *type;
     130        psRegion region;
     131        psFitsImageSize(&nC,&nR,type,modelFits,region);
     132        psImage *image = psFitsReadImage(modelFits,region,0);
    121133        psMetadata *header = psFitsReadHeader(NULL,modelFits);
    122134
    123135        // Allocate the data structures for this chip
    124         psImage *raim = psImageAlloc(image->cols,image->rows,PS_TYPE_F32);
    125         psImage *decim = psImageAlloc(image->cols,image->rows,PS_TYPE_F32);
    126         psImage *model = psImageAlloc(image->cols,image->rows,PS_TYPE_F32);
     136        psImage *raim = psImageAlloc(image->numCols,image->numRows,PS_TYPE_F32);
     137        psImage *decim = psImageAlloc(image->numCols,image->numRows,PS_TYPE_F32);
     138        psImage *model = psImageAlloc(image->numCols,image->numRows,PS_TYPE_F32);
    127139
    128140        // Read header and construct original positions
     
    142154        psSphere *sky = psSphereAlloc(); // Sky coordinates
    143155       
    144         for (v = 0; v < image->nrows; v++) {
     156        for (v = 0; v < image->numRows; v++) {
    145157          pix->y = (v - yoffset) * ybin;
    146           for (u = 0; u < image->ncols; u++) {
     158          for (u = 0; u < image->numCols; u++) {
    147159            pix->x = (u - xoffset) * xbin;
    148160            psPlaneTransformApply(fp, chip->toFPA, pix);
    149161            psPlaneTransformApply(tp, smfFile->fpa->toTPA, fp);
    150             psDeproject(sky, tp, astromFile->fpa->toSky);
    151 
    152             // FIX project sky to stack projection cell grid.
    153             if (!data->radians) {
    154               sky->r *= 180.0 / M_PI;
    155               sky->d *= 180.0 / M_PI;
    156             }
    157             raim->data.F32[v][u] = sky->r;
    158             decim->data.F32[v][u] = sky->d;
     162            psDeproject(sky, tp, smfFile->fpa->toSky);
     163
     164            psProject(tp,sky,stack->fpa->toSky);
     165
     166            raim->data.F32[v][u] = tp->x;
     167            decim->data.F32[v][u] = tp->y;
    159168            model->data.F32[v][u] = 0.0;
    160169
    161170            // Check the bounds so we'll know how large of an area to model in the map
    162             if (sky->r < data->ra_min) { data->ra_min = sky->r; }
    163             else if (sky->r > data->ra_max) { data->ra_max = sky->r; }
    164             if (sky->d < data->dec_min) { data->dec_min = sky->d; }
    165             else if (sky->d > data->dec_max) { data->dec_max = sky->d; }
     171            if (tp->x < data->ra_min) { data->ra_min = tp->x; }
     172            else if (tp->x > data->ra_max) { data->ra_max = tp->x; }
     173            if (tp->y < data->dec_min) { data->dec_min = tp->y; }
     174            else if (tp->y > data->dec_max) { data->dec_max = tp->y; }
    166175          }
    167176        }
     
    187196          // FIX this should try to find the imagefile.
    188197          if (data->fit_OTAS) { // We are fitting OTAs, so allocate a new image
    189             psImage *solution = psImageAlloc(image->cols,image->rows,PS_TYPE_F32);
     198            psImage *solution = psImageAlloc(image->numCols,image->numRows,PS_TYPE_F32);
    190199            psMetadataAddPtr(data->OTA_solutions,PS_LIST_TAIL, chipName, PS_DATA_UNKNOWN | PS_META_REPLACE, "OTA solution element", solution);
    191200          }
     
    194203            psStringAppend(&solutionFileName, ".%s.fits",chipName);
    195204            psFits *solutionFits = psFitsOpen(solutionFileName,"r");
    196             psImage *solution = psFitsReadImage(solutionFits,NULL,0);
     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);
    197207          }
    198208        }
     
    215225    }
    216226
     227    // Allocate the modelMap for the region we're covering.
     228
     229    psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
     230    psImageBinning *binning = psImageBinningAlloc();
     231    binning->nXruff = 100; // Number of samples
     232    binning->nYruff = 100;
     233    binning->nXfine = ceil(data->ra_max - data->ra_min) + 1; // This is the range we're looking at
     234    binning->nYfine = ceil(data->dec_max - data->dec_min) + 1;
     235
     236    data->modelMap = psImageMapNoImageAlloc( binning,stats);
     237   
    217238    return true;
    218239}
Note: See TracChangeset for help on using the changeset viewer.