diff --git a/docs/steps/lv3.rst b/docs/steps/lv3.rst index 673d1f1..e478cb1 100644 --- a/docs/steps/lv3.rst +++ b/docs/steps/lv3.rst @@ -8,6 +8,29 @@ For more details, see the `official documentation = len(crf_files): + log.warning( + "_blot_to_detector_frame: ref_index %d out of range (%d exposures)", + ref_index, len(crf_files), + ) + return + + log.info( + "Blotting %d resampled exposures to detector frame of %s", + len(single_files), os.path.basename(crf_files[ref_index]), + ) + + with datamodels.open(crf_files[ref_index]) as ref_model: + blot_wcs = ref_model.meta.wcs + blot_shape = ref_model.data.shape + + ref_pixflux_area = ref_model.meta.photometry.pixelarea_steradians + blot_wcs.array_shape = blot_shape + ref_pixel_area = compute_image_pixel_area(blot_wcs) + pix_ratio = np.sqrt(ref_pixflux_area / ref_pixel_area) + + for single_file in single_files: + with datamodels.open(single_file) as single_model: + blotted = gwcs_blot( + median_data=single_model.data.astype(np.float32), + median_wcs=single_model.meta.wcs, + blot_shape=blot_shape, + blot_wcs=blot_wcs, + pix_ratio=pix_ratio, + fillval=self.blot_fillval, + ) + + out_name = single_file.replace("_i2d_single.fits", "_blot_det.fits") + blot_model = datamodels.ImageModel(data=blotted) + blot_model.update(ref_model) + blot_model.meta.wcs = copy.deepcopy(blot_wcs) + save_file(blot_model, out_name=out_name, dr_version=self.dr_version) + blot_model.close() + + log.info( + " %s -> %s", + os.path.basename(single_file), + os.path.basename(out_name), + ) + + gc.collect() def propagate_metadata(self, files):