IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 3, 2013, 1:43:50 PM (13 years ago)
Author:
eugene
Message:

merge changes from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130509/ippScripts/scripts/chip_imfile.pl

    r35594 r35747  
    200200
    201201    ## get the ppImage recipe for this camera and CHIP reduction
    202     $command = "$ppConfigDump -camera $camera -dump-recipe PPIMAGE -recipe PPIMAGE $recipe_ppImage -";
     202    $command = "$ppConfigDump -dump-recipe PPIMAGE -recipe PPIMAGE $recipe_ppImage -";
     203    if ($dump_config) {
     204        # use this camera's recipes
     205        $command .= " -camera $camera";
     206    } else {
     207        # get recipes as set in config dump file
     208        $command .= " -ipprc $configuration";
     209    }
    203210    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    204211        run(command => $command, verbose => 0);
     
    224231    }
    225232
    226 
    227     ## XXX make the feature more general?
     233    my $no_compress_image = metadataLookupBool($recipeData, 'NO.COMPRESS');
     234
    228235    my $useDeburnedImage = metadataLookupBool($recipeData, 'USE.DEBURNED.IMAGE');
     236    my $ppImageApplyBurntool = metadataLookupBool($recipeData, 'APPLY.BURNTOOL');
     237    my $burntoolArguments;
    229238
    230239    if ($useDeburnedImage) {
     
    327336        }
    328337
    329         ## We now know that we have an image that has been burntooled.
    330         my ($tempFile, $tempName) = tempfile( "/tmp/chip.$exp_id.$class_id.deburned.XXXX",
     338        # if recipe option PPIMAGE:APPLY.BURNTOOL is set and the burntool information is stored in
     339        # an external table (usual case), check the existence of that table file and set $burntoolArguments.
     340        # If burntool state does not match, say if the burntool data is stored in a fits extension in
     341        # the rawImfile, use the burntool program.
     342        if ($ppImageApplyBurntool && ($burntoolState == -1 * $burntoolStateGood)) {
     343            my $burntoolTable_uri = $uri;
     344            $burntoolTable_uri =~ s/fits$/burn.tbl/;
     345            my $burntoolTable_uriReal = $ipprc->file_resolve( $burntoolTable_uri );
     346            if ((!$burntoolTable_uriReal)||(!($ipprc->file_exists($burntoolTable_uri)))) {
     347                my $repair_cmd = "$nebrepair $burntoolTable_uri";
     348                my ($repair_success, $repair_error_code, $repair_full_buf, $repair_stdout_buf, $repair_stderr_buf )
     349                    = run(command => $repair_cmd, verbose => $verbose);
     350                unless ($repair_success) {
     351                    &my_die("Unable to attempt repair: $uri $repair_error_code", $exp_id,$chip_id, $class_id,
     352                        $PS_EXIT_SYS_ERROR);
     353                }
     354                $burntoolTable_uriReal = $ipprc->file_resolve( $burntoolTable_uri );
     355            }
     356            unless ($ipprc->file_exists($burntoolTable_uri)) {
     357                &my_die("Couldn't find burntool table: $burntoolTable_uri",$exp_id,$chip_id,$class_id,
     358                    $PS_EXIT_SYS_ERROR);
     359            }
     360            $burntoolArguments = " -burntool $burntoolTable_uri";
     361        } else {
     362            ## use external burntool program
     363
     364            ## We now know that we have an image that has been burntooled.
     365            my ($tempFile, $tempName) = tempfile( "/tmp/chip.$exp_id.$class_id.deburned.XXXX",
    331366                                              UNLINK => !$save_temps, SUFFIX => '.fits' );
    332367
    333         # get the UNIX version of the (possible) neb: or path: filename
    334         my $uriReal = $ipprc->file_resolve( $uri );
    335         # Catch errors here
    336         if (!$uriReal) {
    337             my $repair_cmd = "$nebrepair $uri";
    338             my ($repair_success, $repair_error_code, $repair_full_buf, $repair_stdout_buf, $repair_stderr_buf ) = run(command => $repair_cmd, verbose => $verbose);
    339             unless ($repair_success) {
    340                 &my_die("Unable to attempt repair: $uri $repair_error_code", $exp_id,$chip_id, $class_id, $PS_EXIT_SYS_ERROR);
    341             }
    342             $uriReal = $ipprc->file_resolve( $uri );
    343         }
    344            
    345         &my_die("Unable to resolve $uri on $host", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) if !$uriReal;
    346 
    347         # funpack into the temp file.
    348         my $funpack_cmd = "$funpack -S $uriReal > $tempName";
    349         ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $funpack_cmd, verbose => $verbose);
    350         unless ($success) {
    351             # Catch errors here
    352             my $repair_cmd = "$nebrepair $uri";
    353             my ($repair_success, $repair_error_code, $repair_full_buf, $repair_stdout_buf, $repair_stderr_buf ) = run(command => $repair_cmd, verbose => $verbose);
    354             unless ($repair_success) {
    355                 &my_die("Unable to attempt repair: $uri $repair_error_code", $exp_id,$chip_id, $class_id, $PS_EXIT_SYS_ERROR);
    356             }
    357             ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $funpack_cmd, verbose => $verbose);
    358         }
    359         unless ($success) {
    360             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    361             &my_die("Unable to perform funpack: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
    362         }
    363 
    364         ## Construct commands to apply the pre-calculated burntool trailfits to the pixel data.
    365         my ($burntoolTable_uri, $burntoolTable_uriReal);
    366         my $burntool_cmd = "$burntool ";
    367 
    368         if ($burntoolState == -1 * $burntoolStateGood) {   # Burntool information stored in an external table.
    369             $burntoolTable_uri = $uri;
    370             $burntoolTable_uri =~ s/fits$/burn.tbl/;
    371             $burntoolTable_uriReal = $ipprc->file_resolve( $burntoolTable_uri );
    372             if ((!$burntoolTable_uriReal)||(!($ipprc->file_exists($burntoolTable_uri)))) {
    373                 my $repair_cmd = "$nebrepair $burntoolTable_uri";
    374                 my ($repair_success, $repair_error_code, $repair_full_buf, $repair_stdout_buf, $repair_stderr_buf ) = run(command => $repair_cmd, verbose => $verbose);
    375                 unless ($repair_success) {
    376                     &my_die("Unable to attempt repair: $uri $repair_error_code", $exp_id,$chip_id, $class_id, $PS_EXIT_SYS_ERROR);
    377                 }
    378                 $burntoolTable_uriReal = $ipprc->file_resolve( $burntoolTable_uri );
    379             }
    380             unless ($ipprc->file_exists($burntoolTable_uri)) {
    381                 # Catch errors here
    382                 &my_die("Couldn't find burntool table: $burntoolTable_uri",$exp_id,$chip_id,$class_id, $PS_EXIT_SYS_ERROR);
    383             }
    384 
    385             $burntool_cmd .= "$tempName in=${burntoolTable_uriReal} persist=t apply=t";
    386         }
    387         elsif ($burntoolState == $burntoolStateGood) { # Burntool information stored in a header table.
    388             $burntool_cmd .= "$tempName persist=t apply=t";
    389         }
    390         else {
    391             &my_die("Image data not properly burntooled, impossible state", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
    392         }
    393 
    394         ## Run burntool to change the pixels of tempfile, and repoint $uri to that file.
    395         ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf) =
    396             run(command => $burntool_cmd, verbose => $verbose);
    397         unless ($success) {
    398             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    399             &my_die("Unable to perform burntool: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
    400         }
    401 
    402         $uri = $tempName;
    403         unless ($ipprc->file_exists($uri)) {
    404             &my_die("Couldn't find deburned input file: $uri\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
    405         }
    406 
    407 #       print STDERR "$uri $uriReal $tempName $burntoolTable_uri $burntoolTable_uriReal $burntool_cmd $save_temps\n";
    408 #       exit(100);
    409     }
    410 
    411     # apply the 'tiltystreak' operation, if desired
     368            # get the UNIX version of the (possible) neb: or path: filename
     369            my $uriReal = $ipprc->file_resolve( $uri );
     370                # Catch errors here
     371            if (!$uriReal) {
     372                my $repair_cmd = "$nebrepair $uri";
     373                my ($repair_success, $repair_error_code, $repair_full_buf, $repair_stdout_buf, $repair_stderr_buf ) = run(command => $repair_cmd, verbose => $verbose);
     374                unless ($repair_success) {
     375                    &my_die("Unable to attempt repair: $uri $repair_error_code", $exp_id,$chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     376                }
     377                $uriReal = $ipprc->file_resolve( $uri );
     378            }
     379               
     380            &my_die("Unable to resolve $uri on $host", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) if !$uriReal;
     381
     382            # funpack into the temp file.
     383            my $funpack_cmd = "$funpack -S $uriReal > $tempName";
     384            ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $funpack_cmd, verbose => $verbose);
     385            unless ($success) {
     386                # Catch errors here
     387                my $repair_cmd = "$nebrepair $uri";
     388                my ($repair_success, $repair_error_code, $repair_full_buf, $repair_stdout_buf, $repair_stderr_buf ) = run(command => $repair_cmd, verbose => $verbose);
     389                unless ($repair_success) {
     390                    &my_die("Unable to attempt repair: $uri $repair_error_code", $exp_id,$chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     391                }
     392                ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $funpack_cmd, verbose => $verbose);
     393            }
     394            unless ($success) {
     395                    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     396                &my_die("Unable to perform funpack: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     397            }
     398
     399            ## Construct commands to apply the pre-calculated burntool trailfits to the pixel data.
     400            my ($burntoolTable_uri, $burntoolTable_uriReal);
     401            my $burntool_cmd = "$burntool ";
     402
     403            if ($burntoolState == -1 * $burntoolStateGood) {   # Burntool information stored in an external table.
     404                $burntoolTable_uri = $uri;
     405                $burntoolTable_uri =~ s/fits$/burn.tbl/;
     406                $burntoolTable_uriReal = $ipprc->file_resolve( $burntoolTable_uri );
     407                if ((!$burntoolTable_uriReal)||(!($ipprc->file_exists($burntoolTable_uri)))) {
     408                    my $repair_cmd = "$nebrepair $burntoolTable_uri";
     409                    my ($repair_success, $repair_error_code, $repair_full_buf, $repair_stdout_buf, $repair_stderr_buf ) = run(command => $repair_cmd, verbose => $verbose);
     410                    unless ($repair_success) {
     411                        &my_die("Unable to attempt repair: $uri $repair_error_code", $exp_id,$chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     412                    }
     413                    $burntoolTable_uriReal = $ipprc->file_resolve( $burntoolTable_uri );
     414                }
     415                unless ($ipprc->file_exists($burntoolTable_uri)) {
     416                    # Catch errors here
     417                    &my_die("Couldn't find burntool table: $burntoolTable_uri",$exp_id,$chip_id,$class_id, $PS_EXIT_SYS_ERROR);
     418                }
     419
     420                $burntool_cmd .= "$tempName in=${burntoolTable_uriReal} persist=t apply=t";
     421            }
     422            elsif ($burntoolState == $burntoolStateGood) { # Burntool information stored in a header table.
     423                $burntool_cmd .= "$tempName persist=t apply=t";
     424            }
     425            else {
     426                &my_die("Image data not properly burntooled, impossible state", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     427            }
     428
     429            ## Run burntool to change the pixels of tempfile, and repoint $uri to that file.
     430            ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf) =
     431                run(command => $burntool_cmd, verbose => $verbose);
     432            unless ($success) {
     433                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     434                &my_die("Unable to perform burntool: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     435            }
     436
     437            $uri = $tempName;
     438            unless ($ipprc->file_exists($uri)) {
     439                &my_die("Couldn't find deburned input file: $uri\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     440            }
     441
     442            if ($dump_config) {
     443                # tell ppImage to not apply burntool since we have done it here
     444                $burntoolArguments = ' -Db PPIMAGE:APPLY.BURNTOOL F';
     445            }
     446    #       print STDERR "$uri $uriReal $tempName $burntoolTable_uri $burntoolTable_uriReal $burntool_cmd $save_temps\n";
     447    #       exit(100);
     448
     449        }
     450    }
     451
    412452    my $tiltystreakApply = metadataLookupBool($recipeData, 'TILTYSTREAK.APPLY');
    413453    if ($tiltystreakApply) {
    414 
    415         my $tiltystreakByClass = metadataLookupMD($recipeData, 'TILTYSTREAK.BY.CLASS');
    416         my $tiltystreakClassApply = metadataLookupBool($tiltystreakByClass, "APPLY.$class_id");
    417         if ($tiltystreakClassApply) {
    418 
    419             my $tiltystreakClassOptions = metadataLookupStr($tiltystreakByClass, "OPTIONS.$class_id");
    420             if ($tiltystreakClassOptions eq "none") {
    421                 $tiltystreakClassOptions = "";
    422             }
    423 
    424             my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf);
    425 
    426             # XXX make these optional (must be built by psbuild as well...)
    427             my $funpack = can_run('funpack') or &my_die ("Can't find funpack", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
    428             my $tiltystreak = can_run('tiltystreak') or &my_die ("Can't find tiltystreak", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
    429 
    430             # create an temporary output file:
    431             my ($tempFile, $tempName) = tempfile( "/tmp/chip.$exp_id.$class_id.tmp.XXXX", UNLINK => !$save_temps );
    432 
    433             print "uri: $uri\n";
    434 
    435             # get the UNIX version of the (possible) neb: or path: filename
    436             my $uriReal = $ipprc->file_resolve( $uri );
    437 
    438             print "uriReal: $uriReal\n";
    439 
    440             # unpack the data (is a NOP if not compressed)
    441             $command = "$funpack -S $uriReal > $tempName";
    442             ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
    443             unless ($success) {
    444                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    445                 &my_die("Unable to perform funpack: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
    446             }
    447 
    448             # run tiltystreak
    449             $command = "$tiltystreak $tempName $tiltystreakClassOptions";
    450             ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
    451             unless ($success) {
    452                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    453                 &my_die("Unable to perform tiltystreak: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
    454             }
    455 
    456             # supply the output file as the new input file
    457             $uri = $tempName;
    458         }
     454        # NOTE: application of TILTYSTREAK.APPLY was here. Removed after r35685
     455        &my_die("Unable to perform tiltystreak: code has been removed", $exp_id, $chip_id, $class_id,
     456            $PS_EXIT_PROG_ERROR);
    459457    }
    460458
     
    479477        $command .= " -Db PPIMAGE:BIN1.FITS FALSE -Db PPIMAGE:BIN2.FITS FALSE";
    480478    }
     479    if ($no_compress_image) {
     480        $command .= " -R PPIMAGE.CHIP FITS.TYPE NONE";
     481    }
     482    $command .= $burntoolArguments if $burntoolArguments;
    481483    $command .= " -threads $threads" if defined $threads;
    482484    $command .= " -image_id $chip_imfile_id" if defined $chip_imfile_id;
Note: See TracChangeset for help on using the changeset viewer.