From 705cb69af1a1a7e5cb55c6665405f1982e17d565 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Tue, 28 Jul 2020 12:26:22 -0300 Subject: [PATCH] new release 1.1, simpler plot --- GAIA_query.py | 25 ++++++---- modules/_version.py | 2 +- modules/makePlot.py | 119 +++++++++++++++++++++++--------------------- 3 files changed, 79 insertions(+), 67 deletions(-) diff --git a/GAIA_query.py b/GAIA_query.py index d365b6f..3a9a21a 100644 --- a/GAIA_query.py +++ b/GAIA_query.py @@ -53,14 +53,19 @@ def main(): print("Filters applied, {:.1f}% of data lost".format( 100. - (len(data) * 100.) / N_old)) - print("Obtaining magnitudes/colors and their uncertainties") - mag, e_mag, col1, e_col1, col2, e_col2 = uncertMags( - data, col1_n, col2_n) - - print("Write output file in input/ folder") - writeOut.main( - clust['name'], data, mag, e_mag, col1, e_col1, col2, e_col2, - col1_n, col2_n) + if read is False: + print("Obtaining magnitudes/colors and their uncertainties") + mag, e_mag, col1, e_col1, col2, e_col2 = uncertMags( + data, col1_n, col2_n) + + print("Write output file in input/ folder") + writeOut.main( + clust['name'], data, mag, e_mag, col1, e_col1, col2, e_col2, + col1_n, col2_n) + else: + mag, e_mag, col1, e_col1, col2, e_col2 = data['Gmag'],\ + data['e_Gmag'], data[col1_n], data['e_' + col1_n],\ + data[col2_n], data['e_' + col2_n] print("Plotting") makePlot.main( @@ -71,7 +76,9 @@ def main(): mag, e_mag, col1, e_col1, col2, e_col2, data['Plx'], data['pmRA'], data['e_pmRA'], data['pmDE'], data['e_pmDE'], data['RV'], col1_n, col2_n, - babusiaux_filters) + babusiaux_filters, clust['box_s']) + + print("\nEnd") def babusiaux_filt(data): diff --git a/modules/_version.py b/modules/_version.py index 07a81e0..f04c9ab 100644 --- a/modules/_version.py +++ b/modules/_version.py @@ -1 +1 @@ -__version__ = "v1.0" \ No newline at end of file +__version__ = "v1.1" \ No newline at end of file diff --git a/modules/makePlot.py b/modules/makePlot.py index 88b142c..9e5bf2c 100644 --- a/modules/makePlot.py +++ b/modules/makePlot.py @@ -3,19 +3,18 @@ from scipy.spatial import distance import matplotlib.pyplot as plt import matplotlib.cm as cm -from matplotlib.colors import Normalize import matplotlib.offsetbox as offsetbox import matplotlib.gridspec as gridspec import warnings def main( - name, center, rad, e_mmax, e_c1max, e_c2max, plx_min, plx_max, - ra, dec, mag, e_mag, col1, e_col1, col2, e_col2, - plx, pmRA, e_pmRA, pmDE, e_pmDE, radv, col1_n, col2_n, - babusiaux_filters): + name, center, rad, e_mmax, e_c1max, e_c2max, plx_min, plx_max, ra, dec, + mag, e_mag, col1, e_col1, col2, e_col2, plx, pmRA, e_pmRA, pmDE, e_pmDE, + radv, col1_n, col2_n, babusiaux_filters, box_s, Nmax=25000): """ """ + plt.style.use('seaborn-darkgrid') fig = plt.figure(figsize=(30, 25)) gs = gridspec.GridSpec(10, 12) @@ -26,28 +25,43 @@ def main( for i, col in enumerate([ra, mag, col1, col2, plx, pmRA, radv]): # Count valid data for each column col_sizes[0].append(col_names[i]) - col_sizes[1].append(col[~col.mask].size) + try: + col_sizes[1].append(col[~col.mask].size) + except AttributeError: + col_sizes[1].append(col.size) ax1 = plt.subplot(gs[0:2, 0:2]) + ax1.set_title("Field: [{} x {}]".format(box_s, box_s), fontsize=10) ax1.bar(col_sizes[0], col_sizes[1]) fig.autofmt_xdate() + # Select at most Nmax random stars to plot + if ra.size > Nmax: + print("WARNING: too many stars ({}). Plotting {} random stars".format( + ra.size, Nmax)) + ra, dec, mag, e_mag, col1, e_col1, col2, e_col2, plx, pmRA, e_pmRA,\ + pmDE, e_pmDE, radv = random_choice( + ra, dec, mag, e_mag, col1, e_col1, col2, e_col2, plx, pmRA, + e_pmRA, pmDE, e_pmDE, radv, Nmax) + ax2 = plt.subplot(gs[0:2, 2:4]) ax2.set_title(r"$N_{{T}}={},\, rad={:.3f}\,[deg]$".format( - ra.size, rad), fontsize=8) + ra.size, rad), fontsize=10) plt.xlabel("RA [deg]") plt.ylabel("DEC [deg]") ra_min = max(min(ra), center[0] - 3. * rad) ra_max = min(max(ra), center[0] + 3. * rad) + ra_rng = ra_max - ra_min de_min = max(min(dec), center[1] - 3. * rad) de_max = min(max(dec), center[1] + 3. * rad) - msk = (ra > ra_min) & (ra < ra_max) & (dec > de_min) & (dec < de_max) - ax2.scatter(ra[msk], dec[msk], s=star_size(mag[msk]), c='k') + de_rng = de_max - de_min + rade_rng = min(ra_rng, de_rng) / 2. + ax2.scatter(ra, dec, s=star_size(mag), c='k') # Radius circle = plt.Circle(center, rad, color='red', lw=1.5, fill=False) fig.gca().add_artist(circle) - plt.xlim(ra_min, ra_max) - plt.ylim(de_min, de_max) + plt.xlim(center[0] - rade_rng, center[0] + rade_rng) + plt.ylim(center[1] - rade_rng, center[1] + rade_rng) ax2.invert_xaxis() ax4 = plt.subplot(gs[0:2, 4:6]) @@ -71,14 +85,12 @@ def main( ax5 = plt.subplot(gs[2:4, 0:2]) ax5.set_title( "N(r<{}, e_mag<{}, e_c1<{}, e_c2<{})={}".format( - rad, e_mmax, e_c1max, e_c2max, msk.data.sum()), fontsize=8) + rad, e_mmax, e_c1max, e_c2max, msk.data.sum()), fontsize=10) plt.xlabel(col1_n) plt.ylabel(mag_n) ax5.scatter(col1[msk], mag[msk], s=4, lw=.1, edgecolor='w') - # no masked elements - msk4 = (~col1[msk].mask) & (~mag[msk].mask) x_max_cmd, x_min_cmd, y_min_cmd, y_max_cmd = diag_limits( - 'mag', col1[msk][msk4], mag[msk][msk4]) + 'mag', col1[msk], mag[msk]) plt.xlim(x_min_cmd, x_max_cmd) plt.ylim(y_min_cmd, y_max_cmd) @@ -86,10 +98,8 @@ def main( plt.xlabel(col2_n) plt.ylabel(mag_n) ax6.scatter(col2[msk], mag[msk], s=4, lw=.1, edgecolor='w') - # no masked elements - msk4 = (~col2[msk].mask) & (~mag[msk].mask) x_max_cmd, x_min_cmd, y_min_cmd, y_max_cmd = diag_limits( - 'mag', col2[msk][msk4], mag[msk][msk4]) + 'mag', col2[msk], mag[msk]) plt.xlim(x_min_cmd, x_max_cmd) plt.ylim(y_min_cmd, y_max_cmd) @@ -97,10 +107,8 @@ def main( plt.xlabel(col1_n) plt.ylabel(col2_n) ax9.scatter(col1[msk], col2[msk], s=4, lw=.1, edgecolor='w') - # no masked elements - msk4 = (~col1[msk].mask) & (~col2[msk].mask) x_max_cmd, x_min_cmd, y_min_cmd, y_max_cmd = diag_limits( - 'col', col1[msk][msk4], col2[msk][msk4]) + 'col', col1[msk], col2[msk]) plt.xlim(x_min_cmd, x_max_cmd) plt.ylim(y_min_cmd, y_max_cmd) @@ -108,7 +116,7 @@ def main( print("Setting plx_min=0.") plx_min = 0. ax8 = plt.subplot(gs[4:6, 0:2]) - ax8.set_title("{} < Plx [mas] < {}".format(plx_min, plx_max), fontsize=8) + ax8.set_title("{} < Plx [mas] < {}".format(plx_min, plx_max), fontsize=10) plt.xlabel("Plx [mas]") msk2 = (d_col < rad) & (e_mag < e_mmax) &\ (e_col1 < e_c1max) & (e_col2 < e_c2max) &\ @@ -126,38 +134,26 @@ def main( ax8.add_artist(ob) plt.xlim(0., 3.) - ax7 = plt.subplot(gs[4:6, 2:4]) - ax7.set_title("N(r<, e_G<, e_XP<, -30) & (pmDE > -30) & (pmRA < 30) &\ - (pmDE < 30) & (d_col < rad) - pmRA_f, pmDE_f, epmRA_f, epmDE_f = pmRA[msk3], pmDE[msk3],\ - e_pmRA[msk3], e_pmDE[msk3] - ax3.set_title("N(r