def read_region_file(region_fn): """ Reads a region file and returns a 'region' object. """ region_file = open(region_fn, 'r') lines = region_file.readlines() region_file.close() for line in lines: if line.startswith('#'): lines.remove(line) coords = lines[1] region_str = lines[2] reg_split = region_str.split('(') reg_type = reg_split[0] params = reg_split[1].rstrip().rstrip(')').split(',') if reg_type == 'circle': x, y, r = float(params[0]), float(params[1]), float(params[2]) reg_obj = region('circle', [r], [x, y], coords) elif reg_type == 'annulus': x, y, r1, r2 = float(params[0]), float(params[1]), float( params[2]), float(params[3]) reg_obj = region('annulus', [r1, r2], [x, y], coords) return reg_obj
def make_cc_regions(event_file, source_radius_asec=30, back_rad_1_asec=60, back_rad_2_asec=90, source_fn='source.reg', back_fn='back.reg'): """ Creates the source and background region files for a given event file Arguments: - event_file: the event file to create regions for Optional Arguments: - source_radius_asec: the radius of the source region circle, in pixels - back_radius_1_asec: the inner radius of the background region annulus, in pixels - back_radius_2_asec: the outer radius of the background region annulus, in pixels - source_fn: filename of the source region - back_fn: filename of the background region """ print('Making source and background region files...\n') x, y = find_centroid(event_file) source_reg = region('circle', [source_radius_asec], [x, y], coords='physical') back_reg = region('annulus', [back_rad_1_asec, back_rad_2_asec], [x, y], coords='physical') source_reg.write(source_fn) back_reg.write(back_fn)
def make_coord_regions(event_file, source_rad, back_rad, RA, DEC, source_fn='source.reg', back_fn='back.reg'): """ Create source and background .reg files. Source is a circle of radius=source_rad and ... """ source_reg = region('circle', [source_rad], [RA, DEC], coords='fk5') back_reg = region('annulus', [100 - back_rad, 100 + back_rad], [RA, DEC], coords='fk5') source_reg.write(source_fn) back_reg.write(back_fn)
def make_wt_regions(event_file, source_rad, back_rad, source_fn='source.reg', back_fn='back.reg', chanlow=0, chanhigh=1023): """ Create source and background .reg files. Source is a circle of radius=source_rad and ... """ x, y = find_centroid(event_file, chanlow=chanlow, chanhigh=chanhigh) source_reg = region('circle', [source_rad], [x, y]) back_reg = region('annulus', [100 - back_rad, 100 + back_rad], [x, y]) source_reg.write(source_fn) back_reg.write(back_fn)
def make_pileup_regions_centroid(event_file, source_rad, back_rad, RA, DEC, pile_up_rad=3., source_fn='source.reg', back_fn='back.reg', chanlow=30, chanhigh=1023): """ Create source and background .reg files. Source is an annulus of radius=source_rad and ... """ x, y = find_centroid(event_file, chanlow=chanlow, chanhigh=chanhigh) source_reg = region('annulus', [pile_up_rad, source_rad], [x, y]) back_reg = region('annulus', [100 - back_rad, 100 + back_rad], [x, y]) source_reg.write(source_fn) back_reg.write(back_fn)