IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36310


Ignore:
Timestamp:
Nov 24, 2013, 3:28:13 PM (13 years ago)
Author:
eugene
Message:

add a radius check function to pcm fit source

Location:
branches/eam_branches/ipp-20130904/psphot
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130904/psphot/src/psphotExtendedSourceFits.c

    r36307 r36310  
    315315
    316316// XXX TEST
    317             if (false && !isInteractive) {
     317            if (!isInteractive) {
    318318                if (!psThreadJobAddPending(job)) {
    319319                    psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
  • branches/eam_branches/ipp-20130904/psphot/src/psphotSourceFits.c

    r36198 r36310  
    1919static int NfitIterPCM = 0;
    2020static int NfitPixPCM = 0;
     21
     22bool psphotPCMfitCheckSize (pmPCMdata *pcm, pmSource *source, psImageMaskType maskVal, float psfSize);
    2123
    2224bool psphotFitInit (int nThreads) {
     
    585587    }
    586588
    587     float t1, t2, t4, t5;
    588     t1 = t2 = t4 = t5 = 0.0;
     589    float t1, t2, t3, t4, t5;
     590    t1 = t2 = t3 = t4 = t5 = 0.0;
    589591    if (TIMING) { psTimerStart ("psphotFitPCM"); }
    590592
     
    642644    }
    643645
    644     if (TIMING) { t4 = psTimerMark ("psphotFitPCM"); }
     646    if (TIMING) { t3 = psTimerMark ("psphotFitPCM"); }
    645647
    646648    // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5);
     
    648650    NfitIterPCM += pcm->modelConv->nIter;
    649651    NfitPixPCM += pcm->modelConv->nDOF;
     652    if (TIMING) { t4 = psTimerMark ("psphotFitPCM"); }
     653
     654    psphotPCMfitCheckSize (pcm, source, maskVal, psfSize);
    650655    if (TIMING) { t5 = psTimerMark ("psphotFitPCM"); }
    651656
    652657    if (TIMING) {
    653658        int nPixBig = source->pixels->numCols * source->pixels->numRows;
    654         fprintf (stderr, "psphotFitPCM : nIter: %2d, radius: %6.1f, npix: %5d of %5d, t1: %6.4f, t2: %6.4f, t4: %6.4f, t5: %6.4f\n", model->nIter, model->fitRadius, model->nPix, nPixBig, t1, t2, t4, t5);
     659        fprintf (stderr, "psphotFitPCM : nIter: %2d, radius: %6.1f, npix: %5d of %5d, t1: %6.4f, t2: %6.4f, t3: %6.4f, t4: %6.4f, t5: %6.4f\n", model->nIter, model->fitRadius, model->nPix, nPixBig, t1, t2, t3, t4, t5);
    655660    }
    656661    if (EXTRA_VERBOSE && !TIMING) {
     
    12461251}
    12471252
    1248  
     1253// # define N_REFF_CHECK 11
     1254// float drefCheck[] = {-0.02, -0.04, -0.06, 0.0, 0.85, 0.90, 0.95, 1.00, 1.05, 1.10, 1.15, 1.20, 1.25};
     1255
     1256// we have an initial fit, check to see if the current size is besst
     1257bool psphotPCMfitCheckSize (pmPCMdata *pcm, pmSource *source, psImageMaskType maskVal, float psfSize) {
     1258
     1259    // PAR is already at my current best guess
     1260    psF32 *PAR = pcm->modelConv->params->data.F32;
     1261
     1262    // store best guess as a shape
     1263    psEllipseAxes centerAxes;
     1264    pmModelParamsToAxes (&centerAxes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], true);
     1265
     1266    float xMin = NAN;
     1267    float iMin = NAN;
     1268    float rMin = NAN;
     1269
     1270    // loop over Reff, keeping the ARatio and Theta constant
     1271    for (int j = -20; j < 21; j++) {
     1272
     1273        float dref = j * 0.02;
     1274
     1275        psEllipseAxes guessAxes;
     1276        guessAxes.major = centerAxes.major + dref;
     1277        guessAxes.minor = guessAxes.major * centerAxes.minor / centerAxes.major;
     1278        guessAxes.theta = centerAxes.theta;
     1279
     1280        if (!isfinite(guessAxes.major)) return false;
     1281        if (!isfinite(guessAxes.minor)) return false;
     1282        if (!isfinite(guessAxes.theta)) return false;
     1283
     1284        // convert the major,minor,theta to shape parameters for an Reff-like model
     1285        pmModelAxesToParams (&PAR[PM_PAR_SXX], &PAR[PM_PAR_SXY], &PAR[PM_PAR_SYY], guessAxes, true);
     1286
     1287        // generated the modelFlux
     1288        pmPCMMakeModel (source, pcm->modelConv, maskVal, psfSize);
     1289       
     1290        float YY = 0.0;
     1291        float YM = 0.0;
     1292        float MM = 0.0;
     1293        bool usePoisson = false;
     1294
     1295        for (int iy = 0; iy < source->pixels->numRows; iy++) {
     1296            for (int ix = 0; ix < source->pixels->numCols; ix++) {
     1297                // skip masked points
     1298                if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix]) {
     1299                    continue;
     1300                }
     1301                // skip zero-variance points
     1302                if (source->variance->data.F32[iy][ix] == 0) {
     1303                    continue;
     1304                }
     1305                // skip nan value points
     1306                if (!isfinite(source->pixels->data.F32[iy][ix])) {
     1307                    continue;
     1308                }
     1309
     1310                float fy = source->pixels->data.F32[iy][ix];
     1311                float fm = source->modelFlux->data.F32[iy][ix];
     1312                float wt = (usePoisson) ? 1.0 / source->variance->data.F32[iy][ix] : 1.0;
     1313
     1314                YY += PS_SQR(fy) * wt;
     1315                YM += fm * fy * wt;
     1316                MM += PS_SQR(fm) * wt;
     1317            }
     1318        }
     1319
     1320        float Io = YM / MM;
     1321        float Chisq = YY - 2 * Io * YM + Io * Io * MM;
     1322        if (isnan(xMin) || (Chisq < xMin)) {
     1323            xMin = Chisq;
     1324            iMin = Io;
     1325            rMin = dref;
     1326        }
     1327        // fprintf (stderr, "%d | %f %f %f | %f %f %f\n", j, dref, Io, Chisq, rMin, iMin, xMin);
     1328    }
     1329
     1330    psEllipseAxes guessAxes;
     1331    guessAxes.major = centerAxes.major + rMin;
     1332    guessAxes.minor = guessAxes.major * centerAxes.minor / centerAxes.major;
     1333    guessAxes.theta = centerAxes.theta;
     1334
     1335    if (!isfinite(guessAxes.major)) return false;
     1336    if (!isfinite(guessAxes.minor)) return false;
     1337    if (!isfinite(guessAxes.theta)) return false;
     1338
     1339    // convert the major,minor,theta to shape parameters for an Reff-like model
     1340    pmModelAxesToParams (&PAR[PM_PAR_SXX], &PAR[PM_PAR_SXY], &PAR[PM_PAR_SYY], guessAxes, true);
     1341    PAR[PM_PAR_I0] = iMin;
     1342
     1343    return true;
     1344}
     1345
  • branches/eam_branches/ipp-20130904/psphot/test/tap_psphot_galaxygrid.pro

    r36307 r36310  
    607607  $psphotConfig = $psphotConfig -Db PSPHOT:POISSON.ERRORS.PHOT.LMM F
    608608  $psphotConfig = $psphotConfig -Db PSPHOT:EXTENDED_SOURCE_FITS_POISSON F
     609   $psphotConfig = $psphotConfig -Di PSPHOT:EXT_FIT_ITER 40
    609610
    610611  # ppImage / psphot on the output
     
    614615  exec ppImage $ppImageConfig $psphotConfig -file $basename.fits $outname >>& $outname.log
    615616  break -auto on
     617end
     618
     619macro cmf.load.reset
     620  $fields = X Y M T R r MT
     621  foreach field $fields
     622    foreach set in ot
     623      delete -q $field\$set\_s
     624    end
     625  end
     626
     627  delete -q min_S Min_S
    616628end
    617629
     
    12621274  local radius Nrun
    12631275
     1276  if (1)
     1277    $Nrun = 0
     1278    foreach radius 1.0 1.5 2.0 2.5 3.0 4.0 6.0 8.0
     1279      # mkexp.devexp.single tests.20131120/testrad.ps1v1.exp.$Nrun EXP $radius 1.0
     1280      fitexp tests.20131120/testrad.ps1v1.exp.$Nrun tests.20131120/testrad.ps1v1.exp.$Nrun.t4s EXP_CONV
     1281      $Nrun ++
     1282    end
     1283  end
     1284
    12641285  $Nrun = 0
    12651286  foreach radius 1.0 1.5 2.0 2.5 3.0 4.0 6.0 8.0
    1266     mkexp.devexp.single tests.20131120/testrad.ps1v1.exp.$Nrun EXP $radius 1.0
    1267     fitexp tests.20131120/testrad.ps1v1.exp.$Nrun tests.20131120/testrad.ps1v1.exp.$Nrun.t4 EXP_CONV
    1268     $Nrun ++
    1269   end
    1270 
    1271   $Nrun = 0
    1272   foreach radius 1.0 1.5 2.0 2.5 3.0 4.0 6.0 8.0
    1273     cmf.load.concat tests.20131120/testrad.ps1v1.exp.$Nrun.dat tests.20131120/testrad.ps1v1.exp.$Nrun.t4.cmf EXP
     1287    cmf.load.concat tests.20131120/testrad.ps1v1.exp.$Nrun.dat tests.20131120/testrad.ps1v1.exp.$Nrun.t4s.cmf EXP
    12741288    set dM_m = Mot_m - Min_m
    12751289    vstat -q dM_m
     
    12841298  grid.plots.devexp a
    12851299end
     1300
     1301macro check.radius.loop
     1302  if ($0 != 2)
     1303    echo "USAGE: check.radius.loop (ext)"
     1304    break
     1305  end
     1306
     1307  # cmf.load.reset
     1308
     1309  local radius Nrun
     1310
     1311  $Nrun = 0
     1312  foreach radius 1.0 1.5 2.0 2.5 3.0 4.0 6.0 8.0
     1313    cmf.load.concat tests.20131120/testrad.ps1v1.exp.$Nrun.dat tests.20131120/testrad.ps1v1.exp.$Nrun.$1.cmf EXP
     1314    set dM_m = Mot_m - Min_m
     1315    vstat -q dM_m
     1316    $mag_off = $MEDIAN
     1317    set dR_m = Rot_m - Rin_m
     1318    vstat -q dR_m
     1319    $rad_off = $MEDIAN
     1320    echo $radius $mag_off $rad_off
     1321    $Nrun ++
     1322  end
     1323
     1324  grid.plots.devexp a
     1325end
     1326
     1327macro check.fit
     1328  if ($0 != 3)
     1329    echo "USAGE: check.fit (dat) (cmf)"
     1330    break
     1331  end
     1332
     1333  cmf.load.concat $1 $2 EXP
     1334  set dM_m = Mot_m - Min_m
     1335  vstat -q dM_m
     1336  $mag_off = $MEDIAN
     1337  set dR_m = Rot_m - Rin_m
     1338  vstat -q dR_m
     1339  $rad_off = $MEDIAN
     1340  echo $mag_off $rad_off
     1341end
Note: See TracChangeset for help on using the changeset viewer.