def starfit(folder, multiplicities=['<STR_LIT>'], models='<STR_LIT>',<EOL>use_emcee=False, plot_only=False, overwrite=False, verbose=False,<EOL>logger=None, starmodel_type=None, ini_file='<STR_LIT>',<EOL>no_plots=False, bands=None, **kwargs):
nstars = {'<STR_LIT>':<NUM_LIT:1>,<EOL>'<STR_LIT>':<NUM_LIT:2>,<EOL>'<STR_LIT>':<NUM_LIT:3>}<EOL>if starmodel_type is None:<EOL><INDENT>Mod = StarModel<EOL><DEDENT>else:<EOL><INDENT>Mod = starmodel_type<EOL><DEDENT>ichrone = None<EOL>print('<STR_LIT>'.format(folder))<EOL>for mult in multiplicities:<EOL><INDENT>print('<STR_LIT>'.format(mult))<EOL>model_filename = '<STR_LIT>'.format(models, mult)<EOL>logfile = os.path.join(folder, '<STR_LIT>')<EOL>logger = initLogging(logfile, logger)<EOL>name = os.path.basename(os.path.abspath(folder))<EOL>mod = None<EOL>try:<EOL><INDENT>start = time.time()<EOL>if plot_only:<EOL><INDENT>try:<EOL><INDENT>mod = Mod.load_hdf('<STR_LIT>'.format(folder,model_filename),<EOL>name=name)<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>else:<EOL><INDENT>fit_model = True<EOL>try:<EOL><INDENT>mod = Mod.load_hdf('<STR_LIT>'.format(folder,model_filename),<EOL>name=name)<EOL>fit_model = False<EOL><DEDENT>except:<EOL><INDENT>filename = '<STR_LIT>'.format(folder,model_filename)<EOL>if os.path.exists(filename):<EOL><INDENT>os.remove(filename)<EOL><DEDENT><DEDENT>if fit_model or overwrite:<EOL><INDENT>ini_file_path = os.path.join(folder, ini_file)<EOL>c = ConfigObj(ini_file_path)<EOL>if ichrone is None:<EOL><INDENT>if bands is None:<EOL><INDENT>bands = StarModel.get_bands(ini_file_path)<EOL><DEDENT>else:<EOL><INDENT>bands += StarModel.get_bands(ini_file_path)<EOL><DEDENT>ichrone = get_ichrone(models, bands)<EOL><DEDENT>N = nstars[mult] if '<STR_LIT:N>' not in c else None<EOL>mod = Mod.from_ini(ichrone, folder, use_emcee=use_emcee, N=N,<EOL>ini_file=ini_file, name=name)<EOL>try:<EOL><INDENT>mod.obs.print_ascii()<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT>mod.fit(verbose=verbose, overwrite=overwrite, **kwargs)<EOL>mod.save_hdf(os.path.join(folder, model_filename), overwrite=overwrite)<EOL><DEDENT>else:<EOL><INDENT>logger.info('<STR_LIT>'.format(model_filename))<EOL><DEDENT><DEDENT>make_corners = False<EOL>for x in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>f = os.path.join(folder,<EOL>'<STR_LIT>'.format(models, mult, x))<EOL>if not os.path.exists(f):<EOL><INDENT>make_corners = True<EOL>break<EOL><DEDENT>else:<EOL><INDENT>t_mod = os.path.getmtime(os.path.join(folder,model_filename))<EOL>t_plot = os.path.getmtime(f)<EOL>if t_mod > t_plot:<EOL><INDENT>make_corners=True<EOL><DEDENT><DEDENT><DEDENT>if (make_corners or plot_only) and not no_plots:<EOL><INDENT>corner_base = os.path.join(folder, '<STR_LIT>'.format(models, mult))<EOL>fig1,fig2 = mod.corner_plots(corner_base)<EOL><DEDENT>magplot_file = os.path.join(folder, '<STR_LIT>'.format(models, mult))<EOL>make_magplot = False <EOL>if os.path.exists(magplot_file):<EOL><INDENT>if os.path.getmtime(os.path.join(folder, model_filename)) >os.path.getmtime(magplot_file) orplot_only:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>make_magplot = False<EOL><DEDENT><DEDENT>if make_magplot:<EOL><INDENT>fig = mod.mag_plot()<EOL>plt.savefig(os.path.join(folder,'<STR_LIT>'.format(models, mult)))<EOL><DEDENT>end = time.time()<EOL>if plot_only:<EOL><INDENT>logger.info('<STR_LIT>'.format(mult) +<EOL>'<STR_LIT>'.format(folder, (end-start)/<NUM_LIT>))<EOL><DEDENT>else:<EOL><INDENT>logger.info('<STR_LIT>'.format(mult) +<EOL>'<STR_LIT>'.format(folder, (end-start)/<NUM_LIT>))<EOL><DEDENT><DEDENT>except KeyboardInterrupt:<EOL><INDENT>logger.error('<STR_LIT>'.format(mult,folder))<EOL>raise<EOL><DEDENT>except:<EOL><INDENT>logger.error('<STR_LIT>'.format(mult,folder),<EOL>exc_info=True)<EOL><DEDENT><DEDENT>return mod, logger<EOL>
Runs starfit routine for a given folder.