In [1]:
%matplotlib inline
import json
import os
os.environ['XPA_METHOD'] = 'local'
import numpy as np
from bubbly.viewer import BubblyViewer
from bubbly.extractors import RGBExtractor
from bubbly.cluster import merge, xmatch
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['axes.grid'] = False
In [9]:
bv = BubblyViewer()
bv.load_longitude(305)
In [2]:
import h5py
with h5py.File('../data/full_search/305.h5', 'r') as infile:
stamps = infile['stamps'][...]
scores = infile['scores'][...]
mask = np.isfinite(scores)
stamps = stamps[mask]
scores = scores[mask]
rank = np.argsort(scores)[::-1]
lohi = np.argsort(scores)
In [37]:
#data = json.load(open('../models/l305_scores.json'))
#jstamps = np.array(data['stamps'])
#jscores = np.array(data['scores'])
#jmask = (np.abs(jstamps[:, 1] - 305) < 0.5) & np.isfinite(jscores)
#jstamps = jstamps[jmask]
#jscores = jscores[jmask]
#jrank = np.argsort(scores)[::-1]
#jlohi = np.argsort(scores)
In [3]:
plt.hist(scores, histtype='step', bins=np.linspace(-1, 1, 15))
plt.yscale('log')
plt.xlabel("Scores")
plt.ylabel("N")
Out[3]:
In [4]:
ex = RGBExtractor()
ex.shp = (100, 100)
ss = np.linspace(1, -1, 20)
ss += np.random.random(ss.size) * .01
inds = lohi[np.minimum(np.searchsorted(scores[lohi], ss), lohi.size-1)]
ims = [ex.extract(*stamps[i]) for i in inds]
nx = 5
ny = int(np.ceil(inds.size / 5))
im = np.vstack(np.hstack(ims[i:i+nx]) for i in range(0, inds.size, nx))
plt.figure(figsize=(15, 15))
plt.imshow(im, origin='upper')
opts = dict(color = '#0000ff', ha='center', va='center', fontsize=18)
for i in range(inds.size):
x = (i % nx + 0.5) * ex.shp[0]
y = (i / nx + 0.5) * ex.shp[0]
plt.annotate("%0.2f" % scores[inds[i]], xy = (x, y), **opts)
In [17]:
from bubbly.field import get_field
from bubbly.util import scale
from bubbly.dr1 import bubble_params
f = get_field(305)
g = scale(f.i4[::7, ::7])
r = scale(f.mips[::7, ::7])
b = r * 0
im = np.dstack((r, g, b))
def plot_stamps(stamps, **kwargs):
kwargs.setdefault('facecolor', 'none')
kwargs.setdefault('edgecolor', 'b')
kwargs.setdefault('alpha', .1)
ax = plt.gca()
for s in stamps:
r = plt.Rectangle((s[1] - s[-1], s[2] - s[-1]), width = 2 * s[-1], height = 2 * s[-1], **kwargs)
ax.add_patch(r)
mwp = [b for b in bubble_params() if np.abs(b[1] - 305) <= .5]
unmerged = stamps[scores > .2]
merged, mscores = merge(unmerged, scores[scores > 0.2])
In [18]:
plt.figure(figsize=(10, 10), dpi=100)
plt.imshow(im, extent=[306, 304, -1, 1])
plt.axvline(304.5)
plt.axvline(305.5)
plot_stamps(unmerged)
plot_stamps(merged, edgecolor='r', alpha=1)
plt.xlim(306, 304)
plt.ylim(-1, 1)
plt.gca().set_aspect('equal')
In [19]:
match = xmatch(merged, mwp)
print 'Bubbly -> mwp: (%i)' % ((match >= 0).sum())
for i, j in enumerate(match):
if j < 0:
continue
print '%i -> %i' % (i, j)
print 'Unmatched Bubbly (%i / %i)' % ((match == -1).sum(), merged.shape[0])
print np.where(match == -1)[0].tolist()
print 'Unmatched mwp (%i / %i)' % (len(mwp) - (match >= 0).sum(), len(mwp))
z = np.zeros(len(mwp))
z[match] = 1
print np.where(z == 0)[0].tolist()
In [10]:
#bubbly in blue, MWP in red
bv.clear()
bv.outline(merged, color='red')
bv.outline(mwp)
In [20]:
order = np.argsort(mscores)[::-1]
for m, s in zip(merged[order], mscores[order]):
plt.imshow(ex.extract(*m))
plt.title(s)
plt.show()
In [ ]: