IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 25, 2012, 10:05:21 AM (14 years ago)
Author:
eugene
Message:

merge changes from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsWrite.c

    r34284 r34466  
    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  int validSeeingCount = 0;
     44  for (int d = 0; d < detections->n; d++) {
     45    if (detections->data[d] != NULL) {
     46      if (det == NULL) {
     47        det = detections->data[d];
     48      }
     49      if (isfinite(((ppMopsDetections*) detections->data[d])->seeing)) {
     50        validSeeingCount += 1;
     51      }
     52    }
    4353  }
    4454  if (det != NULL) {
     55    //Get the SEEING median
     56    psVector* seeingValues = psVectorAlloc(validSeeingCount, PS_TYPE_F32);
     57    psVectorInit(seeingValues, NAN);
     58    validSeeingCount = 0;
     59    for (int d = 0; d < detections->n; d++) {
     60      if ( (detections->data[d] != NULL) && (isfinite(((ppMopsDetections*) detections->data[d])->seeing)) ){
     61        seeingValues->data.F32[validSeeingCount++] = ((ppMopsDetections*) detections->data[d])->seeing;
     62      }
     63    }
     64    psStats *seeingStats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN);
     65    psVectorStats(seeingStats, seeingValues, NULL, NULL, 0);
    4566    psMetadataAddF64(header, PS_LIST_TAIL, "MJD-OBS", 0, "MJD of exposure midpoint", det->mjd);
    4667    psMetadataAddStr(header, PS_LIST_TAIL, "RA", 0, "Right Ascension of boresight", det->raBoresight);
     
    5273    psMetadataAddStr(header, PS_LIST_TAIL, "FILTER", 0, "Filter name", det->filter);
    5374    psMetadataAddF32(header, PS_LIST_TAIL, "AIRMASS", 0, "Airmass of exposure", det->airmass);
    54     psMetadataAddF32(header, PS_LIST_TAIL, "SEEING", 0, "Mean seeing", det->seeing);
     75    psMetadataAddF32(header, PS_LIST_TAIL, "SEEING", 0, "Mean seeing", seeingStats->sampleMedian);
    5576  } else {
    5677    psWarning("no inputs with surviving detections. output header will be incomplete");
     
    112133      // Write data of version 2 (see ICD)
    113134      psMetadataAdd (row, PS_LIST_TAIL, "IPP_IDET",         PS_DATA_U32, "IPP detection identifier index",
    114                      NAN);
     135                     NAN);
    115136      psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_FLUX",    PS_DATA_F32, "PSF fit instrumental magnitude",
    116                      NAN);
     137                     NAN);
    117138      psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_FLUX_SIG",PS_DATA_F32, "Sigma of PSF instrumental magnitude",
    118                      NAN);
     139                     NAN);
    119140      psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG",           PS_DATA_F32, "magnitude in standard aperture",
    120                      NAN);
     141                     NAN);
    121142      psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RAW",       PS_DATA_F32, "magnitude in real aperture",
    122                      NAN);
     143                     NAN);
    123144      psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RADIUS",    PS_DATA_F32, "radius used for aperture mags",
    124                      NAN);
     145                     NAN);
    125146      psMetadataAdd (row, PS_LIST_TAIL, "AP_FLUX",          PS_DATA_F32, "instrumental flux in standard aperture",
    126                      NAN);
     147                     NAN);
    127148      psMetadataAdd (row, PS_LIST_TAIL, "AP_FLUX_SIG",      PS_DATA_F32, "aperture flux error",
    128                      NAN);
     149                     NAN);
    129150      psMetadataAdd (row, PS_LIST_TAIL, "PEAK_FLUX_AS_MAG", PS_DATA_F32, "Peak flux expressed as magnitude",
    130                      NAN);
     151                     NAN);
    131152      psMetadataAdd (row, PS_LIST_TAIL, "CAL_PSF_MAG",      PS_DATA_F32, "PSF Magnitude using supplied calibration",
    132                      NAN);
     153                     NAN);
    133154      psMetadataAdd (row, PS_LIST_TAIL, "CAL_PSF_MAG_SIG",  PS_DATA_F32, "measured scatter of zero point calibration",
    134                      NAN);
     155                     NAN);
    135156      psMetadataAdd (row, PS_LIST_TAIL, "SKY",              PS_DATA_F32, "Sky level",
    136                      NAN);
     157                     NAN);
    137158      psMetadataAdd (row, PS_LIST_TAIL, "SKY_SIGMA",        PS_DATA_F32, "Sigma of sky level",
    138                      NAN);
     159                     NAN);
    139160      psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF_PERFECT",   PS_DATA_F32, "PSF coverage/quality factor (poor)",
    140                      NAN);
     161                     NAN);
    141162      psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_R1",       PS_DATA_F32, "first radial moment",
    142                      NAN);
     163                     NAN);
    143164      psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_RH",       PS_DATA_F32, "half radial moment",
    144                      NAN);
     165                     NAN);
    145166      psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX",        PS_DATA_F32, "Kron Flux (in 2.5 R1)",
    146                      NAN);
     167                     NAN);
    147168      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);
     169                     NAN);
     170      psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_INNER",  PS_DATA_F32, "Kron Flux (in 1.0 R1)",
     171                     NAN);
    151172      psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_OUTER",  PS_DATA_F32, "Kron Flux (in 4.0 R1)",
    152                      NAN);
     173                     NAN);
    153174      psMetadataAdd (row, PS_LIST_TAIL, "DIFF_R_P",         PS_DATA_F32, "distance to positive match source",
    154                      NAN);
     175                     NAN);
    155176      psMetadataAdd (row, PS_LIST_TAIL, "DIFF_SN_P",        PS_DATA_F32, "signal-to-noise of pos match src",
    156                      NAN);
     177                     NAN);
    157178      psMetadataAdd (row, PS_LIST_TAIL, "DIFF_R_M",         PS_DATA_F32, "distance to negative match source",
    158                      NAN);
     179                     NAN);
    159180      psMetadataAdd (row, PS_LIST_TAIL, "DIFF_SN_M",        PS_DATA_F32, "signal-to-noise of neg match src",
    160                      NAN);
     181                     NAN);
    161182      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);
     183                     0);
     184      psMetadataAdd (row, PS_LIST_TAIL, "N_FRAMES",         PS_DATA_U16, "Number of frames overlapping source center",
     185                     0);
     186      psMetadataAdd (row, PS_LIST_TAIL, "PADDING",          PS_DATA_S16, "padding",
     187                     0);
    167188      if (args->version == 3) {
    168         // TODO: Write data of version 3 (see ICD)
     189        // TODO: Write data of version 3 (see ICD)
    169190      }
    170191    }
     
    179200  } else {
    180201
    181 #define addColumn(_outName, _inName, _convertTo32)                      \
     202#define addColumn(_outName, _inName, _convertTo32)                      \
    182203    if (!addOutputColumn(table, detections, total, _outName, _inName, _convertTo32)) { \
    183204      psError(PS_ERR_UNKNOWN, false, "Failed to add column %s", _outName); \
    184       return false;                                                     \
     205      return false;                                                     \
    185206    }
    186207
     
    198219    addColumn("EXT_SIGNIFICANCE", "EXT_NSIGMA", 0);
    199220    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);       
     221    addColumn("PSF_MINOR", NULL, 0);
     222    addColumn("PSF_THETA", NULL, 0);
     223    addColumn("PSF_QUALITY", "PSF_QF", 0);
     224    addColumn("PSF_NPIX", NULL, 1);
    204225    addColumn("MOMENTS_XX", NULL, 0);
    205226    addColumn("MOMENTS_XY", NULL, 0);
     
    287308      ppMopsDetections *det = detections->data[i];
    288309      if (!det || det->num == 0) {
    289         // no detections survived for this input
    290         continue;
     310        // no detections survived for this input
     311        continue;
    291312      }
    292313      psVector *in = NULL;
    293314      in = psMetadataLookupVector(NULL, det->table, inColumnName);
    294315      if (!in) {
    295         psError(PS_ERR_PROGRAMMING, true, "failed to find input column: %s (convertTo32 is true)", inColumnName);
    296         return false;
     316        psError(PS_ERR_PROGRAMMING, true, "failed to find input column: %s (convertTo32 is true)", inColumnName);
     317        return false;
    297318      }
    298319      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;
     320        psError(PS_ERR_PROGRAMMING, true, "input column to convert is not S64 or U64: %s %d",
     321                inColumnName, in->type.type);
     322        return false;
    302323      }
    303324      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         }
     325        // First time through set up the output vector and the copy parameters
     326        if (in->type.type == PS_TYPE_S64) {
     327          out = psVectorAlloc(outputSize, PS_TYPE_S32);
     328        } else {
     329          out = psVectorAlloc(outputSize, PS_TYPE_U32);
     330        }
    310331      }
    311332      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         }
     333        if (in->type.type == PS_TYPE_S64) {
     334          out->data.S32[next++] = in->data.S64[d];
     335        } else {
     336          out->data.U32[next++] = in->data.U64[d];
     337        }
    317338      }
    318339    }
     
    323344      ppMopsDetections *det = detections->data[i];
    324345      if (!det || det->num == 0) {
    325         // no detections survived for this input
    326         continue;
     346        // no detections survived for this input
     347        continue;
    327348      }
    328349      psVector *in = NULL;
    329350      in = psMetadataLookupVector(NULL, det->table, inColumnName);
    330351      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;
     352        psError(PS_ERR_PROGRAMMING, true, "failed to find input column: %s (convertTo32 is false)", inColumnName);
     353        out = psVectorAlloc(outputSize, PS_TYPE_F32);
     354        psVectorInit(out, NAN);
     355        psMetadataAddVector(table, PS_LIST_TAIL, outColumnName, 0, NULL, out);
     356        return false;
    336357      }
    337358      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. 
     359        // First time through set up the output vector and the copy parameters
     360        out = psVectorAlloc(outputSize, in->type.type);
     361        next = (void *) out->data.U8;
     362        switch (in->type.type) {
     363        case PS_TYPE_S8:
     364          elementSize = sizeof(psS8);
     365          break;
     366        case PS_TYPE_U8:
     367          elementSize = sizeof(psU8);
     368          break;
     369        case PS_TYPE_S16:
     370          elementSize = sizeof(psS16);
     371          break;
     372        case PS_TYPE_U16:
     373          elementSize = sizeof(psU16);
     374          break;
     375        case PS_TYPE_S32:
     376          elementSize = sizeof(psS32);
     377          break;
     378        case PS_TYPE_U32:
     379          elementSize = sizeof(psU32);
     380          break;
     381        case PS_TYPE_S64:
     382          elementSize = sizeof(psS64);
     383          break;
     384        case PS_TYPE_U64:
     385          elementSize = sizeof(psU64);
     386          break;
     387        case PS_TYPE_F32:
     388          elementSize = sizeof(psF32);
     389          break;
     390        case PS_TYPE_F64:
     391          elementSize = sizeof(psF64);
     392          break;
     393        default:
     394          psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Unknown vector type %d", in->type.type);
     395          return false;
     396        }
     397      }
     398      // We are doing nasty things here so we can use memcpy.
    378399      // It would be safer to do a proper loop over the elements.
    379400      long toCopy = det->num * elementSize;
Note: See TracChangeset for help on using the changeset viewer.