def combine_seg_map(self, filt, out_dir): """Combines bright and faint segmentation maps. Regions belonging to bright objects are expanded by 5 pixels""" cat_name = out_dir + '/' + filt + '_clean.cat' bright_name = out_dir + '/' + filt + '_bright_seg_map.fits' faint_name = out_dir + '/' + filt + '_faint_seg_map.fits' hdu1 = pyfits.open(bright_name) hdu2 = pyfits.open(faint_name) br = hdu1[0].data ft = hdu2[0].data hdu2.close() hdu1.close() cat = Table.read(cat_name, format='ascii.basic') new_seg = br # Expand bright regions by 5 pixels q, = np.where(cat['IS_BRIGHT'] == 1) for i in q: new_seg = fn.seg_expand(new_seg, buff=5, val=int(i) + 1, set_to=int(i) + 1) # +1 to account for renumbering q, = np.where(cat['IS_BRIGHT'] == 0) s = ft.shape for i in q: for j in range(s[0]): pix, = np.where((ft[j, :] == cat['OLD_NUMBER'][i]) & (new_seg[j, :] == 0)) new_seg[j][pix] = cat['NUMBER'][i] + 1 new_seg_name = out_dir + '/' + filt + '_comb_seg_map.fits' print "Bright faint combined seg map created at", new_seg_name pyfits.writeto(new_seg_name, new_seg, clobber=True) os.remove(bright_name) os.remove(faint_name)
def make_new_seg(self, seg_map, out_dir, out_name): """Expands bright seg map objects by params.buffer pixels """ data = pyfits.open(seg_map)[0].data new_seg = fn.seg_expand(data, buff=self.params.buffer) new_name = out_dir + '/' + out_name + "_bright_seg_map_new.fits" if os.path.isfile(new_name) is True: subprocess.call(["rm", new_name]) pyfits.writeto(new_name, new_seg)