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, get_background_overlaps=True, historical=historical, ) # Create components comps = SphereComponent.load_raw_components(comps_filename) # COMPONENT OVERLAPS overlaps = expectmax.get_all_lnoverlaps(data_dict, comps) print('overlaps.shape', overlaps.shape, len(comps)) # MEMBERSHIP PROBABILITIES membership_probabilities = np.array( [expectmax.calc_membership_probs(ol) for ol in overlaps]) # Create a table for i in range(membership_probabilities.shape[1] - 1): data_table['membership_%d' % (i + 1)] = membership_probabilities[:, i] data_table['membership_bg'] = membership_probabilities[:, -1] # Print data
return recent_lims else: try: return [np.min((current_lims[0], recent_lims[0])), np.max((current_lims[1], recent_lims[1]))] except: import pdb; pdb.set_trace() labels = 'XYZUVW' units = 3*['pc'] + 3*['km/s'] plt_dir = '../plots/scocen_formation/' all_comps_file = '../results/all_nonbg_scocen_comps.npy' # Reading in and tidying components all_comps = SphereComponent.load_raw_components(all_comps_file) # # Pop off some manually identified duplicates # all_comps.pop(9) # all_comps.pop(6) print('ages of components: {}'.format([c.get_age() for c in all_comps])) max_age = np.max([c.get_age() for c in all_comps]) ntimes = 100 times = np.linspace(max_age, 0, ntimes) #for time in times: time_ix = ntimes - ntimes/2
""" import numpy as np import sys sys.path.insert(0, '..') from chronostar.component import SphereComponent from chronostar import tabletool from chronostar import expectmax from astropy.table import Table, vstack, join # Create components #c = np.load('all_nonbg_scocen_comps.npy') # including LCC #comps = [SphereComponent(pars=x) for x in c] comps = SphereComponent.load_raw_components('all_nonbg_scocen_comps.npy') print('components', c.shape) print('Are there duplicate components?') #datafile = 'data_table_cartesian_with_bg_ols.fits' datafile = 'data_table_cartesian_including_tims_stars_with_bg_ols.fits' # Read Gaia data including both stars with known and missing radial velocities #datafile = 'data_table_cartesian_100k.fits' 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
''' Noticed issue with calculating a component's current day mean. Behaviour of trace_cartesian_orbit varies based on whether a single age is provided vs a range of times ''' import numpy as np import sys sys.path.insert(0, '..') from chronostar.component import SphereComponent from chronostar.traceorbit import trace_cartesian_orbit bugged_comp = SphereComponent.load_raw_components('bugged_component.npy')[0] y_pos_now = bugged_comp.get_mean_now()[1] print('Mean then: {}'.format(bugged_comp.get_mean())) print('Internally calculated mean_now: {}'.format(bugged_comp.get_mean_now())) mean_then = bugged_comp.get_mean() age = bugged_comp.get_age() y_pos_linear = mean_then[1] + mean_then[4] * age print('Linear Y motion: {}'.format(y_pos_linear)) print('Difference of {}'.format(y_pos_now - y_pos_linear)) ts = np.linspace(0, bugged_comp.get_age(), 50) for method in [ 'odeint', 'symplec4_c', 'rk4_c', 'dopr54_c',
# Initialise all stars in dataset to be full members of first component using_bg = config.config.get('include_background_distribution', False) init_memb_probs = np.zeros((len(data_dict['means']), 1 + using_bg)) init_memb_probs[:, 0] = 1. store_burnin_chains = config.advanced.get('store_burnin_chains', False) if store_burnin_chains: log_message(msg='Storing burnin chains', symbol='-') # Try and recover any results from previous run try: prev_med_and_spans = np.load(run_dir + 'final/' + final_med_and_spans_file) prev_memb_probs = np.load(run_dir + 'final/' + final_memb_probs_file) try: prev_comps = Component.load_raw_components( str(run_dir + 'final/' + final_comps_file)) # Final comps are there, they just can't be read by current module # so quickly fit them based on fixed prev membership probabilities except AttributeError: logging.info('Component class has been modified, reconstructing ' 'from chain') prev_comps = ncomps * [None] for i in range(ncomps): final_cdir = run_dir + 'final/comp{}/'.format(i) chain = np.load(final_cdir + 'final_chain.npy') lnprob = np.load(final_cdir + 'final_lnprob.npy') npars = len(Component.PARAMETER_FORMAT) best_ix = np.argmax(lnprob) best_pars = chain.reshape(-1, npars)[best_ix] prev_comps[i] = Component(emcee_pars=best_pars) Component.store_raw_components(
if PLOT_BPMG_REAL: # PLOTTING ITERATION 6E # star_pars_file = '../../data/beta_Pictoris_with_gaia_small_xyzuvw.fits' table_file = '../../data/paper1/beta_Pictoris_corrected_everything.fits' bpmg_table = Table.read(table_file) star_pars, table_ixs = tabletool.build_data_dict_from_table( bpmg_table, return_table_ixs=True) nstars = len(table_ixs[0]) fit_name = 'bpmg_and_nearby' rdir = '../../results/beta_Pictoris_with_gaia_small_inv2/6/E/final/' memb_file = rdir + 'final_membership.npy' comp_file = rdir + 'final_comps.npy' z = np.load(memb_file) comps = SphereComponent.load_raw_components(comp_file) # Assign markers based on BANYAN membership banyan_markers = np.array(nstars * ['.']) banyan_membs = bpmg_table['banyan_assoc'][table_ixs] # Assign markers to each star (via `banyan_markers`) whilst concurrently # building list of maker style and the corresponding association for legend marker_style = [] marker_label = [] banyan_memb_set = set(banyan_membs) for bassoc in banyan_memb_set: if bassoc not in acronyms.keys(): acronyms[bassoc] = bassoc # Do BPMG manually banyan_markers[np.where(banyan_membs == 'beta Pictoris')] = 'v'
""" Temporary script which aids in the loading and analysis of BPMG 6E fit """ import numpy as np from astropy.table import Table import sys sys.path.insert(0, '..') from chronostar import tabletool from chronostar.component import SphereComponent master_table_file = '../data/paper1/beta_Pictoris_corrected_everything.fits' bpmg_rdir = '../results/beta_Pictoris_with_gaia_small_inv2/' fz = np.load(bpmg_rdir + 'final_membership.npy') fcomps = SphereComponent.load_raw_components(bpmg_rdir + 'final_comps.npy') fmers = np.load(bpmg_rdir + 'final_med_errs.npy') master_table = Table.read(master_table_file) star_pars, table_ixs = tabletool.build_data_dict_from_table( master_table, return_table_ixs=True) old_table_file = '../data/paper1/beta_Pictoris_with_gaia_small_everything_final.fits' old_table = Table.read(old_table_file)