<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Get the data
Try GAIA and 2MASS
in gaiadr1 and gaiadr2 they also provide 2mass, allwise, sdss "best neigbour" pairs 
catalogs provided by GAIA
Step1:  Try GAIA and WISE
Step2:  Combine
Step3:  Plot W1-J vs J
<ASSISTANT_TASK:>
Python Code:
cmd = "SELECT * FROM gaiadr2.gaia_source AS g, \
gaiadr2.tmass_best_neighbour AS tbest, \
gaiadr1.tmass_original_valid AS tmass \
WHERE g.source_id = tbest.source_id AND tbest.tmass_oid = tmass.tmass_oid \
AND pmra IS NOT NULL AND abs(pmra)<3 \
AND pmdec IS NOT NULL AND abs(pmdec)<3;"
print(cmd)
job1 = Gaia.launch_job_async(cmd, dump_to_file=True)
print (job1)
gaia_2mass = job1.get_results()
print(len(gaia_2mass['source_id']))
print(gaia_2mass['ra', 'dec', 'ra_2', 'dec_2', 'phot_g_mean_mag', 'j_m']) 
Explanation: Get the data
Try GAIA and 2MASS
in gaiadr1 and gaiadr2 they also provide 2mass, allwise, sdss "best neigbour" pairs 
catalogs provided by GAIA:
gaiadr1.gaiadr1.allwise_original_valid
gaiadr1.gaiadr1.gsc23_original_valid
gaiadr1.gaiadr1.ppmxl_original_valid
gaiadr1.gaiadr1.sdssdr9_original_valid
gaiadr1.gaiadr1.tmass_original_valid
gaiadr1.gaiadr1.ucac4_original_valid
gaiadr1.gaiadr1.urat1_original_valid
End of explanation
cmd = "SELECT * FROM gaiadr2.gaia_source AS g, \
gaiadr2.allwise_best_neighbour AS wbest, \
gaiadr1.allwise_original_valid AS allwise \
WHERE g.source_id = wbest.source_id AND wbest.allwise_oid = allwise.allwise_oid AND CONTAINS(POINT('ICRS',g.ra,g.dec),\
CIRCLE('ICRS'," + str(obj_ra) + "," + str(obj_dec) + "," + str(cone_radius) + "))=1;"
print(cmd)
job2 = Gaia.launch_job_async(cmd, dump_to_file=True)
print(job2)
gaia_wise = job2.get_results()
print(len(gaia_wise['source_id']))
print(gaia_wise['ra', 'dec', 'ra_2', 'dec_2', 'phot_g_mean_mag']) 
Explanation: Try GAIA and WISE
End of explanation
sep_min = 1.0 * u.arcsec # minimum separation in arcsec
# Using GAIA coord
# ref_epoch: J2015.5
ra_2mass = gaia_2mass['ra']
dec_2mass = gaia_2mass['dec']
c_2mass = coordinates.SkyCoord(ra=ra_2mass, dec=dec_2mass, unit=(u.deg, u.deg), frame="icrs")
ra_wise  = gaia_wise['ra']
dec_wise = gaia_wise['dec']
c_wise = coordinates.SkyCoord(ra=ra_wise, dec=dec_wise, unit=(u.deg, u.deg), frame="icrs")
idx_2mass1, idx_wise1, d2d, d3d = c_wise.search_around_sky(c_2mass, sep_min)
# select only one nearest if there are more in the search reagion (minimum seperation parameter)!
print("GAIA + 2MASS + WISE (using gaia coord): ", len(idx_2mass1))
#####
# Using 2MASS and WISE coord
# ra_2 and dec_2 here are RA and DEC of 2MASS and WISE accordingly
ra_2mass = gaia_2mass['ra_2']
dec_2mass = gaia_2mass['dec_2']
c_2mass = coordinates.SkyCoord(ra=ra_2mass, dec=dec_2mass, unit=(u.deg, u.deg), frame="icrs")
ra_wise  = gaia_wise['ra_2']
dec_wise = gaia_wise['dec_2']
c_wise = coordinates.SkyCoord(ra=ra_wise, dec=dec_wise, unit=(u.deg, u.deg), frame="icrs")
idx_2mass2, idx_wise2, d2d, d3d = c_wise.search_around_sky(c_2mass, sep_min)
# select only one nearest if there are more in the search reagion (minimum seperation parameter)!
print("GAIA + 2MASS + WISE (using 2MASS-WISE coord): ", len(idx_2mass2))
print("Confusion level :", abs(len(idx_2mass1) - len(idx_2mass2))/3840. * 100, '%')
# Combine dataset
# GAIA-WISE
# GAIA-2MASS
# result of match with each other
gaia_2mass___wise = gaia_2mass[idx_2mass2] 
gaia_wise___2mass = gaia_wise[idx_wise2]
#Check
if np.all(gaia_2mass___wise['solution_id'] == gaia_wise___2mass['solution_id']):
    # remove duplicating data 
    # remove duplicating IDs in each dataset
    gaia_wise___2mass.remove_columns(['source_id_2', 'designation_2', 'allwise_oid_2'])
    gaia_2mass___wise.remove_columns(['source_id_2', 'designation_2', 'tmass_oid_2'])
    
    # remove gaia data from gaia_wise___2mas
    gaia_wise___2mass.remove_columns(['solution_id', 'designation', 'source_id', 'random_index', 'ref_epoch', 'ra', 'ra_error', 'dec', 'dec_error', 'parallax', 'parallax_error', 'parallax_over_error', 'pmra', 'pmra_error', 'pmdec', 'pmdec_error', 'ra_dec_corr', 'ra_parallax_corr', 'ra_pmra_corr', 'ra_pmdec_corr', 'dec_parallax_corr', 'dec_pmra_corr', 'dec_pmdec_corr', 'parallax_pmra_corr', 'parallax_pmdec_corr', 'pmra_pmdec_corr', 'astrometric_n_obs_al', 'astrometric_n_obs_ac', 'astrometric_n_good_obs_al', 'astrometric_n_bad_obs_al', 'astrometric_gof_al', 'astrometric_chi2_al', 'astrometric_excess_noise', 'astrometric_excess_noise_sig', 'astrometric_params_solved', 'astrometric_primary_flag', 'astrometric_weight_al', 'astrometric_pseudo_colour', 'astrometric_pseudo_colour_error', 'mean_varpi_factor_al', 'astrometric_matched_observations', 'visibility_periods_used', 'astrometric_sigma5d_max', 'frame_rotator_object_type', 'matched_observations', 'duplicated_source', 'phot_g_n_obs', 'phot_g_mean_flux', 'phot_g_mean_flux_error', 'phot_g_mean_flux_over_error', 'phot_g_mean_mag', 'phot_bp_n_obs', 'phot_bp_mean_flux', 'phot_bp_mean_flux_error', 'phot_bp_mean_flux_over_error', 'phot_bp_mean_mag', 'phot_rp_n_obs', 'phot_rp_mean_flux', 'phot_rp_mean_flux_error', 'phot_rp_mean_flux_over_error', 'phot_rp_mean_mag', 'phot_bp_rp_excess_factor', 'phot_proc_mode', 'bp_rp', 'bp_g', 'g_rp', 'radial_velocity', 'radial_velocity_error', 'rv_nb_transits', 'rv_template_teff', 'rv_template_logg', 'rv_template_fe_h', 'phot_variable_flag', 'l', 'b', 'ecl_lon', 'ecl_lat', 'priam_flags', 'teff_val', 'teff_percentile_lower', 'teff_percentile_upper', 'a_g_val', 'a_g_percentile_lower', 'a_g_percentile_upper', 'e_bp_min_rp_val', 'e_bp_min_rp_percentile_lower', 'e_bp_min_rp_percentile_upper', 'flame_flags', 'radius_val', 'radius_percentile_lower', 'radius_percentile_upper', 'lum_val', 'lum_percentile_lower', 'lum_percentile_upper', 'datalink_url', 'epoch_photometry_url'])
    # merge (hstack)
    gaia_2mass_wise = hstack([gaia_2mass___wise, gaia_wise___2mass], 
                           table_names=['2mass', 'wise'],
                           uniq_col_name='{table_name}_{col_name}')
    print("Merge...")
    print(len(gaia_2mass_wise))
else:
    print("Big Error: not match")
print(gaia_2mass_wise.colnames)
# Make a sample of galaxy using W1-J cut
w1j = gaia_2mass_wise['w1mpro'] - gaia_2mass_wise['j_m']
cutw1j = -1.7
galaxy_sample = gaia_2mass_wise[w1j<cutw1j]
# Make a sample of star using large proper motion
cut1 = gaia_2mass_wise[gaia_2mass_wise['pmra'] > 2]
star_sample = gaia_2mass_wise[gaia_2mass_wise['pmdec'] > 2]
Explanation: Combine
End of explanation
plt.scatter(gaia_2mass_wise['w1mpro'] - gaia_2mass_wise['j_m'], gaia_2mass_wise['j_m'], 
            marker='.', color='gray', alpha=0.9)
plt.scatter(galaxy_sample['w1mpro'] - galaxy_sample['j_m'], galaxy_sample['j_m'], 
            marker='s', color='red', alpha=0.1)
plt.scatter(star_sample['w1mpro'] - star_sample['j_m'], star_sample['j_m'], 
            marker='o', color='blue', alpha=0.1)
plt.gca().invert_yaxis()
# list of parameters
params = ['j_m', 'h_m', 'ks_m', 
          'w1mpro', 'w2mpro', 'w3mpro', 'w4mpro', 
          'phot_g_mean_mag', 'phot_bp_mean_mag', 'phot_rp_mean_mag']
## check Masked value
# unmasked value = 0 
# NaN, INF
ma_p = np.zeros(len(params))
for i,p in enumerate(params):
    for data in gaia_2mass_wise[p]:
        if data is ma.masked:
            ma_p[i] += 1
    
    print(p, ma_p[i])
58/3730.
np.mean(gaia_2mass_wise['phot_bp_mean_mag'])
np.where(gaia_2mass_wise['phot_bp_mean_mag'] == ma.masked)
maske = gaia_2mass_wise['phot_bp_mean_mag'][gaia_2mass_wise['phot_bp_mean_mag'] == ma.masked]
print(maske)
maske.data
x = np.array([1, 2, 3, -1, 5])
mx = ma.masked_array(x, mask=[0, 0, 0, 1, 0])
mx
mx.data
np.mean(mx.data)
np.mean(mx)
print(mx)
print(x)
a = np.copy(maske)
maske
print(a)
print(mx)
print(x)
Explanation: Plot W1-J vs J
End of explanation
<END_TASK>