def _get_kernel_data(self, data, subkernel=True): self.fold(data) if self.kernel is None: raise PSFErr('notset') kernel = self.kernel dep = None indep = None lo = None hi = None if isinstance(kernel, Data): dep = numpy.asarray(kernel.get_dep()) indep = kernel.get_indep() elif callable(kernel): dep = kernel(*self.model.args, **self.model.kwargs) indep = self.model.args kshape = self.model.kshape if subkernel: (dep, newshape) = self.model.init_kernel(dep) if (numpy.array(kshape) != numpy.array(newshape)).any(): newindep = [] for axis in indep: args = extract_kernel(axis, self.model.kshape, self.model.size, self.model.center, self.model.lo, self.model.hi, self.model.width, self.model.radial) newaxis = args[0] lo = args[3] # subkernel offsets (lower bound) hi = args[4] # subkernel offsets (upper bound) newindep.append(newaxis) indep = newindep kshape = newshape if self.model.frac is not None: info('PSF frac: %s' % self.model.frac) if numpy.isscalar(kshape): kshape = [kshape] return (indep, dep, kshape, lo, hi)
def init_kernel(self, kernel): # If PSF dataset, normalize before kernel extraction # if not self.is_model and self.norm: if self.norm: kernel = normalize(kernel) (kernel, kshape, self.frac, lo, hi) = extract_kernel(kernel, self.kshape, self.size, self.center, self.lo, self.hi, self.width, self.radial) # If PSF model, then normalize integrated volume to 1, after # kernel extraction # if self.is_model and self.norm: # self.frac = 1.0 # kernel = normalize(kernel) # Find brightest pixel of PSF--assume that is the origin # Just assuming that the origin is half of szs1 can lead to # unwanted pixel shifts--but this assumes that origin should # be centered on brightest pixel. brightPixel = list(numpy.where(kernel == kernel.max())).pop() # if more than one pixel qualifies as brightest, such as const2D # use the middle of subkernel -- assumes the user provided center at # time of kernel extraction, so that should be middle of subkernel. origin = None if (not numpy.isscalar(brightPixel)) and len(brightPixel) != 1: origin = set_origin(kshape) else: # brightPixel is a NumPy index (int64) which - as of NumPy 1.18 # and Python 3.8 - causes a TypeError with the message # "only integer scalar arrays can be converted to a scalar index" # to be thrown here if sent directly to set_origin. So # we convert to a Python integer type. # origin = set_origin(kshape, int(brightPixel)) if self.origin is None: self.origin = origin if self.is_model and not self.frozen: # if the kernel model has thawed parameters, clear the old FFT and # recompute the kernel FFT at each model evaluation self._tcd.clear_kernel_fft() return (kernel, kshape)
def init_kernel(self, kernel): # If PSF dataset, normalize before kernel extraction # if not self.is_model and self.norm: if self.norm: kernel = normalize(kernel) (kernel, kshape, self.frac, lo, hi) = extract_kernel(kernel, self.kshape, self.size, self.center, self.lo, self.hi, self.width, self.radial) # If PSF model, then normalize integrated volume to 1, after # kernel extraction # if self.is_model and self.norm: # self.frac = 1.0 # kernel = normalize(kernel) # Find brightest pixel of PSF--assume that is the origin # Just assuming that the origin is half of szs1 can lead to # unwanted pixel shifts--but this assumes that origin should # be centered on brightest pixel. brightPixel = list(numpy.where(kernel == kernel.max())).pop() origin = None # if more than one pixel qualifies as brightest, such as const2D # use the middle of subkernel -- assumes the user provided center at # time of kernel extraction, so that should be middle of subkernel. if (not numpy.isscalar(brightPixel)) and len(brightPixel) != 1: origin = set_origin(kshape) else: origin = set_origin(kshape, brightPixel) if self.origin is None: self.origin = origin if self.is_model and not self.frozen: # if the kernel model has thawed parameters, clear the old FFT and # recompute the kernel FFT at each model evaluation self._tcd.clear_kernel_fft() return (kernel, kshape)