IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 34800 for trunk


Ignore:
Timestamp:
Dec 11, 2012, 2:04:31 PM (13 years ago)
Author:
watersc1
Message:

Merge from my branch including background restoration and stack stage projection cell binned images.

Location:
trunk
Files:
94 edited
6 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/Nebulous-Server/bin/neb-voladm

    r32615 r34800  
    6868        if (defined $allocate and $allocate !~ m/^[01]$/)
    6969        or (defined $available and $available !~ m/^[01]$/)
    70         or (defined $xattr and $xattr !~ m/^[012]$/);
     70        or (defined $xattr and $xattr !~ m/^[0123]$/);
    7171}
    7272
  • trunk/Ohana

  • trunk/Ohana/src/libohana/src

  • trunk/Ohana/src/opihi

  • trunk/Ohana/src/opihi/cmd.astro

  • trunk/Ohana/src/opihi/cmd.data

  • trunk/extsrc/gpcsw/gpcsrc/Make.Common

    r31150 r34800  
    156156# compilation and -shared applies to the link stage.
    157157#
    158 FCDEBUG  = -g -O -fno-automatic
     158FCDEBUG  = -g -O0 -fno-automatic
    159159FFWARN   = -Wall
    160160FFLAGS   = $(FCDEBUG) $(EXTRA_FFLAGS) $(FFWARN) $(CCDEFS) $(CCINCS)
    161 CCDEBUG  = -g -O
     161CCDEBUG  = -g -O0
    162162CCSHARE  = -fPIC -shared
    163163CCWARN   = -Wall -Wstrict-prototypes # -Wshadow
  • trunk/ippMonitor

  • trunk/ippScripts/Build.PL

    r33627 r34800  
    128128        scripts/listvideocells.pl
    129129        scripts/skycalibration.pl
     130        scripts/regenerate_background.pl
    130131    )],
    131132    dist_abstract => 'Scripts for running the Pan-STARRS IPP',
  • trunk/ippScripts/MANIFEST

    r31435 r34800  
    4646scripts/skycell_jpeg.pl
    4747scripts/lap_science.pl
     48scripts/regenerate_background.pl
    4849t/00_distribution.t
  • trunk/ippScripts/scripts/destreak_restore_camera.pl

  • trunk/ippScripts/scripts/detrend_process_imfile.pl

    r33666 r34800  
    2727my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
    2828my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
     29my $nebrepair = can_run('neb-repair') or (warn "Can't find neb-repair" and $missing_tools = 1);
     30
    2931if ($missing_tools) {
    3032    warn("Can't find required tools.");
     
    124126# Run ppImage
    125127unless ($no_op) {
     128    my $repair_cmd = "$nebrepair $input_uri";
     129    my ($repair_success, $repair_error_code, $repair_full_buf, $repair_stdout_buf, $repair_stderr_buf ) = run(command => $repair_cmd, verbose => $verbose);
     130    unless ($repair_success) {
     131        &my_die("Unable to attempt repair: $input_uri $repair_error_code", $det_id, $exp_id, $class_id $PS_EXIT_SYS_ERROR);
     132    }
     133
     134
    126135    my $command = "$ppImage -file $input_uri $outroot";
    127136    $command .= " -recipe PPIMAGE $ppimage_recipe";
  • trunk/ippScripts/scripts/ipp_apply_burntool_single.pl

  • trunk/ippScripts/scripts/magic_destreak.pl

  • trunk/ippScripts/scripts/skycell_jpeg.pl

    r28403 r34800  
    268268
    269269    my %tangents = ();
     270
     271    my %products = ('image' => "PPSTACK.UNCONV",
     272                    'mask'  => "PPSTACK.UNCONV.MASK",
     273                    'variance' => "PPSTACK.UNCONV.VARIANCE",
     274                    'exp'   => "PPSTACK.UNCONV.EXP",
     275                    'num'   => "PPSTACK.UNCONV.EXPNUM",
     276                    'bkg'   => "PPSTACK.OUTPUT.BKGMODEL"
     277        );
    270278   
    271279    foreach my $imfile (@$imfiles) {
     
    281289
    282290        $projection_cell =~ s/^(.*)\..*$/$1/;
    283        
     291
    284292        unless (exists($tangents{$projection_cell})) {
    285293            # Make a temp file and fill, but be sure to save
    286             ($tempFile, $tempName) = tempfile("/tmp/skycell.$projection_cell.XXXX",
    287                                                  UNLINK => !$save_temps);
    288             $tangents{$projection_cell}{FILE} = $tempFile;
    289             $tangents{$projection_cell}{NAME} = $tempName;
    290             if ($masks) {
    291                 my ($maskFile, $maskName) = tempfile("/tmp/skycell.$projection_cell.masks.XXXX",
    292                                                      UNLINK => !$save_temps);
    293                 $tangents{$projection_cell}{MFILE} = $maskFile;
    294                 $tangents{$projection_cell}{MNAME} = $maskName;
    295             }           
    296         }
    297         print "$skycell_id $projection_cell\n";
    298         my $file = $ipprc->filename("PPSTACK.OUTPUT", $path_base, $skycell_id);
    299         print "$file $state $quality\n";
    300         my $f_fh = $tangents{$projection_cell}{FILE};
    301         print $f_fh "$file\n";
    302         if ($masks) {
    303             my $mask = $ipprc->filename("PPSTACK.OUTPUT.MASK", $path_base, $skycell_id);
    304             print "$mask\n";
    305             my $m_fh = $tangents{$projection_cell}{MFILE};
    306             print $m_fh "$mask\n";
     294            foreach my $key (keys %products) {
     295                ($tempFile, $tempName) = tempfile("/tmp/skycell.$projection_cell.$key.XXXX",
     296                                                  UNLINK => !$save_temps);
     297                $tangents{$projection_cell}{$key}{FILE} = $tempFile;
     298                $tangents{$projection_cell}{$key}{NAME} = $tempName;
     299            }
     300        }
     301        foreach my $key (keys %products) {
     302            print "$skycell_id $projection_cell\n";     
     303            my $file = $ipprc->filename($products{$key}, $path_base, $skycell_id);
     304            print "$file $state $quality\n";
     305            my $f_fh = $tangents{$projection_cell}{$key}{FILE};
     306            print $f_fh "$file\n";
    307307        }
    308308    }
    309309    foreach my $projection_cell (keys %tangents) {
    310         $command = "$ppSkycell -images $tangents{$projection_cell}{NAME}";
    311         if ($masks) {
    312             $command .= " -masks $tangents{$projection_cell}{MNAME} ";
    313         }
    314         $command .= " ${outroot}.${projection_cell} ";
    315         print "$command\n";
    316         ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
    317         unless ($success) {
    318             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    319             &my_die("unable to perform ppSkycell: $error_code", $stage_id, $error_code);
    320         }
     310        ## Loop over results here.
     311        # Images
     312        # Masks
     313        # Variances
     314        # Nexptime
     315        # Nexp
     316        # Backgrounds
     317       
     318        foreach my $key (keys %products) {
     319            $command = "$ppSkycell -images $tangents{$projection_cell}{$key}{NAME}";
     320            $command .= " ${outroot}.${projection_cell}.${key} ";
     321            if ($key eq 'bkg') {
     322                $command .= " -Di BIN1 1 -Di BIN2 1 ";
     323            }
     324            elsif ($key eq 'image') {
     325                $command .= " -masks $tangents{$projection_cell}{mask}{NAME} ";
     326            }
     327            elsif ($key eq 'mask') {
     328                next; # This should be made with the images.
     329            }
     330            print "$command\n";
     331            ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     332            unless ($success) {
     333                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     334                &my_die("unable to perform ppSkycell: $error_code", $stage_id, $error_code);
     335            }
     336        }
     337
    321338        # Update database:
    322339        $command = "$stacktool -addsummary -sass_id $stage_id -projection_cell $projection_cell -path_base $outroot";
  • trunk/ippScripts/scripts/stack_skycell.pl

    r32562 r34800  
    229229    my $sources = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $file->{path_base}); # Sources name
    230230
     231    my $bkgmodel = $ipprc->filename("PSWARP.OUTPUT.BKGMODEL", $file->{path_base});
     232
    231233    &my_die("Image $image does not exist", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists( $image );
    232234    &my_die("Mask $mask does not exist", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists( $mask );
     
    240242    print $listFile "\tPSF\tSTR\t" . $psf . "\n" if $convolve;
    241243    print $listFile "\tSOURCES\tSTR\t" . $sources . "\n";
     244    print $listFile "\tBKGMODEL\tSTR\t" . $bkgmodel . "\n" if $ipprc->file_exists( $bkgmodel );
    242245
    243246    print $listFile "END\n\n";
  • trunk/ippScripts/scripts/warp_skycell.pl

    r33053 r34800  
    128128# Where do we get the astrometry source from?
    129129my $astromSource;               # The astrometry source
     130my $doBackground;               # Do we want to make background models?
    130131{
    131132    my $command = "$ppConfigDump -camera $camera -recipe PSWARP $recipe_pswarp -dump-recipe PSWARP -";
     
    139140        &my_die("Unable to parse metadata config doc", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_PROG_ERROR);
    140141    $astromSource = metadataLookupStr($metadata, 'ASTROM.SOURCE');
     142    $doBackground = metadataLookupBool($metadata, 'BACKGROUND.MODEL');   
    141143}
    142144
     
    168170if ($do_stats) {
    169171    $outputStats = prepare_output ("SKYCELL.STATS", $outroot, $skycell_id, 1) if $do_stats;
     172}
     173my $outputBKGs;
     174if ($doBackground) {
     175    $outputBKGs = prepare_output ("PSWARP.OUTPUT.BKGMODEL", $outroot, $skycell_id, 1);
    170176}
    171177my $configuration;
     
    209215my ($weightFile, $weightName) = tempfile( "$tempOutRoot.weight.list.XXXX", UNLINK => !$save_temps);
    210216my ($astromFile, $astromName) = tempfile( "$tempOutRoot.astrom.list.XXXX", UNLINK => !$save_temps);
    211 
     217my ($bkgFile, $bkgName);
     218if ($doBackground) {
     219    ($bkgFile, $bkgName) = tempfile( "$tempOutRoot.bkg.list.XXXX", UNLINK => !$save_temps);
     220}
    212221my $wrote_astrom = 0;
    213222foreach my $imfile (@$imfiles) {
     
    235244    print $maskFile   "$mask\n";
    236245    print $weightFile "$weight\n";
     246    my $bkg;
     247    if ($doBackground) {
     248        $bkg    = $ipprc->filename("PSPHOT.BACKMDL", $imfile->{chip_path_base}, $imfile->{class_id});
     249        print $bkgFile "$bkg\n";
     250    }
    237251
    238252    if (!$wrote_astrom) {
     
    245259close $weightFile;
    246260close $astromFile;
    247 
     261if ($doBackground) {
     262    close($bkgFile);
     263}
    248264# We need the recipe to determine if we care whether the PSF is generated or not
    249265my $recipe;
     
    269285    $command .= " -variancelist $weightName";
    270286    $command .= " -astromlist $astromName";
     287    $command .= " -bkglist $bkgName" if ($doBackground);
    271288    $command .= " $outroot $skyFile";
    272289    $command .= " -F PSPHOT.PSF.SAVE PSPHOT.PSF.SKY.SAVE";
  • trunk/ippTasks

  • trunk/ippTasks/Makefile.am

    r33030 r34800  
    4545        diffphot.pro \
    4646        lap.pro \
    47         vp.pro
     47        vp.pro \
     48        bg.regeneration.pro
    4849
    4950other_files = \
  • trunk/ippToPsps

  • trunk/ippTools/share/Makefile.am

    r34766 r34800  
    393393        stacktool_sassskyfile.sql \
    394394        stacktool_tosum.sql \
     395        stacktool_tobkg.sql \
    395396        stacktool_tosummary.sql \
    396397        stacktool_addsummary.sql \
  • trunk/ippTools/share/camtool_find_pendingimfile.sql

  • trunk/ippTools/share/chiptool_setimfiletoupdate.sql

  • trunk/ippTools/share/pxadmin_create_tables.sql

  • trunk/ippTools/share/stacktool_inputskyfile.sql

    r32937 r34800  
    44    rawExp.exp_id,
    55    rawExp.exp_name,
     6    rawExp.exp_time,
    67    rawExp.object,
    78    rawExp.dateobs,
  • trunk/ippTools/share/warptool_towarped.sql

  • trunk/ippTools/src

  • trunk/ippTools/src/magictool.c

  • trunk/ippTools/src/stacktool.c

    r34731 r34800  
    3737static bool inputskyfileMode(pxConfig *config);
    3838static bool tosumMode(pxConfig *config);
     39static bool tobkgMode(pxConfig *config);
    3940static bool addsumskyfileMode(pxConfig *config);
    4041static bool sumskyfileMode(pxConfig *config);
     
    7677        MODECASE(STACKTOOL_MODE_INPUTSKYFILE,          inputskyfileMode);
    7778        MODECASE(STACKTOOL_MODE_TOSUM,                 tosumMode);
     79        MODECASE(STACKTOOL_MODE_TOBKG,                 tobkgMode);
    7880        MODECASE(STACKTOOL_MODE_ADDSUMSKYFILE,         addsumskyfileMode);
    7981        MODECASE(STACKTOOL_MODE_SUMSKYFILE,            sumskyfileMode);
     
    952954        // negative simple so the default is true
    953955        if (!ippdbPrintMetadatas(stdout, output, "stackSumSkyfile", !simple)) {
     956            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     957            psFree(output);
     958            return false;
     959        }
     960    }
     961
     962    psFree(output);
     963
     964    return true;
     965}
     966
     967static bool tobkgMode(pxConfig *config)
     968{
     969    PS_ASSERT_PTR_NON_NULL(config, false);
     970
     971    psMetadata *where = psMetadataAlloc();
     972    PXOPT_COPY_S64(config->args, where, "-stack_id", "stack_id", "==");
     973    pxAddLabelSearchArgs (config, where, "-label", "stackRun.label", "==");
     974
     975    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     976    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     977
     978    psString query = pxDataGet("stacktool_tobkg.sql");
     979    if (!query) {
     980        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     981        return false;
     982    }
     983
     984    psString whereClause = psStringCopy(""); // WHERE conditions to add
     985    if (psListLength(where->list)) {
     986        psString new = psDBGenerateWhereConditionSQL(where, NULL);
     987        psStringAppend(&whereClause, "\nAND %s", new);
     988        psFree(new);
     989    }
     990    psFree(where);
     991
     992    psStringAppend(&query, "\nORDER by priority DESC, stack_id");
     993
     994    // treat limit == 0 as "no limit"
     995    if (limit) {
     996        psString limitString = psDBGenerateLimitSQL(limit);
     997        psStringAppend(&query, " %s", limitString);
     998        psFree(limitString);
     999    }
     1000
     1001    if (!p_psDBRunQueryF(config->dbh, query, whereClause)) {
     1002        psError(PS_ERR_UNKNOWN, false, "database error");
     1003        psFree(query);
     1004        return false;
     1005    }
     1006    psFree(query);
     1007
     1008    psArray *output = p_psDBFetchResult(config->dbh);
     1009    if (!output) {
     1010        psErrorCode err = psErrorCodeLast();
     1011        switch (err) {
     1012            case PS_ERR_DB_CLIENT:
     1013                psError(PXTOOLS_ERR_SYS, false, "database error");
     1014            case PS_ERR_DB_SERVER:
     1015                psError(PXTOOLS_ERR_PROG, false, "database error");
     1016            default:
     1017                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1018        }
     1019
     1020        return false;
     1021    }
     1022    if (!psArrayLength(output)) {
     1023        psTrace("stacktool", PS_LOG_INFO, "no rows found");
     1024        psFree(output);
     1025        return true;
     1026    }
     1027
     1028    if (psArrayLength(output)) {
     1029        // negative simple so the default is true
     1030        if (!ippdbPrintMetadatas(stdout, output, "stackBkgSkyfile", !simple)) {
    9541031            psError(PS_ERR_UNKNOWN, false, "failed to print array");
    9551032            psFree(output);
     
    16811758    PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);
    16821759    PXOPT_LOOKUP_S16(quality, config->args, "-set_quality", false, false);
     1760    PXOPT_LOOKUP_S16(background_model, config->args, "-set_background_model", false, false);
    16831761
    16841762    psMetadata *where = psMetadataAlloc();
    16851763    PXOPT_COPY_S64(config->args, where, "-stack_id",   "stack_id",   "==");
    16861764
    1687     if (!pxSetFaultCode(config->dbh, "stackSumSkyfile", where, fault, quality)) {
     1765    if (background_model) {
     1766      psMetadata *values = psMetadataAlloc();
     1767      PXOPT_COPY_S16(config->args, values, "-set_background_model", "background_model", "==");
     1768      long rows = psDBUpdateRows(config->dbh,"stackSumSkyfile", where, values);
     1769      psFree(values);
     1770      if (!rows) {
     1771        // This maybe should rollback and error if rows != 1
     1772        psError(PS_ERR_UNKNOWN, true, "no rows changed");
     1773        return false;
     1774      }
     1775    }
     1776    else {   
     1777      if (!pxSetFaultCode(config->dbh, "stackSumSkyfile", where, fault, quality)) {
    16881778        psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
    16891779        psFree (where);
    16901780        return false;
     1781      }
    16911782    }
    16921783    psFree (where);
  • trunk/ippTools/src/stacktool.h

    r28375 r34800  
    3131    STACKTOOL_MODE_INPUTSKYFILE,
    3232    STACKTOOL_MODE_TOSUM,
     33    STACKTOOL_MODE_TOBKG,
    3334    STACKTOOL_MODE_ADDSUMSKYFILE,
    3435    STACKTOOL_MODE_SUMSKYFILE,
  • trunk/ippTools/src/stacktoolConfig.c

    r34731 r34800  
    150150    psMetadataAddBool(tosumArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
    151151
     152    // -tobkg
     153    psMetadata *tobkgArgs = psMetadataAlloc();
     154    psMetadataAddS64(tobkgArgs, PS_LIST_TAIL, "-stack_id", 0,            "search by stack ID", 0);
     155    psMetadataAddStr(tobkgArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "search by label", NULL);
     156    psMetadataAddU64(tobkgArgs, PS_LIST_TAIL, "-limit",  0,            "limit result set to N items", 0);
     157    psMetadataAddBool(tobkgArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
     158   
    152159    // -addsumskyfile
    153160    psMetadata *addsumskyfileArgs = psMetadataAlloc();
     
    280287    psMetadataAddS16(updatesumskyfileArgs, PS_LIST_TAIL, "-fault", 0,            "set fault code (required)", 0);
    281288    psMetadataAddS16(updatesumskyfileArgs, PS_LIST_TAIL, "-set_quality", 0,            "set quality", 0);
    282 
     289    psMetadataAddS16(updatesumskyfileArgs, PS_LIST_TAIL, "-set_background_model", 0,   "set background model", 0);
     290   
    283291    // -exportrun
    284292    psMetadata *exportrunArgs = psMetadataAlloc();
     
    304312    PXOPT_ADD_MODE("-inputskyfile",    "", STACKTOOL_MODE_INPUTSKYFILE,    inputskyfileArgs);
    305313    PXOPT_ADD_MODE("-tosum",           "", STACKTOOL_MODE_TOSUM,          tosumArgs);
     314    PXOPT_ADD_MODE("-tobkg",           "", STACKTOOL_MODE_TOBKG,          tobkgArgs);
    306315    PXOPT_ADD_MODE("-addsumskyfile",   "", STACKTOOL_MODE_ADDSUMSKYFILE,   addsumskyfileArgs);
    307316    PXOPT_ADD_MODE("-sumskyfile",      "list results of stackRun", STACKTOOL_MODE_SUMSKYFILE,      sumskyfileArgs);
  • trunk/ippTools/src/warptool.c

    r34766 r34800  
    20592059        PXOPT_LOOKUP_S64(magicked, config->args, "-set_magicked", false, false);
    20602060        PXOPT_LOOKUP_S16(quality, config->args, "-set_quality", false, false);
     2061
    20612062        if (magicked) {
    20622063            psStringAppend(&set_magicked_skyfile, "\n , warpSkyfile.magicked = %" PRId64, magicked);
     
    20652066        if (quality) {
    20662067          psStringAppend(&set_magicked_skyfile, "\n , warpSkyfile.quality = %"PRId16, quality);
     2068        }
     2069        PXOPT_LOOKUP_S16(background_model, config->args, "-set_background_model", false, false);
     2070        if (background_model) {
     2071          psStringAppend(&set_magicked_skyfile, "\n , warpSkyfile.background_model = %"PRId16, background_model);
    20672072        }
    20682073    } else if (!strcmp(data_state, "cleaned") || !strcmp(data_state, "purged")) {
     
    21252130    // warp_id, skycell_id, fault are required
    21262131    PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
    2127 
    2128     if (!state) {
     2132    PXOPT_LOOKUP_S16(background_model, config->args, "-set_background_model", false, false);
     2133    if (background_model) {
     2134      // CZW 2012-12-06: I'm unclear why we don't use this form for all updates?
     2135      psMetadata *where = psMetadataAlloc();
     2136      psMetadata *values = psMetadataAlloc();
     2137      PXOPT_COPY_S64(config->args, where, "-warp_id", "warp_id", "==");
     2138      PXOPT_COPY_STR(config->args, where, "-skycell_id", "skycell_id", "==");
     2139      PXOPT_COPY_S16(config->args, values, "-set_background_model", "background_model", "==");
     2140      long rows = psDBUpdateRows(config->dbh,"warpSkyfile", where, values);
     2141      psFree(values);
     2142      psFree(where);
     2143      if (!rows) {
     2144        // This maybe should rollback and error if rows != 1
     2145        psError(PS_ERR_UNKNOWN, true, "no rows changed");
     2146        return false;
     2147      }
     2148    }
     2149    else if (!state) {
    21292150      psMetadata *where = psMetadataAlloc();
    21302151      PXOPT_COPY_S64(config->args, where, "-warp_id", "warp_id", "==");
  • trunk/ippTools/src/warptoolConfig.c

    r34766 r34800  
    410410    psMetadataAddS16(updateskyfileArgs, PS_LIST_TAIL, "-set_quality",  0,"new quality value", 0);
    411411    psMetadataAddStr(updateskyfileArgs, PS_LIST_TAIL, "-set_state", 0,   "set state", 0);
    412 
     412    psMetadataAddS16(updateskyfileArgs, PS_LIST_TAIL, "-set_background_model", 0, "set the background_model value", 0);
    413413    // -exportrun
    414414    psMetadata *exportrunArgs = psMetadataAlloc();
  • trunk/ippconfig

  • trunk/ippconfig/gpc1/pswarp.config

    r19094 r34800  
    11ASTROM.SOURCE           STR     PSASTRO.OUTPUT  # Source file rule for astrometry, or NULL
     2BACKGROUND.MODEL        BOOL    TRUE
     3BKG.XGRID               S32     50
     4BKG.YGRID               S32     50
  • trunk/ippconfig/recipes/filerules-mef.mdc

    r34528 r34800  
    120120PSWARP.SKYCELL          INPUT    @FILES        CHIP       IMAGE
    121121PSWARP.ASTROM           INPUT    @FILES        CHIP       CMF
     122PSWARP.BKGMODEL           INPUT    @FILES        CHIP       IMAGE
    122123
    123124## files used by ppsub
     
    138139PPSTACK.INPUT.PSF       INPUT    @FILES        CHIP       PSF
    139140PPSTACK.INPUT.SOURCES   INPUT    @FILES        FPA        CMF
     141PPSTACK.INPUT.BKGMODEL    INPUT    @FILES        FPA        IMAGE
    140142
    141143## files used by ppstamp
     
    296298PSWARP.BIN2             OUTPUT {OUTPUT}.b2.fits                  IMAGE     COMP_IMG   FPA        TRUE      NONE
    297299PSWARP.CONFIG           OUTPUT {OUTPUT}.pswarp.mdc               TEXT      NONE       FPA        TRUE      NONE
     300PSWARP.OUTPUT.BKGMODEL  OUTPUT {OUTPUT}.mdl.fits                      IMAGE           NONE       FPA        TRUE      NONE
    298301                                                                                     
    299302SKYCELL.STATS           OUTPUT {OUTPUT}.stats                    STATS     NONE       FPA        TRUE      NONE
     
    342345PPSTACK.OUTPUT.JPEG1    OUTPUT {OUTPUT}.b1.jpg                   JPEG      NONE       FPA        TRUE      NONE
    343346PPSTACK.OUTPUT.JPEG2    OUTPUT {OUTPUT}.b2.jpg                   JPEG      NONE       FPA        TRUE      NONE
     347PPSTACK.OUTPUT.BKGMODEL OUTPUT {OUTPUT}.mdl.fits                 IMAGE     NONE       FPA        TRUE      NONE
     348PPSTACK.OUTPUT.BKGREST  OUTPUT {OUTPUT}.bkgrest.fits             IMAGE            NONE       FPA        TRUE      NONE
    344349PPSTACK.CONFIG          OUTPUT {OUTPUT}.ppStack.mdc              TEXT      NONE       FPA        TRUE      NONE
    345350                                                                                     
     
    370375PPSKYCELL.BIN1          OUTPUT {OUTPUT}.{FILE.INDEX}.b1.fits     IMAGE     NONE       FPA        TRUE      NONE
    371376PPSKYCELL.BIN2          OUTPUT {OUTPUT}.{FILE.INDEX}.b2.fits     IMAGE     NONE       FPA        TRUE      NONE
     377PPSKYCELL.BIN1.MASK          OUTPUT {OUTPUT}.{FILE.INDEX}.b1.mk.fits     MASK     COMP_MASK       FPA        TRUE      NONE
     378PPSKYCELL.BIN2.MASK          OUTPUT {OUTPUT}.{FILE.INDEX}.b2.mk.fits     MASK     COMP_MASK       FPA       TRUE      NONE
    372379
    373380LOG.IMFILE              OUTPUT {OUTPUT}.{CHIP.NAME}.log          TEXT      NONE       CHIP       TRUE      NONE
  • trunk/ippconfig/recipes/filerules-simple.mdc

    r34528 r34800  
    9090PSWARP.SKYCELL            INPUT    @FILES        FPA        IMAGE     
    9191PSWARP.ASTROM             INPUT    @FILES        FPA        CMF
     92PSWARP.BKGMODEL           INPUT    @FILES        CHIP       IMAGE
    9293
    9394## files used by ppsub
     
    108109PPSTACK.INPUT.PSF         INPUT    @FILES        CHIP       PSF
    109110PPSTACK.INPUT.SOURCES     INPUT    @FILES        FPA        CMF
     111PPSTACK.INPUT.BKGMODEL    INPUT    @FILES        FPA        IMAGE
    110112
    111113## files used by ppstamp
     
    251253PSWARP.BIN2                  OUTPUT {OUTPUT}.b2.fits              IMAGE           NONE       FPA        TRUE      NONE
    252254PSWARP.CONFIG                OUTPUT {OUTPUT}.pswarp.mdc           TEXT            NONE       FPA        TRUE      NONE
     255PSWARP.OUTPUT.BKGMODEL       OUTPUT {OUTPUT}.mdl.fits             IMAGE           NONE   FPA        TRUE      NONE
    253256                                                     
    254257SKYCELL.STATS                OUTPUT {OUTPUT}.stats                STATS           NONE       FPA        TRUE      NONE
     
    300303PPSTACK.OUTPUT.JPEG1         OUTPUT {OUTPUT}.b1.jpg               JPEG            NONE       FPA        TRUE      NONE
    301304PPSTACK.OUTPUT.JPEG2         OUTPUT {OUTPUT}.b2.jpg               JPEG            NONE       FPA        TRUE      NONE
     305PPSTACK.OUTPUT.BKGMODEL      OUTPUT {OUTPUT}.mdl.fits             IMAGE           NONE       FPA        TRUE      NONE
     306PPSTACK.OUTPUT.BKGREST       OUTPUT {OUTPUT}.bkgrest.fits         IMAGE           NONE       FPA        TRUE      NONE
    302307PPSTACK.CONFIG               OUTPUT {OUTPUT}.ppStack.mdc          TEXT            NONE       FPA        TRUE      NONE
    303308                                             
     
    327332PPSKYCELL.BIN1               OUTPUT {OUTPUT}.{FILE.INDEX}.b1.fits     IMAGE     NONE       FPA        TRUE      NONE
    328333PPSKYCELL.BIN2               OUTPUT {OUTPUT}.{FILE.INDEX}.b2.fits     IMAGE     NONE       FPA        TRUE      NONE
     334PPSKYCELL.BIN1.MASK          OUTPUT {OUTPUT}.b1.mk.fits     MASK     COMP_MASK       FPA        TRUE      NONE
     335PPSKYCELL.BIN2.MASK          OUTPUT {OUTPUT}.b2.mk.fits     MASK     COMP_MASK       FPA       TRUE      NONE
    329336
    330337LOG.IMFILE                   OUTPUT {OUTPUT}.imfile.log           TEXT            NONE       FPA        TRUE      NONE
  • trunk/ippconfig/recipes/filerules-split.mdc

    r34528 r34800  
    108108PSWARP.SKYCELL            INPUT    @FILES        FPA        IMAGE
    109109PSWARP.ASTROM             INPUT    @FILES        CHIP       CMF
     110PSWARP.BKGMODEL           INPUT    @FILES        CHIP       IMAGE
    110111                         
    111112## files used by ppsub   
     
    126127PPSTACK.INPUT.PSF         INPUT    @FILES        CHIP       PSF
    127128PPSTACK.INPUT.SOURCES     INPUT    @FILES        FPA        CMF
     129PPSTACK.INPUT.BKGMODEL    INPUT    @FILES        FPA        IMAGE
    128130                         
    129131## files used by ppstamp 
     
    278280PSWARP.CONFIG                OUTPUT {OUTPUT}.pswarp.mdc               TEXT            NONE       FPA        TRUE      NONE
    279281PSWARP.OUTPUT.UNCOMPRESSED   OUTPUT {OUTPUT}.fits                     IMAGE           NONE       FPA        TRUE      NONE
     282PSWARP.OUTPUT.BKGMODEL       OUTPUT {OUTPUT}.mdl.fits                 IMAGE           NONE       FPA        TRUE      NONE
    280283                                                                                                   
    281284SKYCELL.STATS                OUTPUT {OUTPUT}.stats                    STATS           NONE       FPA        TRUE      NONE
     
    333336PPSTACK.OUTPUT.JPEG1         OUTPUT {OUTPUT}.b1.jpg                   JPEG            NONE       FPA        TRUE      NONE
    334337PPSTACK.OUTPUT.JPEG2         OUTPUT {OUTPUT}.b2.jpg                   JPEG            NONE       FPA        TRUE      NONE
     338PPSTACK.OUTPUT.BKGMODEL      OUTPUT {OUTPUT}.mdl.fits                 IMAGE           NONE       FPA        TRUE      NONE
     339PPSTACK.OUTPUT.BKGREST       OUTPUT {OUTPUT}.bkgrest.fits             IMAGE           NONE       FPA        TRUE      NONE
    335340PPSTACK.CONFIG               OUTPUT {OUTPUT}.ppStack.mdc              TEXT            NONE       FPA        TRUE      NONE
    336341
     
    360365PPSKYCELL.JPEG1              OUTPUT {OUTPUT}.0.b1.jpeg     JPEG            NONE       CHIP       TRUE      NONE
    361366PPSKYCELL.JPEG2              OUTPUT {OUTPUT}.0.b2.jpeg     JPEG            NONE       CHIP       TRUE      NONE
    362 PPSKYCELL.BIN1          OUTPUT {OUTPUT}.0.b1.fits     IMAGE     COMP_IMG       FPA        TRUE      NONE
    363 PPSKYCELL.BIN2          OUTPUT {OUTPUT}.0.b2.fits     IMAGE     COMP_IMG       FPA       TRUE      NONE
     367PPSKYCELL.BIN1               OUTPUT {OUTPUT}.b1.fits     IMAGE     COMP_IMG       FPA        TRUE      NONE
     368PPSKYCELL.BIN2               OUTPUT {OUTPUT}.b2.fits     IMAGE     COMP_IMG       FPA       TRUE      NONE
     369PPSKYCELL.BIN1.MASK          OUTPUT {OUTPUT}.b1.mk.fits     MASK     COMP_MASK       FPA        TRUE      NONE
     370PPSKYCELL.BIN2.MASK          OUTPUT {OUTPUT}.b2.mk.fits     MASK     COMP_MASK       FPA       TRUE      NONE
    364371
    365372LOG.IMFILE                   OUTPUT {OUTPUT}.{CHIP.NAME}.log          TEXT            NONE       CHIP       TRUE      NONE
  • trunk/ippconfig/recipes/nightly_science.config

    r34608 r34800  
    229229  DIFFABLE  BOOL TRUE
    230230  REDUCTION STR SWEETSPOT
     231  ADDITIONAL_STACK_LABEL STR ecliptic.rp
    231232#  REDUCTION STR SSTF_4SIG
    232233#  WARP      S16 60
     
    240241  DIFFABLE    BOOL TRUE
    241242  REDUCTION STR SWEETSPOT
     243  ADDITIONAL_STACK_LABEL STR ecliptic.rp
    242244#  REDUCTION STR SSTF_4SIG
    243245END
     
    250252  DIFFABLE    BOOL TRUE
    251253  REDUCTION STR SWEETSPOT
     254  ADDITIONAL_STACK_LABEL STR ecliptic.rp
    252255#  REDUCTION STR SSTF_4SIG
    253256END
     
    260263  DIFFABLE    BOOL TRUE
    261264  REDUCTION STR SWEETSPOT
     265  ADDITIONAL_STACK_LABEL STR ecliptic.rp
    262266#  REDUCTION STR SSTF_4SIG
    263267END
  • trunk/ippconfig/recipes/ppBackground.mdc

    r28486 r34800  
    11# Recipe options for ppBackground
    22
     3BINNING_RECIPE  STR     PSPHOT
     4BINNING_XNAME   STR     BACKGROUND.XBIN
     5BINNING_YNAME   STR     BACKGROUND.YBIN
     6
     7DEFAULT    METADATA
     8END
     9
     10
     11STACK       METADATA
     12  BINNING_RECIPE        STR     PSWARP
     13  BINNING_XNAME STR     BKG.XGRID       
     14  BINNING_YNAME STR     BKG.YGRID
     15END
     16           
    317
    418BACKGROUND       METADATA
  • trunk/ippconfig/recipes/ppStack.config

    r34091 r34800  
    103103STACK.TYPE      STR     DEEP_STACK
    104104
     105DEFAULT.EXPTIME  F32    NAN
     106
    105107# Recipe overrides for STACK
    106108STACK   METADATA
  • trunk/ippconfig/recipes/ppSub.config

  • trunk/ippconfig/recipes/pswarp.config

    r28442 r34800  
    1919MASKSTAT.ADVISORY   U32 0x080
    2020
     21BACKGROUND.MODEL    BOOL   FALSE             # Construct a warped version of the chip stage background
     22BKG.XGRID              S32    4               # These need to be tuned
     23BKG.YGRID              S32    4
    2124
    2225# Default recipe for warping
  • trunk/ippconfig/recipes/reductionClasses.mdc

  • trunk/ppBackground/src/ppBackground.h

    r28300 r34800  
    3737    );
    3838
     39/// Determine the binning from the recipe if available.
     40psImageBinning *ppBackgroundBinningByRecipe(const psImage *image, // Image for which to generate a bg model
     41                                            const pmConfig *config, // Configuration
     42                                            psString recipe_name,
     43                                            psString Xbin_name,
     44                                            psString Ybin_name
     45                                            );
     46
     47
    3948/// Restore the background to an image
    4049bool ppBackgroundRestore(
  • trunk/ppBackground/src/ppBackgroundRestore.c

    r34298 r34800  
    55
    66#include "ppBackground.h"
     7
     8psImageBinning *ppBackgroundBinningByRecipe(const psImage *image, // Image for which to generate a bg model
     9                                            const pmConfig *config, // Configuration
     10                                            psString recipe_name,
     11                                            psString Xbin_name,
     12                                            psString Ybin_name
     13                                            )
     14{
     15  bool status = true;
     16
     17  psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, recipe_name);
     18  assert (recipe);
     19
     20  // I have the fine image size, I know the binning factor, determine the ruff image size
     21  psImageBinning *binning = psImageBinningAlloc();
     22  binning->nXfine = image->numCols;
     23  binning->nYfine = image->numRows;
     24  binning->nXbin  = psMetadataLookupS32(&status, recipe, Xbin_name);
     25  binning->nYbin  = psMetadataLookupS32(&status, recipe, Ybin_name);
     26
     27  psImageBinningSetRuffSize(binning, PS_IMAGE_BINNING_CENTER);
     28  psImageBinningSetSkip(binning, image);
     29
     30  return binning;
     31}
     32
     33 
     34
    735
    836bool ppBackgroundRestore(pmChip *chip, const pmChip *background, const pmChip *pattern,
     
    2755    if (background) {
    2856        pmReadout *bgRO = pmFPAviewThisReadout(view, background->parent); // Readout with background
    29         psImageBinning *binning = psphotBackgroundBinning(image, config);
     57
     58        psImageBinning *binning;
     59        psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPBACKGROUND_RECIPE); // Recipe
     60        if (!recipe) {
     61          binning = psphotBackgroundBinning(image, config);
     62        }
     63        else {
     64          binning = ppBackgroundBinningByRecipe(image,config,
     65                                                psMetadataLookupStr(NULL,recipe,"BINNING_RECIPE"),
     66                                                psMetadataLookupStr(NULL,recipe,"BINNING_XNAME"),
     67                                                psMetadataLookupStr(NULL,recipe,"BINNING_YNAME"));
     68        }
     69                                               
     70        fprintf(stderr,"%d %d %d %d\n",binning->nXfine,binning->nYfine,binning->nXbin,binning->nYbin);
    3071        if (!binning) {
    3172            psError(psErrorCodeLast(), false, "Unable to find background binning");
     
    4990        for (int y = 0; y < numRows; y++) {
    5091            for (int x = 0; x < numCols; x++) {
     92              if ((y % 250 == 0)&&(x % 250 == 0)) {
     93                printf("%d %d %g\n",x,y,bgImage->data.F32[y][x]);
     94              }
    5195                image->data.F32[y][x] += bgImage->data.F32[y][x];
     96               
    5297            }
    5398        }
  • trunk/ppImage/src

  • trunk/ppSkycell/src/ppSkycellCamera.c

    r28375 r34800  
    103103        return false;
    104104    }
    105     if (!pmFPAfileDefineOutput(data->config, NULL, "PPSKYCELL.BIN1")) {
     105    pmFPAfile *bin1 = pmFPAfileDefineOutput(data->config, NULL, "PPSKYCELL.BIN1");
     106    if (!bin1) {
    106107        psError(psErrorCodeLast(), false, "Unable to define output.");
    107108        return false;
    108109    }
    109     if (!pmFPAfileDefineOutput(data->config, NULL, "PPSKYCELL.BIN2")) {
     110    pmFPAfile *bin2 = pmFPAfileDefineOutput(data->config, NULL, "PPSKYCELL.BIN2");
     111    if (!bin2) {
    110112        psError(psErrorCodeLast(), false, "Unable to define output.");
    111113        return false;
     114    }
     115    if (data->masksName) {
     116      pmFPAfile *mask1 = pmFPAfileDefineOutput(data->config, bin1->fpa , "PPSKYCELL.BIN1.MASK");
     117      if (!mask1) {
     118        psError(psErrorCodeLast(), false, "Unable to define output.");
     119        return false;
     120      }
     121      mask1->save = true;
     122      pmFPAfile *mask2 = pmFPAfileDefineOutput(data->config, bin2->fpa , "PPSKYCELL.BIN2.MASK");
     123      if (!mask2) {
     124        psError(psErrorCodeLast(), false, "Unable to define output.");
     125        return false;
     126      }
     127      mask2->save = true;
    112128    }
    113129
  • trunk/ppSkycell/src/ppSkycellLoop.c

    r28375 r34800  
    1515                         )
    1616{
    17     base->x0 = PS_MIN(base->x0, compare->x0);
    18     base->x1 = PS_MAX(base->x1, compare->x1);
     17    base->x0 = PS_MAX(base->x0, compare->x0);
     18    base->x1 = PS_MIN(base->x1, compare->x1);
    1919    base->y0 = PS_MIN(base->y0, compare->y0);
    2020    base->y1 = PS_MAX(base->y1, compare->y1);
     
    2727{
    2828    psPlane *fromCoords = psPlaneAlloc(), *toCoords = psPlaneAlloc(); // Coordinates for transforms
    29     psRegion *region = psRegionAlloc(INFINITY, -INFINITY, INFINITY, -INFINITY); // Region for skycell
     29    psRegion *region = psRegionAlloc(-INFINITY, INFINITY, INFINITY, -INFINITY); // Region for skycell
    3030
    3131// Limit the region using the nominated point (X,Y)
     
    3838    toCoords->x += wcs->crpix1; \
    3939    toCoords->y += wcs->crpix2; \
    40     region->x0 = PS_MIN(region->x0, toCoords->x); \
    41     region->x1 = PS_MAX(region->x1, toCoords->x); \
     40    region->x0 = PS_MAX(region->x0, toCoords->x); \
     41    region->x1 = PS_MIN(region->x1, toCoords->x); \
    4242    region->y0 = PS_MIN(region->y0, toCoords->y); \
    4343    region->y1 = PS_MAX(region->y1, toCoords->y);
     
    132132    psVector *target = psVectorAlloc(data->numInputs, PS_TYPE_S32); // Target for each input
    133133    psArray *imageRegions = psArrayAlloc(data->numInputs); // Region for image
    134 
     134    psArray *regionHDUs = psArrayAlloc(data->numInputs);
     135    // Determine which projection cells we have to deal with.
    135136    for (int i = 0; i < data->numInputs; i++) {
    136137        pmFPAfile *file = pmFPAfileSelectSingle(data->config->files, "PPSKYCELL.IMAGE", i); // File to examine
     
    178179            target->data.S32[i] = numProj;
    179180            psTrace("ppSkycell", 3, "Image %d uses new projection\n", i);
    180 
     181            psArrayAdd(regionHDUs,1,hdu);
    181182            numProj++;
    182183        }
     
    184185
    185186    pmFPAfileActivate(data->config->files, false, NULL);
    186 
     187    // Loop over projections
    187188    for (int i = 0; i < numProj; i++) {
    188189        psRegion *projRegion = projRegions->data[i]; // Region for skycell projection
    189190        psTrace("ppSkycell", 2, "Projection %d: [%.0f:%.0f,%.0f:%.0f]\n",
    190191                i, projRegion->x0, projRegion->x1, projRegion->y0, projRegion->y1);
    191         int xSize = projRegion->x1 - projRegion->x0 + 1; // Size of unbinned image
     192        int xSize = -projRegion->x1 + projRegion->x0 + 1; // Size of unbinned image
    192193        int ySize = projRegion->y1 - projRegion->y0 + 1; // Size of unbinned image
    193194        // Size of binned image 1
     
    198199        psImage *image1 = psImageAlloc(numCols1, numRows1, PS_TYPE_F32); // Binned image
    199200        psImage *image2 = psImageAlloc(numCols2, numRows2, PS_TYPE_F32); // Binned image
    200         psImageInit(image1, 0);
    201         psImageInit(image2, 0);
    202 
     201        psImageInit(image1,NAN);
     202        psImageInit(image2,NAN);
     203       
    203204        psImage *mask1 = NULL, *mask2 = NULL; // Binned masks
    204205        if (data->masksName) {
     
    208209            psImageInit(mask2, 0xFF);
    209210        }
    210 
     211        pmHDU *projhdu = NULL;
     212        int modify_wcs1 = 1;
     213        int modify_wcs2 = 1;
     214        // Loop over inputs to this projection.
    211215        for (int j = 0; j < data->numInputs; j++) {
    212216            if (target->data.S32[j] != i) {
    213217                continue;
    214218            }
    215 
    216219            pmFPAfileActivateSingle(data->config->files, true, "PPSKYCELL.IMAGE", j);
    217220            if (data->masksName) {
     
    227230
    228231            pmFPAfile *file = pmFPAfileSelectSingle(data->config->files, "PPSKYCELL.IMAGE", j);
     232            if (!projhdu) {
     233              projhdu = file->fpa->hdu;
     234              //              psMetadataCopy(projhdu->header,file->fpa->hdu->header);
     235            }
     236#if 0
     237            else {
     238              if ((psMetadataLookupF32(NULL,file->fpa->hdu->header,"CRPIX1") >=
     239                   psMetadataLookupF32(NULL,projhdu->header,"CRPIX1"))&&
     240                  (psMetadataLookupF32(NULL,file->fpa->hdu->header,"CRPIX2") >=
     241                   psMetadataLookupF32(NULL,projhdu->header,"CRPIX1"))) {
     242                projhdu = file->fpa->hdu;
     243                psMetadataCopy(projhdu->header,file->fpa->hdu->header);
     244              }
     245            }
     246#endif   
     247           
    229248            pmReadout *inRO = pmFPAviewThisReadout(view, file->fpa); // Readout with input
    230249            psFree(view);
    231250
    232             // Flip images; no idea why this has to be done, but apparently it does
    233             {
    234                 psImage *rot = psImageRotate(NULL, inRO->image, M_PI, NAN, PS_INTERPOLATE_BILINEAR);
    235                 psFree(inRO->image);
    236                 inRO->image = rot;
    237             }
    238             if (inRO->mask) {
    239                 psImage *rot = psImageRotate(NULL, inRO->mask, M_PI, 0, PS_INTERPOLATE_FLAT);
    240                 psFree(inRO->mask);
    241                 inRO->mask = rot;
    242             }
    243 
     251            //      data->maskVal = 0xffff;
    244252            pmReadout *bin1RO = pmReadoutAlloc(NULL), *bin2RO = pmReadoutAlloc(NULL); // Binned readouts
    245253            if (!pmReadoutRebin(bin1RO, inRO, data->maskVal, data->bin1, data->bin1)) {
     
    256264            psRegion *imageRegion = imageRegions->data[j]; // Region for image
    257265            // Offsets for image on skycell
    258             int xOffset1 = (imageRegion->x0 - projRegion->x0) / (float)data->bin1;
    259             int yOffset1 = (imageRegion->y0 - projRegion->y0) / (float)data->bin1;
     266            int xOffset1 = (-imageRegion->x0 + projRegion->x0) / (float)data->bin1;
     267            int yOffset1 = (-imageRegion->y1 + projRegion->y1) / (float)data->bin1;
    260268            int xOffset2 = xOffset1 / (float)data->bin2, yOffset2 = yOffset1 / (float)data->bin2;
    261 
    262269            // XXX Completely neglecting rotations
    263270            // The skycells are divided up neatly with them all having the same orientation
    264             psImageOverlaySection(image1, bin1RO->image, xOffset1, yOffset1, "=");
    265             psImageOverlaySection(image2, bin2RO->image, xOffset2, yOffset2, "=");
     271            psImageOverlaySection(image1, bin1RO->image, xOffset1, yOffset1, "E");
     272            psImageOverlaySection(image2, bin2RO->image, xOffset2, yOffset2, "E");
    266273            if (data->masksName) {
    267                 psImageOverlaySection(mask1, bin1RO->mask, xOffset1, yOffset1, "=");
    268                 psImageOverlaySection(mask2, bin2RO->mask, xOffset2, yOffset2, "=");
     274                psImageOverlaySection(mask1, bin1RO->mask, xOffset1, yOffset1, "M");
     275                psImageOverlaySection(mask2, bin2RO->mask, xOffset2, yOffset2, "M");
    269276            }
    270277
     
    287294          pmFPAfileActivate(data->config->files, true, "PPSKYCELL.BIN1");
    288295          pmFPAfileActivate(data->config->files, true, "PPSKYCELL.BIN2");
     296          if (data->masksName) {
     297            pmFPAfileActivate(data->config->files, true, "PPSKYCELL.BIN1.MASK");
     298            pmFPAfileActivate(data->config->files, true, "PPSKYCELL.BIN2.MASK");
     299          }
    289300        }
    290301       
     
    313324
    314325        if (data->doFits) {
     326
     327          pmFPAfile *fits1 = pmFPAfileSelectSingle(data->config->files, "PPSKYCELL.BIN1", 0);
     328          // Copy header from projection root hdu
     329          fits1->fpa->hdu = pmHDUAlloc(NULL);
     330          fits1->fpa->hdu->header = psMetadataAlloc();
     331          psMetadataCopy(fits1->fpa->hdu->header,projhdu->header);
     332
     333          // Change wcs here
     334#define WCS_DEBUG 0
     335          if (modify_wcs1) {
     336            pmAstromWCS *WCS = pmAstromWCSfromHeader(fits1->fpa->hdu->header);
     337            double cd1f = 1.0 * data->bin1;
     338            double cd2f = 1.0 * data->bin1;
     339#if WCS_DEBUG
     340            fprintf(stderr,">>> %d %d (%g %g) (%g %g) (%g %g)\n",data->bin1,data->bin2,
     341                    cd1f,cd2f,WCS->cdelt1,WCS->cdelt2,
     342                    WCS->crpix1,WCS->crpix2
     343                    );
     344#endif
     345            WCS->cdelt1 *= cd1f;
     346            WCS->cdelt2 *= cd2f;
     347            WCS->crpix1 = WCS->crpix1 / cd1f;
     348            WCS->crpix2 = WCS->crpix2 / cd2f;
     349#if WCS_DEBUG
     350            fprintf(stderr,">>> %d %d (%g %g) (%g %g) (%g %g) %d %d %d %d\n",data->bin1,data->bin2,
     351                    cd1f,cd2f,WCS->cdelt1,WCS->cdelt2,
     352                    WCS->crpix1,WCS->crpix2,
     353                    WCS->trans->x->nX,              WCS->trans->x->nY,
     354                    WCS->trans->y->nX,              WCS->trans->y->nY
     355                    );
     356#endif
     357            for (int q = 0; q <= WCS->trans->x->nX; q++) {
     358              for (int r = 0; r <= WCS->trans->x->nY; r++) {
     359                WCS->trans->x->coeff[q][r] *= pow(cd1f,q) * pow(cd2f,r);
     360#if WCS_DEBUG
     361                fprintf(stderr,"PC: %d %d %g %g\n",
     362                        q,r,pow(cd1f,q) * pow(cd2f,r),
     363                        WCS->trans->x->coeff[q][r]);
     364#endif
     365              }
     366            }
     367            for (int q = 0; q <= WCS->trans->y->nX; q++) {
     368              for (int r = 0; r <= WCS->trans->y->nY; r++) {
     369                WCS->trans->y->coeff[q][r] *= pow(cd1f,q) * pow(cd2f,r);
     370#if WCS_DEBUG
     371                fprintf(stderr,"PC: %d %d %g %g\n",
     372                         q,r,pow(cd1f,q) * pow(cd2f,r),
     373                         WCS->trans->y->coeff[q][r]);
     374#endif
     375              }
     376            }
     377            pmAstromWCStoHeader (fits1->fpa->hdu->header,WCS);
     378            WCS = pmAstromWCSfromHeader(fits1->fpa->hdu->header);
     379#if WCS_DEBUG
     380            fprintf(stderr,">>> %d %d (%g %g) (%g %g) (%g %g)\n",data->bin1,data->bin2,
     381                    cd1f,cd2f,WCS->cdelt1,WCS->cdelt2,
     382                    WCS->crpix1,WCS->crpix2
     383                    );
     384#endif
     385            modify_wcs1 = 0;
     386          }
     387
     388         
     389          pmChip *Fchip1 = pmFPAfileThisChip(data->config->files, view, "PPSKYCELL.BIN1");
     390          psMetadataAddS32(Fchip1->concepts,PS_LIST_TAIL,"CHIP.XPARITY", PS_META_REPLACE,"",1);
     391          psMetadataAddS32(Fchip1->concepts,PS_LIST_TAIL,"CHIP.YPARITY", PS_META_REPLACE,"",1);
     392
    315393          pmCell *Fcell1 = pmFPAfileThisCell(data->config->files, view, "PPSKYCELL.BIN1"); // Rebinned cell 1
    316           pmCell *Fcell2 = pmFPAfileThisCell(data->config->files, view, "PPSKYCELL.BIN2"); // Rebinned cell 2
    317 
    318           // This is a hack to get a functioning header created so the fits images can be written out.
     394/*        // This is a hack to get a functioning header created so the fits images can be written out. */
    319395          psMetadataAddS32(Fcell1->concepts,PS_LIST_TAIL,"CELL.XPARITY", PS_META_REPLACE,"",1);
    320396          psMetadataAddS32(Fcell1->concepts,PS_LIST_TAIL,"CELL.YPARITY", PS_META_REPLACE,"",1);
    321397          psMetadataAddS32(Fcell1->concepts,PS_LIST_TAIL,"CELL.READDIR", PS_META_REPLACE,"",1);
     398
     399          pmReadout *Fro1 = pmReadoutAlloc(Fcell1);
     400          Fro1->image = image1;
     401          Fro1->mask = mask1;
     402          Fro1->data_exists = Fcell1->data_exists = Fcell1->parent->data_exists = true;
     403         
     404          fits1->save = true;
     405          fits1->fileIndex = i;
     406
     407          // Do the mask if we need to
     408          if (data->masksName) {
     409/*          pmFPAfile *Mask1 = pmFPAfileSelectSingle(data->config->files, "PPSKYCELL.BIN1.MASK", 0); */
     410/*          //      Mask1->fpa->hdu = pmHDUAlloc(NULL); */
     411/*          //      Mask1->fpa->hdu->header = psMetadataAlloc(); */
     412/*          //      psMetadataCopy(Mask1->fpa->hdu->header,fits1->fpa->hdu->header); */
     413/*          pmChip *Mchip1 = pmFPAfileThisChip(data->config->files, view, "PPSKYCELL.BIN1.MASK"); */
     414/*          psMetadataAddS32(Mchip1->concepts,PS_LIST_TAIL,"CHIP.XPARITY", PS_META_REPLACE,"",1); */
     415/*          psMetadataAddS32(Mchip1->concepts,PS_LIST_TAIL,"CHIP.YPARITY", PS_META_REPLACE,"",1); */
     416           
     417/*          pmCell *Mcell1 = pmFPAfileThisCell(data->config->files, view, "PPSKYCELL.BIN1.MASK"); // Rebinned cell 1 */
     418/*          /\*           // This is a hack to get a functioning header created so the fits images can be written out. *\/ */
     419/*          psMetadataAddS32(Mcell1->concepts,PS_LIST_TAIL,"CELL.XPARITY", PS_META_REPLACE,"",1); */
     420/*          psMetadataAddS32(Mcell1->concepts,PS_LIST_TAIL,"CELL.YPARITY", PS_META_REPLACE,"",1); */
     421/*          psMetadataAddS32(Mcell1->concepts,PS_LIST_TAIL,"CELL.READDIR", PS_META_REPLACE,"",1); */
     422           
     423/*          pmReadout *Mro1 = pmReadoutAlloc(Mcell1); */
     424/*          Mro1->image = image1; */
     425/*          Mro1->mask = mask1; */
     426/*          Mro1->data_exists = Mcell1->data_exists = Mcell1->parent->data_exists = true; */
     427           
     428/*          Mask1->save = true; */
     429/*          Mask1->fileIndex = i; */
     430          }
     431           
     432           
     433         
     434          // Repeat with second binned image
     435          pmFPAfile *fits2 = pmFPAfileSelectSingle(data->config->files, "PPSKYCELL.BIN2", 0);
     436          fits2->fpa->hdu = pmHDUAlloc(NULL);
     437          fits2->fpa->hdu->header = psMetadataAlloc();
     438          psMetadataCopy(fits2->fpa->hdu->header,projhdu->header);
     439
     440          if (modify_wcs2) {
     441            pmAstromWCS *WCS = pmAstromWCSfromHeader(fits2->fpa->hdu->header);
     442            double cd1f = 1.0 * data->bin2 * data->bin1;
     443            double cd2f = 1.0 * data->bin2 * data->bin1;
     444           
     445            WCS->cdelt1 *= cd1f;
     446            WCS->cdelt2 *= cd2f;
     447            WCS->crpix1 = WCS->crpix1 / cd1f;
     448            WCS->crpix2 = WCS->crpix2 / cd2f;
     449           
     450            for (int q = 0; q < WCS->trans->x->nX; q++) {
     451              for (int r = 0; r < WCS->trans->x->nY; r++) {
     452                WCS->trans->x->coeff[q][r] *= pow(cd1f,q) * pow(cd2f,r);
     453              }
     454            }
     455            for (int q = 0; q < WCS->trans->y->nX; q++) {
     456              for (int r = 0; r < WCS->trans->y->nY; r++) {
     457                WCS->trans->y->coeff[q][r] *= pow(cd1f,q) * pow(cd2f,r);
     458              }
     459            }
     460            pmAstromWCStoHeader (fits2->fpa->hdu->header,WCS);
     461            modify_wcs2 = 0;
     462          }
     463         
     464          pmChip *Fchip2 = pmFPAfileThisChip(data->config->files, view, "PPSKYCELL.BIN2");
     465          psMetadataAddS32(Fchip2->concepts,PS_LIST_TAIL,"CHIP.XPARITY", PS_META_REPLACE,"",1);
     466          psMetadataAddS32(Fchip2->concepts,PS_LIST_TAIL,"CHIP.YPARITY", PS_META_REPLACE,"",1);
     467
     468         
     469          pmCell *Fcell2 = pmFPAfileThisCell(data->config->files, view, "PPSKYCELL.BIN2"); // Rebinned cell 2
    322470          psMetadataAddS32(Fcell2->concepts,PS_LIST_TAIL,"CELL.XPARITY", PS_META_REPLACE,"",1);
    323471          psMetadataAddS32(Fcell2->concepts,PS_LIST_TAIL,"CELL.YPARITY", PS_META_REPLACE,"",1);
    324472          psMetadataAddS32(Fcell2->concepts,PS_LIST_TAIL,"CELL.READDIR", PS_META_REPLACE,"",1);
    325 
    326           psMetadataAddS32(Fcell1->parent->concepts,PS_LIST_TAIL,"CHIP.XPARITY", PS_META_REPLACE,"",1);
    327           psMetadataAddS32(Fcell1->parent->concepts,PS_LIST_TAIL,"CHIP.YPARITY", PS_META_REPLACE,"",1);
    328           psMetadataAddS32(Fcell2->parent->concepts,PS_LIST_TAIL,"CHIP.XPARITY", PS_META_REPLACE,"",1);
    329           psMetadataAddS32(Fcell2->parent->concepts,PS_LIST_TAIL,"CHIP.YPARITY", PS_META_REPLACE,"",1);
    330 
    331           pmReadout *Fro1 = pmReadoutAlloc(Fcell1), *Fro2 = pmReadoutAlloc(Fcell2); // Binned readouts
    332          
    333           Fro1->image = image1;
     473         
     474          pmReadout *Fro2 = pmReadoutAlloc(Fcell2);
    334475          Fro2->image = image2;
    335           Fro1->mask = mask1;
    336476          Fro2->mask = mask2;
    337          
    338           Fro1->data_exists = Fcell1->data_exists = Fcell1->parent->data_exists = true;
    339477          Fro2->data_exists = Fcell2->data_exists = Fcell2->parent->data_exists = true;
    340          
    341           pmFPAfile *fits1 = pmFPAfileSelectSingle(data->config->files, "PPSKYCELL.BIN1", 0);
    342           fits1->save = true;
    343           fits1->fileIndex = i;
    344           pmFPAfile *fits2 = pmFPAfileSelectSingle(data->config->files, "PPSKYCELL.BIN2", 0);
     478
    345479          fits2->save = true;
    346480          fits2->fileIndex = i;
     481
     482         
    347483        }
    348484
  • trunk/ppStack/src/Makefile.am

    r30620 r34800  
    1 bin_PROGRAMS = ppStack
     1bin_PROGRAMS = ppStack ppStackMedian
    22
    33if HAVE_SVNVERSION
     
    2525ppStack_LDFLAGS = $(PSLIB_LIBS)   $(PSMODULE_LIBS)   $(PSPHOT_LIBS)   $(PPSTATS_LIBS)   $(PPSTACK_LIBS)
    2626
     27ppStackMedian_CFLAGS    = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSPHOT_CFLAGS) $(PPSTATS_CFLAGS) $(PPSTACK_CFLAGS)
     28ppStackMedian_LDFLAGS = $(PSLIB_LIBS)   $(PSMODULE_LIBS)   $(PSPHOT_LIBS)   $(PPSTATS_LIBS)   $(PPSTACK_LIBS)
     29
    2730ppStack_SOURCES =               \
    2831        ppStack.c               \
     
    4346        ppStackCombinePrepare.c \
    4447        ppStackCombineInitial.c \
     48        ppStackCombineAlternate.c       \
     49        ppStackReject.c         \
     50        ppStackCombineFinal.c   \
     51        ppStackCleanup.c        \
     52        ppStackPhotometry.c     \
     53        ppStackFinish.c         \
     54        ppStackTarget.c         \
     55        ppStackUpdateHeader.c   \
     56        ppStackJPEGs.c          \
     57        ppStackStats.c          \
     58        ppStackErrorCodes.c
     59
     60ppStackMedian_SOURCES =         \
     61        ppStackMedian.c         \
     62        ppStackArguments.c      \
     63        ppStackCamera.c         \
     64        ppStackFiles.c          \
     65        ppStackMedianLoop.c             \
     66        ppStackPSF.c            \
     67        ppStackReadout.c        \
     68        ppStackVersion.c        \
     69        ppStackMatch.c          \
     70        ppStackSources.c        \
     71        ppStackThread.c         \
     72        ppStackOptions.c        \
     73        ppStackSetup.c          \
     74        ppStackPrepare.c        \
     75        ppStackConvolve.c       \
     76        ppStackCombinePrepare.c \
     77        ppStackCombineInitial.c \
     78        ppStackCombineAlternate.c       \
    4579        ppStackReject.c         \
    4680        ppStackCombineFinal.c   \
  • trunk/ppStack/src/ppStack.h

    r34092 r34800  
    3838    PPSTACK_FILES_STACK,                // Stack files
    3939    PPSTACK_FILES_UNCONV,               // Unconvolved stack files
    40     PPSTACK_FILES_PHOT                  // Files for photometry
     40    PPSTACK_FILES_PHOT,                 // Files for photometry
     41    PPSTACK_FILES_BKG,                  // Files for bkg
     42    PPSTACK_FILES_MEDIAN_IN,                // Files for median only stacks.
     43    PPSTACK_FILES_MEDIAN_OUT                // Files for median only stacks.
    4144} ppStackFileList;
    4245
     
    111114bool ppStackReadoutFinalThread(psThreadJob *job // Job to process
    112115    );
     116// Perform median stacking for background
     117bool ppStackCombineBackground(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config);
     118bool ppStackCombineMedian(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config);
    113119
    114120// Return software version
  • trunk/ppStack/src/ppStackArguments.c

    r31422 r34800  
    324324    }
    325325
     326   
    326327    psTrace("ppStack", 1, "Done parsing arguments\n");
    327328
  • trunk/ppStack/src/ppStackCamera.c

    r30620 r34800  
    156156            psString psf = psMetadataLookupStr(&mdok, input, "PSF"); // Name of PSF
    157157            psString sources = psMetadataLookupStr(&mdok, input, "SOURCES"); // Name of sources
    158 
     158            psString bkgmodel = psMetadataLookupStr(&mdok, input, "BKGMODEL"); // Name of warped background model
     159           
    159160            pmFPAfile *imageFile = defineFile(config, NULL, "PPSTACK.INPUT",
    160161                                              image, PM_FPA_FILE_IMAGE); // File for image
     
    215216            }
    216217
     218            // Grab bkgmodel information here
     219            if (!bkgmodel ||  strlen(bkgmodel) == 0) {
     220              // We have no background models.
     221            }
     222            else {
     223              pmFPAfile *inputBKG = defineFile(config,NULL,"PPSTACK.INPUT.BKGMODEL",bkgmodel,
     224                                               PM_FPA_FILE_IMAGE);
     225              if (!inputBKG) {
     226                psError(psErrorCodeLast(), false,
     227                        "Unable to define file from bkgmodel %d (%s)",i,bkgmodel);
     228                return(false);
     229              }
     230            }// End bkgmodel
     231
     232
     233           
     234           
    217235            i++;
    218236        }
     
    460478    jpeg2->save = true;
    461479
     480    // Output background
     481    pmFPAfile *outBkg = pmFPAfileDefineOutput(config,NULL,"PPSTACK.OUTPUT.BKGMODEL");
     482    if (!outBkg) {
     483      psError(psErrorCodeLast(), false, _("Unable to generate output file from PPSTACK.OUTPUT.BKGMODEL"));
     484      return(false);
     485    }
     486    if (outBkg->type != PM_FPA_FILE_IMAGE) {
     487      psError(PPSTACK_ERR_CONFIG, true, "PPSTACK.OUTPUT.BKGMODEL is not of type IMAGE");
     488      return(false);
     489    }
     490    outBkg->save = true;
     491    pmFPAfile *outBkgRest = pmFPAfileDefineOutput(config,NULL,"PPSTACK.OUTPUT.BKGREST");
     492    if (!outBkgRest) {
     493      psError(psErrorCodeLast(), false, _("Unable to generate output file from PPSTACK.OUTPUT.BKGREST"));
     494      return(false);
     495    }
     496    if (outBkgRest->type != PM_FPA_FILE_IMAGE) {
     497      psError(PPSTACK_ERR_CONFIG, true, "PPSTACK.OUTPUT.BKGREST is not of type IMAGE");
     498      return(false);
     499    }
     500   
    462501    // For photometry, we operate on the chip-mosaicked image
    463502    // we create a copy of the mosaicked image for psphot so we can write out a clean image
     
    496535    }
    497536
     537    // Define output file here.
     538   
    498539    return true;
    499540}
  • trunk/ppStack/src/ppStackCleanup.c

    r30874 r34800  
    2222    options->outRO = NULL;
    2323
    24     options->expRO->data_exists = false;
    25     options->expRO->parent->data_exists = false;
    26     options->expRO->parent->parent->data_exists = false;
    27     psFree(options->expRO);
    28     options->expRO = NULL;
     24    if (options->expRO) {
     25      options->expRO->data_exists = false;
     26      if (options->expRO->parent) {
     27        options->expRO->parent->data_exists = false;
     28        options->expRO->parent->parent->data_exists = false;
     29      }
     30      psFree(options->expRO);
     31      options->expRO = NULL;
     32    }
    2933
     34    if (options->bkgRO) {
     35      options->bkgRO->data_exists = false;
     36      if (options->bkgRO->parent) {
     37        options->bkgRO->parent->data_exists = false;
     38        options->bkgRO->parent->parent->data_exists = false;
     39      }
     40      psFree(options->bkgRO);
     41      options->bkgRO = NULL;
     42    }
     43   
    3044    for (int i = 0; i < options->num; i++) {
    3145        pmCellFreeData(options->cells->data[i]);
     
    6276
    6377bool ppStackCleanup (pmConfig *config, ppStackOptions *options) {
    64 
    6578    psExit exitValue = ppStackExitCode(PS_EXIT_SUCCESS); // Exit code
    66 
     79   
    6780    // Ensure everything closes
    6881    if (config) {
     
    7285        ppStackFileActivation(config, PPSTACK_FILES_UNCONV, true);
    7386        ppStackFileActivation(config, PPSTACK_FILES_PHOT, true);
     87        ppStackFileActivation(config, PPSTACK_FILES_MEDIAN_IN, true);
     88        ppStackFileActivation(config, PPSTACK_FILES_MEDIAN_OUT, true);
    7489        if (!ppStackFilesIterateUp(config)) {
    7590            psError(psErrorCodeLast(), false, "Unable to close files.");
  • trunk/ppStack/src/ppStackCombinePrepare.c

    r30620 r34800  
    11#include "ppStack.h"
    22
    3 bool ppStackCombinePrepare(const char *outName, const char *expName,
     3bool ppStackCombinePrepare(const char *outName, const char *expName, const char *bkgName,
    44                           ppStackFileList files, ppStackThreadData *stack,
    55                           ppStackOptions *options, pmConfig *config)
     
    2727    options->outRO = pmReadoutAlloc(cell); // Output readout
    2828
    29     pmCell *expCell = pmFPAfileThisCell(config->files, view, expName); // Exposure cell
    30     options->expRO = pmReadoutAlloc(expCell); // Output readout
     29    if (expName) {
     30      pmCell *expCell = pmFPAfileThisCell(config->files, view, expName); // Exposure cell
     31      options->expRO = pmReadoutAlloc(expCell); //Output readout
     32    }
     33/*     else { */
     34/*       options->expRO = NULL; */
     35/*     } */
     36    pmCell *bkgCell;
     37    int bkg_r0,bkg_c0;
     38    int bkg_nC,bkg_nR;
     39    if (bkgName) {
     40      ppStackFileActivationSingle(config, PPSTACK_FILES_BKG, true, 0);
     41      pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT.BKGMODEL", 0);
     42      pmFPAview *view = ppStackFilesIterateDown(config);
     43      pmReadout *ro = pmFPAviewThisReadout(view,file->fpa);
     44
     45      bkg_r0 = ro->image->row0;
     46      bkg_c0 = ro->image->col0;
     47      bkg_nC = ro->image->numCols;
     48      bkg_nR = ro->image->numRows;
     49      bkgCell = pmFPAfileThisCell(config->files, view, bkgName); // Bkg cell
     50     
     51      options->bkgRO = pmReadoutAlloc(bkgCell); // BKG readout
     52      //      if (!pmHDUGenerateForFPA(options->bkgRO->parent->parent->parent)) {
     53      options->bkgRO->parent->parent->parent->hdu = pmHDUAlloc(NULL);
     54      if (!options->bkgRO->parent->parent->parent->hdu) {
     55        fprintf(stderr,"failed to generate a HDU for this thing.\n");
     56      }
     57      options->bkgRO->parent->parent->parent->hdu->header = psMetadataCopy(options->bkgRO->parent->parent->parent->hdu->header,
     58                                                                           ro->parent->parent->parent->hdu->header);
     59
     60      options->bkgRO->parent->concepts = psMetadataCopy(options->bkgRO->parent->concepts,
     61                                                        ro->parent->concepts);
     62      options->bkgRO->parent->parent->concepts = psMetadataCopy(options->bkgRO->parent->parent->concepts,
     63                                                                ro->parent->parent->concepts);
     64      options->bkgRO->parent->parent->parent->concepts = psMetadataCopy(options->bkgRO->parent->parent->parent->concepts,
     65                                                                        ro->parent->parent->parent->concepts);
     66
     67    }
     68    else {
     69      options->bkgRO = NULL;
     70    }
    3171
    3272    psFree(view);
     
    4282    }
    4383
    44     if (!pmReadoutStackDefineOutput(options->expRO, col0, row0, numCols, numRows, true, true, 0)) {
     84    if (expName) {
     85      if (!pmReadoutStackDefineOutput(options->expRO, col0, row0, numCols, numRows, true, true, 0)) {
    4586        psError(PPSTACK_ERR_ARGUMENTS, false, "Unable to prepare output.");
    4687        return false;
     88      }
     89    }
     90
     91    if (bkgName) {
     92      if (!pmReadoutStackDefineOutput(options->bkgRO, bkg_c0, bkg_r0, bkg_nC, bkg_nR, false, false, 0)) {
     93        psError(PPSTACK_ERR_ARGUMENTS, false, "Unable to prepare output.");
     94        return false;
     95      }
     96     
     97
     98     
    4799    }
    48100
  • trunk/ppStack/src/ppStackFiles.c

    r31158 r34800  
    1414/// Files required for the convolution
    1515static char *filesConvolve[] = { "PPSTACK.INPUT", "PPSTACK.INPUT.MASK", "PPSTACK.INPUT.VARIANCE", NULL };
     16
     17/// Files required for the background
     18static char *filesBkg[] = { "PPSTACK.INPUT.BKGMODEL", NULL };
     19
     20/// Files required for median only stacking
     21static char *filesMedianIn[] =  { "PPSTACK.INPUT",                                                           
     22                              NULL };
     23/// Files required for median only stacking
     24static char *filesMedianOut[] =  { "PPSTACK.OUTPUT",                                                         
     25                              NULL };
    1626
    1727/// Regular (convolved) stack files
     
    1929                              "PPSTACK.OUTPUT.EXP", "PPSTACK.OUTPUT.EXPNUM", "PPSTACK.OUTPUT.EXPWT",
    2030                              "PPSTACK.OUTPUT.JPEG1", "PPSTACK.OUTPUT.JPEG2",
     31                              "PPSTACK.OUTPUT.BKGMODEL",
    2132                              NULL };
    2233/// Unconvolved stack files
     
    4152      case PPSTACK_FILES_UNCONV:   return filesUnconv;
    4253      case PPSTACK_FILES_PHOT:     return filesPhot;
     54    case PPSTACK_FILES_BKG:        return filesBkg;
     55    case PPSTACK_FILES_MEDIAN_IN:        return filesMedianIn;
     56    case PPSTACK_FILES_MEDIAN_OUT:        return filesMedianOut;
    4357      default:
    4458        psAbort("Unrecognised file list: %x", list);
  • trunk/ppStack/src/ppStackLoop.c

    r31435 r34800  
    6363
    6464    // Prepare for combination
    65     if (!ppStackCombinePrepare("PPSTACK.OUTPUT", "PPSTACK.OUTPUT.EXP", PPSTACK_FILES_STACK, stack, options, config)) {
     65    if (!ppStackCombinePrepare("PPSTACK.OUTPUT", "PPSTACK.OUTPUT.EXP", "PPSTACK.OUTPUT.BKGMODEL", PPSTACK_FILES_STACK, stack, options, config)) {
    6666        psError(psErrorCodeLast(), false, "Unable to prepare for combination.");
    6767        psFree(stack);
     
    8484        pmCellFreeData(options->cells->data[i]);
    8585    }
    86     psFree(stack);
     86    //    psFree(stack);
    8787
    8888    // Pixel rejection
     
    142142    }
    143143
     144    // Generate median background stack here.
     145    if (!ppStackCombineBackground(stack, options, config)) {
     146      psError(psErrorCodeLast(), false, "Unable to generate median of background images.");
     147      psFree(stack);
     148      return false;
     149    }
     150    ppStackFileActivation(config,PPSTACK_FILES_BKG ,false);   
    144151    // Photometry
    145152    psTrace("ppStack", 1, "Photometering stacked image....\n");
     
    171178        return false;
    172179    }
    173     psFree(stack);
     180    //    psFree(stack);
    174181    psLogMsg("ppStack", PS_LOG_INFO, "Stage 7: Cleanup, WCS & JPEGS: %f sec", psTimerClear("PPSTACK_STEPS"));
    175182    ppStackMemDump("cleanup");
     
    186193
    187194        // Prepare for combination
    188         if (!ppStackCombinePrepare("PPSTACK.UNCONV", "PPSTACK.UNCONV.EXP", PPSTACK_FILES_UNCONV,
     195        if (!ppStackCombinePrepare("PPSTACK.UNCONV", "PPSTACK.UNCONV.EXP", NULL, PPSTACK_FILES_UNCONV,
    189196                                   stack, options, config)) {
    190197            psError(psErrorCodeLast(), false, "Unable to prepare for combination.");
  • trunk/ppStack/src/ppStackLoop.h

    r30620 r34800  
    44// Loop over the inputs, doing the combination
    55bool ppStackLoop(
     6    pmConfig *config,                    // Configuration
     7    ppStackOptions *options             // Options for stacking
     8    );
     9// Median only loop.
     10bool ppStackMedianLoop(
    611    pmConfig *config,                    // Configuration
    712    ppStackOptions *options             // Options for stacking
     
    3237    const char *outName,                // Name of output file
    3338    const char *expName,                // Name of exposure file
     39    const char *bkgName,                // Name of background file
    3440    ppStackFileList files,              // Files of interest
    3541    ppStackThreadData *stack,           // Stack
  • trunk/ppStack/src/ppStackOptions.h

    r34093 r34800  
    4848    // Rejection
    4949    psArray *rejected;                  // Rejected pixels
     50    // Background
     51    pmReadout *bkgRO;                   // Output background readout
     52    psArray   *bkgImages;               // Input background images
    5053} ppStackOptions;
    5154
  • trunk/ppStack/src/ppStackPrepare.c

    r34095 r34800  
    132132    psVectorInit(options->inputMask, 0);
    133133    options->exposures = psVectorAlloc(options->num, PS_TYPE_F32);
     134
    134135    psVectorInit(options->exposures, NAN);
    135136
     
    150151
    151152        options->exposures->data.F32[i] = psMetadataLookupF32(NULL, cell->concepts, "CELL.EXPOSURE");
     153        if ((options->exposures->data.F32[i] == 0)||
     154            (!(isfinite(options->exposures->data.F32[i])))){
     155          options->exposures->data.F32[i] = psMetadataLookupF32(NULL,recipe,"DEFAULT.EXPTIME");
     156        }
    152157        options->sumExposure += options->exposures->data.F32[i];
    153158
  • trunk/ppStack/src/ppStackReadout.c

    r30620 r34800  
    194194
    195195
    196 
    197196bool ppStackReadoutFinal(const pmConfig *config, pmReadout *outRO, pmReadout *expRO, const psArray *readouts,
    198197                         const psVector *mask, const psArray *rejected, const psVector *weightings,
  • trunk/ppStack/src/ppStackSetup.c

    r31158 r34800  
    8989    options->origMasks = psArrayAlloc(num);
    9090    options->origVariances = psArrayAlloc(num);
     91    options->bkgImages = psArrayAlloc(num);
    9192    pmFPAview *view = pmFPAviewAlloc(0);
     93    int nullMasks = 0;
     94    int nullVariances = 0;
    9295    for (int i = 0; i < num; i++) {
    9396        {
     
    97100        {
    98101            // We want the convolved mask, since that defines the area that has been tested for outliers
     102          if (options->convolve) {
    99103            options->origMasks->data[i] = psMemIncrRefCounter(options->convMasks->data[i]);
     104          }
     105          else {
     106            pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT.MASK", i);
     107            options->origMasks->data[i] = pmFPAfileName(file, view, config);
     108          }
     109          if (!(options->origMasks->data[i])) {
     110            nullMasks++;
     111          }
    100112        }
    101113        {
    102114            pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT.VARIANCE", i);
    103115            options->origVariances->data[i] = pmFPAfileName(file, view, config);
     116            if (!(options->origVariances->data[i])) {
     117              nullVariances++;
     118            }
    104119        }
     120/*      { */
     121/*        pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT.BKGMODEL", i); */
     122/*        options->bkgImages->data[i] = pmFPAfileName(file, view, config); */
     123/*      } */
    105124    }
     125    if (nullMasks == num) {
     126      psFree(options->origMasks);
     127    }
     128    if (nullVariances == num) {
     129      psFree(options->origVariances);
     130    }
     131   
    106132    psFree(view);
    107133
  • trunk/ppStack/src/ppStackThread.c

    r31158 r34800  
    4040    psFree(stack->maskFits);
    4141    psFree(stack->varianceFits);
     42    psFree(stack->bkgFits);
    4243    return;
    4344}
     
    6768        PS_ASSERT_ARRAYS_SIZE_EQUAL(cells, covariances, NULL);
    6869    }
    69 
     70   
    7071    ppStackThreadData *stack = psAlloc(sizeof(ppStackThreadData)); // Thread data, to return
    7172    psMemSetDeallocator(stack, (psFreeFunc)stackThreadDataFree);
     
    7778    stack->maskFits   = psArrayAlloc(numInputs);
    7879    stack->varianceFits = psArrayAlloc(numInputs);
     80    stack->bkgFits    = psArrayAlloc(numInputs);
    7981    for (int i = 0; i < numInputs; i++) {
    8082        if (!cells->data[i]) {
     
    9597            psFree(resolved); \
    9698        }
    97 
     99               
    98100        IMAGE_OPEN(imageNames, stack->imageFits, i);
    99         IMAGE_OPEN(maskNames, stack->maskFits, i);
    100         IMAGE_OPEN(varianceNames, stack->varianceFits, i);
     101        if (maskNames) {
     102          IMAGE_OPEN(maskNames, stack->maskFits, i);
     103        }
     104        if (varianceNames) {
     105          IMAGE_OPEN(varianceNames, stack->varianceFits, i);
     106        }
    101107    }
    102108
  • trunk/ppStack/src/ppStackThread.h

    r31158 r34800  
    2525    psArray *maskFits;                  // FITS file pointers for masks
    2626    psArray *varianceFits;              // FITS file pointers for variances
     27    psArray *bkgFits;                   // FITS file pointers for background models
    2728} ppStackThreadData;
    2829
  • trunk/ppStack/src/ppStackUpdateHeader.c

    r31158 r34800  
    66
    77    pmReadout *outRO = options->outRO;                                      // Output readout
     8    pmReadout *expRO = options->expRO;
    89
    910    // Propagate WCS
    1011    bool wcsDone = false;           // Have we done the WCS?
    1112    for (int i = 0; i < options->num && !wcsDone; i++) {
    12         if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
     13      if ((options->inputMask)&&(options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i])) {
    1314            continue;
    1415        }
     
    123124        snprintf (field, 64, "AIR_%04d", i);
    124125        psMetadataAddF32(hdu->header, PS_LIST_TAIL, field, PS_META_REPLACE, "input image airmass", value);
    125     }   
     126    }
     127
     128    // Copy information into expRO, because it should be there too.
     129    if ((expRO)&&(expRO->parent)) {
     130      pmHDU *expROhdu = pmHDUFromCell(expRO->parent);
     131      if (!expROhdu->header) {
     132        expROhdu->header = psMetadataAlloc();
     133      }
     134      expRO->parent->parent->parent->hdu->header = psMetadataCopy(expRO->parent->parent->parent->hdu->header,
     135                                                                  outRO->parent->parent->parent->hdu->header);
     136     
     137      expRO->parent->concepts = psMetadataCopy(expRO->parent->concepts,
     138                                               outRO->parent->concepts);
     139      expRO->parent->parent->concepts = psMetadataCopy(expRO->parent->parent->concepts,
     140                                                       outRO->parent->concepts);
     141      expRO->parent->parent->parent->concepts = psMetadataCopy(expRO->parent->parent->parent->concepts,
     142                                                               outRO->parent->parent->parent->concepts);
     143    }
     144   
    126145    return true;
    127146}
  • trunk/ppViz/src/ppVizPSF/ppVizPSFCamera.c

    r26367 r34800  
    1919    files->data[0] = psStringCopy(name);
    2020    if (psMetadataLookup(config->arguments, file)) {
     21
    2122        psMetadataRemoveKey(config->arguments, file);
    2223    }
     
    4243        fileArguments("SOURCES", data->sourcesName, "Input sources", data->config);
    4344        pmFPAfile *srcs = pmFPAfileBindFromArgs(&status, psf, data->config,
    44                                                 "PSPHOT.INPUT.CMF", "SOURCES"); // File
     45                                                "PSPHOT.INPUT.CMF", "SOURCES"); // File
     46        fprintf(stderr,"%ld %d\n",(long) srcs, status);
    4547        if (!status || !srcs) {
    4648            psError(PS_ERR_IO, false, "Failed to build file from PSPHOT.INPUT.CMF");
  • trunk/ppViz/src/ppVizPSF/ppVizPSFLoop.c

    r27667 r34800  
    2020        return NULL;
    2121    }
    22 
     22    fprintf(stderr,"Woo!\n");
    2323    pmChip *chip;                       // Chip from FPA
    2424    while ((chip = pmFPAviewNextChip(view, psfFile->fpa, 1))) {
     
    5656                psWarning("More than one readout present for chip %d, cell %d", view->chip, view->cell);
    5757            }
    58 
     58            fprintf(stderr,"Woo!\n");
    5959            pmReadout *readout;         // Readout from cell
    6060            while ((readout = pmFPAviewNextReadout(view, psfFile->fpa, 1))) {
     61              fprintf(stderr,"Woo?\n");
    6162                if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
    6263                    psError(PS_ERR_UNKNOWN, false, "Error loading data from files.");
    6364                    return false;
    6465                }
    65                 if (!readout->data_exists) {
    66                     continue;
    67                 }
    68 
     66                fprintf(stderr,"Woo2?\n");
    6967                pmPSF *psf = psMetadataLookupPtr(NULL, chip->analysis, "PSPHOT.PSF");              // PSF
    7068                assert(psf);
     
    7270                bool mdok;              // Status of MD lookup
    7371                psArray *sources = psMetadataLookupPtr(&mdok, readout->analysis, "PSPHOT.SOURCES"); // Sources
     72
     73                if (sources && !readout->data_exists) {  // This fails if -sources not specified
     74                    continue;
     75                }
     76                readout->data_exists = true;
     77                fprintf(stderr,"Woo! %ld\n", sources ? sources->n : -1);
     78
     79                fprintf(stderr,"%d\n",mdok);
    7480                int numCols = 0, numRows = 0;              // Size of image
    7581                psVector *xOffset = NULL, *yOffset = NULL; // Offset from source to true position
     
    8086                    psLogMsg("ppVizPSF", PS_LOG_INFO, "Generating %dx%d image", numCols, numRows);
    8187                }
    82                 if (sources) {
     88                if (sources && !sources->n) {
    8389                    psMemIncrRefCounter(sources);
    8490                    psLogMsg("ppVizPSF", PS_LOG_INFO, "Using %ld input sources from CMF file", sources->n);
     
    8995
    9096                if (data->fakeNum > 0 && isfinite(data->fakeMag)) {
     97                  fprintf(stderr,"Here! fakes\n");
    9198                    long numOld = 0; // Old number of sources
    9299                    long numNew = -1; // New number of sources
     
    118125                }
    119126                if (!sources && !data->input) {
     127                  fprintf(stderr,"Here! default\n");
    120128                    // Generate fake image with only a single realisation of the PSF
    121129                    sources = psArrayAlloc(1);
     
    151159                psFree(psf->residuals);
    152160                psf->residuals = NULL;
    153 
     161                fprintf(stderr,"still here");
    154162                if (sources) {
     163                  fprintf(stderr,"Here! sources?\n");
    155164                    if (!pmReadoutFakeFromSources(readout, numCols, numRows, sources, 0, xOffset, yOffset,
    156165                                                  psf, data->minFlux, 0, false, true)) {
     
    159168                    }
    160169                } else if (data->input) {
     170
    161171                    psVector *x = data->input->data[0]; // x coordinates
    162172                    psVector *y = data->input->data[1]; // y coordinates
    163173                    psVector *mag = data->input->data[2]; // Magnitudes
     174                    fprintf(stderr,"Here! input? %d %d %g %d %ld\n",numCols,numRows,data->minFlux,1,x->n);
    164175                    if (!pmReadoutFakeFromVectors(readout, numCols, numRows, x, y, mag, xOffset, yOffset,
    165176                                                  psf, data->minFlux, 0, false, true)) {
     
    168179                    }
    169180                }
    170 
     181               
    171182                psFree(sources);
    172183                psFree(xOffset);
  • trunk/psLib/src/imageops/psImageInterpolate.c

    r34365 r34800  
    3131#include "psImageConvolve.h"
    3232
    33 # define IS_BILIN_SEPARABLE 0
     33# define IS_BILIN_SEPARABLE 1
    3434
    3535#include "psImageInterpolate.h"
     
    189189    switch (mode) {
    190190      case PS_INTERPOLATE_FLAT:
     191      case PS_INTERPOLATE_BILINEAR_SIMPLE:
    191192        // Nothing to pre-compute
    192193        break;
     
    287288# endif
    288289      case PS_INTERPOLATE_BIQUADRATIC:
     290      case PS_INTERPOLATE_BILINEAR_SIMPLE:
    289291        // 2D kernel, would cost too much memory to pre-calculate
    290292        break;
     293
    291294      default:
    292295        psAbort("Unsupported interpolation mode: %x", mode);
     
    937940
    938941
     942psImageInterpolateStatus interpolateJustWork(double *imageValue, double *varianceValue,
     943                                             psImageMaskType *maskValue, float x, float y,
     944                                             const psImageInterpolation *interp) {
     945  float u1,u2;
     946  int xl,xh;
     947  int yl,yh;
     948  const psImage *image = interp->image; // Image to interpolate
     949
     950  xl = floor(x);
     951  if (xl < 0) { xl = 0; }
     952  if (xl >= image->numCols) {xl = image->numCols - 1; }
     953  xh = xl + 1;
     954  if (xh >= image->numCols) {xh = image->numCols - 1; }
     955
     956  yl = floor(y);
     957  if (yl < 0) { yl = 0; }
     958  if (yl >= image->numRows) {yl = image->numRows - 1; }
     959  yh = yl + 1;
     960  if (yh >= image->numRows) {yh = image->numRows - 1; }
     961
     962  if (imageValue && image) {
     963    if (image->data.F32[yl][xl] == image->data.F32[yl][xh]) {
     964      u1 = image->data.F32[yl][xh];
     965    }
     966    else {
     967      u1 = (xh - x) * image->data.F32[yl][xl] + (x - xl) * image->data.F32[yl][xh];
     968    }
     969    if (image->data.F32[yh][xl] == image->data.F32[yh][xh]) {
     970      u2 = image->data.F32[yh][xh];
     971    }
     972    else {
     973      u2 = (xh - x) * image->data.F32[yh][xl] + (x - xl) * image->data.F32[yh][xh];
     974    }
     975    if (u1 == u2) {
     976      *imageValue = u1;
     977    }
     978    else {
     979      *imageValue = (yh - y) * u1 + (y - yl) * u2;
     980    }
     981    if ((floor(x) >= image->numCols)||
     982        (floor(y) >= image->numRows)) {
     983      *imageValue = NAN;
     984    }
     985  }
     986#if (0)
     987  if (*imageValue == 0.0) {
     988    fprintf(stderr,"IJK: Zero!: %g %g [%d %d %d %d] %g %g (%g %g %g %g)\n",
     989            x,y,xl,xh,yl,yh,u1,u2,
     990            image->data.F32[yl][xl],image->data.F32[yl][xh],image->data.F32[yh][xl],image->data.F32[yh][xh]
     991            );
     992  }
     993#endif
     994  return PS_INTERPOLATE_STATUS_GOOD;
     995}
     996 
    939997
    940998psImageInterpolateStatus psImageInterpolate(double *imageValue, double *varianceValue,
     
    9691027      case PS_INTERPOLATE_BIQUADRATIC:
    9701028        return interpolateKernel(imageValue, varianceValue, maskValue, x, y, interp);
     1029      case PS_INTERPOLATE_BILINEAR_SIMPLE:
     1030        return interpolateJustWork(imageValue, varianceValue, maskValue, x, y, interp);
    9711031      case PS_INTERPOLATE_BILINEAR:
    9721032# if (!IS_BILIN_SEPARABLE)
    973         return interpolateKernel(imageValue, varianceValue, maskValue, x, y, interp);
     1033        return interpolateKernel(imageValue, varianceValue, maskValue, x, y, interp);
    9741034# endif
    9751035      case PS_INTERPOLATE_GAUSS:
     
    10191079    switch (mode) {
    10201080      case PS_INTERPOLATE_FLAT:
     1081      case PS_INTERPOLATE_BILINEAR_SIMPLE:
    10211082        // No smearing by design
    10221083        return 1.0;
     
    10831144    if (!strcasecmp(name, "FLAT"))     return PS_INTERPOLATE_FLAT;
    10841145    if (!strcasecmp(name, "BILINEAR")) return PS_INTERPOLATE_BILINEAR;
     1146    if (!strcasecmp(name, "SIMPLEBILINEAR")) return PS_INTERPOLATE_BILINEAR_SIMPLE;
    10851147    if (!strcasecmp(name, "BIQUADRATIC")) return PS_INTERPOLATE_BIQUADRATIC;
    10861148    if (!strcasecmp(name, "GAUSS"))    return PS_INTERPOLATE_GAUSS;
  • trunk/psLib/src/imageops/psImageInterpolate.h

    r21281 r34800  
    3333    PS_INTERPOLATE_LANCZOS3,            ///< Sinc interpolation with 6x6 pixel kernel
    3434    PS_INTERPOLATE_LANCZOS4,            ///< Sinc interpolation with 8x8 pixel kernel
     35    PS_INTERPOLATE_BILINEAR_SIMPLE,     ///< Simple manual bilinear interpolation
    3536} psImageInterpolateMode;
    3637
  • trunk/psLib/src/imageops/psImagePixelManip.c

    r12953 r34800  
    216216    }
    217217
    218 
     218#define psImageOverlayLoopClean(DATATYPE,OP) {   \
     219      for (int row=y0;row<imageRowLimit;row++) {            \
     220        ps##DATATYPE* imageRow = image->data.DATATYPE[row];        \
     221        ps##DATATYPE* overlayRow = overlay->data.DATATYPE[row-y0]; \
     222        for (int col=x0;col<imageColLimit;col++) {                 \
     223          if (!isfinite(imageRow[col])) {                          \
     224            imageRow[col] OP overlayRow[col-x0];                   \
     225          }                                                        \
     226          else if (!isfinite(overlayRow[col-x0])) {                \
     227            imageRow[col] = imageRow[col];                         \
     228          }                                                        \
     229          else {                                                   \
     230            imageRow[col] = overlayRow[col-x0];                    \
     231          }                                                             \
     232        }                                                               \
     233      }                                                                 \
     234      pixelsOverlaid += (imageRowLimit - y0) * (imageColLimit - x0);    \
     235    }
     236
     237#define psImageOverlayLoopMask(DATATYPE) {                  \
     238      for (int row=y0;row<imageRowLimit;row++) {            \
     239        ps##DATATYPE* imageRow = image->data.DATATYPE[row];        \
     240        ps##DATATYPE* overlayRow = overlay->data.DATATYPE[row-y0]; \
     241        for (int col=x0;col<imageColLimit;col++) {                 \
     242          if (!isfinite(imageRow[col])) {                          \
     243            imageRow[col] = overlayRow[col-x0];            \
     244          }                                                        \
     245          else if (!isfinite(overlayRow[col-x0])) {                \
     246            imageRow[col] = imageRow[col];                         \
     247          }                                                        \
     248          else {                                                   \
     249            imageRow[col] &= overlayRow[col-x0];                   \
     250          }                                                             \
     251        }                                                               \
     252      }                                                                 \
     253      pixelsOverlaid += (imageRowLimit - y0) * (imageColLimit - x0);    \
     254    }
     255       
     256   
     257   
    219258    #define psImageOverlayLoop(DATATYPE,OP) { \
    220259        for (int row=y0;row<imageRowLimit;row++) { \
    221260            ps##DATATYPE* imageRow = image->data.DATATYPE[row]; \
    222261            ps##DATATYPE* overlayRow = overlay->data.DATATYPE[row-y0]; \
    223             for (int col=x0;col<imageColLimit;col++) { \
    224                 imageRow[col] OP overlayRow[col-x0]; \
    225             } \
    226         } \
     262            for (int col=x0;col<imageColLimit;col++) {                \
     263                imageRow[col] OP overlayRow[col-x0];                  \
     264              }                                                        \
     265        }                                                              \
    227266        pixelsOverlaid += (imageRowLimit - y0) * (imageColLimit - x0); \
    228     }
     267      }
    229268
    230269    #define psImageOverlayLoopDivide(DATATYPE,BADVALUE) { \
     
    273312        psImageOverlayLoop(DATATYPE,*=); \
    274313        break; \
     314    case 'E': \
     315      psImageOverlayLoopClean(DATATYPE,=); \
     316      break;                               \
    275317    case '/': \
    276318        psImageOverlayLoopDivide(DATATYPE,BADVALUE); \
    277319        break; \
    278320    case '=': \
    279         psImageOverlaySetLoop(DATATYPE); \
     321        psImageOverlaySetLoop(DATATYPE);                \
    280322        break; \
    281323    default: \
     
    286328    } \
    287329    break;
     330    #define psImageOverlayCaseInt(DATATYPE,BADVALUE) \
     331case PS_TYPE_##DATATYPE: \
     332    switch (*op) { \
     333    case '+': \
     334        psImageOverlayLoop(DATATYPE,+=); \
     335        break; \
     336    case '-': \
     337        psImageOverlayLoop(DATATYPE,-=); \
     338        break; \
     339    case '*': \
     340        psImageOverlayLoop(DATATYPE,*=); \
     341        break; \
     342    case 'E': \
     343      psImageOverlayLoopClean(DATATYPE,=); \
     344      break;                               \
     345    case 'M':                              \
     346      psImageOverlayLoopMask(DATATYPE);    \
     347      break;                               \
     348    case '/': \
     349        psImageOverlayLoopDivide(DATATYPE,BADVALUE); \
     350        break; \
     351    case '=': \
     352        psImageOverlaySetLoop(DATATYPE);                \
     353        break; \
     354    default: \
     355        psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
     356                _("Specified operation, '%s', is not supported."), \
     357                op); \
     358        return pixelsOverlaid; \
     359    } \
     360    break;
    288361
    289362    switch (type) {
    290         psImageOverlayCase(U8, 0);
    291         psImageOverlayCase(U16,0);
    292         psImageOverlayCase(U32,0);       // Not a requirement
    293         psImageOverlayCase(U64,0);       // Not a requirement
    294         psImageOverlayCase(S8, 0);
    295         psImageOverlayCase(S16,0);
    296         psImageOverlayCase(S32,0);       // Not a requirement
    297         psImageOverlayCase(S64,0);       // Not a requirement
     363        psImageOverlayCaseInt(U8, 0);
     364        psImageOverlayCaseInt(U16,0);
     365        psImageOverlayCaseInt(U32,0);       // Not a requirement
     366        psImageOverlayCaseInt(U64,0);       // Not a requirement
     367        psImageOverlayCaseInt(S8, 0);
     368        psImageOverlayCaseInt(S16,0);
     369        psImageOverlayCaseInt(S32,0);       // Not a requirement
     370        psImageOverlayCaseInt(S64,0);       // Not a requirement
    298371        psImageOverlayCase(F32,NAN);
    299372        psImageOverlayCase(F64,NAN);
  • trunk/psModules

  • trunk/psModules/src/camera/pmFPABin.c

    r24906 r34800  
    4343    }
    4444
     45    int Nbits = (int) (ceil(log(maskVal)/log(2)) + 1);
     46    int *bitcounter = malloc(sizeof(int) * Nbits);
     47    int pxlcount;
     48
    4549    int xLast = numColsIn - 1, yLast = numRowsIn - 1; // Last index
    4650    int yStart = psImageBinningGetFineY(binning, 0); // Starting input y for binning
     
    5559            float sum = 0.0;            // Sum of pixels
    5660            int numPix = 0;             // Number of pixels
     61
     62            for (int j = 0; j < Nbits; j++) { // Reset bit counter
     63              bitcounter[j] = 0;
     64            }
     65            pxlcount = 0;
     66           
    5767            for (int y = yStart; y < yStop; y++) {
    5868                for (int x = xStart; x < xStop; x++) {
     69                  if (inMask && (inMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] != 0)) {
     70                      for (int j = 0; j < Nbits; j++) {
     71                        psImageMaskType M = (psImageMaskType) pow(2,j);
     72                        if (inMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & M) {
     73                          bitcounter[j]++;
     74                        }
     75                      }
     76                    }
     77                 
    5978                    if (inMask && (inMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal)) {
    6079                        continue;
     
    6584                    sum += inImage->data.F32[y][x];
    6685                    numPix++;
     86
     87
    6788                }
    6889            }
    69 
     90           
     91           
    7092            // Values to set
    7193            float imageValue;
     
    79101            }
    80102            outImage->data.F32[yOut][xOut] = imageValue;
    81             outMask->data.PS_TYPE_IMAGE_MASK_DATA[yOut][xOut] = maskValue;
     103            //            outMask->data.PS_TYPE_IMAGE_MASK_DATA[yOut][xOut] = maskValue;
     104            outMask->data.PS_TYPE_IMAGE_MASK_DATA[yOut][xOut] = 0;
     105            for (int j = 0; j < Nbits; j++) {
     106              if (bitcounter[j] > 0.5 * pxlcount) {
     107                outMask->data.PS_TYPE_IMAGE_MASK_DATA[yOut][xOut] |= (int) pow(2,j);
     108              }
     109            }
    82110            xStart = xStop;
    83111        }
  • trunk/psModules/src/camera/pmFPAfileIO.c

    r34403 r34800  
    7676    while ((item = psMetadataGetAndIncrement (iter)) != NULL) {
    7777        pmFPAfile *file = item->data.V;
    78 
    7978        switch (place) {
    8079          case PM_FPA_BEFORE:
  • trunk/psModules/src/detrend/pmDark.c

    r33089 r34800  
    353353
    354354    // retrieve the required parameter vectors
    355     psArray *values  = psMetadataLookupPtr(&mdok, output->analysis, "DARK.VALUES");
    356     psAssert(values, "values not supplied");
     355    psArray *in_values  = psMetadataLookupPtr(&mdok, output->analysis, "DARK.VALUES");
     356    psAssert(in_values, "values not supplied");
    357357    psVector *roMask = psMetadataLookupPtr(&mdok, output->analysis, "DARK.RO.MASK");
    358358    psAssert(roMask, "roMask not supplied");
    359     psVector *orders = psMetadataLookupPtr(&mdok, output->analysis, "DARK.ORDERS");
    360     psAssert(orders, "orders not supplied");
    361 
    362     psPolynomialMD *poly = psPolynomialMDAlloc(orders); // Polynomial for fitting
     359    psVector *max_orders = psMetadataLookupPtr(&mdok, output->analysis, "DARK.ORDERS");
     360    psAssert(max_orders, "orders not supplied");
     361
     362    psArray *values_set = psArrayAlloc(max_orders->n);
     363    psArray *poly_set = psArrayAlloc(max_orders->n);
     364    psVector *logL = psVectorAlloc(max_orders->n,PS_TYPE_F64);
     365
     366    for (int i = 0; i < max_orders->n; i++) {
     367      psVector *orders = psVectorAlloc(i+1,PS_TYPE_U8);
     368      for (int j = 0; j < orders->n; j++) {
     369        orders->data.U8[j] = max_orders->data.U8[j];
     370      }
     371      poly_set->data[i] =  psPolynomialMDAlloc(orders); // Polynomial for fitting
     372     
     373      psArray *values = psArrayAlloc(in_values->n);
     374     
     375      for (int j = 0; j < values->n; j++) {
     376        psVector *these_values = psVectorAlloc(i+1,PS_TYPE_F32);
     377        psVector *input_values = in_values->data[j];
     378
     379        for (int k = 0; k < orders->n; k++) {
     380          these_values->data.F32[k] = input_values->data.F32[k];
     381        }
     382        values->data[j] = these_values;
     383      }
     384      values_set->data[i] = values;
     385    }
    363386
    364387    // retrieve the norm vector, if supplied
     
    383406    }
    384407
    385     pmDarkVisualInit(values);
     408    pmDarkVisualInit(values_set->data[max_orders->n - 1]);
    386409
    387410    pmReadout *outReadout = output->readouts->data[0];
     
    423446            }
    424447
    425             if (!psPolynomialMDClipFit(poly, pixels, NULL, mask, 0xff, values, iter, rej)) {
     448            int k_best = 0;
     449            for (int k = 0; k < max_orders->n; k++) {
     450              psPolynomialMD *poly = poly_set->data[k];
     451              psArray *values = values_set->data[k];
     452             
     453              if (!psPolynomialMDClipFit(poly, pixels, NULL, mask, 0xff, values, iter, rej)) {
    426454                psErrorClear();         // Nothing we can do about it
    427455                psVectorInit(poly->coeff, NAN);
    428             }
    429 
    430             pmDarkVisualPixelFit(pixels, mask);
    431             pmDarkVisualPixelModel(poly, values);
    432 
    433             for (int k = 0; k < poly->coeff->n; k++) {
     456              }
     457
     458              pmDarkVisualPixelFit(pixels, mask);
     459              pmDarkVisualPixelModel(poly, values);
     460
     461              // Insert math here to choose optimum model.
     462              logL->data.F64[k] = 0.0;
     463              psPolynomialMD *polySig = poly_set->data[0];
     464              for (int m = 0; m < poly->deviations->n; m++) {
     465                logL->data.F64[k] += pow(poly->deviations->data.F32[m] / polySig->stdevFit,2);
     466/*              if ((xOut == 20) && (yOut == 256)) { */
     467/*                psTrace("psModules.detrend",3,"pmDarkCombine DEV: %d %d: input %d models: Norders: %d logL: %g value: %g\n", */
     468/*                        xOut,yOut,m,k,logL->data.F64[k],poly->deviations->data.F32[m]); */
     469/*              } */
     470              }
     471              if (k > 0) {
     472                if ( ( logL->data.F64[k - 1] - logL->data.F64[k] ) > 1) { // Hard coded criterion for a ~5% limit with one degree of freedom
     473                  k_best = k;
     474                }
     475              }
     476              if ((xOut <= 600) && (yOut <= 600)) {
     477                psTrace("psModules.detrend",3,"pmDarkCombine: %d %d: models: Norders: %d logL: %g BestOrders: %d\n",
     478                        xOut,yOut,k,logL->data.F64[k],k_best);
     479              }
     480            }
     481            if (k_best > 1) {
     482              k_best = 1;
     483            }
     484/*          k_best = 1; */
     485            // Select the polynomial that seems best.
     486            psPolynomialMD *poly = poly_set->data[k_best];
     487             
     488            //            for (int k = 0; k < poly->coeff->n; k++) {
     489            for (int k = 0; k < max_orders->n + 1; k++) { // There is one more coefficient than is stored here.
    434490                pmReadout *ro = output->readouts->data[k]; // Readout of interest
    435                 ro->image->data.F32[yOut][xOut] = poly->coeff->data.F64[k];
     491                if (k < poly->coeff->n) {
     492                  ro->image->data.F32[yOut][xOut] = poly->coeff->data.F64[k];
     493                }
     494                else {
     495                  ro->image->data.F32[yOut][xOut] = 0.0;
     496                }
    436497            }
    437498            counts->data.U16[yOut][xOut] = poly->numFit;
  • trunk/psModules/src/imcombine/pmStack.c

    r34150 r34800  
    13581358}
    13591359
     1360bool pmStackSimpleMedianCombine(
     1361                                pmReadout *combined,
     1362                                psArray *input) {
     1363  int num = input->n;
     1364  //  int numCols, numRows;
     1365  int minInputCols, maxInputCols, minInputRows, maxInputRows; // Smallest and largest values to combine
     1366  int xSize, ySize;                   // Size of the output image
     1367
     1368  psArray *stack = psArrayAlloc(num); // Stack of readouts 
     1369  for (int i = 0; i < num; i++) {
     1370    //    pmStackData *data = input->data[i]; // Stack data for this input
     1371    pmReadout *ro = input->data[i]; // data->readout;  // Readout of interest
     1372    if (!ro) {
     1373      continue;
     1374    }
     1375    stack->data[i] = psMemIncrRefCounter(ro);
     1376  }   
     1377
     1378  if (!pmReadoutStackValidate(&minInputCols, &maxInputCols, &minInputRows, &maxInputRows, &xSize, &ySize,
     1379                              stack)) {
     1380    psError(psErrorCodeLast(), false, "Input stack is not valid.");
     1381    psFree(stack);
     1382    return false;
     1383  }
     1384
     1385  psVector *pixelData = psVectorAlloc(input->n,PS_TYPE_F32);
     1386  psStats  *stats     = psStatsAlloc(PS_STAT_ROBUST_MEDIAN);
     1387
     1388  for (int y = minInputRows; y < maxInputRows; y++) {
     1389    for (int x = minInputCols; x < maxInputCols; x++) {
     1390      for (int i = 0; i < input->n; i++) {
     1391        pmReadout *ro  = stack->data[i];
     1392        psImage *image = ro->image;
     1393        pixelData->data.F32[i] = image->data.F32[y][x];
     1394      }
     1395      if (!psVectorStats(stats,pixelData,NULL,NULL,0)) {
     1396        psError(PS_ERR_UNKNOWN, false, "Unable to calculate median");
     1397        psFree(stats);
     1398        psFree(pixelData);
     1399        psFree(stack);
     1400        return(false);
     1401      }
     1402      combined->image->data.F32[y][x] = stats->robustMedian;
     1403      combined->mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = 0;
     1404    }
     1405  }
     1406 
     1407  psFree(stats);
     1408  psFree(pixelData);
     1409  psFree(stack);
     1410  return (true);
     1411}
     1412
    13601413/// Stack input images
    13611414bool pmStackCombine(
  • trunk/psModules/src/imcombine/pmStack.h

    r27427 r34800  
    4141                              float addVariance ///< Additional variance when rejecting
    4242    );
     43/// Stack input images simply
     44bool pmStackSimpleMedianCombine(pmReadout *combined, ///< Combined readout (output)
     45                                psArray *input       ///< Input array of pmStackData
     46                                );
    4347
    4448/// Stack input images
  • trunk/psModules/src/objects/Makefile.am

    r34403 r34800  
    111111        pmSourceOutputs.h \
    112112        pmSourceIO.h \
     113        pmSourceSatstar.h \
    113114        pmSourcePlots.h \
    114115        pmSourceVisual.h \
  • trunk/psModules/src/objects/pmFootprintCullPeaks.c

    r34198 r34800  
    9191
    9292        // max flux is above threshold for brightest peak
    93         pmPeak *maxPeak = fp->peaks->data[0];
     93      pmPeak *maxPeak = NULL;
     94      for (int i = 0; i < fp->peaks->n; i++) {
     95        pmPeak *testPeak = fp->peaks->data[i];
     96        float this_peak = useSmoothedImage ? testPeak->smoothFlux : testPeak->rawFlux;
     97       
     98        if (isfinite(this_peak)) {
     99          maxPeak = fp->peaks->data[i];
     100          break;
     101        }
     102      }
     103      psAssert(maxPeak,"maxPeak was not set in these peaks");
     104      //      = fp->peaks->data[0];
    94105        float maxFlux = useSmoothedImage ? maxPeak->smoothFlux : maxPeak->rawFlux;
    95106
  • trunk/psphot

  • trunk/psphot/src

  • trunk/psphot/src/psphotStackImageLoop.c

  • trunk/pstamp/scripts

  • trunk/psvideophot

  • trunk/pswarp/src/pswarp.c

    r27904 r34800  
    4646        goto DIE;
    4747    }
     48    if (psMetadataLookupBool(NULL,config->arguments,"BACKGROUND.MODEL")) {
     49      if (!pswarpDefineBackground(config)) {
     50        goto DIE;
     51      }
     52    }
    4853
    4954    // Open the statistics file
     
    6671    if (!pswarpLoop(config, stats)) {
    6772        goto DIE;
     73    }
     74    if (psMetadataLookupBool(NULL,config->arguments,"BACKGROUND.MODEL")) {
     75      if (!pswarpLoopBackground(config, stats)) {
     76        fprintf(stderr,"Dying!\n");
     77        goto DIE;
     78      }
    6879    }
    6980
  • trunk/pswarp/src/pswarp.h

    r28043 r34800  
    6262    psImage *region;
    6363
     64    /** values which are needed to control the background model warping. */
     65    bool background_warping;
     66    double offset_x;
     67    double offset_y;
     68 
    6469    /** input values for this tile */
    6570    int gridX;
     
    8186bool pswarpParseCamera (pmConfig *config);
    8287bool pswarpDefine (pmConfig *config);
     88bool pswarpDefineBackground (pmConfig *config);
    8389bool pswarpLoop (pmConfig *config, psMetadata *stats);
     90bool pswarpLoopBackground (pmConfig *config, psMetadata *stats);
    8491psExit pswarpExitCode(psExit exitValue);
    8592bool pswarpTransformReadout (pmReadout *output, pmReadout *input, pmConfig *config);
  • trunk/pswarp/src/pswarpArguments.c

    r34089 r34800  
    8686    pmConfigFileSetsMD (config->arguments, &argc, argv, "MASK", "-mask", "-masklist");
    8787    pmConfigFileSetsMD (config->arguments, &argc, argv, "VARIANCE", "-variance", "-variancelist");
    88 
     88    pmConfigFileSetsMD (config->arguments, &argc, argv, "BACKGROUND", "-background", "-bkglist");
     89   
    8990    if (argc != 3) {
    9091        usage();
     
    164165    }
    165166
     167    bool doBKG = psMetadataLookupBool(&status,recipe, "BACKGROUND.MODEL"); ///< Generate the warped background model?
     168    if (!status) {
     169      doBKG = false;
     170      psWarning("BACKGROUND.MODEL is not set in the %s recipe -- defaulting to FALSE.", PSWARP_RECIPE);
     171    }
     172    int bkgXgrid = psMetadataLookupS32(&status,recipe, "BKG.XGRID"); ///< Xsize of background model
     173    if (!status) {
     174      bkgXgrid = 10;
     175      psWarning("BKG.XGRID is not set in the %s recipe -- defaultint to %d.",PSWARP_RECIPE,bkgXgrid);
     176    }
     177    int bkgYgrid = psMetadataLookupS32(&status,recipe, "BKG.YGRID"); ///< Xsize of background model
     178    if (!status) {
     179      bkgYgrid = 10;
     180      psWarning("BKG.YGRID is not set in the %s recipe -- defaultint to %d.",PSWARP_RECIPE,bkgYgrid);
     181    }
     182
     183   
    166184    // Set recipe values in the recipe (since we've possibly altered some)
    167185    psMetadataAddS32(recipe, PS_LIST_TAIL, "GRID.NX", PS_META_REPLACE,
     
    176194                     "Fraction of bad flux for a pixel to be marked as poor", poorFrac);
    177195    psMetadataAddBool(recipe, PS_LIST_TAIL, "PSF", PS_META_REPLACE, "Generate a PSF Model?", PSF);
    178 
     196    psMetadataAddBool(recipe, PS_LIST_TAIL, "BACKGROUND.MODEL", PS_META_REPLACE, "Generate the warped background model?", doBKG);
     197    psMetadataAddS32(recipe, PS_LIST_TAIL, "BKG.XGRID", PS_META_REPLACE, "Xsize of background model", bkgXgrid);
     198    psMetadataAddS32(recipe, PS_LIST_TAIL, "BKG.YGRID", PS_META_REPLACE, "Ysize of background model", bkgYgrid);
     199   
     200   
    179201    // Set recipe values in the arguments
    180202    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "GRID.NX", 0,
     
    189211                     "Fraction of bad flux for a pixel to be marked as poor", poorFrac);
    190212    psMetadataAddBool(config->arguments, PS_LIST_TAIL, "PSF", PS_META_REPLACE, "Generate a PSF Model?", PSF);
     213    psMetadataAddBool(config->arguments, PS_LIST_TAIL, "BACKGROUND.MODEL", PS_META_REPLACE, "Generate the warped background model?", doBKG);
     214    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "BKG.XGRID", PS_META_REPLACE, "Xsize of background model", bkgXgrid);
     215    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "BKG.YGRID", PS_META_REPLACE, "Ysize of background model", bkgYgrid);
    191216
    192217    psTrace("pswarp", 1, "Done with pswarpArguments...\n");
  • trunk/pswarp/src/pswarpDefine.c

    r27989 r34800  
    4141        return false;
    4242    }
    43 
     43   
    4444    // open the full skycell file; no need to defer different depths. only load the header data
    4545    pmFPAview *view = pmFPAviewAlloc (0);
     
    8686        psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.X0");
    8787        psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.Y0");
     88
     89       
    8890    }
    8991
     
    123125        }
    124126    }
    125 
     127   
    126128    view->chip = view->cell = view->readout = -1;
    127129    pmFPAAddSourceFromView(output->fpa, view, output->format);
     130
    128131
    129132    psFree (view);
    130133    return true;
    131134}
     135
     136bool pswarpDefineBackground (pmConfig *config) {
     137
     138    // load the PSWARP recipe
     139    psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE);
     140    if (!recipe) {
     141        psError(PSWARP_ERR_CONFIG, true, "Can't find PSWARP recipe!\n");
     142        return false;
     143    }
     144
     145    // select the input data sources
     146    pmFPAfile *skycell = psMetadataLookupPtr (NULL, config->files, "PSWARP.SKYCELL");
     147    if (!skycell) {
     148        psError(PSWARP_ERR_CONFIG, false, "Can't find skycell data!\n");
     149        return false;
     150    }
     151    pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PSWARP.OUTPUT.BKGMODEL");
     152    if (!output) {
     153        psError(PSWARP_ERR_CONFIG, false, "Can't find output data!\n");
     154        return false;
     155    }
     156    pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PSWARP.INPUT");
     157    if (!input) {
     158        psError(PSWARP_ERR_CONFIG, false, "Can't find input data!\n");
     159        return false;
     160    }
     161   
     162    // open the full skycell file; no need to defer different depths. only load the header data
     163    pmFPAview *view = pmFPAviewAlloc (0);
     164    pmFPAfileOpen (skycell, view, config);
     165
     166    // Read header and create target
     167    {
     168        if (!pmFPAReadHeaderSet(skycell->fpa, skycell->fits, config)) {
     169            psError(psErrorCodeLast(), false, "Unable to read headers for skycell.");
     170            psFree(view);
     171            return false;
     172        }
     173        view->chip = 0;
     174        view->cell = 0;
     175        view->readout = 0;
     176        pmCell *source = pmFPAfileThisCell(config->files, view, "PSWARP.SKYCELL"); ///< Source cell
     177        pmHDU *hdu = pmHDUFromCell(source); ///< HDU for source
     178        if (!hdu || !hdu->header) {
     179            psError(PM_ERR_PROG, false, "Unable to find header for sky cell.");
     180            psFree(view);
     181            return false;
     182        }
     183        int numCols = psMetadataLookupS32(NULL, hdu->header, "NAXIS1"); ///< Number of columns
     184        int numRows = psMetadataLookupS32(NULL, hdu->header, "NAXIS2"); ///< Number of rows
     185        if ((numCols == 0) || (numRows == 0)) {
     186            psError(PSWARP_ERR_DATA, false, "skycell has invalid dimensions %d x %d", numCols, numRows);
     187            psFree(view);
     188            return false;
     189        }
     190
     191        pmCell *target = pmFPAviewThisCell(view, output->fpa); ///< Target cell
     192        pmReadout *readout = pmReadoutAlloc(target); ///< Target readout
     193        readout->image = psImageAlloc(numCols / output->xBin, numRows / output->yBin, PS_TYPE_F32);
     194        psImageInit(readout->image, NAN);
     195        psFree(readout);                // Drop reference
     196
     197        bool status = false;
     198        psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.XBIN");
     199        psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.YBIN");
     200/*      psMetadataAddS32(target->concepts,PS_LIST_TAIL,"CELL.XBIN",PS_META_REPLACE,"",output->xBin); */
     201/*      psMetadataAddS32(target->concepts,PS_LIST_TAIL,"CELL.YBIN",PS_META_REPLACE,"",output->yBin); */
     202        psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.XSIZE");
     203        psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.YSIZE");
     204/*      psMetadataAddS32(target->concepts,PS_LIST_TAIL,"CELL.XSIZE",PS_META_REPLACE,"",numCols / output->xBin); */
     205/*      psMetadataAddS32(target->concepts,PS_LIST_TAIL,"CELL.YSIZE",PS_META_REPLACE,"",numRows / output->yBin); */
     206        psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.XPARITY");
     207        psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.YPARITY");
     208        psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.X0");
     209        psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.Y0");
     210
     211       
     212    }
     213
     214    // XXX this is not a sufficient test
     215    view->chip = 0;
     216    view->cell = 0;
     217    view->readout = -1;
     218    pmHDU *phu = pmFPAviewThisPHU(view, skycell->fpa); ///< Skycell PHU
     219    pmHDU *hdu = pmFPAviewThisHDU(view, skycell->fpa); ///< Skycell header
     220
     221    pmAstromWCS *WCS = pmAstromWCSfromHeader(hdu->header);
     222
     223    double cd1f = 1.0 * output->xBin;
     224    double cd2f = 1.0 * output->yBin;
     225   
     226    WCS->crpix1 = WCS->crpix1 / cd1f;
     227    WCS->crpix2 = WCS->crpix2 / cd2f;
     228   
     229    WCS->cdelt1 *= cd1f;
     230    WCS->cdelt2 *= cd2f;
     231
     232    WCS->trans->x->coeff[1][0] *= cd1f;
     233    WCS->trans->x->coeff[0][1] *= cd2f;
     234    WCS->trans->y->coeff[1][0] *= cd1f;
     235    WCS->trans->y->coeff[0][1] *= cd2f;
     236   
     237   
     238    pmAstromWCStoHeader (hdu->header,WCS);
     239
     240    bool bilevelAstrometry = false;
     241    if (phu) {
     242        char *ctype = psMetadataLookupStr(NULL, phu->header, "CTYPE1");
     243        if (ctype) {
     244            bilevelAstrometry = !strcmp(&ctype[4], "-DIS");
     245        }
     246    }
     247
     248    // We read from the skycell into the output.  i.e., the output receives the desired astrometry.
     249    pmChip *outputChip = pmFPAviewThisChip(view, output->fpa); ///< Chip in the output
     250    if (bilevelAstrometry) {
     251        if (!pmAstromReadBilevelMosaic(output->fpa, phu->header)) {
     252            psError(psErrorCodeLast(), false, "Unable to read bilevel mosaic astrometry for skycell.");
     253            psFree(view);
     254            return false;
     255        }
     256        if (!pmAstromReadBilevelChip(outputChip, hdu->header)) {
     257            psError(psErrorCodeLast(), false, "Unable to read bilevel chip astrometry for skycell.");
     258            psFree(view);
     259            return false;
     260        }
     261    } else {
     262        // we use a default FPA pixel scale of 1.0
     263      if (!pmAstromReadWCS(output->fpa, outputChip, hdu->header, 1.0)) {
     264            psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for skycell.");
     265            psFree(view);
     266            return false;
     267        }
     268    }
     269
     270   
     271    view->chip = view->cell = view->readout = -1;
     272    pmFPAAddSourceFromView(output->fpa, view, output->format);
     273
     274
     275    psFree (view);
     276    return true;
     277}
  • trunk/pswarp/src/pswarpFileNames.h

    r21368 r34800  
    1212  "PSWARP.MASK",
    1313  "PSWARP.VARIANCE",
     14  "PSWARP.BKGMODEL",
    1415  NULL
    1516};
     
    2021  "PSWARP.OUTPUT.MASK",
    2122  "PSWARP.OUTPUT.VARIANCE",
     23  "PSWARP.OUTPUT.BKGMODEL",
    2224  NULL
    2325};
  • trunk/pswarp/src/pswarpLoop.c

    r29928 r34800  
    179179        // read WCS data from the corresponding header
    180180        pmHDU *hdu = pmFPAviewThisHDU (view, astrom->fpa);
     181
     182       
    181183        if (bilevelAstrometry) {
    182184            if (!pmAstromReadBilevelChip (chip, hdu->header)) {
     
    195197            }
    196198        }
    197 
     199       
    198200        pmCell *cell;
    199201        while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
     
    227229
    228230                pswarpTransformReadout(output, readout, config);
    229 
     231               
    230232                if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
    231233                    psError(psErrorCodeLast(), false, "Unable to write files.");
     
    255257        goto DONE;
    256258    }
    257 
     259   
    258260    pmCell *outCell = output->parent;   ///< Output cell
    259261    pmChip *outChip = outCell->parent;  ///< Output chip
     
    450452    return true;
    451453}
     454
     455// Loop over the inputs, warp them to the output skycell and then write out the output.
     456bool pswarpLoopBackground(pmConfig *config, psMetadata *stats)
     457{
     458    bool status;
     459    bool mdok;                          // Status of MD lookup
     460    const char *skyCamera = psMetadataLookupStr(NULL, config->arguments,
     461                                                "SKYCELL.CAMERA");  // Name of camera for skycell
     462    pmConfigCamerasCull(config, skyCamera);
     463    pmConfigRecipesCull(config, "PSWARP,PPSTATS,PSPHOT,PSASTRO,MASKS,JPEG");
     464
     465    // load the recipe
     466    psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSWARP_RECIPE);
     467    if (!recipe) {
     468        psError(PSWARP_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE);
     469        return false;
     470    }
     471
     472    if (!pswarpSetMaskBits(config)) {
     473        psError(psErrorCodeLast(), false, "failed to set mask bits");
     474        return NULL;
     475    }
     476
     477    // select the input data sources
     478    pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PSWARP.BKGMODEL");
     479    if (!input) {
     480        psError(PSWARP_ERR_CONFIG, true, "Can't find input data!\n");
     481        return false;
     482    }
     483
     484    // use the external astrometry source if supplied
     485    pmFPAfile *astrom = psMetadataLookupPtr(NULL, config->files, "PSWARP.ASTROM");
     486    if (!astrom) {
     487        astrom = input;
     488    }
     489
     490    if (astrom->camera != input->camera) {
     491        psError(PSWARP_ERR_DATA, true, "Input camera and astrometry camera do not match.");
     492        return false;
     493    }
     494
     495    // select the output readout
     496    pmFPAview *view = pmFPAviewAlloc(0);
     497    view->chip = 0;
     498    view->cell = 0;
     499    view->readout = 0;
     500    pmReadout *output = pmFPAfileThisReadout(config->files, view, "PSWARP.OUTPUT.BKGMODEL");
     501    if (!output) {
     502        psError(PSWARP_ERR_CONFIG, true, "Can't find output background data!\n");
     503        return false;
     504    }
     505    psFree (view);
     506    // Turn all skycell files on to generate them, and then turn them off for the loop over the input images
     507    // the input, which is in a different format.
     508    {
     509        pswarpFileActivation(config, detectorFiles, false);
     510        pswarpFileActivation(config, photFiles, false);
     511        pswarpFileActivation(config, independentFiles, false);
     512        pswarpFileActivation(config, skycellFiles, true);
     513        if (!pswarpIOChecksBefore(config)) {
     514            psError(psErrorCodeLast(), false, "Unable to read files.");
     515            goto DONE;
     516        }
     517        pswarpFileActivation(config, skycellFiles, false);
     518    }
     519    // Read the input astrometry
     520    // XXX rather than use the activations here, this should just explicitly loop over the desired filerule
     521    {
     522
     523      pmFPAfileActivate(config->files, true, "PSWARP.ASTROM");
     524
     525        pmChip *chip;
     526        pmFPAview *view = pmFPAviewAlloc(0);
     527        if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
     528            psError(psErrorCodeLast(), false, "Unable to read files.");
     529            goto DONE;
     530        }
     531
     532        while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
     533#if 0
     534          // This needs to be removed because otherwise it throws an error of duplicate PSPHOT.DETECTIONS.
     535            if (!chip->process || !chip->file_exists) { continue; }
     536            if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
     537                psError(psErrorCodeLast(), false, "Unable to read files.");
     538                goto DONE;
     539            }
     540#endif
     541            pmCell *cell;
     542            while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
     543              psTrace ("pswarp", 4, "ACell %d: %x %x %d\n", view->cell, cell->file_exists, cell->process,psErrorCodeLast());
     544                if (!cell->process || !cell->file_exists) { continue; }
     545                if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE) ||
     546                    !pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {
     547                    psError(psErrorCodeLast(), false, "Unable to read files.");
     548                    goto DONE;
     549                }
     550            }
     551            if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {
     552                psError(psErrorCodeLast(), false, "Unable to write files.");
     553                goto DONE;
     554            }
     555        }
     556        if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {
     557            psError(psErrorCodeLast(), false, "Unable to write files.");
     558            goto DONE;
     559        }
     560        psFree(view);
     561        pswarpFileActivation(config, detectorFiles, true);
     562        pmFPAfileActivate(config->files, false, "PSWARP.ASTROM");
     563    }
     564
     565    // Don't care about the skycell anymore --- we've read it, and that's all we need to do.
     566    pmFPAfileActivate(config->files, false, "PSWARP.SKYCELL");
     567    view = pmFPAviewAlloc(0);
     568
     569    // find the FPA phu
     570    bool bilevelAstrometry = false;
     571    pmHDU *phu = pmFPAviewThisPHU(view, astrom->fpa);
     572
     573    //    pmAstromWCS *WCSF = pmAstromWCSfromHeader(phu->header);
     574   
     575    if (phu) {
     576        char *ctype = psMetadataLookupStr(NULL, phu->header, "CTYPE1");
     577        if (ctype) {
     578            bilevelAstrometry = !strcmp (&ctype[4], "-DIS");
     579        }
     580    }
     581    if (bilevelAstrometry) {
     582        if (!pmAstromReadBilevelMosaic(input->fpa, phu->header)) {
     583            psError(psErrorCodeLast(), false, "Unable to read bilevel mosaic astrometry for input FPA.");
     584            psFree(view);
     585            psFree(stats);
     586            goto DONE;
     587        }
     588    }
     589
     590    psList *cells = psListAlloc(NULL);  // List of cells, for concepts averaging
     591
     592    // files associated with the science image
     593    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
     594        psError(psErrorCodeLast(), false, "Unable to read files.");
     595        goto DONE;
     596    }
     597    pmChip *chip;
     598    while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
     599        psTrace ("pswarp", 4, "DChip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
     600        if (!chip->process || !chip->file_exists) { continue; }
     601        if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
     602            psError(psErrorCodeLast(), false, "Unable to read files.");
     603            goto DONE;
     604        }
     605
     606        // Pull information from the header of the background files so we can use it to set values.
     607        pmHDU *hdu = pmFPAviewThisHDU(view,input->fpa);
     608        psMetadata *header = hdu->header;
     609       
     610        int IMAXIS1 = psMetadataLookupS32(NULL,header,"IMNAXIS1");
     611        int IMAXIS2 = psMetadataLookupS32(NULL,header,"IMNAXIS2");
     612        int NAXIS1 = psMetadataLookupS32(NULL,header,"NAXIS1");
     613        int NAXIS2 = psMetadataLookupS32(NULL,header,"NAXIS2");
     614        char *CCDSUM = psMetadataLookupStr(NULL,header,"CCDSUM");
     615        int CCDSUM1 = atoi(strtok(CCDSUM," "));
     616        int CCDSUM2 = atoi(strtok(NULL," "));
     617       
     618        psMetadataAddF32(config->arguments,PS_LIST_TAIL,"BKG_WARP_XOFFSET", PS_META_REPLACE,
     619                         "xoffset for background model data", (NAXIS1 * CCDSUM1 - IMAXIS1) / (2.0 * CCDSUM1));
     620        psMetadataAddF32(config->arguments,PS_LIST_TAIL,"BKG_WARP_YOFFSET", PS_META_REPLACE,
     621                         "yoffset for background model data", (NAXIS2 * CCDSUM2 - IMAXIS2) / (2.0 * CCDSUM2));
     622        psTrace("pswarp",5,"%d %d %d %d %d %d %g %g %d %d",
     623                psMetadataLookupS32(NULL,header,"IMNAXIS1"),
     624                psMetadataLookupS32(NULL,header,"IMNAXIS2"),
     625                psMetadataLookupS32(NULL,header,"NAXIS1"),
     626                psMetadataLookupS32(NULL,header,"NAXIS2"),
     627                CCDSUM1,CCDSUM2,
     628                psMetadataLookupF32(NULL,config->arguments,"BKG_WARP_XOFFSET"),
     629                psMetadataLookupF32(NULL,config->arguments,"BKG_WARP_YOFFSET"),
     630                psMetadataLookupS32(NULL,config->arguments,"BKG.XGRID"),
     631                psMetadataLookupS32(NULL,config->arguments,"BKG.YGRID"));
     632       
     633       
     634        // read WCS data from the corresponding header
     635        hdu = pmFPAviewThisHDU (view, astrom->fpa);
     636
     637        pmAstromWCS *WCS = pmAstromWCSfromHeader(hdu->header);
     638
     639        double cd1f = (1.0 * CCDSUM1);// * (1.0 * psMetadataLookupS32(NULL,config->arguments,"BKG.XGRID"));
     640        double cd2f = (1.0 * CCDSUM2);// * (1.0 * psMetadataLookupS32(NULL,config->arguments,"BKG.YGRID"));
     641
     642        WCS->cdelt1 *= cd1f;
     643        WCS->cdelt2 *= cd2f;
     644        WCS->crpix1 = WCS->crpix1 / cd1f;
     645        WCS->crpix2 = WCS->crpix2 / cd2f;
     646
     647        // WCS->trans->x->nX/nY
     648        for (int q = 0; q <= WCS->trans->x->nX; q++) {
     649          for (int r = 0; r <= WCS->trans->x->nY; r++) {
     650            WCS->trans->x->coeff[q][r] *= pow(cd1f,q) * pow(cd2f,r);
     651          }
     652        }
     653        for (int q = 0; q <= WCS->trans->y->nX; q++) {
     654          for (int r = 0; r <= WCS->trans->y->nY; r++) {
     655            WCS->trans->y->coeff[q][r] *= pow(cd1f,q) * pow(cd2f,r);
     656          }
     657        }
     658        pmAstromWCStoHeader (hdu->header,WCS);
     659       
     660        if (bilevelAstrometry) {
     661            if (!pmAstromReadBilevelChip (chip, hdu->header)) {
     662                psError(psErrorCodeLast(), false, "Unable to read bilevel chip astrometry for input FPA.");
     663                psFree(view);
     664                psFree(stats);
     665                goto DONE;
     666            }
     667        } else {
     668            // we use a default FPA pixel scale of 1.0
     669            if (!pmAstromReadWCS (astrom->fpa, chip, hdu->header, 1.0)) {
     670                psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for input FPA.");
     671                psFree(view);
     672                psFree(stats);
     673                goto DONE;
     674            }
     675        }
     676        // Modify structure here.
     677
     678       
     679        pmCell *cell;
     680        while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
     681            psTrace ("pswarp", 4, "DCell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     682            if (!cell->process || !cell->file_exists) { continue; }
     683            if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
     684                psError(psErrorCodeLast(), false, "Unable to read files.");
     685                goto DONE;
     686            }
     687
     688            psListAdd(cells, PS_LIST_TAIL, cell);
     689
     690            // process each of the readouts
     691            pmReadout *readout;
     692            while ((readout = pmFPAviewNextReadout(view, input->fpa, 1)) != NULL) {
     693                if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
     694                    psError(psErrorCodeLast(), false, "Unable to read files.");
     695                    goto DONE;
     696                }
     697                if (!readout->data_exists) {
     698                    continue;
     699                }
     700
     701                for (int x = 0; x < readout->image->numCols; x++) {
     702                  for (int y = 0; y < readout->image->numRows; y++) {
     703                    readout->image->data.F32[y][x] = readout->image->data.F32[y][x] * (cd1f * cd2f) /
     704                      (psMetadataLookupS32(&mdok,config->arguments,"BKG.XGRID") *
     705                       psMetadataLookupS32(&mdok,config->arguments,"BKG.YGRID"));
     706                  }
     707                }
     708               
     709                psMetadataAddS32(config->arguments,PS_LIST_TAIL, "INTERPOLATION.MODE", PS_META_REPLACE, "", 8);
     710
     711                psMetadataAddBool(config->arguments,PS_LIST_TAIL, "BACKGROUND_WARPING", PS_META_REPLACE, "", true);
     712                pswarpTransformReadout(output, readout, config);
     713                psMetadataAddBool(config->arguments,PS_LIST_TAIL, "BACKGROUND_WARPING", PS_META_REPLACE, "", false);
     714
     715                if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
     716                    psError(psErrorCodeLast(), false, "Unable to write files.");
     717                    goto DONE;
     718                }
     719            }
     720            if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
     721                psError(psErrorCodeLast(), false, "Unable to write files.");
     722                goto DONE;
     723            }
     724        }
     725        if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
     726            psError(psErrorCodeLast(), false, "Unable to write files.");
     727            goto DONE;
     728        }
     729    }
     730    if (!output->data_exists) {
     731        psWarning("No overlap between input and skycell.");
     732        psphotFilesActivate(config, false);
     733        psFree(cells);
     734        psFree(view);
     735        goto DONE;
     736    }
     737    pmCell *outCell = output->parent;   ///< Output cell
     738    pmChip *outChip = outCell->parent;  ///< Output chip
     739    pmFPA *outFPA = outChip->parent;    ///< Output FP
     740
     741/*     if (!pswarpPixelsLit(output, stats, config)) { */
     742/*         psError(psErrorCodeLast(), false, "Unable to calculate pixel regions."); */
     743/*         psFree(cells); */
     744/*         psFree(view); */
     745/*         goto DONE; */
     746/*     } */
     747    psRegion *trimsec = psMetadataLookupPtr(NULL, outCell->concepts, "CELL.TRIMSEC"); ///< Trim section
     748    trimsec->x0 = trimsec->x1 = trimsec->y0 = trimsec->y1 = 0; ///< All pixels
     749
     750    if (!psMetadataCopy(outFPA->concepts, input->fpa->concepts)) {
     751        psError(psErrorCodeLast(), false, "Unable to copy FPA concepts from input to output.");
     752        psFree(stats);
     753        psFree(view);
     754        goto DONE;
     755    }
     756
     757    pmHDU *hdu = outFPA->hdu;           ///< HDU for the output warped image
     758
     759    // Copy header from target
     760    {
     761        pmFPAview *skyView = pmFPAviewAlloc(0); ///< View into skycell
     762        skyView->chip = skyView->cell = 0;
     763        pmCell *cell = pmFPAfileThisCell(config->files, skyView, "PSWARP.SKYCELL"); // Skycell cell
     764        psFree(skyView);
     765        pmHDU *skyHDU = pmHDUFromCell(cell); ///< HDU
     766        if (!skyHDU) {
     767            psError(PSWARP_ERR_DATA, false, "Unable to find skycell HDU.");
     768            psFree(view);
     769            goto DONE;
     770        }
     771        hdu->header = psMetadataCopy(hdu->header, skyHDU->header);
     772    }
     773    pswarpVersionHeader(hdu->header);
     774   
     775    if (!pmAstromWriteWCS(hdu->header, outFPA, outChip, WCS_NONLIN_TOL)) {
     776        psError(psErrorCodeLast(), false, "Unable to generate WCS header.");
     777        psFree(stats);
     778        goto DONE;
     779    }
     780    if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
     781        psError(psErrorCodeLast(), false, "Unable to write files.");
     782        goto DONE;
     783    }
     784    // Done with the detector side of things
     785    pswarpFileActivation(config, detectorFiles, false);
     786    pswarpFileActivation(config, independentFiles, false);
     787
     788
     789    // Add MD5 information for readout
     790    const char *chipName = psMetadataLookupStr(NULL, output->parent->parent->concepts, "CHIP.NAME");
     791    const char *cellName = psMetadataLookupStr(NULL, output->parent->concepts, "CELL.NAME");
     792    psString headerName = NULL; ///< Header name for MD5
     793    psStringAppend(&headerName, "MD5_%s_%s_%d", chipName, cellName, view->readout);
     794    psVector *md5 = psImageMD5(output->image); ///< md5 hash
     795    psString md5string = psMD5toString(md5); ///< String
     796    psFree(md5);
     797    psMetadataAddStr(hdu->header, PS_LIST_TAIL, headerName, PS_META_REPLACE,
     798                     "Image MD5", md5string);
     799    psFree(md5string);
     800    psFree(headerName);
     801    psFree(view);
     802 DONE:
     803
     804    return true;
     805}
  • trunk/pswarp/src/pswarpParseCamera.c

    r28442 r34800  
    8484    }
    8585
     86    pmFPAfile *inBackground = defineInputFile(config, NULL, "PSWARP.BKGMODEL", "BACKGROUND",
     87                                              PM_FPA_FILE_IMAGE);
     88    if (!inBackground) {
     89      psLogMsg("pswarp", PS_LOG_INFO, "No background models supplied");
     90    }
     91   
    8692    // The input skycell is a required argument: it defines the output image
    8793    // XXX we may need a different skycell structure here
     
    134140    }
    135141
     142    if (inBackground && psMetadataLookupBool(&mdok, recipe, "BACKGROUND.MODEL")) {
     143      pmFPAfile *outBackground = pmFPAfileDefineSkycell(config, NULL, "PSWARP.OUTPUT.BKGMODEL");
     144/*       pmFPAfile *outBackground = pmFPAfileDefineFromFPA(config,output->fpa, */
     145/*                                                      psMetadataLookupS32(&mdok,recipe,"BKG.XGRID"), */
     146/*                                                      psMetadataLookupS32(&mdok,recipe,"BKG.YGRID"), */
     147/*                                                      "PSWARP.OUTPUT.BKGMODEL"); */
     148      outBackground->xBin = psMetadataLookupS32(&mdok, recipe, "BKG.XGRID");
     149      outBackground->yBin = psMetadataLookupS32(&mdok, recipe, "BKG.YGRID");
     150     
     151      if (!outBackground) {
     152        psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.OUTPUT.BKGMODEL");
     153        return false;
     154      }
     155      outBackground->save = true;
     156    }
     157   
    136158    if (psMetadataLookupBool(&mdok, recipe, "PSF")) {
    137159        // This file, PSPHOT.INPUT, is just used as a carrier; output files (eg, PSPHOT.RESID) are defined by
  • trunk/pswarp/src/pswarpTransformReadout.c

    r34089 r34800  
    2929    psImageInterpolateMode interpolationMode = psMetadataLookupS32(NULL, config->arguments,
    3030                                                                   "INTERPOLATION.MODE"); ///< Mode for interp
     31
    3132    int numKernels = psMetadataLookupS32(NULL, config->arguments, "INTERPOLATION.NUM"); ///< Number of kernels
    3233
     
    6061    // output coordinates to input coordinates
    6162    pswarpMapGrid *grid = pswarpMapGridFromImage(input, output, nGridX, nGridY);
    62 
     63    //    if (psMetadataLookupBool(NULL,config->arguments,"BACKGROUND_WARPING")) {
     64   
    6365    // XXX optionally modify the grid based on this result and force the maxError < XXX
    6466    double maxError = pswarpMapGridMaxError(grid); // Maximum (positional) error from using grid
     
    130132            args->goodPixels = 0;
    131133
     134            if (psMetadataLookupBool(NULL,config->arguments,"BACKGROUND_WARPING")) {
     135              args->background_warping = true;
     136              args->offset_x = psMetadataLookupF32(NULL,config->arguments,"BKG_WARP_XOFFSET");
     137              args->offset_y = psMetadataLookupF32(NULL,config->arguments,"BKG_WARP_YOFFSET");
     138            }
     139
     140           
    132141            // allocate a job
    133142            psThreadJob *job = psThreadJobAlloc ("PSWARP_TRANSFORM_TILE");
     
    171180        } else {
    172181            pswarpTransformTileArgs *args = job->args->data[0];
    173             // fprintf (stderr, "finished job %d,%d, Nargs: %ld\n", args->gridX, args->gridY, job->args->n);
    174182            goodPixels += args->goodPixels;
    175183            xMin = PS_MIN(args->xMin, xMin);
     
    183191                jacobian += args->jacobian * args->goodPixels;
    184192            }
     193
     194           
    185195        }
    186196        psFree(job);
     
    201211
    202212    if (goodPixels > 0 && psMetadataLookupBool(&mdok, recipe, "SOURCES")) {
     213      if (!psMetadataLookupBool(NULL,config->arguments,"BACKGROUND_WARPING")) {
    203214        if (!pswarpTransformSources(output, input, config)) {
    204             psError(psErrorCodeLast(), false, "Unable to interpolate image.");
    205             return false;
     215          psError(psErrorCodeLast(), false, "Unable to interpolate image.");
     216          return false;
    206217        }
     218      }
    207219    }
    208220
  • trunk/pswarp/src/pswarpTransformSources.c

    r32351 r34800  
    4141    if (!outDetections) {
    4242        outDetections = pmDetectionsAlloc();
    43         psMetadataAddPtr(output->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_DATA_ARRAY, "Warped sources", outDetections);
     43        psMetadataAddPtr(output->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_DATA_ARRAY , "Warped sources", outDetections);
    4444    }
    4545    psArray *outSources = outDetections->allSources;
  • trunk/pswarp/src/pswarpTransformTile.c

    r29331 r34800  
    4646    args->jacobian = NAN;
    4747
     48    args->background_warping = false;
     49    args->offset_x = 0.0;
     50    args->offset_y = 0.0;
     51   
    4852    return args;
    4953}
     
    8387    // Iterate over the output image pixels (parent frame)
    8488    long goodPixels = 0;                ///< Number of input pixels landing on the output image
     89
    8590    for (int y = yMin; y < yMax; y++) {
    8691        for (int x = xMin; x < xMax; x++) {
    87 
    8892            // Only transform those pixels requested
    8993            if (region && region->data.PS_TYPE_IMAGE_MASK_DATA[y][x]) {
    9094                continue;
    9195            }
    92 
    9396            // pswarpMapApply converts the output coordinate (x,y) to the input coordinate.
    9497            // both are in the parent frames of the input and output images.
    9598            double xIn, yIn;            // Input pixel coordinates
    9699            pswarpMapApply(&xIn, &yIn, map, x + 0.5, y + 0.5);
     100
     101            // This needs to use a more reliable method to do this offset and limiting
     102            //      if (args->interp->mode == 8) {
     103            if (args->background_warping) {
     104              //              double xOffset = 177.0 / 400.0; // (modelsize * modelbinning - xsize) / 2.0
     105              //              double yOffset = 166.0 / 400.0; // (modelsize * modelbinning - ysize) / 2.0
     106              xIn += args->offset_x;
     107              yIn += args->offset_y;
     108
     109              if ((xIn > inNumCols - args->offset_x)||
     110                  (yIn > inNumRows - args->offset_y)||
     111                  (xIn < args->offset_x)||
     112                  (yIn < args->offset_y)) {
     113                continue;
     114              }
     115            }
     116           
    97117            if (xIn < 0 || xIn >= inNumCols || yIn < 0 || yIn >= inNumRows) {
    98118                continue;
Note: See TracChangeset for help on using the changeset viewer.