figure(1) clf() errorbar(xdata, ydata, xerr=xerr, yerr=yerr, marker='.', linestyle='none') MC = pymc_linear_fit_withoutliers(xdata, ydata, data1err=xerr, data2err=yerr, return_MC=True) MC.sample(50000,burn=10000,verbose=1) mmean = MC.stats()['slope']['mean'] bmean = MC.stats()['intercept']['mean'] plot(linspace(0,300),linspace(0,300)*mmean+bmean,color='k',linewidth=2) for m,b in zip(MC.trace('slope')[-100:],MC.trace('intercept')[-100:]): plot(linspace(0,300),linspace(0,300)*m+b, color='k', alpha=0.05) scatter(xdata[MC.badvals.value.astype('bool')], ydata[MC.badvals.value.astype('bool')], color='r') from agpy import pymc_plotting import pymc figure(2) clf() pymc_plotting.hist2d(MC,'slope','intercept',fignum=2,bins=50) figure(3) clf() pymc.Matplot.plot(MC.slope,new=False) figure(4) clf() pymc.Matplot.plot(MC.intercept,new=False)
lm = agpy.blackbody.fit_blackbody_lmfit(wavelength, flux, err=err, blackbody_function=agpy.blackbody.modified_blackbody_wavelength, logscale=16, guesses=(tguess,bguess,nguess), wavelength_units='microns') print lm.params """ Incomplete testing so far. Looks like luminosity comes out very wrong. Other parameters seem to be recovered well enough. """ wavelength = np.array([20,70,160,250,350,500,850,1100]) frequency = 3e14 / wavelength flux = agpy.blackbody.modified_blackbody(frequency, 15, beta=1.75, normalize=False, logN=22, logscale=16) err = 0.1 * flux flux += np.random.randn(len(wavelength)) * err tguess, bguess, nguess = 20.,2.,21.5 mc = agpy.blackbody.fit_blackbody_montecarlo(frequency, flux, err=err, blackbody_function=agpy.blackbody.modified_blackbody, logscale=16, temperature_guess=tguess, beta_guess=bguess, scale_guess=nguess, #guesses=(tguess,bguess,nguess), scale_keyword='logscale', return_MC=True) from agpy import pymc_plotting pymc_plotting.hist2d(mc, mc.temperature, mc.beta)
from measure_tau import savefig, savepath #import astropy.io.fits as pyfits from agpy import pymc_plotting import pylab as pl import numpy as np pl.rc('font',size=24) for fignum,abundance in enumerate((-8.5,-9.0)): execfile('load_parameter_traces.py') fig = pl.figure(1+fignum) pl.clf() ax1 = pymc_plotting.hist2d(mc_lognormal_freemach_traces, 'tauoneone_mu','sigma', bins=50, clear=True, fignum=1, varslice=(2.5e5,None,None), colorbar=False, axis=pl.subplot(231)) ax2 = pymc_plotting.hist2d(mc_lognormal_freemach_traces, 'tautwotwo_mu','sigma', bins=50, clear=True, fignum=1, varslice=(2.5e5,None,None), colorbar=False, axis=pl.subplot(232)) ax3 = pymc_plotting.hist2d(mc_lognormal_freemach_traces, 'tau_ratio','sigma', bins=50, clear=True, fignum=1, varslice=(2.5e5,None,None), colorbar=False, axis=pl.subplot(233)) ax4 = pymc_plotting.hist2d(mc_hopkins_freemach_traces, 'tauoneone_mu','sigma', bins=50, clear=True, fignum=1, varslice=(2.5e5,None,None), colorbar=False, axis=pl.subplot(234)) ax5 = pymc_plotting.hist2d(mc_hopkins_freemach_traces, 'tautwotwo_mu','sigma', bins=50, clear=True, fignum=1, varslice=(2.5e5,None,None), colorbar=False, axis=pl.subplot(235)) ax6 = pymc_plotting.hist2d(mc_hopkins_freemach_traces, 'tau_ratio','sigma', bins=50,
from measure_tau import trace_data_path, abundance, savefig, savepath import astropy.io.fits as pyfits from agpy import pymc_plotting #import pylab as pl lognormal_freemach_statstable = pyfits.getdata(trace_data_path+'lognormal_freemach_statstable_abundance%s.fits' % abundance) mc_lognormal_freemach_traces = pyfits.getdata(trace_data_path+"mc_lognormal_freemach_traces.fits") ax = pymc_plotting.hist2d(mc_lognormal_freemach_traces, 'tau_ratio','mach', bins=50, clear=True, fignum=1, varslice=(None,None,None), colorbar=True) ax.hlines([3.68],*ax.get_xlim(),linestyles=['--'], colors=['k'], label="H$_2$CO Lower-limit") ax.hlines([6.58],*ax.get_xlim(),linestyles=[':'], colors=['k'], label="CO Lower-limit") ax.legend(loc='best') ax.set_ylabel(r"$\mathcal{M}_{3D}$") ax.set_xlabel('$\\tau_{1-1}/\\tau_{2-2}$',fontsize=24) savefig(savepath+"mach_vs_tauratio_lognormal_mcmc_contours.png")
from measure_tau import trace_data_path, savefig, savepath import astropy.io.fits as pyfits from agpy import pymc_plotting import pylab as pl pl.rc('font',size=30) for abundance in (-8.5,-9.0): for withfree in ('with','free'): logtraces = pyfits.getdata(trace_data_path+"mc_lognormal_%smach_traces%s.fits" % (withfree,abundance)) ax = pymc_plotting.hist2d(logtraces, 'b','mach', bins=50, clear=True, fignum=1, varslice=(2.5e5,None,None), colorbar=True) ax.hlines([3.68],*ax.get_xlim(),linestyles=['--'], colors=['k'], label="H$_2$CO") ax.hlines([6.58],*ax.get_xlim(),linestyles=[':'], colors=['k'], label="CO") ax.legend(loc='best') ax.set_ylabel(r"$\mathcal{M}_{3D}$") ax.set_xlabel('$b$',fontsize=36) savefig(savepath+"mach_vs_b_lognormal_mcmc_contours_%smach_abundance%s.png" % (withfree,abundance)) hoptraces = pyfits.getdata(trace_data_path+"mc_hopkins_%smach_traces_abundance%s.fits" % (withfree,abundance)) if 'mach' in hoptraces.names: mach = 'mach' else:
""" Incomplete testing so far. Looks like luminosity comes out very wrong. Other parameters seem to be recovered well enough. """ wavelength = np.array([20, 70, 160, 250, 350, 500, 850, 1100]) frequency = 3e14 / wavelength flux = agpy.blackbody.modified_blackbody(frequency, 15, beta=1.75, normalize=False, logN=22, logscale=16) err = 0.1 * flux flux += np.random.randn(len(wavelength)) * err tguess, bguess, nguess = 20., 2., 21.5 mc = agpy.blackbody.fit_blackbody_montecarlo( frequency, flux, err=err, blackbody_function=agpy.blackbody.modified_blackbody, logscale=16, temperature_guess=tguess, beta_guess=bguess, scale_guess=nguess, #guesses=(tguess,bguess,nguess), scale_keyword='logscale', return_MC=True) from agpy import pymc_plotting pymc_plotting.hist2d(mc, mc.temperature, mc.beta)