IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 14, 2009, 4:46:29 PM (17 years ago)
Author:
Paul Price
Message:

Updating scripts to provide detections to MOPS following developments in diff tables and CMF file format.

File:
1 edited

Legend:

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

    r19717 r24190  
    7171    die "Unable to connect to database: $DBI::errstr";
    7272
    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 .= ';';
     73my $where_label = defined $label ? "AND label = '$label'" : ""; # WHERE for label
    7674
    77 my $rows = $db->selectall_arrayref( $sql, { Slice => {} } ) or die "Unable to execute SQL: $DBI::errstr";
    78 $db->disconnect;
     75my $sql = "
     76-- Get a list of exposures on which magic may be performed
     77SELECT
     78    exp_id,
     79    MAX(diffWarps.diff_id) AS diff_id,
     80    -- The following trick pulls out the 'inverse' value for the maximum diff_id
     81    CONVERT(SUBSTRING_INDEX(GROUP_CONCAT(diffWarps.inverse ORDER BY diffWarps.diff_id), ',', 1), UNSIGNED) AS inverse
     82FROM (
     83    -- Forward diffs
     84    SELECT
     85        diffRun.diff_id,
     86        warp1 AS warp_id,
     87        0 AS inverse
     88    FROM diffRun
     89    JOIN diffInputSkyfile USING(diff_id)
     90    WHERE diffInputSkyfile.warp1 IS NOT NULL
     91        AND diffRun.exposure = 1
     92        $where_label
     93    UNION
     94    -- Backward diffs
     95    SELECT
     96        diffRun.diff_id,
     97        warp2 AS warp_id,
     98        1 AS inverse
     99    FROM diffRun
     100    JOIN diffInputSkyfile USING(diff_id)
     101    WHERE diffInputSkyfile.warp2 IS NOT NULL
     102        AND diffRun.exposure = 1
     103        AND diffRun.bothways = 1
     104        $where_label
     105    ) AS diffWarps
     106JOIN warpRun USING(warp_id)
     107JOIN fakeRun USING(fake_id)
     108JOIN camRun USING(cam_id)
     109JOIN chipRun USING(chip_id)
     110WHERE diffRun.state = 'full'
     111    AND rawExp.camera = '$camera'
     112GROUP BY exp_id;";
    79113
    80 print "Selected " . scalar @$rows . " rows.\n";
     114my $diffs = $db->selectall_arrayref( $sql, { Slice => {} } ) or die "Unable to execute SQL: $DBI::errstr";
     115
     116print "Selected " . scalar @$diffs . " rows.\n";
    81117
    82118$ipprc->outroot_prepare( $outroot );
     
    84120my ($dsFile, $dsName) = tempfile( "$outrootResolved.dslist.XXXX", UNLINK => !$save_temps);
    85121
    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};
     122foreach my $diff ( @$diffs ) {
     123    my $exp_id = $diff->{exp_id};
     124    my $diff_id = $diff->{diff_id};
     125    my $inverse = $diff->{inverse};
    93126
    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);
     127    my $sql = "SELECT * FROM diffSkyfile WHERE diff_id = $diff_id;";
     128    my $skycells = $db->selectall_arrayref( $sql, { Slice => {} } ) or die "Unable to execute SQL: $DBI::errstr";
    97129
    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);
     130    foreach my $skycell ( @$skycells ) {
     131        my $skycell_id = $diff->{skycell_id};
     132        my $path_base = $diff->{path_base};
    101133
    102     my $output = caturi( $outroot, "mops.$exp_id.$skycell_id.$diff_id.fits" );
    103     $output = $ipprc->file_resolve($output);
     134        my $sources = $inverse ? "PPSUB.INVERSE.SOURCES" : "PPSUB.OUTPUT.SOURCES";
    104135
    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;
     136        my $input = $ipprc->filename($sources, $path_base);
     137        die "Can't find $input\n" unless $ipprc->file_exists($input);
     138        $input = $ipprc->file_resolve($input);
     139
     140        my $output = caturi( $outroot, "mops.$exp_id.$skycell_id.$diff_id.fits" );
     141        $output = $ipprc->file_resolve($output);
     142
     143        unless ($no_op) {
     144            $ipprc->file_prepare($output);
     145            my $command = "$mops --input $input --extname SkyChip.psf --output $output";
     146            my $success = run( command => $command, verbose => $verbose );
     147            die "Couldn't translate $input\n" unless $success;
     148        }
     149
     150        # format: filename|filesize|md5sum|filetype|
     151        # note: since we omit filesize and md5sum, dsreg will calculate them
     152        print $dsFile "${output}|||ipp-mops|\n";
    110153    }
    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";
    115154}
    116155close $dsFile;
     156$db->disconnect;
    117157
    118158# Register new files with the data store
Note: See TracChangeset for help on using the changeset viewer.