IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 22, 2007, 5:09:53 PM (19 years ago)
Author:
Paul Price
Message:

When we went to process TC3 images, we found that our camera formats
didn't handle its case (PHU=CHIP, EXT=CELL) properly. In order to
accomodate it, I've reworked the camera formats (including adding a
source to an FPA, and generating mosaic camera configurations). Now,
the particular format of the camera format file is *very* dependent
upon the FITS file:

Case PHU EXTENSIONS Description

  1. FPA CHIP CONTENTS(METADATA) has a list of extensions, each with a chip type.

CHIPS(METADATA) has a list of chip types, each with cell:type

  1. FPA CELL CONTENTS(METADATA) has a list of extensions, each with chip:cell:type

No need for CHIPS.

  1. FPA NONE CONTENTS(STRING) has a list of extensions, chip:cell:type

No need for CHIPS

  1. CHIP CELL CONTENTS(METADATA) is a menu, each with a chip type

CHIPS(METADATA) has a list of chip types(METADATA), containg a list of
extensions.

  1. CHIP NONE CONTENTS(METADATA) is a menu, each with a chip type

CHIPS(METADATA) has a list of chip types(STRING) with cell:type

  1. CELL NONE CONTENTS(METADATA) is a menu, each with a cell type.

No need for CHIPS.

Debugged and plugged memory leaks for this fix. Now able to
successfully read TC3 and Megacam (all 3 formats). Can't run ppImage
with PPIMAGE_N on file with PHU=CHIP because it's trying to write out
a PHU (at the FPA level) before it reads any of the input data. This
behaviour exists in a previous version (IPP 1.0; in fact, the current
fix deals with it a bit better --- error instead of SEGV), so it
should be safe to use this now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/config/pmConfigCamera.c

    r11754 r12564  
    1111
    1212#include "pmConfigCamera.h"
     13
     14
     15#define TABLE_OF_CONTENTS "CONTENTS"    // Name for camera format metadata containing the contents
     16#define CHIP_TYPES "CHIPS"              // Name for camera format metadata containing the chip types
     17#define CELL_TYPES "CELLS"              // Name for camera format metadata containing the cell types
    1318
    1419
     
    6873                             psMetadata *newCameras, // New list of camera configurations
    6974                             const char *name, // Name of original camera configuration
    70                              pmFPALevel level // Level
     75                             pmFPALevel mosaicLevel // Level to which we are mosaicking
    7176                            )
    7277{
     
    7479    assert(newCameras);
    7580    assert(name);
    76     assert(level == PM_FPA_LEVEL_CHIP || level == PM_FPA_LEVEL_FPA);
     81    assert(mosaicLevel == PM_FPA_LEVEL_CHIP || mosaicLevel == PM_FPA_LEVEL_FPA);
    7782
    7883    // See if the old one is there
     
    8489    // See if the new one is already there
    8590    psString newName = NULL;       // Name of mosaicked camera
    86     psStringAppend(&newName, "_%s-%s", name, level == PM_FPA_LEVEL_CHIP ? "CHIP" : "FPA");
     91    psStringAppend(&newName, "_%s-%s", name, mosaicLevel == PM_FPA_LEVEL_CHIP ? "CHIP" : "FPA");
    8792    if (psMetadataLookup(oldCameras, newName)) {
    8893        return true;
     
    99104        return NULL;
    100105    }
    101     switch (level) {
    102     case PM_FPA_LEVEL_CHIP: {
    103             // Replace the contents of each chip with a single cell
    104             psMetadataIterator *fpaIter = psMetadataIteratorAlloc(fpa, PS_LIST_HEAD, NULL); // Iterator
    105             psMetadataItem *fpaItem = NULL;     // Item from iteration
    106             while ((fpaItem = psMetadataGetAndIncrement(fpaIter))) {
    107                 if (fpaItem->type != PS_DATA_STRING) {
    108                     psWarning("Element %s within FPA in camera configuration is not of type STR.",
    109                               fpaItem->name);
    110                     continue;
    111                 }
    112 
    113                 psFree(fpaItem->data.str);
    114                 fpaItem->data.str = psStringCopy("MosaickedCell");
    115                 psFree(fpaItem->comment);
    116                 fpaItem->comment = psStringCopy("Mosaicked cell; automatically generated");
    117             }
    118             psFree(fpaIter);
    119         }
    120         break;
    121     case PM_FPA_LEVEL_FPA: {
    122             while (psListLength(fpa->list) > 0) {
    123                 psMetadataRemoveIndex(fpa, PS_LIST_TAIL);
    124             }
    125 
    126             psMetadataAddStr(fpa, PS_LIST_HEAD, "MosaickedChip", 0,
    127                              "Mosaicked chip with mosaicked cell; automatically generated",
    128                              "MosaickedCell");
    129         }
    130         break;
     106    switch (mosaicLevel) {
     107      case PM_FPA_LEVEL_CHIP: {
     108          // Replace the contents of each chip with a single cell
     109          psMetadataIterator *fpaIter = psMetadataIteratorAlloc(fpa, PS_LIST_HEAD, NULL); // Iterator
     110          psMetadataItem *fpaItem = NULL;     // Item from iteration
     111          while ((fpaItem = psMetadataGetAndIncrement(fpaIter))) {
     112              if (fpaItem->type != PS_DATA_STRING) {
     113                  psWarning("Element %s within FPA in camera configuration is not of type STR.",
     114                            fpaItem->name);
     115                  continue;
     116              }
     117
     118              psFree(fpaItem->data.str);
     119              fpaItem->data.str = psStringCopy("MosaickedCell");
     120              psFree(fpaItem->comment);
     121              fpaItem->comment = psStringCopy("Mosaicked cell; automatically generated");
     122          }
     123          psFree(fpaIter);
     124          break;
     125      }
     126      case PM_FPA_LEVEL_FPA: {
     127          // Replace the contents of the FPA with a single chip containing a single cell
     128          while (psListLength(fpa->list) > 0) {
     129              psMetadataRemoveIndex(fpa, PS_LIST_TAIL);
     130          }
     131
     132          psMetadataAddStr(fpa, PS_LIST_HEAD, "MosaickedChip", 0,
     133                           "Mosaicked chip with mosaicked cell; automatically generated",
     134                           "MosaickedCell");
     135          break;
     136      }
    131137    default:
    132138        psAbort("Should never get here.\n");
     
    142148        psMetadata *format = formatsItem->data.V; // The camera format
    143149
    144         // Add a RULE
     150        // Add a RULE, so that when a mosaic is written to a FITS file, it can be recognised again when read.
    145151        psMetadata *rule = psMetadataLookupMetadata(&mdok, format, "RULE"); // Way to identify format from PHU
    146152        if (!mdok || !rule) {
     
    148154            continue;
    149155        }
    150         switch (level) {
     156        switch (mosaicLevel) {
    151157        case PM_FPA_LEVEL_CHIP:
    152158            psMetadataAddStr(rule, PS_LIST_TAIL, "PSMOSAIC", 0, "Mosaicked level", "CHIP");
     
    173179        }
    174180        if (strcasecmp(phuItem->data.str, "CELL") == 0 ||
    175                 (level == PM_FPA_LEVEL_FPA && (strcasecmp(phuItem->data.str, "CHIP") == 0))) {
     181                (mosaicLevel == PM_FPA_LEVEL_FPA && (strcasecmp(phuItem->data.str, "CHIP") == 0))) {
    176182            psFree(phuItem->data.str);
    177             if (level == PM_FPA_LEVEL_CHIP) {
     183            if (mosaicLevel == PM_FPA_LEVEL_CHIP) {
    178184                phuItem->data.str = psStringCopy("CHIP");
    179185            } else {
     
    187193            continue;
    188194        }
    189         switch (level) {
    190         case PM_FPA_LEVEL_CHIP:
    191             if (strcasecmp(extensionsItem->data.str, "NONE") == 0) {
    192                 if (strcasecmp(phuItem->data.str, "FPA") == 0) {
    193                     break;              // Don't need a "CONTENT" to identify the content!
    194                 }
    195                 psMetadataItem *contentItem = psMetadataLookup(file, "CONTENT"); // Key to CONTENTS menu
    196                 if (!contentItem || contentItem->type != PS_DATA_STRING) {
    197                     psWarning("Couldn't find CONTENT of type STR in the FILE information "
    198                               "in the camera format %s.\n", formatsItem->name);
    199                     continue;
    200                 }
    201                 psFree(contentItem->data.str);
    202                 contentItem->data.str = psStringCopy("{CHIP.NAME}");
    203             } else if (strcasecmp(extensionsItem->data.str, "CELL") == 0) {
     195        switch (mosaicLevel) {
     196          case PM_FPA_LEVEL_CHIP:
     197            if (strcasecmp(phuItem->data.str, "FPA") == 0 &&
     198                strcasecmp(extensionsItem->data.str, "CELL") == 0) {
    204199                psFree(extensionsItem->data.str);
    205200                extensionsItem->data.str = psStringCopy("CHIP");
    206             }
    207             break;
    208         case PM_FPA_LEVEL_FPA:
     201            } else {
     202                psFree(extensionsItem->data.str);
     203                extensionsItem->data.str = psStringCopy("NONE");
     204
     205                if (strcasecmp(phuItem->data.str, "FPA") == 0) {
     206                    // Don't need a "CONTENT" to identify the content!
     207                    if (psMetadataLookup(file, "CONTENT")) {
     208                        psMetadataRemoveKey(file, "CONTENT");
     209                    }
     210                    break;
     211                }
     212                psMetadataAddStr(file, PS_LIST_TAIL, "CONTENT", PS_META_REPLACE, "Key to CONTENTS menu",
     213                                 "{CHIP.NAME}");
     214            }
     215
     216#if 0
     217            // Don't need CELL.NAME for chip-mosaicked camera
     218            if (psMetadataLookup(file, "CELL.NAME")) {
     219                psMetadataRemoveKey(file, "CELL.NAME");
     220            }
     221#endif
     222            break;
     223          case PM_FPA_LEVEL_FPA:
    209224            psFree(extensionsItem->data.str);
    210225            extensionsItem->data.str = psStringCopy("NONE");
     226#if 0
     227            // Don't need CHIP.NAME or CELL.NAME for fpa-mosaicked camera
     228            if (psMetadataLookup(file, "CHIP.NAME")) {
     229                psMetadataRemoveKey(file, "CHIP.NAME");
     230            }
     231            if (psMetadataLookup(file, "CELL.NAME")) {
     232                psMetadataRemoveKey(file, "CELL.NAME");
     233            }
     234#endif
    211235            break;
    212236        default:
     
    215239
    216240        // Fix up the CONTENTS to contain only the mosaicked cell for each chip
    217         switch (level) {
    218         case PM_FPA_LEVEL_CHIP:
    219             if (strcasecmp(phuItem->data.str, "FPA") == 0 &&
    220                     strcasecmp(extensionsItem->data.str, "NONE") == 0) {
    221                 // List the contents on a single line
    222                 psString contentsLine = NULL; // Contents of the PHU
    223                 psMetadataIterator *fpaIter = psMetadataIteratorAlloc(fpa, PS_LIST_HEAD, NULL); // Iterator
    224                 psMetadataItem *fpaItem;    // Item from iteration
    225                 while ((fpaItem = psMetadataGetAndIncrement(fpaIter))) {
    226                     if (fpaItem->type != PS_DATA_STRING) {
    227                         // We've already thrown a warning on this, above.
    228                         continue;
     241        switch (mosaicLevel) {
     242          case PM_FPA_LEVEL_FPA:
     243            psMetadataAddStr(format, PS_LIST_TAIL, TABLE_OF_CONTENTS, PS_META_REPLACE, NULL,
     244                             "MosaickedChip:MosaickedCell:_mosaic");
     245            break;
     246          case PM_FPA_LEVEL_CHIP:
     247            if (strcasecmp(phuItem->data.str, "FPA") == 0) {
     248                if (strcasecmp(extensionsItem->data.str, "CHIP") == 0) {
     249                    // List the chipName:chipType for each chip.
     250
     251                    psMetadata *contents = psMetadataAlloc(); // List of contents, with chipName:chipType
     252
     253                    psMetadataIterator *fpaIter = psMetadataIteratorAlloc(fpa, PS_LIST_HEAD, NULL); // Iteratr
     254                    psMetadataItem *fpaItem;    // Item from iteration
     255                    while ((fpaItem = psMetadataGetAndIncrement(fpaIter))) {
     256                        if (fpaItem->type != PS_DATA_STRING) {
     257                            // We've already thrown a warning on this, above.
     258                            continue;
     259                        }
     260                        psString content = NULL; // Content to add
     261                        psStringAppend(&content, "%s:_mosaicChip ", fpaItem->name);
     262                        psMetadataAddStr(contents, PS_LIST_TAIL, fpaItem->name, 0, NULL, content);
     263                        psFree(content);
    229264                    }
    230                     psStringAppend(&contentsLine, "%s:MosaickedCell:_mosaic ", fpaItem->name);
     265                    psFree(fpaIter);
     266                    psMetadataAddMetadata(format, PS_LIST_TAIL, TABLE_OF_CONTENTS, PS_META_REPLACE,
     267                                          "List of contents", contents);
     268                    psFree(contents);
     269
     270                    psMetadata *chips = psMetadataAlloc(); // List of chip types, with cellName:cellType
     271                    psMetadataAddStr(chips, PS_LIST_TAIL, "_mosaicChip", 0, NULL,
     272                                     "MosaickedCell:_mosaic");
     273                    psMetadataAddMetadata(format, PS_LIST_TAIL, CHIP_TYPES, PS_META_REPLACE,
     274                                          "List of chip types", chips);
     275                    psFree(chips);
     276                    break;
     277                } else if (strcasecmp(extensionsItem->data.str, "NONE") == 0) {
     278                    // List the contents on a single line
     279                    psString contentsLine = NULL; // Contents of the PHU
     280                    psMetadataIterator *fpaIter = psMetadataIteratorAlloc(fpa, PS_LIST_HEAD, NULL); // Iteratr
     281                    psMetadataItem *fpaItem;    // Item from iteration
     282                    while ((fpaItem = psMetadataGetAndIncrement(fpaIter))) {
     283                        if (fpaItem->type != PS_DATA_STRING) {
     284                            // We've already thrown a warning on this, above.
     285                            continue;
     286                        }
     287                        psStringAppend(&contentsLine, "%s:MosaickedCell:_mosaic ", fpaItem->name);
     288                    }
     289                    psFree(fpaIter);
     290                    psMetadataAddStr(format, PS_LIST_TAIL, TABLE_OF_CONTENTS, PS_META_REPLACE,
     291                                     NULL, contentsLine);
     292                    psFree(contentsLine);
     293                    break;
    231294                }
    232                 psFree(fpaIter);
    233                 psMetadataAddStr(format, PS_LIST_TAIL, "CONTENTS", PS_META_REPLACE, NULL, contentsLine);
    234                 psFree(contentsLine);
    235                 break;
    236             }
    237 
    238             psMetadata *contents = psMetadataLookupMetadata(&mdok, format, "CONTENTS"); // Contents of file
     295            }
     296            // PHU level is CHIP, EXTENSIONS is NONE.
     297
     298            psMetadata *contents = psMetadataLookupMetadata(&mdok, format,
     299                                                            TABLE_OF_CONTENTS); // File contents
    239300            if (!mdok || !contents) {
    240                 psWarning("Couldn't find CONTENTS in the camera format %s.\n", formatsItem->name);
     301                psWarning("Couldn't find %s in the camera format %s.\n", TABLE_OF_CONTENTS,
     302                          formatsItem->name);
    241303                continue;
    242304            }
     
    244306                psMetadataRemoveIndex(contents, PS_LIST_TAIL);
    245307            }
     308
    246309            psMetadataIterator *fpaIter = psMetadataIteratorAlloc(fpa, PS_LIST_HEAD, NULL); // Iterator
    247310            psMetadataItem *fpaItem;    // Item from iteration
     
    252315                }
    253316
    254                 psString content = NULL;    // Content of the chip
    255                 psStringAppend(&content, "%s:MosaickedCell:_mosaic", fpaItem->name);
    256                 psMetadataAddStr(contents, PS_LIST_TAIL, fpaItem->name, 0, NULL, content);
    257                 psFree(content);            // Drop reference
     317                psMetadataAddStr(contents, PS_LIST_TAIL, fpaItem->name, 0, NULL, "_mosaicChip");
    258318            }
    259319            psFree(fpaIter);
    260             break;
    261         case PM_FPA_LEVEL_FPA:
    262             psMetadataAddStr(format, PS_LIST_TAIL, "CONTENTS", PS_META_REPLACE, NULL,
    263                              "MosaickedChip:MosaickedCell:_mosaic");
     320
     321            psMetadata *chips = psMetadataAlloc(); // List of chip types, with cellName:cellType
     322            psMetadataAddStr(chips, PS_LIST_TAIL, "_mosaicChip", 0, NULL,
     323                             "MosaickedCell:_mosaic");
     324            psMetadataAddMetadata(format, PS_LIST_TAIL, CHIP_TYPES, PS_META_REPLACE,
     325                                  "List of chip types", chips);
     326            psFree(chips);
    264327            break;
    265328        default:
     
    268331
    269332        // Fix the cell type
    270         psMetadata *cells = psMetadataLookupMetadata(&mdok, format, "CELLS"); // CELLS information
     333        psMetadata *cells = psMetadataLookupMetadata(&mdok, format, CELL_TYPES); // CELLS information
    271334        if (!mdok || !cells) {
    272335            psWarning("Couldn't find CELLS of type METADATA in the camera format %s.\n", formatsItem->name);
     
    316379        }
    317380
    318         if (level == PM_FPA_LEVEL_FPA) {
     381        if (mosaicLevel == PM_FPA_LEVEL_FPA) {
    319382            removeChipConceptsSources(translation);
    320383            removeChipConceptsSources(database);
     
    347410}
    348411
    349 
    350412// Generate the chip mosaicked version of a camera configuration
    351413bool pmConfigCameraMosaickedVersions(psMetadata *site, // The site configuration
Note: See TracChangeset for help on using the changeset viewer.