IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36812


Ignore:
Timestamp:
Jun 4, 2014, 11:07:54 AM (12 years ago)
Author:
bills
Message:

implement background restoration for chip stamps

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/scripts/pstamp_job_run.pl

    r36811 r36812  
    2929my ($job_id, $redirect_output, $outputBase, $rownum, $jobType, $options);
    3030my ($verbose, $dbname, $dbserver, $no_update, $save_temps);
     31my $very_verbose = 0; # for debugging
    3132
    3233GetOptions(
     
    6768}
    6869
     70if ($verbose && $save_temps) {
     71    # we're probably debugging turn up the verbosity
     72    $very_verbose = 1;
     73}
     74
    6975if (!$dbserver) {
    7076    $dbserver =  metadataLookupStr($ipprc->{_siteConfig}, 'PS_DBSERVER');
     
    7379my $temproot = metadataLookupStr($ipprc->{_siteConfig}, "TEMP.DIR");
    7480$temproot = "/tmp" if !defined $temproot;
    75 
    7681
    7782my $missing_tools;
     
    8388my $dquery_job_run = can_run('dquery_job_run.pl') or (warn "Can't find dquery_job_run.pl" and $missing_tools = 1);
    8489my $whichnode = can_run('whichnode') or (warn "can't find whichnode" and $missing_tools = 1);
     90my $ppBackground = can_run('ppBackground') or (warn "Can't find ppBackground" and $missing_tools = 1);
    8591my $ppBackgroundStack = can_run('ppBackgroundStack') or (warn "Can't find ppBackgroundStack" and $missing_tools = 1);
    8692my $stack_bkg_mk_mdc = can_run('stack_bkg_mk_mdc.pl') or (warn "Can't find stack_bkg_mk_mdc.pl" and $missing_tools = 1);
     
    686692}
    687693
     694# use ppBackground or ppBackgroundStack to produce background restored images
    688695sub create_background_restored_images {
    689696    my $params = shift;
    690697    my $stage = $params->{stage};
     698
     699    if ($stage ne 'stack' and $stage ne 'chip') {
     700        # this function is only supported for chip and stack stage
     701        # perhaps the parser should catch this ...
     702        print STDERR "background restoration not currently supported for stage $params->{stage}\n";
     703        return $PSTAMP_BG_RESTORE_NOT_AVAILABLE;
     704    }
     705
     706    my $tempdir = tempdir("$temproot/pstamp.$job_id.XXXX", CLEANUP => !$save_temps);
     707    my $imagedb = $params->{imagedb};
     708    my $camera = $params->{camera};
     709
     710    # reinstantiate IPP Configuration using the now known camera so that we get the applicable file rules
     711    $ipprc = PS::IPP::Config->new($camera);
     712
     713    my $input_image = $params->{image};
     714    my $input_mask = $params->{mask};
     715    my $input_variance = $params->{weight};
     716
    691717    if ($stage eq 'stack') {
    692         my $tempdir = tempdir("$temproot/pstamp.$job_id.XXXX", CLEANUP => !$save_temps);
    693         my $camera = $params->{camera};
    694         my $imagedb = $params->{imagedb};
    695718        my $stack_id = $params->{stack_id};
    696719        my $mdcfile = "$tempdir/stk.$stack_id.bkg_input.mdc";
     
    704727            }
    705728        }
    706         my $input_image = $params->{image};
    707         my $input_mask = $params->{mask};
    708         # XXX: perhaps we should save the background restored file in the working directory instead of a tempdir
     729
    709730        my $outroot = "$tempdir/stk.$stack_id";
     731
    710732        # XXX: get otapath from a config file or detrend system
    711733        my $otapath = "neb:///detrends/background_OTA_models.20140527/test_solutions";
    712734        {
    713735            my $command = "$ppBackgroundStack $outroot -input $mdcfile -image $input_image"
    714                . " -OTApath $otapath"
    715                ;
     736               . " -OTApath $otapath" ;
    716737            $command .= " -mask $input_mask" if $input_mask;
    717738            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    718                 run(command => $command, verbose => 0);
     739                run(command => $command, verbose => $very_verbose);
    719740            unless ($success) {
    720741                # we turned off verbosity because ppBackgroundStack emits too much output
     
    726747        }
    727748        # it's all good change the image to be passed to ppstamp
    728         # XXX use filerule
    729         $params->{image} = "$outroot.bkgrest.fits";
     749        $params->{image} = $ipprc->filename('PPBACKGROUND.STACK.OUTPUT', $outroot) or
     750                &my_die("Unable to resolve ppBackgroundStack output file name", $job_id, $PS_EXIT_UNKNOWN_ERROR, 'run');
     751
     752    } elsif ($stage eq 'chip') {
     753        my $input_mdl = $params->{backmdl};
     754        my $chip_id = $params->{chip_id};
     755        my $class_id = $params->{class_id};
     756        my $outroot = "$tempdir/bgrestored.ch.$chip_id";
     757        {
     758            my $command = "$ppBackground $outroot -background $input_mdl -image $input_image";
     759            # XXX: I think ppBackground might always require mask and variance images
     760            $command .= " -mask $input_mask";
     761            $command .= " -variance $input_variance";
     762
     763            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     764                run(command => $command, verbose => $verbose);
     765            unless ($success) {
     766                print STDERR join "", @$stderr_buf;
     767                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     768                &my_die("Unable to perform ppBackground: $error_code", $job_id, $PS_EXIT_CONFIG_ERROR, 'run');
     769            }
     770        }
     771        $params->{image} = $ipprc->filename('PPBACKGROUND.OUTPUT', $outroot, $class_id) or
     772                &my_die("Unable to resolve ppBackgroundStack output image name", $job_id, $PS_EXIT_CONFIG_ERROR, 'run');
     773        $params->{mask} = $ipprc->filename('PPBACKGROUND.OUTPUT.MASK', $outroot, $class_id) or
     774                &my_die("Unable to resolve ppBackgroundStack output mask name", $job_id, $PS_EXIT_CONFIG_ERROR, 'run');
     775        $params->{weight} = $ipprc->filename('PPBACKGROUND.OUTPUT.VARIANCE', $outroot, $class_id) or
     776                &my_die("Unable to resolve ppBackgroundStack output variance name", $job_id, $PS_EXIT_CONFIG_ERROR, 'run');
     777
    730778    } else {
    731         print STDERR "background restoration not currently supported for stage $params->{stage}\n";
    732         return $PSTAMP_BG_RESTORE_NOT_AVAILABLE;
     779        # can't get here
     780        &my_die( "background restoration not currently supported for stage $params->{stage}\n",
     781            $job_id, $PS_EXIT_PROG_ERROR, 'stop'); ;
    733782    }
    734783
Note: See TracChangeset for help on using the changeset viewer.