IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13275


Ignore:
Timestamp:
May 4, 2007, 4:52:03 PM (19 years ago)
Author:
Paul Price
Message:

Major upgrade to allow use of Nebulous

Location:
trunk/ippScripts/scripts
Files:
18 edited

Legend:

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

    r13090 r13275  
    1717use PS::IPP::Metadata::List qw( parse_md_list );
    1818use Statistics::Descriptive;
    19 
    20 use PS::IPP::Config qw(
    21     $PS_EXIT_SUCCESS
    22     $PS_EXIT_UNKNOWN_ERROR
    23     $PS_EXIT_SYS_ERROR
    24     $PS_EXIT_CONFIG_ERROR
    25     $PS_EXIT_PROG_ERROR
    26     $PS_EXIT_DATA_ERROR
    27     $PS_EXIT_TIMEOUT_ERROR
    28     );
     19use File::Temp qw( tempfile );
     20
     21use PS::IPP::Config qw($PS_EXIT_SUCCESS
     22                       $PS_EXIT_UNKNOWN_ERROR
     23                       $PS_EXIT_SYS_ERROR
     24                       $PS_EXIT_CONFIG_ERROR
     25                       $PS_EXIT_PROG_ERROR
     26                       $PS_EXIT_DATA_ERROR
     27                       $PS_EXIT_TIMEOUT_ERROR
     28                       caturi
     29                       );
    2930my $ipprc = PS::IPP::Config->new(); # IPP configuration
    30 use File::Spec;
    3131
    3232use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    125125}
    126126
    127 # Set output directory
    128 if (defined $workdir) {
    129     $workdir = $ipprc->convert_filename_absolute( $workdir );
    130     $workdir = File::Spec->catdir( $workdir, $exp_id );
    131 } else {
    132     my $example = $ipprc->convert_filename_absolute( ${$files}[0]->{path_base}) ; # Example original name
    133     my ($vol, $dir, $file) = File::Spec->splitpath( $example );
    134     $workdir = $dir;
    135 }
    136 system "mkdir -p $workdir" unless -d $workdir;
    137 
    138 # Generate the file list, and get the statistics
    139 my $outputFile =  "$exp_id.cam$cam_id";
    140 my $outputRoot = File::Spec->catfile( $workdir, $outputFile );
    141 
    142 my $list1Name = $outputRoot . '.b1.list'; # Name for the input file list for binning 1
    143 my $list2Name = $outputRoot . '.b2.list'; # Name for the input file list for binning 2
    144 my $list3Name = $outputRoot . '.b3.list'; # Name for the input file list for chip astrometry
     127my ($list1File, $list1Name) = tempfile( "$exp_id.cam$cam_id.b1.list.XXXX", UNLINK => 1 ); # For binning 1
     128my ($list2File, $list2Name) = tempfile( "$exp_id.cam$cam_id.b2.list.XXXX", UNLINK => 1 ); # For binning 2
     129my ($list3File, $list3Name) = tempfile( "$exp_id.cam$cam_id.b3.list.XXXX", UNLINK => 1 ); # For astrometry
    145130
    146131my @means;                      # Array of means
    147132my @stdevs;                     # Array of stdevs
    148 open my $list1File, '>' . $list1Name;
    149 open my $list2File, '>' . $list2Name;
    150 open my $list3File, '>' . $list3Name;
    151 
    152 print "$list1Name $list2Name $list3Name\n";
    153 
    154133my $chipObjects;
    155134foreach my $file (@$files) {
    156135    # use the path_base as OUTPUT root and convert the filenames with ipprc->filename:
    157136    my $class_id = $file->{class_id};
    158     my $origRoot = $ipprc->convert_filename_absolute( $file->{path_base} ); # Original root name
    159 
    160     # if there is only one chip, we use this name for the input to addstar
    161     $chipObjects = $ipprc->filename("PSASTRO.OUTPUT", $origRoot, $class_id);
    162     print $list1File $ipprc->filename("PPIMAGE.BIN1", $origRoot, $class_id);
    163     print $list2File $ipprc->filename("PPIMAGE.BIN2", $origRoot, $class_id);
     137
     138    # If there is only one chip, we use this name for the input to addstar
     139    $chipObjects = $ipprc->filename("PSASTRO.OUTPUT", $file->{path_base}, $class_id);
     140    print $list1File $ipprc->filename("PPIMAGE.BIN1", $file->{path_base}, $class_id);
     141    print $list2File $ipprc->filename("PPIMAGE.BIN2", $file->{path_base}, $class_id);
    164142    print $list3File $chipObjects;
    165143    push @means, $file->{bg};
     
    170148close $list3File;
    171149
    172 # Output products --- need to synch with the camera configuration!
     150# Output products
     151$workdir = caturi( $workdir, $exp_id ) if defined $workdir;
     152my $outputRoot = $ipprc->file_prepare( "$exp_id.cam$cam_id", $workdir, ${$files}[0]->{path_base} );
    173153my $jpeg1 = $ipprc->filename("PPIMAGE.JPEG1", $outputRoot); # Binned JPEG #1
    174154my $jpeg2 = $ipprc->filename("PPIMAGE.JPEG2", $outputRoot); # Binned JPEG #2
    175155my $fpaObjects = $ipprc->filename("PSASTRO.OUTPUT", $outputRoot); # MEF psastro output
    176 # my $dvo_camera = $ipprc->dvocamera();
    177156
    178157unless ($no_op) {
     
    188167            &my_die("Unable to perform psastro: $error_code", $cam_id, $error_code);
    189168        }
    190         &my_die("Unable to find expected output file: $fpaObjects", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $fpaObjects;
    191169    } else {
    192         system "cp $chipObjects $fpaObjects";
    193     }
     170        $ipprc->file_copy($chipObjects, $fpaObjects);
     171    }
     172    &my_die("Unable to find expected output file: $fpaObjects", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($fpaObjects);
    194173
    195174    # run addstar on either the single chip output or the single fpa output
     
    197176    # XXX which in turn points at ippconfig/dvo.site
    198177    {
    199         my $command = "addstar -D CAMERA $camera $fpaObjects";
     178        my $command = "addstar -D CAMERA $camera " . $ipprc->file_resolve($fpaObjects);
    200179        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    201180            run(command => $command, verbose => 1);
     
    215194            &my_die("Unable to perform ppImage: $error_code", $cam_id, $error_code);
    216195        }
    217         &my_die("Unable to find expected output file: $jpeg1", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $jpeg1;
     196        &my_die("Unable to find expected output file: $jpeg1", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($jpeg1);
    218197    }
    219198
     
    227206            &my_die("Unable to perform ppImage: $error_code", $cam_id, $error_code);
    228207        }
    229         &my_die("Unable to find expected output file: $jpeg2", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $jpeg2;
    230     }
    231 }
    232 
    233 # XXX keep the same outroot as the input
     208        &my_die("Unable to find expected output file: $jpeg2", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($jpeg2);
     209    }
     210}
     211
    234212# Add the result into the database
    235 $outputRoot = $ipprc->convert_filename_relative( $outputRoot );
    236 
    237213unless ($no_update) {
    238214    my $command = "$camtool -addprocessedexp -cam_id $cam_id -uri UNKNOWN -path_base $outputRoot " .
     
    247223        exit($error_code);
    248224    }
    249 
    250     unlink $list1Name;
    251     unlink $list2Name;
    252225}
    253226
  • trunk/ippScripts/scripts/chip_imfile.pl

    r13129 r13275  
    1414use PS::IPP::Metadata::Stats;
    1515use Data::Dumper;
    16 use PS::IPP::Config qw(
    17     $PS_EXIT_SUCCESS
    18     $PS_EXIT_UNKNOWN_ERROR
    19     $PS_EXIT_SYS_ERROR
    20     $PS_EXIT_CONFIG_ERROR
    21     $PS_EXIT_PROG_ERROR
    22     $PS_EXIT_DATA_ERROR
    23     $PS_EXIT_TIMEOUT_ERROR
    24     );
     16use PS::IPP::Config qw($PS_EXIT_SUCCESS
     17                       $PS_EXIT_UNKNOWN_ERROR
     18                       $PS_EXIT_SYS_ERROR
     19                       $PS_EXIT_CONFIG_ERROR
     20                       $PS_EXIT_PROG_ERROR
     21                       $PS_EXIT_DATA_ERROR
     22                       $PS_EXIT_TIMEOUT_ERROR
     23                       caturi
     24                       );
    2525my $ipprc = PS::IPP::Config->new(); # IPP configuration
    26 use File::Spec;
    2726
    2827use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    7877$ppImage .= " -dbname $dbname" if defined $dbname;
    7978
    80 $input = $ipprc->convert_filename_absolute( $input );
    8179
    82 # Set output directory
    83 if (defined $workdir) {
    84     $workdir = $ipprc->convert_filename_absolute( $workdir );
    85     $workdir = File::Spec->catdir( $workdir, $exp_id );
    86 } else {
    87     my ($vol, $dir, $file) = File::Spec->splitpath( $input );
    88     $workdir = $dir;
    89 }
    90 system "mkdir -p $workdir" unless -d $workdir;
     80$workdir = caturi( $workdir, $exp_id ) if defined $workdir;
    9181
    92 ### Output file name --- must match camera configuration!
    93 my $outputFile =  "$exp_id.chp$chip_id";
    94 my $outputRoot = File::Spec->catfile( $workdir, $outputFile );
     82my $outputRoot = $ipprc->file_prepare( "$exp_id.chp$chip_id", $workdir, $input );
    9583my $outputImage = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id);
    9684my $outputBin1 = $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $class_id);
     
    10492    print "outputBin1: $outputBin1\n";
    10593    print "outputStats: $outputStats\n";
    106    
     94
    10795    my $command = "$ppImage -file $input $outputRoot -recipe PPIMAGE " . RECIPE .
    10896        " -stat $outputStats"; # Command to run ppImage
     
    113101        &my_die("Unable to perform ppImage: $error_code", $chip_id, $class_id, $error_code);
    114102    }
    115     &my_die("Couldn't find expected output file: $outputImage\n", $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputImage;
    116     &my_die("Couldn't find expected output file: $outputBin1\n", $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputBin1;
    117     &my_die("Couldn't find expected output file: $outputBin2\n", $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputBin2;
    118     &my_die("Couldn't find expected output file: $outputStats\n", $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputStats;
     103    &my_die("Couldn't find expected output file: $outputImage\n", $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputImage);
     104    &my_die("Couldn't find expected output file: $outputBin1\n", $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputBin1);
     105    &my_die("Couldn't find expected output file: $outputBin2\n", $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputBin2);
     106    &my_die("Couldn't find expected output file: $outputStats\n", $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputStats);
    119107
    120108    # Get the statistics on the processed image
    121109    my $statsFile;              # File handle
    122     open $statsFile, $outputStats or &my_die("Can't open statistics file $outputStats: $!", $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     110    open $statsFile, $ipprc->file_resolve($outputStats) or &my_die("Can't open statistics file $outputStats: $!", $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
    123111    my @contents = <$statsFile>; # Contents of file
    124112    close $statsFile;
     
    131119
    132120# Add the processed file to the database
    133 $outputImage = $ipprc->convert_filename_relative( $outputImage);
    134 $outputRoot  = $ipprc->convert_filename_relative( $outputRoot );
    135 
    136121my $bg = ($stats->bg_mean() or 'NAN');
    137122my $bg_stdev = ($stats->bg_stdev() or 'NAN');
     
    155140        exit($error_code);
    156141    }
    157 
    158     unlink $outputStats;
    159142}
    160143
  • trunk/ippScripts/scripts/detrend_norm_apply.pl

    r12800 r13275  
    1414use Data::Dumper;
    1515
    16 use PS::IPP::Config qw(
    17     $PS_EXIT_SUCCESS
    18     $PS_EXIT_UNKNOWN_ERROR
    19     $PS_EXIT_SYS_ERROR
    20     $PS_EXIT_CONFIG_ERROR
    21     $PS_EXIT_PROG_ERROR
    22     $PS_EXIT_DATA_ERROR
    23     $PS_EXIT_TIMEOUT_ERROR
    24     );
     16use PS::IPP::Config qw($PS_EXIT_SUCCESS
     17                       $PS_EXIT_UNKNOWN_ERROR
     18                       $PS_EXIT_SYS_ERROR
     19                       $PS_EXIT_CONFIG_ERROR
     20                       $PS_EXIT_PROG_ERROR
     21                       $PS_EXIT_DATA_ERROR
     22                       $PS_EXIT_TIMEOUT_ERROR
     23                       caturi
     24                       );
    2525my $ipprc = PS::IPP::Config->new(); # IPP configuration
    26 use File::Spec;
    2726
    2827use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    8281}
    8382
    84 $input = $ipprc->convert_filename_absolute( $input );
     83$workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
    8584
    86 # Set output directory
    87 if (defined $workdir) {
    88     $workdir = $ipprc->convert_filename_absolute( $workdir );
    89     my $subdir = "$camera.$det_type.$det_id";
    90     $workdir = File::Spec->catdir( $workdir, $subdir );
    91 } else {
    92     my ($vol, $dir, $file) = File::Spec->splitpath( $input );
    93     $workdir = $dir;
    94 }
    95 system "mkdir -p $workdir" unless -d $workdir;
    96 
    97 # Output name
    98 my $outputFile = "$camera.$det_type.norm.$det_id.$iter"; # Root name
    99 my $outputRoot = File::Spec->catfile( $workdir, $outputFile );
    100 
     85my $outputRoot = $ipprc->file_prepare( "$camera.$det_type.norm.$det_id.$iter", $workdir, $input );
    10186my $output = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id);
    10287my $b1name = $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $class_id);
    10388my $b2name = $ipprc->filename("PPIMAGE.BIN2", $outputRoot, $class_id);
    104 
    10589my $statsName = $outputRoot . '.' . $class_id . '.stats'; # Statistics file
    10690
     
    116100        &my_die("Unable to perform ppImage: $error_code", $det_id, $iter, $class_id, $error_code);
    117101    }
    118     &my_die("Can't find expected output file: $output", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -e $output;
    119     &my_die("Can't find expected output file: $b1name", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -e $b1name;
    120     &my_die("Can't find expected output file: $b2name", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -e $b2name;
    121     &my_die("Can't find expected output file: $statsName", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -e $statsName;
     102    &my_die("Can't find expected output file: $output", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($output);
     103    &my_die("Can't find expected output file: $b1name", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($b1name);
     104    &my_die("Can't find expected output file: $b2name", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($b2name);
     105    &my_die("Can't find expected output file: $statsName", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($statsName);
    122106   
    123107    # Get the statistics on the normalised image
    124     my $statsFile;              # File handle
    125     open $statsFile, $statsName or &my_die("Can't open statistics file $statsName: $!\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR);
     108    my $statsFile; # File handle
     109    open $statsFile, $ipprc->file_resolve($statsName) or &my_die("Can't open statistics file $statsName: $!\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR);
     110    &my_die("Can't open statistics file $statsName: $!\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless defined $statsFile;
    126111    my @contents = <$statsFile>; # Contents of file
    127112    close $statsFile;
     
    130115        or &my_die("Unable to parse metadata config", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
    131116    $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
    132 }   
     117}
    133118
    134119# Update the database
    135 $output = $ipprc->convert_filename_relative( $output );
    136 $outputRoot = $ipprc->convert_filename_relative( $outputRoot );
    137 
    138120my $bg = ($stats->bg_mean() or 'NAN');
    139121my $bg_stdev = ($stats->bg_stdev() or 'NAN');
     
    153135        exit($error_code);
    154136    }
    155 
    156     unlink $statsName;
    157137}
    158138
  • trunk/ippScripts/scripts/detrend_norm_exp.pl

    r12800 r13275  
    1717use PS::IPP::Metadata::List qw( parse_md_list );
    1818use Statistics::Descriptive;
     19use File::Temp qw( tempfile );
    1920
    20 use PS::IPP::Config qw(
    21     $PS_EXIT_SUCCESS
    22     $PS_EXIT_UNKNOWN_ERROR
    23     $PS_EXIT_SYS_ERROR
    24     $PS_EXIT_CONFIG_ERROR
    25     $PS_EXIT_PROG_ERROR
    26     $PS_EXIT_DATA_ERROR
    27     $PS_EXIT_TIMEOUT_ERROR
    28     );
     21use PS::IPP::Config qw($PS_EXIT_SUCCESS
     22                       $PS_EXIT_UNKNOWN_ERROR
     23                       $PS_EXIT_SYS_ERROR
     24                       $PS_EXIT_CONFIG_ERROR
     25                       $PS_EXIT_PROG_ERROR
     26                       $PS_EXIT_DATA_ERROR
     27                       $PS_EXIT_TIMEOUT_ERROR
     28                       caturi
     29                       );
    2930my $ipprc = PS::IPP::Config->new(); # IPP configuration
    30 use File::Spec;
    3131
    3232use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    115115}
    116116
    117 # Set output directory
    118 if (defined $workdir) {
    119     $workdir = $ipprc->convert_filename_absolute( $workdir );
    120     my $subdir = "$camera.$det_type.$det_id";
    121     $workdir = File::Spec->catdir( $workdir, $subdir );
    122 } else {
    123     my $example = $ipprc->convert_filename_absolute( ${$files}[0]->{path_base} ); # Example file, for path
    124     my ($vol, $dir, $file) = File::Spec->splitpath( $example );
    125     $workdir = $dir;
    126 }
    127 system "mkdir -p $workdir" unless -d $workdir;
    128 
    129 # Generate the file list, and get the statistics
    130 my $outputFile = "$camera.$det_type.norm.$det_id.$iter"; # Root output name
    131 my $outputRoot = File::Spec->catfile( $workdir, $outputFile );
    132 
    133 my $list1Name = $outputRoot . '.b1.list'; # Name for the input file list for binning 1
    134 my $list2Name = $outputRoot . '.b2.list'; # Name for the input file list for binning 2
     117my ($list1File, $list1Name) = tempfile( "$camera.$det_type.norm.$det_id.$iter.b1.list.XXXX", UNLINK => 1 );
     118my ($list2File, $list2Name) = tempfile( "$camera.$det_type.norm.$det_id.$iter.b2.list.XXXX", UNLINK => 1 );
    135119my @means;                      # Array of means
    136120my @stdevs;                     # Array of stdevs
    137 open my $list1File, '>' . $list1Name;
    138 open my $list2File, '>' . $list2Name;
    139121foreach my $file (@$files) {
    140     my $origRoot = $ipprc->convert_filename_absolute( $file->{path_base} ); # Original root name
    141     print $list1File ( $ipprc->filename( "PPIMAGE.BIN1", $origRoot, $file->{class_id} ) . "\n");
    142     print $list2File ( $ipprc->filename( "PPIMAGE.BIN2", $origRoot, $file->{class_id} ) . "\n");
     122    print $list1File ( $ipprc->filename( "PPIMAGE.BIN1", $file->{path_base}, $file->{class_id} ) . "\n");
     123    print $list2File ( $ipprc->filename( "PPIMAGE.BIN2", $file->{path_base}, $file->{class_id} ) . "\n");
    143124    push @means, $file->{bg};
    144125    push @stdevs, $file->{bg_stdev};
     
    148129
    149130# Output products
     131$workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
     132my $outputRoot = $ipprc->file_prepare( "$camera.$det_type.norm.$det_id.$iter", $workdir );
    150133my $jpeg1Name = $ipprc->filename("PPIMAGE.JPEG1", $outputRoot); # Binned JPEG #1
    151134my $jpeg2Name = $ipprc->filename("PPIMAGE.JPEG2", $outputRoot); # Binned JPEG #2
     
    157140        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    158141            run(command => $command, verbose => 1);
    159         &my_die("Unable to find expected output file: $jpeg1Name", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless -f $jpeg1Name;
     142        &my_die("Unable to find expected output file: $jpeg1Name", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg1Name);
    160143    }
    161144   
     
    165148        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    166149            run(command => $command, verbose => 1);
    167         &my_die("Unable to find expected output file: $jpeg2Name", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless -f $jpeg2Name;
     150        &my_die("Unable to find expected output file: $jpeg2Name", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg2Name);
    168151    }
    169152}
    170 
    171 # Add the result into the database
    172 $outputRoot = $ipprc->convert_filename_relative( $outputRoot );
    173153
    174154unless ($no_update) {
     
    183163        &my_die("Unable to perform dettool -addnormalizedexp: $error_code", $det_id, $iter, $error_code);
    184164    }
    185 
    186     unlink $list1Name;
    187     unlink $list2Name;
    188165}
    189166
  • trunk/ippScripts/scripts/detrend_process_exp.pl

    r12800 r13275  
    1818use Statistics::Descriptive;
    1919
    20 use PS::IPP::Config qw(
    21     $PS_EXIT_SUCCESS
    22     $PS_EXIT_UNKNOWN_ERROR
    23     $PS_EXIT_SYS_ERROR
    24     $PS_EXIT_CONFIG_ERROR
    25     $PS_EXIT_PROG_ERROR
    26     $PS_EXIT_DATA_ERROR
    27     $PS_EXIT_TIMEOUT_ERROR
    28     );
     20use PS::IPP::Config qw($PS_EXIT_SUCCESS
     21                       $PS_EXIT_UNKNOWN_ERROR
     22                       $PS_EXIT_SYS_ERROR
     23                       $PS_EXIT_CONFIG_ERROR
     24                       $PS_EXIT_PROG_ERROR
     25                       $PS_EXIT_DATA_ERROR
     26                       $PS_EXIT_TIMEOUT_ERROR
     27                       caturi
     28                       );
    2929my $ipprc = PS::IPP::Config->new(); # IPP configuration
    30 use File::Spec;
     30use File::Temp qw( tempfile );
    3131
    3232use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    115115}
    116116
    117 # Set output directory
    118 if (defined $workdir) {
    119     $workdir = $ipprc->convert_filename_absolute( $workdir );
    120     my $subdir = "$camera.$det_type.$det_id";
    121     $workdir = File::Spec->catdir( $workdir, $subdir, $exp_tag );
    122 } else {
    123     my $example = $ipprc->convert_filename_absolute( ${$files}[0]->{path_base} ); # Example original name
    124     my ($vol, $dir, $file) = File::Spec->splitpath( $example );
    125     $workdir = $dir;
    126 }
    127 system "mkdir -p $workdir" unless -d $workdir;
    128 
    129 my $outputFile = $exp_tag . '.detproc.' . $det_id; # Root name
    130 my $outputRoot = File::Spec->catfile( $workdir, $outputFile );
    131 
    132 # output files:
    133 my $list1Name = $outputRoot . '.b1.list'; # Name for the input file list for binning 1
    134 my $list2Name = $outputRoot . '.b2.list'; # Name for the input file list for binning 2
     117# File lists for the two binnings
     118my ($list1File, $list1Name) = tempfile( "$exp_tag.detproc.$det_id.b1.list.XXXX", UNLINK => 1 );
     119my ($list2File, $list2Name) = tempfile( "$exp_tag.detproc.$det_id.b2.list.XXXX", UNLINK => 1 );
    135120my @means;                      # Array of means
    136121my @stdevs;                     # Array of stdevs
    137 open my $list1File, '>' . $list1Name;
    138 open my $list2File, '>' . $list2Name;
    139122foreach my $file (@$files) {
    140     my $origRoot = $ipprc->convert_filename_absolute( $file->{path_base} ); # Original root name
    141     print $list1File ($ipprc->filename( "PPIMAGE.BIN1", $origRoot, $file->{class_id} ) . "\n");
    142     print $list2File ($ipprc->filename( "PPIMAGE.BIN2", $origRoot, $file->{class_id} ) . "\n");
     123    print $list1File ($ipprc->filename( "PPIMAGE.BIN1", $file->{path_base}, $file->{class_id} ) . "\n");
     124    print $list2File ($ipprc->filename( "PPIMAGE.BIN2", $file->{path_base}, $file->{class_id} ) . "\n");
    143125    push @means, $file->{bg};
    144126    push @stdevs, $file->{bg_stdev};
     
    147129close $list2File;
    148130
    149 # Output products
     131# Output files
     132$workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
     133my $outputRoot = $ipprc->file_prepare( "$exp_tag.detproc.$det_id", $workdir, ${$files}[0]->{path_base} );
    150134my $jpeg1 = $ipprc->filename("PPIMAGE.JPEG1", $outputRoot); # Binned JPEG #1
    151135my $jpeg2 = $ipprc->filename("PPIMAGE.JPEG2", $outputRoot); # Binned JPEG #2
     
    161145            &my_die("Unable to perform ppImage: $error_code", $det_id, $exp_tag, $error_code);
    162146        }
    163         &my_die("Unable to find expected output file: $jpeg1", $det_id, $exp_tag, $PS_EXIT_SYS_ERROR) unless -f $jpeg1;
     147        &my_die("Unable to find expected output file: $jpeg1", $det_id, $exp_tag, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg1);
    164148    }
    165149   
     
    173157            &my_die("Unable to perform ppImage: $error_code", $det_id, $exp_tag, $error_code);
    174158        }
    175         &my_die("Unable to find expected output file: $jpeg2", $det_id, $exp_tag, $PS_EXIT_SYS_ERROR) unless -f $jpeg2;
    176     }
    177 }
    178 
    179 # Add the result into the database
    180 $outputRoot = $ipprc->convert_filename_relative( $outputRoot );
     159        &my_die("Unable to find expected output file: $jpeg2", $det_id, $exp_tag, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg2);
     160    }
     161}
    181162
    182163unless ($no_update) {
     
    192173        exit($error_code);
    193174    }
    194 
    195     unlink $list1Name;
    196     unlink $list2Name;
    197175}
    198176
  • trunk/ippScripts/scripts/detrend_process_imfile.pl

    r12800 r13275  
    1717use PS::IPP::Metadata::Stats;
    1818
    19 use PS::IPP::Config qw(
    20     $PS_EXIT_SUCCESS
    21     $PS_EXIT_UNKNOWN_ERROR
    22     $PS_EXIT_SYS_ERROR
    23     $PS_EXIT_CONFIG_ERROR
    24     $PS_EXIT_PROG_ERROR
    25     $PS_EXIT_DATA_ERROR
    26     $PS_EXIT_TIMEOUT_ERROR
    27     );
     19use PS::IPP::Config qw($PS_EXIT_SUCCESS
     20                       $PS_EXIT_UNKNOWN_ERROR
     21                       $PS_EXIT_SYS_ERROR
     22                       $PS_EXIT_CONFIG_ERROR
     23                       $PS_EXIT_PROG_ERROR
     24                       $PS_EXIT_DATA_ERROR
     25                       $PS_EXIT_TIMEOUT_ERROR
     26                       caturi
     27                       );
    2828my $ipprc = PS::IPP::Config->new(); # IPP configuration
    29 use File::Spec;
    3029
    3130use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    8887}
    8988
    90 $input_uri = $ipprc->convert_filename_absolute( $input_uri );
     89$workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
    9190
    92 # Set output directory
    93 if (defined $workdir) {
    94     $workdir = $ipprc->convert_filename_absolute( $workdir );
    95     my $subdir = "$camera.$det_type.$det_id";
    96     $workdir = File::Spec->catdir( $workdir, $subdir, $exp_tag );
    97 } else {
    98     my ($vol, $dir, $file) = File::Spec->splitpath( $input_uri );
    99     $workdir = $dir;
    100 }
    101 system "mkdir -p $workdir" unless -d $workdir;
    102 
    103 # Output files
    104 my $outputFile = "$exp_tag.detproc.$det_id"; # Root name
    105 my $outputRoot = File::Spec->catfile( $workdir, $outputFile );
     91my $outputRoot = $ipprc->file_prepare( "$exp_tag.detproc.$det_id", $workdir, $input_uri );
    10692my $outputImage = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id);
    10793my $outputBin1 = $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $class_id);
     
    120106        &my_die("Unable to perform ppImage: $error_code", $det_id, $exp_tag, $class_id, $error_code);
    121107    }
    122     &my_die("Couldn't find expected output file: $outputImage", $det_id, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputImage;
    123     &my_die("Couldn't find expected output file: $outputStats", $det_id, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputStats;
    124     &my_die("Couldn't find expected output file: $outputBin1", $det_id, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputBin1;
    125     &my_die("Couldn't find expected output file: $outputBin2", $det_id, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputBin2;
     108    &my_die("Couldn't find expected output file: $outputImage", $det_id, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputImage);
     109    &my_die("Couldn't find expected output file: $outputStats", $det_id, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputStats);
     110    &my_die("Couldn't find expected output file: $outputBin1", $det_id, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputBin1);
     111    &my_die("Couldn't find expected output file: $outputBin2", $det_id, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputBin2);
    126112
    127113    # Get the statistics on the processed image
    128114    my $statsFile;              # File handle
    129     open $statsFile, "$outputStats" or die "Can't open statistics file $outputStats: $!\n";
     115    open $statsFile, $ipprc->file_resolve("$outputStats") or die "Can't open statistics file $outputStats: $!\n";
    130116    my @contents = <$statsFile>; # Contents of file
    131117    close $statsFile;
     
    135121    $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
    136122}
    137 
    138 # Take off the absolute path, to stuff into the database
    139 $outputImage = $ipprc->convert_filename_relative( $outputImage );
    140 $outputRoot = $ipprc->convert_filename_relative( $outputRoot );
    141123
    142124my $bg = ($stats->bg_mean() or 'NAN');
     
    158140        exit($error_code);
    159141    }
    160 
    161     unlink $outputStats;
    162142}
    163143
  • trunk/ippScripts/scripts/detrend_reject_exp.pl

    r12800 r13275  
    1717use PS::IPP::Metadata::List qw( parse_md_list );
    1818use Statistics::Descriptive;
    19 use File::Spec;
    20 
    21 use PS::IPP::Config qw(
    22     $PS_EXIT_SUCCESS
    23     $PS_EXIT_UNKNOWN_ERROR
    24     $PS_EXIT_SYS_ERROR
    25     $PS_EXIT_CONFIG_ERROR
    26     $PS_EXIT_PROG_ERROR
    27     $PS_EXIT_DATA_ERROR
    28     $PS_EXIT_TIMEOUT_ERROR
    29     );
     19
     20use PS::IPP::Config qw($PS_EXIT_SUCCESS
     21                       $PS_EXIT_UNKNOWN_ERROR
     22                       $PS_EXIT_SYS_ERROR
     23                       $PS_EXIT_CONFIG_ERROR
     24                       $PS_EXIT_PROG_ERROR
     25                       $PS_EXIT_DATA_ERROR
     26                       $PS_EXIT_TIMEOUT_ERROR
     27                       caturi
     28                       );
    3029my $ipprc = PS::IPP::Config->new(); # IPP configuration
    3130
     
    122121my $reject_meanstdev = rejection_limit( 'ENSEMBLE.MEANSTDEV', $det_type, $filter );
    123122
    124 my $logName = "$camera.$det_type.$det_id.$iter.detreject.log"; # Name for log
    125 if (defined $workdir) {
    126     $workdir = $ipprc->convert_filename_absolute( $workdir );
    127     my $subdir = "$camera.$det_type.$det_id";
    128     $workdir = File::Spec->catdir( $workdir, $subdir );
    129     system "mkdir -p $workdir" unless -d $workdir;
    130     $logName = File::Spec->catfile( $workdir, $logName );
    131 }
     123$workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
     124
     125my $logName = $ipprc->file_prepare( "$camera.$det_type.$det_id.$iter.detreject.log", $workdir ); # Name for log
     126
    132127my $logFile;
    133128unless ($no_op) {
    134     open $logFile, "> $logName" or &my_die("Unable to open log file $logName.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR);
     129    $logFile = $ipprc->file_create_open( $logName );
    135130    print $logFile "Ensemble mean " . $meanStats->mean() . " +/- " . $meanStats->standard_deviation .
    136131        ", stdev " . $stdevStats->mean() . " +/- " . $stdevStats->standard_deviation() . "\n\n";
  • trunk/ippScripts/scripts/detrend_reject_imfile.pl

    r12979 r13275  
    1717use PS::IPP::Metadata::List qw( parse_md_list );
    1818use Statistics::Descriptive;
    19 
    20 use PS::IPP::Config qw(
    21     $PS_EXIT_SUCCESS
    22     $PS_EXIT_UNKNOWN_ERROR
    23     $PS_EXIT_SYS_ERROR
    24     $PS_EXIT_CONFIG_ERROR
    25     $PS_EXIT_PROG_ERROR
    26     $PS_EXIT_DATA_ERROR
    27     $PS_EXIT_TIMEOUT_ERROR
    28     );
     19use File::Temp qw( tempfile );
     20
     21use PS::IPP::Config qw($PS_EXIT_SUCCESS
     22                       $PS_EXIT_UNKNOWN_ERROR
     23                       $PS_EXIT_SYS_ERROR
     24                       $PS_EXIT_CONFIG_ERROR
     25                       $PS_EXIT_PROG_ERROR
     26                       $PS_EXIT_DATA_ERROR
     27                       $PS_EXIT_TIMEOUT_ERROR
     28                       caturi
     29                       );
    2930my $ipprc = PS::IPP::Config->new(); # IPP configuration
    30 use File::Spec;
    3131
    3232use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    9393}
    9494
    95 # Set output directory
    96 if (defined $workdir) {
    97     $workdir = $ipprc->convert_filename_absolute( $workdir );
    98     my $subdir = "$camera.$det_type.$det_id";
    99     $workdir = File::Spec->catdir( $workdir, $subdir, $exp_tag );
    100 } else {
    101     my $example = $ipprc->convert_filename_absolute( ${$files}[0]->{path_base} ); # Example original name
    102     my ($vol, $dir, $file) = File::Spec->splitpath( $example );
    103     $workdir = $dir;
    104 }
    105 system "mkdir -p $workdir" unless -d $workdir;
    106 
    107 # Generate the file list, and get the statistics
    108 my $outputFile = "$exp_tag.detresid.$det_id.$iter"; # Root name
    109 my $outputRoot = File::Spec->catfile( $workdir, $outputFile );
    110 
    111 my $list1Name = $outputRoot . '.b1.list'; # Name for the input file list for binning 1
    112 my $list2Name = $outputRoot . '.b2.list'; # Name for the input file list for binning 2
    113 
     95
     96my ($list1File, $list1Name) = tempfile( "$exp_tag.detresid.$det_id.$iter.b1.list.XXXX", UNLINK => 1 );
     97my ($list2File, $list2Name) = tempfile( "$exp_tag.detresid.$det_id.$iter.b2.list.XXXX", UNLINK => 1 );
    11498my @means;                      # Array of means
    11599my @variances;                  # Array of variances
    116100my @meanStdevs;                 # Array of mean stdevs
    117101my @names;                      # Array of names (class_id)
    118 open my $list1File, '>' . $list1Name;
    119 open my $list2File, '>' . $list2Name;
    120102foreach my $file (@$files) {
    121     my $origRoot = $ipprc->convert_filename_absolute( $file->{path_base} ); # Original root name
    122     print $list1File ($ipprc->filename( "PPIMAGE.BIN1", $origRoot, $file->{class_id} ) . "\n");
    123     print $list2File ($ipprc->filename( "PPIMAGE.BIN2", $origRoot, $file->{class_id} ) . "\n");
     103    print $list1File ($ipprc->filename( "PPIMAGE.BIN1", $file->{path_base}, $file->{class_id} ) . "\n");
     104    print $list2File ($ipprc->filename( "PPIMAGE.BIN2", $file->{path_base}, $file->{class_id} ) . "\n");
    124105    push @means, $file->{bg};
    125106    push @meanStdevs, $file->{bg_mean_stdev};
     
    131112close $list2File;
    132113
    133 # Output products --- need to synch with the camera configuration!
     114# Output products
     115$workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
     116my $outputRoot = $ipprc->file_prepare( "$exp_tag.detresid.$det_id.$iter", $workdir, ${$files}[0]->{path_base} );
    134117my $jpeg1Name = $ipprc->filename("PPIMAGE.JPEG1", $outputRoot); # Binned JPEG #1
    135118my $jpeg2Name = $ipprc->filename("PPIMAGE.JPEG2", $outputRoot); # Binned JPEG #2
     
    146129            &my_die("Unable to run ppImage: $error_code", $det_id, $iter, $exp_tag, $error_code);
    147130        }
    148         &my_die("Unable to find expected output file: $jpeg1Name", $det_id, $iter, $exp_tag, $PS_EXIT_SYS_ERROR) unless -f $jpeg1Name;
     131        &my_die("Unable to find expected output file: $jpeg1Name", $det_id, $iter, $exp_tag, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg1Name);
    149132    }
    150133   
     
    158141            &my_die("Unable to run ppImage: $error_code", $det_id, $iter, $exp_tag, $error_code);
    159142        }
    160         &my_die("Unable to find expected output file: $jpeg2Name", $det_id, $iter, $exp_tag, $PS_EXIT_SYS_ERROR) unless -f $jpeg2Name;
     143        &my_die("Unable to find expected output file: $jpeg2Name", $det_id, $iter, $exp_tag, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg2Name);
    161144    }
    162145}
     
    173156my $reject_exp_sn           = rejection_limit( 'EXP.SN',           $det_type, $filter );
    174157
    175 my $logName = "$exp_tag.detreject.$det_id.$iter.log"; # Name for log
    176 $logName = File::Spec->catfile( $workdir, $logName );
     158my $logName = caturi( $workdir, "$exp_tag.detreject.$det_id.$iter.log" ); # Name for log
    177159my $logFile;
    178160unless ($no_op) {
    179     open $logFile, "> $logName" or &my_die("Unable to open log file $logName", $det_id, $iter, $exp_tag, $PS_EXIT_SYS_ERROR);
     161    $logFile = $ipprc->file_create_open( $logName );
    180162}
    181163
     
    311293
    312294# Add the result into the database
    313 $outputRoot = $ipprc->convert_filename_relative( $outputRoot );
    314 
    315295my $bg = $mean;
    316296my $bg_stdev = $stdev;
     
    330310        exit($error_code);
    331311    }
    332 
    333     unlink $list1Name;
    334     unlink $list2Name;
    335312}
    336313
  • trunk/ippScripts/scripts/detrend_resid.pl

    r12800 r13275  
    1818use Data::Dumper;
    1919
    20 use PS::IPP::Config qw(
    21     $PS_EXIT_SUCCESS
    22     $PS_EXIT_UNKNOWN_ERROR
    23     $PS_EXIT_SYS_ERROR
    24     $PS_EXIT_CONFIG_ERROR
    25     $PS_EXIT_PROG_ERROR
    26     $PS_EXIT_DATA_ERROR
    27     $PS_EXIT_TIMEOUT_ERROR
    28     );
     20use PS::IPP::Config qw($PS_EXIT_SUCCESS
     21                       $PS_EXIT_UNKNOWN_ERROR
     22                       $PS_EXIT_SYS_ERROR
     23                       $PS_EXIT_CONFIG_ERROR
     24                       $PS_EXIT_PROG_ERROR
     25                       $PS_EXIT_DATA_ERROR
     26                       $PS_EXIT_TIMEOUT_ERROR
     27                       caturi
     28                       );
    2929my $ipprc = PS::IPP::Config->new(); # IPP configuration
    30 use File::Spec;
    3130
    3231use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    118117&my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR) unless defined $recipe;
    119118
    120 # Set output directory
    121 if (defined $workdir) {
    122     $workdir = $ipprc->convert_filename_absolute( $workdir );
    123     my $subdir = "$camera.$det_type.$det_id";
    124     $workdir = File::Spec->catdir( $workdir, $subdir, $exp_tag );
    125 } else {
    126     my ($vol, $dir, $file) = File::Spec->splitpath( $ipprc->convert_filename_absolute( $input_uri ) );
    127     $workdir = $dir;
    128 }
    129 system "mkdir -p $workdir" unless -d $workdir;
    130 
    131 my $outputFile = "$exp_tag.detresid.$det_id.$iter"; # Root name
    132 my $outputRoot = File::Spec->catfile( $workdir, $outputFile );
    133 
     119$workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
     120
     121my $outputRoot = $ipprc->file_prepare( "$exp_tag.detresid.$det_id.$iter", $workdir, $input_uri );
    134122my $outputName = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id);
    135123my $bin1Name =  $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $class_id);
    136124my $bin2Name =  $ipprc->filename("PPIMAGE.BIN2", $outputRoot, $class_id);
    137 
    138125my $outputStats = $outputRoot . '.' . $class_id . '.stats';
    139 
    140 $detrend = $ipprc->convert_filename_absolute( $detrend ) if defined $detrend;
    141 $input_uri = $ipprc->convert_filename_absolute( $input_uri );
    142126
    143127# Run ppImage
     
    160144        &my_die("Unable to perform ppImage: $error_code", $det_id, $iter, $exp_tag, $class_id, $error_code);
    161145    }
    162     &my_die("Couldn't find expected output file: $outputName", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputName;
    163     &my_die("Couldn't find expected output file: $outputStats", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputStats;
    164     &my_die("Couldn't find expected output file: $bin1Name", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $bin1Name;
    165     &my_die("Couldn't find expected output file: $bin2Name", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $bin2Name;
     146    &my_die("Couldn't find expected output file: $outputName", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputName);
     147    &my_die("Couldn't find expected output file: $outputStats", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputStats);
     148    &my_die("Couldn't find expected output file: $bin1Name", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($bin1Name);
     149    &my_die("Couldn't find expected output file: $bin2Name", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($bin2Name);
    166150
    167151    # Get the statistics on the residual image
    168152    my $statsFile;              # File handle
    169     open $statsFile, $outputStats or &my_die("Can't open statistics file $outputStats: $!", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR);
     153    open $statsFile, $ipprc->file_resolve($outputStats) or &my_die("Can't open statistics file $outputStats: $!", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR);
    170154    my @contents = <$statsFile>; # Contents of file
    171155    close $statsFile;
     
    178162
    179163# Add the processed file to the database
    180 $outputName = $ipprc->convert_filename_relative( $outputName );
    181 $outputRoot = $ipprc->convert_filename_relative( $outputRoot );
    182 
    183164my $bg = ($stats->bg_mean() or 'NAN');
    184165my $bg_stdev = ($stats->bg_stdev() or 'NAN');
     
    198179        exit($error_code);
    199180    }
    200 
    201     unlink $outputStats;   
    202181}
    203182
  • trunk/ippScripts/scripts/detrend_stack.pl

    r12800 r13275  
    1818use PS::IPP::Metadata::Stats;
    1919
    20 use PS::IPP::Config qw(
    21     $PS_EXIT_SUCCESS
    22     $PS_EXIT_UNKNOWN_ERROR
    23     $PS_EXIT_SYS_ERROR
    24     $PS_EXIT_CONFIG_ERROR
    25     $PS_EXIT_PROG_ERROR
    26     $PS_EXIT_DATA_ERROR
    27     $PS_EXIT_TIMEOUT_ERROR
    28     );
     20use PS::IPP::Config qw($PS_EXIT_SUCCESS
     21                       $PS_EXIT_UNKNOWN_ERROR
     22                       $PS_EXIT_SYS_ERROR
     23                       $PS_EXIT_CONFIG_ERROR
     24                       $PS_EXIT_PROG_ERROR
     25                       $PS_EXIT_DATA_ERROR
     26                       $PS_EXIT_TIMEOUT_ERROR
     27                       caturi
     28                       );
    2929my $ipprc = PS::IPP::Config->new(); # IPP configuration
    30 use File::Spec;
    3130
    3231use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    9897}
    9998
    100 # Set output directory
    101 if (defined $workdir) {
    102     $workdir = $ipprc->convert_filename_absolute( $workdir );
    103     my $subdir = "$camera.$det_type.$det_id";
    104     $workdir = File::Spec->catdir( $workdir, $subdir );
    105 } else {
    106     my $example = $ipprc->convert_filename_absolute( ${$files}[0]->{uri} ); # Example file
    107     my ($vol, $dir, $file) = File::Spec->splitpath( $example );
    108     $workdir = $dir;
    109 }
    110 system "mkdir -p $workdir" unless -d $workdir;
     99$workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
    111100
    112 # Stack the files
    113 my $outputFile = "$camera.$det_type.$det_id.$iter.$class_id"; # Root name
    114 my $outputRoot = File::Spec->catfile( $workdir, $outputFile );
     101my $outputRoot = $ipprc->file_prepare( "$camera.$det_type.$det_id.$iter.$class_id", $workdir, ${$files}[0]->{uri} );
    115102my $outputStack = $outputRoot . '.fits'; # Output name
    116103my $outputStats = $outputRoot . '.stats'; # Statistics name
    117104
     105# Stack the files
    118106my $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
    119107unless ($no_op) {
    120108    my $command = "$ppMerge $outputStack"; # Command to run
    121109    foreach my $file (@$files) {
    122         my $uri = $file->{uri}; # URI for input file
    123         $uri = $ipprc->convert_filename_absolute($uri);
    124         $command .= ' ' . $uri;
     110        $command .= ' ' . $file->{uri};
    125111    }
    126112    $command .= " -recipe PPMERGE $recipe";
     
    134120        &my_die("Unable to perform ppMerge: $error_code", $det_id, $iter, $class_id, $error_code);
    135121    }
    136     &my_die("Unable to find expected output file: $outputStack\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputStack;
    137     &my_die("Unable to find expected output file: $outputStats\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputStats;
     122    &my_die("Unable to find expected output file: $outputStack\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputStack);
     123    &my_die("Unable to find expected output file: $outputStats\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputStats);
    138124
    139125    # Get the statistics on the stacked image
    140     open(my $statsFile, "$outputStats") or
     126    open(my $statsFile, $ipprc->file_resolve("$outputStats")) or
    141127        &my_die("Can't open statistics file $outputStats: $!", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR);
    142128    my $contents = do { local $/; <$statsFile> }; # Contents of file
     
    156142
    157143# Add the resultant into the database
    158 $outputStack = $ipprc->convert_filename_relative($outputStack);
    159144unless ($no_update) {
    160145    my $command = "$dettool -addstacked -det_id $det_id -iteration $iter -class_id $class_id" .
     
    170155        exit($error_code);
    171156    }
    172 
    173     unlink $outputStats;
    174157}
    175158
  • trunk/ippScripts/scripts/diff_skycell.pl

    r13118 r13275  
    1919use Data::Dumper;
    2020
    21 use PS::IPP::Config qw(
    22     $PS_EXIT_SUCCESS
    23     $PS_EXIT_UNKNOWN_ERROR
    24     $PS_EXIT_SYS_ERROR
    25     $PS_EXIT_CONFIG_ERROR
    26     $PS_EXIT_PROG_ERROR
    27     $PS_EXIT_DATA_ERROR
    28     $PS_EXIT_TIMEOUT_ERROR
    29     );
     21use PS::IPP::Config qw($PS_EXIT_SUCCESS
     22                       $PS_EXIT_UNKNOWN_ERROR
     23                       $PS_EXIT_SYS_ERROR
     24                       $PS_EXIT_CONFIG_ERROR
     25                       $PS_EXIT_PROG_ERROR
     26                       $PS_EXIT_DATA_ERROR
     27                       $PS_EXIT_TIMEOUT_ERROR
     28                       caturi
     29                       );
    3030my $ipprc = PS::IPP::Config->new(); # IPP configuration
    31 use File::Spec;
    3231
    3332use constant POIS_OPTIONS => '-v -B 1000';
     
    8988my $camera;                     # Camera
    9089foreach my $file (@$files) {
    91     my $uri = $ipprc->convert_filename_absolute( $file->{uri} ); # URI for file
    9290    if (defined $file->{template} and $file->{template}) {
    93         $template = $uri;
    94     } else {
    95         $input = $uri;
     91        $template = $file->{uri};
     92    } else {
     93        $input = $file->{uri};
    9694    }
    9795    if (defined $tess_id) {
     
    119117$ipprc->define_camera($camera);
    120118
    121 ### Working directory
    122 if (defined $workdir) {
    123     $workdir = $ipprc->convert_filename_absolute( $workdir );
    124     $workdir = File::Spec->catdir( $workdir, "tess_" . $tess_id, "sky_" . $skycell_id );
    125 } else {
    126     my ($vol, $dir, $file) = File::Spec->splitpath( $input );
    127     $workdir = $dir;
    128 }
    129 system "mkdir -p $workdir" unless -d $workdir;
    130119
    131120# Get the output filenames
    132 my $outputFile = "$tess_id.$skycell_id.dif$diff_id"; # Root name
    133 my $outputRoot = File::Spec->catfile( $workdir, $outputFile );
    134 
     121$workdir = caturi( $workdir, "tess_" . $tess_id, "sky_" . $skycell_id ) if defined $workdir;
     122my $outputRoot = $ipprc->file_prepare( "$tess_id.$skycell_id.dif$diff_id", $workdir, $input );
    135123my $outputName = $outputRoot . ".fits";
    136124my $bin1Name =  $ipprc->filename("PPIMAGE.BIN1", $outputRoot);
     
    138126my $outputStats = $outputRoot . '.stats';
    139127
     128
     129### XXX We have to play around some here, because pois can't use Nebulous
     130my $outputNameResolved = $ipprc->file_create( $outputName );
     131my $templateResolved = $ipprc->file_resolve( $template );
     132my $inputResolved = $ipprc->file_resolve( $input );
     133
    140134# Perform subtraction
    141135my $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
    142136unless ($no_op) {
    143     my $command = "$pois " . POIS_OPTIONS() . " $template $input $outputName"; # Command to run pois
     137    my $command = "$pois " . POIS_OPTIONS() . " $templateResolved $inputResolved $outputNameResolved"; # Command to run pois
    144138
    145139    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    149143        &my_die("Unable to perform ppImage: $error_code", $diff_id, $error_code);
    150144    }
    151     &my_die("Couldn't find expected output file: $outputName", $diff_id, $PS_EXIT_SYS_ERROR) unless -f $outputName;
    152 #    &my_die("Couldn't find expected output file: $bin1Name",    $diff_id, $PS_EXIT_SYS_ERROR) unless -f $bin1Name;
    153 #    &my_die("Couldn't find expected output file: $bin2Name",    $diff_id, $PS_EXIT_SYS_ERROR) unless -f $bin2Name;
    154 #    &my_die("Couldn't find expected output file: $outputStats", $diff_id, $PS_EXIT_SYS_ERROR) unless -f $outputStats;
     145    &my_die("Couldn't find expected output file: $outputName", $diff_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputName);
     146#    &my_die("Couldn't find expected output file: $bin1Name",    $diff_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($bin1Name);
     147#    &my_die("Couldn't find expected output file: $bin2Name",    $diff_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($bin2Name);
     148#    &my_die("Couldn't find expected output file: $outputStats", $diff_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputStats);
    155149
    156150    # Get the statistics on the residual image
    157151    if (0) { ### Disabled because pois doesn't output stats yet
    158152        my $statsFile;          # File handle
    159         open $statsFile, $outputStats or &my_die("Can't open statistics file $outputStats: $!", $diff_id, $PS_EXIT_SYS_ERROR);
     153        open $statsFile, $ipprc->file_resolve($outputStats) or &my_die("Can't open statistics file $outputStats: $!", $diff_id, $PS_EXIT_SYS_ERROR);
    160154        my @contents = <$statsFile>; # Contents of file
    161155        close $statsFile;
     
    167161
    168162# Add the processed file to the database
    169 $outputName = $ipprc->convert_filename_relative( $outputName );
    170 $outputRoot = $ipprc->convert_filename_relative( $outputRoot );
    171 
    172163my $bg = ($stats->bg_mean() or 'NAN');
    173164my $bg_stdev = ($stats->bg_stdev() or 'NAN');
     
    187178            &my_die("Unable to perform difftool -adddiffskyfile: $error_code", $diff_id, $error_code);
    188179        }
    189        
    190 #       unlink $outputStats;   
    191180    }
    192181
  • trunk/ippScripts/scripts/ipp_datapath.pl

    r10572 r13275  
    99die "No filename specified.\n" if scalar @ARGV != 1;
    1010
    11 print $ipprc->convert_filename_absolute(shift @ARGV) . "\n";
     11print $ipprc->file_resolve(shift @ARGV) . "\n";
    1212
    13131;
  • trunk/ippScripts/scripts/ipp_serial_inject_mosaic.pl

    r13018 r13275  
    55
    66use IPC::Cmd 0.36 qw( can_run run );
    7 use PS::IPP::Config;
     7use PS::IPP::Config qw( caturi );
    88use Data::Dumper;
    9 use File::Spec;
    109
    1110use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    1413my ($camera,                    # Camera used
    1514    $telescope,                 # Telescope used
    16     $workdir,                   # Working directory to append
    1715    $dbname,                    # Database name
     16    $workdir,                   # Working directory
     17    $path,                      # Path to data
    1818    );
    1919GetOptions(
    20            'camera|c=s' => \$camera,
     20           'camera|c=s'    => \$camera,
    2121           'telescope|t=s' => \$telescope,
    22            'workdir=s' => \$workdir,
    23            'dbname=s' => \$dbname,
     22           'workdir=s'     => \$workdir,
     23           'path=s'        => \$path,
     24           'dbname=s'      => \$dbname,
    2425) or pod2usage( 2 );
    2526
    2627pod2usage(
    27           -msg => "Required options: --camera --telescope --workdir --dbname",
     28          -msg => "Required options: --camera --telescope --workdir --path --dbname",
    2829          -exitval => 3,
    29           ) unless defined $camera and defined $telescope and defined $workdir and defined $dbname;
     30          ) unless defined $camera
     31    and defined $telescope
     32    and defined $workdir
     33    and defined $path
     34    and defined $dbname;
    3035
    3136my $ipprc = PS::IPP::Config->new(); # IPP configuration
    32 my $workdir_abs = $ipprc->convert_filename_absolute( $workdir );
    3337
    3438# Look for programs we need
     
    3640my $pxinject = can_run('pxinject')  or (warn "Can't find pxinject" and $missing_tools = 1);
    3741
     42if (scalar @ARGV == 0) {
     43    die "No exposures provided.\n";
     44}
     45
    3846# Inject new data into the database
    39 if (scalar @ARGV != 0) {
    40     my @classes;                # Names of the classes
    41     my @files;                  # What to add to the filename for each class
    42     my $imfiles;
    43     my $add_dir;                # Add directory name to get file name?
    44     if ($camera eq "MEGACAM") {
    45         for (my $i = 0; $i < 36; $i++) {
    46             push @classes, sprintf("ccd%02d", $i);
    47             push @files, sprintf(".ccd%02d", $i);
    48         }
    49     } elsif ($camera eq "MCSHORT") {
    50         @classes = ( 'ccd12', 'ccd13', 'ccd14', 'ccd21', 'ccd22', 'ccd23' );
    51         @files   = ( '.ccd12', '.ccd13', '.ccd14', '.ccd21', '.ccd22', '.ccd23' );
    52        
    53     } elsif ($camera eq "CTIO_MOSAIC2") {
    54         @classes = ();
    55         @files = ();
    56     } elsif ($camera eq "TC3") {
    57         @classes = ( 'CCID58-1-06b2', 'CCID45-1-14A', 'CCID45-1-11A', 'CCID45-1-22A',
    58                    'CCID45-1-04C', 'CCID45-1-13A', 'CCID45-1-05A', 'CCID45-1-19A' );
    59         @files = ( '00', '01', '10', '11', '20', '21', '30', '31' );
    60         $add_dir = 1;
    61     } elsif ($camera eq "SIMMOSAIC") {
    62         @classes = ( 'Chip00', 'Chip01', 'Chip10', 'Chip11' );
    63         @files   = ( '.Chip00', '.Chip01', '.Chip10', '.Chip11' );
    64     } elsif ($camera eq "SIMTEST") {
    65         @classes = ();
    66         @files = ();
    67     } else {
    68         die "Unrecognised camera name: $camera.\n";
     47my @classes;                    # Names of the classes
     48my @files;                      # What to add to the filename for each class
     49my $imfiles;
     50my $add_dir;                    # Add directory name to get file name?
     51if ($camera eq "MEGACAM") {
     52    for (my $i = 0; $i < 36; $i++) {
     53        push @classes, sprintf("ccd%02d", $i);
     54        push @files, sprintf(".ccd%02d", $i);
     55    }
     56} elsif ($camera eq "MCSHORT") {
     57    @classes = ( 'ccd12', 'ccd13', 'ccd14', 'ccd21', 'ccd22', 'ccd23' );
     58    @files   = ( '.ccd12', '.ccd13', '.ccd14', '.ccd21', '.ccd22', '.ccd23' );
     59} elsif ($camera eq "CTIO_MOSAIC2") {
     60    @classes = ();
     61    @files = ();
     62} elsif ($camera eq "TC3") {
     63    @classes = ( 'CCID58-1-06b2', 'CCID45-1-14A', 'CCID45-1-11A', 'CCID45-1-22A',
     64                 'CCID45-1-04C', 'CCID45-1-13A', 'CCID45-1-05A', 'CCID45-1-19A' );
     65    @files = ( '00', '01', '10', '11', '20', '21', '30', '31' );
     66    $add_dir = 1;
     67} elsif ($camera eq "SIMMOSAIC") {
     68    @classes = ( 'Chip00', 'Chip01', 'Chip10', 'Chip11' );
     69    @files   = ( '.Chip00', '.Chip01', '.Chip10', '.Chip11' );
     70} elsif ($camera eq "SIMTEST") {
     71    @classes = ();
     72    @files = ();
     73} else {
     74    die "Unrecognised camera name: $camera.\n";
     75}
     76
     77foreach my $exp ( @ARGV ) {
     78    my $command = "$pxinject -newExp -exp_id $exp -inst $camera -telescope $telescope -workdir $workdir -dbname $dbname -imfiles " . (scalar @classes or 1) ; # Command to run
     79    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     80        run( command => $command, verbose => 1 );
     81    die "Unable to inject $exp: $error_code\n" if not $success;
     82   
     83    my @line = split(/\s+/, $$stdout_buf[0]); # The output line, containing the exposure tag
     84    my $exp_tag = $line[2];     # The exposure tag
     85    for (my $i = 0; $i < scalar @classes; $i++) {
     86        my $class_id = $classes[$i];
     87        my $file_id = $files[$i];
     88        my $filename = $exp . $file_id . '.fits';
     89        $filename = caturi( $exp, $filename ) if defined $add_dir;
     90        $filename = caturi( $path, $filename );
     91
     92        die "Unable to find file $filename" unless -f $ipprc->file_resolve( $filename );
     93
     94        $filename = $ipprc->convert_filename_relative( $filename );
     95        my $command = "$pxinject -newImfile -exp_tag $exp_tag -class chip -class_id $class_id -uri $filename -dbname $dbname"; # Command to run
     96        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     97            run( command => $command, verbose => 1 );
     98        die "Unable to inject $exp $class_id: $error_code\n" if not $success;
    6999    }
    70100
    71     foreach my $exp ( @ARGV ) {
    72         my $command = "$pxinject -newExp -exp_id $exp -inst $camera -telescope $telescope -workdir $workdir -dbname $dbname -imfiles " . (scalar @classes or 1) ; # Command to run
     101    if (scalar @classes == 0) {
     102        my $filename = "$exp.fits";
     103        $filename = caturi( $exp, $filename ) if defined $add_dir;
     104        $filename = caturi( $path, $filename );
     105
     106        die "Unable to find file $filename" unless -f $ipprc->file_resolve( $filename );
     107
     108        $filename = $ipprc->convert_filename_relative( $filename );
     109        my $command = "$pxinject -newImfile -exp_tag $exp_tag -class fpa -class_id fpa -dbname $dbname -uri $filename"; # Command to run
    73110        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    74111            run( command => $command, verbose => 1 );
    75         die "Unable to inject $exp: $error_code\n" if not $success;
    76        
    77         my @line = split(/\s+/, $$stdout_buf[0]); # The output line, containing the exposure tag
    78         my $exp_tag = $line[2]; # The exposure tag
    79         for (my $i = 0; $i < scalar @classes; $i++) {
    80             my $class_id = $classes[$i];
    81             my $file_id = $files[$i];
    82             my $filename = "$exp$file_id.fits";
    83             $filename = File::Spec->catfile( $exp, $filename ) if defined $add_dir;
    84             $filename = File::Spec->catfile( $workdir_abs, $filename);
    85             $filename = $ipprc->convert_filename_relative( $filename );
    86             my $command = "$pxinject -newImfile -exp_tag $exp_tag -class chip -class_id $class_id -uri $filename -dbname $dbname"; # Command to run
    87             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    88                 run( command => $command, verbose => 1 );
    89             die "Unable to inject $exp $class_id: $error_code\n" if not $success;
    90         }
     112        die "Unable to inject $exp imfile: $error_code\n" if not $success;
     113    }
    91114
    92         if (scalar @classes == 0) {
    93             my $filename = "$exp.fits";
    94             $filename = File::Spec->catfile( $exp, $filename ) if defined $add_dir;
    95             $filename = File::Spec->catfile( $workdir_abs, $filename);
    96             $filename = $ipprc->convert_filename_relative( $filename );
    97             my $command = "$pxinject -newImfile -exp_tag $exp_tag -class fpa -class_id fpa -dbname $dbname -uri $filename"; # Command to run
    98             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    99                 run( command => $command, verbose => 1 );
    100             die "Unable to inject $exp imfile: $error_code\n" if not $success;
    101         }
    102 
    103     }
    104115}
    105116
    106117END {
    107118    my $status = $?;
    108     system("sync") == 0
    109         or die "failed to execute sync: $!" ;
    110     $? = $status;
     119system("sync") == 0
     120    or die "failed to execute sync: $!" ;
     121$? = $status;
    111122}
    112123
  • trunk/ippScripts/scripts/ipp_simulation_data.pl

    r13122 r13275  
    1313use Pod::Usage qw( pod2usage );
    1414use PS::IPP::Config qw(
    15     $PS_EXIT_SUCCESS
    16     $PS_EXIT_UNKNOWN_ERROR
    17     $PS_EXIT_SYS_ERROR
    18     $PS_EXIT_CONFIG_ERROR
    19     $PS_EXIT_PROG_ERROR
    20     $PS_EXIT_DATA_ERROR
    21     $PS_EXIT_TIMEOUT_ERROR
    22     );
     15                       $PS_EXIT_SUCCESS
     16                       $PS_EXIT_UNKNOWN_ERROR
     17                       $PS_EXIT_SYS_ERROR
     18                       $PS_EXIT_CONFIG_ERROR
     19                       $PS_EXIT_PROG_ERROR
     20                       $PS_EXIT_DATA_ERROR
     21                       $PS_EXIT_TIMEOUT_ERROR
     22                       caturi
     23                       );
    2324
    2425my $ipprc = PS::IPP::Config->new(); # IPP configuration
     
    2829    $telescope,                 # Telesceope name
    2930    $dbname,                    # Database name
     31    $path,                      # Path to data
    3032    $workdir,                   # Working directory for data
    3133    $no_update                  # Don't update the database
     
    3739           'telescope=s'   => \$telescope,
    3840           'dbname=s'      => \$dbname,
     41           'path=s'        => \$path,
    3942           'workdir=s'     => \$workdir,
    4043           'no-update'     => \$no_update,
     
    4447
    4548pod2usage(
    46           -msg => "Required options: --name --camera --telescope --dbname",
     49          -msg => "Required options: --name --path --camera --telescope --dbname",
    4750            -exitval => 3,
    4851          ) unless
    4952    defined $name and
     53    defined $path and
    5054    defined $camera and
    5155    defined $telescope and
    5256    defined $dbname;
    5357
     58$workdir = $path if not defined $workdir;
    5459
    5560# Look for programs we need
     
    6469    exit($PS_EXIT_CONFIG_ERROR);
    6570}
    66 
    67 $workdir = $ipprc->convert_filename_absolute( $workdir );
    6871
    6972# Number of bias images
     
    120123    my $basename;               # Output base filename
    121124    ( $basename, $counter ) = filename( $name, $counter );
    122     my $filename = File::Spec->catfile( $workdir, $basename ) if defined $workdir; # File name
     125    my $filename = caturi( $path, $basename );
    123126    run( command => "$ppSim -camera $camera -type BIAS $filename",
    124127         verbose => 1 ) or die "Unable to run ppSim";
    125     run( command => "$inject --camera $camera --telescope $telescope --workdir $workdir " .
     128    run( command => "$inject --camera $camera --telescope $telescope --path $path --workdir $workdir " .
    126129         "--dbname $dbname $basename",
    127130         verbose => 1 ) or die "Unable to inject file.";
     
    132135    my $basename;               # Output base filename
    133136    ( $basename, $counter ) = filename( $name, $counter );
    134     my $filename = File::Spec->catfile( $workdir, $basename ) if defined $workdir; # File name
     137    my $filename = caturi( $path, $basename );
    135138    run ( command => "$ppSim -camera $camera -type DARK -exptime $exptime $filename",
    136139          verbose => 1 ) or die "Unable to run ppSim";
    137     run( command => "$inject --camera $camera --telescope $telescope --workdir $workdir " .
     140    run( command => "$inject --camera $camera --telescope $telescope --path $path --workdir $workdir " .
    138141         "--dbname $dbname $basename",
    139142         verbose => 1 ) or die "Unable to inject file.";
     
    146149        my $basename;           # Output base filename
    147150        ( $basename, $counter ) = filename( $name, $counter );
    148         my $filename = File::Spec->catfile( $workdir, $basename ) if defined $workdir; # File name
     151        my $filename = caturi( $path, $basename );
    149152        run( command => "$ppSim -camera $camera -type FLAT -filter $filter -exptime $exptime $filename",
    150153             verbose => 1 ) or die "Unable to run ppSim";
    151         run( command => "$inject --camera $camera --telescope $telescope --workdir $workdir " .
     154        run( command => "$inject --camera $camera --telescope $telescope --path $path --workdir $workdir " .
    152155             "--dbname $dbname $basename",
    153156             verbose => 1 ) or die "Unable to inject file.";
     
    174177        my $basename;           # Output base filename
    175178        ( $basename, $counter ) = filename( $name, $counter );
    176         my $filename = File::Spec->catfile( $workdir, $basename ) if defined $workdir; # File name
     179        my $filename = caturi( $path, $basename );
    177180        run( command => "$ppSim -camera $camera -type OBJECT -filter $filter -exptime $exptime " .
    178181             "-skyrate $sky -ra $ra -dec $dec -pa $pa -scale $scale -zp $zp -seeing $seeing $filename",
    179182             verbose => 1 ) or die "Unable to run ppSim";
    180         run( command => "$inject --camera $camera --telescope $telescope --workdir $workdir " .
    181              "--dbname $dbname $basename ",
     183        run( command => "$inject --camera $camera --telescope $telescope --path $path --workdir $workdir " .
     184             "--dbname $dbname $basename",
    182185             verbose => 1 ) or die "Unable to inject file.";
    183186    }
     
    199202}
    200203
    201 
    202 
    203 
    204204__END__
  • trunk/ippScripts/scripts/register_imfile.pl

    r12934 r13275  
    5959
    6060my $RECIPE = "PPSTATS_PHASE0"; # Recipe to use for ppStats
    61 # use constant RECIPE => "PPSTATS_PHASE0"; # Recipe to use for ppStats
    6261
    6362# These values should be constant for all components
     
    104103);
    105104
    106 # Resolve the input URI
    107 $uri = $ipprc->convert_filename_absolute($uri);
    108 
    109105# Run ppStats on the input file
    110106my $stats;
     
    131127    unless ($stats->parse($metadata)) {
    132128        warn ("Unable to find all values");
    133         &my_die ($exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
    134         # XXX is this a programming or a config error?
     129        &my_die ($exp_tag, $class_id, $PS_EXIT_CONFIG_ERROR);
    135130    }
    136131
    137132    if (0) {
    138     # XXX for a test, randomly declare a failure and return to pantasks
    139     my $rnd = rand(1);
    140     if ($rnd > 0.5) {
    141         warn ("random failure");
    142         &my_die ($exp_tag, $class_id, $PS_EXIT_DATA_ERROR);
    143     }
    144 }
     133        # XXX for a test, randomly declare a failure and return to pantasks
     134        my $rnd = rand(1);
     135        if ($rnd > 0.5) {
     136            warn ("random failure");
     137            &my_die ($exp_tag, $class_id, $PS_EXIT_DATA_ERROR);
     138        }
     139    }
    145140}
    146141
     
    175170    unless ($success) {
    176171        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    177         # XXX if we can't run -addprocessedimfile, we can't actually set the
    178         # error code.
    179         # XXX if this is not a database error, it is probably a
    180         # programming error (in regtool or the passed args)
     172        # If we can't run -addprocessedimfile, we can't actually set the error code. If this is not
     173        # a database error, it is probably a programming error (in regtool or the passed args)
    181174        warn ("Unable to perform regtool -addprocessedimfile: $error_code");
    182175        exit($error_code);
  • trunk/ippScripts/scripts/stack_skycell.pl

    r13120 r13275  
    1919use Data::Dumper;
    2020
    21 use PS::IPP::Config qw(
    22     $PS_EXIT_SUCCESS
    23     $PS_EXIT_UNKNOWN_ERROR
    24     $PS_EXIT_SYS_ERROR
    25     $PS_EXIT_CONFIG_ERROR
    26     $PS_EXIT_PROG_ERROR
    27     $PS_EXIT_DATA_ERROR
    28     $PS_EXIT_TIMEOUT_ERROR
    29     );
     21use PS::IPP::Config qw($PS_EXIT_SUCCESS
     22                       $PS_EXIT_UNKNOWN_ERROR
     23                       $PS_EXIT_SYS_ERROR
     24                       $PS_EXIT_CONFIG_ERROR
     25                       $PS_EXIT_PROG_ERROR
     26                       $PS_EXIT_DATA_ERROR
     27                       $PS_EXIT_TIMEOUT_ERROR
     28                       caturi
     29                       );
    3030my $ipprc = PS::IPP::Config->new(); # IPP configuration
    31 use File::Spec;
    3231
    3332use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    8685my $camera;                     # Camera
    8786foreach my $file (@$files) {
    88     my $uri = $ipprc->convert_filename_absolute( $file->{uri} ); # URI for file
    89     $inputList .= "$uri ";
     87    $inputList .= $file->{uri} . ' ';
    9088    if (defined $tess_id) {
    9189        &my_die("Tesselation identifiers don't match", $stack_id, $PS_EXIT_SYS_ERROR) unless
     
    110108$ipprc->define_camera($camera);
    111109
    112 
    113 ### Working directory
    114 if (defined $workdir) {
    115     $workdir = $ipprc->convert_filename_absolute( $workdir );
    116     $workdir = File::Spec->catdir( $workdir, "tess_" . $tess_id, "sky_" . $skycell_id );
    117 } else {
    118     my ($vol, $dir, $file) = File::Spec->splitpath( $ipprc->convert_filename_absolute( $$files[0]->{uri} ) );
    119     $workdir = $dir;
    120 }
    121 system "mkdir -p $workdir" unless -d $workdir;
    122 
    123110# Get the output filenames
    124 my $outputFile = "$tess_id.$skycell_id.stk$stack_id"; # Root name
    125 my $outputRoot = File::Spec->catfile( $workdir, $outputFile );
    126 
     111$workdir = caturi( $workdir, "tess_" . $tess_id, "sky_" . $skycell_id ) if defined $workdir;
     112my $outputRoot = $ipprc->file_prepare( "$tess_id.$skycell_id.stk$stack_id", $workdir, $$files[0]->{uri} );
    127113my $outputName = $outputRoot . ".fits";
    128114#my $bin1Name =  $ipprc->filename("PPSTAC.BIN1", $outputRoot);
     
    141127        &my_die("Unable to perform ppImage: $error_code", $stack_id, $error_code);
    142128    }
    143     &my_die("Couldn't find expected output file: $outputName", $stack_id, $PS_EXIT_SYS_ERROR) unless -f $outputName;
    144 #    &my_die("Couldn't find expected output file: $bin1Name",    $stack_id, $PS_EXIT_SYS_ERROR) unless -f $bin1Name;
    145 #    &my_die("Couldn't find expected output file: $bin2Name",    $stack_id, $PS_EXIT_SYS_ERROR) unless -f $bin2Name;
    146 #    &my_die("Couldn't find expected output file: $outputStats", $stack_id, $PS_EXIT_SYS_ERROR) unless -f $outputStats;
     129    &my_die("Couldn't find expected output file: $outputName", $stack_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputName);
     130#    &my_die("Couldn't find expected output file: $bin1Name",    $stack_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($bin1Name);
     131#    &my_die("Couldn't find expected output file: $bin2Name",    $stack_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($bin2Name);
     132#    &my_die("Couldn't find expected output file: $outputStats", $stack_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputStats);
    147133
    148134    # Get the statistics on the residual image
    149135    if (0) { ### Disabled because ppStac doesn't output stats yet
    150136        my $statsFile;          # File handle
    151         open $statsFile, $outputStats or &my_die("Can't open statistics file $outputStats: $!", $stack_id, $PS_EXIT_SYS_ERROR);
     137        open $statsFile, $ipprc->file_resolve($outputStats) or &my_die("Can't open statistics file $outputStats: $!", $stack_id, $PS_EXIT_SYS_ERROR);
    152138        my @contents = <$statsFile>; # Contents of file
    153139        close $statsFile;
     
    159145
    160146# Add the processed file to the database
    161 $outputName = $ipprc->convert_filename_relative( $outputName );
    162 $outputRoot = $ipprc->convert_filename_relative( $outputRoot );
    163 
    164147my $bg = ($stats->bg_mean() or 'NAN');
    165148my $bg_stdev = ($stats->bg_stdev() or 'NAN');
     
    179162            &my_die("Unable to perform stacktool -addsumskyfile: $error_code", $stack_id, $error_code);
    180163        }
    181        
    182 #       unlink $outputStats;   
    183164    }
    184165
  • trunk/ippScripts/scripts/warp_overlap.pl

    r13176 r13275  
    1717use PS::IPP::Metadata::Stats;
    1818use PS::IPP::Metadata::List qw( parse_md_list );
    19 
    20 use PS::IPP::Config qw(
    21     $PS_EXIT_SUCCESS
    22     $PS_EXIT_UNKNOWN_ERROR
    23     $PS_EXIT_SYS_ERROR
    24     $PS_EXIT_CONFIG_ERROR
    25     $PS_EXIT_PROG_ERROR
    26     $PS_EXIT_DATA_ERROR
    27     $PS_EXIT_TIMEOUT_ERROR
    28     metadataLookupStr
    29     );
     19use File::Temp qw( tempfile );
     20
     21use PS::IPP::Config qw($PS_EXIT_SUCCESS
     22                       $PS_EXIT_UNKNOWN_ERROR
     23                       $PS_EXIT_SYS_ERROR
     24                       $PS_EXIT_CONFIG_ERROR
     25                       $PS_EXIT_PROG_ERROR
     26                       $PS_EXIT_DATA_ERROR
     27                       $PS_EXIT_TIMEOUT_ERROR
     28                       metadataLookupStr
     29                       caturi
     30                       );
    3031my $ipprc = PS::IPP::Config->new(); # IPP configuration
    3132use File::Spec;
     
    8283}
    8384
    84 # Make sure everything is from the same exposure, and get the exposure tag
    85 my $exp_tag;                    # Exposure tag
    86 foreach my $imfile ( @$imfiles ) {
    87     unless (defined $exp_tag) {
    88         $exp_tag = $imfile->{exp_tag};
    89     } elsif ($exp_tag ne $imfile->{exp_tag}) {
    90         &my_die("Multiple exposures in the same warp.", $warp_id, $PS_EXIT_SYS_ERROR);
    91     }
    92 }
    93 
    94 # Set output directory
    95 if (defined $workdir) {
    96     $workdir = $ipprc->convert_filename_absolute( $workdir );
    97 } else {
    98     my $example = $ipprc->convert_filename_absolute( $$imfiles[0]->{uri} );
    99     my ($vol, $dir, $file) = File::Spec->splitpath( $example );
    100     $workdir = $dir;
    101 }
    102 system "mkdir -p $workdir" unless -d $workdir;
    103 
    104 
    10585# Determine the imfile/skycell overlaps
    10686my @overlaps = ();
     
    11191    my $tessellations = $ipprc->tessellations(); # Hash of defined tessellations
    11292    foreach my $tess_id ( keys %$tessellations ) {
     93        ### Because DVO doesn't use psModules, it doesn't understand Nebulous --- check
     94        my $uri = URI->new( $$tessellations{$tess_id} );
     95        if (defined $uri->scheme() and $uri->scheme() eq 'neb') {
     96            &my_die("Tessellation $tess_id refers to a Nebulous path: $$tessellations{$tess_id}", $warp_id, $PS_EXIT_CONFIG_ERROR);
     97        }                   
     98       
    11399        my $tess_dir = $ipprc->convert_filename_absolute( $$tessellations{$tess_id} ); # Catdir for DVO
    114100        print STDERR "tessellation: $tess_id, $tess_dir\n";
    115101
    116102        my $imfile = $imfiles->[0];
    117         my $camRoot = $ipprc->convert_filename_absolute( $imfile->{cam_path_base} );
     103        my $camRoot = $imfile->{cam_path_base};
    118104        my $psastroFile = $ipprc->filename("PSASTRO.OUTPUT", $camRoot); # MEF psastro output
    119105       
     
    123109       
    124110        # run the dvoImageOverlaps program to get the overlaps with this image
    125         my $command = "$dvoImageOverlaps -D CATDIR $tess_dir $psastroFile";
     111        my $command = "$dvoImageOverlaps -D CATDIR $tess_dir " . $ipprc->file_resolve($psastroFile);
    126112        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    127113            run(command => $command, verbose => 1);
     
    145131            if ($fileLevel eq "chip") {
    146132                my $class_id = $imfile->{class_id};
    147                 my $chipRoot = $ipprc->convert_filename_absolute( $imfile->{chip_path_base} );
     133                my $chipRoot = $ipprc->file_resolve( $imfile->{chip_path_base} );
    148134                my $extname = $ipprc->extname_rule("CMF.HEAD", $class_id); # MEF psastro output
    149135               
     
    176162        # Extract the skycells to images, used as warp templates.
    177163        foreach my $skycell_id (@unique_skycells) {
    178             my $skyDir = File::Spec->catdir($workdir, "tess_" . $tess_id, "sky_" . $skycell_id );
    179             system "mkdir -p $skyDir" unless -d $skyDir;
    180             my $skyFile = File::Spec->catfile( $skyDir , $skycell_id );
    181             my $command = "$dvoImageExtract -D CATDIR $tess_dir $skycell_id -o $skyFile";
    182             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    183                 run(command => $command, verbose => 1);
    184             unless ($success) {
    185                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    186                 &my_die("Unable to perform dvoImageExtract: $error_code", $warp_id, $error_code);
     164            my $skyDir = caturi($workdir, "tess_" . $tess_id, "sky_" . $skycell_id );
     165            my $skyFile = $ipprc->file_prepare( $skycell_id, $skyDir );
     166            unless ($ipprc->file_exists( $skyFile )) {
     167                my $skyFileResolved = $ipprc->file_create( $skyFile ); # Resolved filename, for Nebulous
     168                my $command = "$dvoImageExtract -D CATDIR $tess_dir $skycell_id -o $skyFileResolved";
     169                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     170                    run(command => $command, verbose => 1);
     171                unless ($success) {
     172                    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     173                    &my_die("Unable to perform dvoImageExtract: $error_code", $warp_id, $error_code);
     174                }
    187175            }
    188176        }
     
    202190
    203191# Generate a MDC file with the overlaps
    204 my $overlapName = File::Spec->catfile( $workdir, 'overlaps.wrp' . $warp_id . '.mdc' );
    205 open my $overlapFile, "> $overlapName" or die "Unable to open mdc file $overlapName";
     192my ($overlapFile, $overlapName) = tempfile( 'overlaps.wrp' . $warp_id . '.mdc.XXXX', UNLINK => 1 );
    206193print $overlapFile "warpSkyCellMap MULTI\n\n";
    207194foreach my $overlap (@overlaps) {
     
    229216        exit($error_code);
    230217    }
    231 
    232     unlink $overlapName;
    233218}
    234219
  • trunk/ippScripts/scripts/warp_skycell.pl

    r13112 r13275  
    1818use PS::IPP::Metadata::List qw( parse_md_list );
    1919
    20 use PS::IPP::Config qw(
    21     $PS_EXIT_SUCCESS
    22     $PS_EXIT_UNKNOWN_ERROR
    23     $PS_EXIT_SYS_ERROR
    24     $PS_EXIT_CONFIG_ERROR
    25     $PS_EXIT_PROG_ERROR
    26     $PS_EXIT_DATA_ERROR
    27     $PS_EXIT_TIMEOUT_ERROR
    28     );
     20use PS::IPP::Config qw($PS_EXIT_SUCCESS
     21                       $PS_EXIT_UNKNOWN_ERROR
     22                       $PS_EXIT_SYS_ERROR
     23                       $PS_EXIT_CONFIG_ERROR
     24                       $PS_EXIT_PROG_ERROR
     25                       $PS_EXIT_DATA_ERROR
     26                       $PS_EXIT_TIMEOUT_ERROR
     27                       caturi
     28                       );
    2929my $ipprc = PS::IPP::Config->new(); # IPP configuration
    3030use File::Spec;
     31use File::Temp qw( tempfile );
    3132
    3233use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    8485}
    8586
    86 # Set output directory
    87 if (defined $workdir) {
    88     $workdir = $ipprc->convert_filename_absolute( $workdir );
    89     $workdir = File::Spec->catdir( $workdir, "tess_" . $tess_id, "sky_" . $skycell_id );
    90 } else {
    91     my $example = $ipprc->convert_filename_absolute( $$imfiles[0]->{uri} );
    92     my ($vol, $dir, $file) = File::Spec->splitpath( $example );
    93     $workdir = $dir;
    94 }
    95 system "mkdir -p $workdir" unless -d $workdir;
    96 
    97 my $outputFile = "$tess_id.$skycell_id.wrp$warp_id"; # Root name
    98 my $outputRoot = File::Spec->catfile( $workdir, $outputFile );
     87$workdir = caturi( $workdir, "tess_" . $tess_id, "sky_" . $skycell_id ) if defined $workdir;
     88my $outputRoot = $ipprc->file_prepare( "$tess_id.$skycell_id.wrp$warp_id", $workdir, $$imfiles[0]->{uri} );
    9989my $outputImage = $ipprc->filename("PSWARP.OUTPUT", $outputRoot, $skycell_id );
    10090my $outputBin1 = $ipprc->filename("PSWARP.BIN1", $outputRoot, $skycell_id );
    10191my $outputBin2 = $ipprc->filename("PSWARP.BIN2", $outputRoot, $skycell_id );
    10292my $outputStats = $outputRoot . '.stats';
    103 my $skyFile = File::Spec->catfile( $workdir, $skycell_id ); # Target sky cell file
    104 my $listName = $outputRoot . '.list';
     93my $skyFile = caturi( $workdir, $skycell_id ); # Target sky cell file
    10594
    10695# Get list of filenames
    107 open my $listFile, "> $listName" or &my_die("Unable to open $listName", $warp_id, $skycell_id, $tess_id, $PS_EXIT_SYS_ERROR);
     96my ($listFile, $listName) = tempfile( "$tess_id.$skycell_id.wrp$warp_id.list.XXXX", UNLINK => 1);
    10897foreach my $imfile (@$imfiles) {
    109     my $uri = $ipprc->convert_filename_absolute( $imfile->{uri} );
    110 
    111     print $listFile "$uri\n";
     98    print $listFile ( $imfile->{uri} . "\n");
    11299}
    113100close $listFile;
     
    123110        &my_die("Unable to perform pswarp: $error_code", $warp_id, $skycell_id, $error_code);
    124111    }
    125     &my_die("Couldn't find expected output file: $outputImage", $warp_id, $skycell_id, $tess_id, $PS_EXIT_SYS_ERROR) unless -f $outputImage;
    126     &my_die("Couldn't find expected output file: $outputStats", $warp_id, $skycell_id, $tess_id, $PS_EXIT_SYS_ERROR) unless -f $outputStats;
    127 #    &my_die("Couldn't find expected output file: $outputBin1", $warp_id, $skycell_id, $tess_id, $PS_EXIT_SYS_ERROR) unless -f $outputBin1;
    128 #    &my_die("Couldn't find expected output file: $outputBin2", $warp_id, $skycell_id, $tess_id, $PS_EXIT_SYS_ERROR) unless -f $outputBin2;
     112    &my_die("Couldn't find expected output file: $outputImage", $warp_id, $skycell_id, $tess_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputImage);
     113    &my_die("Couldn't find expected output file: $outputStats", $warp_id, $skycell_id, $tess_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputStats);
     114#    &my_die("Couldn't find expected output file: $outputBin1", $warp_id, $skycell_id, $tess_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputBin1);
     115#    &my_die("Couldn't find expected output file: $outputBin2", $warp_id, $skycell_id, $tess_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputBin2);
    129116
    130117    # Get the statistics on the warped image
    131118    my $statsFile;              # File handle
    132     open $statsFile, "$outputStats" or die "Can't open statistics file $outputStats: $!\n";
     119    open $statsFile, $ipprc->file_resolve($outputStats) or die "Can't open statistics file $outputStats: $!\n";
    133120    my @contents = <$statsFile>; # Contents of file
    134121    close $statsFile;
     
    138125}
    139126
    140 # Take off the absolute path, to stuff into the database
    141 $outputImage = $ipprc->convert_filename_relative( $outputImage );
    142 $outputRoot = $ipprc->convert_filename_relative( $outputRoot );
    143 
     127# Add the processed file to the database
    144128my $bg = ($stats->bg_mean() or 'NAN');
    145129my $bg_stdev = ($stats->bg_stdev() or 'NAN');
    146 
    147 # Add the processed file to the database
    148130unless ($no_update) {
    149131    my $command = "$warptool -addwarped -warp_id $warp_id -skycell_id $skycell_id -tess_id $tess_id" .
     
    159141        exit($error_code);
    160142    }
    161 
    162     unlink $outputStats;
    163143}
    164144
Note: See TracChangeset for help on using the changeset viewer.