logging.basicConfig(filename=rdir + 'log.log', level=logging.INFO) log_message('Beginning Chronostar run', symbol='_', surround=True) log_message('Setting up', symbol='.', surround=True) assert os.access(rdir, os.W_OK) # ------------------------------------------------------------ # ----- SETTING UP ALL DATA PREP --------------------------- # ------------------------------------------------------------ # Set up some filename constants (INPUT files) FOR COMPARISON and expectmax final_comps_file_with_rv = '../data/no_rv_paper/beta_pic_sphere_component.npy' final_memb_probs_file_with_rv = '../data/no_rv_paper/beta_memb_probs.npy' bp_comp_with_rv = SphereComponent.load_components(final_comps_file_with_rv) bp_probs_with_rv = np.load(final_memb_probs_file_with_rv) print(bp_probs_with_rv) # Set up some filename constants (OUTPUT files) final_comps_file = 'final_comps.npy' final_med_and_spans_file = 'final_med_and_spans.npy' final_memb_probs_file = 'final_membership.npy' # TODO: data_loadfile: mask out rows with nans # First see if a data savefile path has been provided, and if # so, then just assume this script has already been performed # and the data prep has already been done if (config.config['data_savefile'] != '' and os.path.isfile(config.config['data_savefile'])):
# Fit the first component log_message(msg='FITTING {} COMPONENT'.format(ncomps), symbol='*', surround=True) run_dir = rdir + '{}/'.format(ncomps) # Initialise all stars in dataset to be full members of first component init_memb_probs = np.zeros((len(data_dict['means']),2)) init_memb_probs[:,0] = 1. # 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_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) np.save(str(run_dir+'final/'+final_comps_file), prev_comps)
log_message('Beginning Chronostar run', symbol='_', surround=True) log_message('Setting up', symbol='.', surround=True) assert os.access(rdir, os.W_OK) # ------------------------------------------------------------ # ----- SETTING UP ALL DATA PREP --------------------------- # ------------------------------------------------------------ # Set up some filename constants (INPUT files) FOR COMPARISON and expectmax final_comps_file_with_rv = '../data/no_rv_paper/beta_pic_sphere_component.npy' final_memb_probs_file_with_rv = '../data/no_rv_paper/beta_memb_probs.npy' bp_comp_with_rv = SphereComponent.load_components(final_comps_file_with_rv) bp_probs_with_rv = np.load(final_memb_probs_file_with_rv) print(bp_probs_with_rv) # Set up some filename constants (OUTPUT files) final_comps_file = 'final_comps.npy' final_med_and_spans_file = 'final_med_and_spans.npy' final_memb_probs_file = 'final_membership.npy' # TODO: data_loadfile: mask out rows with nans # First see if a data savefile path has been provided, and if # so, then just assume this script has already been performed # and the data prep has already been done if (config.config['data_savefile'] != '' and os.path.isfile(config.config['data_savefile'])):
# Fit the first component log_message(msg='FITTING {} COMPONENT'.format(ncomps), symbol='*', surround=True) run_dir = rdir + '{}/'.format(ncomps) # Initialise all stars in dataset to be full members of first component init_memb_probs = np.zeros((len(data_dict['means']), 2)) init_memb_probs[:, 0] = 1. # 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_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) np.save(str(run_dir + 'final/' + final_comps_file), prev_comps)