Changeset 25027 for branches/pap/ippScripts/scripts/ipp_serial_mops.pl
- Timestamp:
- Aug 7, 2009, 4:08:25 PM (17 years ago)
- Location:
- branches/pap
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippScripts/scripts/ipp_serial_mops.pl (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap
- Property svn:mergeinfo changed
-
branches/pap/ippScripts/scripts/ipp_serial_mops.pl
r19717 r25027 15 15 use PS::IPP::Metadata::List qw( parse_md_list ); 16 16 use PS::IPP::Config qw( caturi ); 17 use Carp qw( carp ); 17 18 18 19 # Look for programs we need 19 20 my $missing_tools; 20 my $ mops = can_run('ipp_mops_translate.pl') or (warn "Can't find ipp_mops_translate.pl" and $missing_tools = 1);21 my $ppmops = can_run('ppMops') or (warn "Can't find ppMops" and $missing_tools = 1); 21 22 my $dsreg = can_run('dsreg') or (warn "Can't find dsreg" and $missing_tools = 1); 22 23 die "Can't find required tools.\n" if $missing_tools; … … 71 72 die "Unable to connect to database: $DBI::errstr"; 72 73 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 .= ';'; 74 my $where_label = defined $label ? "AND diffRun.label = '$label'" : ""; # WHERE for label 76 75 77 my $rows = $db->selectall_arrayref( $sql, { Slice => {} } ) or die "Unable to execute SQL: $DBI::errstr"; 78 $db->disconnect; 76 my $sql = " 77 -- Get a list of exposures on which magic may be performed 78 SELECT 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 85 FROM ( 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 113 JOIN warpRun USING(warp_id) 114 JOIN fakeRun USING(fake_id) 115 JOIN camRun USING(cam_id) 116 JOIN chipRun USING(chip_id) 117 JOIN rawExp USING(exp_id) 118 JOIN warpRun AS warpTemplate ON warpTemplate.warp_id = diffWarps.template_warp 119 JOIN fakeRun AS fakeTemplate ON fakeTemplate.fake_id = warpTemplate.fake_id 120 JOIN camRun AS camTemplate ON camTemplate.cam_id = fakeTemplate.cam_id 121 JOIN camProcessedExp AS camProcessedTemplate ON camProcessedTemplate.cam_id = camTemplate.cam_id 122 JOIN chipRun AS chipTemplate ON chipTemplate.chip_id = camTemplate.chip_id 123 JOIN rawExp AS rawTemplate ON rawTemplate.exp_id = chipTemplate.exp_id 124 WHERE rawExp.camera = '$camera' 125 GROUP BY exp_id;"; 79 126 80 print "Selected " . scalar @$rows . " rows.\n"; 127 my $diffs = $db->selectall_arrayref( $sql, { Slice => {} } ) or die "Unable to execute SQL: $DBI::errstr"; 128 129 print "Selected " . scalar @$diffs . " rows.\n"; 81 130 82 131 $ipprc->outroot_prepare( $outroot ); … … 84 133 my ($dsFile, $dsName) = tempfile( "$outrootResolved.dslist.XXXX", UNLINK => !$save_temps); 85 134 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}; 135 foreach 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}; 93 141 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); 97 144 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"; 101 147 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}; 104 151 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"; 110 171 } 111 112 # format: filename|filesize|md5sum|filetype|113 # note: since we omit filesize and md5sum, dsreg will calculate them114 print $dsFile "${output}|||ipp-mops|\n";115 172 } 116 173 close $dsFile; 174 $db->disconnect; 117 175 118 176 # Register new files with the data store
Note:
See TracChangeset
for help on using the changeset viewer.
