def blot(self): """MAIN FUNCTION Resamples the input image onto the WCS associated with the given instrument/apertures """ # Get detector names from the aperture list if isinstance(self.aperture, str): self.aperture = [self.aperture] self.detector = [element.split('_')[0] for element in self.aperture] # Make sure detector, ra, dec, and roll have same number # of elements if ((len(self.center_dec) != len(self.center_ra)) | \ (len(self.center_dec) != len(self.pav3))): raise ValueError(('WARNING: center_ra, center_dec ' 'and pav3 all must have the same number ' 'of elements.')) if type(self.blotfile) == str: input_mod = datamodels.ImageModel(self.blotfile) outbase = self.blotfile elif type(self.blotfile) == datamodels.image.ImageModel: # Not a great solution at the moment. Save # imagemodel instance so that you have a fits # file from which the header can be retrieved input_mod = copy(self.blotfile) self.blotfile.save('temp.fits') self.blotfile = 'temp.fits' outbase = 'mosaic' else: raise ValueError('WARNING: unrecognized type for blotfile') # Create a GWCS object from the input file's header input_header = fits.getheader(self.blotfile, ext=1) transform = gwcs.utils.make_fitswcs_transform(input_header) input_mod.meta.wcs = gwcs.WCS(forward_transform=transform, output_frame='world') # Filter and pupil information filtername = input_mod.meta.instrument.filter try: pupil = input_mod.meta.instrument.pupil except: pupil = 'CLEAR' # Get position angle of input data input_pav3 = input_mod.meta.wcsinfo.roll_ref # Name of temporary file output for set_telescope_pointing # to work on shellname = 'temp_wcs_container.fits' blist = [] for (aper, det, ra, dec, roll) in \ zip(self.aperture, self.detector, self.center_ra, self.center_dec, self.pav3): # Get aperture-specific info self.siaf = get_instance(self.instrument)[aper] # Create datamodel with appropriate metadata bmodel = self.make_model(det, ra, dec, input_pav3, filtername, pupil) bmodel.save(shellname, overwrite=True) # Use set_telescope_pointing to compute local roll # angle and PC matrix stp.add_wcs(shellname, roll=roll) bmodel = datamodels.open(shellname) # Now we need to run assign_wcs step so that these # files get a gwcs object attached to them. if self.distortion_file is not None: bmodel = AssignWcsStep.call( bmodel, override_distortion=self.distortion_file) else: bmodel = AssignWcsStep.call(bmodel) # Add to the list of data model instances to blot to blist.append(bmodel) # Place the model instances to blot to in a ModelContainer blot_list = container.ModelContainer(blist) # Blot the image to each of the WCSs in the blot_list pars = {'sinscl': 1.0, 'interp': 'poly5'} reffiles = {} blotter = outlier_detection.OutlierDetection(blot_list, reffiles=reffiles, **pars) blotter.input_models = blot_list self.blotted_datamodels = blotter.blot_median(input_mod)
def blot(self): # Make sure detector, ra, dec, and roll have same number # of elements if ((len(self.detector) != len(self.center_ra)) | \ (len(self.detector) != len(self.center_dec)) | \ (len(self.detector) != len(self.pav3))): print('WARNING: detector, center_ra, center_dec') print('and pav3 all must have the same number') print('of elements.') sys.exit() if type(self.blotfile) == str: input_mod = datamodels.ImageModel(self.blotfile) outbase = self.blotfile # Create a GWCS object from the input file's header #input_header = fits.getheader(self.blotfile) #transform = gwcs.utils.make_fitswcs_transform(header) #input_mod.meta.wcs = gwcs.WCS(transform) elif type(self.blotfile) == datamodels.image.ImageModel: # Not a great solution at the moment. Save # imagemodel instance so that you have a fits # file from which the header can be retrieved input_mod = copy(self.blotfile) self.blotfile.save('temp.fits') self.blotfile = 'temp.fits' outbase = 'mosaic' else: print('WARNING: unrecognized type for blotfile') sys.exit() # Create a GWCS object from the input file's header input_header = fits.getheader(self.blotfile, ext=1) transform = gwcs.utils.make_fitswcs_transform(input_header) input_mod.meta.wcs = gwcs.WCS(forward_transform=transform, output_frame='world') # Filter and pupil information filter = input_mod.meta.instrument.filter try: pupil = input_mod.meta.instrument.pupil except: pupil = 'CLEAR' # get position angle of input data input_pav3 = input_mod.meta.wcsinfo.roll_ref # parity is always -1 for nircam parity = -1 # Name of temporary file output for set_telescope_pointing # to work on shellname = 'temp_wcs_container.fits' blist = [] for (det,ra,dec,roll) in \ zip(self.detector,self.center_ra,\ self.center_dec,self.pav3): # get detector-specific info v2ref, v3ref, v3ang = self.get_siaf_info(det) # create datamodel with appropriate metadata bmodel = self.make_model(det, ra, dec, v2ref, v3ref, v3ang, parity, input_pav3, filter, pupil) #shellname = 'wcs_model_to_blot_to_{}_{}_{}_{}.fits'.format(det,ra,dec,roll) bmodel.save(shellname, overwrite=True) #tmpname = 'wcs_model_to_blot_to_BASEMODEL_{}_{}_{}_{}.fits'.format(det,ra,dec,roll) #bmodel.save(tmpname,overwrite=True) # use set_telescope_pointing to compute local roll # angle and PC matrix stp.add_wcs(shellname, roll=roll) bmodel = datamodels.open(shellname) # Now we need to run assign_wcs step so that these # files get a gwcs object attached to them. dist_reffile = [s for s in self.distfiles if det in s][0] bmodel = AssignWcsStep.call(bmodel, override_distortion=dist_reffile) #tmpname = 'wcs_model_to_blot_to_ASSIGNWCS_{}_{}_{}_{}.fits'.format(det,ra,dec,roll) #bmodel.save(tmpname,overwrite=True) # Add to the list of data model instances to blot to blist.append(bmodel) #place the model instances to blot to in a ModelContainer blot_list = container.ModelContainer(blist) #blot the image to each of the WCSs in the blot_list pars = {'sinscl': 1.0, 'interp': 'poly5'} reffiles = {} mm = outlier_detection.OutlierDetection(blot_list, reffiles=reffiles, **pars) blotted_datamodels = outlier_detection.blot_median( input_mod, blot_list, **mm.outlierpars) for (bltted,det,ra,dec,roll) in \ zip(blotted_datamodels,self.detector,self.center_ra,\ self.center_dec,self.pav3): if self.outfile is None: self.outfile = 'blotted_from_{}_to_{}_{}_{}_{}.fits'.format( outbase, det, ra, dec, roll) bltted.save(self.outfile)