IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 3, 2013, 2:43:13 PM (13 years ago)
Author:
eugene
Message:

thread psphotModelBackground, psphotAddOrSubNoise, psphotGuessModel; add recipe options to control selection of extended models fitted; iterate on the trail window a bit

Location:
trunk/psphot
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot

  • trunk/psphot/src

  • trunk/psphot/src/psphotAddNoise.c

    r34492 r35769  
    11# include "psphotInternal.h"
    22
     3bool psphotAddOrSubNoise_Threaded (psThreadJob *job);
    34bool psphotMaskSource(pmSource *source, bool add, psImageMaskType maskVal);
    45
     
    3233}
    3334
    34 static int Nmasked = 0;
    35 
    3635// the return state indicates if any sources were actually replaced
    3736bool psphotAddOrSubNoiseReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, bool add) {
    3837
    3938    bool status = false;
     39
     40    psTimerStart ("psphot.noise");
    4041
    4142    // find the currently selected readout
     
    5556    if (!sources) return false;
    5657
    57     psTimerStart ("psphot.noise");
     58    // determine the number of allowed threads
     59    int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads
     60    if (!status) {
     61        nThreads = 0;
     62    }
    5863
    5964    // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
     
    8489
    8590    psphotVisualShowImage (readout);
     91
     92    // choose Cx, Cy (see psphotThreadTools.c for overview of the concepts)
     93    int Cx = 1, Cy = 1;
     94    psphotChooseCellSizes (&Cx, &Cy, readout, nThreads);
     95
     96    psArray *cellGroups = psphotAssignSources (Cx, Cy, sources);
     97
     98    for (int i = 0; i < cellGroups->n; i++) {
     99
     100        psArray *cells = cellGroups->data[i];
     101
     102        for (int j = 0; j < cells->n; j++) {
     103
     104            // allocate a job -- if threads are not defined, this just runs the job
     105            psThreadJob *job = psThreadJobAlloc ("PSPHOT_ADD_NOISE");
     106            psArrayAdd(job->args, 1, cells->data[j]); // sources
     107            PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
     108            PS_ARRAY_ADD_SCALAR(job->args, markVal,  PS_TYPE_IMAGE_MASK);
     109            PS_ARRAY_ADD_SCALAR(job->args, FACTOR,   PS_TYPE_F32);
     110            PS_ARRAY_ADD_SCALAR(job->args, SIZE,     PS_TYPE_F32);
     111            PS_ARRAY_ADD_SCALAR(job->args, add,      PS_TYPE_U8);
     112
     113# if (1)
     114            if (!psThreadJobAddPending(job)) {
     115                psError(PS_ERR_UNKNOWN, false, "Unable to add/sub noise.");
     116                return false;
     117            }
     118# else
     119            if (!psphotAddOrSubNoise_Threaded(job)) {
     120                psError(PS_ERR_UNKNOWN, false, "Unable to add/sub noise.");
     121                return false;
     122            }
     123            psFree(job);
     124# endif
     125        }
     126
     127        // wait for the threads to finish and manage results
     128        if (!psThreadPoolWait (false, true)) {
     129            psFree(cellGroups);
     130            psError(PS_ERR_UNKNOWN, false, "Unable to add/sub noise.");
     131            return false;
     132        }
     133
     134        // we have only supplied one type of job, so we can assume the types here
     135        psThreadJob *job = NULL;
     136        while ((job = psThreadJobGetDone()) != NULL) {
     137            // we have no returned data from this operation
     138            if (job->args->n < 1) {
     139                fprintf (stderr, "error with job\n");
     140            }
     141            psFree(job);
     142        }
     143    }
     144
     145    if (add) {
     146        psLogMsg ("psphot.noise", PS_LOG_WARN, "add noise for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.noise"));
     147    } else {
     148        psLogMsg ("psphot.noise", PS_LOG_WARN, "sub noise for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.noise"));
     149    }
     150
     151    psFree (cellGroups);
     152
     153    psphotVisualShowImage (readout);
     154
     155    return true;
     156}
     157
     158bool psphotAddOrSubNoise_Threaded (psThreadJob *job) {
     159
     160    psArray *sources = job->args->data[0];
     161    psImageMaskType maskVal = PS_SCALAR_VALUE(job->args->data[1], PS_TYPE_IMAGE_MASK_DATA);
     162    psImageMaskType markVal = PS_SCALAR_VALUE(job->args->data[2], PS_TYPE_IMAGE_MASK_DATA);
     163    psF32 FACTOR = PS_SCALAR_VALUE(job->args->data[3], F32);
     164    psF32 SIZE = PS_SCALAR_VALUE(job->args->data[4], F32);
     165    psBool add  = PS_SCALAR_VALUE(job->args->data[5], U8);
    86166
    87167    // loop over all source
     
    104184        psphotMaskSource (source, add, markVal);
    105185    }
    106     if (add) {
    107         psLogMsg ("psphot.noise", PS_LOG_WARN, "add noise for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.noise"));
    108     } else {
    109         psLogMsg ("psphot.noise", PS_LOG_WARN, "sub noise for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.noise"));
    110     }
    111     fprintf (stderr, "masked %d objects\n", Nmasked);
    112 
    113     psphotVisualShowImage (readout);
    114 
    115186    return true;
    116187}
     
    142213        }
    143214    }
    144     Nmasked ++;
    145 
    146     return true;
    147 }
    148 
     215    return true;
     216}
     217
Note: See TracChangeset for help on using the changeset viewer.