IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18148


Ignore:
Timestamp:
Jun 16, 2008, 12:13:21 PM (18 years ago)
Author:
jhoblitt
Message:

add stacktool -random_subset support (completely untested - probably does not work)

Location:
trunk/ippTools/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/dettool.c

    r18099 r18148  
    603603      psArray *subset = psArrayAlloc (randomLimit);
    604604      for (int i = 0; i < randomLimit; i++ ){
    605         int j = indexVector->data.S32[i];
    606         subset->data[i] = psMemIncrRefCounter (detrendExps->data[j]);
     605        int j = indexVector->data.S32[i];
     606        subset->data[i] = psMemIncrRefCounter (detrendExps->data[j]);
    607607      }
    608608      psFree (detrendExps);
  • trunk/ippTools/src/stacktool.c

    r18101 r18148  
    120120    PXOPT_COPY_F32(config->args, whereRE, "-select_solang_max", "solang", "<=");
    121121    PXOPT_COPY_STR(config->args, whereWSF, "-select_skycell_id", "skycell_id", "==");
     122    PXOPT_LOOKUP_BOOL(randomSubset, config->args, "-random_subset", false);
     123    PXOPT_LOOKUP_S32(randomLimit, config->args, "-random_limit", false, false);
    122124
    123125    if (!psListLength(whereRE->list) && !psListLength(whereWSF->list) &&
     
    182184    }
    183185
     186    // valid_warpids should be NULL unless randomSubset is specified
     187    psVector *valid_warpids = NULL;
     188    if (randomSubset && (randomLimit < psArrayLength(output))) {
     189        // loop over the array of metadata and figure out which warp_id are in
     190        // the result set
     191        psArray *warps = psArrayAlloc(0);
     192        for (long i = 0; i < psArrayLength(output); i++) {
     193            psMetadata *md = output->data[i];
     194
     195            // pull out the warp_id
     196            bool status;
     197            psS64 warp_id = psMetadataLookupS64(&status, md, "warp_id");
     198            if (!status) {
     199                psError(PS_ERR_UNKNOWN, false, "failed to lookup warp_id");
     200                psFree(output);
     201                psFree(warps);
     202                return NULL;
     203            }
     204
     205            psArrayAdd(warps, 0, warp_id);
     206        }
     207
     208        // generate a random-valued vector, return an index sorted by the
     209        // random values
     210        psVector *randomVector = psVectorAlloc(psArrayLength(output), PS_TYPE_F32);
     211        psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     212        for (int i = 0; i < randomVector->n; i++) {
     213            randomVector->data.F32[i] = psRandomUniform(rng);
     214        }
     215        psVector *indexVector = psVectorSortIndex(NULL, randomVector);
     216        psFree(randdomVector);
     217
     218        // accept for first n of the sequence
     219        valid_warpids = psVectorAlloc(randomLimit, PS_TYPE_S64);
     220        for (int i = 0; i < randomLimit; i++ ){
     221            int j = indexVector->data.S32[i];
     222            valid_warpids->data[i] = psMemIncrRefCounter (warps->data[j]);
     223        }
     224        psFree(indexVector);
     225        psFree(warps);
     226    }
     227
     228
    184229    psHash *stacks = psHashAlloc(psArrayLength(output));
    185230
    186     // loop over the array of metadata
     231    // loop over the array of metadata and build a hash keyed by tess_id &
     232    // skycell_id
    187233    for (long i = 0; i < psArrayLength(output); i++) {
    188234        psMetadata *md = output->data[i];
    189235
    190         // pull out the warp_id, skycell_id, & tess_id
    191236        bool status;
     237        if (valid_warpids) {
     238            psS64 warp_id = psMetadataLookupS64(&status, md, "warp_id");
     239            if (!status) {
     240                psError(PS_ERR_UNKNOWN, false, "failed to lookup warp_id");
     241                psFree(valid_warpids);
     242                psFree(output);
     243                return NULL;
     244            }
     245
     246            // is this a warp_id that should be left out of the stack set(s)?
     247            for (long i = 0; i < psArrayLength(valid_warpids); i++) {
     248                if (valid_warpids->data[i] == warp_id) {
     249                    continue;
     250                }
     251            }
     252        }
     253
     254        // pull out the skycell_id, & tess_id
    192255        psString skycell_id = psMetadataLookupStr(&status, md, "skycell_id");
    193256        if (!status) {
    194257            psError(PS_ERR_UNKNOWN, false, "failed to lookup skycell_id");
     258            psFree(valid_warpids);
    195259            psFree(output);
    196260            return NULL;
     
    200264        if (!status) {
    201265            psError(PS_ERR_UNKNOWN, false, "failed to lookup tess_id");
     266            psFree(valid_warpids);
    202267            psFree(output);
    203268            return NULL;
     
    220285
    221286    }
     287    psFree(valid_warpids);
    222288    psFree(output);
    223289
  • trunk/ippTools/src/stacktoolConfig.c

    r18093 r18148  
    9191    psMetadataAddF64(queueArgs, PS_LIST_TAIL, "-select_solang_max",  0,
    9292            "define max solar angle", NAN);
     93    psMetadataAddBool(definebyqueryArgs, PS_LIST_TAIL, "-random_subset",  0,
     94            "use a random subset of elements", false);
     95    psMetadataAddS32(definebyqueryArgs, PS_LIST_TAIL, "-random_limit",  0,
     96            "use this number of random elements", 20);
    9397
    9498    psMetadataAddBool(queueArgs, PS_LIST_TAIL, "-all",  0,
Note: See TracChangeset for help on using the changeset viewer.