IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 30, 2009, 5:20:29 PM (17 years ago)
Author:
watersc1
Message:

Finished up my edits to the detrend cleanup, and some changes to my
copy of burntool and the pslib astrometry. Detrend cleanup has not
been tested yet. That's up next.

Location:
branches/czw_branch/cleanup
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/cleanup

  • branches/czw_branch/cleanup/ippScripts/scripts/magic_destreak_revert.pl

    r24686 r24951  
    6060
    6161pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    62 pod2usage( -msg => "Required options: --magic_ds_id --camera --streaks --stage --stage_id --component --uri --path_base --outroot",
     62pod2usage( -msg => "Required options: --magic_ds_id --camera --stage --stage_id --component --path_base --outroot",
    6363           -exitval => 3) unless
    6464    defined $magic_ds_id and
     
    7070    defined $outroot;
    7171
    72 # XXX: for testing
    73 $no_update = 1;
    74 
    7572&my_die("bytes and md5sum are is required for raw stage stage", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR) if ($stage eq 'raw' and (!$bytes or !$md5sum));
    7673
     
    8784if ($@ or not defined $nebulous) {
    8885    &my_die ("Unable to create a Nebulous::Client object with proxy $nebulousServer", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
    89     return undef;
    9086}
    9187
     
    9995} elsif ($stage eq "diff") {
    10096    $skycell_id = $component;
    101 } else {
     97} elsif ($stage ne "camera") {
    10298    &my_die("Invalid value for stage: $stage", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
    10399}
     
    108104my $basename = basename($path_base);
    109105my $nebulousInput = inNebulous($dirname);
    110 
    111 # parse replace arguments check for errors and set up
    112 # the appropriate paths
    113 # this program doesn't make sense if $replace is false
    114 &my_die("Invalid value for replace: $replace", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR) if $replace ne "T";
    115106
    116107if (defined($replace) and ($replace eq "T")) {
     
    120111}
    121112
    122 # default value is "NULL" do not use
     113&my_die("replace not allowed for non-nebulous files", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR)
     114    if ($replace eq "T") and !$nebulousInput;
     115
     116
     117# default value is "NULL" do not use it
    123118if (defined($recoveryroot) and ($recoveryroot eq "NULL")) {
    124119    $recoveryroot = undef;
     
    135130    $backup_path_base = $tmproot . "$basename";
    136131} else {
    137     # note: trailing / is necessary
     132    # note: the trailing / here is necessary
    138133    $tmproot = "$outroot/";
    139134    $backup_path_base = $tmproot . $basename;
     
    147142
    148143
    149 my ($image, $mask, $ch_mask, $weight);
    150 my ($bimage, $bmask, $bch_mask, $bweight);
     144my ($image, $mask, $ch_mask, $weight, $sources, $astrom);
     145my ($bimage, $bmask, $bch_mask, $bweight, $bsources, $bastrom);
    151146
    152147if ($stage eq "raw") {
     
    172167    $bch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $backup_path_base, $class_id);
    173168    $bweight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $backup_path_base, $class_id);
     169} elsif ($stage eq "camera") {
     170    $astrom =  $ipprc->filename("PSASTRO.OUTPUT", $path_base);
     171    $bastrom = $ipprc->filename("PSASTRO.OUTPUT", $backup_path_base);
    174172} elsif ($stage eq "warp") {
    175173    $image  = $ipprc->filename("PSWARP.OUTPUT", $path_base);
    176174    $mask   = $ipprc->filename("PSWARP.OUTPUT.MASK", $path_base);
    177175    $weight = $ipprc->filename("PSWARP.OUTPUT.VARIANCE", $path_base);
     176    $sources = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $path_base);
    178177    $bimage  = $ipprc->filename("PSWARP.OUTPUT", $backup_path_base);
    179178    $bmask   = $ipprc->filename("PSWARP.OUTPUT.MASK", $backup_path_base);
    180179    $bweight = $ipprc->filename("PSWARP.OUTPUT.VARIANCE", $backup_path_base);
     180    $bsources = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $backup_path_base);
    181181} elsif ($stage eq "diff") {
    182182    my $name = $inverse ? "PPSUB.INVERSE" : "PPSUB.OUTPUT"; # Base name for images
     
    184184    $mask   = $ipprc->filename("$name.MASK", $path_base);
    185185    $weight = $ipprc->filename("$name.VARIANCE", $path_base);
     186    $sources = $ipprc->filename("PPSUB.OUTPUT.SOURCES", $path_base);
    186187    $bimage  = $ipprc->filename($name, $backup_path_base);
    187188    $bmask   = $ipprc->filename("$name.MASK", $backup_path_base);
    188189    $bweight = $ipprc->filename("$name.VARIANCE", $backup_path_base);
    189 }
    190 
    191 do_swap($image, $bimage) or
     190    $bsources = $ipprc->filename("PPSUB.OUTPUT.SOURCES", $backup_path_base);
     191}
     192
     193if ($image) {
     194    revert_file($image, $bimage) or
    192195        &my_die("failed to restore image file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
     196}
     197
    193198if ($mask) {
    194     my $swap_result = do_swap($mask, $bmask);
    195     if (! $swap_result) {
    196         # delete next 5 lines
    197         if ($stage eq "chip") {
    198             # XXX: this is a kludge to get around my test environment
    199             # Don't commit
    200             print STDERR "failed to resotre camera mask file, proceeding\n";
     199    if (!revert_file($mask, $bmask)) {
     200        if ($stage eq 'chip') {
     201            # don't fail if the mask file (from the camera stage) fails to revert.
     202            # It probably doesn't exist
     203            # XXX: Handle this properly
     204            print STDERR "failure to revert mask file, ignored\n";
    201205        } else {
    202         &my_die("failed to restore mask file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
    203         }  # delete this line
    204     }
    205 }
     206            &my_die("failed to restore mask file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
     207        }
     208    }
     209}
     210
    206211if ($ch_mask) {
    207     do_swap($ch_mask, $bch_mask) or
    208         &my_die("failed to restore chip mask", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
     212    if (!revert_file($ch_mask, $bch_mask)) {
     213        &my_die("failed to restore chip mask file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
     214    }
    209215}
     216
     217
    210218if ($weight) {
    211     do_swap($weight, $bweight) or
     219    revert_file($weight, $bweight) or
    212220        &my_die("failed to restore variance image", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
    213221}
    214222
    215 # now reverse the desreaked file
    216 # Change magicdstool to set the magicked value to zero
    217 # Actually we should probably do this first to insure that no data gets deleted
    218 # Input result into database
    219 if (0) {
    220     # XXX: this is the wrong mode
    221     my $command = "$magicdstool -adddestreakedfile";
     223if ($sources) {
     224    revert_file($sources, $bsources) or
     225        &my_die("failed to restore sources file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
     226}
     227
     228if ($astrom) {
     229    revert_file($astrom, $bastrom) or
     230        &my_die("failed to restore astrometry file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
     231}
     232
     233# now revert the row in the database
     234{
     235    my $command = "$magicdstool -revertdestreakedfile";
    222236    $command   .= " -magic_ds_id $magic_ds_id";
    223237    $command   .= " -component $component";
    224     $command   .= " -setmagicked" if $replace;
    225     $command   .= " -backup_path_base $backup_path_base" if $backup_path_base;
    226     $command   .= " -recovery_path_base $recovery_path_base" if $recovery_path_base;
    227238    $command   .= " -dbname $dbname" if defined $dbname;
    228239
     
    242253
    243254
    244 
    245255### Pau.
    246256
     
    256266}
    257267
    258 sub do_swap
     268sub revert_file
    259269{
    260270    my $original = shift;
     
    297307        if ($b_path and -e $b_path) {
    298308            print "ready to delete backup\n" if $verbose;
    299             if (! $nebulous->delete($backup)) {
     309            if (! $ipprc->file_delete($backup)) {
    300310                print "failed to delete $backup\n";
    301311                return 0;
     
    307317        # delete the 'backup' (destreaked target) file if it exists
    308318        if ($b_path and -e $b_path) {
    309             if (! $nebulous->delete($backup)) {
     319            if (! $ipprc->file_delete($backup)) {
    310320                print "failed to delete $backup\n";
    311321                return 0;
     
    348358    $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code;
    349359
    350     my $command = "$magicdstool -adddestreakedfile";
    351     $command   .= " -magic_ds_id $magic_ds_id";
    352     $command   .= " -component $component";
    353     $command   .= " -fault $exit_code";
    354     $command   .= " -dbname $dbname" if defined $dbname;
    355 
    356     # Add the processed file to the database
    357     unless ($no_update) {
    358         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    359             run(command => $command, verbose => $verbose);
    360         unless ($success) {
    361             carp("failed to update database for $magic_ds_id $component");
    362         }
    363     } else {
    364         print "Skipping command: $command\n";
    365     }
     360    # we wouldn't be here unless an entry already exists in the database
     361#    my $command = "$magicdstool -adddestreakedfile";
     362#    $command   .= " -magic_ds_id $magic_ds_id";
     363#    $command   .= " -component $component";
     364#    $command   .= " -fault $exit_code";
     365#    $command   .= " -dbname $dbname" if defined $dbname;
     366
     367#    # Add the processed file to the database
     368#    unless ($no_update) {
     369#        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     370#            run(command => $command, verbose => $verbose);
     371#        unless ($success) {
     372#            carp("failed to update database for $magic_ds_id $component");
     373#        }
     374#    } else {
     375#        print "Skipping command: $command\n";
     376#    }
    366377
    367378    carp($msg);
Note: See TracChangeset for help on using the changeset viewer.