Index: trunk/ippScripts/scripts/background_chip.pl
===================================================================
--- trunk/ippScripts/scripts/background_chip.pl	(revision 35841)
+++ trunk/ippScripts/scripts/background_chip.pl	(revision 35853)
@@ -34,4 +34,5 @@
 my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
 my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
+my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
 if ($missing_tools) {
     warn("Can't find required tools.");
@@ -134,5 +135,11 @@
 }
 my $in_wt = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $in_path, $class_id);
-my $in_bg = $ipprc->filename("PSPHOT.BACKMDL", $in_path, $class_id);
+my $in_bg;
+if (1) {
+    $in_bg = $ipprc->filename("PPIMAGE.BACKMDL", $cam_path_base, $class_id);
+}
+else {
+    $in_bg = $ipprc->filename("PSPHOT.BACKMDL", $in_path, $class_id);
+}
 my $in_pattern = $ipprc->filename("PPIMAGE.PATTERN", $in_path, $class_id);
 my $in_config = $ipprc->filename("PPIMAGE.CONFIG", $in_path, $class_id);
@@ -220,4 +227,16 @@
 }
 
+my $do_binned_images = 1;   # Generate the binned images that are useful for making JPEGs
+if ($do_binned_images) {
+    my $command = "$ppImage -file $out_image -mask $out_mask $outroot -recipe PPIMAGE PPIMAGE_PA -Db PHOTOM F";
+    my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+	run(command => $command, verbose => $verbose);
+    unless ($success) {
+	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+	&my_die("Unable to perform ppImage: $error_code", $chip_bg_id, $class_id, $error_code);
+    }
+}
+
+
 if (!$quality and !$no_op) {
     &my_die("Couldn't find expected output file: $out_image", $chip_bg_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($out_image);
Index: trunk/ippScripts/scripts/lap_science.pl
===================================================================
--- trunk/ippScripts/scripts/lap_science.pl	(revision 35841)
+++ trunk/ippScripts/scripts/lap_science.pl	(revision 35853)
@@ -309,4 +309,6 @@
     my $magicDS_update_cmd  = "magicdstool -setfiletoupdate -magic_ds_id $chip_magicDS_id -set_label $label";
     $magicDS_update_cmd    .= " -dbname $dbname " if defined $dbname;
+    my $warptool_preupdate_cmd = "warptool -revertwarped -warp_id $warp_id -fault 26";
+    $warptool_preupdate_cmd .= " -dbname $dbname " if defined $dbname;
     my $warptool_update_cmd = "warptool -setskyfiletoupdate -warp_id $warp_id -set_label $label";
     $warptool_update_cmd   .= " -dbname $dbname " if defined $dbname;
@@ -339,4 +341,12 @@
 # 	        }
 #             }
+        }
+
+
+        ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run(command => $warptool_preupdate_cmd, verbose => $verbose);
+        unless ($success) {
+            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+            &my_die("Unable to perform warptool --revertwarped: $error_code", $exposure->{exp_id}, $data_group);
         }
 
Index: trunk/ippScripts/scripts/skycell_jpeg.pl
===================================================================
--- trunk/ippScripts/scripts/skycell_jpeg.pl	(revision 35841)
+++ trunk/ippScripts/scripts/skycell_jpeg.pl	(revision 35853)
@@ -17,4 +17,5 @@
 my ($help,$masks);
 my ($tempFile,$tempName,$maskFile,$maskName);
+$verbose = 0;
 my $ppSkycell = can_run('ppSkycell') or (warn "Can't find ppSkycell" and $missing_tools = 1);
 my $warptool  = can_run('warptool') or (warn "Can't find warptool" and $missing_tools = 1);
@@ -38,5 +39,5 @@
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2) if @ARGV;
 pod2usage(
-    -msg => "Required options: --stage --stage_id --path_base\nHelpful options: --camera --dbname",
+    -msg => "Required options: --stage --stage_id --outroot\nHelpful options: --camera --dbname",
     -exitval => 3,
     ) unless
@@ -100,12 +101,12 @@
 	    }		
 	}
-	print "$skycell_id $projection_cell\n";	
+#	print "$skycell_id $projection_cell\n";	
 	my $file = $ipprc->filename("PSWARP.OUTPUT", $path_base, $skycell_id);
-	print "$file $state $quality\n";
+#	print "$file $state $quality\n";
 	my $f_fh = $tangents{$projection_cell}{FILE};
 	print $f_fh "$file\n";
 	if ($masks) {
 	    my $mask = $ipprc->filename("PSWARP.OUTPUT.MASK", $path_base, $skycell_id);
-	    print "$mask\n";
+#	    print "$mask\n";
 	    my $m_fh = $tangents{$projection_cell}{MFILE};
 	    print $m_fh "$mask\n";
@@ -118,5 +119,5 @@
 	}
 	$command .= " ${outroot}.${projection_cell} ";
-	print "$command\n";
+#	print "$command\n";
 	( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
 	unless ($success) {
@@ -197,12 +198,12 @@
 	    }		
 	}
-	print "$skycell_id $projection_cell\n";	
+#	print "$skycell_id $projection_cell\n";	
 	my $file = $ipprc->filename("PPSUB.OUTPUT", $path_base, $skycell_id);
-	print "$file $state $quality\n";
+#	print "$file $state $quality\n";
 	my $f_fh = $tangents{$projection_cell}{FILE};
 	print $f_fh "$file\n";
 	if ($masks) {
 	    my $mask = $ipprc->filename("PPSUB.OUTPUT.MASK", $path_base, $skycell_id);
-	    print "$mask\n";
+#	    print "$mask\n";
 	    my $m_fh = $tangents{$projection_cell}{MFILE};
 	    print $m_fh "$mask\n";
@@ -215,5 +216,5 @@
 	}
 	$command .= " ${outroot}.${projection_cell} ";
-	print "$command\n";
+#	print "$command\n";
 	( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
 	unless ($success) {
@@ -297,12 +298,16 @@
 		$tangents{$projection_cell}{$key}{FILE} = $tempFile;
 		$tangents{$projection_cell}{$key}{NAME} = $tempName;
+		$tangents{$projection_cell}{$key}{N}    = 0;
 	    }
 	}
 	foreach my $key (keys %products) {
-	    print "$skycell_id $projection_cell\n";	
+#	    print "$skycell_id $projection_cell\n";	
 	    my $file = $ipprc->filename($products{$key}, $path_base, $skycell_id);
-	    print "$file $state $quality\n";
+#	    print "$file $state $quality\n";
 	    my $f_fh = $tangents{$projection_cell}{$key}{FILE};
-	    print $f_fh "$file\n";
+	    if ($ipprc->file_exists($file)) {
+		print $f_fh "$file\n";
+		$tangents{$projection_cell}{$key}{N} ++;
+	    }
 	}
     }
@@ -322,15 +327,22 @@
 		$command .= " -Di BIN1 1 -Di BIN2 1 ";
 	    }
-	    elsif ($key eq 'image') {
-		$command .= " -masks $tangents{$projection_cell}{mask}{NAME} ";
-	    }
-	    elsif ($key eq 'mask') { 
-		next; # This should be made with the images.
-	    }
-	    print "$command\n";
-	    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
-	    unless ($success) {
-		$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-		&my_die("unable to perform ppSkycell: $error_code", $stage_id, $error_code);
+# 	    elsif ($key eq 'image') {
+# 		$command .= " -masks $tangents{$projection_cell}{mask}{NAME} ";
+# 	    }
+# 	    elsif ($key eq 'mask') { 
+# 		next; # This should be made with the images.
+# 	    }
+	    else {
+		# Append the image list to other objects, in case the WCS information is unpopulated
+		$command .= " -wcsref $tangents{$projection_cell}{image}{NAME} ";
+	    }
+	    if ($tangents{$projection_cell}{$key}{N} > 0) {
+		print "$command\n";
+		( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
+		unless ($success) {
+		    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+#		    print "Was unable to perform ppSkycell $stage_id $error_code $key\n";
+		    &my_die("unable to perform ppSkycell: $error_code", $stage_id, $error_code);
+		}
 	    }
 	}
