IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 29, 2010, 3:55:49 PM (16 years ago)
Author:
eugene
Message:

update merges from trunk

Location:
branches/eam_branches/20100225
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20100225

  • branches/eam_branches/20100225/pswarp/src/pswarpLoop.c

    r27063 r27517  
    1919
    2020
    21 // XXX these are generic functions which should be moved to psModules
    22 // Activate a list of files
    23 static void fileActivation(pmConfig *config, // Configuration
    24                            char **files, // Files to turn on/off
    25                            bool state   // Activation state
    26     )
    27 {
    28     for (int i = 0; files[i] != NULL; i++) {
    29         pmFPAfileActivate(config->files, state, files[i]);
    30     }
    31     return;
    32 }
    33 
    34 /**
    35  * Run down the FPA hierarchy, checking files
    36  */
    37 static bool ioChecksBefore(pmConfig *config ///< Configuration
    38                            )
    39 {
    40     pmFPAview *view = pmFPAviewAlloc(0); ///< View for checking
    41     bool status = true;                 ///< Status of checks
    42     status &= pmFPAfileIOChecks(config, view, PM_FPA_BEFORE);
    43     view->chip = 0;
    44     status &= pmFPAfileIOChecks(config, view, PM_FPA_BEFORE);
    45     view->cell = 0;
    46     status &= pmFPAfileIOChecks(config, view, PM_FPA_BEFORE);
    47     psFree(view);
    48     return status;
    49 }
    50 
    51 /**
    52  * Run up the FPA hierarchy, checking files
    53  */
    54 static bool ioChecksAfter(pmConfig *config ///< Configuration
    55                           )
    56 {
    57     pmFPAview *view = pmFPAviewAlloc(0); ///< View for checking
    58     view->chip = view->cell = 0;
    59     bool status = true;                 ///< Status of checks
    60     status &= pmFPAfileIOChecks(config, view, PM_FPA_AFTER);
    61     view->cell = -1;
    62     status &= pmFPAfileIOChecks(config, view, PM_FPA_AFTER);
    63     view->chip = -1;
    64     status &= pmFPAfileIOChecks(config, view, PM_FPA_AFTER);
    65     psFree(view);
    66     return status;
    67 }
    68 
    69 
    70 /**
    71  * Loop over the inputs, warp them to the output skycell and then write out the output.
    72  */
    73 bool pswarpLoop(pmConfig *config)
     21
     22// Loop over the inputs, warp them to the output skycell and then write out the output.
     23bool pswarpLoop(pmConfig *config, psMetadata *stats)
    7424{
    7525    bool status;
     26    bool mdok;                          // Status of MD lookup
    7627
    7728    const char *skyCamera = psMetadataLookupStr(NULL, config->arguments,
    78                                                 "SKYCELL.CAMERA");  ///< Name of camera for skycell
     29                                                "SKYCELL.CAMERA");  // Name of camera for skycell
    7930    pmConfigCamerasCull(config, skyCamera);
    8031    pmConfigRecipesCull(config, "PSWARP,PPSTATS,PSPHOT,PSASTRO,MASKS,JPEG");
    81 
    8232
    8333    // load the recipe
    8434    psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSWARP_RECIPE);
    8535    if (!recipe) {
    86         psError(PSPHOT_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE);
     36        psError(PSWARP_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE);
    8737        return false;
    8838    }
    8939
    9040    if (!pswarpSetMaskBits(config)) {
    91         psError(PS_ERR_IO, false, "failed to set mask bits");
     41        psError(psErrorCodeLast(), false, "failed to set mask bits");
    9242        return NULL;
    9343    }
     
    11161
    11262    if (astrom->camera != input->camera) {
    113         psError(PS_ERR_UNKNOWN, true, "Input camera and astrometry camera do not match.");
     63        psError(PSWARP_ERR_DATA, true, "Input camera and astrometry camera do not match.");
    11464        return false;
    11565    }
     
    12777    psFree (view);
    12878
    129     bool mdok;                          ///< Status of MD lookup
    130     const char *statsName = psMetadataLookupStr(&mdok, config->arguments, "STATS"); ///< Filename for statistics
    131     psMetadata *stats = NULL;           ///< Container for statistics
    132     FILE *statsFile = NULL;             ///< File stream for statistics
    133     if (mdok && statsName && strlen(statsName) > 0) {
    134         psString resolved = pmConfigConvertFilename(statsName, config, true, true);
    135         statsFile = fopen(resolved, "w");
    136         if (!statsFile) {
    137             psError(PS_ERR_IO, true, "Unable to open statistics file %s for writing.\n", resolved);
    138             psFree(resolved);
    139             return false;
    140         }
    141         psFree(resolved);
    142         stats = psMetadataAlloc();
    143         psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", 0, "No problems", 0);
    144     }
    14579
    14680    // Turn all skycell files on to generate them, and then turn them off for the loop over the input images
    14781    // the input, which is in a different format.
    14882    {
    149         fileActivation(config, detectorFiles, false);
    150         fileActivation(config, photFiles, false);
    151         fileActivation(config, independentFiles, false);
    152         fileActivation(config, skycellFiles, true);
    153         ioChecksBefore(config);
    154         fileActivation(config, skycellFiles, false);
     83        pswarpFileActivation(config, detectorFiles, false);
     84        pswarpFileActivation(config, photFiles, false);
     85        pswarpFileActivation(config, independentFiles, false);
     86        pswarpFileActivation(config, skycellFiles, true);
     87        if (!pswarpIOChecksBefore(config)) {
     88            psError(psErrorCodeLast(), false, "Unable to read files.");
     89            goto DONE;
     90        }
     91        pswarpFileActivation(config, skycellFiles, false);
    15592    }
    15693
     
    16299        pmChip *chip;
    163100        pmFPAview *view = pmFPAviewAlloc(0);
    164         if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
    165             return false;
     101        if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
     102            psError(psErrorCodeLast(), false, "Unable to read files.");
     103            goto DONE;
    166104        }
    167105        while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
     
    169107            if (!chip->process || !chip->file_exists) { continue; }
    170108            if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
    171                 return false;
     109                psError(psErrorCodeLast(), false, "Unable to read files.");
     110                goto DONE;
    172111            }
    173112            pmCell *cell;
     
    177116                if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE) ||
    178117                    !pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {
    179                     return false;
     118                    psError(psErrorCodeLast(), false, "Unable to read files.");
     119                    goto DONE;
    180120                }
    181121            }
    182122            if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {
    183                 return false;
     123                psError(psErrorCodeLast(), false, "Unable to write files.");
     124                goto DONE;
    184125            }
    185126        }
    186127        if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {
    187             return false;
    188         }
    189         psFree(view);
    190 
    191         fileActivation(config, detectorFiles, true);
     128            psError(psErrorCodeLast(), false, "Unable to write files.");
     129            goto DONE;
     130        }
     131        psFree(view);
     132
     133        pswarpFileActivation(config, detectorFiles, true);
    192134        pmFPAfileActivate(config->files, false, "PSWARP.ASTROM");
    193135    }
     
    211153    if (bilevelAstrometry) {
    212154        if (!pmAstromReadBilevelMosaic(input->fpa, phu->header)) {
    213             psError(PS_ERR_UNKNOWN, false, "Unable to read bilevel mosaic astrometry for input FPA.");
     155            psError(psErrorCodeLast(), false, "Unable to read bilevel mosaic astrometry for input FPA.");
    214156            psFree(view);
    215157            psFree(stats);
    216             return false;
     158            goto DONE;
    217159        }
    218160    }
     
    222164    // files associated with the science image
    223165    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
    224         return false;
     166        psError(psErrorCodeLast(), false, "Unable to read files.");
     167        goto DONE;
    225168    }
    226169
     
    230173        if (!chip->process || !chip->file_exists) { continue; }
    231174        if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
    232             return false;
     175            psError(psErrorCodeLast(), false, "Unable to read files.");
     176            goto DONE;
    233177        }
    234178
     
    237181        if (bilevelAstrometry) {
    238182            if (!pmAstromReadBilevelChip (chip, hdu->header)) {
    239                 psError(PS_ERR_UNKNOWN, false, "Unable to read bilevel chip astrometry for input FPA.");
     183                psError(psErrorCodeLast(), false, "Unable to read bilevel chip astrometry for input FPA.");
    240184                psFree(view);
    241185                psFree(stats);
    242                 return false;
     186                goto DONE;
    243187            }
    244188        } else {
    245189            // we use a default FPA pixel scale of 1.0
    246190            if (!pmAstromReadWCS (input->fpa, chip, hdu->header, 1.0)) {
    247                 psError(PS_ERR_UNKNOWN, false, "Unable to read WCS astrometry for input FPA.");
     191                psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for input FPA.");
    248192                psFree(view);
    249193                psFree(stats);
    250                 return false;
     194                goto DONE;
    251195            }
    252196        }
     
    257201            if (!cell->process || !cell->file_exists) { continue; }
    258202            if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
    259                 return false;
     203                psError(psErrorCodeLast(), false, "Unable to read files.");
     204                goto DONE;
    260205            }
    261206
     
    266211            while ((readout = pmFPAviewNextReadout(view, input->fpa, 1)) != NULL) {
    267212                if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
    268                     return false;
     213                    psError(psErrorCodeLast(), false, "Unable to read files.");
     214                    goto DONE;
    269215                }
    270216                if (!readout->data_exists) {
     
    283229
    284230                if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
    285                     return false;
     231                    psError(psErrorCodeLast(), false, "Unable to write files.");
     232                    goto DONE;
    286233                }
    287234            }
    288235            if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
    289                 return false;
     236                psError(psErrorCodeLast(), false, "Unable to write files.");
     237                goto DONE;
    290238            }
    291239        }
    292240        if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
    293             return false;
     241            psError(psErrorCodeLast(), false, "Unable to write files.");
     242            goto DONE;
    294243        }
    295244    }
     
    312261
    313262    if (!pswarpPixelsLit(output, stats, config)) {
    314         psError(PS_ERR_UNKNOWN, false, "Unable to calculate pixel regions.");
     263        psError(psErrorCodeLast(), false, "Unable to calculate pixel regions.");
    315264        psFree(cells);
    316265        psFree(view);
    317         return false;
     266        goto DONE;
    318267    }
    319268
     
    349298
    350299    if (!pmConceptsAverageCells(outCell, cells, NULL, NULL, false)) {
    351         psError(PS_ERR_UNKNOWN, false, "Unable to average cell concepts.");
     300        psError(psErrorCodeLast(), false, "Unable to average cell concepts.");
    352301        psFree(stats);
    353302        psFree(cells);
    354303        psFree(view);
    355         return false;
     304        goto DONE;
    356305    }
    357306    psFree(cells);
     
    361310
    362311    if (!psMetadataCopy(outFPA->concepts, input->fpa->concepts)) {
    363         psError(PS_ERR_UNKNOWN, false, "Unable to copy FPA concepts from input to output.");
     312        psError(psErrorCodeLast(), false, "Unable to copy FPA concepts from input to output.");
    364313        psFree(stats);
    365314        psFree(view);
    366         return false;
    367     }
    368 
    369     // Update ZP from the astrometry
    370     {
    371         psMetadataItem *item = psMetadataLookup(outFPA->concepts, "FPA.ZP");
    372         item->data.F32 = psMetadataLookupF32(NULL, astrom->fpa->concepts, "FPA.ZP");
    373     }
     315        goto DONE;
     316    }
     317
    374318    // Update ZP from the astrometry
    375319    {
     
    388332        pmHDU *skyHDU = pmHDUFromCell(cell); ///< HDU
    389333        if (!skyHDU) {
    390             psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find skycell HDU.");
     334            psError(PSWARP_ERR_DATA, false, "Unable to find skycell HDU.");
    391335            psFree(view);
    392             return false;
     336            goto DONE;
    393337        }
    394338        hdu->header = psMetadataCopy(hdu->header, skyHDU->header);
     
    398342
    399343    if (!pmAstromWriteWCS(hdu->header, outFPA, outChip, WCS_NONLIN_TOL)) {
    400         psError(PS_ERR_UNKNOWN, false, "Unable to generate WCS header.");
     344        psError(psErrorCodeLast(), false, "Unable to generate WCS header.");
    401345        psFree(stats);
    402         return false;
     346        goto DONE;
    403347    }
    404348
    405349    if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
    406         return false;
     350        psError(psErrorCodeLast(), false, "Unable to write files.");
     351        goto DONE;
    407352    }
    408353
    409354    // Done with the detector side of things
    410     fileActivation(config, detectorFiles, false);
    411     fileActivation(config, independentFiles, false);
     355    pswarpFileActivation(config, detectorFiles, false);
     356    pswarpFileActivation(config, independentFiles, false);
    412357
    413358    // We need a new PSF model for the warped frame.  It would be good to generate this analytically, but
     
    415360
    416361    if (psMetadataLookupBool(&mdok, recipe, "PSF")) {
    417         fileActivation(config, photFiles, true);
    418         ioChecksBefore(config);
     362        pswarpFileActivation(config, photFiles, true);
     363        if (!pswarpIOChecksBefore(config)) {
     364            psError(psErrorCodeLast(), false, "Unable to read files.");
     365            goto DONE;
     366        }
    419367
    420368        // supply the readout and fpa of interest to psphot
     
    428376        psArray *sources = psphotLoadPSFSources (config, view);
    429377        if (!sources) {
    430             psError(PS_ERR_UNKNOWN, false, "No sources supplied to measure PSF");
    431             return false;
     378            psError(psErrorCodeLast(), false, "No sources supplied to measure PSF");
     379            goto DONE;
    432380        }
    433381
     
    498446 DONE:
    499447
    500     // Ensure everything is written out, at every level
    501     fileActivation(config, independentFiles, true);
    502     fileActivation(config, skycellFiles, true);
    503     ioChecksAfter(config);
    504 
    505     // Write out summary statistics
    506     if (stats) {
    507         psMetadataAddF32(stats, PS_LIST_TAIL, "DT_WARP", 0, "Time for warp completion",
    508                          psTimerMark("pswarp"));
    509 
    510         const char *statsMDC = psMetadataConfigFormat(stats);
    511         if (!statsMDC) {
    512             psError(psErrorCodeLast(), false, "Unable to get statistics file.");
    513             psFree(stats);
    514             fclose(statsFile);
    515             return false;
    516         }
    517         psFree(stats);
    518         if (fprintf(statsFile, "%s", statsMDC) != strlen(statsMDC)) {
    519             psError(PSWARP_ERR_IO, true, "Unable to write statistics file.");
    520             psFree(statsMDC);
    521             return false;
    522         }
    523         psFree(statsMDC);
    524         if (fclose(statsFile) == EOF) {
    525             psError(PSWARP_ERR_IO, true, "Unable to close statistics file.");
    526             return false;
    527         }
    528         pmConfigRunFilenameAddWrite(config, "STATS", statsName);
    529     }
    530 
    531     // Dump configuration
    532     psString dump_file = psMetadataLookupStr(&status, config->arguments, "DUMP_CONFIG");
    533     if (dump_file) {
    534         if (!pmConfigDump(config, dump_file)) {
    535             psError(psErrorCodeLast(), false, "Unable to dump configuration");
    536             return false;
    537         }
    538     }
    539 
    540448    return true;
    541449}
Note: See TracChangeset for help on using the changeset viewer.