IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38552


Ignore:
Timestamp:
Jun 25, 2015, 10:05:06 PM (11 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ipp-20150616
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20150616

  • branches/eam_branches/ipp-20150616/ippScripts/scripts/staticsky.pl

    r37915 r38552  
    4343    print "USAGE: staticsky.pl --sky_id (sky_id) --outroot (root) --camera (camera) [options]\n";
    4444    print "  --sky_id (sky_id)   : run identifier\n";
     45    print "  --run-state (state) : run state (new or update)\n";
    4546    print "  --camera (camera)   : Camera name\n";
    4647    print "  --dbname (dbname)   : Database name\n";
     
    6263
    6364my ($sky_id, $camera, $dbname, $threads, $outroot, $reduction, $require_sources, $verbose, $no_update, $no_op, $redirect, $save_temps);
     65my $run_state ='new';
     66
    6467GetOptions(
    6568    'sky_id=s'          => \$sky_id, # Diff identifier
     69    'run-state=s'       => \$run_state,
    6670    'camera|c=s'        => \$camera, # Camera name
    6771    'dbname|d=s'        => \$dbname, # Database name
     
    8892    defined $camera;
    8993
     94
     95&my_die("unexpected run state: $run_state",  $sky_id, $PS_EXIT_PROG_ERROR) unless ($run_state eq 'new') or ($run_state eq 'update');
     96my $updatemode = $run_state eq 'update';
     97
    9098my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $sky_id, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
    9199
     
    126134my $nInputs = @$files;
    127135
    128 if (1) {
     136{
    129137        my $recipe_psphot  = $ipprc->reduction($reduction, 'STACKPHOT_PSPHOT'); # Recipe to use for psphot
    130138        my $recipe_ppsub   = $ipprc->reduction($reduction, 'STACKPHOT_PPSUB'); # Recipe to use for ppsub
     
    163171            my $expnumRaw = $ipprc->filename("PPSTACK.UNCONV.EXPNUM",   $path_base ); # Expnum name
    164172
    165             my $sources   = $ipprc->filename("PSPHOT.OUT.CMF.MEF",      $path_base ); # Sources name
     173            my $sources;
     174            my ($psfRaw, $backmdlRaw);
     175            if (!$updatemode) {
     176                # sources from stack run.
     177                # XXX: We don't need this file anymore.
     178                $sources   = $ipprc->filename("PSPHOT.OUT.CMF.MEF",      $path_base ); # Sources name
     179            } else {
     180                # name of output sources from this run when in new state
     181                $require_sources = 1 unless $no_op;
     182                $sources  = $ipprc->filename("PSPHOT.STACK.OUTPUT", $outroot, $stack_id);
     183                # During update we rename the sources file to this
     184                my $originalSources = "$sources.original";
     185                if (!$ipprc->file_exists($originalSources)) {
     186                    if ($ipprc->file_exists($sources)) {
     187                        unless ($no_op) {
     188                            if (!$ipprc->file_rename($sources, $originalSources)) {
     189                                &my_die("failed to rename $sources $originalSources",  $sky_id, $PS_EXIT_PROG_ERROR);
     190                            }
     191                        }
     192                    } else {
     193                        # maybe this should be a fault 2
     194                        &my_die("failed to to find either sources file to update as either $sources or $originalSources",  $sky_id, $PS_EXIT_PROG_ERROR);
     195                    }
     196                }
     197                $sources = $originalSources;
     198                $psfRaw  = $ipprc->filename("PSPHOT.STACK.PSF.SAVE", $outroot, $stack_id);
     199                $backmdlRaw  = $ipprc->filename("PSPHOT.STACK.BACKMDL", $outroot, $stack_id);
     200            }
     201
    166202
    167203            # XXX is this the correct PSF file?
     
    194230                print $listFile "  SOURCES       STR  " . $sources   . "\n";
    195231            }
     232            if ($updatemode) {
     233                &my_die("Couldn't find input: $psfRaw", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$psfRaw");
     234                &my_die("Couldn't find input: $backmdlRaw",    $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$backmdlRaw");
     235                print $listFile "  RAW:PSF       STR  " . $psfRaw . "\n";
     236                print $listFile "  RAW:BACKMDL   STR  " . $backmdlRaw . "\n";
     237            }
    196238            if ($needConvolvedImages) {
    197239                print $listFile "  CNV:IMAGE     STR  " . $imageCnv  . "\n";
     
    205247        }
    206248
    207         # my $cmdflags;
     249        close $listFile;
    208250
    209251        # Perform stack photometry analysis
    210252        {
    211253            my $command = "$psphotStack $outroot";
     254            $command .= " -updatemode" if $updatemode;
    212255            $command .= " -input $listName";
    213256            $command .= " -threads $threads" if defined $threads;
     
    215258            $command .= " -recipe PPSUB   $recipe_ppsub";
    216259            $command .= " -recipe PPSTACK $recipe_ppstack";
    217             $command .= " -dumpconfig $configuration";
     260            $command .= " -dumpconfig $configuration" if !$updatemode;
    218261            $command .= " -tracedest $traceDest -log $logDest";
    219262            # $command .= " -dbname $dbname" if defined $dbname;
     
    275318                    # &my_die("Couldn't find expected output file: $chisqMask",           $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqMask);
    276319                    # &my_die("Couldn't find expected output file: $chisqVariance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqVariance);
     320
     321                    if (!$updatemode) {
     322                        # XXX: should be checking for existence of psf and backmdl output files
     323                    }
    277324                }
    278325            } else {
     
    280327            }
    281328        }
    282 } else {
    283     # XXX This mode is no longer used. We run psphotStack even if there is only one filter
    284         # single input. Run psphot
    285         # find the recipe
    286         my $recipe_psphot  = $ipprc->reduction($reduction, 'STACKPHOT_SINGLE_PSPHOT'); # Recipe to use for psphot
    287         unless ($recipe_psphot) {
    288             &my_die("Couldn't find selected reduction for STACKPHOT: $reduction\n", $sky_id, $PS_EXIT_CONFIG_ERROR);
    289         }
    290 
    291         print "reduction:      $reduction\n";
    292         print "recipe_psphot:  $recipe_psphot\n";
    293 
    294         my $configuration = $ipprc->filename("PSPHOT.SKY.CONFIG", $outroot);
    295 
    296         my $file = $files->[0];
    297 
    298         # XXX if we take the input from 'warp', we will need to make different selections here
    299         my $path_base = $file->{path_base};
    300         print "input: $path_base\n";
    301 
    302         # examine the recipe to determine whether to analyze the "raw" or convolved images
    303         my $command = "$ppConfigDump -camera $camera -dump-recipe PSPHOT -recipe PSPHOT $recipe_psphot -";
    304         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    305         run(command => $command, verbose => 0);
    306         unless ($success) {
    307             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    308             &my_die("Unable to perform ppConfigDump: $error_code", $sky_id, $PS_EXIT_SYS_ERROR);
    309         }
    310         my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
    311             &my_die("Unable to parse metadata config doc", $sky_id, $PS_EXIT_SYS_ERROR);
    312 
    313         my $use_raw = metadataLookupBool($recipeData, 'PSPHOT.STACK.USE.RAW');
    314 
    315         my ($image, $mask, $variance, $expnum);
    316         if ($use_raw) {
    317             $image  = $ipprc->filename("PPSTACK.UNCONV",          $path_base ); # Image name
    318             $mask   = $ipprc->filename("PPSTACK.UNCONV.MASK",     $path_base ); # Mask name
    319             $variance = $ipprc->filename("PPSTACK.UNCONV.VARIANCE", $path_base ); # Weight name
    320             $expnum = $ipprc->filename("PPSTACK.OUTPUT.EXPNUM", $path_base ); # Expnum name
    321         } else {
    322             $image  = $ipprc->filename("PPSTACK.OUTPUT",          $path_base ); # Image name
    323             $mask   = $ipprc->filename("PPSTACK.OUTPUT.MASK",     $path_base ); # Mask name
    324             $variance = $ipprc->filename("PPSTACK.OUTPUT.VARIANCE", $path_base ); # Weight name
    325             $expnum = $ipprc->filename("PPSTACK.OUTPUT.EXPNUM", $path_base ); # Expnum name
    326         }
    327 
    328         my $output_sources_filerule = "PSPHOT.OUT.CMF.MEF";
    329         my $output_psf_filerule = "PSPHOT.PSF.SKY.SAVE";
    330 
    331         # XXX we could make some different choices if some inputs do not exist...
    332         &my_die("Couldn't find input: $image",  $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$image");
    333         &my_die("Couldn't find input: $mask",   $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$mask");
    334         &my_die("Couldn't find input: $variance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$variance");
    335         &my_die("Couldn't find input: $expnum", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$expnum");
    336 
    337         # Perform stack photometry analysis
    338         {
    339             my $command = "$psphot $outroot";
    340             $command .= " -file $image";
    341             $command .= " -mask $mask";
    342             $command .= " -variance $variance";
    343             $command .= " -expnum $expnum";
    344             $command .= " -threads $threads" if defined $threads;
    345             $command .= " -recipe PSPHOT  $recipe_psphot";
    346             $command .= " -dumpconfig $configuration" if $configuration;
    347             $command .= " -tracedest $traceDest -log $logDest";
    348             $command .= " -F PSPHOT.OUTPUT $output_sources_filerule";
    349             $command .= " -F PSPHOT.PSF.SAVE $output_psf_filerule";
    350 
    351             unless ($no_op) {
    352                 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
    353                 unless ($success) {
    354                     $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    355                     &my_die("Unable to perform psphot: $error_code", $sky_id, $error_code);
    356                 }
    357 
    358                 my $quality = 0;
    359                 if (!$quality) {
    360                     my $outputSources  = $ipprc->filename($output_sources_filerule, $outroot);
    361                     &my_die("Couldn't find expected output file: $outputSources", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
    362                     my $outputPSF  = $ipprc->filename($output_psf_filerule, $outroot);
    363                     &my_die("Couldn't find expected output file: $outputPSF", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputPSF);
    364                 }
    365 
    366                 &my_die("Couldn't find expected output file: $configuration", $sky_id, $PS_EXIT_SYS_ERROR)
    367                     unless $ipprc->file_exists($configuration);
    368             } else {
    369                 print "Not executing: $command\n";
    370             }
    371         }
    372329}
    373330
     
    377334    {
    378335        my $command = "$staticskytool -sky_id $sky_id";
    379         $command .= " -addresult -path_base $outroot";
    380         $command .= " -num_inputs $nInputs";
    381         # $command .= " $cmdflags";
    382         $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
    383         $command .= " -hostname $host" if defined $host;
    384         $command .= " -dbname $dbname" if defined $dbname;
     336        if ($updatemode) {
     337            $command .= " -updaterun -set_state full";
     338        } else {
     339            $command .= " -addresult -path_base $outroot";
     340            $command .= " -num_inputs $nInputs";
     341            $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
     342            $command .= " -hostname $host" if defined $host;
     343            $command .= " -dbname $dbname" if defined $dbname;
     344        }
    385345
    386346        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    388348        unless ($success) {
    389349            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    390             my $err_message = "Unable to perform staticskytool -addresult";
     350            my $err_message = "Unable to perform: $command\n";
    391351            warn($err_message);
    392352            exit $error_code;
     
    406366    warn($msg);
    407367    if (defined $sky_id and not $no_update) {
     368       
    408369        my $command = "$staticskytool -sky_id $sky_id -fault $exit_code";
    409         $command .= " -addresult";
    410         $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
    411         $command .= " -hostname $host" if defined $host;
    412         $command .= " -path_base $outroot" if defined $outroot;
    413         $command .= " -dbname $dbname" if defined $dbname;
     370        if ($updatemode) {
     371            $command .= " -updateresult";
     372        } else {
     373            $command .= " -addresult";
     374            $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
     375            $command .= " -hostname $host" if defined $host;
     376            $command .= " -path_base $outroot" if defined $outroot;
     377            $command .= " -dbname $dbname" if defined $dbname;
     378        }
    414379        run(command => $command, verbose => $verbose);
    415380    }
  • branches/eam_branches/ipp-20150616/ippTasks/staticsky.pro

    r36555 r38552  
    172172    # set.host.for.skycell $SKYCELL_ID
    173173    host anyhost
    174     set.workdir.by.skycell $SKYCELL_ID $WORKDIR_TEMPLATE $default_host WORKDIR
    175 
    176     basename $TESS_DIR -var TESS_ID
     174
    177175    if ("$PATH_BASE" == "NULL")
     176        set.workdir.by.skycell $SKYCELL_ID $WORKDIR_TEMPLATE $default_host WORKDIR
     177        basename $TESS_DIR -var TESS_ID
    178178        sprintf outroot "%s/%s/%s/%s.%s.sky.%s" $WORKDIR $TESS_ID $SKYCELL_ID $TESS_ID $SKYCELL_ID $SKY_ID
    179179    else
     180        # run-state must be update use existing path_base
    180181        $outroot = $PATH_BASE
    181182    end
     
    184185    stderr $LOGDIR/staticsky.log
    185186
    186     $run = staticsky.pl --threads @MAX_THREADS@ --sky_id $SKY_ID --outroot $outroot --redirect-output --camera $CAMERA
     187    $run = staticsky.pl --sky_id $SKY_ID --run-state $RUN_STATE --outroot $outroot --redirect-output --camera $CAMERA  --threads @MAX_THREADS@
    187188    if ("$REDUCTION" != "NULL")
    188189      $run = $run --reduction $REDUCTION
  • branches/eam_branches/ipp-20150616/psLib/src/fits/psFitsImage.c

    r37050 r38552  
    751751
    752752    // Remove any BOFFSET values that exist in the header if we are not using that scaling anymore
    753     if (options&&(!((options->scaling == PS_FITS_SCALE_LOG_RANGE)||
    754                     (options->scaling == PS_FITS_SCALE_LOG_MANUAL)||
    755                     (options->scaling == PS_FITS_SCALE_LOG_STDEV_POSITIVE)||
    756                     (options->scaling == PS_FITS_SCALE_LOG_STDEV_NEGATIVE)||
    757                     (options->scaling == PS_FITS_SCALE_LOG_STDEV_BOTH)||
    758                     (options->scaling == PS_FITS_SCALE_ASINH_RANGE)||
    759                     (options->scaling == PS_FITS_SCALE_ASINH_MANUAL)||
    760                     (options->scaling == PS_FITS_SCALE_ASINH_STDEV_POSITIVE)||
    761                     (options->scaling == PS_FITS_SCALE_ASINH_STDEV_NEGATIVE)||
    762                     (options->scaling == PS_FITS_SCALE_ASINH_STDEV_BOTH)))) {
    763       if (psMetadataLookup(header,"BOFFSET")) {
     753    if (options && (!((options->scaling == PS_FITS_SCALE_LOG_RANGE)||
     754                      (options->scaling == PS_FITS_SCALE_LOG_MANUAL)||
     755                      (options->scaling == PS_FITS_SCALE_LOG_STDEV_POSITIVE)||
     756                      (options->scaling == PS_FITS_SCALE_LOG_STDEV_NEGATIVE)||
     757                      (options->scaling == PS_FITS_SCALE_LOG_STDEV_BOTH)||
     758                      (options->scaling == PS_FITS_SCALE_ASINH_RANGE)||
     759                      (options->scaling == PS_FITS_SCALE_ASINH_MANUAL)||
     760                      (options->scaling == PS_FITS_SCALE_ASINH_STDEV_POSITIVE)||
     761                      (options->scaling == PS_FITS_SCALE_ASINH_STDEV_NEGATIVE)||
     762                      (options->scaling == PS_FITS_SCALE_ASINH_STDEV_BOTH)))) {
     763      if (header && psMetadataLookup(header,"BOFFSET")) {
    764764        psMetadataRemoveKey(header,"BOFFSET");
    765765      }
    766766    }   
    767767    // Remove any BSOFTENvalues that exist in the header if we are not using that scaling anymore
    768     if (options&&(!((options->scaling == PS_FITS_SCALE_ASINH_RANGE)||
    769                     (options->scaling == PS_FITS_SCALE_ASINH_MANUAL)||
    770                     (options->scaling == PS_FITS_SCALE_ASINH_STDEV_POSITIVE)||
    771                     (options->scaling == PS_FITS_SCALE_ASINH_STDEV_NEGATIVE)||
    772                     (options->scaling == PS_FITS_SCALE_ASINH_STDEV_BOTH)))) {
    773       if (psMetadataLookup(header,"BSOFTEN")) {
     768    if (options && (!((options->scaling == PS_FITS_SCALE_ASINH_RANGE)||
     769                      (options->scaling == PS_FITS_SCALE_ASINH_MANUAL)||
     770                      (options->scaling == PS_FITS_SCALE_ASINH_STDEV_POSITIVE)||
     771                      (options->scaling == PS_FITS_SCALE_ASINH_STDEV_NEGATIVE)||
     772                      (options->scaling == PS_FITS_SCALE_ASINH_STDEV_BOTH)))) {
     773      if (header && psMetadataLookup(header,"BSOFTEN")) {
    774774        psMetadataRemoveKey(header,"BSOFTEN");
    775775      }
    776776    }   
    777777
    778     // If there is no options set, remove all our non-standard keywords, because no one asked for them.
     778    // If there are no options set, remove all our non-standard keywords, because no one asked for them.
    779779    if (!options) {
    780       if (psMetadataLookup(header,"BOFFSET")) {
     780      if (header && psMetadataLookup(header,"BOFFSET")) {
    781781        psMetadataRemoveKey(header,"BOFFSET");
    782782      }
    783       if (psMetadataLookup(header,"BSOFTEN")) {
     783      if (header && psMetadataLookup(header,"BSOFTEN")) {
    784784        psMetadataRemoveKey(header,"BSOFTEN");
    785785      }
  • branches/eam_branches/ipp-20150616/psphot/src/psphot.h

    r38388 r38552  
    513513bool psphotSourceChildren (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc);
    514514bool psphotSourceChildrenReadout (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc, int index);
    515 psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objectsSrc, bool sourcesSubtracted);
     515psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *fileruleOut, const char *fileruleSrc, psArray *objectsSrc, bool sourcesSubtracted);
    516516
    517517bool psphotSourceParents (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc);
  • branches/eam_branches/ipp-20150616/psphot/src/psphotExtendedSourceFits.c

    r37881 r38552  
    149149    fitOptions->poissonErrors = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_FITS_POISSON");
    150150    if (!status) fitOptions->poissonErrors = true;
     151
     152    // Save pointer to fitOptions for possible use later reinstantiating the pcm models on the output readout
     153    // and during radial apertures measurements.
     154    psMetadataAddPtr (readout->analysis, PS_LIST_TAIL, "PCM_FIT_OPTIONS", PS_DATA_UNKNOWN | PS_META_REPLACE, "pcm fit options",
     155        fitOptions);
    151156
    152157    // maskVal is used to test for rejected pixels, and must include markVal
  • branches/eam_branches/ipp-20150616/psphot/src/psphotFitSourcesLinear.c

    r38039 r38552  
    269269            continue;
    270270        }
    271         if (modelSum < 0.5) continue; // skip sources with no model constraint (somewhat arbitrary limit)
    272         if (modelSum < 0.8) {
    273             psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "low-sig model @ %f, %f (%f masked sum, %f sum, %f peak)\n",
    274                      source->peak->xf, source->peak->yf, maskedSum, modelSum, source->peak->rawFlux);
    275         }
    276         if (maskedSum < 0.5) {
    277             psLogMsg ("psphot.ensemble",  PS_LOG_MINUTIA, "worrying model @ %f, %f (%f masked sum, %f sum, %f peak)\n",
    278                      source->peak->xf, source->peak->yf, maskedSum, modelSum, source->peak->rawFlux);
    279         }
    280 
    281271        bool isPSF = false;
    282272        pmModel *model = pmSourceGetModel (&isPSF, source);
     273
     274        float Io = model->params->data.F32[PM_PAR_I0];
     275        model->params->data.F32[PM_PAR_I0] = 1.0;
     276        float normFlux = model->class->modelFlux(model->params);
     277        model->params->data.F32[PM_PAR_I0] = Io;
     278
     279        // printf("%5d %4.3f %4.3f %4.3f\n", source->seq, normFlux, modelSum, maskedSum);
     280        float cut = .85;
     281        if (modelSum  < cut * normFlux) continue;
     282        if (maskedSum < cut * normFlux) continue;
    283283
    284284        // clear the 'mark' pixels and remask on the fit aperture
  • branches/eam_branches/ipp-20150616/psphot/src/psphotGalaxyParams.c

    r38302 r38552  
    581581
    582582        if (bgPixels->n < numPixels) {
    583             fprintf(stderr, "could not find enough background pixels for source %d found %ld need %d\n", source->id, bgPixels->n, numPixels);
     583            // fprintf(stderr, "could not find enough background pixels for source %d found %ld need %d\n", source->id, bgPixels->n, numPixels);
    584584            goto restoreModel;
    585585        }
  • branches/eam_branches/ipp-20150616/psphot/src/psphotMergeSources.c

    r38389 r38552  
    853853// array containing the child sources.  XXX currently, this is only used by psphotStackReadout
    854854// (sources go on allSources so that psphotChoosePSF can be called repeatedly)
    855 psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objectsSrc, bool sourcesSubtracted) {
     855psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *fileruleOut, const char *fileruleSrc, psArray *objectsSrc, bool sourcesSubtracted) {
    856856
    857857    bool status;
    858858
    859     int nImages = psphotFileruleCount(config, filerule);
     859    int nImages = psphotFileruleCount(config, fileruleOut);
    860860
    861861    // generate look-up arrays for detections and readouts
    862862    psArray *detArrays = psArrayAlloc(nImages);
    863863    psArray *readouts = psArrayAlloc(nImages);
     864    psArray *fitOptionsArray = psArrayAlloc(nImages);
     865
     866    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
     867    assert (recipe);
     868    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
     869    assert (maskVal);
     870    int psfSize  = psMetadataLookupS32 (&status, recipe, "PCM_BOX_SIZE");
     871    assert (status);
    864872
    865873    for (int i = 0; i < nImages; i++) {
    866874
    867875        // find the currently selected readout
    868         pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest
     876        pmFPAfile *file = pmFPAfileSelectSingle(config->files, fileruleOut, i); // File of interest
    869877        psAssert (file, "missing file?");
    870878
    871879        pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
    872880        psAssert (readout, "missing readout?");
     881
     882        pmFPAfile *fileSrc = pmFPAfileSelectSingle(config->files, fileruleSrc, i); // File of interest
     883        psAssert (file, "missing file?");
     884
     885        pmReadout *readoutSrc = pmFPAviewThisReadout(view, fileSrc->fpa);
     886        psAssert (readoutSrc, "missing readout?");
     887
    873888
    874889        // create DETECTIONS containers for each image, in case one lacks it
     
    886901            psAssert (detections, "missing detections?");
    887902        }
     903        pmSourceFitOptions *fitOptions = NULL;
     904        if (psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_FITS")) {
     905            fitOptions = psMetadataLookupPtr (&status, readoutSrc->analysis, "PCM_FIT_OPTIONS");
     906            psAssert (fitOptions, "missing pcm fit options");
     907            psMetadataAddPtr (readout->analysis, PS_LIST_TAIL, "PCM_FIT_OPTIONS", PS_DATA_UNKNOWN | PS_META_REPLACE, "pcm fit options", fitOptions);
     908        }
    888909
    889910        // we need to save the new sources on the detection arrays of the appropriate image
    890911        detArrays->data[i] = psMemIncrRefCounter(detections);
    891912        readouts->data[i] = psMemIncrRefCounter(readout);
     913        if (fitOptions) {
     914            fitOptionsArray->data[i] = psMemIncrRefCounter(fitOptions);
     915        }
    892916    }
    893917
     
    932956            // does this copy all model data? (NO)
    933957            sourceOut->modelPSF = pmModelCopy(sourceSrc->modelPSF);
    934             sourceOut->modelEXT = pmModelCopy(sourceSrc->modelEXT);
    935 
     958
     959            bool foundModelEXT = false;
    936960            if (sourceSrc->modelFits) {
    937961                sourceOut->modelFits = psArrayAlloc(sourceSrc->modelFits->n);
    938962                for (int j = 0; j < sourceSrc->modelFits->n; j++) {
    939                     sourceOut->modelFits->data[j] = pmModelCopy(sourceSrc->modelFits->data[j]);
    940                 }
     963                    pmModel *modelSrc = sourceSrc->modelFits->data[j];
     964                    pmModel *modelOut = sourceOut->modelFits->data[j] = pmModelCopy(modelSrc);
     965                    if (modelSrc == sourceSrc->modelEXT) {
     966                        foundModelEXT = true;
     967                        sourceOut->modelEXT = psMemIncrRefCounter (modelOut);
     968                    }
     969                    modelOut->isPCM = modelSrc->isPCM;
     970                }
    941971            }
     972            if (!foundModelEXT && sourceSrc->modelEXT) {
     973                // Will this ever happen?
     974                sourceOut->modelEXT = pmModelCopy(sourceSrc->modelEXT);
     975            }
    942976
    943977            // drop the references to the original image pixels:
     
    949983            pmReadout *readout = readouts->data[index];
    950984
     985            pmSourceFitOptions *fitOptions = fitOptionsArray->data[index];
     986
    951987            // allocate image, weight, mask for the new image for each peak
    952988            if (sourceOut->modelPSF) {
    953989                pmSourceRedefinePixels (sourceOut, readout, sourceOut->peak->x, sourceOut->peak->y,
    954                                                                         sourceOut->modelPSF->fitRadius);
     990                                                                        sourceSrc->windowRadius);
    955991            } else {
    956992                // if we have no pixels we can't use it to determine the psf so make sure this bit is off
     
    9651001            if (!sourcesSubtracted) {
    9661002                sourceOut->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
    967             }
     1003            } else {
     1004                bool isPSF = false;
     1005                pmModel *model = pmSourceGetModel (&isPSF, sourceOut);
     1006                if (model && sourceSrc->modelFlux) {
     1007                    if (model->isPCM) {
     1008                        pmPCMdata *pcm = pmPCMinit (sourceOut, fitOptions, model, maskVal, psfSize);
     1009                        if (pcm) {
     1010                            // pmPCMMakeModel (sourceOut, model, pcm->nsigma, maskVal, psfSize);
     1011                            pmPCMCacheModel (sourceOut, maskVal, psfSize, pcm->nsigma);
     1012                            psFree(pcm);
     1013                        } else {
     1014                            // What to do here?
     1015                            psAssert (pcm, "pmPCMinit failed!");
     1016                        }
     1017                    } else {
     1018                        pmSourceCacheModel (sourceOut, maskVal);
     1019                    }
     1020                }
     1021            }
    9681022
    9691023            // set the output detections:
     
    9811035    psFree (detArrays);
    9821036    psFree (readouts);
     1037    psFree (fitOptionsArray);
    9831038
    9841039    return objectsOut;
  • branches/eam_branches/ipp-20150616/psphot/src/psphotModelBackground.c

    r38387 r38552  
    558558
    559559    fprintf (stdout, "\n");
    560     psLogMsg ("psphot", PS_LOG_INFO, "--- psphot Model Background ---");
     560    psLogMsg ("psphot", PS_LOG_INFO, "--- psphot Load Background Model ---");
    561561
    562562    // loop over the available readouts
  • branches/eam_branches/ipp-20150616/psphot/src/psphotReplaceUnfit.c

    r35769 r38552  
    316316    }
    317317
     318    pmSourceFitOptions *fitOptions = NULL;
     319    if (psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_FITS")) {
     320        fitOptions = psMetadataLookupPtr (&status, readout->analysis, "PCM_FIT_OPTIONS");
     321        psAssert (fitOptions, "missing pcm fit options");
     322    }
    318323
    319324    // XXX the sources have already been copied (merge into here?)
     
    368373            source->modelPSF = modelPSF;
    369374            source->modelPSF->fitRadius = radius;
    370             model = source->modelPSF;
     375            //  model = source->modelPSF;
    371376        }
    372377
    373378        if (model->isPCM) {
     379#if 0
    374380            psAssert(false, "this section is not complete");
    375381
     
    389395
    390396            psImageConvolveFFT (source->modelFlux, rawModelFlux, NULL, 0, psfKernel);
    391          
    392397            psFree (psfKernel);
    393398            psFree (rawModelFlux);
    394         }
    395 
    396         pmSourceCacheModel (source, maskVal);  // ALLOC x14 (!)
     399#endif
     400           pmPCMdata *pcm = pmPCMinit (source, fitOptions, model, maskVal, psfSize);
     401            if (pcm) {
     402                pmPCMCacheModel (source, maskVal, psfSize, pcm->nsigma);
     403                psFree(pcm);
     404            } else {
     405                psAssert (pcm, "pmPCMinit failed!");
     406            }
     407         
     408        } else {
     409            pmSourceCacheModel (source, maskVal);  // ALLOC x14 (!)
     410        }
    397411    }
    398412
  • branches/eam_branches/ipp-20150616/psphot/src/psphotStackReadout.c

    r38385 r38552  
    3535        psphotSaveImage (NULL, readout->mask, line);
    3636    }
     37    // psphotSaveImage leaves an error on the stack
     38    psErrorClear();
    3739    return true;
    3840}
     
    348350    // XXX NOTE : if we use the pre-20130914 psphotStackReadout code, we need to use 'false' for the
    349351    // sourcesSubtracted argument
    350     psArray *objectsOut = psphotSourceChildrenByObject (config, view, STACK_OUT, objects, true);
     352
     353    // do this here so that the variance image is available to reset the models
     354    psphotStackMatchPSFsetup (config, view, STACK_OUT, STACK_RAW);
     355    psArray *objectsOut = psphotSourceChildrenByObject (config, view, STACK_OUT, STACK_RAW, objects, true);
    351356    if (!objectsOut) {
    352357        psFree(objects);
     
    364369
    365370        // set up the FWHM vector
    366         psphotStackMatchPSFsetup (config, view, STACK_OUT, STACK_RAW);
    367371        psphotDumpImages (config, view, STACK_RAW, "raw.t0");
    368372        psphotDumpImages (config, view, STACK_OUT, "out.t0");
  • branches/eam_branches/ipp-20150616/psphot/src/psphotStackUpdateReadout.c

    r38396 r38552  
    116116    // XXX NOTE : if we use the pre-20130914 psphotStackReadout code, we need to use 'false' for the
    117117    // sourcesSubtracted argument
    118     psArray *objectsOut = psphotSourceChildrenByObject (config, view, STACK_OUT, objects, true);
     118    // XXX: do this here so that the variance is availble to rebuild the models
     119    psphotStackMatchPSFsetup (config, view, STACK_OUT, STACK_RAW);
     120    psArray *objectsOut = psphotSourceChildrenByObject (config, view, STACK_OUT, STACK_RAW, objects, true);
    119121    if (!objectsOut) {
    120122        psFree(objects);
     
    135137        // this forces photometry on the undetected sources from other images
    136138
    137         // set up the FWHM vector
    138         psphotStackMatchPSFsetup (config, view, STACK_OUT, STACK_RAW);
     139//      Moved this up above
     140//      psphotStackMatchPSFsetup (config, view, STACK_OUT, STACK_RAW);
    139141        psphotDumpImages (config, view, STACK_RAW, "raw.t0");
    140142        psphotDumpImages (config, view, STACK_OUT, "out.t0");
     
    177179                // and to subtract the sources
    178180                psphotFitSourcesLinear (config, view, STACK_OUT, false, false);
     181
     182#ifdef notyet
     183            psphotRemoveAllSources (config, view, STACK_OUT, false);
     184#endif
     185
    179186                snprintf (line, 256, "%s.%d", "out.t4", entry);
    180187                psphotDumpImages (config, view, STACK_OUT, line);
     
    221228        COPY_PARAM( "MSKY_NX" );
    222229        COPY_PARAM( "MSKY_NY" );
    223         COPY_PARAM( "CHIP_SEEING" );
     230        // COPY_PARAM( "CHIP_SEEING" );
    224231}
    225232
     
    293300    maskVal |= markVal;
    294301
     302    // This code currently assumes that all extended source models are PCM.
     303    // Examine the recipe and make sure that this is true.
     304    psMetadata *allModels = psMetadataLookupMetadata (&status, recipe, "EXTENDED_SOURCE_MODELS");
     305    if (!status) {
     306        psAssert (allModels, "failed to find list of extended source models\n");
     307    }
     308    psMetadataIterator *iter = psMetadataIteratorAlloc (allModels, PS_LIST_HEAD, NULL);
     309    psMetadataItem *item = NULL;
     310    while ((item = psMetadataGetAndIncrement (iter)) != NULL) {
     311        if (item->type != PS_DATA_METADATA) {
     312            psAbort ("Invalid type for EXTENDED_SOURCE_MODEL entry %s, not a metadata folder", item->name);
     313        }
     314        psMetadata *model = (psMetadata *) item->data.md;
     315        // char *modelName = psMetadataLookupStr (&status, model, "MODEL");
     316
     317        char *convolvedWord = psMetadataLookupStr (&status, model, "PSF_CONVOLVED");
     318        if (!status || (strcasecmp (convolvedWord, "true") && strcasecmp (convolvedWord, "false"))) {
     319            psAbort ("PSF_CONVOLVED entry invalid or missing for EXTENDED_SOURCE_MODEL entry %s", item->name);
     320        }
     321        bool convolved = !strcasecmp (convolvedWord, "true");
     322        psAssert (convolved, "EXTENDED SOURCE model %s is not convolved. This code is not ready for that\n", item->name);
     323    }
     324    psFree (iter);
     325
    295326    // setup the PSF fit radius details
    296327    psphotInitRadiusPSF (recipe, readout);
     
    312343    fitOptions->poissonErrors = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_FITS_POISSON");
    313344    if (!status) fitOptions->poissonErrors = true;
     345
    314346    int psfSize  = psMetadataLookupS32 (&status, recipe, "PCM_BOX_SIZE");
    315347    assert (status);
     348   
     349    // Remember these data for later
     350    psMetadataAddPtr (readout->analysis, PS_LIST_TAIL, "PCM_FIT_OPTIONS", PS_DATA_UNKNOWN | PS_META_REPLACE, "pcm fit options", fitOptions);
    316351
    317352    for (int i = 0; i < sources->n; i++) {
     
    331366            // fprintf(stderr, "source %d %5d should not have a psf model 0x%08X%08X\n", index, source->seq, source->mode2, source->mode);
    332367            psFree(source->modelPSF) ;
     368            modelPSF = NULL;
     369            // At least once I saw a source with an extended model but no psf model
     370            psFree(source->modelEXT);
     371            source->modelEXT = NULL;
    333372        }
    334373
    335374        // make sure that the window radius is large enough. Should we do this regardless of whether
    336375        // or not the source is extended?
    337         if (source->modelEXT) {
    338             float fitRadius = NAN;
    339             float windowRadius = NAN;
     376        float fitRadius = NAN;
     377        float windowRadius = NAN;
     378        if (1 || source->modelEXT) {
    340379            if (!psphotSetRadiusMoments (&fitRadius, &windowRadius, readout, source, markVal)) {
    341380                psError (PSPHOT_ERR_UNKNOWN, false, "failed to set radius for ext source");
     
    387426                float modelFlux = pow(10., -0.4 * model->mag);
    388427
    389                 // XXX: We are assuming here that we only use PCM models. Should get that information from the recipe.
     428                model->fitRadius = fitRadius;
     429
     430                // XXX: We are assuming here that we only use PCM models.
     431                // I Should be getting that information from the recipe.
    390432                pmPCMdata *pcm = pmPCMinit (source, fitOptions, model, maskVal, psfSize);
    391433                if (!pcm) {
     
    394436                }
    395437                model->params->data.F32[PM_PAR_I0] = 1.0;
    396                 pmPCMMakeModel (source, model, pcm->nsigma, maskVal, psfSize);
     438                // XXX: this duplicates work that pmPCMCacheModel does
     439                // pmPCMMakeModel (source, model, pcm->nsigma, maskVal, psfSize);
    397440                float normFlux = model->class->modelFlux(model->params);
    398441                float I0 = modelFlux / normFlux;
  • branches/eam_branches/ipp-20150616/pstamp/scripts/pstampparse.pl

    r38195 r38552  
    142142
    143143if ($extver eq "1") {
    144     print STDERR "WARNING WARNING WARNING\n";
    145     print STDERR "Very soon version 1 postage stamp requests will be rejected. Please update your request tables to version 2 format.\n";
     144    print STDERR "Version 1 postage stamp requests are no longer accepted. Please update your request tables to version 2 format.\n";
    146145    print STDERR "Note that EMAIL will not be optional\n";
    147146
     
    247246# if any is known. Do we want to do this for any other channels?
    248247# requests from data store will have those values.
    249 if ($label and $label eq 'WEB.UP') {
     248if ($label and ($label eq 'WEB.UP' or $label eq 'WEB')) {
    250249    if ($labelForUser) {
    251250        $label = $labelForUser;
  • branches/eam_branches/ipp-20150616/tools/croot

    r38374 r38552  
    1515        $setlast = 1;
    1616        shift;
    17     } elsif ($ARGV[0] eq '--camera') {
     17    } elsif (($ARGV[0] eq '--camera') or ($ARGV[0] eq '-c')) {
    1818        shift;
    1919        $camera = shift;
Note: See TracChangeset for help on using the changeset viewer.