Exemplo n.º 1
0
    def __init__(self,cdts,Rcut,hyp,Dist,centre_init):
        """
        Constructor of the logposteriorModule
        """
        rad,thet        = Deg2pc(cdts,centre_init,Dist)
        c,r,t,self.Rmax = TruncSort(cdts,rad,thet,Rcut)
        self.pro        = c[:,2]
        self.cdts       = c[:,:2]
        self.Dist       = Dist
        #-------------- Finds the mode of the band -------
        band_all        = c[:,3]
        idv             = np.where(np.isfinite(c[:,3]))[0]
        band            = c[idv,3]
        kde             = st.gaussian_kde(band)
        x               = np.linspace(np.min(band),np.max(band),num=1000)
        self.mode       = x[kde(x).argmax()]
        print "Mode of band at ",self.mode

        #---- repleace NANs by mode -----
        idnv            = np.setdiff1d(np.arange(len(band_all)),idv)
        band_all[idnv]  = self.mode
        self.delta_band = band_all - self.mode
        #------------- poisson ----------------
        self.quadrants  = [0,np.pi/2.0,np.pi,3.0*np.pi/2.0,2.0*np.pi]
        self.poisson    = st.poisson(len(r)/4.0)
        #-------------- priors ----------------
        self.Prior_0    = st.norm(loc=centre_init[0],scale=hyp[0])
        self.Prior_1    = st.norm(loc=centre_init[1],scale=hyp[1])
        self.Prior_2    = st.uniform(loc=-0.5*np.pi,scale=np.pi)
        self.Prior_3    = st.halfcauchy(loc=0.01,scale=hyp[2])
        self.Prior_4    = st.halfcauchy(loc=0.01,scale=hyp[2])
        self.Prior_5    = st.truncexpon(b=hyp[3],loc=2.01,scale=hyp[4])
        self.Prior_6    = st.norm(loc=hyp[5],scale=hyp[6])
        print "Module Initialized"
Exemplo n.º 2
0
 def __init__(self, cdts, Rcut, hyp, Dist, centre_init):
     """
     Constructor of the logposteriorModule
     """
     rad, thet = Deg2pc(cdts, centre_init, Dist)
     c, r, t, self.Rmax = TruncSort(cdts, rad, thet, Rcut)
     self.pro = c[:, 2]
     self.cdts = c[:, :2]
     self.Dist = Dist
     #------------- poisson ----------------
     self.quadrants = [
         0, np.pi / 2.0, np.pi, 3.0 * np.pi / 2.0, 2.0 * np.pi
     ]
     self.poisson = st.poisson(len(r) / 4.0)
     #-------------- priors ----------------
     self.Prior_0 = st.norm(loc=centre_init[0], scale=hyp[0])
     self.Prior_1 = st.norm(loc=centre_init[1], scale=hyp[1])
     self.Prior_2 = st.uniform(loc=-0.5 * np.pi, scale=np.pi)
     self.Prior_3 = st.halfcauchy(loc=0.01, scale=hyp[2])
     self.Prior_4 = st.halfcauchy(loc=0.01, scale=hyp[3])
     self.Prior_5 = st.halfcauchy(loc=0.01, scale=hyp[2])
     self.Prior_6 = st.halfcauchy(loc=0.01, scale=hyp[3])
     self.Prior_7 = st.truncexpon(b=hyp[4], loc=0.01, scale=hyp[5])
     self.Prior_8 = st.truncexpon(b=hyp[4], loc=0.01, scale=hyp[5])
     print("Module Initialized")
Exemplo n.º 3
0
 def __init__(self, cdts, Rcut, hyp, Dist, centre):
     """
     Constructor of the logposteriorModule
     """
     rad, thet = Deg2pc(cdts, centre, Dist)
     c, r, t, self.Rmax = TruncSort(cdts, rad, thet, Rcut)
     self.pro = c[:, 2]
     self.rad = r
     # -------- Priors --------
     self.Prior_0 = st.halfcauchy(loc=0, scale=hyp[0])
     self.Prior_1 = st.halfcauchy(loc=0, scale=hyp[1])
     print("Module Initialized")
Exemplo n.º 4
0
 def __init__(self, cdts, Rcut, hyp, Dist, centre_init):
     """
     Constructor of the logposteriorModule
     """
     rad, thet = Deg2pc(cdts, centre_init, Dist)
     c, r, t, self.Rmax = TruncSort(cdts, rad, thet, Rcut)
     self.pro = c[:, 2]
     self.cdts = c[:, :2]
     self.Dist = Dist
     print "There are ", len(self.cdts), " observations."
     # sys.exit()
     #------------- poisson ----------------
     self.quadrants = [
         0, np.pi / 2.0, np.pi, 3.0 * np.pi / 2.0, 2.0 * np.pi
     ]
     self.poisson = st.poisson(len(r) / 4.0)
     #-------------- priors ----------------
     self.Prior_0 = st.norm(loc=centre_init[0], scale=hyp[0])
     self.Prior_1 = st.norm(loc=centre_init[1], scale=hyp[1])
     self.Prior_2 = st.halfcauchy(loc=0.01, scale=hyp[2])
     self.Prior_3 = st.truncexpon(b=hyp[3], loc=2.01, scale=hyp[4])
     print "Module Initialized"
Exemplo n.º 5
0
samp = samples[np.random.choice(np.arange(len(samples)),size=100,replace=False)]


############### Stores the covariance matrix ##############
print("Finding covariance matrix around MAP ...")
covar = fCovar(samples,MAP)
np.savetxt(dir_out+"/"+model+"_covariance.txt",covar,
		fmt=str('%2.3f'),delimiter=" & ",newline=str("\\\ \n"))


# ------ establish new centre (if needed) ------
if not exte == "None":
	centre = MAP[:2]
# -------- prepare data for plots ---------
rad,thet              = Deg2pc(cdts,centre,Dist)
cdts,radii,theta,Rmax = TruncSort(cdts,rad,thet,Rcut)

if exte == "Ell":
	radii,theta       = RotRadii(cdts,centre,Dist,MAP[3])

Nr,bins,dens          = DenNum(radii,Rmax)
x                     = np.linspace(0.01,Rmax,50)

pdf = PdfPages(dir_out+"/"+model+'_fit.pdf')

plt.figure()
for s,par in enumerate(samp):
	plt.plot(x,mod.Number(x,par,Rmax,np.max(Nr)),lw=1,color="orange",alpha=0.2,zorder=1)
plt.fill_between(radii, Nr+np.sqrt(Nr), Nr-np.sqrt(Nr), facecolor='grey', alpha=0.5,zorder=2)
plt.plot(radii,Nr,lw=1,color="black",zorder=3)
plt.plot(x,mod.Number(x,MAP,Rmax,np.max(Nr)), lw=1,color="red",zorder=4)