IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 28, 2010, 3:09:59 PM (16 years ago)
Author:
watersc1
Message:

JPEG work should be done. Transitioning to try to pick up stackAssociation concept in this branch as well.

Location:
branches/czw_branch/20100519
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20100519

  • branches/czw_branch/20100519/ippScripts/scripts/staticsky.pl

    r27964 r28164  
    2121use PS::IPP::Metadata::List qw( parse_md_list );
    2222use Data::Dumper;
     23use File::Temp qw( tempfile );
     24use File::Basename;
    2325use PS::IPP::Config 1.01 qw( :standard );
    2426
     
    2931my $missing_tools;
    3032my $staticskytool = can_run('staticskytool') or (warn "Can't find staticskytool" and $missing_tools = 1);
    31 my $ppSub = can_run('ppSub') or (warn "Can't find ppSub" and $missing_tools = 1);
     33my $psphotStack = can_run('psphotStack') or (warn "Can't find psphotStack" and $missing_tools = 1);
    3234my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
    3335if ($missing_tools) {
     
    3638}
    3739
    38 my ($sky_id, $dbname, $threads, $outroot, $reduction, $inverse, $run_state, $verbose, $no_update, $no_op, $redirect, $save_temps);
     40my ($sky_id, $camera, $dbname, $threads, $outroot, $reduction, $inverse, $run_state, $verbose, $no_update, $no_op, $redirect, $save_temps);
    3941GetOptions(
    4042    'sky_id=s'          => \$sky_id, # Diff identifier
     43    'camera|c=s'        => \$camera, # Camera name
    4144    'dbname|d=s'        => \$dbname, # Database name
    4245    'threads=s'         => \$threads,   # Number of threads to use
     
    5356pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    5457pod2usage(
    55     -msg => "Required options: --sky_id --outroot",
     58    -msg => "Required options: --sky_id --outroot --camera (--run_state)",
    5659    -exitval => 3,
    5760          ) unless
    5861    defined $sky_id and
    59     defined $outroot;
    60 
    61 my $ipprc = PS::IPP::Config->new() or my_die( "Unable to set up", $sky_id, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
    62 
    63 # XXX camera is not known here; cannot use filerules...
    64 # my $logDest = $ipprc->filename("LOG.EXP", $outroot);
    65 my $logDest = "$outroot.log";
    66 $logDest .= ".update" if $run_state eq "update";
     62    defined $outroot and
     63    defined $camera;
     64#   and defined $run_state;
     65
     66my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $sky_id, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
     67
     68my $logDest = $ipprc->filename("LOG.EXP", $outroot);
     69# $logDest .= ".update" if $run_state eq "update";
    6770$ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $sky_id, $PS_EXIT_SYS_ERROR ) if $redirect;
    6871
    69 my $source_id = $ipprc->source_id($dbname, $PS_TABLE_ID_DIFF);
     72# my $source_id = $ipprc->source_id($dbname, $PS_TABLE_ID_STATICSKY);
    7073
    7174my $outbase = basename($outroot);
     
    9194}
    9295
    93 # XXX do we NEED to define the camera?
    94 # &my_die("Unable to identify camera", $sky_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless defined $camera;
    95 # $ipprc->define_camera($camera);
    96 
    9796# generate the input
    9897print $listFile "INPUT   MULTI\n";
     98my $nInputs = @$files;
    9999
    100100foreach my $file (@$files) {
    101101    print $listFile "INPUT   METADATA\n";
    102102
    103     $path_base = $file->{path_base};
    104     my $imageCnv  = $ipprc->filename("PPSTACK.OUTPUT", $file->{path_base} ); # Mask name
    105     my $maskCnv   = $ipprc->filename("PPSTACK.OUTPUT.MASK", $file->{path_base} ); # Mask name
    106     my $weightCnv = $ipprc->filename("PPSTACK.OUTPUT.VARIANCE", $file->{path_base} ); # Weight name
    107     my $psfCnv    = $ipprc->filename("PSPHOT.PSF.SKY.SAVE", $file->{path_base} ); # PSF name
    108 
    109     my $imageRaw  = $ipprc->filename("PPSTACK.UNCONV", $file->{path_base} ); # Mask name
    110     my $maskRaw   = $ipprc->filename("PPSTACK.UNCONV.MASK", $file->{path_base} ); # Mask name
    111     my $weightRaw = $ipprc->filename("PPSTACK.UNCONV.VARIANCE", $file->{path_base} ); # Weight name
    112 
    113     my $sources   = $ipprc->filename("PSPHOT.OUT.CMF.MEF", $file->{path_base}); # Sources name
    114 
    115     &my_die("Image $image does not exist", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists( $image );
    116     &my_die("Mask $mask does not exist", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists( $mask );
    117     &my_die("Weight $weight does not exist", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists( $weight );
    118     &my_die("PSF $psf does not exist", $stack_id, $PS_EXIT_SYS_ERROR) if ($convolve and not $ipprc->file_exists( $psf ));
    119     &my_die("Sources $sources does not exist", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists( $sources );
    120 
    121     print $listFile "  RAW:IMAGE     STR  " . $imageRaw  . "\n";
    122     print $listFile "  RAW:MASK      STR  " . $maskRaw   . "\n";
    123     print $listFile "  RAW:VARIANCE  STR  " . $weightRaw . "\n";
    124 
    125     print $listFile "  CNV:IMAGE     STR  " . $imageCnv  . "\n";
    126     print $listFile "  CNV:MASK      STR  " . $maskCnv   . "\n";
    127     print $listFile "  CNV:VARIANCE  STR  " . $weightCnv . "\n";
    128     print $listFile "  CNV:PSF       STR  " . $psfCnv    . "\n";
    129 
    130     print $listFile "  SOURCES       STR  " . $sources   . "\n";
    131 
    132     print $listFile "END\n\n";
    133 
     103    # XXX if we take the input from 'warp', we will need to make different selections here
     104    my $path_base = $file->{path_base};
     105    print "input: $path_base\n";
     106
     107    my $imageCnv  = $ipprc->filename("PPSTACK.OUTPUT",          $path_base ); # Image name
     108    my $maskCnv   = $ipprc->filename("PPSTACK.OUTPUT.MASK",     $path_base ); # Mask name
     109    my $weightCnv = $ipprc->filename("PPSTACK.OUTPUT.VARIANCE", $path_base ); # Weight name
     110
     111    my $imageRaw  = $ipprc->filename("PPSTACK.UNCONV",          $path_base ); # Image name
     112    my $maskRaw   = $ipprc->filename("PPSTACK.UNCONV.MASK",     $path_base ); # Mask name
     113    my $weightRaw = $ipprc->filename("PPSTACK.UNCONV.VARIANCE", $path_base ); # Weight name
     114
     115    my $sources   = $ipprc->filename("PSPHOT.OUT.CMF.MEF",      $path_base ); # Sources name
     116
     117    # XXX is this the correct PSF file?
     118    my $psfCnv    = $ipprc->filename("PPSTACK.TARGET.PSF",      $path_base ); # PSF name
     119
     120    # XXX we could make some different choices if some inputs do not exist...
    134121    &my_die("Couldn't find input: $imageRaw",  $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$imageRaw");
    135122    &my_die("Couldn't find input: $maskRaw",   $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$maskRaw");
     
    140127    &my_die("Couldn't find input: $psfCnv",    $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$psfCnv");
    141128    &my_die("Couldn't find input: $sources",   $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$sources");
     129
     130    print $listFile "  RAW:IMAGE     STR  " . $imageRaw  . "\n";
     131    print $listFile "  RAW:MASK      STR  " . $maskRaw   . "\n";
     132    print $listFile "  RAW:VARIANCE  STR  " . $weightRaw . "\n";
     133
     134    print $listFile "  CNV:IMAGE     STR  " . $imageCnv  . "\n";
     135    print $listFile "  CNV:MASK      STR  " . $maskCnv   . "\n";
     136    print $listFile "  CNV:VARIANCE  STR  " . $weightCnv . "\n";
     137    print $listFile "  CNV:PSF       STR  " . $psfCnv    . "\n";
     138
     139    print $listFile "  SOURCES       STR  " . $sources   . "\n";
     140
     141    print $listFile "END\n\n";
    142142}
    143143
     
    149149}
    150150
    151 print "reduction: $reduction\n";
     151print "reduction:     $reduction\n";
    152152print "recipe_psphot: $recipe_psphot\n";
    153 
    154 # Get the output filenames
    155 my $outputName = $ipprc->filename("PPSUB.OUTPUT", $outroot);
    156 my $outputMask = $ipprc->filename("PPSUB.OUTPUT.MASK", $outroot);
    157 my $outputVariance = $ipprc->filename("PPSUB.OUTPUT.VARIANCE", $outroot);
    158 my $outputSources = $ipprc->filename("PPSUB.OUTPUT.SOURCES", $outroot);
    159 my $jpeg1Name = $ipprc->filename("PPSUB.OUTPUT.JPEG1", $outroot);
    160 my $jpeg2Name = $ipprc->filename("PPSUB.OUTPUT.JPEG2", $outroot);
    161 my $configuration = $ipprc->filename("PPSUB.CONFIG", $outroot);
    162 my $outputStats = $ipprc->filename("SKYCELL.STATS", $outroot);
    163 my $traceDest = $ipprc->filename("TRACE.EXP", $outroot);
    164 
    165 if ($run_state eq 'update') {
    166     $traceDest .= '.update';
    167     $outputStats .= '.update';
    168 }
    169 
    170 my ($inverseName, $inverseMask, $inverseVariance, $inverseSources);
    171 if ($inverse) {
    172     $inverseName = $ipprc->filename("PPSUB.INVERSE", $outroot);
    173     $inverseMask = $ipprc->filename("PPSUB.INVERSE.MASK", $outroot);
    174     $inverseVariance = $ipprc->filename("PPSUB.INVERSE.VARIANCE", $outroot);
    175     $inverseSources = $ipprc->filename("PPSUB.INVERSE.SOURCES", $outroot);
    176 }
    177153
    178154my $cmdflags;
     
    180156# Perform subtraction
    181157{
    182     my $command = "$ppSub $outroot";
    183     $command .= " -inimage $input";
    184     $command .= " -refimage $template";
    185     $command .= " -inmask $inputMask";
    186     $command .= " -refmask $templateMask";
    187     $command .= " -invariance $inputVariance";
    188     $command .= " -refvariance $templateVariance";
    189     $command .= " -insources $inputSources";
    190     $command .= " -refsources $templateSources";
    191     $command .= " -stats $outputStats";
     158    my $command = "$psphotStack $outroot";
     159    $command .= " -input $listName";
    192160    $command .= " -threads $threads" if defined $threads;
    193     if ($run_state eq "new") {
    194         $command .= " -dumpconfig $configuration";
    195     } else {
    196         my $configurationReal = $ipprc->file_resolve($configuration) or &my_die("Couldn't resolve configuration file: $configuration", $sky_id, $skycell_id, $PS_EXIT_SYS_ERROR);
    197         $command .= " -ipprc $configurationReal";
    198     }
    199     $command .= " -save-inconv" if defined $saveInConv;
    200     $command .= " -save-refconv" if defined $saveRefConv;
    201     $command .= " -recipe PPSUB $recipe_ppSub";
    202161    $command .= " -recipe PSPHOT $recipe_psphot";
    203     $command .= " -recipe PPSTATS WARPSTATS";
    204     $command .= " -F PSPHOT.PSF.SAVE PSPHOT.PSF.SKY.SAVE";
    205     $command .= " -F PSPHOT.OUTPUT PSPHOT.OUT.CMF.MEF";
    206     $command .= " -F PSPHOT.BACKMDL PSPHOT.BACKMDL.MEF";
    207     if ($run_state eq "new") {
    208         $command .= " -photometry";
    209     }
    210     $command .= " -inverse" if $inverse;
    211     $command .= " -tracedest $traceDest -log $logDest";
    212     $command .= " -dbname $dbname" if defined $dbname;
    213     $command .= " -image_id $diff_skyfile_id" if defined $diff_skyfile_id;
    214     $command .= " -source_id $source_id" if defined $source_id;
     162    # $command .= " -dumpconfig $configuration";
     163    # $command .= " -tracedest $traceDest -log $logDest";
     164    # $command .= " -dbname $dbname" if defined $dbname;
     165    # $command .= " -image_id $diff_skyfile_id" if defined $diff_skyfile_id;
     166    # $command .= " -source_id $source_id" if defined $source_id;
    215167
    216168    unless ($no_op) {
     
    219171        unless ($success) {
    220172            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    221             &my_die("Unable to perform ppSub: $error_code", $sky_id, $skycell_id, $error_code);
    222         }
    223 
    224         my $outputStatsReal = $ipprc->file_resolve($outputStats);
    225         &my_die("Couldn't find expected output file: $outputStats", $sky_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStatsReal);
     173            &my_die("Unable to perform ppSub: $error_code", $sky_id, $error_code);
     174        }
     175
     176        # my $outputStatsReal = $ipprc->file_resolve($outputStats);
     177        # &my_die("Couldn't find expected output file: $outputStats", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStatsReal);
    226178
    227179        # measure chip stats
    228         $command = "$ppStatsFromMetadata $outputStatsReal - DIFF_SKYCELL";
    229         ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    230             run(command => $command, verbose => $verbose);
    231         unless ($success) {
    232             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    233             &my_die("Unable to perform ppStatsFromMetadata: $error_code", $sky_id, $skycell_id, $error_code);
    234         }
    235         foreach my $line (@$stdout_buf) {
    236             $cmdflags .= " $line";
    237         }
    238         chomp $cmdflags;
     180        # $command = "$ppStatsFromMetadata $outputStatsReal - DIFF_SKYCELL";
     181        # ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     182        #     run(command => $command, verbose => $verbose);
     183        # unless ($success) {
     184        #     $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     185        #     &my_die("Unable to perform ppStatsFromMetadata: $error_code", $sky_id, $error_code);
     186        # }
     187        # foreach my $line (@$stdout_buf) {
     188        #     $cmdflags .= " $line";
     189        # }
     190        # chomp $cmdflags;
    239191
    240192        my ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag
    241193
    242194        if (!$quality) {
    243             &my_die("Couldn't find expected output file: $outputName", $sky_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName);
    244             &my_die("Couldn't find expected output file: $outputMask", $sky_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
    245             &my_die("Couldn't find expected output file: $outputVariance", $sky_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputVariance);
    246             &my_die("Couldn't find expected output file: $outputSources", $sky_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
    247             &my_die("Couldn't find expected output file: $jpeg1Name",    $sky_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($jpeg1Name);
    248             &my_die("Couldn't find expected output file: $jpeg2Name",    $sky_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($jpeg2Name);
    249             if ($inverse) {
    250                 &my_die("Couldn't find expected output file: $inverseName", $sky_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseName);
    251                 &my_die("Couldn't find expected output file: $inverseMask", $sky_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseMask);
    252                 &my_die("Couldn't find expected output file: $inverseVariance", $sky_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseVariance);
    253                 &my_die("Couldn't find expected output file: $inverseSources", $sky_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseSources);
    254                 if ($run_state eq 'new') {
    255                     &my_die("Couldn't find expected output file: $configuration", $sky_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($configuration);
    256                 }
    257             }
     195
     196            # Get the output filenames
     197            # we have one set of output files per input file set
     198            for (my $i = 0; $i < @$files; $i++) {
     199                my $outputName     = $ipprc->filename("PSPHOT.STACK.OUTPUT.IMAGE", $outroot);
     200                my $outputMask     = $ipprc->filename("PSPHOT.STACK.OUTPUT.MASK", $outroot);
     201                my $outputVariance = $ipprc->filename("PSPHOT.STACK.OUTPUT.VARIANCE", $outroot);
     202                my $outputSources  = $ipprc->filename("PSPHOT.STACK.OUTPUT", $outroot);
     203
     204                &my_die("Couldn't find expected output file: $outputName", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName);
     205                &my_die("Couldn't find expected output file: $outputMask", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
     206                &my_die("Couldn't find expected output file: $outputVariance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputVariance);
     207                &my_die("Couldn't find expected output file: $outputSources", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
     208            }
     209
     210            #my $configuration  = $ipprc->filename("PPSUB.CONFIG", $outroot);
     211            #my $outputStats    = $ipprc->filename("SKYCELL.STATS", $outroot);
     212            #my $traceDest      = $ipprc->filename("TRACE.EXP", $outroot);
     213
     214            # if ($run_state eq 'update') {
     215            #   $traceDest .= '.update';
     216            #   $outputStats .= '.update';
     217            # }
     218
     219            my $chisqName     = $ipprc->filename("PSPHOT.CHISQ.IMAGE", $outroot);
     220            my $chisqMask     = $ipprc->filename("PSPHOT.CHISQ.MASK", $outroot);
     221            my $chisqVariance = $ipprc->filename("PSPHOT.CHISQ.VARIANCE", $outroot);
     222
     223            &my_die("Couldn't find expected output file: $chisqName",     $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqName);
     224            &my_die("Couldn't find expected output file: $chisqMask",     $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqMask);
     225            &my_die("Couldn't find expected output file: $chisqVariance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqVariance);
    258226        }
    259227    } else {
     
    266234    # Add the subtraction result
    267235    {
    268         my $command = "$difftool -sky_id $sky_id -skycell_id $skycell_id";
    269         $command .= " -magicked $magicked" if $magicked;
    270         if ($run_state eq 'new') {
    271             $command .= " -adddiffskyfile -path_base $outroot";
    272             $command .= " $cmdflags";
    273             $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
    274             $command .= " -hostname $host" if defined $host;
    275         } else {
    276             $command .= " -tofullskyfile";
    277         }
     236        my $command = "$staticskytool -sky_id $sky_id";
     237        # if ($run_state eq 'new') {
     238        $command .= " -addresult -path_base $outroot";
     239        $command .= " -num_inputs $nInputs";
     240        $command .= " $cmdflags";
     241        $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
     242        $command .= " -hostname $host" if defined $host;
     243        # } else {
     244        #     $command .= " -tofullskyfile";
     245        # }
    278246        $command .= " -dbname $dbname" if defined $dbname;
    279247
     
    285253                "Unable to perform difftool -adddiffskyfile" :
    286254                "Unable to perform difftool -tofullskyfile";
    287             &my_die("$err_message: $error_code", $sky_id, $skycell_id, $error_code);
     255            &my_die("$err_message: $error_code", $sky_id, $error_code);
    288256        }
    289257    }
     
    300268
    301269    warn($msg);
    302     if (defined $sky_id and defined $skycell_id and not $no_update) {
    303         my $command = "$difftool -sky_id $sky_id -skycell_id $skycell_id -fault $exit_code";
     270    if (defined $sky_id and not $no_update) {
     271        my $command = "$staticskytool -sky_id $sky_id -fault $exit_code";
    304272        if ($run_state eq 'new') {
    305273            $command .= " -adddiffskyfile";
Note: See TracChangeset for help on using the changeset viewer.