In [1]:
import booq
In [2]:
%matplotlib inline
from matplotlib import pyplot as plt
from matplotlib import cm
import numpy
plt.rcParams['figure.figsize'] = (10.0, 10.0)
In [3]:
# let's define some parameters for our mock catalogs
# to be real fake, we have to fake evrything... :(
# let's start with the size of the supposed images
# from where the sources are coming from...
sx = 300
sy = 300
# number of sources to be relative to the size of the image
num_sources = int( 0.1 * (sx*sy)/(sx+sy) )
# and, say there is an error radius
error_radius = 20
In [20]:
from booq.data import mock
from booq import coordinates
# Generate catalog A
A_image_catalog = mock.D2.generate_catalog(num_sources, error_radius, (sy,sx))
A = A_image_catalog.rename(columns={'ID':'id'})
A.loc[:,'ra'] = coordinates.pixel_to_sky(A_image_catalog.x, 0, 1.0/sx)
A.loc[:,'dec'] = coordinates.pixel_to_sky(A_image_catalog.y, 0, 1.0/sy)
# Generate catalog B
B_image_catalog = mock.D2.generate_catalog_around(A_image_catalog.sample(frac=0.75),
0.75, (sy,sx))
B = B_image_catalog.rename(columns={'ID':'id'})
B.loc[:,'ra'] = coordinates.pixel_to_sky(B_image_catalog.x, 0, 1.0/sx)
B.loc[:,'dec'] = coordinates.pixel_to_sky(B_image_catalog.y, 0, 1.0/sy)
In [21]:
from matplotlib import pyplot as plt
from booq import image
imgA = image.pil.draw_sources(A,(sy,sx),colormap='blue')
imgA = image.pil.pil_2_array(imgA)
plt.imshow(image.rgb_2_mono(imgA,'B'), cmap='Blues')
Out[21]:
In [22]:
from matplotlib import pyplot as plt
from booq import image
imgB = image.pil.draw_sources(B,(sy,sx),colormap='red')
imgB = image.pil.pil_2_array(imgB)
plt.imshow(image.rgb_2_mono(imgB,'R'), cmap='Reds')
Out[22]:
In [23]:
plt.imshow( image.pil.array_2_pil( imgA+imgB ) )
Out[23]:
In [24]:
A.describe()
Out[24]:
In [25]:
B.describe()
Out[25]:
In [26]:
from booq.coordinates.skycoords import skycoords
A_coord = skycoords(A.ra.values, A.dec.values)
B_coord = skycoords(B.ra.values, B.dec.values)
In [27]:
from booq.catalogs import xmatch
_Aidx,_Asep = xmatch.nn(A_coord,B_coord)
_Bidx,_Bsep = xmatch.nn(B_coord,A_coord)
_sep = numpy.append(_Asep.arcmin,_Bsep.arcmin)
from booq.utils import stats
_sts = stats.basic(_sep)
from booq import utils
utils.pprint(_sts)
del _Aidx,_Asep,_Bidx,_Bsep,_sep,_sts
In [28]:
from astropy.units import Quantity
radius = Quantity(8,'arcmin')
In [29]:
from booq.catalogs import xmatch
match_A_gc_idx, match_B_gc_idx, match_gc_sep = xmatch.gc(A_coord, B_coord, radius)
In [30]:
from booq import utils
utils.pprint(utils.stats.basic(match_gc_sep.arcmin))
In [31]:
from booq.pipelines import xmatch_nn
reload(xmatch_nn)
df_matched_idx = xmatch_nn.select_pairs(match_A_gc_idx, match_B_gc_idx, match_gc_sep.arcmin)
df_matched_idx
Out[31]:
In [32]:
# def recover_id(indexes,df,id_column):
# # print "input:",indexes
# inds = [ int(n) for n in indexes.split(';') ]
# # print "toint:",inds
# from numpy import unique
# ids = ';'.join(unique([ str(n) for n in df.loc[inds,id_column] ]))
# # print "toids:",ids
# # print
# return ids
# def pkg_recover_id(df,id_column):
# def pkg(indexes,df=df,id_column=id_column):
# return recover_id(indexes,df,id_column)
# return pkg
# recover_id_pkg = pkg_recover_id(B_matched,'id')
In [33]:
# AB_match = DataFrame( {'dist':df_matched_idx.separation.values},
# index=df_matched_idx.A_idx.values )
# if 'B_duplicates' in df_matched_idx.columns:
# for i,row in df_matched_idx.iterrows():
# entry = row.B_duplicates
# if entry is None:
# continue
# inds = [ int(n) for n in entry.split(';') ]
# ids = ';'.join([ str(n) for n in B.loc[inds,'id'] ])
# df_matched_idx.loc[i,'B_duplicates'] = ids
# AB_match.loc[:,'B_duplicates'] = df_matched_idx.B_duplicates.values
# B_matched = B.iloc[df_matched_idx.B_idx]
# B_matched.loc[:,'A_idx'] = df_matched_idx.A_idx.values
# B_matched = B_matched.set_index('A_idx')
# from pandas import DataFrame,concat
# df = concat([ A, B_matched, AB_match ], axis=1, keys=['A','B','AB'])
In [34]:
df = matched_catalog = xmatch_nn.merge_catalogs(A, B, df_matched_idx)
In [35]:
df
Out[35]:
In [ ]: