<jupyter_start><jupyter_text>Plot multiple DBSCAN results<jupyter_code>import os, glob, getpass, sys
import warnings
import numpy as np
import matplotlib.pyplot as plt
from astropy.table import Table, join, vstack, hstack, Column, MaskedColumn, unique
from astropy.utils.exceptions import AstropyWarning

user = getpass.getuser()
sys.path.append('/Users/' + user + '/Dropbox/my_python_packages')
path = '../../'
from gaia.cluster_dbscan import Dbscan as Dbscan
from gaia.cluster_comparison_n import Comparison_n
import itertools
# Read data ====================================
warnings.simplefilter('ignore', AstropyWarning)
data     = Table.read(path  + 'sample_gaia/gaia_sample_cleaned.vot',       format = 'votable')
data_scl = Table.read(path  + 'sample_clusters/cl_scale/scl_standard.vot', format = 'votable')
control  = Table.read(path  + 'sample_control/OPH___control_sample.vot',  format = 'votable') ; control.label = 'Control'

len(data_scl)
# Run DBSCAN ====================================
mpts_s   = [100,    130,   160]
eps_s    = [0.373, 0.418, 0.455]
clusters = []
cl_len   = []

for i in range(len(eps_s)):
    eps  = eps_s[i]
    mpts = mpts_s[i]

    db_test = Dbscan()
    db_test.load(data = data, data_scl = data_scl.to_pandas())
    db_test.add_label()
    db_test.run_dbscan(eps=eps, mpts=mpts)
    db_test.get_clusters()
    cluster_out       = db_test.cl_array[0]
    cluster_out.label = 'mPts = ' + np.str(mpts) # This is useful for plots & histograms
    clusters.append(cluster_out)
    cl_len.append(len(cluster_out))
    
    cluster_out.write('cl_dbscan_mpts_' + np.str(mpts).zfill(3) + '.vot', format = 'votable', overwrite = True)    
# Plot Results ==================================
colors = itertools.cycle(["blue", "limegreen", "red"])
test   = Comparison_n()
test.load_clusters(control=control, cluster_list=clusters)
hists = test.plot_3_hist(x1_bins=5, x2_bins=5, x3_bins=5, fig_nm='04_plot_multi_dbscan_results_ap0.pdf', x2lim=[-20,0], x3lim=[-32.5,-17.5], 
                 linewidth=5, colors=colors, ftsize = 38,ylabel_1 = '# Objects')
# Create Table to quickly inspect the outputs ====
output            = Table(data = [['DBSCAN'] *len(mpts_s)] + [mpts_s, eps_s, cl_len], names = ['Algorithm', 'mPts', 'Eps', 'Elements'])
output['Control'] = [len(join(cluster, test.control, keys='source_id')) for cluster in test.clusters]
output.write('output_dbscan.tex', format = 'ascii.latex', overwrite = True)
output
# Plot Wise ====================================
test.read_wise_fits(path + 'sample_control/wise_RGB_img.fits')
test.plot_wise_img_3(figname='04_plot_multi_dbscan_results_ap1.pdf', markersize=9, mew=3, mec_1 = 'yellow', mec_2='lightgrey', legend_color='limegreen')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18674918092464507, 'fraction_numerical': 0.02038587550054605, 'mean_word_length': 5.1891891891891895, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '440756', 'license': 'MIT', 'n_tokens_mistral': 1033, 'n_tokens_neox': 987, 'n_words': 188, 'path': 'sample_clusters/cl_dbscan/04_plot_multi_dbscan_results.ipynb', 'repo_name': 'hectorcanovas/data_mining_Gaia_DR2', 'size': '2747'}