IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 6, 2012, 6:32:19 PM (14 years ago)
Author:
watersc1
Message:

merge from trunk. Preliminary versions of stacktool/warptool updates and regenerate_background.pl script. The warp code is finished and tested, and I still need to get the stack version resolved.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20120906/ppTranslate/src/ppMopsWrite.c

    r34284 r34772  
    3838
    3939  // Get these header words from the first input non null input
     40  // but for SEEING which is the median of the (non-NULL) detections
     41  // seeings
    4042  ppMopsDetections *det = NULL;
    41   for (int d = 0; d < detections->n && det == NULL; d++) {
    42     det = detections->data[d];
    43   }
     43  for (int d = 0; d < detections->n; d++) {
     44    if (detections->data[d] != NULL) {
     45      if (det == NULL) {
     46        det = detections->data[d];
     47      }
     48    }
     49  }
     50  //Get the SEEING weighted mean. Update the PLTSCALE value
     51  float seeing = 0.;
     52  int totalGood = 0;
     53  for (int d = 0; d < detections->n; d++) {
     54    if ( (detections->data[d] != NULL) && (isfinite(((ppMopsDetections*) detections->data[d])->seeing)) ) {
     55      seeing += ((ppMopsDetections*) detections->data[d])->seeing;
     56      totalGood += 1;
     57      if (isfinite(((ppMopsDetections*) detections->data[d])->platescale)) {
     58          det->platescale = ((ppMopsDetections*) detections->data[d])->platescale;
     59      }
     60    }
     61  }
     62  printf("plate-scale = [%g]\n", det->platescale);
     63  seeing /= (float) totalGood;
    4464  if (det != NULL) {
    4565    psMetadataAddF64(header, PS_LIST_TAIL, "MJD-OBS", 0, "MJD of exposure midpoint", det->mjd);
     
    5272    psMetadataAddStr(header, PS_LIST_TAIL, "FILTER", 0, "Filter name", det->filter);
    5373    psMetadataAddF32(header, PS_LIST_TAIL, "AIRMASS", 0, "Airmass of exposure", det->airmass);
    54     psMetadataAddF32(header, PS_LIST_TAIL, "SEEING", 0, "Mean seeing", det->seeing);
     74    psMetadataAddF32(header, PS_LIST_TAIL, "SEEING", 0, "Mean seeing", seeing);
     75    //MOPS want the name FWHM for SEEING
     76    psMetadataAddF32(header, PS_LIST_TAIL, "FWHM", 0, "Mean seeing", seeing);
    5577  } else {
    5678    psWarning("no inputs with surviving detections. output header will be incomplete");
     
    5880  psMetadataAddStr(header, PS_LIST_TAIL, "OBSCODE", 0, "IAU Observatory code", OBSERVATORY_CODE);
    5981  psMetadataAddF32(header, PS_LIST_TAIL, "MAGZP", 0, "Magnitude zero point", args->zp);
     82  //MOPS want the name ZEROPOINT for MAGZP
     83  psMetadataAddF32(header, PS_LIST_TAIL, "ZEROPOINT", 0, "Magnitude zero point", args->zp);
    6084  psMetadataAddF32(header, PS_LIST_TAIL, "MAGZPERR", 0, "Error in magnitude zero point", args->zpErr);
    6185  psMetadataAddF32(header, PS_LIST_TAIL, "ASTRORMS", 0, "RMS of astrometric fit", args->rmsAstrom);
     86  psMetadataAddStr(header, PS_LIST_TAIL, "CMMTOBS", 0, "Exposure comment", args->comment);
     87  psMetadataAddStr(header, PS_LIST_TAIL, "OBS_MODE", 0, "Exposure observation mode", args->obsMode);
     88  psMetadataAddStr(header, PS_LIST_TAIL, "DIFFTYPE", 0, "WW: Warp-Warp diff / WS: Warp-Stack diff / SW: Stack-Warp diff", args->difftype);
     89  psMetadataAddF32(header, PS_LIST_TAIL, "SKY", 0, "Exposure avg sky background", args->sky);
     90  psMetadataAddStr(header, PS_LIST_TAIL, "SHUTOUTC", 0, "Camera exposure shutter open (UTC)", args->shutoutc);
     91  psMetadataAddF32(header, PS_LIST_TAIL, "PLTSCALE_EXT", 0, "Plate scale at centroid", det->platescale);
     92  psMetadataAddF32(header, PS_LIST_TAIL, "PLTSCALE", 0, "Plate scale at centroid", det->platescale);
    6293
    6394  //field in header that tells about the CMF version
     
    6798
    6899  // Find the total number of detections
    69 
    70100  long total = 0;
    71101  for (long i=0; i<detections->n; i++) {
     
    112142      // Write data of version 2 (see ICD)
    113143      psMetadataAdd (row, PS_LIST_TAIL, "IPP_IDET",         PS_DATA_U32, "IPP detection identifier index",
    114                      NAN);
     144                     NAN);
    115145      psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_FLUX",    PS_DATA_F32, "PSF fit instrumental magnitude",
    116                      NAN);
     146                     NAN);
    117147      psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_FLUX_SIG",PS_DATA_F32, "Sigma of PSF instrumental magnitude",
    118                      NAN);
     148                     NAN);
    119149      psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG",           PS_DATA_F32, "magnitude in standard aperture",
    120                      NAN);
     150                     NAN);
    121151      psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RAW",       PS_DATA_F32, "magnitude in real aperture",
    122                      NAN);
     152                     NAN);
    123153      psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RADIUS",    PS_DATA_F32, "radius used for aperture mags",
    124                      NAN);
     154                     NAN);
    125155      psMetadataAdd (row, PS_LIST_TAIL, "AP_FLUX",          PS_DATA_F32, "instrumental flux in standard aperture",
    126                      NAN);
     156                     NAN);
    127157      psMetadataAdd (row, PS_LIST_TAIL, "AP_FLUX_SIG",      PS_DATA_F32, "aperture flux error",
    128                      NAN);
     158                     NAN);
    129159      psMetadataAdd (row, PS_LIST_TAIL, "PEAK_FLUX_AS_MAG", PS_DATA_F32, "Peak flux expressed as magnitude",
    130                      NAN);
     160                     NAN);
    131161      psMetadataAdd (row, PS_LIST_TAIL, "CAL_PSF_MAG",      PS_DATA_F32, "PSF Magnitude using supplied calibration",
    132                      NAN);
     162                     NAN);
    133163      psMetadataAdd (row, PS_LIST_TAIL, "CAL_PSF_MAG_SIG",  PS_DATA_F32, "measured scatter of zero point calibration",
    134                      NAN);
     164                     NAN);
    135165      psMetadataAdd (row, PS_LIST_TAIL, "SKY",              PS_DATA_F32, "Sky level",
    136                      NAN);
     166                     NAN);
    137167      psMetadataAdd (row, PS_LIST_TAIL, "SKY_SIGMA",        PS_DATA_F32, "Sigma of sky level",
    138                      NAN);
     168                     NAN);
    139169      psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF_PERFECT",   PS_DATA_F32, "PSF coverage/quality factor (poor)",
    140                      NAN);
     170                     NAN);
    141171      psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_R1",       PS_DATA_F32, "first radial moment",
    142                      NAN);
     172                     NAN);
    143173      psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_RH",       PS_DATA_F32, "half radial moment",
    144                      NAN);
     174                     NAN);
    145175      psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX",        PS_DATA_F32, "Kron Flux (in 2.5 R1)",
    146                      NAN);
     176                     NAN);
    147177      psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_ERR",    PS_DATA_F32, "Kron Flux Error",
    148                      NAN);
    149       psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_INNER",  PS_DATA_F32, "Kron Flux (in 1.0 R1)", 
    150                      NAN);
     178                     NAN);
     179      psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_INNER",  PS_DATA_F32, "Kron Flux (in 1.0 R1)",
     180                     NAN);
    151181      psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_OUTER",  PS_DATA_F32, "Kron Flux (in 4.0 R1)",
    152                      NAN);
     182                     NAN);
    153183      psMetadataAdd (row, PS_LIST_TAIL, "DIFF_R_P",         PS_DATA_F32, "distance to positive match source",
    154                      NAN);
     184                     NAN);
    155185      psMetadataAdd (row, PS_LIST_TAIL, "DIFF_SN_P",        PS_DATA_F32, "signal-to-noise of pos match src",
    156                      NAN);
     186                     NAN);
    157187      psMetadataAdd (row, PS_LIST_TAIL, "DIFF_R_M",         PS_DATA_F32, "distance to negative match source",
    158                      NAN);
     188                     NAN);
    159189      psMetadataAdd (row, PS_LIST_TAIL, "DIFF_SN_M",        PS_DATA_F32, "signal-to-noise of neg match src",
    160                      NAN);
     190                     NAN);
    161191      psMetadataAdd (row, PS_LIST_TAIL, "FLAGS2",           PS_DATA_U32, "psphot analysis flags (group 2)",
    162                      0);
    163       psMetadataAdd (row, PS_LIST_TAIL, "N_FRAMES",         PS_DATA_U16, "Number of frames overlapping source center", 
    164                      0);
    165       psMetadataAdd (row, PS_LIST_TAIL, "PADDING",          PS_DATA_S16, "padding", 
    166                      0);
     192                     0);
     193      psMetadataAdd (row, PS_LIST_TAIL, "N_FRAMES",         PS_DATA_U16, "Number of frames overlapping source center",
     194                     0);
     195      psMetadataAdd (row, PS_LIST_TAIL, "PADDING",          PS_DATA_S16, "padding",
     196                     0);
    167197      if (args->version == 3) {
    168         // TODO: Write data of version 3 (see ICD)
     198// Write data of version 3 (see ICD)
     199        psMetadataAdd (row, PS_LIST_TAIL, "RA_EXT",         PS_DATA_F32, "Fitted centroid RA",
     200                       0);
     201        psMetadataAdd (row, PS_LIST_TAIL, "RA_EXT_SIGMA",   PS_DATA_F32, "Fitted RA sigma",
     202                       0);
     203        psMetadataAdd (row, PS_LIST_TAIL, "DEC_EXT",        PS_DATA_F32, "Fitted centroid DEC",
     204                       0);
     205        psMetadataAdd (row, PS_LIST_TAIL, "DEC_EXT_SIGMA",  PS_DATA_F32, "Fitted DEC sigma",
     206                       0);
     207        psMetadataAdd (row, PS_LIST_TAIL, "POSANG_EXT",     PS_DATA_F32, "Fitted position angle",
     208                       0);
     209        psMetadataAdd (row, PS_LIST_TAIL, "EXT_FLUX",       PS_DATA_F32, "Fitted flux",
     210                       0);
     211        psMetadataAdd (row, PS_LIST_TAIL, "EXT_CAL_MAG",    PS_DATA_F32, "Calibrated mag",
     212                       0);
     213        psMetadataAdd (row, PS_LIST_TAIL, "EXT_MAG_SIG",    PS_DATA_F32, "Mag sigma",
     214                       0);
     215        psMetadataAdd (row, PS_LIST_TAIL, "EXT_CHISQ",      PS_DATA_F32, "Chi^2 of fit",
     216                       0);
     217        psMetadataAdd (row, PS_LIST_TAIL, "EXT_NDOF",       PS_DATA_F32, "Fit degrees of freedom",
     218                       0);
    169219      }
    170220    }
     
    179229  } else {
    180230
    181 #define addColumn(_outName, _inName, _convertTo32)                      \
     231#define addColumn(_outName, _inName, _convertTo32)                      \
    182232    if (!addOutputColumn(table, detections, total, _outName, _inName, _convertTo32)) { \
    183233      psError(PS_ERR_UNKNOWN, false, "Failed to add column %s", _outName); \
    184       return false;                                                     \
     234      return false;                                                     \
    185235    }
    186236
     
    198248    addColumn("EXT_SIGNIFICANCE", "EXT_NSIGMA", 0);
    199249    addColumn("PSF_MAJOR", NULL, 0);
    200     addColumn("PSF_MINOR", NULL, 0);     
    201     addColumn("PSF_THETA", NULL, 0);   
    202     addColumn("PSF_QUALITY", "PSF_QF", 0); 
    203     addColumn("PSF_NPIX", NULL, 1);       
     250    addColumn("PSF_MINOR", NULL, 0);
     251    addColumn("PSF_THETA", NULL, 0);
     252    addColumn("PSF_QUALITY", "PSF_QF", 0);
     253    addColumn("PSF_NPIX", NULL, 1);
    204254    addColumn("MOMENTS_XX", NULL, 0);
    205255    addColumn("MOMENTS_XY", NULL, 0);
     
    255305      addColumn("EXT_THETA_ERR", NULL, 0);
    256306    }
     307    if (args->version >= 3) {
     308      addColumn("RA_EXT", NULL, 0);
     309      addColumn("RA_EXT_SIGMA", NULL, 0);
     310      addColumn("DEC_EXT", NULL, 0);
     311      addColumn("DEC_EXT_SIGMA", NULL, 0);
     312      addColumn("POSANG_EXT", NULL, 0);
     313      addColumn("EXT_FLUX", NULL, 0);
     314      addColumn("EXT_CAL_MAG", NULL, 0);
     315      addColumn("EXT_MAG_SIG", NULL, 0);
     316      addColumn("EXT_CHISQ", NULL, 0);
     317      addColumn("EXT_NDOF", NULL, 0);
     318    }
     319
    257320    if (!psFitsWriteTableAllColumns(fits, header, table, OUT_EXTNAME)) {
    258321      psError(psErrorCodeLast(), false, "Unable to write table");
     
    287350      ppMopsDetections *det = detections->data[i];
    288351      if (!det || det->num == 0) {
    289         // no detections survived for this input
    290         continue;
     352        // no detections survived for this input
     353        continue;
    291354      }
    292355      psVector *in = NULL;
    293356      in = psMetadataLookupVector(NULL, det->table, inColumnName);
    294357      if (!in) {
    295         psError(PS_ERR_PROGRAMMING, true, "failed to find input column: %s (convertTo32 is true)", inColumnName);
    296         return false;
     358        psError(PS_ERR_PROGRAMMING, true, "failed to find input column: %s (convertTo32 is true)", inColumnName);
     359        return false;
    297360      }
    298361      if (in->type.type != PS_TYPE_S64 && in->type.type != PS_TYPE_U64) {
    299         psError(PS_ERR_PROGRAMMING, true, "input column to convert is not S64 or U64: %s %d",
    300                 inColumnName, in->type.type);
    301         return false;
     362        psError(PS_ERR_PROGRAMMING, true, "input column to convert is not S64 or U64: %s %d",
     363                inColumnName, in->type.type);
     364        return false;
    302365      }
    303366      if (out == NULL) {
    304         // First time through set up the output vector and the copy parameters
    305         if (in->type.type == PS_TYPE_S64) {
    306           out = psVectorAlloc(outputSize, PS_TYPE_S32);
    307         } else {
    308           out = psVectorAlloc(outputSize, PS_TYPE_U32);
    309         }
     367        // First time through set up the output vector and the copy parameters
     368        if (in->type.type == PS_TYPE_S64) {
     369          out = psVectorAlloc(outputSize, PS_TYPE_S32);
     370        } else {
     371          out = psVectorAlloc(outputSize, PS_TYPE_U32);
     372        }
    310373      }
    311374      for (long d=0; d < det->num; d++) {
    312         if (in->type.type == PS_TYPE_S64) {
    313           out->data.S32[next++] = in->data.S64[d];
    314         } else {
    315           out->data.U32[next++] = in->data.U64[d];
    316         }
     375        if (in->type.type == PS_TYPE_S64) {
     376          out->data.S32[next++] = in->data.S64[d];
     377        } else {
     378          out->data.U32[next++] = in->data.U64[d];
     379        }
    317380      }
    318381    }
     
    323386      ppMopsDetections *det = detections->data[i];
    324387      if (!det || det->num == 0) {
    325         // no detections survived for this input
    326         continue;
     388        // no detections survived for this input
     389        continue;
    327390      }
    328391      psVector *in = NULL;
    329392      in = psMetadataLookupVector(NULL, det->table, inColumnName);
    330393      if (!in) {
    331         psError(PS_ERR_PROGRAMMING, true, "failed to find input column: %s (convertTo32 is false)", inColumnName);
    332         out = psVectorAlloc(outputSize, PS_TYPE_F32);
    333         psVectorInit(out, NAN);
    334         psMetadataAddVector(table, PS_LIST_TAIL, outColumnName, 0, NULL, out);
    335         return false;
     394        psError(PS_ERR_PROGRAMMING, true, "failed to find input column: %s (convertTo32 is false)", inColumnName);
     395        out = psVectorAlloc(outputSize, PS_TYPE_F32);
     396        psVectorInit(out, NAN);
     397        psMetadataAddVector(table, PS_LIST_TAIL, outColumnName, 0, NULL, out);
     398        return false;
    336399      }
    337400      if (out == NULL) {
    338         // First time through set up the output vector and the copy parameters
    339         out = psVectorAlloc(outputSize, in->type.type);
    340         next = (void *) out->data.U8;
    341         switch (in->type.type) {
    342         case PS_TYPE_S8:
    343           elementSize = sizeof(psS8);
    344           break;
    345         case PS_TYPE_U8:
    346           elementSize = sizeof(psU8);
    347           break;
    348         case PS_TYPE_S16:
    349           elementSize = sizeof(psS16);
    350           break;
    351         case PS_TYPE_U16:
    352           elementSize = sizeof(psU16);
    353           break;
    354         case PS_TYPE_S32:
    355           elementSize = sizeof(psS32);
    356           break;
    357         case PS_TYPE_U32:
    358           elementSize = sizeof(psU32);
    359           break;
    360         case PS_TYPE_S64:
    361           elementSize = sizeof(psS64);
    362           break;
    363         case PS_TYPE_U64:
    364           elementSize = sizeof(psU64);
    365           break;
    366         case PS_TYPE_F32:
    367           elementSize = sizeof(psF32);
    368           break;
    369         case PS_TYPE_F64:
    370           elementSize = sizeof(psF64);
    371           break;
    372         default:
    373           psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Unknown vector type %d", in->type.type);
    374           return false;
    375         }
    376       }
    377       // We are doing nasty things here so we can use memcpy. 
     401        // First time through set up the output vector and the copy parameters
     402        out = psVectorAlloc(outputSize, in->type.type);
     403        next = (void *) out->data.U8;
     404        switch (in->type.type) {
     405        case PS_TYPE_S8:
     406          elementSize = sizeof(psS8);
     407          break;
     408        case PS_TYPE_U8:
     409          elementSize = sizeof(psU8);
     410          break;
     411        case PS_TYPE_S16:
     412          elementSize = sizeof(psS16);
     413          break;
     414        case PS_TYPE_U16:
     415          elementSize = sizeof(psU16);
     416          break;
     417        case PS_TYPE_S32:
     418          elementSize = sizeof(psS32);
     419          break;
     420        case PS_TYPE_U32:
     421          elementSize = sizeof(psU32);
     422          break;
     423        case PS_TYPE_S64:
     424          elementSize = sizeof(psS64);
     425          break;
     426        case PS_TYPE_U64:
     427          elementSize = sizeof(psU64);
     428          break;
     429        case PS_TYPE_F32:
     430          elementSize = sizeof(psF32);
     431          break;
     432        case PS_TYPE_F64:
     433          elementSize = sizeof(psF64);
     434          break;
     435        default:
     436          psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Unknown vector type %d", in->type.type);
     437          return false;
     438        }
     439      }
     440      // We are doing nasty things here so we can use memcpy.
    378441      // It would be safer to do a proper loop over the elements.
    379442      long toCopy = det->num * elementSize;
Note: See TracChangeset for help on using the changeset viewer.