def main(): coords, mqns, smiles = load() data = {"x": [], "y": [], "c": [], "s": [], "labels": smiles} for i, _ in enumerate(coords): data["x"].append(coords[i][0]) data["y"].append(coords[i][1]) data["c"].append(mqns[i][0]) data["s"].append(random.randint(1, 5)) df = pd.DataFrame.from_dict(data) faerun = Faerun() faerun.add_scatter( "drugbank", df, shader="smoothCircle", point_scale=2.0, colormap="jet", has_legend=True, categorical=False, ) with open("example.faerun", "wb+") as f: pickle.dump(faerun.create_python_data(), f, protocol=pickle.HIGHEST_PROTOCOL) info = ( "#Welcome to Fearun", "This is a small demonstration visualising drugs stored in [Drugbank](http://drugbank.ca) using coordinates generated by a PCA projection." "", "By the way, this info was generated using markdown, this means that you can easily:", "- Add lists", "- Build tables", "- Insert images and links", "- Add code examples", "- ...", ) host( "example.faerun", label_type="smiles", legend=True, theme="light", info="\n".join(info), )
def main(): coords, mqns, smiles = load() data = {'x': [], 'y': [], 'z': [], 'c': [], 'labels': smiles} for i, _ in enumerate(coords): data['x'].append(coords[i][0]) data['y'].append(coords[i][1]) data['z'].append(coords[i][2]) data['c'].append(mqns[i][0]) df = pd.DataFrame.from_dict(data) faerun = Faerun() faerun.add_scatter('drugbank', df, shader='sphere', point_scale=5.0, colormap='jet', has_legend=True, categorical=False) with open('example.faerun', 'wb+') as f: pickle.dump(faerun.create_python_data(), f, protocol=pickle.HIGHEST_PROTOCOL) info = ( '#Welcome to Fearun', 'This is a small demonstration visualising drugs stored in [Drugbank](http://drugbank.ca) using coordinates generated by a PCA projection.' '', 'By the way, this info was generated using markdown, this means that you can easily:', '- Add lists', '- Build tables', '- Insert images and links', '- Add code examples', '- ...') host('example.faerun', label_type='default', legend=True, theme='dark', info='\n'.join(info), view='free')
def main(): f = Faerun(clear_color="#222222", coords=True, view="front") x = np.linspace(0, 12.0, 326) y = np.sin(np.pi * x) z = np.cos(np.pi * x) c = np.random.randint(0, 2, len(x)) labels = [str(l) + "__Test" for l in c] data = {"x": x, "y": y, "z": z, "c": c, "labels": labels} f.add_scatter( "helix", data, shader="smoothCircle", colormap="Dark2", point_scale=5.0, categorical=True, has_legend=True, legend_labels=[(0, "Zero"), (1, "One")], selected_labels=["None", "Just a Small Test"], ) f.add_tree("helixtree", { "from": [1, 5, 6, 7], "to": [2, 7, 8, 9] }, point_helper="helix") f.plot("helix") with open("helix.faerun", "wb+") as handle: pickle.dump(f.create_python_data(), handle, protocol=pickle.HIGHEST_PROTOCOL)
def main(): f = Faerun(title="faerun-example", clear_color="#222222", coords=False, view="free") x = np.linspace(0, 12.0, 326) y = np.sin(np.pi * x) z = np.cos(np.pi * x) c = np.random.randint(0, 2, len(x)) labels = [""] * len(c) for i, e in enumerate(c): labels[i] = str(e) + "__" + str(i % 20) data = {"x": x, "y": y, "z": z, "c": c, "labels": labels} f.add_scatter( "helix", data, shader="sphere", colormap="Dark2", point_scale=5.0, categorical=True, has_legend=True, legend_labels=[(0, "Zero"), (1, "One")], ) f.plot("helix") with open("helix.faerun", "wb+") as handle: pickle.dump(f.create_python_data(), handle, protocol=pickle.HIGHEST_PROTOCOL) def custom_label_formatter(label, index, name): return f"Example: {label} ({index}, {name})" def custom_link_formatter(label, index, name): return f"https://www.google.com/search?q={label}" info = ( "#Welcome to Fearun", "This is a small Faerun example." "", "Yay markdown! This means that you can easily:", "- Add lists", "- Build tables", "- Insert images and links", "- Add code examples", "- ...", ) host( "helix.faerun", label_type="default", title="Helix", theme="dark", label_formatter=custom_label_formatter, link_formatter=custom_link_formatter, info="\n".join(info), )
) faerun.add_scatter("cosinus", df2, shader="sphere", point_scale=5.0, colormap="jet", has_legend=True) faerun.add_scatter( "categorical", data3, shader="sphere", point_scale=5.0, colormap=["Set1", "viridis"], has_legend=True, categorical=[True, False], legend_labels=legend_labels, series_title=["A", "B"], ondblclick=["console.log(labels[0])", "console.log('B:' + labels[0])"], ) with open("index.pickle", "wb+") as handle: pickle.dump(faerun.create_python_data(), handle, protocol=pickle.HIGHEST_PROTOCOL) file = open("index.pickle", "rb") obj = pickle.load(file) file.close() faerun.plot(template="default")
def main(da, dataset_path): """ Main function """ # Initialize and configure tmap # dims = 2048 # enc = tm.Minhash(int(da.emb_dim.count()), 42, dims) # lf = tm.LSHForest(dims * 4, 256, weighted=True) # enc = tm.Minhash() # lf = tm.LSHForest(weighted=True) labels = [] image_labels = [] # data = [] # da = da.isel(scene_id=0).stack(dict(tile_id=('x', 'y'))) da = da.sel(x=slice(-1000e3, None)).stack( dict(tile_id=("x", "y", "scene_id"))) # sel(tile_id=da.tile_id.values[:100]) # scene_ids = list(da.unstack().scene_id.values) x_ = [] y_ = [] z_ = [] for tile_id in tqdm(da.tile_id.values): try: da_ = da.sel(tile_id=tile_id) i0, j0 = da_.i0.item(), da_.j0.item() try: scene_id = da_.scene_id.item() except: scene_id = tile_id[-1] # x_.append(tile_id[0]) # y_.append(tile_id[1]) fn = _get_tile_image_path(dataset_path=dataset_path, scene_id=scene_id, i0=i0, j0=j0) # img_str = base64.b64encode(open(fn, "rb").read()) # "data:image/png;base64," + str(img_str).replace("b'", "").replace("'", "") # labels.append(scene_ids.index(scene_id)) # c = da_.isel(pca_dim=3).values # c = 0 # labels.append(c) image_labels.append("get_image?path=" + str(fn)) # data.append(da_.values) except FileNotFoundError: continue # lf.batch_add(enc.batch_from_weight_array(data)) # lf.index() # x, y, s, t, _ = tm.layout_from_lsh_forest(lf) # x = np.array(x_) # y = np.array(y_) # z = np.array(z_) x = da.isel(pca_dim=0).values y = da.isel(pca_dim=1).values z = da.isel(pca_dim=2).values c = da.isel(pca_dim=3).values # from sklearn.manifold import TSNE # X = da.values.T # X_embedded = TSNE(n_components=2,).fit_transform(X) # x, y = X[:,0], X[:,1] f = Faerun( clear_color="#111111", view="front", coords=True, x_title="pca dim 0", y_title="pca dim 1", ) f.add_scatter( "EMB", { "x": x, "y": y, "z": z, "c": c, "labels": image_labels }, colormap="jet", # shader="smoothCircle", shader="sphere", point_scale=5.0, max_point_size=10, has_legend=True, categorical=False, ) # f.add_tree( # "EMB_tree", {"from": s, "to": t}, point_helper="EMB", color="#666666" # ) with open("tmap.faerun", "wb+") as handle: pickle.dump(f.create_python_data(), handle, protocol=pickle.HIGHEST_PROTOCOL)
df, shader="circle", point_scale=5.0, has_legend=True, legend_labels=[(0.0, "Low"), (50.0, "Inbetween"), (df["c"].max(), "High")], ) faerun.add_scatter( "cosinus", df2, shader="sphere", point_scale=5.0, colormap="jet", has_legend=True ) faerun.add_scatter( "categorical", data3, shader="sphere", point_scale=5.0, colormap=["Set1", "viridis"], has_legend=True, categorical=[True, False], legend_labels=legend_labels, series_title=["A", "B"], ondblclick=["console.log(labels[0])", "console.log('B:' + labels[0])"], ) with open("index.pickle", "wb+") as handle: pickle.dump(faerun.create_python_data(), handle, protocol=pickle.HIGHEST_PROTOCOL) file = open("index.pickle", "rb") obj = pickle.load(file) file.close() faerun.plot(template="default")