IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

updates from trunk

Location:
branches/simmosaic_branches
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/simmosaic_branches

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

    r23688 r27839  
    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}
     
    105106
    106107# Run addstar -resort to ensure the db is indexed
     108# XXX addstar should be able to recognize and skip indexed tables
    107109{
    108110    my $command = "$addstar -resort";
     
    111113
    112114    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    113         run(command => $command, verbose => $verbose);
    114 
    115     unless ($success) { 
    116         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    117         &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);
    118120    }
    119121}
     
    134136
    135137    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    136         run(command => $command, verbose => $verbose);
    137 
    138     unless ($success) {
    139         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    140         &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";
    141196    }
    142197}
     
    144199# get a single input exposure
    145200# flatcorr -inputexp -corr_id $corr_id -limit 1
    146 my $chip_id;
    147 {
     201sub get_chip_id {
     202
    148203    my $command = "$flatcorr -inputexp";
    149204    $command .= " -corr_id $corr_id";
     
    164219        &my_die("Unable to parse metadata list", $corr_id, $PS_EXIT_PROG_ERROR);
    165220
    166     # check for existence 
     221    # check for existence
    167222    my $file = $$files[0];
    168     $chip_id = $file->{chip_id};
     223    my $chip_id = $file->{chip_id};
     224
     225    return $chip_id;
    169226}
    170227
    171228# get the list of imfiles for the single input exposure
    172229# flatcorr -inputimfile -chip_id $chip_id
    173 my $files;
    174 {
     230sub get_imfiles {
     231    my $chip_id = shift;
     232
    175233    my $command = "$flatcorr -inputimfile";
    176234    $command .= " -chip_id $chip_id";
     
    187245
    188246    # extract the metadata for the files into a hash list
    189     $files = parse_md_list($metadata) or
     247    my $files = parse_md_list($metadata) or
    190248        &my_die("Unable to parse metadata list", $corr_id, $PS_EXIT_PROG_ERROR);
     249
     250    return $files;
    191251}
    192252
    193253# set up the detrend run to store the corrected imfiles
    194 my $det_id;
    195 {
    196     # get the filelevel from one of these chips
    197     my $file = $$files[0];
     254sub get_det_id {
     255    # get the filelevel from the supplied chip
     256    my $file = shift;
    198257
    199258    my $filelevel = $file->{filelevel};
     
    215274
    216275    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    217         run(command => $command, verbose => $verbose);
    218 
    219     unless ($success) { 
    220         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    221         &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);
    222281    }
    223282
     
    230289
    231290    # $file = $$output[0];
    232     $det_id = $$output[0]->{det_id};
    233 }
    234 
    235 # use input chip image as a reference image
    236 foreach my $file (@$files) {
    237     # create the detrend correction for the imfiles based on the input imfiles
    238     my $reffile = $file->{uri};
    239     my $class_id = $file->{class_id};
    240 
    241     my $uri = $ipprc->filename("DVOCORR.OUTPUT", $outcorr, $class_id);
    242     unless ($uri) {
    243         &my_die ("Unable to find DVOCORR.OUTPUT in filerules", $corr_id, $PS_EXIT_PROG_ERROR);
    244     }
    245 
    246     my $command = "$dvoMakeCorr $outcorr";
    247     $command .= " -file $outgrid.fits";
    248     $command .= " -ref $reffile";
    249 
    250     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    251         run(command => $command, verbose => $verbose);
    252 
    253     unless ($success) {
    254         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    255         &my_die ("Unable to perform dvoMakeCorr: $error_code", $corr_id, $PS_EXIT_PROG_ERROR);
    256     }
    257 
    258     # register the detrend correction imfile
    259     $command = "$dettool -register_detrend_imfile";
    260     $command .= " -det_id $det_id";
    261     $command .= " -class_id $class_id";
    262     $command .= " -uri $uri";
    263     $command .= " -dbname $dbname" if defined $dbname;
    264 
    265     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    266         run(command => $command, verbose => $verbose);
    267 
    268     unless ($success) {
    269         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    270         &my_die ("Unable to register new detrend: $error_code", $corr_id, $PS_EXIT_PROG_ERROR);
    271     }
    272 }
    273 
    274 # set the detrun state to 'stop'
    275 {
    276     my $command = "$dettool -updatedetrun";
    277     $command .= " -det_id $det_id";
    278     $command .= " -state stop";
    279     $command .= " -dbname $dbname" if defined $dbname;
    280 
    281     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    282         run(command => $command, verbose => $verbose);
    283 
    284     unless ($success) {
    285         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    286         warn ("Unable to perform dettool -updatedetrun: $error_code");
    287         exit($error_code);
    288     }
    289 }
    290 
    291 # Push the results into the database
    292 {
    293     my $command = "$flatcorr -addprocess";
    294     $command .= " -corr_id $corr_id";
    295     $command .= " -hostname $host" if defined $host;
    296     $command .= " -dbname $dbname" if defined $dbname;
    297 
    298     unless ($no_update) {
    299 
    300         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    301             run(command => $command, verbose => $verbose);
    302         unless ($success) {
    303             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    304             warn ("Unable to perform regtool -addprocessedimfile: $error_code");
    305             exit($error_code);
    306         }
    307     } else {
    308         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        }
    309336    }
    310337}
     
    319346    if (not $no_update) {
    320347        my $command = "$flatcorr -addprocess";
    321         $command .= " -corr_id $corr_id";
     348        $command .= " -corr_id $corr_id";
    322349        $command .= " -fault $exit_code";
    323350        $command .= " -hostname $host" if defined $host;
Note: See TracChangeset for help on using the changeset viewer.