def get_region(assoc_name, gagne_reference_data = None): if gagne_reference_data is None: gagne_reference_data =\ '../data/gagne_bonafide_full_kinematics_with_lit_and_best_radial_velocity' \ '_comb_binars_with_banyan_radec.fits' gagne_table = tabletool.read(gagne_reference_data) if assoc_name not in set(gagne_table['Moving group']): raise UserWarning,\ 'Association name must be one of:\n{}\nReceived: "{}"'.format( list(set(gagne_table['Moving group'])), assoc_name ) # Dummy comment # Extract all stars subtable = gagne_table[np.where(gagne_table['Moving group'] == assoc_name)] star_means = tabletool.build_data_dict_from_table(subtable, only_means=True) data_upper_bound = np.nanmax(star_means, axis=0) data_lower_bound = np.nanmin(star_means, axis=0) data_span = data_upper_bound - data_lower_bound data_centre = 0.5 * (data_upper_bound + data_lower_bound) # Set up boundaries of box that span double the association box_lower_bound = data_centre - data_span box_upper_bound = data_centre + data_span return box_lower_bound, box_upper_bound
sys.path.insert(0, '../../') from chronostar.component import SphereComponent from chronostar import tabletool from chronostar import expectmax from astropy.table import Table, vstack, join ##### FILENAMES ############################################################ datafile = 'data/scocen_data_with_broken_radial_velocities.fits' #datafile = 'data/scocen_data_with_original_radial_velocities.fits' output_filename = datafile.replace('data/', 'results/').replace( '.fits', '_with_membership.fits') comps_filename = 'data/all_nonbg_scocen_comps_unique.npy' ############################################################################ data_table = tabletool.read(datafile) # This table is masked. Unmask: data_table = data_table.filled() print('DATA READ', len(data_table)) historical = 'c_XU' in data_table.colnames ############################################################################ ############ COMPONENT OVERLAPS ############################################ ############################################################################ print('Create data dict') # Create data dict data_dict = tabletool.build_data_dict_from_table( data_table,
# and the data prep has already been done if (config.config['data_savefile'] != '' and os.path.isfile(config.config['data_savefile'])): log_message('Loading pre-prepared data (with background)') data_table = tabletool.load(config.config['data_savefile']) historical = 'c_XU' in data_table.colnames # Otherwise, perform entire process else: # Construct synthetic data if required datafile = config.config['data_loadfile'] assert os.path.exists(datafile) # Read in data as table log_message('Read data into table') data_table = tabletool.read(datafile) # historical = 'c_XU' in data_table.colnames # column names... historical = False log_message('Data table has {} rows'.format(len(data_table))) # data_table['radial_velocity'] = data_table['radial_velocity_best'] # data_table['radial_velocity_error'] = data_table['radial_velocity_error_best'] # # By the end of this, data will be a astropy table # with cartesian data written in # columns in default way. if config.config['convert_to_cartesian']: print('Converting to cartesian')
def get_region(assoc_name, pos_margin=30., vel_margin=5., scale_margin=None, gagne_reference_data=None): """ Get a 6D box surrounding a known association with members from BANYAN Parameters ---------- assoc_name: str Name of the association as listed in BANYAN table. One of: {'118 Tau', '32 Orionis', 'AB Doradus', 'Carina', 'Carina-Near', 'Columba', 'Coma Ber', 'Corona Australis', 'Hyades', 'IC 2391', 'IC 2602', 'Lower Centaurus-Crux', 'Octans', 'Platais 8', 'Pleiades', 'TW Hya', 'Taurus', 'Tucana-Horologium', 'Upper Centaurus Lupus', 'Upper CrA', 'Upper Scorpius', 'Ursa Major', 'beta Pictoris', 'chi{ 1 For (Alessi 13)', 'epsilon Cha', 'eta Cha', 'rho Ophiuci'} pos_margin: float {30.} Margin in position space around known members from which new candidate members are included vel_margin: float {5.} Margin in velocity space around known members from which new candidate members are included gagne_reference_data: str filename to BANYAN table Returns ------- box_lower_bounds: [6] float array The lower bounds of the 6D box [X,Y,Z,U,V,W] box_upper_bounds: [6] float array The upper bounds of the 6D box [X,Y,Z,U,V,W] """ if gagne_reference_data is None: gagne_reference_data =\ '../data/gagne_bonafide_full_kinematics_with_lit_and_best_radial_velocity' \ '_comb_binars_with_banyan_radec.fits' gagne_table = tabletool.read(gagne_reference_data) if assoc_name not in set(gagne_table['Moving group']): raise UserWarning( 'Association name must be one of:\n{}\nReceived: "{}"'.format( list(set(gagne_table['Moving group'])), assoc_name)) # Extract all stars subtable = gagne_table[np.where(gagne_table['Moving group'] == assoc_name)] logging.info('Initial membership list has {} members'.format( len(subtable))) star_means = tabletool.build_data_dict_from_table(subtable, only_means=True) data_upper_bound = np.nanmax(star_means, axis=0) data_lower_bound = np.nanmin(star_means, axis=0) logging.info('Stars span from {} to {}'.format(np.round(data_lower_bound), np.round(data_upper_bound))) # First try and scale box margins on. # scale_margin of 1 would double total span (1 + 1) if scale_margin is not None: data_span = data_upper_bound - data_lower_bound box_margin = 0.5 * scale_margin * data_span # Set up boundaries of box that span double the association box_lower_bound = data_lower_bound - box_margin box_upper_bound = data_upper_bound + box_margin # Set margin based on provided (or default) constant amounts else: data_margin = np.array(3 * [pos_margin] + 3 * [vel_margin]) box_lower_bound = data_lower_bound - data_margin box_upper_bound = data_upper_bound + data_margin logging.info('Range extended.\nLower: {}\nUpper: {}'.format( np.round(box_lower_bound), np.round(box_upper_bound))) return box_lower_bound, box_upper_bound
""" Add very large RV errors for stars with no known RVs. Convert to cartesian. """ import numpy as np import sys sys.path.insert(0, '..') from chronostar import tabletool from astropy.table import Table datafile = '../data/ScoCen_box_result.fits' d = tabletool.read(datafile) # Set missing radial velocities (nan) to 0 d['radial_velocity'] = np.nan_to_num(d['radial_velocity']) # Set missing radial velocity errors (nan) to 1e+10 d['radial_velocity_error'][np.isnan(d['radial_velocity_error'])] = 1e+4 print('Convert to cartesian') tabletool.convert_table_astro2cart(table=d, return_table=True) d.write( '/priv/mulga1/marusa/chronostar/data/ScoCen_box_result_15M_ready_for_bg_ols.fits' ) print('Cartesian written.', len(d))