IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 11, 2015, 7:38:53 PM (11 years ago)
Author:
eugene
Message:

add checkFileruleFileSave to use the value of FILERULE:FILE.SAVE to set i/o option; set the warp-to-chip map info

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppSub/src/ppSubDefineOutput.c

    r31435 r37966  
    2222#include "ppSub.h"
    2323
     24bool ppSubCopyWarpToChip (psMetadata *tgtHeader, psMetadata *srcHeader);
     25
    2426bool ppSubDefineOutput(const char *name, pmConfig *config)
    2527{
    2628    psAssert(name, "Require name");
    2729    psAssert(config, "Require configuration");
     30
     31    bool status = false;
    2832
    2933    pmFPAview *view = ppSubViewReadout(); // View to readout
     
    4448
    4549    // Convolved input images
    46     psMetadata *recipe = psMetadataLookupPtr(NULL, config->recipes, PPSUB_RECIPE);
    47     bool noConvolve = psMetadataLookupBool(NULL, recipe, "NOCONVOLVE"); // Do not use convolved images.
     50    psMetadata *recipe = psMetadataLookupPtr(&status, config->recipes, PPSUB_RECIPE);
     51    bool noConvolve = psMetadataLookupBool(&status, recipe, "NOCONVOLVE"); // Do not use convolved images.
     52    bool reverse = psMetadataLookupBool(&status, config->arguments, "REVERSE"); // Reverse sense of subtraction?
     53    bool mapFromPositive = psMetadataLookupBool(&status, config->arguments, "CHIP.MAP.FROM.POSITIVE");
     54    // mapFromPositive = true means "always grab the warp->chip map from the positive image (eg, A for A - B, B for B - A)
     55    // mapFromPositive = false means "always grab the warp->chip map from the first image (eg, PPSUB.INPUT if not 'reverse')
    4856
    4957    pmReadout *inConv;
    5058    if (noConvolve) {
    5159      inConv = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT"); // Input readout
    52     }
    53     else {
     60    } else {
    5461      inConv = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT.CONV"); // Input readout
    5562    }
     
    5764    if (noConvolve) {
    5865      refConv = pmFPAfileThisReadout(config->files, view, "PPSUB.REF"); // Reference readout
    59     }
    60     else {
     66    } else {
    6167      refConv = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV"); // Reference readout
    6268    }
    63     psFree(view);
    6469
    6570    // Add kernel descrption to header.
     
    7883        psError(PPSUB_ERR_UNKNOWN, true, "Unable to find SUBTRACTION.KERNEL");
    7984        psFree(outRO);
     85        psFree(view);
    8086        return false;
    8187    }
     
    8591    }
    8692    outHDU->header = psMetadataCopy(outHDU->header, hdu->header);
     93
     94    // in warp-stack mode, we should always use the warp
     95    // in warp-warp mode, we should use the positive warp for the positive subtraction
     96
     97    bool normalDiff = true;
     98    if (!strcmp (name, "PPSUB.INVERSE"))  {
     99      normalDiff = false;
     100    }
     101
     102    if (reverse) {
     103      // normal  = PPSUB.REF - PPSUB.INPUT
     104      // inverse = PPSUB.INPUT - PPSUB.REF
     105      if (mapFromPositive) {
     106        pmCell *cell_Pos = normalDiff ? pmFPAfileThisCell(config->files, view, "PPSUB.REF") : pmFPAfileThisCell(config->files, view, "PPSUB.INPUT");
     107        pmHDU *hdu_Pos = pmHDUFromCell(cell_Pos);
     108        ppSubCopyWarpToChip (outHDU->header, hdu_Pos->header);
     109      } else {
     110        pmCell *cell_Pos = pmFPAfileThisCell(config->files, view, "PPSUB.REF");
     111        pmHDU *hdu_Pos = pmHDUFromCell(cell_Pos);
     112        ppSubCopyWarpToChip (outHDU->header, hdu_Pos->header);
     113      }
     114    } else {
     115      // normal  = PPSUB.INPUT - PPSUB.REF
     116      // inverse = PPSUB.REF - PPSUB.INPUT
     117      if (mapFromPositive) {
     118        pmCell *cell_Pos = normalDiff ? pmFPAfileThisCell(config->files, view, "PPSUB.INPUT") : pmFPAfileThisCell(config->files, view, "PPSUB.REF");
     119        pmHDU *hdu_Pos = pmHDUFromCell(cell_Pos);
     120        ppSubCopyWarpToChip (outHDU->header, hdu_Pos->header);
     121      } else {
     122        pmCell *cell_Pos = pmFPAfileThisCell(config->files, view, "PPSUB.INPUT");
     123        pmHDU *hdu_Pos = pmHDUFromCell(cell_Pos);
     124        ppSubCopyWarpToChip (outHDU->header, hdu_Pos->header);
     125      }
     126    }
    87127
    88128    // Add additional data to the header
     
    104144
    105145    psFree(outRO);
     146    psFree(view);
    106147
    107148    return true;
    108149}
     150
     151// we have 4 sets of header keywords to copy:
     152// SRC_nnnn, SEC_nnnn, MPX_nnnn, MPY_nnnn
     153
     154bool ppSubCopyWarpToChip (psMetadata *tgtHeader, psMetadata *srcHeader) {
     155
     156  char keyword[80];
     157
     158  bool status = false;
     159
     160  int Nchip = 0;
     161  while (true) {
     162    snprintf (keyword, 80, "SRC_%04d", Nchip);
     163    char *string = psMetadataLookupStr (&status, srcHeader, keyword);
     164    if (!status) {
     165      break;
     166    }
     167    psMetadataAddStr(tgtHeader, PS_LIST_TAIL, keyword, PS_META_REPLACE, "input image", string);
     168    Nchip ++;
     169  }
     170   
     171  for (int i = 0; i < Nchip; i++) {
     172    snprintf (keyword, 80, "SEC_%04d", i);
     173    char *string = psMetadataLookupStr (&status, srcHeader, keyword);
     174    if (!status) {
     175      psWarning ("cannot find keyword %s\n", keyword);
     176      continue;
     177    }
     178    psMetadataAddStr(tgtHeader, PS_LIST_TAIL, keyword, PS_META_REPLACE, "input image", string);
     179  }
     180
     181  for (int i = 0; i < Nchip; i++) {
     182    snprintf (keyword, 80, "MPX_%04d", i);
     183    char *string = psMetadataLookupStr (&status, srcHeader, keyword);
     184    if (!status) {
     185      psWarning ("cannot find keyword %s\n", keyword);
     186      continue;
     187    }
     188    psMetadataAddStr(tgtHeader, PS_LIST_TAIL, keyword, PS_META_REPLACE, "input image", string);
     189  }
     190
     191  for (int i = 0; i < Nchip; i++) {
     192    snprintf (keyword, 80, "MPY_%04d", i);
     193    char *string = psMetadataLookupStr (&status, srcHeader, keyword);
     194    if (!status) {
     195      psWarning ("cannot find keyword %s\n", keyword);
     196      continue;
     197    }
     198    psMetadataAddStr(tgtHeader, PS_LIST_TAIL, keyword, PS_META_REPLACE, "input image", string);
     199  }
     200  return true;
     201}
     202
     203bool ppSubCopyWarpToChip_Alt (psMetadata *tgtHeader, psMetadata *srcHeader, bool isPositive) {
     204
     205  char srcKeyword[80], tgtKeyword[80];
     206
     207  bool status = false;
     208
     209  int Nchip = 0;
     210  while (true) {
     211    snprintf (srcKeyword, 80, "SRC_%04d", Nchip);
     212    if (isPositive) {
     213      snprintf (tgtKeyword, 80, "SRCP_%03d", Nchip);
     214    } else {
     215      snprintf (tgtKeyword, 80, "SRCM_%03d", Nchip);
     216    }
     217
     218    char *string = psMetadataLookupStr (&status, srcHeader, srcKeyword);
     219    if (!status) {
     220      break;
     221    }
     222    psMetadataAddStr(tgtHeader, PS_LIST_TAIL, srcKeyword, PS_META_REPLACE, "input image", string);
     223    Nchip ++;
     224  }
     225   
     226  for (int i = 0; i < Nchip; i++) {
     227    snprintf (srcKeyword, 80, "SEC_%04d", i);
     228    if (isPositive) {
     229      snprintf (tgtKeyword, 80, "SECP_%03d", Nchip);
     230    } else {
     231      snprintf (tgtKeyword, 80, "SECM_%03d", Nchip);
     232    }
     233
     234    char *string = psMetadataLookupStr (&status, srcHeader, srcKeyword);
     235    if (!status) {
     236      psWarning ("cannot find keyword %s\n", srcKeyword);
     237      continue;
     238    }
     239    psMetadataAddStr(tgtHeader, PS_LIST_TAIL, srcKeyword, PS_META_REPLACE, "input image", string);
     240  }
     241
     242  for (int i = 0; i < Nchip; i++) {
     243    snprintf (srcKeyword, 80, "MPX_%04d", i);
     244    if (isPositive) {
     245      snprintf (tgtKeyword, 80, "MPXP_%03d", Nchip);
     246    } else {
     247      snprintf (tgtKeyword, 80, "MPXM_%03d", Nchip);
     248    }
     249
     250    char *string = psMetadataLookupStr (&status, srcHeader, srcKeyword);
     251    if (!status) {
     252      psWarning ("cannot find keyword %s\n", srcKeyword);
     253      continue;
     254    }
     255    psMetadataAddStr(tgtHeader, PS_LIST_TAIL, srcKeyword, PS_META_REPLACE, "input image", string);
     256  }
     257
     258  for (int i = 0; i < Nchip; i++) {
     259    snprintf (srcKeyword, 80, "MPY_%04d", i);
     260    if (isPositive) {
     261      snprintf (tgtKeyword, 80, "MPYP_%03d", Nchip);
     262    } else {
     263      snprintf (tgtKeyword, 80, "MPYM_%03d", Nchip);
     264    }
     265
     266    char *string = psMetadataLookupStr (&status, srcHeader, srcKeyword);
     267    if (!status) {
     268      psWarning ("cannot find keyword %s\n", srcKeyword);
     269      continue;
     270    }
     271    psMetadataAddStr(tgtHeader, PS_LIST_TAIL, srcKeyword, PS_META_REPLACE, "input image", string);
     272  }
     273  return true;
     274}
     275
Note: See TracChangeset for help on using the changeset viewer.