IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.