IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 11255


Ignore:
Timestamp:
Jan 23, 2007, 5:11:19 PM (19 years ago)
Author:
Paul Price
Message:

Enabling different formats for output pmFPAfiles. To do this, needed to overhaul the writing functions to generate a new FPA using the new format, and write that. To get the blank PHU, needed to do similarly for the open function (!), since it writes blanks immediately after opening the file. Tested with inputting 6 megacam split chips and writing to spliced format --- works successfully.

Location:
trunk/psModules/src/camera
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/camera/pmFPAConstruct.c

    r11237 r11255  
    766766
    767767    pmFPAview *view = addSource(fpa, phuView, NULL, format, true);
    768     bool status = (view == NULL);
     768    bool status = (view != NULL);
    769769    psFree(view);
    770770    return status;
     
    895895
    896896}
     897
     898
     899pmFPALevel pmFPAPHULevel(const psMetadata *format)
     900{
     901    PS_ASSERT_METADATA_NON_NULL(format, PM_FPA_LEVEL_NONE);
     902
     903    bool mdok;                          // Status of MD lookup
     904    psMetadata *fileInfo = psMetadataLookupMetadata(&mdok, format, "FILE"); // Contents of FILE metadata
     905    if (!mdok || !fileInfo) {
     906        psError(PS_ERR_UNKNOWN, true, "Unable to find FILE in camera format configuration.\n");
     907        return PM_FPA_LEVEL_NONE;
     908    }
     909    const char *phu = psMetadataLookupStr(&mdok, fileInfo, "PHU"); // PHU level
     910    if (!mdok || !phu || strlen(phu) == 0) {
     911        psError(PS_ERR_UNKNOWN, true, "Unable to find PHU in FILE in camera format configuration.\n");
     912        return PM_FPA_LEVEL_NONE;
     913    }
     914
     915    return pmFPALevelFromName(phu);
     916}
     917
     918pmFPALevel pmFPAExtensionsLevel(const psMetadata *format)
     919{
     920    PS_ASSERT_METADATA_NON_NULL(format, PM_FPA_LEVEL_NONE);
     921
     922    bool mdok;                          // Status of MD lookup
     923    psMetadata *fileInfo = psMetadataLookupMetadata(&mdok, format, "FILE"); // Contents of FILE metadata
     924    if (!mdok || !fileInfo) {
     925        psError(PS_ERR_UNKNOWN, true, "Unable to find FILE in camera format configuration.\n");
     926        return PM_FPA_LEVEL_NONE;
     927    }
     928
     929    const char *extensions = psMetadataLookupStr(&mdok, fileInfo, "EXTENSIONS"); // EXTENSIONS level
     930    if (!mdok || !extensions || strlen(extensions) == 0) {
     931        psError(PS_ERR_UNKNOWN, true, "Unable to find EXTENSIONS in FILE in camera format configuration.\n");
     932        return PM_FPA_LEVEL_NONE;
     933    }
     934
     935    return pmFPALevelFromName(extensions);
     936}
     937
  • trunk/psModules/src/camera/pmFPAConstruct.h

    r11253 r11255  
    44 * @author Paul Price, IfA
    55 *
    6  * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    7  * @date $Date: 2007-01-24 02:54:14 $
     6 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     7 * @date $Date: 2007-01-24 03:11:19 $
    88 * Copyright 2005-2006 Institute for Astronomy, University of Hawaii
    99 */
     
    6161                bool concepts           ///< Print concepts?
    6262               );
     63
     64/// Return the PHU level for an FPA, given the format
     65pmFPALevel pmFPAPHULevel(const psMetadata *format);
     66
     67/// Return the Extensions level for an FPA, given the format
     68pmFPALevel pmFPAExtensionsLevel(const psMetadata *format);
     69
    6370/// @}
     71
    6472#endif
  • trunk/psModules/src/camera/pmFPACopy.c

    r10516 r11255  
    3737}
    3838
     39#if 0
    3940// Find the blank (image-less) PHU, given a cell.
    4041static pmHDU *findBlankPHU(const pmCell *cell // The cell for which to find the PHU
     
    5758    return NULL;
    5859}
     60#endif
    5961
    6062//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     
    277279    binItem->data.S32 *= yBin;
    278280
     281    #if 0
    279282    // Copy any headers
    280283    pmHDU *targetHDU = pmHDUFromCell(target); // The target HDU
     
    285288        }
    286289    }
     290
    287291    // Copy the PHU over as well, if required
    288292    pmHDU *targetPHU = findBlankPHU(target); // The target PHU
    289293    if (targetPHU && targetPHU != targetHDU && !targetPHU->header) {
    290         pmHDU *sourcePHU = findBlankPHU(source); // The source PHU
    291         if (sourcePHU->header) {
     294        //        pmHDU *sourcePHU = pmHDUGetHighest(source->parent->parent, source->parent, source); // A source HDU
     295        pmHDU *sourcePHU = findBlankPHU(source); // The target PHU
     296        if (sourcePHU && sourcePHU->header) {
    292297            targetPHU->header = psMetadataCopy(targetPHU->header, sourcePHU->header);
    293298        }
    294299    }
     300    #endif
    295301
    296302    target->data_exists = true;
  • trunk/psModules/src/camera/pmFPAMosaic.c

    r10966 r11255  
    12001200        return false;
    12011201    }
    1202     targetHDU->header = psMetadataCopy(targetHDU->header, sourceHDU->header);
     1202
     1203    if (sourceHDU->header) {
     1204        targetHDU->header = psMetadataCopy(targetHDU->header, sourceHDU->header);
     1205    } else if (!targetHDU->header) {
     1206        targetHDU->header = psMetadataAlloc();
     1207    }
    12031208
    12041209    if (!pmConfigConformHeader(targetHDU->header, targetHDU->format)) {
  • trunk/psModules/src/camera/pmFPAWrite.c

    r10966 r11255  
    3838        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find HDU.\n");
    3939        return false;
     40    }
     41    if (!hdu->header) {
     42        hdu->header = psMetadataAlloc();
    4043    }
    4144    bool mdok;                          // Status of MD lookup
  • trunk/psModules/src/camera/pmFPAfile.c

    r11144 r11255  
    382382    return PM_FPA_FILE_NONE;
    383383}
    384 
  • trunk/psModules/src/camera/pmFPAfileDefine.c

    r11242 r11255  
    106106}
    107107
     108// Check the various levels for file operations to make sure that they are suitable based on the format
     109static void adjustLevels(pmFPAfile *file, // File for which to adjust levels
     110                         const psMetadata *format // Format to use to adjust levels
     111                        )
     112{
     113    assert(file);
     114    assert(format);
     115
     116
     117    return;
     118}
     119
    108120// define a pmFPAfile, bind to the optional fpa if supplied
    109121pmFPAfile *pmFPAfileDefineOutput(pmConfig *config, pmFPA *fpa, const char *name)
     
    167179    }
    168180
    169     file->fileLevel = pmFPALevelFromName(psMetadataLookupStr(&status, data, "FILE.LEVEL"));
     181    file->camera = psMemIncrRefCounter(config->camera);
     182    const char *formatName = psMetadataLookupStr (&status, data, "FILE.FORMAT");
     183    psMetadata *format = NULL;          // Camera format to use
     184    if (formatName && strcasecmp(formatName, "NONE") != 0) {
     185        // select the format list from the selected camera
     186        psMetadata *formats = psMetadataLookupMetadata(&status, file->camera, "FORMATS"); // List of formats
     187
     188        // select the desired format
     189        format = psMetadataLookupMetadata(&status, formats, formatName);
     190        if (!format) {
     191            psError(PS_ERR_IO, false, "format %s for %s not defined", formatName, name);
     192            psFree(file);
     193            return NULL;
     194        }
     195        file->format = psMemIncrRefCounter(format);
     196        #if 0
     197
     198        file->src = psMemIncrRefCounter(fpa);
     199        file->fpa = pmFPAConstruct(file->camera);
     200        #endif
     201
     202    } else {
     203        format = config->format;
     204        #if 0
     205
     206        file->fpa = psMemIncrRefCounter(fpa);
     207        #endif
     208
     209    }
     210    #if 1
     211    file->fpa = psMemIncrRefCounter(fpa);
     212    #endif
     213
     214
     215    file->fileLevel = pmFPAPHULevel(format);
    170216    if (file->fileLevel == PM_FPA_LEVEL_NONE) {
    171         psError(PS_ERR_IO, true, "FILE.LEVEL is not set for %s\n", name);
    172         return NULL;
    173     }
    174 
    175     file->dataLevel = pmFPALevelFromName(psMetadataLookupStr (&status, data, "DATA.LEVEL"));
     217        psError(PS_ERR_IO, true, "Unable to determine file level for %s\n", name);
     218        return NULL;
     219    }
     220
     221    file->dataLevel = pmFPALevelFromName(psMetadataLookupStr(&status, data, "DATA.LEVEL"));
    176222    if (file->dataLevel == PM_FPA_LEVEL_NONE) {
    177223        psError(PS_ERR_IO, true, "DATA.LEVEL is not set for %s\n", name);
     
    182228    file->freeLevel = file->dataLevel;
    183229
    184     if (fpa != NULL) {
    185         file->fpa = psMemIncrRefCounter(fpa);
    186     }
    187 
    188     #if 0
    189     // for WRITE type of data, the output format needs to be determined
    190     // this is only needed if the output file is not identical in structure to the input?
    191     // for
    192     char *formatLine = psMetadataLookupStr (&status, data, "FILE.FORMAT");
    193     if (formatLine && strcasecmp (formatLine, "NONE")) {
    194 
    195         char *formatName = NULL;
    196 
    197         psArray *words = psStringSplitArray (formatLine, ":", false);
    198         if (!words || !words->n) {
    199             psAbort("pmFPAfileDefine", "programming error: cannot be NULL or empty!");
    200         }
    201         if (words->n == 1) {
    202             // format selected in this camera
    203             formatName = formatLine;
    204             file->camera = psMemIncrRefCounter (config->camera);
    205         }
    206         if (words->n == 2) {
    207             // select the requested camera
    208             formatName = words->data[1];
    209             file->camera = pmConfigCameraByName(config, words->data[0]);
    210             // XXX do we need to save the camera name?
    211             if (!file->camera) {
    212                 psError(PS_ERR_IO, false, "camera %s not found\n", (char *)words->data[0]);
    213                 psFree(words);
    214                 return NULL;
    215             }
    216         }
    217 
    218         // select the format list from the selected camera
    219         psMetadata *formats = psMetadataLookupMetadata(&status, file->camera, "FORMATS"); // List of formats
    220 
    221         // select the desired format
    222         char *formatFile = psMetadataLookupStr (&status, formats, formatName);
    223         if (!formatFile) {
    224             psError(PS_ERR_IO, false, "format %s for %s not defined", formatName, name);
    225             psFree (file);
    226             psFree (words);
    227             return NULL;
    228         }
    229         pmConfigFileRead(&file->format, formatFile, formatName);
    230         psFree (words);
    231     }
    232     #endif
     230    pmFPALevel extLevel = pmFPAExtensionsLevel(format); // Level for extensions
     231    if (extLevel != PM_FPA_LEVEL_NONE) {
     232        if (extLevel < file->dataLevel) {
     233            psWarning("Level for extensions is higher than desired data level --- adjusting.\n");
     234            file->dataLevel = extLevel;
     235        }
     236        if (extLevel < file->freeLevel) {
     237            psWarning("Level for extensions is higher than desired free level --- adjusting.\n");
     238            file->freeLevel = extLevel;
     239        }
     240    }
     241    adjustLevels(file, format);
     242
    233243
    234244    // add argument-supplied OUTPUT name to this file
    235245    char *outname = psMetadataLookupStr(&status, config->arguments, "OUTPUT");
    236     psMetadataAddStr (file->names, PS_LIST_TAIL, "OUTPUT", PS_META_NO_REPLACE, "", outname);
     246    psMetadataAddStr(file->names, PS_LIST_TAIL, "OUTPUT", PS_META_NO_REPLACE, "", outname);
    237247
    238248    // place the resulting file in the config system
     
    241251    return (file); // the returned value is a view into the version on 'files'
    242252}
     253
    243254
    244255// search for argname on the config->argument list
  • trunk/psModules/src/camera/pmFPAfileFitsIO.c

    r10081 r11255  
    1616#include "pmFPAfile.h"
    1717#include "pmFPAfileFitsIO.h"
     18#include "pmFPACopy.h"
     19
     20pmFPA *pmFPAfileSuitableFPA(const pmFPAfile *file, const pmFPAview *view)
     21{
     22    PS_ASSERT_PTR_NON_NULL(file, NULL);
     23    PS_ASSERT_PTR_NON_NULL(view, NULL);
     24
     25    if (!file->format) {
     26        return psMemIncrRefCounter(file->fpa);
     27    }
     28
     29    // Need to change format
     30    pmFPA *fpa = pmFPAConstruct(file->camera);
     31
     32    pmFPAview *phuView = pmFPAviewAlloc(0); // View corresponding to the PHU
     33    *phuView = *view;               // Copy contents
     34    pmFPALevel phuLevel = pmFPAPHULevel(file->format); // Level for the PHU
     35    switch (phuLevel) {
     36    case PM_FPA_LEVEL_FPA:
     37        phuView->chip = -1;
     38        // Flow through
     39    case PM_FPA_LEVEL_CHIP:
     40        phuView->cell = -1;
     41        // Flow through
     42    case PM_FPA_LEVEL_CELL:
     43        phuView->readout = -1;
     44        break;
     45    case PM_FPA_LEVEL_READOUT:
     46    case PM_FPA_LEVEL_NONE:
     47    default:
     48        psAbort(PS_FILE_LINE, "Should never get here: bad phu level.\n");
     49    }
     50
     51    if (!pmFPAAddSourceFromView(fpa, phuView, file->format)) {
     52        psError(PS_ERR_UNKNOWN, false, "Unable to insert HDU into FPA for writing.\n");
     53        psFree(fpa);
     54        psFree(phuView);
     55        return false;
     56    }
     57    psFree(phuView);
     58
     59
     60    switch (phuLevel) {
     61    case PM_FPA_LEVEL_FPA:
     62        if (!pmFPACopy(fpa, file->fpa)) {
     63            psError(PS_ERR_UNKNOWN, false, "Unable to copy FPA for format conversion.\n");
     64            return NULL;
     65        }
     66        return fpa;
     67    case PM_FPA_LEVEL_CHIP: {
     68            pmChip *chip = pmFPAviewThisChip(view, fpa); // Chip of interest
     69            pmChip *srcChip = pmFPAviewThisChip(view, file->fpa); // Source chip
     70            if (!pmChipCopy(chip, srcChip)) {
     71                psError(PS_ERR_UNKNOWN, false, "Unable to copy chip for format conversion.\n");
     72                return false;
     73            }
     74            return fpa;
     75        }
     76    case PM_FPA_LEVEL_CELL: {
     77            pmCell *cell = pmFPAviewThisCell(view, fpa); // Cell of interest
     78            pmCell *srcCell = pmFPAviewThisCell(view, file->fpa); // Source cell
     79            if (!pmCellCopy(cell, srcCell)) {
     80                psError(PS_ERR_UNKNOWN, false, "Unable to copy cell for format conversion.\n");
     81                return false;
     82            }
     83            return fpa;
     84        }
     85    case PM_FPA_LEVEL_READOUT:
     86    case PM_FPA_LEVEL_NONE:
     87    default:
     88        psAbort(PS_FILE_LINE, "Should never get here: bad phu level.\n");
     89    }
     90    return NULL;
     91}
    1892
    1993// given an already-opened fits file, read the table corresponding to the specified view
     
    159233    assert(file);
    160234
    161     pmFPA *fpa = file->fpa;             // FPA of interest
    162235    psFits *fits = file->fits;          // FITS file
    163 
    164     // pmFPAWrite takes care of all PHUs as needed
    165     if (view->chip == -1) {
    166         return fpaWriteFunc(fpa, fits, NULL, false, true);
    167     }
    168 
    169     if (view->chip >= fpa->chips->n) {
    170         psError(PS_ERR_IO, true, "Requested chip == %d >= fpa->chips->n == %ld", view->chip, fpa->chips->n);
    171         return false;
    172     }
    173     pmChip *chip = fpa->chips->data[view->chip]; // Chip of interest
    174 
    175     if (view->cell == -1) {
    176         return chipWriteFunc(chip, fits, NULL, false, true);
    177     }
    178 
    179     if (view->cell >= chip->cells->n) {
    180         psError(PS_ERR_IO, true, "Requested cell == %d >= chip->cells->n == %ld", view->cell, chip->cells->n);
    181         return false;
    182     }
    183     pmCell *cell = chip->cells->data[view->cell]; // Cell of interest
    184 
    185     if (view->readout == -1) {
    186         return cellWriteFunc(cell, fits, NULL, false);
    187     }
    188     psError(PS_ERR_UNKNOWN, true, "Bad view: %d,%d", view->chip, view->cell);
     236    PS_ASSERT_PTR_NON_NULL(fits, false);
     237
     238    pmFPA *fpa = pmFPAfileSuitableFPA(file, view); // FPA to write
     239
     240    switch (pmFPAviewLevel(view)) {
     241    case PM_FPA_LEVEL_FPA: {
     242            bool success = fpaWriteFunc(fpa, fits, NULL, false, true);
     243            psFree(fpa);
     244            return success;
     245        }
     246    case PM_FPA_LEVEL_CHIP: {
     247            pmChip *chip = pmFPAviewThisChip(view, fpa); // Chip of interest
     248            bool success = chipWriteFunc(chip, fits, NULL, false, true);
     249            psFree(fpa);
     250            return success;
     251        }
     252    case PM_FPA_LEVEL_CELL: {
     253            pmCell *cell = pmFPAviewThisCell(view, fpa); // Cell of interest
     254            bool success = cellWriteFunc(cell, fits, NULL, false);
     255            psFree(fpa);
     256            return success;
     257        }
     258    case PM_FPA_LEVEL_READOUT:
     259        #if 0 // XXX disable readout write for now
     260
     261        {
     262            pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); // Readout of interest
     263            if (changeFormat)
     264        {
     265            // No copy function defined for readouts!
     266            psError(PS_ERR_UNKNOWN, false, "Unable to copy readout for format conversion on write.\n");
     267                return false;
     268            }
     269            if (view->nRows == 0)
     270        {
     271            return pmReadoutWrite(readout, fits, NULL, NULL);
     272            } else
     273            {
     274                return pmReadoutWriteSegment(readout, fits, view->nRows, view->iRows, NULL, NULL);
     275            }
     276        }
     277        #endif
     278    case PM_FPA_LEVEL_NONE:
     279    default:
     280        psAbort(PS_FILE_LINE, "Should never reach here: invalid file level.");
     281    }
     282
    189283    return false;
    190 
    191     // XXX disable readout write for now
    192     #if 0
    193 
    194     if (view->readout >= cell->readouts->n) {
    195         psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouts->n == %d",
    196                 view->readout, cell->readouts->n);
    197         return false;
    198     }
    199     pmReadout *readout = cell->readouts->data[view->readout];
    200 
    201     if (view->nRows == 0) {
    202         pmReadoutWrite (readout, fits, NULL, NULL);
    203     } else {
    204         pmReadoutWriteSegment (readout, fits, view->nRows, view->iRows, NULL, NULL);
    205     }
    206     return true;
    207     #endif
    208284}
    209285
  • trunk/psModules/src/camera/pmFPAfileFitsIO.h

    r11253 r11255  
    55 * @author PAP, IfA
    66 *
    7  * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    8  * @date $Date: 2007-01-24 02:54:14 $
     7 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     8 * @date $Date: 2007-01-24 03:11:19 $
    99 * Copyright 2004-2005 Institute for Astronomy, University of Hawaii
    1010 */
     
    6161                             const char *name ///< Name of table
    6262                            );
     63
     64/// Produce a suitable FPA for writing, on the basis of the input FPAfile
     65///
     66/// A format change is done is required.  Otherwise the file->fpa is returned (incremented).
     67pmFPA *pmFPAfileSuitableFPA(const pmFPAfile *file,///< File containing the fpa
     68                            const pmFPAview *view ///< View at which to produce the fpa
     69                           );
     70
    6371/// @}
     72
    6473# endif
  • trunk/psModules/src/camera/pmFPAfileIO.c

    r11242 r11255  
    108108    }
    109109    if (file->mode == PM_FPA_MODE_WRITE) {
     110        // Want to write out any potential blank
     111        pmFPA *fpa = pmFPAfileSuitableFPA(file, view);
     112
    110113        switch (file->fileLevel) {
    111114        case PM_FPA_LEVEL_FPA:
    112             pmFPAWrite (file->fpa, file->fits, NULL, true, false);
     115            pmFPAWrite(fpa, file->fits, NULL, true, false);
    113116            break;
    114117        case PM_FPA_LEVEL_CHIP: {
    115                 pmChip *chip = pmFPAviewThisChip(view, file->fpa);
    116                 pmChipWrite (chip, file->fits, NULL, true, false);
     118                pmChip *chip = pmFPAviewThisChip(view, fpa);
     119                pmChipWrite(chip, file->fits, NULL, true, false);
    117120                break;
    118121            }
    119122        case PM_FPA_LEVEL_CELL: {
    120                 pmCell *cell = pmFPAviewThisCell(view, file->fpa);
     123                pmCell *cell = pmFPAviewThisCell(view, fpa);
    121124                pmCellWrite(cell, file->fits, NULL, true);
    122125                break;
     
    126129            break;
    127130        }
     131
     132        psFree(fpa);
    128133    }
    129134
     
    152157        return true;
    153158    }
     159
     160    #if 0
     161    // do we need to open this file?
     162    if (level != file->fileLevel) {
     163        psTrace("psModules.camera", 6, "skip open of %s at this level %s: fileLevel is %s",
     164                file->name, pmFPALevelToName(level), pmFPALevelToName(file->fileLevel));
     165        return true;
     166    }
     167    #endif
    154168
    155169    if (file->mode == PM_FPA_MODE_NONE) {
     
    755769        switch (place) {
    756770        case PM_FPA_BEFORE:
     771            #if 0
     772
     773            if (!pmFPAfileOpen(file, view, config)) {
     774                psError(PS_ERR_IO, false, "failed OPEN in FPA_BEFORE block for %s", file->name);
     775                goto failure;
     776            }
     777            #endif
    757778            if (!pmFPAfileRead (file, view, config)) {
    758779                psError(PS_ERR_IO, false, "failed READ in FPA_BEFORE block for %s", file->name);
Note: See TracChangeset for help on using the changeset viewer.