IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 20, 2009, 11:23:43 AM (17 years ago)
Author:
watersc1
Message:

preliminary addstar/addtool code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/cleanup/ippScripts/scripts/addstar_run.pl

    r25088 r25147  
    4040}
    4141
    42 my ( $exp_tag, $add_id, $camera, $outroot, $recipe, $dbname, $reduction, $dvodb, $verbose, $no_update,
     42my ( $exp_tag, $add_id, $camera, $outroot, $camroot, $recipe, $dbname, $reduction, $dvodb, $verbose, $no_update,
    4343     $no_op, $redirect, $save_temps, $run_state);
    4444GetOptions(
     
    4949    'dbname|d=s'        => \$dbname, # Database name
    5050    'outroot|w=s'       => \$outroot, # output file base name
     51    'camroot|w=s'       => \$camroot, # camera stage root name.
    5152    'reduction=s'       => \$reduction, # Reduction class
    5253    'dvodb|w=s'         => \$dvodb,  # output DVO database
     
    111112    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    112113        &my_die("Unable to parse metadata config doc", $add_id, $PS_EXIT_PROG_ERROR);
    113 
     114   
    114115    # extract the metadata for the files into a hash list
    115116    $files = parse_md_list($metadata) or
    116         &my_die("Unable to parse metadata list", $add_id, $PS_EXIT_PROG_ERROR);
    117 
    118 #     # since I can't figure out how to do input and output within PERL, I'm writing to a temp file
    119 #     my ($statFile, $statName) = tempfile( "/tmp/$exp_tag.add.$add_id.stats.XXXX", UNLINK => !$save_temps );
    120 #     print "saving stats to $statName\n";
    121 #     foreach my $line (@$stdout_buf) {
    122 #         print $statFile $line;
    123 #     }
    124 #     close $statFile;
    125 
    126 #     # parse the stats in the metadata file
    127 #     $command = "$ppStatsFromMetadata $statName - CAMERA_EXP_IMFILE";
    128 #     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    129 #         run(command => $command, verbose => $verbose);
    130 #     unless ($success) {
    131 #         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    132 #         warn("Unable to perform ppStatsFromMetadata: $error_code\n");
    133 #         exit($error_code);
    134 #     }
    135 
    136 #     foreach my $line (@$stdout_buf) {
    137 #         $cmdflags .= " $line";
    138 #     }
    139 #     chomp $cmdflags;
    140 }
    141 
    142 # ### not needed to have such an extensive temp file name.
    143 # my ($list1File, $list1Name) = tempfile( "/tmp/$exp_tag.cm.$cam_id.b1.list.XXXX", UNLINK => !$save_temps ); # For binning 1
    144 # my ($list2File, $list2Name) = tempfile( "/tmp/$exp_tag.cm.$cam_id.b2.list.XXXX", UNLINK => !$save_temps ); # For binning 2
    145 # my ($list3File, $list3Name) = tempfile( "/tmp/$exp_tag.cm.$cam_id.b3.list.XXXX", UNLINK => !$save_temps ); # For astrometry
    146 
    147 # ### XXX for the moment, always generate the bright-star mask
    148 # my ($list4File, $list4Name) = tempfile( "/tmp/$exp_tag.cm.$cam_id.b4.list.XXXX", UNLINK => !$save_temps ); # For astrometry
    149 
    150 # # XXX we perform astrometry iff photometry output exists
     117        &my_die("Unable to parse metadata list", $add_id, $PS_EXIT_PROG_ERROR);   
     118}
     119
    151120my $chipObjectsExist = 0;
    152 # foreach my $file (@$files) {
    153 #     # use the path_base as OUTPUT root and convert the filenames with ipprc->filename:
    154 #     my $class_id = $file->{class_id};
    155 
    156 #     # If there is only one chip, we use this name for the input to addstar
    157 #     # we expect the chip analysis stage to produce psphot output (cmf file) and two binned images
    158 #     my $chipObjects = $ipprc->filename("PSPHOT.OUTPUT", $file->{path_base}, $class_id);
    159 #     my $chipMask   = $ipprc->filename("PPIMAGE.CHIP.MASK", $file->{path_base}, $class_id);
    160 
    161 #     # if any of the output chip photometry files exist, we can run psastro / addstar below
    162 #     if ($ipprc->file_exists($chipObjects)) {
    163 #         $chipObjectsExist = 1;
    164 #     } else {
    165 #         if ($verbose) { print "skipping $chipObjects (not found)\n"; }
    166 #         next;
    167 #     }
    168 
    169 #     print $list1File ($ipprc->filename("PPIMAGE.BIN1", $file->{path_base}, $class_id) . "\n");
    170 #     print $list2File ($ipprc->filename("PPIMAGE.BIN2", $file->{path_base}, $class_id) . "\n");
    171 #     print $list3File ($chipObjects . "\n");
    172 #     print $list4File ($chipMask . "\n");
    173 # }
    174 # close $list1File;
    175 # close $list2File;
    176 # close $list3File;
    177 # close $list4File;
    178121
    179122# Output products
     
    181124
    182125# the camera configurations should define the psastro output to be a single file (MEF), regardless of the inputs
    183 # my $jpeg1      = $ipprc->filename("PPIMAGE.JPEG1",      $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
    184 # my $jpeg2      = $ipprc->filename("PPIMAGE.JPEG2",      $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
    185 my $fpaObjects = $ipprc->filename("PSASTRO.OUTPUT",     $outroot) or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR);
    186 # my $fpaStats   = $ipprc->filename("PSASTRO.STATS",      $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
     126my $fpaObjects = $ipprc->filename("PSASTRO.OUTPUT",     $camroot) or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR);
    187127my $traceDest  = $ipprc->filename("TRACE.EXP",          $outroot) or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR);
    188 #my $configuration = $ipprc->filename("PSASTRO.CONFIG",  $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
    189128
    190129if ($run_state eq 'update') {
    191130    $traceDest .= '.update';
    192 #    $fpaStats .= '.update';
    193131}
    194132
     
    203141
    204142unless ($no_op) {
    205 
    206     ## build the output JPEG images first so we get them even if the astrometry fails
    207 
    208     # Make the jpeg for binning 1
    209 #     if ($run_state eq 'new') {
    210 #         my $command = "$ppImage -list $list1Name $outroot"; # Command to run
    211 #         $command .= " -recipe PPIMAGE $recipe1";
    212 #         $command .= " -dbname $dbname" if defined $dbname;
    213 
    214 #         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    215 #             run(command => $command, verbose => $verbose);
    216 #         unless ($success) {
    217 #             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    218 #             &my_die("Unable to perform ppImage: $error_code", $cam_id, $error_code);
    219 #         }
    220 #         &my_die("Unable to find expected output file: $jpeg1", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($jpeg1);
    221 #     }
    222 
    223 #     # Make the jpeg for binning 2
    224 #     if ($run_state eq 'new') {
    225 #         my $command = "$ppImage -list $list2Name $outroot"; # Command to run
    226 #         $command .= " -recipe PPIMAGE $recipe2";
    227 #         $command .= " -dbname $dbname" if defined $dbname;
    228 
    229 #         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    230 #             run(command => $command, verbose => $verbose);
    231 #         unless ($success) {
    232 #             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    233 #             &my_die("Unable to perform ppImage: $error_code", $cam_id, $error_code);
    234 #         }
    235 #         &my_die("Unable to find expected output file: $jpeg2", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($jpeg2);
    236 #     }
    237 
    238     # only run psastro / addstar if any of the output chip astrometry files exist (should we test for successful astrometry?)
    239 #    if ($chipObjectsExist) {
    240         # run psastro on the chipObjects, producing fpaObjects
    241 #         my $command;
    242 #         $command  = "$psastro";
    243 #       $command .= " -list $list3Name";
    244 #       $command .= " -masklist $list4Name";
    245 #       $command .= " $outroot";
    246 #         $command .= " -recipe PSASTRO $recipe_psastro";
    247 #         $command .= " -tracedest $traceDest -log $logDest";
    248 #         $command .= " -dbname $dbname" if defined $dbname;
    249 
    250 #         my $do_stats;
    251 #         if ($run_state eq 'new') {
    252 #             $command .= " -stats $fpaStats -recipe PPSTATS CAMSTATS";
    253 #             $command .= " -dumpconfig $configuration";
    254 #             $do_stats = 1;
    255 #         } elsif ($run_state eq 'update') {
    256 #             $command .= " -ipprc $configuration";
    257 #         } else {
    258 #             &my_die("invalid value for run-state: $run_state", $cam_id, $PS_EXIT_CONFIG_ERROR);
    259 #         }
    260 
    261 #         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    262 #             run(command => $command, verbose => $verbose);
    263 #         unless ($success) {
    264 #             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    265 #             &my_die("Unable to perform psastro: $error_code", $cam_id, $error_code);
    266 #         }
    267 
    268 #         my $quality;            # Quality flag
    269 #         if ($do_stats) {
    270 #             my $fpaStatsReal = $ipprc->file_resolve($fpaStats);
    271 #             &my_die("Couldn't find expected output file: $fpaStats", $cam_id, $PS_EXIT_SYS_ERROR) unless -f $fpaStatsReal;
    272 
    273 #             # parse stats from metadata
    274 #             $command = "$ppStatsFromMetadata $fpaStatsReal - CAMERA_EXP_FPA";
    275 #             ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    276 #                 run(command => $command, verbose => $verbose);
    277 #             unless ($success) {
    278 #                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    279 #                 &my_die("Unable to perform ppStatsFromMetadata: $error_code", $cam_id, $error_code);
    280 #             }
    281 #             foreach my $line (@$stdout_buf) {
    282 #                 $cmdflags .= " $line";
    283 #             }
    284 #             chomp $cmdflags;
    285 
    286 #             ($quality) = $cmdflags =~ /-quality (\d+)/;
    287 #         }
    288 
    289 #         if (!$quality) {
    290 #             &my_die("Unable to find expected output file: $fpaObjects", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($fpaObjects);
    291 #         }
    292 
    293 #         # run addstar on the output fpaObjects (if a DVO database is defined)
    294         if (defined $dvodbReal and ($run_state eq 'new')) {
    295 
    296             ## XXX the camera analysis can either save the full set of
    297             ## detections, or just the image metadata, in the dvodb
    298 
    299             ## get the addstar recipe for this camera and CAMERA reduction
    300             my $command = "$ppConfigDump -camera $camera -recipe ADDSTAR $recipe_addstar -dump-recipe ADDSTAR -";
    301             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    302                 run(command => $command, verbose => $verbose);
    303             unless ($success) {
    304                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    305                 &my_die("Unable to perform ppConfigDump: $error_code", $add_id, $PS_EXIT_SYS_ERROR);
    306             }
    307             my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
    308                 &my_die("Unable to parse metadata config doc", $add_id, $PS_EXIT_SYS_ERROR);
    309 
    310             ## allow the dvodb to save only images, or the full detection set
    311             my $imagesOnly = metadataLookupBool($recipeData, 'IMAGES.ONLY');
    312 
    313             # XXX this construct requires the user to have a valid .ptolemyrc
    314             # XXX which in turn points at ippconfig/dvo.site
    315             # require a defined output dvo database to run addstar (ie, refuse to use the .ptolemyrc default)
    316             # XXX this needs to be converted to addstar_client...
    317 
    318             my $camdir = $ipprc->dvo_cameradir(); # Camera directory for addstar
    319             $command  = "$addstar -D CAMERA $camdir -update";
    320             $command .= " -image" if $imagesOnly;
    321             $command .= " -D CATDIR $dvodbReal";
    322 
    323             my $realFile = $ipprc->file_resolve($fpaObjects);
    324             $command .= " $realFile";
    325 
    326             my $mjd_addstar_start = DateTime->now->mjd;   # MJD of starting script
    327 
    328             ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    329                 run(command => $command, verbose => $verbose);
    330             unless ($success) {
    331                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    332                 &my_die("Unable to perform addstar: $error_code", $add_id, $error_code);
    333             }
    334             $dtime_addstar = 86400.0*(DateTime->now->mjd - $mjd_addstar_start);   # MJD of starting script
    335         }
    336 }
    337 
    338 
    339 my $dtime_script = (DateTime->now->mjd - $mjd_start) * 86400;
     143    if (defined $dvodbReal and ($run_state eq 'new')) {
     144        ## XXX the camera analysis can either save the full set of
     145        ## detections, or just the image metadata, in the dvodb
     146       
     147        ## get the addstar recipe for this camera and CAMERA reduction
     148        my $command = "$ppConfigDump -camera $camera -recipe ADDSTAR $recipe_addstar -dump-recipe ADDSTAR -";
     149        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     150            run(command => $command, verbose => $verbose);
     151        unless ($success) {
     152            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     153            &my_die("Unable to perform ppConfigDump: $error_code", $add_id, $PS_EXIT_SYS_ERROR);
     154        }
     155        my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
     156            &my_die("Unable to parse metadata config doc", $add_id, $PS_EXIT_SYS_ERROR);
     157       
     158        ## allow the dvodb to save only images, or the full detection set
     159        my $imagesOnly = metadataLookupBool($recipeData, 'IMAGES.ONLY');
     160       
     161        # XXX this construct requires the user to have a valid .ptolemyrc
     162        # XXX which in turn points at ippconfig/dvo.site
     163        # require a defined output dvo database to run addstar (ie, refuse to use the .ptolemyrc default)
     164        # XXX this needs to be converted to addstar_client...
     165
     166        my $camdir = $ipprc->dvo_cameradir(); # Camera directory for addstar
     167        $command  = "$addstar -D CAMERA $camdir -update";
     168        $command .= " -image" if $imagesOnly;
     169        $command .= " -D CATDIR $dvodbReal";
     170       
     171        my $realFile = $ipprc->file_resolve($fpaObjects);
     172        $command .= " $realFile";
     173       
     174        my $mjd_addstar_start = DateTime->now->mjd;   # MJD of starting script
     175       
     176        ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     177            run(command => $command, verbose => $verbose);
     178        unless ($success) {
     179            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     180            &my_die("Unable to perform addstar: $error_code", $add_id, $error_code);
     181        }
     182        $dtime_addstar = 86400.0*(DateTime->now->mjd - $mjd_addstar_start);   # MJD of starting script
     183    }
     184}
     185
    340186
    341187# This needs to be updated when addtool is written. BROKEN
     
    345191    $fpaCommand .= " -path_base $outroot";
    346192    $fpaCommand .= " $cmdflags";
    347     $fpaCommand .= " -hostname $host" if defined $host;
    348     $fpaCommand .= " -dtime_script $dtime_script";
    349193    $fpaCommand .= " -dtime_addstar $dtime_addstar";
    350194} else {
     
    390234            $command .= " -fault $exit_code";
    391235        }
    392         $command .= " -hostname $host" if defined $host;
    393236        $command .= " -dbname $dbname" if defined $dbname;
    394237        system ($command);
Note: See TracChangeset for help on using the changeset viewer.