def get_streak_mask(img, pix_pts, **kwargs): #streak = Streak(gaussian_filter(img,sig_G), assert (has_astride) streak = Streak(img, output_path='.', **kwargs) streak.detect() edges = streak.streaks if not edges: return np.ones(img.shape, bool) verts = [np.vstack((edge['x'], edge['y'])).T for edge in edges] paths = [plt.mpl.path.Path(v) for v in verts] contains = np.vstack([p.contains_points(pix_pts) for p in paths]) mask = np.any(contains, 0).reshape(img_sh) return np.logical_not(mask)
def _set_streak_mask( self, **kwargs): streak = Streak(self.img, output_path='.', **kwargs) streak.detect() edges = streak.streaks if not edges: print("no edges!") self.mask =np.ones(self.img.shape, bool ) verts = [ np.vstack(( edge['x'], edge['y'])).T for edge in edges] paths = [ plt.mpl.path.Path(v) for v in verts ] contains = np.vstack( [ p.contains_points(self.pix_pts) for p in paths ]) mask = np.any( contains,0).reshape( self.img.shape) self.mask = np.logical_not(mask)
def plot_streak(img, ax, sig_G_lst=[0], **kwargs): assert (has_astride) m = np.median(img[img > 0]) s = np.std(img[img > 0]) ax.imshow(img, vmax=m + 4 * s, vmin=m - s, cmap='viridis') for sig_G in sig_G_lst: streak = Streak(gaussian_filter(img, sig_G), output_path='.', **kwargs) streak.detect() edges = streak.streaks if not edges: return 0 verts = [np.vstack((edge['x'], edge['y'])).T for edge in edges] paths = [plt.mpl.path.Path(v) for v in verts] for p in paths: patch = plt.mpl.patches.PathPatch(p, facecolor='none', lw=2, edgecolor='Deeppink') ax.add_patch(patch)
def find_streaks(): plt.style.use(astropy_mpl_style) for filename in glob.glob("*.fits"): fits.info(filename) # Read a fits image and create a Streak instance. streak = Streak(filename) # Detect streaks. streak.detect() # Write outputs and plot figures. streak.write_outputs() streak.plot_figures()
def _set_streak_mask(self, sig_G=None, **kwargs): assert (has_astride) if sig_G is not None: streak = Streak(gauss_filt(self.img, sig_G), output_path='.', **kwargs) streak.detect() else: streak = Streak(self.img, output_path='.', **kwargs) streak.detect() self.streak = streak edges = streak.streaks if not edges: self.has_streak = False self.mask = np.ones(self.img.shape, bool) self.circulaity = [] self.streak_centers = [] self.roundness = [] self.areas = [] return verts = [np.vstack((edge['x'], edge['y'])).T for edge in edges] paths = [plt.mpl.path.Path(v) for v in verts] self.streak_centers = [ [edge['y_center'], \ edge['x_center']] for edge in edges ] self.circularity = [edge['shape_factor'] for edge in edges] self.roundness = [edge['radius_deviation'] for edge in edges] self.areas = [edge['area'] for edge in edges] contains = np.vstack([p.contains_points(self.pix_pts) for p in paths]) self.streak_masks = [c.reshape(self.img.shape) for c in contains] mask = np.any(contains, 0).reshape(self.img.shape) self.mask = np.logical_not(mask) self.has_streak = True
def find_edges(img, sig_G=0, **kwargs): streak = Streak(gaussian_filter(img,sig_G), **kwargs) streak.detect() return streak.streaks
nrows=6 ncols=7 fig,axs = plt.subplots(nrows=nrows, ncols=ncols) k = 0 for row in xrange(nrows): for col in xrange( ncols): img = subs[k] ax = axs[row,col] ax.clear() ax.set_title(str(k)) ax.imshow(img, aspect='auto') # raw version streak = Streak(gaussian_filter(img,0), output_path='.', min_points=0, shape_cut=1, area_cut=10, radius_dev_cut=0., connectivity_angle=10.) streak.detect() edges = streak.streaks if edges: verts = [ np.vstack(( edge['x'], edge['y'])).T for edge in edges] paths = [ plt.mpl.path.Path(v) for v in verts ] for p in paths: patch = plt.mpl.patches.PathPatch(p, facecolor='none', lw=2, edgecolor='Deeppink') ax.add_patch(patch) # smoothed version streak = Streak(gaussian_filter(img,1.4), output_path='.',
def do_one(ff, output_path, shape, area, contour, rad, angle, remove_bkg, bkg_box_size, min_points, max_area): """ process a directory one fits-file (ff) """ try: # Read a fits image and create a Streak instance. streak = Streak(ff, output_path=output_path) # Detect streaks. # Set the parameters streak.shape_cut = shape streak.area_cut = area streak.contour_threshold = contour streak.remove_bkg = remove_bkg streak.radius_dev_cut = rad streak.connectivity_angle = angle streak.remove_bkg = remove_bkg streak.bkg_box_size = bkg_box_size streak.min_points = min_points streak.detect() # filter out the detections that are too big for edge in streak.streaks: if edge['area'] > max_area: streak.streaks.remove(edge) n = len(streak.streaks) except: n = -1 if n > 0: # Write outputs and plot figures. streak.write_outputs() streak.plot_figures() if n == 0: sys.stdout.write('.') elif n < 0: sys.stdout.write('X') elif n < 10: sys.stdout.write('%d' % n) else: sys.stdout.write('*') sys.stdout.flush() return n
def do_one(ff, output_path=None, shape=None, area=None, contour=None): """ process a directory one fits-file (ff) """ # Read a fits image and create a Streak instance. streak = Streak(ff, output_path=output_path) # Detect streaks. # streak.shape_cut = .14 # streak.area_cut = 120 # streak.contour_threshold = 12 #Customization of values streak.shape_cut = shape streak.area_cut = area streak.contour_threshold = contour streak.detect() # Write outputs and plot figures. streak.write_outputs() streak.plot_figures() streakfile = output_path + "/streaks.txt" fp = open(streakfile) lines = fp.readlines() fp.close() #print("streaks found %d" % (len(lines)-1)) #print("%d " % (len(lines)-1)) n = len(lines) - 1 if n == 0: sys.stdout.write('.') elif n < 10: sys.stdout.write('%d' % n) else: sys.stdout.write('*') sys.stdout.flush() #Delete/move files #if n == 0: # shutil.rmtree(output_path) return int(n) #def do_one(ff,output_path=None,shape=None,area=None,contour=None): BACKUP """ process a directory one fits-file (ff) """ # Read a fits image and create a Streak instance. streak = Streak(ff, output_path=output_path) # Detect streaks. # streak.shape_cut = .14 # streak.area_cut = 120 # streak.contour_threshold = 12 #Customization of values streak.shape_cut = shape streak.area_cut = area streak.contour_threshold = contour streak.detect() # Write outputs and plot figures. streak.write_outputs() streak.plot_figures() streakfile = output_path + "/streaks.txt" fp = open(streakfile) lines = fp.readlines() fp.close() #print("streaks found %d" % (len(lines)-1)) #print("%d " % (len(lines)-1)) n = len(lines) - 1 if n == 0: sys.stdout.write('.') elif n < 10: sys.stdout.write('%d' % n) else: sys.stdout.write('*') sys.stdout.flush() #Delete/move files if n == 0: shutil.rmtree(output_path) return int(n)