IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 4, 2008, 2:25:06 PM (18 years ago)
Author:
eugene
Message:

major work to finish and fix the syntax

File:
1 edited

Legend:

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

    r19327 r19373  
    3434use PS::IPP::Metadata::Config;
    3535use PS::IPP::Metadata::Stats;
     36use PS::IPP::Metadata::List qw( parse_md_list );
    3637use PS::IPP::Config 1.01 qw( :standard );
    3738
     
    4243use Pod::Usage qw( pod2usage );
    4344
    44 my ($corr_id, $dvodb, $region, $filter, $dbname, $workdir, $no_update, $no_op);
     45my ($corr_id, $dvodb, $region, $filter, $dbname, $workdir, $verbose, $no_update, $no_op);
    4546GetOptions(
    4647    'corr_id|i=s'      => \$corr_id,
     
    5051    'dbname|d=s'       => \$dbname,# Database name
    5152    'workdir|w=s'      => \$workdir, # Working directory for output files
     53    'verbose'           => \$verbose,   # Print to stdout
    5254    'no-update'        => \$no_update,
    5355    'no-op'            => \$no_op,
     
    6668my $missing_tools;
    6769my $relphot     = can_run('relphot')      or (warn "Can't find relphot"      and $missing_tools = 1);
     70my $addstar     = can_run('addstar')      or (warn "Can't find addstar"      and $missing_tools = 1);
    6871my $dvoMakeCorr = can_run('dvoMakeCorr')  or (warn "Can't find dvoMakeCorr"  and $missing_tools = 1);
    6972my $detselect   = can_run('detselect')    or (warn "Can't find detselect"    and $missing_tools = 1);
     
    7679}
    7780
    78 my($outgrid, $outcorr);
    79 
    80 $outgrid = "$workdir/grid.$corr_id.fits";
    81 $outcorr = "$workdir/corr.$corr_id";
     81my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     82
     83my $outgrid = "$workdir/grid.$corr_id.fits";
     84my $outcorr = "$workdir/corr.$corr_id";
    8285
    8386# parse the region (RAs,RAe:DECs,DECe) : item = +/-NNN.NNNN
     
    8689my ($DECs, $DECe) = split (",", $coords[1]);
    8790
     91# Run addstar -resort to ensure the db is indexed
     92{
     93    my $command = "echo $addstar -resort";
     94    $command .= " -D CATDIR $dvodb";
     95    $command .= " -region $RAs $RAe $DECs $DECe";
     96
     97    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     98        run(command => $command, verbose => $verbose);
     99
     100    unless ($success) {
     101        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     102        &my_die ("Unable to perform addstar -resort for dvodb $dvodb on region $region: $error_code", $corr_id, $error_code);
     103    }
     104}
     105
    88106# Run relphot (filter) for the specified region (need to clarify the options like imfreeze)
    89107{
    90     my $command = "$relphot $filter";
    91     $command .= "-D CATDIR $dvodb";
    92     $command .= "-region $RAs $RAe $DECs $DECe";
    93     $command .= "-grid $outgrid";
    94     $command .= "-imfreeze";
    95 
    96     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    97         cache_run(command => $command, verbose => 1);
    98 
    99     unless ($success) {
    100         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    101         &my_die ("Unable to perform relphot -grid on region $region: $error_code", $dvo_id, $region, "RELPHOT", $status, $dbname);
     108    my $command = "echo $relphot $filter";
     109    $command .= " -D CATDIR $dvodb";
     110    $command .= " -region $RAs $RAe $DECs $DECe";
     111    $command .= " -grid $outgrid";
     112    $command .= " -imfreeze";
     113
     114    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     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 relphot -grid for dvodb $dvodb on region $region: $error_code", $corr_id, $error_code);
    102120    }
    103121}
     
    107125my $chip_id;
    108126{
    109     my $command = "$flatcorr -inputexp -corr_id $corr_id -limit 1"; # Command to run
    110     $command .= " -dbname $dbname" if defined $dbname;
     127    my $command = "$flatcorr -inputexp";
     128    $command .= " -corr_id $corr_id";
     129    $command .= " -limit 1";
     130    $command .= " -dbname $dbname" if defined $dbname;
     131
    111132    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    112133        run(command => $command, verbose => $verbose);
     
    119140
    120141    # extract the metadata for the files into a hash list
    121     $files = parse_md_list($metadata) or
     142    my $files = parse_md_list($metadata) or
    122143        &my_die("Unable to parse metadata list", $corr_id, $PS_EXIT_PROG_ERROR);
    123144
    124     # check for existence
     145    # check for existence 
    125146    my $file = $$files[0];
    126147    $chip_id = $file->{chip_id};
     
    131152my $files;
    132153{
    133     my $command = "$flatcorr -inputimfile -chip_id $chip_id"; # Command to run
    134     $command .= " -dbname $dbname" if defined $dbname;
     154    my $command = "$flatcorr -inputimfile";
     155    $command .= " -chip_id $chip_id";
     156    $command .= " -dbname $dbname" if defined $dbname;
     157
    135158    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    136159        run(command => $command, verbose => $verbose);
     
    150173my $det_id;
    151174{
     175    # get the filelevel from one of these chips
     176    my $file = $$files[0];
     177
     178    my $filelevel = $file->{filelevel};
     179    my $camera    = $file->{camera};
     180    my $telescope = $file->{telescope};
     181    my $filter    = $file->{filter};
     182
     183    ## XXX the flat-field correction is only defined for a single
     184    ## camera.  we are grabbing the camera here, but we are assuming
     185    ## the flatcorrRun was defined for only a single camera.
     186    $ipprc->define_camera($camera);
     187
    152188    my $command = "$dettool -register_detrend";
    153     $command .= "-det_type FLATCORR";
    154     $command .= "-file_level $fileLevel";
    155     $command .= "-workdir $workdir";
    156     $command .= "-inst $inst";
    157     $command .= " -dbname $dbname" if defined $dbname;
    158     ## XXX what else do we need, and where do we get it?
    159 
    160     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    161         cache_run(command => $command, verbose => 1);
     189    $command .= " -det_type FLATCORR";
     190    $command .= " -filelevel $filelevel";
     191    $command .= " -workdir $workdir";
     192    $command .= " -inst $camera";
     193    $command .= " -telescope $telescope";
     194    $command .= " -filter $filter";
     195    $command .= " -dbname $dbname" if defined $dbname;
     196
     197    ## the flat-field correction is valid for any airmass, exptime, solangle
     198    ## for now, we assume the posangle and ccd_temp are not important
     199    ## XXX someone needs to set the use_begin, use_end values??
     200    ## XXX inherit a label from the flatcorrRun?
     201
     202    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     203        run(command => $command, verbose => 1);
    162204
    163205    unless ($success) {
     
    173215        &my_die("Unable to parse metadata list", $corr_id, $PS_EXIT_PROG_ERROR);
    174216
    175     my $file = $$output[0];
    176 
    177     $det_id = $file->{det_id};
     217    # $file = $$output[0];
     218    $det_id = $$output[0]->{det_id};
    178219}
    179220
     
    184225    my $class_id = $file->{class_id};
    185226
    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);
     227    my $uri = $ipprc->filename("DVOCORR.OUTPUT", $outcorr, $class_id);
     228    unless ($uri) {
     229        &my_die ("Unable to find DVOCORR.OUTPUT in filerules", $corr_id, $PS_EXIT_PROG_ERROR);
     230    }
     231
     232    my $command = "echo $dvoMakeCorr $outcorr";
     233    $command .= " -file $outgrid";
     234    $command .= " -ref $reffile";
     235
     236    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     237        run(command => $command, verbose => 1);
    192238
    193239    unless ($success) {
     
    197243
    198244    # register the detrend correction imfile
    199     my $command = "$dettool -register_detrend_imfile";
     245    $command = "$dettool -register_detrend_imfile";
    200246    $command .= " -det_id $det_id";
    201247    $command .= " -class_id $class_id";
     
    203249    $command .= " -dbname $dbname" if defined $dbname;
    204250
    205     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    206         cache_run(command => $command, verbose => 1);
     251    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     252        run(command => $command, verbose => 1);
    207253
    208254    unless ($success) {
     
    212258}
    213259
    214 my $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
    220 unless ($no_update) {
     260# set the detrun state to 'stop'
     261{
     262    my $command = "$dettool -updatedetrun";
     263    $command .= " -det_id $det_id";
     264    $command .= " -state stop";
     265    $command .= " -dbname $dbname" if defined $dbname;
     266
    221267    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    222268        run(command => $command, verbose => 1);
     269
    223270    unless ($success) {
    224271        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     
    226273        exit($error_code);
    227274    }
    228 } else {
    229     print "skipping command: $command\n";
    230 }
    231 
    232 my $command = "$flatcorr -addprocess";
    233 $command .= " -corr_id $corr_id";
    234 $command .= " -dbname $dbname" if defined $dbname;
     275}
    235276
    236277# Push the results into the database
    237 unless ($no_update) {
    238     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    239         run(command => $command, verbose => 1);
    240     unless ($success) {
    241         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    242         warn ("Unable to perform regtool -addprocessedimfile: $error_code");
    243         exit($error_code);
    244     }
    245 } else {
    246     print "skipping command: $command\n";
     278{
     279    my $command = "$flatcorr -addprocess";
     280    $command .= " -corr_id $corr_id";
     281    $command .= " -hostname $host" if defined $host;
     282    $command .= " -dbname $dbname" if defined $dbname;
     283
     284    unless ($no_update) {
     285
     286        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     287            run(command => $command, verbose => 1);
     288        unless ($success) {
     289            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     290            warn ("Unable to perform regtool -addprocessedimfile: $error_code");
     291            exit($error_code);
     292        }
     293    } else {
     294        print "skipping command: $command\n";
     295    }
    247296}
    248297
     
    250299{
    251300    my $msg = shift; # Warning message on die
    252     my $dvo_id    = shift;
    253     my $region    = shift;
    254     my $last_step = shift;
    255     my $status    = shift;
    256     my $dbname    = shift;
     301    my $corr_id    = shift;
     302    my $exit_code  = shift;
    257303
    258304    carp($msg);
    259     if (defined $dvo_id && defined $region && defined $last_step && defined $status and not $no_update) {
    260         my $command = "$caltool -addcalrun";
    261         $command .= " -dvo_id $dvo_id";
    262         $command .= " -region $region";
    263         $command .= " -last_step $last_step";
    264         $command .= " -status $status";
     305    if (not $no_update) {
     306        my $command = "$flatcorr -addprocess";
     307        $command .= " -corr_id $corr_id";
     308        $command .= " -code $exit_code";
     309        $command .= " -hostname $host" if defined $host;
    265310        $command .= " -dbname $dbname" if defined $dbname;
    266311        system ($command);
Note: See TracChangeset for help on using the changeset viewer.