IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16687


Ignore:
Timestamp:
Feb 27, 2008, 11:36:52 AM (18 years ago)
Author:
jhoblitt
Message:

fwv stacktool -definebyquery

Location:
trunk/ippTools
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/scripts/camtest.sh

    r14018 r16687  
    88camtool -pendingimfile || exit 1
    99
    10 camtool -addprocessedexp -cam_id 1 -uri file:///cam -bg 1 -bg_stdev 2 -bg_mean_stdev 3 -sigma_ra 1 -sigma_dec 2 -zp_mean 10 -zp_stdev 2 -fwhm 42 -fwhm_range 100 -n_stars 2 -n_extended 0 -n_astrom 42 -n_cr 10000000 -path_base file:///foo || exit 1
    11 camtool -addprocessedexp -cam_id 2 -uri file:///cam -bg 1 -bg_stdev 2 -bg_mean_stdev 3 -sigma_ra 1 -sigma_dec 2 -zp_mean 10 -zp_stdev 2 -fwhm 42 -fwhm_range 100 -n_stars 2 -n_extended 0 -n_astrom 42 -n_cr 10000000 -path_base file:///foo || exit 1
     10camtool -addprocessedexp -cam_id 1 -uri file:///cam -bg 1 -bg_stdev 2 -bg_mean_stdev 3 -sigma_ra 1 -sigma_dec 2 -zp_mean 10 -zp_stdev 2 -n_stars 2 -n_extended 0 -n_astrom 42 -n_cr 10000000 -path_base file:///foo || exit 1
     11camtool -addprocessedexp -cam_id 2 -uri file:///cam -bg 1 -bg_stdev 2 -bg_mean_stdev 3 -sigma_ra 1 -sigma_dec 2 -zp_mean 10 -zp_stdev 2 -n_stars 2 -n_extended 0 -n_astrom 42 -n_cr 10000000 -path_base file:///foo || exit 1
  • trunk/ippTools/scripts/warptest.sh

    r14018 r16687  
    55camtest.sh || exit 1
    66
    7 warptool -definerun -mode warp -workdir file:///foo || exit 1
    8 
    9 warptool -addinputexp -warp_id 1 -cam_id 1 || exit 1
    10 warptool -addinputexp -warp_id 1 -cam_id 2 || exit 1
    11 
    12 warptool -updaterun -warp_id 1 -state run || exit 1
     7#warptool -definerun -mode warp -workdir file:///foo || exit 1
     8#warptool -addinputexp -warp_id 1 -cam_id 1 || exit 1
     9#warptool -addinputexp -warp_id 1 -cam_id 2 || exit 1
     10#warptool -updaterun -warp_id 1 -state run || exit 1
    1311
    1412warptool -exp -warp_id 1 || exit 1
  • trunk/ippTools/share/Makefile.am

    r16613 r16687  
    6464        regtool_revertprocessedexp.sql \
    6565        regtool_revertprocessedimfile.sql \
     66        stacktool_find_complete_warps.sql \
    6667        stacktool_inputskyfile.sql \
     68        stacktool_revertsumskyfile.sql \
    6769        stacktool_sumskyfile.sql \
    6870        stacktool_tosum.sql \
    69         stacktool_revertsumskyfile.sql \
    7071        warptool_exp.sql \
    7172        warptool_imfile.sql \
  • trunk/ippTools/src/stacktool.c

    r16678 r16687  
    9595{
    9696    PS_ASSERT_PTR_NON_NULL(config, false);
     97
     98    // required options
     99    PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false);
     100
     101    // default
     102    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     103    PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false);
     104
     105
     106    psString query = pxDataGet("stacktool_find_complete_warps.sql");
     107    if (!query) {
     108        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     109        return false;
     110    }
     111
     112    if (config->where) {
     113        psString whereClause = psDBGenerateWhereConditionSQL(config->where, NULL);
     114        psStringAppend(&query, " AND %s", whereClause);
     115        psFree(whereClause);
     116    }
     117
     118    if (!p_psDBRunQuery(config->dbh, query)) {
     119        psError(PS_ERR_UNKNOWN, false, "database error");
     120        psFree(query);
     121        return false;
     122    }
     123    psFree(query);
     124
     125    psArray *output = p_psDBFetchResult(config->dbh);
     126    if (!output) {
     127        psErrorCode err = psErrorCodeLast();
     128        switch (err) {
     129            case PS_ERR_DB_CLIENT:
     130                psError(PXTOOLS_ERR_SYS, false, "database error");
     131            case PS_ERR_DB_SERVER:
     132                psError(PXTOOLS_ERR_PROG, false, "database error");
     133            default:
     134                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     135        }
     136
     137        return false;
     138    }
     139    if (!psArrayLength(output)) {
     140        psTrace("stacktool", PS_LOG_INFO, "no rows found");
     141        psFree(output);
     142        return true;
     143    }
     144
     145    psHash *stacks = psHashAlloc(psArrayLength(output));
     146
     147    // loop over the array of metadata
     148    for (long i = 0; i < psArrayLength(output); i++) {
     149        psMetadata *md = output->data[i];
     150       
     151        // pull out the warp_id, skycell_id, & tess_id
     152        bool status;
     153        psString skycell_id = psMetadataLookupStr(&status, md, "skycell_id");
     154        if (!status) {
     155            psError(PS_ERR_UNKNOWN, false, "failed to lookup skycell_id");
     156            psFree(output);
     157            return NULL;
     158        }
     159
     160        psString tess_id = psMetadataLookupStr(&status, md, "tess_id");
     161        if (!status) {
     162            psError(PS_ERR_UNKNOWN, false, "failed to lookup tess_id");
     163            psFree(output);
     164            return NULL;
     165        }
     166
     167        // group the warps by skycell_id & tess_id
     168        psString key = NULL;
     169        psStringAppend(&key, "%s:%s", skycell_id, tess_id);
     170
     171        // check to see if the hash key already exists
     172        psArray *col = psHashLookup(stacks, key);
     173        if (!col) {
     174            // if it doesn't, create an new psArray for this stack
     175            col = psArrayAllocEmpty(0);
     176            psHashAdd(stacks, key, col);
     177        }
     178        // add this warp to the stack for this key
     179        psArrayAdd(col, 0, md);
     180        psFree(key);
     181
     182    }
     183    psFree(output);
     184
     185    psArray *grouped = psHashToArray(stacks);
     186    psFree(stacks);
     187
     188    if (!psDBTransaction(config->dbh)) {
     189        psError(PS_ERR_UNKNOWN, false, "database error");
     190        return false;
     191    }
     192
     193    // loop over groups
     194    for (long i = 0; i < psArrayLength(grouped); i++) {
     195        psArray *col = grouped->data[i];
     196
     197        // pull the skycell_id & tess_id from the first warp in the stack
     198        bool status;
     199        psString skycell_id = psMetadataLookupStr(&status, col->data[0], "skycell_id");
     200        if (!status) {
     201            psError(PS_ERR_UNKNOWN, false, "failed to lookup skycell_id");
     202            psFree(grouped);
     203            return NULL;
     204        }
     205
     206        psString tess_id = psMetadataLookupStr(&status, col->data[0], "tess_id");
     207        if (!status) {
     208            psError(PS_ERR_UNKNOWN, false, "failed to lookup tess_id");
     209            psFree(grouped);
     210            return NULL;
     211        }
     212
     213        // create a new stackRun for the group
     214        stackRunRow *run = stackRunRowAlloc(
     215            0,          // ID
     216            "run",      // state
     217            workdir,
     218            NULL,       // dvodb
     219            registered,
     220            skycell_id,
     221            tess_id
     222        );
     223        if (!stackRunInsertObject(config->dbh, run)) {
     224            if (!psDBRollback(config->dbh)) {
     225                psError(PS_ERR_UNKNOWN, false, "database error");
     226            }
     227            psError(PS_ERR_UNKNOWN, false, "database error");
     228            psFree(run);
     229            psFree(grouped);
     230            return false;
     231        }
     232
     233        // figure out the new stack_id
     234        psS64 stack_id = psDBLastInsertID(config->dbh);
     235        run->stack_id = stack_id;
     236
     237        if (!stackRunPrintObject(stdout, run, !simple)) {
     238            psError(PS_ERR_UNKNOWN, false, "failed to print object");
     239            psFree(run);
     240            psFree(grouped);
     241            return false;
     242        }
     243        psFree(run);
     244
     245        // loop over this stack and add each warp to the stackRun
     246        for (long j = 0; j < psArrayLength(col); j++) {
     247            bool status;
     248            psS64 warp_id = psMetadataLookupS64(&status, col->data[0], "warp_id");
     249            if (!status) {
     250                if (!psDBRollback(config->dbh)) {
     251                    psError(PS_ERR_UNKNOWN, false, "database error");
     252                }
     253                psError(PS_ERR_UNKNOWN, false, "failed to lookup warp_id");
     254                psFree(grouped);
     255                return NULL;
     256            }
     257
     258            if (!stackInputSkyfileInsert(config->dbh,
     259                stack_id,
     260                warp_id
     261            )) {
     262                if (!psDBRollback(config->dbh)) {
     263                    psError(PS_ERR_UNKNOWN, false, "database error");
     264                }
     265                psError(PS_ERR_UNKNOWN, false, "database error");
     266                psFree(grouped);
     267                return false;
     268            }
     269
     270        }
     271
     272    }
     273
     274    // point of no return
     275    if (!psDBCommit(config->dbh)) {
     276        psError(PS_ERR_UNKNOWN, false, "database error");
     277        return false;
     278    }
     279
     280    psFree(grouped);
     281
    97282    return true;
    98283}
  • trunk/ippTools/src/stacktoolConfig.c

    r16678 r16687  
    4747    // -definebyquery
    4848    psMetadata *definebyqueryArgs = psMetadataAlloc();
     49    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-workdir", 0,
     50            "define workdir (required)", NULL);
     51    psMetadataAddTime(definebyqueryArgs, PS_LIST_TAIL, "-registered",  0,
     52            "time detrend run was registered", now);
     53    psMetadataAddBool(definebyqueryArgs, PS_LIST_TAIL, "-simple",  0,
     54            "use the simple output format", false);
     55    // skycell
     56    // tess_id
     57    // warp_id
    4958
    5059    // -definerun
Note: See TracChangeset for help on using the changeset viewer.