def run(self) -> None: """ Run method of the module. Smooths the images with a Gaussian kernel, locates the brightest pixel in each image, measures the integrated flux around the brightest pixel, calculates the median and standard deviation of the photometry, and applies sigma clipping to remove low quality images. Returns ------- NoneType None """ pixscale = self.m_image_in_port.get_attribute('PIXSCALE') nimages = self.m_image_in_port.get_shape()[0] if self.m_fwhm is not None: self.m_fwhm = int(math.ceil(self.m_fwhm / pixscale)) if self.m_position is not None and self.m_position[2] is not None: self.m_position = (self.m_position[0], self.m_position[0], int(math.ceil(self.m_position[2] / pixscale))) if len(self.m_aperture) == 2: self.m_aperture = (self.m_aperture[0], None, self.m_aperture[1] / pixscale) elif len(self.m_aperture) == 3: self.m_aperture = (self.m_aperture[0], self.m_aperture[1] / pixscale, self.m_aperture[2] / pixscale) starpos = star_positions(self.m_image_in_port, self.m_fwhm, self.m_position) phot = np.zeros(nimages) start_time = time.time() for i in range(nimages): progress(i, nimages, 'Aperture photometry...', start_time) phot[i] = self.aperture_phot(self.m_image_in_port[i, ], starpos[i, :], self.m_aperture) if self.m_method == 'median': phot_ref = np.nanmedian(phot) print(f'Median = {phot_ref:.2f}') elif self.m_method == 'max': phot_ref = np.nanmax(phot) print(f'Maximum = {phot_ref:.2f}') elif self.m_method == 'range': phot_ref = np.nanmedian(phot) print(f'Median = {phot_ref:.2f}') phot_std = np.nanstd(phot) print(f'Standard deviation = {phot_std:.2f}') if self.m_method in ['median', 'max']: index_del = np.logical_or( (phot > phot_ref + self.m_threshold * phot_std), (phot < phot_ref - self.m_threshold * phot_std)) elif self.m_method == 'range': index_del = np.logical_or((phot < self.m_threshold[0]), (phot > self.m_threshold[1])) index_del[np.isnan(phot)] = True index_del = np.where(index_del)[0] index_sel = np.ones(nimages, dtype=bool) index_sel[index_del] = False write_selected_data(memory=self._m_config_port.get_attribute('MEMORY'), indices=index_del, image_in_port=self.m_image_in_port, selected_out_port=self.m_selected_out_port, removed_out_port=self.m_removed_out_port) history = f'frames removed = {np.size(index_del)}' if self.m_index_out_port is not None: self.m_index_out_port.set_all(index_del, data_dim=1) self.m_index_out_port.copy_attributes(self.m_image_in_port) self.m_index_out_port.add_attribute('STAR_POSITION', starpos, static=False) self.m_index_out_port.add_history('FrameSelectionModule', history) write_selected_attributes(indices=index_del, image_in_port=self.m_image_in_port, selected_out_port=self.m_selected_out_port, removed_out_port=self.m_removed_out_port, module_type='FrameSelectionModule', history=history) self.m_selected_out_port.add_attribute('STAR_POSITION', starpos[index_sel], static=False) self.m_selected_out_port.add_history('FrameSelectionModule', history) self.m_removed_out_port.add_attribute('STAR_POSITION', starpos[index_del], static=False) self.m_removed_out_port.add_history('FrameSelectionModule', history) self.m_image_in_port.close_port()
def run(self) -> None: """ Run method of the module. Smooths the images with a Gaussian kernel, locates the brightest pixel in each image, measures the integrated flux around the brightest pixel, calculates the median and standard deviation of the photometry, and applies sigma clipping to remove low quality images. Returns ------- NoneType None """ self.m_selected_out_port.del_all_data() self.m_selected_out_port.del_all_attributes() self.m_removed_out_port.del_all_data() self.m_removed_out_port.del_all_attributes() if self.m_index_out_port is not None: self.m_index_out_port.del_all_data() self.m_index_out_port.del_all_attributes() pixscale = self.m_image_in_port.get_attribute('PIXSCALE') nimages = self.m_image_in_port.get_shape()[0] self.m_fwhm = int(math.ceil(self.m_fwhm / pixscale)) if self.m_position is not None and self.m_position[2] is not None: self.m_position = (self.m_position[0], self.m_position[0], int(math.ceil(self.m_position[2] / pixscale))) if len(self.m_aperture) == 2: self.m_aperture = (self.m_aperture[0], None, self.m_aperture[1] / pixscale) elif len(self.m_aperture) == 3: self.m_aperture = (self.m_aperture[0], self.m_aperture[1] / pixscale, self.m_aperture[2] / pixscale) starpos = star_positions(self.m_image_in_port, self.m_fwhm, self.m_position) phot = np.zeros(nimages) start_time = time.time() for i in range(nimages): progress(i, nimages, 'Aperture photometry...', start_time) phot[i] = self.photometry(self.m_image_in_port[i, ], starpos[i, :], self.m_aperture) if self.m_method == 'median': phot_ref = np.nanmedian(phot) print(f'Median = {phot_ref:.2f}') elif self.m_method == 'max': phot_ref = np.nanmax(phot) print(f'Maximum = {phot_ref:.2f}') phot_std = np.nanstd(phot) print(f'Standard deviation = {phot_std:.2f}') index_rm = np.logical_or( (phot > phot_ref + self.m_threshold * phot_std), (phot < phot_ref - self.m_threshold * phot_std)) index_rm[np.isnan(phot)] = True indices = np.asarray(np.where(index_rm)[0], dtype=np.int) if np.size(indices) > 0: memory = self._m_config_port.get_attribute('MEMORY') frames = memory_frames(memory, nimages) if memory == 0 or memory >= nimages: memory = nimages start_time = time.time() for i, _ in enumerate(frames[:-1]): progress(i, len(frames[:-1]), 'Writing selected data...', start_time) index_del = np.where( np.logical_and(indices >= frames[i], indices < frames[i + 1])) write_selected_data( images=self.m_image_in_port[frames[i]:frames[i + 1], ], indices=indices[index_del] % memory, port_selected=self.m_selected_out_port, port_removed=self.m_removed_out_port) else: warnings.warn('No frames were removed.') history = f'frames removed = {np.size(indices)}' if self.m_index_out_port is not None: self.m_index_out_port.set_all(np.transpose(indices)) self.m_index_out_port.copy_attributes(self.m_image_in_port) self.m_index_out_port.add_attribute('STAR_POSITION', starpos, static=False) self.m_index_out_port.add_history('FrameSelectionModule', history) # Copy attributes before write_selected_attributes is used self.m_selected_out_port.copy_attributes(self.m_image_in_port) # Copy attributes before write_selected_attributes is used self.m_removed_out_port.copy_attributes(self.m_image_in_port) write_selected_attributes(indices, self.m_image_in_port, self.m_selected_out_port, self.m_removed_out_port) indices_select = np.ones(nimages, dtype=bool) indices_select[indices] = False indices_select = np.where(indices_select) self.m_selected_out_port.add_attribute('STAR_POSITION', starpos[indices_select], static=False) self.m_selected_out_port.add_history('FrameSelectionModule', history) self.m_removed_out_port.add_attribute('STAR_POSITION', starpos[indices], static=False) self.m_removed_out_port.add_history('FrameSelectionModule', history) self.m_image_in_port.close_port()