def test_write_wizir_catalog(): d = tmpdir() fpath = path.join(d.path, 'mark_a.reg') std_catalog = get_catalog('MARK_A') sl.write_ds9_regions(std_catalog, fpath, WCS=True) cat = sl.read_ds9_regions(fpath) assert len(cat) == len(std_catalog)
def test_read_write_ds9(): s1 = sl.read_dao_file(data.ap_file()) d = tmpdir() f2 = path.join(d.path, 'i.reg') sl.write_ds9_regions(s1, f2) s2 = sl.read_ds9_regions(f2) assert s2[['id', 'x', 'y']].equals(s1[['id', 'x', 'y']]) assert not s2.auto_id.any()
def test_read_noid_reg(): reg = u""" # Region file format: DS9 version 4.1 global color=green dashlist=8 3 width=1 font="helvetica 10 normal roman" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1 image circle(869.40377,745.33678,13.888889) circle(1225.6722,742.09608,13.888889) circle(753.77706,465.33857,13.888889) circle(1034.8725,499.95079,13.888889) circle(1194.5182,211.78505,13.888889) """ regstrm = StringIO(reg) s = sl.read_ds9_regions(regstrm) assert s.id[1] == 1 assert s.x[3] == 753.77706 assert s.auto_id.all()
def test_gapick_short(): d = TmpDir() r = main( ga_max_iter=2, # just two iteration of GA ga_pop=15, # small population overwrite=True, out_dir=d.path, fine=True, ) assert (r.count() > 10) ap = read_dao_file(path.join(d.path, 'i.ap')) lst = read_dao_file(path.join(d.path, 'gen_last.lst')) coo = read_dao_file(path.join(d.path, 'i.coo')) nei = read_dao_file(path.join(d.path, 'i.nei')) reg = read_ds9_regions(path.join(d.path, 'gen_last.reg'))
def test_read_wcs_reg(): reg = u""" # Region file format: DS9 version 4.1 global color=green dashlist=8 3 width=1 font="helvetica 10 normal roman" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1 fk5 circle(21:45:00.7278,+65:45:56.751,2.275") # color=#38ACFB text={1} id=1 circle(21:45:33.1351,+65:50:07.545,2.275") # color=#38ACFB text={7} circle(21:45:41.7344,+65:45:45.371,2.275") # color=#38ACFB text={8} id=8 circle(21:45:46.9471,+65:45:43.794,2.275") # color=#38ACFB text={9} id=9 """ regstrm = StringIO(reg) s = sl.read_ds9_regions(regstrm) assert s.ra[8] == '21:45:41.7344' assert s.dec[1] == '+65:45:56.751' assert s.auto_id.any() assert not s.auto_id.all()
def test_gapick_short(): d = TmpDir() r = main( ga_max_iter = 2, # just two iteration of GA ga_pop = 15, # small population overwrite = True, out_dir = d.path, fine = False, demo=True, ) assert (r.stars_number() > 10) ap = read_dao_file(path.join(d.path, 'i.ap')) lst = read_dao_file(path.join(d.path, 'gen_last.lst')) coo = read_dao_file(path.join(d.path, 'i.coo')) nei = read_dao_file(path.join(d.path, 'i.nei')) reg = read_ds9_regions(path.join(d.path, 'gen_last.reg'))
def __do(arg): # TODO: __do arguments - in/out files/streams i = stdin o = stdout # http://stackoverflow.com/questions/14207708/ioerror-errno-32-broken-pipe-python from signal import signal, SIGPIPE, SIG_DFL signal(SIGPIPE, SIG_DFL) if arg.input_format: arg.input_format = arg.input_format.upper() if arg.output_format: arg.output_format = arg.output_format.upper() if arg.input_format == 'DS9': s = sl.read_ds9_regions(i) else: daotype = None if arg.input_format == 'COO': daotype = sl.DAO.COO_FILE elif arg.input_format == 'SHORT': daotype = sl.DAO.SHORT_FILE s = sl.read_dao_file(i, dao_type=daotype) if arg.verbose: print ('Columns of input file: {}'.format(s.columns), file=stderr) if arg.sort is not None: s.sort_values(s.columns[arg.sort], ascending=not arg.descending, inplace=True) if arg.verbose: print ('Sorting by {}'.format(s.columns[arg.sort]), file=stderr) if arg.output_format == 'DS9': sl.write_ds9_regions(s, o) else: daotype = sl.DAO.UNKNOWN_FILE if arg.output_format == 'COO': daotype = sl.DAO.COO_FILE elif arg.output_format == 'SHORT': daotype = sl.DAO.SHORT_FILE sl.write_dao_file(s, o, dao_type=daotype) return sl