IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 7, 2009, 4:08:25 PM (17 years ago)
Author:
Paul Price
Message:

Merging trunk (r25026) to get up-to-date on old branch.

Location:
branches/pap
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/pap

  • branches/pap/ippScripts/scripts/chip_imfile.pl

    r23688 r25027  
    2020use PS::IPP::Metadata::Config;
    2121use PS::IPP::Config 1.01 qw( :standard );
     22use File::Temp qw( tempfile );
    2223
    2324use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    3940# Parse the command-line arguments
    4041my ( $exp_id, $chip_id, $class_id, $chip_imfile_id, $uri, $camera, $outroot, $dbname, $run_state, $reduction, $threads, $verbose,
    41      $no_update, $no_op, $redirect, $magicked, $deburned );
     42     $no_update, $save_temps, $no_op, $redirect, $magicked, $deburned );
    4243GetOptions(
    4344    'exp_id=s'          => \$exp_id,    # Exposure identifier
     
    5253    'run-state=s'       => \$run_state, # current state of the run (new, update)
    5354    'magicked'          => \$magicked,  # magicked state of input file
    54     'deburned=s'        => \$deburned,  # does deburned image exist? 
     55    'deburned=s'        => \$deburned,  # does deburned image exist?
    5556    'threads=s'         => \$threads,   # Number of threads to use for ppImage
    5657    'verbose'           => \$verbose,   # Print to stdout
     
    5859    'no-op'             => \$no_op,     # Don't do any operations?
    5960    'redirect-output'   => \$redirect,
     61    'save-temps'        => \$save_temps, # Save temporary files?
    6062    ) or pod2usage( 2 );
    6163
    6264pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    63 pod2usage( -msg => "Required options: --exp_id --chip_id --class_id --uri --camera --outroot --run-state",
     65pod2usage( -msg => "Required options: --exp_id --chip_id --chip_imfile_id --class_id --uri --camera --outroot --run-state",
    6466           -exitval => 3) unless
    6567    defined $exp_id and
     
    142144    my $useDeburnedImage = metadataLookupBool($recipeData, 'USE.DEBURNED.IMAGE');
    143145    if ($useDeburnedImage && $deburned) {
    144         $uri =~ s/fits$/burn.fits/;
    145         &my_die("Couldn't find deburned input file: $uri\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($uri);
     146        $uri =~ s/fits$/burn.fits/;
     147        &my_die("Couldn't find deburned input file: $uri\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($uri);
     148    }
     149
     150    # apply the 'tiltystreak' operation, if desired
     151    my $tiltystreakApply = metadataLookupBool($recipeData, 'TILTYSTREAK.APPLY');
     152    if ($tiltystreakApply) {
     153
     154        my $tiltystreakByClass = metadataLookupMD($recipeData, 'TILTYSTREAK.BY.CLASS');
     155        my $tiltystreakClassApply = metadataLookupBool($tiltystreakByClass, "APPLY.$class_id");
     156        if ($tiltystreakClassApply) {
     157
     158            my $tiltystreakClassOptions = metadataLookupStr($tiltystreakByClass, "OPTIONS.$class_id");
     159            if ($tiltystreakClassOptions eq "none") {
     160                $tiltystreakClassOptions = "";
     161            }
     162
     163            my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf);
     164
     165            # XXX make these optional (must be built by psbuild as well...)
     166            my $funpack = can_run('funpack') or &my_die ("Can't find funpack", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     167            my $tiltystreak = can_run('tiltystreak') or &my_die ("Can't find tiltystreak", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     168
     169            # create an temporary output file:
     170            my ($tempFile, $tempName) = tempfile( "/tmp/chip.$exp_id.$class_id.tmp.XXXX", UNLINK => !$save_temps );
     171
     172            print "uri: $uri\n";
     173
     174            # get the UNIX version of the (possible) neb: or path: filename
     175            my $uriReal = $ipprc->file_resolve( $uri );
     176
     177            print "uriReal: $uriReal\n";
     178
     179            # unpack the data (is a NOP if not compressed)
     180            $command = "$funpack -S $uriReal > $tempName";
     181            ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     182            unless ($success) {
     183                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     184                &my_die("Unable to perform funpack: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     185            }
     186
     187            # run tiltystreak
     188            $command = "$tiltystreak $tempName $tiltystreakClassOptions";
     189            ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     190            unless ($success) {
     191                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     192                &my_die("Unable to perform tiltystreak: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     193            }
     194
     195            # supply the output file as the new input file
     196            $uri = $tempName;
     197        }
    146198    }
    147199
     
    201253        }
    202254        chomp $cmdflags;
    203         ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag
     255        if (($camera ne "GPC1") or ($class_id ne "XY27") or ($exp_id < 53171)) {
     256            ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag
     257        } else {
     258            # hack to kick ota 27 out of subsequent analysis by setting quality flag to a non-zero value
     259            my ($before, $after) = split " -quality ", $cmdflags;
     260
     261            # get the current value
     262            ($quality) = $after =~ /^(\d+)/;
     263            $after = substr($after, length($quality));
     264
     265            # replace it if it is zero
     266            $quality = 42 if !$quality;
     267
     268            # rebuild the cmdflags
     269            $cmdflags = $before . " -quality $quality";
     270            $cmdflags .= " $after" if $after;
     271        }
    204272    }
    205273
     
    265333            $command = "$chiptool -addprocessedimfile";
    266334            $command .= " -exp_id $exp_id";
    267             $command .= " -uri $outputImage";
     335            $command .= " -uri $outputImage" if defined $outputImage;
    268336            $command .= " -path_base $outroot";
    269337            $command .= " -hostname $host" if defined $host;
Note: See TracChangeset for help on using the changeset viewer.