Changeset 34041 for branches/meh_branches/ppstack_test/tools/dlapstacks
- Timestamp:
- Jun 19, 2012, 5:24:19 PM (14 years ago)
- Location:
- branches/meh_branches/ppstack_test
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
tools/dlapstacks (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/meh_branches/ppstack_test
- Property svn:mergeinfo changed
-
branches/meh_branches/ppstack_test/tools/dlapstacks
r33415 r34041 4 4 use warnings; 5 5 6 # given an RA and DEC lookup find the LAP stack images 7 8 # XXX: consider making these options these could be made options I guess 9 6 # given an RA and DEC or a skycell_id find the LAP stack images containing them 7 # and display using ds9 8 9 # XXX: consider accepting a string of parameters to be passed to ds9 10 # add --fit set ds9 to fit to frame 11 # XXX if label is supplied by the user and it is like MD% 12 # guess at the tess_id 13 # allow mask and variance images to be displayed as well 14 15 my $label = 'LAP.ThreePi.20110809'; 10 16 my $tess_id = 'RINGS.V3'; 11 my $label = 'LAP.ThreePi.20110809';12 17 13 18 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); … … 15 20 use DBI; 16 21 use PS::IPP::Config 1.01 qw( :standard ); 17 18 my $ipprc = PS::IPP::Config->new(); 22 use File::Temp qw( tempfile tempdir ); 23 use File::Basename; 24 use IPC::Cmd 0.36 qw( can_run run ); 25 26 my $ipprc = PS::IPP::Config->new(); 19 27 my $dbh = getDBHandle(); 20 28 21 22 29 my ($requested_filter, $no_display, $skycell_id, $verbose, $ra, $dec, $convolved); 23 30 my ($singleframe, $fitToFrame, $deasin, $save_temps, $data_group); 31 32 # XXX: get this from the ipprc 33 my $temproot = '/local/ipp/tmp'; 34 my $outdir; 24 35 25 36 GetOptions( 26 'filter|f=s' => \$requested_filter, 27 'convolved' => \$convolved, 28 'no-display|n' => \$no_display, 29 'skycell_id=s' => \$skycell_id, 30 'verbose|v' => \$verbose, 37 'filter|f=s' => \$requested_filter, # restrict to a single filter 38 'skycell_id|s=s'=> \$skycell_id, # specificly sset skycell_id of interest 39 'convolved|c' => \$convolved, # display convolved stack images instead of unconvolved 40 'fit' => \$fitToFrame, # scale the images to fit the ds9 frame 41 'single' => \$singleframe, # set ds9 to singleframe mode 42 'deasin|d' => \$deasin, # run ppstamp to remove the ASIN scaling from the stacks 43 'label|l=s' => \$label, # use a different label (careful!) 44 'data_group=s' => \$data_group, # select stacks by data_group 45 'tess_id|t=s' => \$tess_id, # set tess_id 46 'outdir|o=s' => \$outdir, # if deasin save de-asined images to given directory 47 'no-display|n' => \$no_display, # don't run ds9 just print the nebulous pathnames 48 'save-temps' => \$save_temps, # save temporary files 49 'verbose|v' => \$verbose, # print lots of information 31 50 ) or pod2usage( 2 ); 32 51 … … 36 55 $ra = shift; 37 56 $dec = shift; 57 58 pod2usage( -msg => 'if ra is suplied <dec> must be supplied as well', -exitval => 2) 59 if (defined $ra and ! defined $dec); 60 61 if ($skycell_id and !($skycell_id =~ /^skycell/)) { 62 if (length($skycell_id) < 3) { 63 # two character skycell_id NM should probably be 0NM 64 $skycell_id = "0$skycell_id"; 65 } 66 $skycell_id = "skycell.$skycell_id"; 67 } 68 69 my $missing_tools; 70 my $ppstamp; 71 my $ds9; 72 if ($deasin) { 73 $ppstamp = can_run('ppstamp') or (warn "Can't find ppstamp") and $missing_tools = 1; 74 } 75 if (!$no_display) { 76 $ds9 = can_run('ds9') or (warn "Can't find ds9") and $missing_tools = 1; 77 } 78 if ($missing_tools) { 79 # warn("Can't find required tools."); 80 exit($PS_EXIT_CONFIG_ERROR); 81 } 38 82 39 83 my $extension; … … 44 88 } 45 89 46 # run whichimage to find a list of skycells containing the given coordinates 47 my $whichimage_output = `whichimage --listchipcoords --tess_id $tess_id $ra $dec`; 48 49 print $whichimage_output if $verbose; 50 51 my @results = split "\n", $whichimage_output; 52 53 die "whichimage returned no output\n" if scalar @results == 0; 54 55 my $query = "SELECT skycell_id, filter, stack_id, quality, path_base 90 # don't allow MD label unless it's a refstack. 91 # Nightly stacks have too many images 92 if (($data_group && ($data_group =~ /MD/)) or ($label =~ /^MD/)) { 93 unless ($data_group or uc($label) =~ /REF/) { 94 die "cannot use this program for label $label without data_group because that will most likely select nightly stacks and we will match an unreasonably large number of matches. Talk to Bill\n"; 95 } 96 # if tess_id hasn't been set to an MD field, guess that it's a V3 stack 97 unless ($tess_id =~ /MD/) { 98 my $tag = $data_group ? $data_group : $label; 99 my $field = substr $tag, 0, 4; 100 $tess_id = "$field.V3"; 101 print "Setting tess_id to $tess_id\n"; 102 } 103 } 104 105 my $whichimage_output; 106 if (!$skycell_id or (defined $ra and defined $dec)) { 107 # run whichimage to find a list of skycells containing the given coordinates and the 108 # image coordinates of the requested sky coordinates 109 $whichimage_output = `whichimage --listchipcoords --tess_id $tess_id $ra $dec`; 110 111 print "Output from whichimage:\n$whichimage_output\n" if $verbose; 112 113 my @results = split "\n", $whichimage_output; 114 115 die "whichimage returned no output\n" if scalar @results == 0; 116 } else { 117 # we were supplied a skycell create a fake whichimage_output that can be parsed below 118 $whichimage_output = "0 0 dummy $skycell_id -1 -1\n"; 119 } 120 121 my $query = "SELECT skycell_id, filter, stack_id, quality, state, path_base 56 122 FROM stackRun join stackSumSkyfile USING(stack_id) 57 WHERE stackRun.state ='full' AND label = '$label' AND skycell_id = ?"; 123 WHERE stackRun.state ='full' AND skycell_id = ?"; 124 if ($data_group) { 125 $query .= " AND data_group = '$data_group'"; 126 } else { 127 $query .= " AND label = '$label'"; 128 } 58 129 59 130 if ($requested_filter) { … … 69 140 70 141 # @files will contain the list of skycells found in order of skycell_id, filter. 71 # The sewill be displayed in this order so that the image frames are in order of increasing bandpass142 # The images will be displayed in this order so that the image frames are in order of increasing bandpass 72 143 my @files = (); 73 144 … … 81 152 foreach (split "\n", $whichimage_output) { 82 153 chomp; 154 83 155 my ($radeg, $decdeg, undef, $skycell, $x, $y) = split " "; 84 print "$skycell $radeg $decdeg\n" if $verbose; 156 157 print "skycell: $skycell RA (deg): $radeg DEC (deg): $decdeg (X,Y): ($x, $y)\n" if $verbose; 158 85 159 $stmt->execute($skycell) or die $stmt->errstr; 86 160 my $files_found = 0; 87 161 while (my $f = $stmt->fetchrow_hashref()) { 88 162 next if $f->{quality}; 163 next if $f->{state} ne 'full'; 164 89 165 my $filter = $f->{filter}; 90 166 my $stack_id = $f->{stack_id}; 91 167 my $path_base = $f->{path_base}; 168 92 169 # save the skycell coordinates so we can pan efficiently below 93 170 $f->{X} = $x; 94 171 $f->{Y} = $y; 95 172 96 # Find where this filter goes in the array 173 # Find where this filter goes in the array of files 97 174 my $i = $index{$filter}; 98 175 if (!defined $i) { … … 100 177 next; 101 178 } 102 # if multiple skycells match the coordinates bump the index 179 # if multiple skycells match the coordinates bump the index by $num_filters 103 180 $i += $skycells * $num_filters; 104 181 $files[$i] = $f; … … 112 189 113 190 if (!$total_files) { 114 print "no files found\n";191 print "no matching stacks found\n"; 115 192 exit 1; 116 193 } … … 118 195 119 196 if (!$no_display) { 120 # estimate of image size for the case where we have 5 frames 121 my $imagesize = 680; 122 # my $panargs = "-pan to $ra $dec wcs fk5"; 197 my $imagesize; 198 if ($singleframe) { 199 $imagesize = 1024; 200 } else { 201 # estimate of image size for the case where we have 5 frames 202 $imagesize = 680; 203 } 204 my $tempdir; 205 if (!$outdir) { 206 $tempdir = tempdir ("$temproot/dlapstacks.temp.XXXX", CLEANUP => !$save_temps); 207 } 208 if ($deasin) { 209 if ($outdir) { 210 print "Saving deasined files to $outdir\n" if $verbose; 211 # user specified output directory save the files there 212 if (!-d $outdir) { 213 mkdir $outdir or die "failed to mkdir $outdir\n"; 214 } 215 } else { 216 # otherwise use a temporary directory 217 $outdir = $tempdir; 218 print "deasined files will be saved to $outdir\n" if $save_temps; 219 } 220 } 221 # Build the ds9 argument list 123 222 my @args; 223 my $panargs = ""; 124 224 foreach my $f (@files) { 125 225 next if ! $f; 126 my $filename = $f->{path_base} . ".$extension"; 127 my $resolved = $ipprc->file_resolve($filename); 128 next if !$resolved; 129 my $panargs = "-pan to $f->{X} $f->{Y}"; 130 226 my $pathname = $f->{path_base} . ".$extension"; 227 my $filename = $ipprc->file_resolve($pathname); 228 next if !$filename; 229 230 # prefix file name with filter 231 # this will either be the ppstamp output filename or we 232 # will put a symlink to it in tempdir 233 my $base = basename($pathname); 234 my $filt = substr $f->{filter}, 0, 1; 235 $base = "$filt.$base"; 236 if ($deasin) { 237 # run ppstamp to undo the asin scaling. The output from ppstamp is linear F32 images 238 239 # drop the .fits for the output path for ppstamp 240 my $destbase = $base; 241 $destbase =~ s/\.fits//g; 242 243 244 my $command = "$ppstamp -wholefile -file $filename $outdir/$destbase"; 245 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 246 run(command => $command, verbose => $verbose); 247 unless ($success) { 248 print STDERR join "", @$stderr_buf; 249 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 250 die("Unable to perform ppstamp: $error_code\n"); 251 } 252 253 # new filename for ds9 254 $filename = "$outdir/$base"; 255 } else { 256 my $nebname = $filename; 257 $filename = "$tempdir/$base"; 258 symlink $nebname, $filename or die "failed to symlink $nebname"; 259 } 260 261 if ($f->{X} > 0) { 262 $panargs = "-pan to $f->{X} $f->{Y}"; 263 } else { 264 $panargs = ""; 265 } 266 267 # The following is an attempt put the filter name in the image using a region with text a label. 131 268 my $xlabel = $f->{X} + $imagesize / 2; 132 269 my $ylabel = $f->{Y} + $imagesize / 2; 133 # The following is an attempt put the filter name in the image using a region with text a label. 270 134 271 # I couldn't make this work. The circle would appear but without the text 135 272 # my $label = " -regions command 'circle($xlabel,$ylabel,1)' # text={ $f->{filter} }"; … … 140 277 # $panargs .= $label; 141 278 142 push @args, ($resolved, $panargs); 143 } 144 my $ds9cmd = "ds9 -geom 1024x1024 @args"; 279 # I used to pan each frame but it turns out to be quicker to wait until the last image is 280 # loaded. pan thatone and then matching the wcs for the frames. 281 # Also that allows V0 and V3 skycells to have east to the left orientation 282 # push @args, ($filename, $panargs); 283 push @args, $filename; 284 } 285 my $ds9cmd = "$ds9 -geom 1024x1024 @args $panargs"; 286 $ds9cmd .= " -single" if $singleframe; 287 $ds9cmd .= " -zoom to fit" if $fitToFrame; 288 $ds9cmd .= " -match frames wcs"; 289 $ds9cmd .= " -frame first" if $singleframe; 145 290 print "$ds9cmd\n" if $verbose; 146 291 system $ds9cmd; 147 292 } else { 293 # no-display option Just print out some information 294 print "\n" if $verbose; 295 print "Skycell ID stack_id filter path_base\n"; 296 print "------------------------------------------------------------------------------------------\n"; 148 297 foreach my $f (@files) { 149 298 next if !$f; 150 print "$f->{skycell_id} $f->{stack_id} $f->{filter}$f->{path_base}\n";299 print "$f->{skycell_id} $f->{stack_id} $f->{filter} $f->{path_base}\n"; 151 300 } 152 301 } … … 173 322 } 174 323 324 __END__ 325 326 =pod 327 =head1 NAME 328 dlapstacks - display stack images from the PS1 first Grand Reprocessing (LAP) 329 330 =head1 SYNOPSIS 331 332 dlapstacks <ra> <decl> [options] 333 dlapstacks --skycell_id <skycell_id> [<ra> <decl>] [options] 334 335 336 =head1 DESCRIPTION 337 338 Query the gpc1 database to find stacks containing a given RA and DEC or for a specific skycell_id. 339 Display the images using ds9. If coordinates are supplied the display is centered there. 340 341 =head1 OPTIONS 342 343 =over 4 344 345 =item * -s, --skycell_id <skycell_id> 346 347 The skycell_id to display. Note if skycell_id does not begin with "skycell", "skycell" is prepended to the supplied value before querying the database. 348 349 350 =item * <ra> 351 352 Right Ascension. Format: decimal degrees or HH:MM:SS 353 Required unless skycell_id is supplied 354 355 356 =item * <decl> 357 358 Declination. Format: decimal degrees or DD:MM:SS 359 Required unless skycell_id is supplied 360 361 =item * -f, --filter <filter> 362 363 Only display images for the given filter. The SQL wild card character '%' is appended to single character values. 364 365 =item * -c, --convolved 366 367 Display convolved stacks. Default is to display unconvolved stack images. 368 369 =item * --fit 370 371 Instruct ds9 to fit the image to the frame. 372 373 =item * --single 374 375 Set ds9 to single frame mode 376 377 =item * -d, --deasin 378 379 Display images tha have had the ASIN scaling removed. 380 381 =item *-o, --outdir <outdir> 382 383 If --deasin is selected the unscaled images are preserved in the provided directory. 384 The directory created if it does not exist. 385 386 =item * -l, --label <label> 387 388 Chose stacks with the provided label. The default is LAP.ThreePi.20110809. 389 NOTE: If the label begins with MD and --data_group is not provided the label must contain "ref" or "REF". This prevents 390 users from selecting the hundreds of nightly stack images. 391 392 =item * --data_group <data_group> 393 394 Select stacks with the provided data_group. By default stacks are selected by label. 395 396 397 =item * -t, --tess_id <tess_id> 398 399 Set the tessellation that skycells are selected from. Default is RINGS.V3 400 unless a label or data group that begins with MDnm is supplied. In that case the default is 401 MDnm.V3 402 403 =item * -n, --no-display 404 405 Look up the stack images using the provided parameters but rather than displaying them with ds9 print out some information about the stacks. 406 407 =item * --save-temps 408 409 If --deasin is supplied and --outdir is not supplied do not delete temporary images. (For debugging). 410 411 =item * -v, --verbose 412 413 Print information about the progress of the program. 414 415 =cut
Note:
See TracChangeset
for help on using the changeset viewer.
