IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13515


Ignore:
Timestamp:
May 24, 2007, 2:28:58 PM (19 years ago)
Author:
Paul Price
Message:

Get arguments from a single MDC file instead of an annoying number of files with vectors and filenames.

Location:
trunk/ppStack/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppStack/src/ppStackArguments.c

    r13512 r13515  
    1717{
    1818    fprintf(stderr, "\nPan-STARRS Image combination\n\n");
    19     fprintf(stderr, "Usage: %s IMAGES.list MASKS.list OUTPUT_ROOT\n",
     19    fprintf(stderr, "Usage: %s INPUTS.mdc OUTPUT_ROOT\n"
     20            "where INPUTS.mdc contains:\n"
     21            "\tIMAGE(STR):  Image filename\n"
     22            "\tMASK(STR):   Mask filename\n"
     23            "\tSEEING(F32): Seeing FWHM (pixels)\n"
     24            "\tWEIGHT(F32): Relative weighting to be applied\n"
     25            "\tSCALE(F32):  Relative scaling to be applied\n",
    2026            program);
    2127    fprintf(stderr, "\n");
     
    8591    psMetadataAddU8(arguments,  PS_LIST_TAIL, "-mask-bad", 0, "Mask value for bad pixels", 0);
    8692    psMetadataAddU8(arguments,  PS_LIST_TAIL, "-mask-blank", 0, "Mask value for blank region", 0);
    87     psMetadataAddStr(arguments, PS_LIST_TAIL, "-seeing", 0, "Name of file with seeing FWHMs", NULL);
    8893
    89     if (argc == 1 || !psArgumentParse(arguments, &argc, argv) || argc != 4) {
     94    if (argc == 1 || !psArgumentParse(arguments, &argc, argv) || argc != 3) {
    9095        usage(argv[0], arguments, config);
    9196    }
    9297
    93     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "IMAGES.LIST", 0,
    94                      "Name of the input image list", argv[1]);
    95     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "MASKS.LIST", 0,
    96                      "Name of the input masks list", argv[2]);
     98    int numBad = 0;                     // Number of bad lines
     99    psMetadata *inputs = psMetadataConfigRead(NULL, &numBad, argv[1], false); // Information about inputs
     100    if (!inputs || numBad > 0) {
     101        psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unable to cleanly read MDC file with inputs.");
     102        goto ERROR;
     103    }
     104    psMetadataAddMetadata(config->arguments, PS_LIST_TAIL, "INPUTS", 0,
     105                          "Metadata with input details", inputs);
    97106    psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", 0,
    98                      "Root name of the output image list", argv[3]);
     107                     "Root name of the output image list", argv[2]);
    99108
    100     valueArgStr(config, arguments, "-stat",      "STATS",        config->arguments);
     109    valueArgStr(config, arguments, "-stat", "STATS", config->arguments);
    101110
    102111    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // Recipe for ppSim
  • trunk/ppStack/src/ppStackCamera.c

    r13493 r13515  
    1313bool ppStackCamera(pmConfig *config)
    1414{
    15     psString imageName = psMetadataLookupStr(NULL, config->arguments, "IMAGES.LIST"); // Image list filename
    16     assert(imageName);
    17     psString maskName = psMetadataLookupStr(NULL, config->arguments, "MASKS.LIST"); // Mask list filename
    18     assert(maskName);
    19 
    20     psString imageList = psSlurpFilename(imageName); // Contents of image list
    21     if (!imageList) {
    22         psError(PS_ERR_IO, false, "Unable to read list of image files %s", imageName);
    23         return false;
    24     }
    25     psArray *images = psStringSplitArray(imageList, "\n", false); // The image filenames
    26     psFree(imageList);
    27 
    28     psString maskList = psSlurpFilename(maskName); // Contents of mask list
    29     if (!maskList) {
    30         psError(PS_ERR_IO, false, "Unable to read list of mask files %s", maskName);
    31         return false;
    32     }
    33     psArray *masks = psStringSplitArray(maskList, "\n", false); // The mask filenames
    34     psFree(maskList);
    35     if (images->n != masks->n) {
    36         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    37                 "Number input images (%ld) does not match number of input masks (%ld).",
    38                 images->n, masks->n);
    39         psFree(images);
    40         psFree(masks);
    41         return false;
    42     }
    43 
    44     for (int i = 0; i < images->n; i++) {
    45         psString image = images->data[i]; // Name of image
    46         if (!image || strlen(image) == 0) {
    47             psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Image name %d is blank.", i);
    48             psFree(images);
    49             psFree(masks);
    50             return false;
    51         }
    52         psString mask = masks->data[i]; // Name of mask
    53         if (!mask || strlen(mask) == 0) {
    54             psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Mask name %d is blank.", i);
    55             psFree(images);
    56             psFree(masks);
     15    psMetadata *inputs = psMetadataLookupMetadata(NULL, config->arguments, "INPUTS"); // The inputs info
     16    psMetadataIterator *iter = psMetadataIteratorAlloc(inputs, PS_LIST_HEAD, NULL); // Iterator
     17    psMetadataItem *item;               // Item from iteration
     18    int i = 0;                          // Counter
     19    while ((item = psMetadataGetAndIncrement(iter))) {
     20        if (item->type != PS_DATA_METADATA) {
     21            psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     22                    "Component %s of the input metadata is not of type METADATA", item->name);
     23            psFree(iter);
    5724            return false;
    5825        }
    5926
     27        psMetadata *input = item->data.md; // The input metadata of interest
     28
     29        psString image = psMetadataLookupStr(NULL, input, "IMAGE"); // Name of image
     30        if (!image || strlen(image) == 0) {
     31            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Component %s lacks IMAGE of type STR", item->name);
     32            psFree(iter);
     33            return false;
     34        }
     35
     36        psString mask = psMetadataLookupStr(NULL, input, "MASK"); // Name of mask
     37        if (!mask || strlen(mask) == 0) {
     38            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Component %s lacks MASK of type STR", item->name);
     39            psFree(iter);
     40            return false;
     41        }
     42
     43        float seeing = psMetadataLookupF32(NULL, input, "SEEING"); // Seeing FWHM
     44        if (isnan(seeing)) {
     45            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Component %s lacks SEEING of type F32", item->name);
     46            psFree(iter);
     47            return false;
     48        }
     49
     50        float weight = psMetadataLookupF32(NULL, input, "WEIGHT"); // Relative weight
     51        if (isnan(weight)) {
     52            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Component %s lacks WEIGHT of type F32", item->name);
     53            psFree(iter);
     54            return false;
     55        }
     56
     57        float scale = psMetadataLookupF32(NULL, input, "SCALE"); // Relative scale
     58        if (isnan(scale)) {
     59            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Component %s lacks SCALE of type F32", item->name);
     60            psFree(iter);
     61            return false;
     62        }
     63
     64        // Add the image file
    6065        psArray *imageFiles = psArrayAlloc(1); // Array of filenames for this FPA
    6166        imageFiles->data[0] = psMemIncrRefCounter(image);
     
    6873        if (!imageFile || !found) {
    6974            psError(PS_ERR_UNKNOWN, false, "Unable to define file from image %d (%s)", i, image);
    70             psFree(images);
    71             psFree(masks);
    7275            return false;
    7376        }
    7477        if (imageFile->type != PM_FPA_FILE_IMAGE) {
    7578            psError(PS_ERR_IO, true, "PPSTACK.INPUT is not of type IMAGE");
    76             psFree(images);
    77             psFree(masks);
    7879            return false;
    7980        }
    8081
     82        // Add the mask file
    8183        psArray *maskFiles = psArrayAlloc(1); // Array of filenames for this FPA
    8284        maskFiles->data[0] = psMemIncrRefCounter(mask);
     
    9092        if (!maskFile || !found) {
    9193            psError(PS_ERR_UNKNOWN, false, "Unable to define file from mask %d (%s)", i, mask);
    92             psFree(images);
    93             psFree(masks);
    9494            return false;
    9595        }
    9696        if (maskFile->type != PM_FPA_FILE_MASK) {
    9797            psError(PS_ERR_IO, true, "PPSTACK.INPUT.MASK is not of type MASK");
    98             psFree(images);
    99             psFree(masks);
    10098            return false;
    10199        }
     100
     101        psMetadataAddF32(imageFile->fpa->analysis, PS_LIST_TAIL, "PPSTACK.SEEING", 0,
     102                         "Seeing for image", seeing);
     103        psMetadataAddF32(imageFile->fpa->analysis, PS_LIST_TAIL, "PPSTACK.WEIGHT", 0,
     104                         "Relative weight for image", weight);
     105        psMetadataAddF32(imageFile->fpa->analysis, PS_LIST_TAIL, "PPSTACK.SCALE", 0,
     106                         "Relative scale for image", scale);
     107
     108        i++;
    102109    }
     110    psFree(iter);
    103111    psMetadataRemoveKey(config->arguments, "IMAGE.FILENAMES");
    104112    psMetadataRemoveKey(config->arguments, "MASK.FILENAMES");
    105113
    106     psMetadataAddS32(config->arguments, PS_LIST_TAIL, "INPUTS.NUM", 0, "Number of input files", images->n);
    107 
    108     psFree(images);
    109     psFree(masks);
     114    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "INPUTS.NUM", 0, "Number of input files", i);
    110115
    111116    // Output image
  • trunk/ppStack/src/ppStackReadout.c

    r13513 r13515  
    1010
    1111#define ARRAY_BUFFER 16                 // Number to add to array at a time
    12 
    13 
    14 #define WEIGHT 1.0                      // Weighting
    1512
    1613bool ppStackReadout(pmConfig *config, const pmFPAview *view)
     
    3532    // Get the input sources
    3633    psArray *stack = psArrayAllocEmpty(ARRAY_BUFFER); // The stack of inputs
    37     psMetadataIterator *inputIter = psMetadataIteratorAlloc(config->files, PS_LIST_HEAD,
    38                                                             "^PPSTACK.INPUT$"); // Iterator over input files
    39     psMetadataItem *item;               // Item from iteration
     34    psMetadataIterator *fileIter = psMetadataIteratorAlloc(config->files, PS_LIST_HEAD,
     35                                                           "^PPSTACK.INPUT$"); // Iterator over input files
     36    psMetadataItem *fileItem;           // Item from iteration
    4037    psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN); // Statistics
    4138    psRandom *rng = psRandomAlloc(0, PS_RANDOM_TAUS); // Random number generator
    4239    int fileNum = 0;                    // Number of file
    4340    float totExposure = 0.0;            // Total exposure time
    44     while ((item = psMetadataGetAndIncrement(inputIter))) {
    45         assert(item->type == PS_DATA_UNKNOWN);
    46         pmFPAfile *inputFile = item->data.V; // An input file
     41    while ((fileItem = psMetadataGetAndIncrement(fileIter))) {
     42        assert(fileItem->type == PS_DATA_UNKNOWN);
     43        pmFPAfile *inputFile = fileItem->data.V; // An input file
    4744        pmReadout *ro = pmFPAviewThisReadout(view, inputFile->fpa); // Corresponding readout
     45
     46        float seeing = psMetadataLookupF32(NULL, inputFile->fpa->analysis, "PPSTACK.SEEING"); // Seeing FWHM
     47        float weight = psMetadataLookupF32(NULL, inputFile->fpa->analysis, "PPSTACK.WEIGHT"); // Rel. weight
     48        float scale = psMetadataLookupF32(NULL, inputFile->fpa->analysis, "PPSTACK.SCALE"); // Rel. scale
    4849
    4950        // Brain-dead background subtraction
     
    5253            psFree(stats);
    5354            psFree(rng);
    54             psFree(inputIter);
     55            psFree(fileIter);
    5556            psFree(stack);
    5657            psFree(outRO);
     
    5859        }
    5960        (void)psBinaryOp(ro->image, ro->image, "-", psScalarAlloc(stats->robustMedian, PS_TYPE_F32));
     61
     62        // Apply scaling
     63        (void)psBinaryOp(ro->image, ro->image, "*", psScalarAlloc(1.0 / scale, PS_TYPE_F32));
    6064
    6165        // Normalise each input by the exposure time
     
    6670            psFree(stats);
    6771            psFree(rng);
    68             psFree(inputIter);
     72            psFree(fileIter);
    6973            psFree(outRO);
    7074            psFree(stack);
     
    7377        totExposure += exposure;        // Total exposure time
    7478        (void)psBinaryOp(ro->image, ro->image, "/", psScalarAlloc(exposure, PS_TYPE_F32));
    75         pmStackData *data = pmStackDataAlloc(ro, seeing ? seeing->data.F32[fileNum] : 0.0,
    76                                              WEIGHT); // Data to stack
     79        pmStackData *data = pmStackDataAlloc(ro, seeing, weight); // Data to stack
    7780        psArrayAdd(stack, ARRAY_BUFFER, data);
    7881        psFree(data);                   // Drop reference
    7982        fileNum++;
    8083    }
    81     psFree(inputIter);
     84    psFree(fileIter);
    8285    psFree(stats);
    8386    psFree(rng);
Note: See TracChangeset for help on using the changeset viewer.