def main(): parser = MyParser() parser.add_argument('config_fname', help="full path to config filename", nargs='?', type=str) parser.add_argument('redshift', help="central redshift for plotting spectrum", nargs='?', type=float) parser.add_argument('dv', help="velocity range for spectrum (+/-dv)", nargs='?', type=float) #parser.add_argument("--truths", nargs='+', type=float) parser.add_argument('-t', "--test", help="plot data product of test", action="store_true") args = parser.parse_args() if len(sys.argv) < 4 and not args.test: parser.print_help(sys.stderr) sys.exit(1) if args.test: from bayesvp.utilities import get_bayesvp_Dir path = get_bayesvp_Dir() config_fname = path + '/data/example/config_OVI.dat' config_param = DefineParams(config_fname) args.redshift = 0.0 args.dv = 300.0 else: if os.path.isfile(args.config_fname): config_param = DefineParams(args.config_fname) else: sys.exit('Config file does not exist:\n %s' % args.config_fname) output_model = ProcessModel(config_param) output_model.spline_binned_pdf() output_model.plot_model_comparison(args.redshift, args.dv) output_model.write_model_summary() output_model.write_model_spectrum() output_model.plot_gr_indicator() #output_model.corner_plot(nbins=30,truths=args.truths) output_model.corner_plot(nbins=30)
def setUp(self): # read example config file code_path = get_bayesvp_Dir() self.config_ex = code_path + '/data/example/config_OVI.dat' self.config_params = DefineParams(self.config_ex) self.posterior = Posterior(self.config_params)
def bvp_process(config_fname, redshift, dv): config_param = DefineParams(config_fname) output_model = ProcessModel(config_param) output_model.spline_binned_pdf() output_model.plot_model_comparison(redshift, dv) output_model.write_model_summary() output_model.write_model_spectrum() output_model.plot_gr_indicator() output_model.corner_plot(nbins=30) return None
# from bayesvp.vp_model import simple_spec #------------------------------------------------------------- # set the path of the data spectrum_path = '/home/tanvir/BLA_project/codes/examples/' # spectrum_path = 'E:/TANVIR_WORK/codes/examples/' # create a config file config_writer = wc.WriteBayesVPConfig().print_to_file("-i") # load the config file config_fname = spectrum_path + 'bvp_configs/config_HI.dat' # extract all of the relevant information using the DefineParams function config_params = DefineParams(config_fname) #-------- run the MCMC fit -------------------------- # fitting log is written in 'config.log' file. start = time.time() # mc_single(config_params) mcmc(config_fname) # end = time.time() print((end - start) / 60.) #----------------------------------------------------------- # The fitting process after the step is completed. The output chain is a binary file which ends with .npy # contains all the information that we need. # ---- read the .npy file ------
from bayesvp.mcmc_setup import bvp_mcmc as mcmc from bayesvp.config import DefineParams from bayesvp.scripts import bvp_process_model config_file = '/home/vikram/BLA_hub/test_vikram/hi_config.dat' # the mcmc fit mcmc(config_file, print_config=True) # after the chains x = DefineParams(config_file) op = bvp_process_model.ProcessModel(x) op.plot_model_comparison(0.081, 400) op.write_model_summary() op.write_model_spectrum() op.plot_gr_indicator() op.corner_plot()
def setUp(self): code_path = get_bayesvp_Dir() # read example config file self.config_ex = code_path + '/data/example/config_OVI.dat' self.config_params = DefineParams(self.config_ex)
def bvp_mcmc(config_fname, print_config=False): """ Run fixed number of component fit specified by the config file or make copies of the configs and run up to the maximum number of components until the best model is found. Parameters: ----------- config_fname: str Full path + the file name See ./readme.md for detaieded structure of the config file Returns ----------- chains: python format (.npy) binary file One or more chains for each MCMC run. """ # Determine if config is set to automatically choose the best model # If so, create multiple configs file specified by n_component_max auto_vp, n_component_min, n_component_max = determine_autovp(config_fname) if auto_vp: model_evidence = np.zeros(n_component_max - n_component_min + 1) for n in xrange(n_component_max - n_component_min + 1): # Get new config filename; basename_with_path, config_extension = os.path.splitext( config_fname) config_fname_ncomp = (basename_with_path + str(n + n_component_min) + config_extension) # Load config parameter object config_params = DefineParams(config_fname_ncomp) # Run MCMC bvp_mcmc_single(config_params, config_params.chain_fname) # compute values of aic, bic or bf model_evidence[n] = model_info_criterion(config_params) components_count = np.arange(n_component_min, n_component_max + 1) # compare with the previous fit if 0 < n <= n_component_max - 1: #if config_params.model_selection.lower() in ('odds','bf'): # index = np.where(model_evidence[:n+1] == np.max(model_evidence[:n+1]))[0] if config_params.model_selection.lower() in ('aic', 'bic'): index = np.where( model_evidence[:n + 1] == np.min(model_evidence[:n + 1]))[0] # Compare BIC/AIC/Odds ratios if compare_model(model_evidence[n - 1], model_evidence[n], config_params.model_selection): np.savetxt(config_params.mcmc_outputpath + '/' + config_params.model_selection + '_' + config_params.chain_short_fname[:-1] + '.dat', np.c_[components_count[:n + 1], model_evidence[:n + 1]], fmt=('%d', '%.4f'), header='nComponents\tValues') break else: # Load config parameter object config_params = DefineParams(config_fname) if print_config: config_params.print_config_params() # Run fit as specified in config bvp_mcmc_single(config_params)