IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

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

Location:
branches/pap
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/pap

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

    r19717 r25027  
    1515use PS::IPP::Metadata::List qw( parse_md_list );
    1616use PS::IPP::Config qw( caturi );
     17use Carp qw( carp );
    1718
    1819# Look for programs we need
    1920my $missing_tools;
    20 my $mops = can_run('ipp_mops_translate.pl') or (warn "Can't find ipp_mops_translate.pl" and $missing_tools = 1);
     21my $ppmops = can_run('ppMops') or (warn "Can't find ppMops" and $missing_tools = 1);
    2122my $dsreg = can_run('dsreg') or (warn "Can't find dsreg" and $missing_tools = 1);
    2223die "Can't find required tools.\n" if $missing_tools;
     
    7172    die "Unable to connect to database: $DBI::errstr";
    7273
    73 my $sql = "SELECT exp_id, diff_id, skycell_id, warp_id, diffSkyfile.path_base AS diff_path_base, warpSkyfile.path_base AS warp_path_base FROM diffSkyfile JOIN diffRun using(diff_id) JOIN diffInputSkyfile USING(diff_id,tess_id,skycell_id) JOIN warpRun USING(warp_id,tess_id) JOIN warpSkyfile USING(warp_id,skycell_id,tess_id) JOIN fakeRun using(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) WHERE diffSkyfile.fault = 0 AND rawExp.camera = \'$camera\'";
    74 $sql .= " AND diffRun.label = \'$label\'" if defined $label;
    75 $sql .= ';';
     74my $where_label = defined $label ? "AND diffRun.label = '$label'" : ""; # WHERE for label
    7675
    77 my $rows = $db->selectall_arrayref( $sql, { Slice => {} } ) or die "Unable to execute SQL: $DBI::errstr";
    78 $db->disconnect;
     76my $sql = "
     77-- Get a list of exposures on which magic may be performed
     78SELECT
     79    rawExp.exp_id,
     80    MAX(diffWarps.diff_id) AS diff_id,
     81    -- The following trick pulls out the appropriate values for the maximum diff_id
     82    SUBSTRING_INDEX(GROUP_CONCAT(camProcessedTemplate.zpt_obs ORDER BY diffWarps.diff_id), ',', 1) AS zpt_obs,
     83    SUBSTRING_INDEX(GROUP_CONCAT(rawTemplate.exp_time ORDER BY diffWarps.diff_id), ',', 1) AS exp_time,
     84    CONVERT(SUBSTRING_INDEX(GROUP_CONCAT(diffWarps.inverse ORDER BY diffWarps.diff_id), ',', 1), UNSIGNED) AS inverse
     85FROM (
     86    -- Forward diffs
     87    SELECT
     88        diffRun.diff_id,
     89        warp1 AS warp_id,
     90        warp1 AS template_warp,
     91        0 AS inverse
     92    FROM diffRun
     93    JOIN diffInputSkyfile USING(diff_id)
     94    WHERE diffInputSkyfile.warp1 IS NOT NULL
     95        AND diffRun.state = 'full'
     96        AND diffRun.exposure = 1
     97        $where_label
     98    UNION
     99    -- Backward diffs
     100    SELECT
     101        diffRun.diff_id,
     102        warp2 AS warp_id,
     103        warp1 AS template_warp,
     104        1 AS inverse
     105    FROM diffRun
     106    JOIN diffInputSkyfile USING(diff_id)
     107    WHERE diffInputSkyfile.warp2 IS NOT NULL
     108        AND diffRun.state = 'full'
     109        AND diffRun.exposure = 1
     110        AND diffRun.bothways = 1
     111        $where_label
     112    ) AS diffWarps
     113JOIN warpRun USING(warp_id)
     114JOIN fakeRun USING(fake_id)
     115JOIN camRun USING(cam_id)
     116JOIN chipRun USING(chip_id)
     117JOIN rawExp USING(exp_id)
     118JOIN warpRun AS warpTemplate ON warpTemplate.warp_id = diffWarps.template_warp
     119JOIN fakeRun AS fakeTemplate ON fakeTemplate.fake_id = warpTemplate.fake_id
     120JOIN camRun AS camTemplate ON camTemplate.cam_id = fakeTemplate.cam_id
     121JOIN camProcessedExp AS camProcessedTemplate ON camProcessedTemplate.cam_id = camTemplate.cam_id
     122JOIN chipRun AS chipTemplate ON chipTemplate.chip_id = camTemplate.chip_id
     123JOIN rawExp AS rawTemplate ON rawTemplate.exp_id = chipTemplate.exp_id
     124WHERE rawExp.camera = '$camera'
     125GROUP BY exp_id;";
    79126
    80 print "Selected " . scalar @$rows . " rows.\n";
     127my $diffs = $db->selectall_arrayref( $sql, { Slice => {} } ) or die "Unable to execute SQL: $DBI::errstr";
     128
     129print "Selected " . scalar @$diffs . " rows.\n";
    81130
    82131$ipprc->outroot_prepare( $outroot );
     
    84133my ($dsFile, $dsName) = tempfile( "$outrootResolved.dslist.XXXX", UNLINK => !$save_temps);
    85134
    86 foreach my $row ( @$rows ) {
    87     my $exp_id = $row->{exp_id};
    88     my $diff_id = $row->{diff_id};
    89     my $skycell_id = $row->{skycell_id};
    90     my $warp_id = $row->{warp_id};
    91     my $diff_base = $row->{diff_path_base};
    92     my $warp_base = $row->{warp_path_base};
     135foreach my $diff ( @$diffs ) {
     136    my $exp_id = $diff->{exp_id};
     137    my $zp = $diff->{zpt_obs};
     138    my $exp_time = $diff->{exp_time};
     139    my $diff_id = $diff->{diff_id};
     140    my $inverse = $diff->{inverse};
    93141
    94     my $input = $ipprc->filename("PSPHOT.OUT.CMF.MEF", $diff_base);
    95     die "Can't find $input\n" unless $ipprc->file_exists($input);
    96     $input = $ipprc->file_resolve($input);
     142    (carp "Bad ZP or EXPTIME for $exp_id" and next) if not defined $zp or not defined $exp_time;
     143    $zp += 2.5 * log($exp_time) / log(10);
    97144
    98     my $skycell = $ipprc->filename("SKYCELL.TEMPLATE", $warp_base);
    99     die "Can't find $skycell\n" unless $ipprc->file_exists($skycell);
    100     $skycell = $ipprc->file_resolve($skycell);
     145    my $sql = "SELECT * FROM diffSkyfile WHERE diff_id = $diff_id AND fault = 0 AND quality = 0;";
     146    my $skycells = $db->selectall_arrayref( $sql, { Slice => {} } ) or die "Unable to execute SQL: $DBI::errstr";
    101147
    102     my $output = caturi( $outroot, "mops.$exp_id.$skycell_id.$diff_id.fits" );
    103     $output = $ipprc->file_resolve($output);
     148    foreach my $skycell ( @$skycells ) {
     149        my $skycell_id = $skycell->{skycell_id};
     150        my $path_base = $skycell->{path_base};
    104151
    105     unless ($no_op) {
    106         $ipprc->file_prepare($output);
    107         my $command = "$mops --input $input --extname SkyChip.psf --skycell $skycell --output $output";
    108         my $success = run( command => $command, verbose => $verbose );
    109         die "Couldn't translate $input\n" unless $success;
     152        my $sources = $inverse ? "PPSUB.INVERSE.SOURCES" : "PPSUB.OUTPUT.SOURCES";
     153
     154        my $input = $ipprc->filename($sources, $path_base);
     155        (carp "Can't find $input\n" and next) unless $ipprc->file_exists($input);
     156        $input = $ipprc->file_resolve($input);
     157
     158        my $output = caturi( $outroot, "mops.$exp_id.$skycell_id.$diff_id.fits" );
     159        $output = $ipprc->file_resolve($output);
     160
     161        unless ($no_op) {
     162            $ipprc->file_prepare($output);
     163            my $command = "$ppmops $input $zp $output";
     164            my $success = run( command => $command, verbose => $verbose );
     165            (carp "Couldn't translate $input\n" and next) unless $success;
     166        }
     167
     168        # format: filename|filesize|md5sum|filetype|
     169        # note: since we omit filesize and md5sum, dsreg will calculate them
     170        print $dsFile "${output}|||ipp-mops|\n";
    110171    }
    111 
    112     # format: filename|filesize|md5sum|filetype|
    113     # note: since we omit filesize and md5sum, dsreg will calculate them
    114     print $dsFile "${output}|||ipp-mops|\n";
    115172}
    116173close $dsFile;
     174$db->disconnect;
    117175
    118176# Register new files with the data store
Note: See TracChangeset for help on using the changeset viewer.