IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 3666 for trunk/stac/src/stac.c


Ignore:
Timestamp:
Apr 5, 2005, 11:51:26 AM (21 years ago)
Author:
Paul Price
Message:

Removing stac-specific configuration out of functions so that I can use them in other programs. Program appears to work as it did before.

File:
1 edited

Legend:

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

    r3660 r3666  
    22#include "pslib.h"
    33#include "stac.h"
     4#include "stacConfig.h"
    45#include <sys/time.h>
    56
     
    4748
    4849    // Read input files
    49     psArray *inputs = stacReadImages(config);
     50    psArray *inputs = stacReadImages(config->inputs);
    5051
    5152    // Read maps
    52     psArray *maps = stacReadMaps(config);
     53    psArray *maps = stacReadMaps(config->inputs);
    5354
    5455    psTrace("stac.time", 1, "I/O completed at %f seconds\n", getTime() - startTime);
     
    5657    // Get size, if not input
    5758    if (config->outnx == 0 || config->outny == 0) {
    58         stacSize(config, inputs, maps);
     59        stacSize(&config->outnx, &config->outny, &config->xMapDiff, &config->yMapDiff, inputs, maps);
    5960    }
    6061
    6162    // Invert maps
    62     psArray *inverseMaps = stacInvertMaps(maps, config);
     63    psArray *inverseMaps = stacInvertMaps(maps, config->outnx, config->outny);
    6364
    6465    // Generate errors
    65     psArray *errors = stacErrorImages(inputs, config);
     66    psArray *errors = stacErrorImages(inputs, config->gain, config->readnoise);
     67#ifdef TESTING
     68    // Write error images out to check
     69    for (int i = 0; i < inputs->n; i++) {
     70        char errName[MAXCHAR];          // Filename of error image
     71        sprintf(errName,"%s.err",config->inputs->data[i]);
     72        psFits *errorFile = psFitsAlloc(errName);
     73        if (!psFitsWriteImage(errorFile, NULL, error, 0, NULL)) {
     74            psErrorStackPrint(stderr, "Unable to write image: %s\n", errName);
     75        }
     76        psTrace("stac", 1, "Error image written to %s\n", errName);
     77        psFree(errorFile);
     78    }
     79#endif
    6680
    6781    // Transform inputs and errors
     
    6983    psArray *transformedErrors = NULL;
    7084    (void)stacTransform(&transformed, &transformedErrors, inputs, inverseMaps, errors, NULL, NULL, NULL, NULL,
    71                         config);
    72 
     85                        config->outnx, config->outny);
    7386    psTrace("stac.time",1,"Transformation completed at %f seconds\n", getTime() - startTime);
     87
     88#ifdef TESTING
     89    // Write transformed images out to check
     90    for (int i = 0; i < inputs->n; i++) {
     91        char shiftName[MAXCHAR];        // Filename of shift image
     92        char errName[MAXCHAR];          // Filename of error image
     93        sprintf(shiftName,"%s.shift1",config->inputs->data[n],numTransforms);
     94        sprintf(errName,"%s.shifterr1",config->inputs->data[n],numTransforms);
     95        psTrace("stac.transform.test", 6,
     96                "Output files have size: %dx%d\n",outImage->numCols,outImage->numRows);
     97        psFits *shiftFile = psFitsAlloc(shiftName);
     98        psFits *errFile = psFitsAlloc(errName);
     99        if (!psFitsWriteImage(shiftFile, NULL, outImage, 0, NULL)) {
     100            psErrorStackPrint(stderr, "Unable to write image: %s\n", shiftName);
     101        }
     102        psTrace("stac", 1, "Shifted image written to %s\n", shiftName);
     103        if (!psFitsWriteImage(errFile, NULL, outError, 0, NULL)) {
     104            psErrorStackPrint(stderr, "Unable to write image: %s\n", errName);
     105        }
     106        psTrace("stac", 1, "Shifted error image written to %s\n", errName);
     107        psFree(shiftFile);
     108        psFree(errFile);
     109    }
     110#endif
     111
     112
    74113
    75114    psVector *scales = NULL;            // Relative scales between images
    76115    psVector *offsets = NULL;           // Offsets between images
    77     (void)stacScales(&scales, &offsets, transformed, config);
     116    (void)stacScales(&scales, &offsets, transformed, config->starFile, config->starMapFile, config->xMapDiff,
     117                     config->yMapDiff, config->aper);
    78118    // Rescale the images
    79119    (void)stacRescale(transformed, transformedErrors, NULL, scales, offsets);
     120    // Set the saturation and bad values
     121    psVector *saturated = psVectorAlloc(transformed->n, PS_TYPE_F32); // Saturation limits
     122    psVector *bad = psVectorAlloc(transformed->n, PS_TYPE_F32); // Bad limits
     123    for (int i = 0; i < transformed->n; i++) {
     124        saturated->data.F32[i] = (config->saturated - offsets->data.F32[i]) / scales->data.F32[i];
     125        bad->data.F32[i] = (config->bad - offsets->data.F32[i]) / scales->data.F32[i];
     126    }
    80127
    81128    // Combine with rejection
    82129    psArray *rejected = NULL;
    83130    psImage *combined = NULL;
    84     (void)stacCombine(&combined, &rejected, transformed, transformedErrors, config->nReject, NULL, config);
     131    (void)stacCombine(&combined, &rejected, transformed, transformedErrors, config->nReject, NULL, saturated,
     132                      bad, config->reject);
    85133
    86134    psTrace("stac.time",1,"First combination completed at %f seconds\n", getTime() - startTime);
    87135
    88 #ifdef TESTING
     136
     137#ifdef TESTING
     138    // Write rejection images out to check
     139    for (int i = 0; i < nImages; i++) {
     140        char rejName[MAXCHAR];  // Filename of rejection image
     141        sprintf(rejName,"%s.shiftrej",config->inputs->data[i]);
     142       
     143        psFits *rejFile = psFitsAlloc(rejName);
     144        if (!psFitsWriteImage(rejFile, NULL, (*rejected)->data[i], 0, NULL)) {
     145            psErrorStackPrint(stderr, "Unable to write image: %s\n", rejName);
     146        }
     147        psTrace("stac", 1, "Rejection image written to %s\n", rejName);
     148        psFree(rejFile);
     149    }
     150
     151    // Write out pre-combined image
    89152    char preName[MAXCHAR];              // Filename of precombined image
    90153    sprintf(preName,"%s.pre",config->output);
     
    116179
    117180    // Transform rejected pixels to source frame
    118     psArray *rejectedSource = stacRejection(inputs, rejected, regions, maps, inverseMaps, config);
     181    psArray *rejectedSource = stacRejection(inputs, rejected, regions, maps, inverseMaps, config->frac,
     182                                            config->grad, config->inputs);
    119183
    120184    // Get regions of interest in the output frame
     
    134198    // Redo transformation with the masks and scales/offsets
    135199    (void)stacTransform(&transformed, &transformedErrors, inputs, inverseMaps, errors, rejectedSource,
    136                         combineRegion, scales, offsets, config);
     200                        combineRegion, scales, offsets, config->outnx, config->outny);
    137201
    138202    // Combine the newly-transformed CR-free images, no rejection
    139203    psFree(rejected);
    140204    rejected = NULL;
    141     (void)stacCombine(&combined, &rejected, transformed, transformedErrors, 0, combineRegion, config);
     205    (void)stacCombine(&combined, &rejected, transformed, transformedErrors, 0, combineRegion, saturated,
     206                      bad, config->reject);
    142207
    143208    // Write output image
Note: See TracChangeset for help on using the changeset viewer.