def do_plot(args): import ugali.utils.plotting import pylab as plt import triangle config,name,label,coord = args print args filenames = make_filenames(config,label) srcfile = filenames['srcfile'] samfile = filenames['samfile'] memfile = filenames['memfile'] if not exists(srcfile): logger.warning("Couldn't find %s; skipping..."%srcfile) return if not exists(samfile): logger.warning("Couldn't find %s; skipping..."%samfile) return config = ugali.utils.config.Config(config) burn = config['mcmc']['nburn']*config['mcmc']['nwalkers'] source = ugali.analysis.source.Source() source.load(srcfile,section='source') outfile = samfile.replace('.npy','.png') ugali.utils.plotting.plotTriangle(srcfile,samfile,burn=burn) logger.info(" Writing %s..."%outfile) plt.savefig(outfile,bbox_inches='tight',dpi=60) plt.close() plotter = ugali.utils.plotting.SourcePlotter(source,config,radius=0.5) data = pyfits.open(memfile)[1].data if exists(memfile) else None if data is not None: plt.figure() kernel,isochrone = source.kernel,source.isochrone ugali.utils.plotting.plotMembership(config,data,kernel,isochrone) outfile = samfile.replace('.npy','_mem.png') logger.info(" Writing %s..."%outfile) plt.savefig(outfile,bbox_inches='tight',dpi=60) plt.close() plotter.plot6(data) outfile = samfile.replace('.npy','_6panel.png') logger.info(" Writing %s..."%outfile) plt.savefig(outfile,bbox_inches='tight',dpi=60) plt.close() plotter.plot4() outfile = samfile.replace('.npy','_4panel.png') logger.info(" Writing %s..."%outfile) plt.savefig(outfile,bbox_inches='tight',dpi=60) plt.close()
def do_plot(args): import ugali.utils.plotting import pylab as plt import triangle config, name, label, coord = args print args filenames = make_filenames(config, label) srcfile = filenames['srcfile'] samfile = filenames['samfile'] memfile = filenames['memfile'] if not exists(srcfile): logger.warning("Couldn't find %s; skipping..." % srcfile) return if not exists(samfile): logger.warning("Couldn't find %s; skipping..." % samfile) return config = ugali.utils.config.Config(config) burn = config['mcmc']['nburn'] * config['mcmc']['nwalkers'] source = ugali.analysis.source.Source() source.load(srcfile, section='source') outfile = samfile.replace('.npy', '.png') ugali.utils.plotting.plotTriangle(srcfile, samfile, burn=burn) logger.info(" Writing %s..." % outfile) plt.savefig(outfile, bbox_inches='tight', dpi=60) plt.close() plotter = ugali.utils.plotting.SourcePlotter(source, config, radius=0.5) data = pyfits.open(memfile)[1].data if exists(memfile) else None if data is not None: plt.figure() kernel, isochrone = source.kernel, source.isochrone ugali.utils.plotting.plotMembership(config, data, kernel, isochrone) outfile = samfile.replace('.npy', '_mem.png') logger.info(" Writing %s..." % outfile) plt.savefig(outfile, bbox_inches='tight', dpi=60) plt.close() plotter.plot6(data) outfile = samfile.replace('.npy', '_6panel.png') logger.info(" Writing %s..." % outfile) plt.savefig(outfile, bbox_inches='tight', dpi=60) plt.close() plotter.plot4() outfile = samfile.replace('.npy', '_4panel.png') logger.info(" Writing %s..." % outfile) plt.savefig(outfile, bbox_inches='tight', dpi=60) plt.close()
def createResults(config, srcfile, section='source', samples=None): """ Create an MCMC instance """ source = ugali.analysis.source.Source() source.load(srcfile, section=section) loglike = ugali.analysis.loglike.createLoglike(config, source) results = Results(config, loglike, samples) if samples is not None: results.load_samples(samples) return results
def createResults(config,srcfile,section='source',samples=None): """ Create an MCMC instance """ source = ugali.analysis.source.Source() source.load(srcfile,section=section) loglike = ugali.analysis.loglike.createLoglike(config,source) results = Results(config,loglike,samples) if samples is not None: results.load_samples(samples) return results
def do_membership(args): """ Write the membership output file """ config, name, label, coord = args filenames = make_filenames(config, label) srcfile = filenames['srcfile'] memfile = filenames['memfile'] source = ugali.analysis.source.Source() source.load(srcfile, 'source') loglike = ugali.analysis.loglike.createLoglike(config, source) logger.info("Writing %s..." % memfile) loglike.write_membership(memfile)
def do_membership(args): """ Write the membership output file """ config,name,label,coord = args filenames = make_filenames(config,label) srcfile = filenames['srcfile'] memfile = filenames['memfile'] source = ugali.analysis.source.Source() source.load(srcfile,'source') loglike = ugali.analysis.loglike.createLoglike(config,source) logger.info("Writing %s..."%memfile) loglike.write_membership(memfile)
a = 13.5 z = 0.0001 for name in names: if opts.name is not None: if name.lower() != opts.name.lower(): continue print(name) #ra,dec = params['ra'],params['dec'] #lon,lat = cel2gal(ra,dec) #params['lon'],params['lat'] = lon,lat #params['age'] = a #params['metallicity'] = z #srcmdl = join(dirname,'%s_mcmc.yaml'%name) source = ugali.analysis.source.Source() source.load(srcmdl, name) loglike = ugali.analysis.loglike.createLoglike(config, source) params = source.params xpar = opts.xpar ypar = opts.ypar zpar = opts.zpar xval = params[xpar] yval = params[ypar] zval = params[zpar] fmt = '%s = %.5g [+%.2g,-%.2g]' #loglike = ugali.analysis.loglike.createLoglike(config,lon,lat) ##loglike.models['color'] = Padova(age=12.5,z=0.0002,hb_spread=0) #loglike.value(**params)
a = 13.5 z = 0.0001 for name in names: if opts.name is not None: if name.lower() != opts.name.lower(): continue print(name) #ra,dec = params['ra'],params['dec'] #lon,lat = cel2gal(ra,dec) #params['lon'],params['lat'] = lon,lat #params['age'] = a #params['metallicity'] = z #srcmdl = join(dirname,'%s_mcmc.yaml'%name) source = ugali.analysis.source.Source() source.load(srcmdl,name) loglike = ugali.analysis.loglike.createLoglike(config,source) params = source.params xpar = opts.xpar ypar = opts.ypar zpar = opts.zpar xval = params[xpar] yval = params[ypar] zval = params[zpar] fmt = '%s = %.5g [+%.2g,-%.2g]' #loglike = ugali.analysis.loglike.createLoglike(config,lon,lat) ##loglike.models['color'] = Padova(age=12.5,z=0.0002,hb_spread=0) #loglike.value(**params)
def do_plot(args): """ Create plots of mcmc output """ import ugali.utils.plotting import pylab as plt config, name, label, coord = args filenames = make_filenames(config, label) srcfile = filenames['srcfile'] samfile = filenames['samfile'] memfile = filenames['memfile'] if not exists(srcfile): logger.warning("Couldn't find %s; skipping..." % srcfile) return if not exists(samfile): logger.warning("Couldn't find %s; skipping..." % samfile) return config = ugali.utils.config.Config(config) burn = config['mcmc']['nburn'] * config['mcmc']['nwalkers'] source = ugali.analysis.source.Source() source.load(srcfile, section='source') outfile = samfile.replace('.npy', '.pdf') ugali.utils.plotting.plotTriangle(srcfile, samfile, burn=burn) logger.info(" Writing %s..." % outfile) plt.savefig(outfile, bbox_inches='tight', dpi=60) plt.close() plotter = ugali.utils.plotting.SourcePlotter(source, config, radius=0.5) data = fitsio.read(memfile, trim_strings=True) if exists(memfile) else None if data is not None: plt.figure() kernel, isochrone = source.kernel, source.isochrone ugali.utils.plotting.plotMembership(config, data, kernel, isochrone) outfile = samfile.replace('.npy', '_mem.pdf') logger.info(" Writing %s..." % outfile) plt.savefig(outfile, bbox_inches='tight', dpi=350) plt.close() plotter.plot6(data) outfile = samfile.replace('.npy', '_6panel.png') logger.info(" Writing %s..." % outfile) np.seterr(all='ignore') plt.savefig(outfile, bbox_inches='tight', dpi=60) #plt.show() outfile = samfile.replace('.npy', '_6panel.pdf') logger.info(" Writing %s..." % outfile) plt.savefig(outfile, bbox_inches='tight', dpi=60) plt.close() try: title = name plotter.plot4() outfile = samfile.replace('.npy', '_4panel.png') logger.info(" Writing %s..." % outfile) plt.suptitle(title) plt.savefig(outfile, bbox_inches='tight', dpi=60) plt.close() except: logger.warning(" Failed to create plotter.plot4()")