IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16186


Ignore:
Timestamp:
Jan 22, 2008, 5:10:51 PM (18 years ago)
Author:
Paul Price
Message:

Merging pap_branch_080117 into the mainline.

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

Legend:

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

    r15929 r16186  
    7474  file->fits = NULL;
    7575  file->compression = NULL;
    76   file->bitpix = 0;
    77   file->floatType = PS_FITS_FLOAT_NONE;
     76  file->options = NULL;
    7877  file->names = psMetadataAlloc();
    7978
     
    192191      char *name = psMetadataLookupStr (NULL, chip->concepts, "CHIP.NAME");
    193192      if (name != NULL) {
    194         psStringSubstitute(&newName, name, "{CHIP.NAME}");
     193        psStringSubstitute(&newName, name, "{CHIP.NAME}");
    195194      }
    196195    }
     
    201200      char *name = psMetadataLookupStr (NULL, chip->concepts, "CHIP.ID");
    202201      if (name != NULL) {
    203         psStringSubstitute(&newName, name, "{CHIP.ID}");
     202        psStringSubstitute(&newName, name, "{CHIP.ID}");
    204203      }
    205204    }
     
    220219      char *name = psMetadataLookupStr (NULL, cell->concepts, "CELL.NAME");
    221220      if (name != NULL) {
    222         psStringSubstitute(&newName, name, "{CELL.NAME}");
     221        psStringSubstitute(&newName, name, "{CELL.NAME}");
    223222      }
    224223    }
     
    243242      char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.FILTER");
    244243      if (name && *name) {
    245         psStringSubstitute(&newName, name, "{FILTER}");
     244        psStringSubstitute(&newName, name, "{FILTER}");
    246245      }
    247246    }
     
    251250      char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.FILTERID");
    252251      if (name && *name) {
    253         psStringSubstitute(&newName, name, "{FILTER.ID}");
     252        psStringSubstitute(&newName, name, "{FILTER.ID}");
    254253      }
    255254    }
     
    259258      char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.INSTRUMENT");
    260259      if (name && *name) {
    261         psStringSubstitute(&newName, name, "{CAMERA}");
     260        psStringSubstitute(&newName, name, "{CAMERA}");
    262261      }
    263262    }
     
    267266      char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.INSTRUMENT");
    268267      if (name && *name) {
    269         psStringSubstitute(&newName, name, "{INSTRUMENT}");
     268        psStringSubstitute(&newName, name, "{INSTRUMENT}");
    270269      }
    271270    }
     
    275274      char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.DETECTOR");
    276275      if (name && *name) {
    277         psStringSubstitute(&newName, name, "{DETECTOR}");
     276        psStringSubstitute(&newName, name, "{DETECTOR}");
    278277      }
    279278    }
     
    283282      char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.TELESCOPE");
    284283      if (name && *name) {
    285         psStringSubstitute(&newName, name, "{TELESCOPE}");
     284        psStringSubstitute(&newName, name, "{TELESCOPE}");
    286285      }
    287286    }
     
    340339  if (view->cell >= inChip->cells->n) {
    341340    psError(PS_ERR_IO, true, "Requested cell == %d>= inChip->cells->n == %ld",
    342             view->cell, inChip->cells->n);
     341            view->cell, inChip->cells->n);
    343342    return false;
    344343  }
     
    387386  if (view->cell >= inChip->cells->n) {
    388387    psError(PS_ERR_IO, true, "Requested cell == %d>= inChip->cells->n == %ld",
    389             view->cell, inChip->cells->n);
     388            view->cell, inChip->cells->n);
    390389    return false;
    391390  }
  • trunk/psModules/src/camera/pmFPAfile.h

    r15930 r16186  
    44 * @author EAM, IfA
    55 *
    6  * @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
    7  * @date $Date: 2007-12-27 02:07:16 $
     6 * @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
     7 * @date $Date: 2008-01-23 03:10:51 $
    88 * Copyright 2004-2005 Institute for Astronomy, University of Hawaii
    99 */
     
    6565    psFits *fits;                       // for I/O files of fits type (IMAGE, CMP, CMF) we carry a file handle
    6666    psFitsCompression *compression;     // Compression for FITS images
    67     int bitpix;                         // Bits per pixel for output
    68     psFitsFloat floatType;              // Custom floating-point
     67    psFitsOptions *options;             // FITS I/O options
    6968
    7069    bool wrote_phu;                     // have we written a PHU for this file?
  • trunk/psModules/src/camera/pmFPAfileDefine.c

    r15946 r16186  
    3535    }
    3636    int value = psMetadataItemParseS32(item); // Value of interst
     37    return value;
     38}
     39
     40// Parse an option from a metadata, returning the appropriate float value
     41static float parseOptionFloat(const psMetadata *md, // Metadata containing the option
     42                              const char *name, // Option name
     43                              const char *source // Description of source, for warning messages
     44                              )
     45{
     46    psMetadataItem *item = psMetadataLookup(md, name); // Item with the value of interest
     47    if (!item) {
     48        psWarning("Unable to find value for %s in %s", name, source);
     49        return NAN;
     50    }
     51    int value = psMetadataItemParseF32(item); // Value of interst
     52    return value;
     53}
     54
     55// Parse an option from a metadata, returning the appropriate double value
     56static double parseOptionDouble(const psMetadata *md, // Metadata containing the option
     57                                const char *name, // Option name
     58                                const char *source // Description of source, for warning messages
     59                                )
     60{
     61    psMetadataItem *item = psMetadataLookup(md, name); // Item with the value of interest
     62    if (!item) {
     63        psWarning("Unable to find value for %s in %s", name, source);
     64        return NAN;
     65    }
     66    int value = psMetadataItemParseF64(item); // Value of interst
    3767    return value;
    3868}
     
    212242        psMetadata *fitsTypes = psMetadataLookupMetadata(&status, camera, "FITS"); // The FITS schemes
    213243        if (!fitsTypes) {
    214             psWarning("Unable to find FITS in camera configuration --- compression disabled.");
    215             goto COMPRESSION_DONE;
     244            psWarning("Unable to find FITS in camera configuration.");
     245            goto FITS_OPTIONS_DONE;
    216246        }
    217247        psMetadata *scheme = psMetadataLookupMetadata(NULL, fitsTypes, fitsType); // FITS scheme
    218248        if (!scheme) {
    219             psWarning("Unable to find %s in FITS in camera configuration --- compression disabled.",
    220                       fitsType);
    221             goto COMPRESSION_DONE;
    222         }
    223         const char *typeString = psMetadataLookupStr(NULL, scheme, "COMP"); // Compression type
    224         if (!typeString || strlen(typeString) == 0) {
    225             psWarning("Can't find COMP in FITS scheme %s --- compression disabled.", fitsType);
    226             goto COMPRESSION_DONE;
    227         }
    228         psFitsCompressionType type = psFitsCompressionTypeFromString(typeString); // Compression type enum
    229 
    230         psString source = NULL;         // Source of options
     249            psWarning("Unable to find %s in FITS in camera configuration --- will use defaults.", fitsType);
     250            goto FITS_OPTIONS_DONE;
     251        }
     252
     253        psString source = NULL;     // Source of options
    231254        psStringAppend(&source, "%s in FITS in camera %s", fitsType, cameraName);
    232         file->bitpix = parseOptionInt(scheme, "BITPIX", source, 0); // Bits per pixel
     255
     256        psFitsOptions *options = file->options = psFitsOptionsAlloc(); // FITS I/O options
    233257
    234258        // Custom floating-point
    235         const char *floatName = psMetadataLookupStr(NULL, scheme, "FLOAT"); // Name of custom floating-point
     259        const char *floatName = psMetadataLookupStr(NULL, scheme, "FLOAT"); // Name of custom float
    236260        if (floatName) {
    237261            psString fullName = NULL;   // Full name of custom floating-point
    238262            psStringAppend(&fullName, "FLOAT_%s", floatName);
    239             file->floatType = psFitsFloatTypeFromString(fullName);
     263            options->floatType = psFitsFloatTypeFromString(fullName);
    240264            psFree(fullName);
    241265        }
    242266
    243         psVector *tile = psVectorAlloc(3, PS_TYPE_S32); // Tile sizes
    244         tile->data.S32[0] = parseOptionInt(scheme, "TILE.X", source, 0); // Tiling in x
    245         tile->data.S32[1] = parseOptionInt(scheme, "TILE.Y", source, 1); // Tiling in y
    246         tile->data.S32[2] = parseOptionInt(scheme, "TILE.Z", source, 1); // Tiling in z
    247         int noise = parseOptionInt(scheme, "NOISE", source, 16); // Noise bits
    248         int hscale = parseOptionInt(scheme, "HSCALE", source, 0); // Scaling for HCOMPRESS
    249         int hsmooth = parseOptionInt(scheme, "HSMOOTH", source, 0); // Smoothing for HCOMPRESS
     267        options->bitpix = parseOptionInt(scheme, "BITPIX", source, 0); // Bits per pixel
     268
     269        // Scaling options
     270        bool mdok;                  // Status of MD lookup
     271        const char *scalingString = psMetadataLookupStr(&mdok, scheme, "SCALING"); // Scaling name
     272        if (scalingString) {
     273            options->scaling = psFitsScalingFromString(scalingString); // Scaling method
     274
     275            switch (options->scaling) {
     276              case PS_FITS_SCALE_NONE:
     277              case PS_FITS_SCALE_RANGE:
     278                // No options required
     279                break;
     280              case PS_FITS_SCALE_STDEV_POSITIVE:
     281              case PS_FITS_SCALE_STDEV_NEGATIVE:
     282                options->stdevNum = parseOptionFloat(scheme, "STDEV.NUM", source); // Padding to edge
     283                if (!isfinite(options->stdevNum)) {
     284                    psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Bad value for STDEV.NUM for %s", source);
     285                    psFree(source);
     286                    psFree(file);
     287                    return NULL;
     288                }
     289                // Flow through
     290              case PS_FITS_SCALE_STDEV_BOTH:
     291                options->stdevBits = parseOptionInt(scheme, "STDEV.BITS", source, 0); // Bits for stdev
     292                if (options->stdevBits <= 0) {
     293                    psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Bad value for STDEV.BITS (%d) for %s",
     294                            options->stdevBits, source);
     295                    psFree(source);
     296                    psFree(file);
     297                    return NULL;
     298                }
     299                break;
     300              case PS_FITS_SCALE_MANUAL:
     301                options->bscale = parseOptionDouble(scheme, "BSCALE", source); // Scaling
     302                options->bzero = parseOptionDouble(scheme, "BZERO", source); // Zero point
     303                break;
     304              default:
     305                psAbort("Should never get here.");
     306            }
     307        }
     308
     309        // Compression options
     310        const char *compressString = psMetadataLookupStr(NULL, scheme, "COMPRESSION"); // Compression type
     311        if (compressString) {
     312            psFitsCompressionType type = psFitsCompressionTypeFromString(compressString); // Compression
     313            psVector *tile = psVectorAlloc(3, PS_TYPE_S32); // Tile sizes
     314            tile->data.S32[0] = parseOptionInt(scheme, "TILE.X", source, 0); // Tiling in x
     315            tile->data.S32[1] = parseOptionInt(scheme, "TILE.Y", source, 1); // Tiling in y
     316            tile->data.S32[2] = parseOptionInt(scheme, "TILE.Z", source, 1); // Tiling in z
     317            int noise = parseOptionInt(scheme, "NOISE", source, 16); // Noise bits
     318            int hscale = 0, hsmooth = 0;// Scaling and smoothing for HCOMPRESS
     319            if (type == PS_FITS_COMPRESS_HCOMPRESS) {
     320                hscale = parseOptionInt(scheme, "HSCALE", source, 0);
     321                hsmooth = parseOptionInt(scheme, "HSMOOTH", source, 0);
     322            }
     323
     324            file->compression = psFitsCompressionAlloc(type, tile, noise, hscale, hsmooth);
     325            psFree(tile);
     326        }
     327
    250328        psFree(source);
    251 
    252         file->compression = psFitsCompressionAlloc(type, tile, noise, hscale, hsmooth);
    253         psFree(tile);
    254     }
    255 COMPRESSION_DONE:
     329    }
     330 FITS_OPTIONS_DONE:
    256331
    257332    file->fileLevel = pmFPAPHULevel(format);
     
    9711046        }
    9721047        file->detrend = results;
    973         file->fileLevel = pmFPALevelFromName(results->level);
    974         if (file->fileLevel == PM_FPA_LEVEL_NONE) {
     1048        file->fileLevel = pmFPALevelFromName(results->level);
     1049        if (file->fileLevel == PM_FPA_LEVEL_NONE) {
    9751050            psError (PS_ERR_IO, false, "invalid file level for selected detrend data");
    9761051            return NULL;
     
    10211096    // inherit the concepts from the src fpa:
    10221097    pmFPACopyConcepts(file->fpa, file->src);
    1023    
     1098
    10241099    return file;
    10251100}
     
    12331308// pmFPAfile is being used internally.
    12341309pmReadout *pmFPAGenerateReadout(const pmConfig *config, // configuration information
    1235                                 const pmFPAview *view, // select background for this entry
    1236                                 const char *name, // name of internal/external file
    1237                                 const pmFPA *fpa, // use this fpa to generate
    1238                                 const psImageBinning *binning) {
     1310                                const pmFPAview *view, // select background for this entry
     1311                                const char *name, // name of internal/external file
     1312                                const pmFPA *fpa, // use this fpa to generate
     1313                                const psImageBinning *binning) {
    12391314  pmReadout *readout = NULL;
    12401315
     
    12461321    readout = pmFPAfileDefineInternal (config->files, name, binning->nXruff, binning->nYruff, PS_TYPE_F32);
    12471322    return readout;
    1248   } 
     1323  }
    12491324
    12501325  // if the mode is INTERNAL, it has been defined in a previous call.  XXX This seems to require
     
    12531328    readout = file->readout;
    12541329    return readout;
    1255   } 
     1330  }
    12561331
    12571332  // we are using this pmFPAfile as an I/O file: select readout or create
  • trunk/psModules/src/camera/pmFPAfileIO.c

    r15912 r16186  
    685685        psMetadata *menu = psMetadataLookupMetadata(&status, file->camera, "CLASSID"); // Menu of class IDs
    686686        if (!status || !menu) {
    687             psError(PS_ERR_IO, false, "Unable to find CLASSID metadata in camera configuration");
    688             return false;
    689         } 
    690         const char *rule = psMetadataLookupStr(&status, menu, file->detrend->level); // Rule for class_id
    691         if (!status || !rule || strlen(rule) == 0) {
    692             psError(PS_ERR_IO, false, "Unable to find %s in CLASSID in camera configuration", file->detrend->level);
    693             return false;
    694         }
    695         classId = pmFPAfileNameFromRule(rule, file, view);
    696         if (!classId) {
    697             psError(PS_ERR_IO, false, "error converting CLASSID rule to name: %s\n", rule);
    698             return false;
    699         }
     687            psError(PS_ERR_IO, false, "Unable to find CLASSID metadata in camera configuration");
     688            return false;
     689        }
     690        const char *rule = psMetadataLookupStr(&status, menu, file->detrend->level); // Rule for class_id
     691        if (!status || !rule || strlen(rule) == 0) {
     692            psError(PS_ERR_IO, false, "Unable to find %s in CLASSID in camera configuration", file->detrend->level);
     693            return false;
     694        }
     695        classId = pmFPAfileNameFromRule(rule, file, view);
     696        if (!classId) {
     697            psError(PS_ERR_IO, false, "error converting CLASSID rule to name: %s\n", rule);
     698            return false;
     699        }
    700700        psTrace ("psModules.camera", 6, "looking for detrend (%s, %s)\n", file->detrend->detID, classId);
    701701        psFree (file->filename);
     
    751751        }
    752752
    753         // XXX these are probably only needed for WRITE files
     753        // XXX these are probably only needed for WRITE files
    754754        if (file->compression) {
    755755            psTrace("psModules.camera", 7, "Setting compression for %s (%s)\n", file->filename, file->name);
     
    761761        }
    762762
    763         file->fits->floatType = file->floatType;
    764         file->fits->bitpix = file->bitpix;
     763        file->fits->options = psMemIncrRefCounter(file->options);
    765764
    766765        // In some cases, we need to read the PHU after we've opened the file.  This happens for the images
Note: See TracChangeset for help on using the changeset viewer.