IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 19327


Ignore:
Timestamp:
Sep 2, 2008, 9:37:48 AM (18 years ago)
Author:
eugene
Message:

substantial work but still incomplete

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/flatcorr_proc.pl

    r17671 r19327  
    1212
    1313# dettool -register -det_type FLATCORR -filelevel (level) -workdir -inst, etc
     14
    1415# foreach $imfile ()
    1516#   dettool -register_imfile -uri, etc, etc
     
    5455
    5556pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    56 pod2usage( -msg => "Required options: --corr_id --dvodb --region --filter",
     57pod2usage( -msg => "Required options: --corr_id --dvodb --region --filter --workdir",
    5758           -exitval => 3) unless
    5859    defined $corr_id and
    5960    defined $dvodb and
    6061    defined $region and
     62    defined $workdir and
    6163    defined $filter;
    6264
     
    7779
    7880$outgrid = "$workdir/grid.$corr_id.fits";
    79 $outcorr = "$workdir/corr.$corr_id.fits";
     81$outcorr = "$workdir/corr.$corr_id";
    8082
    8183# parse the region (RAs,RAe:DECs,DECe) : item = +/-NNN.NNNN
     
    9092    $command .= "-region $RAs $RAe $DECs $DECe";
    9193    $command .= "-grid $outgrid";
    92     $command .= "-imfreeze?";
     94    $command .= "-imfreeze";
    9395
    9496    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    101103}
    102104
    103 # use one of the input raw images as a reference image
    104 # XXX I'm not sure how this works: do I run this once per imfile for a given exp?
    105 my ($reffile)
    106 {
    107     my $command = "$flatcoor -flatcorrimfile -limit 1";
    108 
    109     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    110         cache_run(command => $command, verbose => 1);
    111 
    112     unless ($success) {
    113         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    114         &my_die ("Unable to perform flatcorr -flatcorrimfile: $error_code", $dvo_id, $region, "RELPHOT", $status, $dbname);
    115     }
    116 
     105# get a single input exposure
     106# flatcorr -inputexp -corr_id $corr_id -limit 1
     107my $chip_id;
     108{
     109    my $command = "$flatcorr -inputexp -corr_id $corr_id -limit 1"; # Command to run
     110    $command .= " -dbname $dbname" if defined $dbname;
     111    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     112        run(command => $command, verbose => $verbose);
     113    unless ($success) {
     114        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     115        &my_die("Unable to perform camtool: $error_code", $corr_id, $error_code);
     116    }
    117117    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    118         &my_die("Unable to parse metadata config doc", $dvo_id, $region, "RELPHOT", $status, $dbname, $PS_EXIT_PROG_ERROR););
    119 
    120     my $imfiles = parse_md_list($metadata) or
    121         &my_die("Unable to parse metadata list", $dvo_id, $region, "RELPHOT", $status, $dbname, $PS_EXIT_PROG_ERROR););
    122 
    123     my $imfile = $imfiles->[0];
    124     $reffile = $imfile->{uri};
    125 }
    126 
    127 {
    128     my $command = "$dvoMakeCorr -file $outgrid -ref $reffile $outcorr";
    129 
    130     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    131         cache_run(command => $command, verbose => 1);
    132 
    133     unless ($success) {
    134         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    135         &my_die ("Unable to perform dvoMakeCorr: $error_code", $dvo_id, $region, "RELASTRO.OBJECTS", $status, $dbname);
    136     }
    137 }
    138 
    139 {
    140     my $command = "$dettool -register";
     118        &my_die("Unable to parse metadata config doc", $corr_id, $PS_EXIT_PROG_ERROR);
     119
     120    # extract the metadata for the files into a hash list
     121    $files = parse_md_list($metadata) or
     122        &my_die("Unable to parse metadata list", $corr_id, $PS_EXIT_PROG_ERROR);
     123
     124    # check for existence
     125    my $file = $$files[0];
     126    $chip_id = $file->{chip_id};
     127}
     128
     129# get the list of imfiles for the single input exposure
     130# flatcorr -inputimfile -chip_id $chip_id
     131my $files;
     132{
     133    my $command = "$flatcorr -inputimfile -chip_id $chip_id"; # Command to run
     134    $command .= " -dbname $dbname" if defined $dbname;
     135    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     136        run(command => $command, verbose => $verbose);
     137    unless ($success) {
     138        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     139        &my_die("Unable to perform camtool: $error_code", $corr_id, $error_code);
     140    }
     141    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     142        &my_die("Unable to parse metadata config doc", $corr_id, $PS_EXIT_PROG_ERROR);
     143
     144    # extract the metadata for the files into a hash list
     145    $files = parse_md_list($metadata) or
     146        &my_die("Unable to parse metadata list", $corr_id, $PS_EXIT_PROG_ERROR);
     147}
     148
     149# set up the detrend run to store the corrected imfiles
     150my $det_id;
     151{
     152    my $command = "$dettool -register_detrend";
    141153    $command .= "-det_type FLATCORR";
    142154    $command .= "-file_level $fileLevel";
     
    151163    unless ($success) {
    152164        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    153         &my_die ("Unable to perform addstar -resort on region $region: $error_code", $dvo_id, $region, "RELASTRO.IMAGES", $status, $dbname);
    154     }
    155 }
    156 
    157 my $command = "$flatcorr -done";
     165        &my_die ("Unable to register new detrend: $error_code", $corr_id, $PS_EXIT_PROG_ERROR);
     166    }
     167
     168    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     169        &my_die("Unable to parse metadata config doc", $corr_id, $PS_EXIT_PROG_ERROR);
     170
     171    # extract the metadata for the files into a hash list
     172    my $output = parse_md_list($metadata) or
     173        &my_die("Unable to parse metadata list", $corr_id, $PS_EXIT_PROG_ERROR);
     174
     175    my $file = $$output[0];
     176
     177    $det_id = $file->{det_id};
     178}
     179
     180# use input chip image as a reference image
     181foreach my $file (@$files) {
     182    # create the detrend correction for the imfiles based on the input imfiles
     183    my $reffile = $file->{uri};
     184    my $class_id = $file->{class_id};
     185
     186    my $uri = ipprc_filename ($outcorr, "DVO.CORR", class_id);
     187
     188    my $command = "$dvoMakeCorr -file $outgrid -ref $reffile $outcorr";
     189
     190    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     191        cache_run(command => $command, verbose => 1);
     192
     193    unless ($success) {
     194        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     195        &my_die ("Unable to perform dvoMakeCorr: $error_code", $corr_id, $PS_EXIT_PROG_ERROR);
     196    }
     197
     198    # register the detrend correction imfile
     199    my $command = "$dettool -register_detrend_imfile";
     200    $command .= " -det_id $det_id";
     201    $command .= " -class_id $class_id";
     202    $command .= " -uri $uri";
     203    $command .= " -dbname $dbname" if defined $dbname;
     204
     205    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     206        cache_run(command => $command, verbose => 1);
     207
     208    unless ($success) {
     209        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     210        &my_die ("Unable to register new detrend: $error_code", $corr_id, $PS_EXIT_PROG_ERROR);
     211    }
     212}
     213
     214my $command = "$dettool -updatedetrun";
     215$command .= " -det_id $det_id";
     216$command .= " -state XXX";
     217$command .= " -dbname $dbname" if defined $dbname;
     218
     219# Push the results into the database
     220unless ($no_update) {
     221    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     222        run(command => $command, verbose => 1);
     223    unless ($success) {
     224        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     225        warn ("Unable to perform dettool -updatedetrun: $error_code");
     226        exit($error_code);
     227    }
     228} else {
     229    print "skipping command: $command\n";
     230}
     231
     232my $command = "$flatcorr -addprocess";
    158233$command .= " -corr_id $corr_id";
    159 $command .= " -stats UNKNOWN";
    160234$command .= " -dbname $dbname" if defined $dbname;
    161235
Note: See TracChangeset for help on using the changeset viewer.