IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26242 for trunk/pstamp/scripts


Ignore:
Timestamp:
Nov 21, 2009, 10:24:29 AM (17 years ago)
Author:
bills
Message:

Add interface and implemenation to allow the selection of cmf, psf, and background model
files to be added to the stamp output.
Output the parameters mdc file for stamp jobs as well as get_image jobs
use it to find "the other outputs".
Save ppstamp args in the mdc as well. This will allow the args file to be
eliminated but this commit doesn't do that.

Location:
trunk/pstamp/scripts
Files:
2 edited

Legend:

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

    r26212 r26242  
    1313use Carp;
    1414use File::Basename;
     15use File::Copy;
    1516use Digest::MD5::File qw( file_md5_hex );
    1617use PS::IPP::PStamp::RequestFile qw( :standard );
     
    2021use PS::IPP::Metadata::Config;
    2122#use PS::IPP::Metadata::Stats;
    22 #use PS::IPP::Metadata::List qw( parse_md_list );
     23use PS::IPP::Metadata::List qw( parse_md_list );
    2324
    2425use PS::IPP::Config qw( :standard );
    2526
    26 my ($job_id, $redirect_output, $outputBase, $rownum, $jobType);
     27my ($job_id, $redirect_output, $outputBase, $rownum, $jobType, $options);
    2728my ($verbose, $dbname, $dbserver, $no_update);
    2829
     
    3233    'rownum=s'          =>  \$rownum,
    3334    'output_base=s'     =>  \$outputBase,
     35    'options=s'         =>  \$options,
    3436    'redirect-output'   =>  \$redirect_output,
    3537    'dbname=s'          =>  \$dbname,
     
    5153my_die("rownum is required", $job_id, $PS_EXIT_PROG_ERROR) if !$rownum;
    5254my_die("output_base is required", $job_id, $PS_EXIT_PROG_ERROR) if !$outputBase;
     55
     56$options = 1 if !$options;
    5357
    5458
     
    107111        my $reglist = "$dir/reglist$job_id";
    108112
    109         open F, ">$reglist" or my_die( "can't open $reglist for output", $job_id, $PS_EXIT_UNKNOWN_ERROR);
     113        my $F;
     114        open $F, ">$reglist" or my_die( "can't open $reglist for output", $job_id, $PS_EXIT_UNKNOWN_ERROR);
    110115
    111116        # Figure out what output images were produced
     
    116121                           $PSTAMP_SELECT_WEIGHT => "wt.fits");
    117122
    118         # we always create a stamp of the image
    119         my $output_mask = $PSTAMP_SELECT_IMAGE;
    120 
    121         # we search the argString for -mask and -variance.
    122         # searching the arg string allows us to avoid adding a column in pstampJob
    123         $output_mask   |= $PSTAMP_SELECT_MASK   if ($argString =~ /-mask/);
    124         $output_mask   |= $PSTAMP_SELECT_WEIGHT if ($argString =~ /-variance/);
     123        my $output_mask = $options & ($PSTAMP_SELECT_IMAGE | $PSTAMP_SELECT_MASK | $PSTAMP_SELECT_WEIGHT);
    125124
    126125        foreach my $key (keys (%extensions)) {
     
    137136
    138137            # XXX is pstamp always the right file type, if not where do we get the right one?
    139             print F file_registration_line($filename, $path, "pstamp") . "\n";
    140         }
    141 
    142         close F;
     138            print $F file_registration_line($filename, $path, "pstamp") . "\n";
     139        }
     140
     141        get_other_outputs($F, $outputBase, $options);
     142
     143        close $F;
    143144        $jobStatus = $PS_EXIT_SUCCESS;
    144145    } elsif ($exitStatus == $PSTAMP_NO_OVERLAP) {
    145         $jobStatus = $PSTAMP_NO_OVERLAP
     146        $jobStatus = $PSTAMP_NO_OVERLAP;
    146147    } else {
    147148        my_die( "ppstamp failed with error code: $exitStatus", $job_id, $exitStatus);
     
    206207    }
    207208}
     209       
     210sub get_other_outputs {
     211    my $f = shift;
     212    my $output_base = shift;
     213    my $options = shift;
     214
     215    if ($options & ( $PSTAMP_SELECT_CMF | $PSTAMP_SELECT_PSF | $PSTAMP_SELECT_BACKMDL)) {
     216if (0) {
     217        my $params_file = $output_base . ".mdc";
     218        open (IN, "<$params_file")
     219            or my_die("failed to open params file: $params_file", $job_id, $PS_EXIT_UNKNOWN_ERROR);
     220
     221        my $data = $mdcParser->parse(join "", (<IN>))
     222            or my_die("failed to parse params file: $params_file", $job_id, $PS_EXIT_UNKNOWN_ERROR);
     223
     224        my $components = parse_md_list($data);
     225
     226        my $n = scalar @$components;
     227        if ($n != 1) {
     228            my_die("params file $params_file contains unexpected number of components: $n",
     229                $job_id, $PS_EXIT_PROG_ERROR);
     230        }
     231        my $comp = $components->[0];
     232}
     233        my $comp = read_params_file($output_base);
     234
     235        my $stage = $comp->{stage};
     236
     237        # raw files don't have any other data products
     238        return 1 if $stage eq "raw";
     239
     240        # add the other data products if they are selected and exist.
     241        # silently skip them if they don't exist. Perhaps this should be
     242        # detected in pstampparse so that the user can be notified with
     243        # a message in parse_error.txt ("warp do not have a background model")
     244        my $cmf_file = $comp->{cmf} if ($options & $PSTAMP_SELECT_CMF);
     245        my $psf_file = $comp->{psf} if ($options & $PSTAMP_SELECT_PSF);
     246        my $backmdl_file = $comp->{backmdl} if ($options & $PSTAMP_SELECT_BACKMDL);
     247
     248        my $outdir = dirname($output_base);
     249        my $basename = basename($output_base);
     250        my ($rownum, $jobnum, $therest) = split /_/, $basename;
     251        &my_die("failed to split basename: $basename", $job_id, $PS_EXIT_CONFIG_ERROR)
     252            if (!$therest or !$rownum or !$jobnum);
     253
     254        my $prefix = "${rownum}_${jobnum}_";
     255
     256        if ($cmf_file) {
     257            print "cmf file is $cmf_file\n";
     258            copy_and_register_file($f, $cmf_file, $outdir, $prefix);
     259        }
     260        if ($psf_file) {
     261            print "psf_file is $psf_file\n";
     262            copy_and_register_file($f, $psf_file, $outdir, $prefix);
     263        }
     264        if ($backmdl_file) {
     265            print "backmdl_file is $backmdl_file\n";;
     266            copy_and_register_file($f, $backmdl_file, $outdir, $prefix);
     267        }
     268    }
     269}
     270sub read_params_file {
     271    my $output_base = shift;
     272
     273    my $params_file = $output_base . ".mdc";
     274    open (IN, "<$params_file")
     275        or my_die("failed to open params file: $params_file", $job_id, $PS_EXIT_UNKNOWN_ERROR);
     276
     277    my $data = $mdcParser->parse(join "", (<IN>))
     278        or my_die("failed to parse params file: $params_file", $job_id, $PS_EXIT_UNKNOWN_ERROR);
     279
     280    my $components = parse_md_list($data);
     281
     282    my $n = scalar @$components;
     283    if ($n != 1) {
     284        my_die("params file $params_file contains unexpected number of components: $n",
     285                $job_id, $PS_EXIT_PROG_ERROR);
     286    }
     287    return $components->[0];
     288}
     289
     290# copy_and_register_file ($f, $src, $destdir, $prefix);
     291sub copy_and_register_file {
     292    my $F = shift;
     293    my $src = shift;
     294    my $destdir = shift;
     295    my $prefix = shift;
     296
     297    my $fn = $prefix . basename($src);
     298    my $dst = "$destdir/$fn";
     299
     300    my $resolved = $ipprc->file_resolve($src);
     301
     302    my_die("failed to resolve $src", $job_id, $PS_EXIT_UNKNOWN_ERROR) if !$resolved;
     303
     304    copy($resolved, $dst) or my_die("failed to copy $resolved to $dst", $job_id, $PS_EXIT_UNKNOWN_ERROR);
     305
     306    print $F file_registration_line($fn, $dst, "fits") . "\n";
     307}
    208308
    209309sub my_die
  • trunk/pstamp/scripts/pstampparse.pl

    r26209 r26242  
    371371            $args .= " -astrom $image->{astrom}" if $image->{astrom};
    372372        }
     373
     374        $image->{job_args} = $args;
     375
     376        # XXX: we can get rid of the following everything that we need is
     377        # in the params file
    373378
    374379        $args .= " -file $imagefile";
Note: See TracChangeset for help on using the changeset viewer.