IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 8, 2007, 12:30:21 PM (19 years ago)
Author:
Paul Price
Message:

Changes to support automatically generated mosaicked camera configurations. Added pmFPAfileDefineChipMosaic and ...FPAMosaic that define fpa files using the new mosaicked camera configurations. Added mosaicLevel to pmFPAfile to prevent the mosaicked files being written out at too low a level. Changes to concept reads so that all concepts are read as available.

File:
1 edited

Legend:

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

    r10724 r10966  
    3030
    3131// define an input-type pmFPAfile, bind to the optional fpa if supplied
    32 pmFPAfile *pmFPAfileDefineInput(pmConfig *config, pmFPA *fpa, char *name)
     32pmFPAfile *pmFPAfileDefineInput(pmConfig *config, pmFPA *fpa, const char *name)
    3333{
    3434    PS_ASSERT_PTR_NON_NULL(config, NULL);
    3535    PS_ASSERT_PTR_NON_NULL(config->files, NULL);
    3636    PS_ASSERT_PTR_NON_NULL(config->camera, NULL);
    37     PS_ASSERT_PTR_NON_NULL(name, NULL);
    38     PS_ASSERT_INT_POSITIVE(strlen(name), NULL);
     37    PS_ASSERT_STRING_NON_EMPTY(name, NULL);
    3938
    4039    bool status;
     
    5049    // select the name from the FILERULES
    5150    // check for alias name (type == STR, name is aliased name)
    52     char *realname = psMetadataLookupStr (&status, filerules, name);
     51    const char *realname = psMetadataLookupStr (&status, filerules, name);
    5352    if (!realname || strlen(realname) == 0) {
    5453        realname = name;
     
    107106
    108107// define a pmFPAfile, bind to the optional fpa if supplied
    109 pmFPAfile *pmFPAfileDefineOutput(pmConfig *config, pmFPA *fpa, char *name)
     108pmFPAfile *pmFPAfileDefineOutput(pmConfig *config, pmFPA *fpa, const char *name)
    110109{
    111110    PS_ASSERT_PTR_NON_NULL(config, NULL);
    112111    PS_ASSERT_PTR_NON_NULL(config->files, NULL);
    113112    PS_ASSERT_PTR_NON_NULL(config->camera, NULL);
    114     PS_ASSERT_PTR_NON_NULL(name, NULL);
    115     PS_ASSERT_INT_POSITIVE(strlen(name), NULL);
     113    PS_ASSERT_STRING_NON_EMPTY(name, NULL);
    116114
    117115    bool status;
    118     char *type;
    119116
    120117    // select the FILERULES from the camera config
     
    127124    // select the name from the FILERULES
    128125    // check for alias name (type == STR, name is aliased name)
    129     char *realname = psMetadataLookupStr (&status, filerules, name);
     126    const char *realname = psMetadataLookupStr (&status, filerules, name);
    130127    if (!realname || strlen(realname) == 0) {
    131128        realname = name;
     
    148145    file->extxtra  = psMemIncrRefCounter(psMetadataLookupStr (&status, data, "EXTNAME.XTRA"));
    149146
    150     type = psMetadataLookupStr (&status, data, "FILE.TYPE");
     147    const char *type = psMetadataLookupStr (&status, data, "FILE.TYPE");
    151148    file->type = pmFPAfileTypeFromString(type);
    152149    if (file->type == PM_FPA_FILE_NONE) {
     
    188185    }
    189186
     187    #if 0
    190188    // for WRITE type of data, the output format needs to be determined
    191189    // this is only needed if the output file is not identical in structure to the input?
     
    231229        psFree (words);
    232230    }
     231    #endif
    233232
    234233    // add argument-supplied OUTPUT name to this file
     
    248247// save the pmFPAfile on config->files
    249248// return the pmFPAfile (a view to the one saved on config->files)
    250 pmFPAfile *pmFPAfileDefineFromArgs (bool *found, pmConfig *config, char *filename, char *argname)
     249pmFPAfile *pmFPAfileDefineFromArgs (bool *found, pmConfig *config, const char *filename, const char *argname)
    251250{
    252251    PS_ASSERT_PTR_NON_NULL(config, NULL);
    253     PS_ASSERT_PTR_NON_NULL(filename, NULL);
    254     PS_ASSERT_INT_POSITIVE(strlen(filename), NULL);
    255     PS_ASSERT_PTR_NON_NULL(argname, NULL);
    256     PS_ASSERT_INT_POSITIVE(strlen(argname), NULL);
     252    PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
     253    PS_ASSERT_STRING_NON_EMPTY(argname, NULL);
    257254
    258255    bool status;
     
    269266    psArray *infiles = psMetadataLookupPtr(&status, config->arguments, argname);
    270267    if (!status) {
    271         psTrace("psModules.camera", 5, "Failed to find %s in argument list", argname);
     268        //        psTrace("psModules.camera", 5, "Failed to find %s in argument list", argname);
     269        psError(PS_ERR_UNEXPECTED_NULL, false, "Failed to find %s in argument list", argname);
    272270        return NULL;
    273271    }
     
    296294        return NULL;
    297295    }
    298     psFitsClose (fits);
     296    psFitsClose(fits);
    299297
    300298    // determine the current format from the header
     
    417415// save the pmFPAfiles on config->files
    418416// return the pmFPAfiles (a view to the one saved on config->files)
    419 pmFPAfile *pmFPAfileDefineSingleFromArgs (bool *found, pmConfig *config, char *filename, char *argname, int entry)
     417pmFPAfile *pmFPAfileDefineSingleFromArgs (bool *found, pmConfig *config, const char *filename,
     418        const char *argname, int entry)
    420419{
    421420    PS_ASSERT_PTR_NON_NULL(config, NULL);
    422     PS_ASSERT_PTR_NON_NULL(filename, NULL);
    423     PS_ASSERT_INT_POSITIVE(strlen(filename), NULL);
    424     PS_ASSERT_PTR_NON_NULL(argname, NULL);
    425     PS_ASSERT_INT_POSITIVE(strlen(argname), NULL);
     421    PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
     422    PS_ASSERT_STRING_NON_EMPTY(argname, NULL);
    426423
    427424    bool status;
     
    533530// define the named pmFPAfile from the camera->config
    534531// only valid for pmFPAfile->mode = READ
    535 pmFPAfile *pmFPAfileDefineFromConf (bool *found, pmConfig *config, char *filename)
     532pmFPAfile *pmFPAfileDefineFromConf (bool *found, pmConfig *config, const char *filename)
    536533{
    537534    PS_ASSERT_PTR_NON_NULL(config, false);
    538     PS_ASSERT_PTR_NON_NULL(filename, false);
    539     PS_ASSERT_INT_POSITIVE(strlen(filename), false);
     535    PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
    540536
    541537    if (*found) {
     
    603599// save the pmFPAfile on config->files
    604600// return the pmFPAfile (a view to the one saved on config->files)
    605 pmFPAfile *pmFPAfileDefineFromDetDB (bool *found, pmConfig *config, char *filename, pmFPA *input, pmDetrendType type)
     601pmFPAfile *pmFPAfileDefineFromDetDB (bool *found, pmConfig *config, const char *filename,
     602                                     pmFPA *input, pmDetrendType type)
    606603{
    607604    PS_ASSERT_PTR_NON_NULL(input, NULL);
     
    609606    PS_ASSERT_PTR_NON_NULL(config->camera, NULL);
    610607    PS_ASSERT_PTR_NON_NULL(config->files, NULL);
    611     PS_ASSERT_PTR_NON_NULL(filename, NULL);
     608    PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
    612609
    613610    pmFPA *fpa = NULL;
     
    681678// create a new output pmFPAfile based on an existing FPA
    682679// only valid for pmFPAfile->mode == WRITE (or internal?)
    683 pmFPAfile *pmFPAfileDefineFromFPA (pmConfig *config, pmFPA *src, int xBin, int yBin, char *filename)
     680pmFPAfile *pmFPAfileDefineFromFPA (pmConfig *config, pmFPA *src, int xBin, int yBin, const char *filename)
    684681{
    685682    PS_ASSERT_PTR_NON_NULL(config, false);
    686683    PS_ASSERT_PTR_NON_NULL(src, false);
    687     PS_ASSERT_PTR_NON_NULL(filename, false);
    688     PS_ASSERT_INT_POSITIVE(strlen(filename), false);
    689 
    690     pmFPA *fpa = pmFPAConstruct (src->camera);
     684    PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
     685
     686    // Need to look up the format
     687    bool mdok;                          // Status of MD lookup
     688    psMetadata *formats = psMetadataLookupMetadata(&mdok, src->camera, "FORMATS"); // The FORMATS
     689    if (!mdok || !formats) {
     690        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find FORMATS in camera configuration %s.\n",
     691                config->cameraName);
     692        return NULL;
     693    }
     694    psMetadata *format = psMetadataLookupMetadata(&mdok, formats, config->formatName); // The format
     695    if (!mdok || !format) {
     696        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find camera format %s within camera %s.\n",
     697                config->formatName, config->cameraName);
     698        return NULL;
     699    }
     700
     701    pmFPA *fpa = pmFPAConstruct(src->camera);
    691702    pmFPAfile *file = pmFPAfileDefineOutput (config, fpa, filename);
    692703    if (!file) {
     
    697708    file->xBin = xBin;
    698709    file->yBin = yBin;
     710    file->format = psMemIncrRefCounter(format);
    699711
    700712    psFree (fpa);
     
    704716// create a new output pmFPAfile based on an existing FPA
    705717// only valid for pmFPAfile->mode == WRITE (or internal?)
    706 pmFPAfile *pmFPAfileDefineNewCamera (pmConfig *config, char *filename)
     718pmFPAfile *pmFPAfileDefineNewCamera (pmConfig *config, const char *filename)
    707719{
    708720    PS_ASSERT_PTR_NON_NULL(config, false);
    709     PS_ASSERT_PTR_NON_NULL(filename, false);
    710     PS_ASSERT_INT_POSITIVE(strlen(filename), false);
     721    PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
    711722
    712723    pmFPAfile *file = pmFPAfileDefineOutput (config, NULL, filename);
     
    724735}
    725736
     737pmFPAfile *pmFPAfileDefineChipMosaic(pmConfig *config, pmFPA *src, const char *filename)
     738{
     739    PS_ASSERT_PTR_NON_NULL(config, NULL);
     740    PS_ASSERT_PTR_NON_NULL(src, NULL);
     741    PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
     742    PS_ASSERT_STRING_NON_EMPTY(config->cameraName, NULL);
     743    PS_ASSERT_STRING_NON_EMPTY(config->formatName, NULL);
     744
     745    if (config->cameraName[0] == '_' &&
     746            strcmp(config->cameraName + strlen(config->cameraName) - 5, "-CHIP") == 0) {
     747        // The input camera has already been mosaicked to this level
     748        pmFPAfile *file = pmFPAfileDefineOutput(config, NULL, filename);
     749        file->camera = psMemIncrRefCounter(config->camera);
     750        file->format = psMemIncrRefCounter(config->format);
     751        file->fpa = pmFPAConstruct(file->camera);
     752        return file;
     753    }
     754
     755    // Find the correct camera configuration
     756    bool mdok;                          // Status of MD lookup
     757    psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->site, "CAMERAS"); // Camera configurations
     758    if (!mdok || !cameras) {
     759        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the site configuration.\n");
     760        return NULL;
     761    }
     762    psString name = NULL;               // Name of the new (automatically-generated) camera configuration
     763    psStringAppend(&name, "_%s-CHIP", config->cameraName);
     764    psMetadata *camera = psMetadataLookupMetadata(&mdok, cameras, name); // Camera configuration of interest
     765    if (!mdok || !camera) {
     766        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find automatically generated "
     767                "camera configuration %s in site configuration.\n", name);
     768        psFree(name);
     769        return NULL;
     770    }
     771    psFree(name);
     772
     773    // Need to look up the format of the same name, but under the mosaic camera
     774    psMetadata *formats = psMetadataLookupMetadata(&mdok, camera, "FORMATS"); // The FORMATS
     775    if (!mdok || !formats) {
     776        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find FORMATS in camera configuration %s.\n",
     777                config->cameraName);
     778        return NULL;
     779    }
     780    psMetadata *format = psMetadataLookupMetadata(&mdok, formats, config->formatName); // The format
     781    if (!mdok || !format) {
     782        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find camera format %s within camera %s.\n",
     783                config->formatName, config->cameraName);
     784        return NULL;
     785    }
     786
     787    pmFPA *fpa = pmFPAConstruct(camera);
     788    if (!fpa) {
     789        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to generate mosaicked camera.\n");
     790        return NULL;
     791    }
     792    pmFPAfile *file = pmFPAfileDefineOutput(config, fpa, filename);
     793    if (!file) {
     794        psErrorStackPrint(stderr, "file %s not defined\n", filename);
     795        return NULL;
     796    }
     797    file->src = src; // inherit output elements from this source pmFPA
     798    file->mosaicLevel = PM_FPA_LEVEL_CHIP; // don't do any I/O on this at a lower level
     799    file->format = psMemIncrRefCounter(format);
     800
     801    psFree(fpa);
     802
     803    return file;
     804}
     805
     806pmFPAfile *pmFPAfileDefineFPAMosaic(pmConfig *config, pmFPA *src, const char *filename)
     807{
     808    PS_ASSERT_PTR_NON_NULL(config, NULL);
     809    PS_ASSERT_PTR_NON_NULL(src, NULL);
     810    PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
     811    PS_ASSERT_STRING_NON_EMPTY(config->cameraName, NULL);
     812
     813    if (config->cameraName[0] == '_' &&
     814            strcmp(config->cameraName + strlen(config->cameraName) - 4 , "-FPA") == 0) {
     815        // The input camera has already been mosaicked to this level
     816        pmFPAfile *file = pmFPAfileDefineOutput(config, NULL, filename);
     817        file->camera = psMemIncrRefCounter(config->camera);
     818        file->format = psMemIncrRefCounter(config->format);
     819        file->fpa = pmFPAConstruct(file->camera);
     820        return file;
     821    }
     822
     823    // Find the correct camera configuration
     824    bool mdok;                          // Status of MD lookup
     825    psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->site, "CAMERAS"); // Camera configurations
     826    if (!mdok || !cameras) {
     827        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the site configuration.\n");
     828        return NULL;
     829    }
     830    psString original;                  // Name of the original camera configuration
     831    psString name = NULL;               // Name of the new (automatically-generated) camera configuration
     832    if (config->cameraName[0] == '_' &&
     833            strcmp(config->cameraName + strlen(config->cameraName) - 5 , "-CHIP") == 0) {
     834        // It's a chip mosaic; we need to get the original name
     835        original = psStringNCopy(config->cameraName + 1, strlen(config->cameraName) - 6);
     836    } else {
     837        original = psMemIncrRefCounter(config->cameraName);
     838    }
     839    psStringAppend(&name, "_%s-FPA", original);
     840    psFree(original);
     841    psMetadata *camera = psMetadataLookupMetadata(&mdok, cameras, name); // Camera configuration of interest
     842    if (!mdok || !camera) {
     843        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find automatically generated "
     844                "camera configuration %s in site configuration.\n", name);
     845        psFree(name);
     846        return NULL;
     847    }
     848    psFree(name);
     849
     850    // Need to look up the format of the same name, but under the mosaic camera
     851    psMetadata *formats = psMetadataLookupMetadata(&mdok, camera, "FORMATS"); // The FORMATS
     852    if (!mdok || !formats) {
     853        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find FORMATS in camera configuration %s.\n",
     854                config->cameraName);
     855        return NULL;
     856    }
     857    psMetadata *format = psMetadataLookupMetadata(&mdok, formats, config->formatName); // The format
     858    if (!mdok || !format) {
     859        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find camera format %s within camera %s.\n",
     860                config->formatName, config->cameraName);
     861        return NULL;
     862    }
     863
     864    pmFPA *fpa = pmFPAConstruct(camera);
     865    if (!fpa) {
     866        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to generate mosaicked camera.\n");
     867        return NULL;
     868    }
     869    pmFPAfile *file = pmFPAfileDefineOutput(config, fpa, filename);
     870    if (!file) {
     871        psErrorStackPrint(stderr, "file %s not defined\n", filename);
     872        return NULL;
     873    }
     874    file->src = src; // inherit output elements from this source pmFPA
     875    file->mosaicLevel = PM_FPA_LEVEL_FPA; // don't do any I/O on this at a lower level
     876    file->format = psMemIncrRefCounter(format);
     877
     878    psFree(fpa);
     879
     880    return file;
     881}
     882
    726883// create a file with the given name, assign it type "INTERNAL", and supply it with an image
    727884// of the requested dimensions. (image only, mask and weight are ignored)
    728 pmReadout *pmFPAfileDefineInternal (psMetadata *files, char *name, int Nx, int Ny, int type)
     885pmReadout *pmFPAfileDefineInternal (psMetadata *files, const char *name, int Nx, int Ny, int type)
    729886{
    730887    PS_ASSERT_PTR_NON_NULL(files, false);
    731     PS_ASSERT_PTR_NON_NULL(name, false);
    732     PS_ASSERT_INT_POSITIVE(strlen(name), false);
     888    PS_ASSERT_STRING_NON_EMPTY(name, NULL);
    733889
    734890    pmReadout *readout = pmReadoutAlloc(NULL);
     
    748904}
    749905
    750 bool pmFPAfileDropInternal(psMetadata *files, char *name)
     906bool pmFPAfileDropInternal(psMetadata *files, const char *name)
    751907{
    752908    PS_ASSERT_PTR_NON_NULL(files, false);
    753     PS_ASSERT_PTR_NON_NULL(name, false);
    754     PS_ASSERT_INT_POSITIVE(strlen(name), false);
     909    PS_ASSERT_STRING_NON_EMPTY(name, NULL);
    755910
    756911    bool status = false;
Note: See TracChangeset for help on using the changeset viewer.