IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8451


Ignore:
Timestamp:
Aug 21, 2006, 3:16:45 PM (20 years ago)
Author:
jhoblitt
Message:

add missing -recip & missing -bg*

Location:
trunk/ippTools/src
Files:
2 edited

Legend:

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

    r8420 r8451  
    4444static  detNormalizedImfileRow *detNormalizedStatToDetNormalizedmfile(pxConfig *config, detNormalizedStatImfileRow *statImfile);
    4545static  detResidImfileRow *detNormalizedToDetResidImfile(pxConfig *config, detNormalizedImfileRow *normalizedImfile);
     46static detResidExpRow *mdToDetResidExp(pxConfig *config, psMetadata *row);
    4647static psArray *validDetInputClassIds(pxConfig *config, const char *det_id);
    4748static psArray *searchInputImfiles(pxConfig *config, const char *det_id);
     
    706707        iteration,
    707708        rawExp->exp_id,
    708         true,   // use
    709         false   // accept
     709        true            // use
    710710    );
    711711}
     
    28342834{
    28352835    PS_ASSERT_PTR_NON_NULL(config, false);
     2836
     2837    /*
     2838which returns a list of exposures for which all component class ids
     2839have had residuals created.  This list includes the detrend id,
     2840iteration, exposure id, detrend type, and whether the exposure was
     2841included in the stack for this iteration.
     2842    */
     2843
     2844
     2845    // select detRun.position
     2846    // select detRun.iteration
     2847    // select detRun.det_type
     2848    // select detInputExp.exp_id
     2849    // select detInputExp.include
     2850    // by:
     2851    // find the current iteration bassed on det_id
     2852    // find all exp_ids in the current det_id/iteration from detInputExp
     2853    // compare to detInputExp.imfiles to derResidImfile by class_id
     2854    // and:
     2855    // detResidImfile.{det_id, iteration, exp_id} is not in detResidExp
     2856
     2857    psString query = psStringCopy(
     2858        "SELECT DISTINCT"
     2859        "   det_id,"
     2860        "   iteration,"
     2861        "   exp_id,"
     2862        "   include"
     2863        " FROM"
     2864        "   (SELECT DISTINCT"
     2865        "       detRun.position AS det_id,"
     2866        "       detRun.iteration,"
     2867        "       detRun.det_type,"
     2868        "       detInputExp.exp_id,"
     2869        "       detInputExp.include,"
     2870        "       rawDetrendExp.imfiles"
     2871        "   FROM detRun"
     2872        "       LEFT JOIN detInputExp"
     2873        "       ON detRun.position = detInputExp.det_id"
     2874        "       AND detRun.iteration = detInputExp.iteration"
     2875        "   LEFT JOIN rawDetrendExp"
     2876        "       ON detInputExp.exp_id = rawDetrendExp.exp_id"
     2877        "   LEFT JOIN detResidImfile"
     2878        "       ON detRun.position = detResidImfile.det_id"
     2879        "       AND detRun.iteration = detResidImfile.iteration"
     2880        "       AND detInputExp.exp_id = detResidImfile.exp_id"
     2881        "   LEFT JOIN detResidExp"
     2882        "       ON detRun.position = detResidExp.det_id"
     2883        "       AND detRun.iteration = detResidExp.iteration"
     2884        "       AND detInputExp.exp_id = detResidExp.exp_id"
     2885        "   WHERE"
     2886        "       detResidExp.det_id IS NULL"
     2887        "       AND detResidExp.iteration IS NULL"
     2888        "       AND detResidExp.exp_id IS NULL"
     2889        "   GROUP BY"
     2890        "       detInputExp.exp_id"
     2891        "   HAVING"
     2892        "       rawDetrendExp.imfiles = COUNT(detResidImfile.class_id)"
     2893        " ) AS toresidexp"
     2894        );
     2895
     2896    {
     2897        // build a query to search by det_id, iteration, exp_id
     2898        psMetadata *where = psMetadataAlloc();
     2899        bool status = false;
     2900        psString det_id = psMetadataLookupStr(&status, config->args, "-det_id");
     2901        if (!status) {
     2902            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id");
     2903            psFree(where);
     2904            psFree(query);
     2905            return false;
     2906        }
     2907        if (det_id) {
     2908            if (!psMetadataAddStr(where, PS_LIST_TAIL, "det_id", 0, "==", det_id)) {
     2909                psError(PS_ERR_UNKNOWN, false, "failed to add item det_id");
     2910                psFree(where);
     2911                psFree(query);
     2912                return false;
     2913            }
     2914        }
     2915        psS32 iteration = psMetadataLookupS32(&status, config->args, "-iteration");
     2916        if (!status) {
     2917            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -iteration");
     2918            psFree(where);
     2919            psFree(query);
     2920            return false;
     2921        }
     2922        // always set iteration
     2923        if (!psMetadataAddS32(where, PS_LIST_TAIL, "iteration", 0, "==", iteration)) {
     2924            psError(PS_ERR_UNKNOWN, false, "failed to add item iteration");
     2925            psFree(where);
     2926            psFree(query);
     2927            return false;
     2928        }
     2929        psString exp_id = psMetadataLookupStr(&status, config->args, "-exp_id");
     2930        if (!status) {
     2931            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_id");
     2932            psFree(where);
     2933            psFree(query);
     2934            return false;
     2935        }
     2936        if (exp_id) {
     2937            if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_id", 0, "==", exp_id)) {
     2938                psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
     2939                psFree(where);
     2940                psFree(query);
     2941                return false;
     2942            }
     2943        }
     2944
     2945        // there's not
     2946        psString whereClaus = psDBGenerateWhereConditionSQL(where, "detNormalizedImfile");
     2947        psFree(where);
     2948        if (whereClaus) {
     2949            psStringAppend(&query, " AND %s", whereClaus);
     2950            psFree(whereClaus);
     2951        }
     2952    }
     2953
     2954    if (!p_psDBRunQuery(config->dbh, query)) {
     2955        psError(PS_ERR_UNKNOWN, false, "database error");
     2956        psFree(query);
     2957        return false;
     2958    }
     2959    psFree(query);
     2960
     2961    psArray *output = p_psDBFetchResult(config->dbh);
     2962    if (!output) {
     2963        // XXX check psError here
     2964        psError(PS_ERR_UNKNOWN, false, "no pending rawDetrendExp rows found");
     2965        return false;
     2966    }
     2967
     2968    // start a transaction so it's all rows or nothing
     2969    if (!psDBTransaction(config->dbh)) {
     2970        psError(PS_ERR_UNKNOWN, false, "database error");
     2971        psFree(output);
     2972        return false;
     2973    }
     2974
     2975    for (long i = 0; i < psArrayLength(output); i++) {
     2976        psMetadata *row = output->data[i];
     2977        // convert metadata into a detResidExp object
     2978        detResidExpRow *residExp = mdToDetResidExp(config, row);
     2979        if (!residExp) {
     2980            if (!psDBRollback(config->dbh)) {
     2981                psError(PS_ERR_UNKNOWN, false, "database error");
     2982            }
     2983            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata to detResidExp");
     2984            psFree(output);
     2985            return false;
     2986        }
     2987        // insert detResidExp object into the database
     2988        if (!detResidExpInsertObject(config->dbh, residExp)) {
     2989            if (!psDBRollback(config->dbh)) {
     2990                psError(PS_ERR_UNKNOWN, false, "database error");
     2991            }
     2992            psError(PS_ERR_UNKNOWN, false, "database error");
     2993            psFree(residExp);
     2994            psFree(output);
     2995        }
     2996        psFree(residExp);
     2997    }
     2998
     2999    psFree(output);
     3000
     3001    if (!psDBCommit(config->dbh)) {
     3002        psError(PS_ERR_UNKNOWN, false, "database error");
     3003        return false;
     3004    }
     3005
     3006    return true;
     3007}
     3008
     3009static detResidExpRow *mdToDetResidExp(pxConfig *config, psMetadata *row)
     3010{
     3011    PS_ASSERT_PTR_NON_NULL(config, NULL);
     3012    PS_ASSERT_PTR_NON_NULL(row, NULL);
     3013
     3014    bool status = false;
     3015    // values from row
     3016    psS32 det_id = psMetadataLookupS32(&status, row, "det_id");
     3017    if (!status) {
     3018        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for det_id");
     3019        return false;
     3020    }
     3021    if (isnan(det_id)) {
     3022        psError(PS_ERR_UNKNOWN, true, "det_id is required");
     3023        return false;
     3024    }
     3025    psS32 iteration = psMetadataLookupS32(&status, row, "iteration");
     3026    if (!status) {
     3027        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for iteration");
     3028        return false;
     3029    }
     3030    psString exp_id = psMetadataLookupStr(&status, row, "exp_id");
     3031    if (!status) {
     3032        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for exp_id");
     3033        return false;
     3034    }
     3035    if (!exp_id) {
     3036        psError(PS_ERR_UNKNOWN, true, "exp_id is required");
     3037        return false;
     3038    }
     3039
     3040    // values from config
     3041    psF32 stats = psMetadataLookupF32(&status, config->args, "-stats");
     3042    if (!status) {
     3043        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -stats");
     3044        return false;
     3045    }
     3046    if (isnan(stats)) {
     3047        psError(PS_ERR_UNKNOWN, true, "-stats is required");
     3048        return false;
     3049    }
     3050    // optional
     3051    bool reject = psMetadataLookupBool(&status, config->args, "-reject");
     3052    if (!status) {
     3053        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -reject");
     3054        return false;
     3055    }
     3056    psString b1_uri = psMetadataLookupStr(&status, config->args, "-b1_uri");
     3057    if (!status) {
     3058        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b1_uri");
     3059        return false;
     3060    }
     3061    if (!b1_uri) {
     3062        psError(PS_ERR_UNKNOWN, true, "-b1_uri is required");
     3063        return false;
     3064    }
     3065    psString b2_uri = psMetadataLookupStr(&status, config->args, "-b2_uri");
     3066    if (!status) {
     3067        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b2_uri");
     3068        return false;
     3069    }
     3070    if (!b2_uri) {
     3071        psError(PS_ERR_UNKNOWN, true, "-b2_uri is required");
     3072        return false;
     3073    }
     3074
     3075    // create a new detResidImfileRow and insert it
     3076    return detResidExpRowAlloc(
     3077            det_id,
     3078            iteration,
     3079            exp_id,
     3080            stats,
     3081            !reject,
     3082            b1_uri,
     3083            b2_uri
     3084        );
     3085}
     3086
     3087#if 0   
     3088    PS_ASSERT_PTR_NON_NULL(config, false);
    28363089 
    28373090    // det_id, exp_id,  & recipe are required
     3091
    28383092    bool status = false;
    28393093    psString det_id = psMetadataLookupStr(&status, config->args, "-det_id");
     
    28553109        return false;
    28563110    }
    2857     psString class_id = psMetadataLookupStr(&status, config->args, "-class_id");
    2858     if (!status) {
    2859         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id");
    2860         return false;
    2861     }
    2862     if (!class_id) {
    2863         psError(PS_ERR_UNKNOWN, true, "-class_id is required");
     3111    psString exp_id = psMetadataLookupStr(&status, config->args, "-exp_id");
     3112    if (!status) {
     3113        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_id");
     3114        return false;
     3115    }
     3116    if (!exp_id) {
     3117        psError(PS_ERR_UNKNOWN, true, "-exp_id is required");
    28643118        return false;
    28653119    }
     
    29353189    return true;
    29363190}
     3191#endif
    29373192
    29383193static bool residexpMode(pxConfig *config)
     
    32263481            newIteration,
    32273482            inputExp->exp_id,
    3228             true,   // use
    3229             true    // accept
     3483            true   // use
    32303484        );
    32313485        psArrayAdd(newInputExps, 0, newInputExp);
  • trunk/ippTools/src/dettoolConfig.c

    r8447 r8451  
    167167    psMetadataAddStr(addstacArgs, PS_LIST_TAIL, "-class_id",  0,
    168168        "define class ID (required)", NULL);
     169    psMetadataAddStr(addstacArgs, PS_LIST_TAIL, "-recip",  0,
     170        "define recipe (required)", NULL);
     171    psMetadataAddF64(addstacArgs, PS_LIST_TAIL, "-bg",  0,
     172        "define exposue background", NAN);
     173    psMetadataAddF64(addstacArgs, PS_LIST_TAIL, "-bg_stdev",  0,
     174        "define exposue background stdev", NAN);
     175    psMetadataAddF64(addstacArgs, PS_LIST_TAIL, "-bg_mean_stdev",  0,
     176        "define exposue background mean stdev", NAN);
    169177    psMetadataAddStr(addstacArgs, PS_LIST_TAIL, "-uri",  0,
    170178        "define URI (required)", NULL);
    171     psMetadataAddStr(addstacArgs, PS_LIST_TAIL, "-recip",  0,
    172         "define recipe (required)", NULL);
    173179    psMetadataAddBool(addstacArgs, PS_LIST_TAIL, "-pleasenormalize",  0,
    174180        "dude, make me normal", false);
     
    278284    psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-class_id",  0,
    279285        "define class ID (required)", NULL);
     286    psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-uri",  0,
     287        "define resid file URI (required)", NULL);
    280288    psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-recip",  0,
    281289        "define recipe (required)", NULL);
    282     psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-uri",  0,
    283         "define resid file URI (required)", NULL);
     290    psMetadataAddF64(addresidimfileArgs, PS_LIST_TAIL, "-bg",  0,
     291        "define exposue background", NAN);
     292    psMetadataAddF64(addresidimfileArgs, PS_LIST_TAIL, "-bg_stdev",  0,
     293        "define exposue background stdev", NAN);
     294    psMetadataAddF64(addresidimfileArgs, PS_LIST_TAIL, "-bg_mean_stdev",  0,
     295        "define exposue background mean stdev", NAN);
    284296    psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-b1_uri",  0,
    285297        "define banana 1", NULL);
     
    310322    psMetadataAddStr(addresidexpArgs, PS_LIST_TAIL, "-exp_id",  0,
    311323        "define detrend ID (required)", NULL);
    312     psMetadataAddStr(addresidexpArgs, PS_LIST_TAIL, "-b1_uri",  0,
    313         "define banana 1", NULL);
    314     psMetadataAddStr(addresidexpArgs, PS_LIST_TAIL, "-b2_uri",  0,
    315         "define banana 2", NULL);
     324    psMetadataAddStr(addresidexpArgs, PS_LIST_TAIL, "-recip",  0,
     325        "define recipe (required)", NULL);
    316326    psMetadataAddF64(addresidexpArgs, PS_LIST_TAIL, "-bg",  0,
    317327        "define exposue background", NAN);
     
    320330    psMetadataAddF64(addresidexpArgs, PS_LIST_TAIL, "-bg_mean_stdev",  0,
    321331        "define exposue background mean stdev", NAN);
     332    psMetadataAddStr(addresidexpArgs, PS_LIST_TAIL, "-b1_uri",  0,
     333        "define banana 1", NULL);
     334    psMetadataAddStr(addresidexpArgs, PS_LIST_TAIL, "-b2_uri",  0,
     335        "define banana 2", NULL);
    322336    psMetadataAddBool(addresidexpArgs, PS_LIST_TAIL, "-reject",  0,
    323337        "exposure is not to be stacked in the next iteration", false);
Note: See TracChangeset for help on using the changeset viewer.