IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2010, 8:41:49 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/tap_branches
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/tap_branches

  • branches/tap_branches/ippScripts/scripts/flatcorr_proc.pl

    r25816 r27838  
    1111# dvoMakeCorr -file outgrid.fits -ref ref.fits outcorr
    1212
    13 # dettool -register -det_type FLATCORR -filelevel (level) -workdir -inst, etc 
    14 
    15 # foreach $imfile () 
     13# dettool -register -det_type FLATCORR -filelevel (level) -workdir -inst, etc
     14
     15# foreach $imfile ()
    1616#   dettool -register_imfile -uri, etc, etc
    1717
     
    2323use Sys::Hostname;
    2424my $host = hostname();
     25my $date = `date`;
    2526print "\n\n";
    26 print "Starting script $0 on $host\n\n";
     27print "Starting script $0 on $host at $date\n\n";
    2728
    2829use vars qw( $VERSION );
     
    4243use Pod::Usage qw( pod2usage );
    4344
    44 my ($corr_id, $det_type, $dvodb, $camera, $region, $filter, $dbname, $workdir, $verbose, $no_update, $no_op);
     45my ($corr_id, $det_type, $dvodb, $camera, $region, $filter, $dbname, $workdir, $make_correction, $verbose, $no_update, $no_op);
    4546GetOptions(
    4647    'corr_id|i=s'      => \$corr_id,
     
    5253    'dbname|d=s'       => \$dbname,# Database name
    5354    'workdir|w=s'      => \$workdir, # Working directory for output files
    54     'verbose'           => \$verbose,   # Print to stdout
     55    'make_correction'  => \$make_correction,   # Generate the correction image and save to the detrend database
     56    'verbose'          => \$verbose,   # Print to stdout
    5557    'no-update'        => \$no_update,
    5658    'no-op'            => \$no_op,
     
    7375my $addstar     = can_run('addstar')      or (warn "Can't find addstar"      and $missing_tools = 1);
    7476my $dvoMakeCorr = can_run('dvoMakeCorr')  or (warn "Can't find dvoMakeCorr"  and $missing_tools = 1);
    75 my $detselect   = can_run('detselect')    or (warn "Can't find detselect"    and $missing_tools = 1);
    76 my $dettool     = can_run('dettool')      or (warn "Can't find dettool"      and $missing_tools = 1);
    77 my $flatcorr    = can_run('flatcorr')     or (warn "Can't find flatcorr"     and $missing_tools = 1);
    78 
    79 if ($missing_tools) { 
     77my $detselect   = can_run('detselect')    or (warn "Can't find detselect"    and $missing_tools = 1);
     78my $dettool     = can_run('dettool')      or (warn "Can't find dettool"      and $missing_tools = 1);
     79my $flatcorr    = can_run('flatcorr')     or (warn "Can't find flatcorr"     and $missing_tools = 1);
     80
     81if ($missing_tools) {
    8082    warn ("Can't find required tools");
    81     exit($PS_EXIT_CONFIG_ERROR); 
     83    exit($PS_EXIT_CONFIG_ERROR);
    8284}
    8385
     
    8688my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    8789
    88 # XXX either workdir needs to be non-nebulous here, or addstar / relphot need to handle
    89 # nebulous interactions...
     90# dvodb must be non-nebulous; workdir may be in nebulous
    9091my $outgrid = "$dvodb/flatcorr/$camera.$filter.$corr_id";
    9192my $outcorr = "$workdir/$camera.$filter.$corr_id";
     
    9596$ipprc->outroot_prepare($outcorr);
    9697
    97 if (not -e "$dvodb/flatcorr") { 
     98if (not -e "$dvodb/flatcorr") {
    9899    mkdir "$dvodb/flatcorr" or &my_die ("Unable to make output directory for relphot $dvodb/flatcorr", $corr_id, 3);
    99100}
     
    104105my ($DECs, $DECe) = split (",", $coords[1]);
    105106
    106 # Run addstar -resort to ensure the db is indexed 
     107# Run addstar -resort to ensure the db is indexed
    107108# XXX addstar should be able to recognize and skip indexed tables
    108109{
    109     my $command = "$addstar -resort"; 
     110    my $command = "$addstar -resort";
    110111    $command .= " -D CATDIR $dvodb";
    111112    $command .= " -region $RAs $RAe $DECs $DECe";
    112113
    113114    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    114         run(command => $command, verbose => $verbose);
    115 
    116     unless ($success) { 
    117         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    118         &my_die ("Unable to perform addstar -resort for dvodb $dvodb on region $region: $error_code", $corr_id, $error_code);
     115        run(command => $command, verbose => $verbose);
     116
     117    unless ($success) {
     118        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     119        &my_die ("Unable to perform addstar -resort for dvodb $dvodb on region $region: $error_code", $corr_id, $error_code);
    119120    }
    120121}
     
    135136
    136137    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    137         run(command => $command, verbose => $verbose);
    138 
    139     unless ($success) {
    140         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    141         &my_die ("Unable to perform relphot -grid for dvodb $dvodb on region $region: $error_code", $corr_id, $error_code);
     138        run(command => $command, verbose => $verbose);
     139
     140    unless ($success) {
     141        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     142        &my_die ("Unable to perform relphot -grid for dvodb $dvodb on region $region: $error_code", $corr_id, $error_code);
     143    }
     144}
     145
     146if ($make_correction) {
     147
     148    # get a single input exposure
     149    # flatcorr -inputexp -corr_id $corr_id -limit 1
     150    my $chip_id = &get_chip_id();
     151
     152    # get the list of imfiles for the single input exposure
     153    # flatcorr -inputimfile -chip_id $chip_id
     154    my $files = &get_imfiles($chip_id);
     155
     156    # set up the detrend run to store the corrected imfiles
     157    my $det_id = &get_det_id($$files[0]);
     158
     159    # make the (full-sized) detrend correction images
     160    &make_detrend_imfiles($det_id, $files);
     161
     162    # set the detrun state to 'stop'
     163    my $command = "$dettool -updatedetrun";
     164    $command .= " -det_id $det_id";
     165    $command .= " -state stop";
     166    $command .= " -dbname $dbname" if defined $dbname;
     167
     168    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     169        run(command => $command, verbose => $verbose);
     170
     171    unless ($success) {
     172        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     173        warn ("Unable to perform dettool -updatedetrun: $error_code");
     174        exit($error_code);
     175    }
     176}
     177
     178# Push the results into the database
     179{
     180    my $command = "$flatcorr -addprocess";
     181    $command .= " -corr_id $corr_id";
     182    $command .= " -hostname $host" if defined $host;
     183    $command .= " -dbname $dbname" if defined $dbname;
     184
     185    unless ($no_update) {
     186
     187        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     188            run(command => $command, verbose => $verbose);
     189        unless ($success) {
     190            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     191            warn ("Unable to perform regtool -addprocessedimfile: $error_code");
     192            exit($error_code);
     193        }
     194    } else {
     195        print "skipping command: $command\n";
    142196    }
    143197}
     
    145199# get a single input exposure
    146200# flatcorr -inputexp -corr_id $corr_id -limit 1
    147 my $chip_id;
    148 {
     201sub get_chip_id {
     202
    149203    my $command = "$flatcorr -inputexp";
    150204    $command .= " -corr_id $corr_id";
     
    165219        &my_die("Unable to parse metadata list", $corr_id, $PS_EXIT_PROG_ERROR);
    166220
    167     # check for existence 
     221    # check for existence
    168222    my $file = $$files[0];
    169     $chip_id = $file->{chip_id};
     223    my $chip_id = $file->{chip_id};
     224
     225    return $chip_id;
    170226}
    171227
    172228# get the list of imfiles for the single input exposure
    173229# flatcorr -inputimfile -chip_id $chip_id
    174 my $files;
    175 {
     230sub get_imfiles {
     231    my $chip_id = shift;
     232
    176233    my $command = "$flatcorr -inputimfile";
    177234    $command .= " -chip_id $chip_id";
     
    188245
    189246    # extract the metadata for the files into a hash list
    190     $files = parse_md_list($metadata) or
     247    my $files = parse_md_list($metadata) or
    191248        &my_die("Unable to parse metadata list", $corr_id, $PS_EXIT_PROG_ERROR);
     249
     250    return $files;
    192251}
    193252
    194253# set up the detrend run to store the corrected imfiles
    195 my $det_id;
    196 {
    197     # get the filelevel from one of these chips
    198     my $file = $$files[0];
     254sub get_det_id {
     255    # get the filelevel from the supplied chip
     256    my $file = shift;
    199257
    200258    my $filelevel = $file->{filelevel};
     
    216274
    217275    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    218         run(command => $command, verbose => $verbose);
    219 
    220     unless ($success) { 
    221         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    222         &my_die ("Unable to register new detrend: $error_code", $corr_id, $PS_EXIT_PROG_ERROR);
     276        run(command => $command, verbose => $verbose);
     277
     278    unless ($success) {
     279        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     280        &my_die ("Unable to register new detrend: $error_code", $corr_id, $PS_EXIT_PROG_ERROR);
    223281    }
    224282
     
    231289
    232290    # $file = $$output[0];
    233     $det_id = $$output[0]->{det_id};
    234 }
    235 
    236 # use input chip image as a reference image
    237 foreach my $file (@$files) {
    238     # create the detrend correction for the imfiles based on the input imfiles
    239     my $reffile = $file->{uri};
    240     my $class_id = $file->{class_id};
    241 
    242     my $uri = $ipprc->filename("DVOCORR.OUTPUT", $outcorr, $class_id);
    243     unless ($uri) {
    244         &my_die ("Unable to find DVOCORR.OUTPUT in filerules", $corr_id, $PS_EXIT_PROG_ERROR);
    245     }
    246 
    247     my $command = "$dvoMakeCorr $outcorr";
    248     $command .= " -file $outgrid.fits";
    249     $command .= " -ref $reffile";
    250 
    251     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    252         run(command => $command, verbose => $verbose);
    253 
    254     unless ($success) {
    255         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    256         &my_die ("Unable to perform dvoMakeCorr: $error_code", $corr_id, $PS_EXIT_PROG_ERROR);
    257     }
    258 
    259     # register the detrend correction imfile
    260     $command = "$dettool -register_detrend_imfile";
    261     $command .= " -det_id $det_id";
    262     $command .= " -class_id $class_id";
    263     $command .= " -uri $uri";
    264     $command .= " -dbname $dbname" if defined $dbname;
    265 
    266     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    267         run(command => $command, verbose => $verbose);
    268 
    269     unless ($success) {
    270         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    271         &my_die ("Unable to register new detrend: $error_code", $corr_id, $PS_EXIT_PROG_ERROR);
    272     }
    273 }
    274 
    275 # set the detrun state to 'stop'
    276 {
    277     my $command = "$dettool -updatedetrun";
    278     $command .= " -det_id $det_id";
    279     $command .= " -state stop";
    280     $command .= " -dbname $dbname" if defined $dbname;
    281 
    282     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    283         run(command => $command, verbose => $verbose);
    284 
    285     unless ($success) {
    286         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    287         warn ("Unable to perform dettool -updatedetrun: $error_code");
    288         exit($error_code);
    289     }
    290 }
    291 
    292 # Push the results into the database
    293 {
    294     my $command = "$flatcorr -addprocess";
    295     $command .= " -corr_id $corr_id";
    296     $command .= " -hostname $host" if defined $host;
    297     $command .= " -dbname $dbname" if defined $dbname;
    298 
    299     unless ($no_update) {
    300 
    301         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    302             run(command => $command, verbose => $verbose);
    303         unless ($success) {
    304             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    305             warn ("Unable to perform regtool -addprocessedimfile: $error_code");
    306             exit($error_code);
    307         }
    308     } else {
    309         print "skipping command: $command\n";
     291    my $det_id = $$output[0]->{det_id};
     292    return $det_id;
     293}
     294
     295# use input chip images as reference images to make the detrend correction images
     296sub make_detrend_imfiles {
     297    my $det_id = shift;
     298    my $files = shift;
     299
     300    foreach my $file (@$files) {
     301        # create the detrend correction for the imfiles based on the input imfiles
     302        my $reffile = $file->{uri};
     303        my $class_id = $file->{class_id};
     304
     305        my $uri = $ipprc->filename("DVOCORR.OUTPUT", $outcorr, $class_id);
     306        unless ($uri) {
     307            &my_die ("Unable to find DVOCORR.OUTPUT in filerules", $corr_id, $PS_EXIT_PROG_ERROR);
     308        }
     309
     310        my $command = "$dvoMakeCorr $outcorr";
     311        $command .= " -file $outgrid.fits";
     312        $command .= " -ref $reffile";
     313
     314        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     315            run(command => $command, verbose => $verbose);
     316
     317        unless ($success) {
     318            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     319            &my_die ("Unable to perform dvoMakeCorr: $error_code", $corr_id, $PS_EXIT_PROG_ERROR);
     320        }
     321
     322        # register the detrend correction imfile
     323        $command = "$dettool -register_detrend_imfile";
     324        $command .= " -det_id $det_id";
     325        $command .= " -class_id $class_id";
     326        $command .= " -uri $uri";
     327        $command .= " -dbname $dbname" if defined $dbname;
     328
     329        ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     330            run(command => $command, verbose => $verbose);
     331
     332        unless ($success) {
     333            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     334            &my_die ("Unable to register new detrend: $error_code", $corr_id, $PS_EXIT_PROG_ERROR);
     335        }
    310336    }
    311337}
     
    320346    if (not $no_update) {
    321347        my $command = "$flatcorr -addprocess";
    322         $command .= " -corr_id $corr_id";
     348        $command .= " -corr_id $corr_id";
    323349        $command .= " -fault $exit_code";
    324350        $command .= " -hostname $host" if defined $host;
Note: See TracChangeset for help on using the changeset viewer.