IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15112


Ignore:
Timestamp:
Sep 29, 2007, 12:01:01 PM (19 years ago)
Author:
Paul Price
Message:

Enabling compression when writing out. Introduces a new field in the FILERULES for output files (COMPRESSION), which provides a keyword which is looked up in COMPRESSION(METADATA) in the camera configuration. That then provides BITPIX,TILE.X,TILE.Y,TILE.Z,NOISE,HSCALE,HSMOOTH to set the compression and bits per pixel. Enabled compression, but not bitpix yet.

Location:
branches/pap_branch_070920/psModules/src/camera
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/pap_branch_070920/psModules/src/camera/pmFPAfile.c

    r14889 r15112  
    4040        psFitsClose (file->fits);
    4141    }
     42    psFree(file->compression);
    4243
    4344    psFree (file->filerule);
     
    7273    file->fpa = NULL;
    7374    file->fits = NULL;
     75    file->compression = NULL;
     76    file->bitpix = 0;
    7477    file->names = psMetadataAlloc();
    7578
  • branches/pap_branch_070920/psModules/src/camera/pmFPAfile.h

    r14889 r15112  
    44 * @author EAM, IfA
    55 *
    6  * @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
    7  * @date $Date: 2007-09-19 21:37:58 $
     6 * @version $Revision: 1.21.2.1 $ $Name: not supported by cvs2svn $
     7 * @date $Date: 2007-09-29 22:01:01 $
    88 * Copyright 2004-2005 Institute for Astronomy, University of Hawaii
    99 */
     
    5151} pmFPAfileState;
    5252
    53 typedef struct
    54 {
     53typedef struct {
    5554    pmFPAfileMode mode;                 // is this file read, written, or only used internally?
    5655    pmFPAfileType type;                 // what type of data is read from / written to disk?
     
    6362
    6463    pmFPA *fpa;                         // for I/O files, we carry a pointer to the complete fpa
    65     psFits *fits;                       // for I/O files of fits type (IMAGE, CMP, CMF), we carry a file handle
     64    psFits *fits;                       // for I/O files of fits type (IMAGE, CMP, CMF) we carry a file handle
     65    psFitsCompression *compression;     // Compression for FITS images
     66    int bitpix;                         // Bits per pixel for output
    6667
    6768    bool wrote_phu;                     // have we written a PHU for this file?
     
    9394    psMetadata *format;                 // Camera format
    9495    psString formatName;                // name of the camera format
    95 }
    96 pmFPAfile;
     96} pmFPAfile;
    9797
    9898// allocate an empty pmFPAfile structure
  • branches/pap_branch_070920/psModules/src/camera/pmFPAfileDefine.c

    r14974 r15112  
    7878}
    7979
     80// Parse an option from a metadata, returning the appropriate integer value
     81static int parseOptionInt(const psMetadata *md, // Metadata containing the option
     82                          const char *name, // Option name
     83                          const char *source, // Description of source, for warning messages
     84                          int defaultValue // Default value
     85                          )
     86{
     87    psMetadataItem *item = psMetadataLookup(md, name); // Item with the value of interest
     88    if (!item) {
     89        psWarning("Unable to find value for %s in %s --- set to %d.", name, source, defaultValue);
     90        return defaultValue;
     91    }
     92    int value = psMetadataItemParseS32(item); // Value of interst
     93    if (value < 0) {
     94        psWarning("Bad value for %s in %s (%d) --- set to %d.", name, source, value, defaultValue);
     95        return defaultValue;
     96    }
     97    return value;
     98}
     99
    80100
    81101// define an input-type pmFPAfile, bind to the optional fpa if supplied
     
    250270        file->fpa = pmFPAConstruct(file->camera);
    251271    }
     272
     273    // Get compression scheme
     274    const char *compName = psMetadataLookupStr(&status, data, "COMPRESSION"); // Name of compression scheme
     275    if (compName && strcasecmp(compName, "NONE") != 0) {
     276        psMetadata *compSchemes = psMetadataLookupMetadata(&status, camera, "COMPRESSION"); // Comp. schemes
     277        if (!compSchemes) {
     278            psWarning("Unable to find COMPRESSION in camera configuration --- compression disabled.");
     279            goto COMPRESSION_DONE;
     280        }
     281        psMetadata *compression = psMetadataLookupMetadata(NULL, compSchemes, compName); // Compression info
     282        if (!compression) {
     283            psWarning("Unable to find %s in COMPRESSION in camera configuration --- compression disabled.",
     284                      compName);
     285            goto COMPRESSION_DONE;
     286        }
     287        const char *typeString = psMetadataLookupStr(NULL, compression, "COMPRESSION"); // Compression type
     288        if (!typeString || strlen(typeString)) {
     289            psWarning("Can't find COMPRESSION in compression scheme %s --- compression disabled.", compName);
     290            goto COMPRESSION_DONE;
     291        }
     292        psFitsCompressionType type = psFitsCompressionTypeFromString(typeString); // Compression type enum
     293
     294        psString source = NULL;         // Source of options
     295        psStringAppend(&source, "%s in COMPRESSION in camera %s", compName, cameraName);
     296        psVector *tile = psVectorAlloc(3, PS_TYPE_S32); // Tile sizes
     297        file->bitpix = parseOptionInt(compression, "BITPIX", source, 0); // Bits per pixel
     298        tile->data.S32[0] = parseOptionInt(compression, "TILE.X", source, 0); // Tiling in x
     299        tile->data.S32[1] = parseOptionInt(compression, "TILE.Y", source, 1); // Tiling in y
     300        tile->data.S32[2] = parseOptionInt(compression, "TILE.Z", source, 1); // Tiling in z
     301        int noise = parseOptionInt(compression, "NOISE", source, 16); // Noise bits
     302        int hscale = parseOptionInt(compression, "HSCALE", source, 0); // Scaling for HCOMPRESS
     303        int hsmooth = parseOptionInt(compression, "HSMOOTH", source, 0); // Smoothing for HCOMPRESS
     304        psFree(source);
     305
     306        file->compression = psFitsCompressionAlloc(type, tile, noise, hscale, hsmooth);
     307        psFree(tile);
     308    }
     309COMPRESSION_DONE:
    252310
    253311    file->fileLevel = pmFPAPHULevel(format);
  • branches/pap_branch_070920/psModules/src/camera/pmFPAfileIO.c

    r14938 r15112  
    688688        }
    689689
    690         // In some cases, we need to read the PHU after we've opened the file.  This happens for
    691         // the images supplied by the detrend database, which are only identified here (pmConfigConvertFilename).
     690        if (file->compression && !psFitsCompressionApply(file->fits, file->compression)) {
     691            psError(PS_ERR_UNKNOWN, false, "Unable to set compression options for %s (%s) (%d:%d:%d)\n",
     692                     file->filename, file->name, view->chip, view->cell, view->readout);
     693            return false;
     694        }
     695
     696        // In some cases, we need to read the PHU after we've opened the file.  This happens for the images
     697        // supplied by the detrend database, which are only identified here (pmConfigConvertFilename).
    692698        if (!pmFPAfileReadPHU (file, view, config)) {
    693             psError (PS_ERR_IO, true, "error reading PHU for %s (%s) (%d:%d:%d)\n", file->filename, file->name, view->chip, view->cell, view->readout);
     699            psError (PS_ERR_IO, true, "error reading PHU for %s (%s) (%d:%d:%d)\n",
     700                     file->filename, file->name, view->chip, view->cell, view->readout);
    694701            return false;
    695702        }
     
    758765            return false;
    759766        }
    760         file->formatName = psStringCopy(config->formatName);
     767        file->formatName = psStringCopy(config->formatName);
    761768
    762769    } else {
     
    795802      case PM_FPA_FILE_WEIGHT:
    796803      case PM_FPA_FILE_FRINGE:
    797         status = pmFPAviewFitsWritePHU (view, file, config);
    798         break;
     804        status = pmFPAviewFitsWritePHU (view, file, config);
     805        break;
    799806      case PM_FPA_FILE_CMF:
    800         status = pmSource_CMF_WritePHU (view, file, config);
    801         break;
     807        status = pmSource_CMF_WritePHU (view, file, config);
     808        break;
    802809      case PM_FPA_FILE_PSF:
    803         status = pmPSFmodelWritePHU (view, file, config);
    804         break;
     810        status = pmPSFmodelWritePHU (view, file, config);
     811        break;
    805812      case PM_FPA_FILE_SX:
    806813      case PM_FPA_FILE_RAW:
Note: See TracChangeset for help on using the changeset viewer.