def dlfParamsdz(z, pPhiStar, pMStar, pAlpha, pBeta): dlog10phiStardz = T.deriv(T(pPhiStar))(1 + z) dmStardz = T.deriv(T(pMStar))(1 + z) dalphadz = T.deriv(T(pAlpha))(1 + z) h, f0, z0, a, b = pBeta zeta = np.log10((1.0 + z) / (1.0 + z0)) dbetadz = (-f0 * (a * 10.0**((a - 1) * zeta) / (1.0 + z0) + b * 10.0**((b - 1) * zeta) / (1.0 + z0)) / (10.0**(a * zeta) + 10.0**(b * zeta))**2) return dlog10phiStardz, dmStardz, dalphadz, dbetadz
def lfParams(z, pPhiStar, pMStar, pAlpha, pBeta): log10phiStar = T(pPhiStar)(1 + z) # mStar = T(pMStar)(1+z) # mStar = np.polyval(pMStar, np.log10(1.0+z)) mStar = np.polyval(pMStar, 1.0 + z) alpha = T(pAlpha)(1 + z) h, f0, z0, a, b = pBeta zeta = np.log10((1.0 + z) / (1.0 + z0)) beta = h + f0 / (10.0**(a * zeta) + 10.0**(b * zeta)) return log10phiStar, mStar, alpha, beta
def calc_opac(self): """ calculates the opacities from the Chebyshev coefficients for the whole T, P range""" for t in range(0, len(self.temp_list)): for p in range(0, len(self.press_list)): for n in range(0, self.nbins_counted): #pick block in descending bin order, but ascending P and T order pick_block = t * len( self.press_list) * self.nbins_counted + ( p + 1) * self.nbins_counted - 1 - n #chebyshev series with the correct coefficients series = T( self.coeffs[self.ncoeffs * pick_block:self.ncoeffs * (pick_block + 1)]) for y in range(0, self.ny): yp = self.ypoints[y] if yp >= self.ystart[pick_block]: self.ky.append( np.exp( series((2.0 * yp - 1.0 - self.ystart[pick_block]) / (1.0 - self.ystart[pick_block])))) else: self.ky.append(self.kmin)
def calc_opac(self): """ calculates the opacities from the Chebyshev coefficients """ for b in range(self.nbins_perfile): # chebyshev series with the correct coefficients series = T(self.coeffs[self.ncoeffs*b:self.ncoeffs*(b+1)]) for y in range(self.ny): yp = self.ypoints[y] if yp >= self.ystart[b]: arg = (2.0*yp-1.0-self.ystart[b])/(1.0-self.ystart[b]) self.ky.append(np.exp(series(arg))) else: self.ky.append(self.kmin)
def func(z, p0, p1, p2, p3): return T([p0, p1, p2, p3])(z)
def func(z, p0, p1, p2): return T([p0, p1, p2])(z)
def func(z, p0, p1, p2): zeta = np.log10((1.0 + z) / (1.0 + 3.5)) return T([p0, p1, p2])(1 + z)
def func(z, p0, p1): return T([p0, p1])(z)
def func(z, p0, p1): return T([p0, p1], domain=[3.7, 7.])(z)
downerr = c - l ax.scatter(zmean, c, color='k', edgecolor='None', zorder=2) ax.errorbar(zmean, c, ecolor='k', capsize=0, xerr=np.vstack((left, right)), yerr=np.vstack((uperr, downerr)), fmt='None', zorder=2) z = np.linspace(0, 7, 500) coeffs = chebfit(zmean[:-1] + 1.0, c[:-1], 1) print(coeffs) plt.plot(z, T(coeffs)(z + 1), lw=2, c='forestgreen') plt.savefig('cfit_alpha.pdf', bbox_inches='tight') #plt.close('all') elif case == 1: fig = plt.figure(figsize=(7, 7), dpi=100) ax = fig.add_subplot(1, 1, 1) ax.tick_params('both', which='major', length=7, width=1) ax.tick_params('both', which='minor', length=5, width=1) ax.set_ylabel(r'$\beta$') ax.set_xlabel('$z$') ax.set_xlim(0., 7)
print("Elevation") x=np.arange(5) print(poly(x)) y=np.arange(6).reshape(3,2) print(y) print(poly(y)) print(p(poly)) print(poly.roots()) from numpy.polynomial import Chebyshev as T #print(p + poly([1],domain=[0,1]))# you gor error because Traceback(most recent call last) and different dommine name print("\n ") print("Chebyshev ") print(poly(T([0, 1]))) print("calculus") print("\n") newdata =p([4,6]) print(newdata) print(newdata.integ()) print(newdata.integ(1)) print(newdata.integ(lbnd=-1)) print(newdata.integ(lbnd=-1, k=1)) print("\n") exa=p([1,2,3]) print(exa.deriv(1)) import matplotlib.pyplot as plt from numpy.polynomial import Chebyshev as T x = np.linspace(-1, 1, 100)
def atz(self, z, p): """Redshift evolution of QLF parameters.""" return T(p)(1+z)
def plot_m_star(fig, composite, sample=False): mpl.rcParams['font.size'] = '14' ax = fig.add_subplot(nplots_x, nplots_y, plot_number + 2) ax.yaxis.tick_right() ax.yaxis.set_ticks_position('both') ax.yaxis.set_label_position('right') ax.set_xlim(zmin, zmax) ax.set_ylim(-32, -23) if composite is not None: bf = composite.bf.x if sample: for theta in composite.samples[np.random.randint(len( composite.samples), size=900)]: params = composite.getparams(theta) M = composite.atz(z, params[1]) ax.plot(z, M, color='k', alpha=0.02, zorder=3) M = composite.atz(z, composite.getparams(bf)[1]) ax.plot(z, M, color='k', zorder=4) zmean, zl, zu, u, l, c = np.loadtxt('M_star.dat', unpack=True) select = zmean > 3.6 zl = zl[select] zu = zu[select] u = u[select] l = l[select] c = c[select] zmean = zmean[select] left = zmean - zl right = zu - zmean uperr = u - c downerr = c - l ax.scatter(zmean, c, color='k', edgecolor='None', zorder=2) ax.errorbar(zmean, c, ecolor='k', capsize=0, xerr=np.vstack((left, right)), yerr=np.vstack((uperr, downerr)), fmt='None', zorder=2) # zm, cm, uperr, downerr = np.loadtxt('Data/manti.txt', usecols=(0,4,5,6), unpack=True) # ax.scatter(zm, cm, color='k', edgecolor='None', zorder=2) # ax.errorbar(zm, cm, ecolor='k', capsize=0, # yerr=np.vstack((uperr, downerr)), # fmt='None', zorder=2) zc = np.linspace(0, 7, 500) coeffs = chebfit(zmean + 1, c, 1) print coeffs plt.plot(zc, T(coeffs)(zc + 1), lw=2, c='goldenrod') def func(z, p0, p1): return T([p0, p1])(z) sigma = np.abs(uperr + downerr) popt, pcov = curve_fit(func, zmean + 1, c, sigma=sigma, p0=[coeffs]) print popt plt.plot(zc, func(zc + 1, *popt), lw=2, c='r', dashes=[8, 3]) ax.set_xticks((0, 1, 2, 3, 4, 5, 6, 7)) ax.set_ylabel(r'$M_*$') ax.set_xticklabels('') return
def plot_phi_star(fig, composite, sample=False): mpl.rcParams['font.size'] = '14' ax = fig.add_subplot(nplots_x, nplots_y, plot_number + 1) ax.set_xlim(zmin, zmax) ax.set_ylim(-13, -5) if composite is not None: bf = composite.bf.x if sample: for theta in composite.samples[np.random.randint(len( composite.samples), size=900)]: params = composite.getparams(theta) phi = composite.atz(z, params[0]) ax.plot(z, phi, color='k', alpha=0.02, zorder=1) phi = composite.atz(z, composite.getparams(bf)[0]) ax.plot(z, phi, color='k', zorder=2) zmean, zl, zu, u, l, c = np.loadtxt('phi_star.dat', unpack=True) select = zmean > 3.6 zl = zl[select] zu = zu[select] u = u[select] l = l[select] c = c[select] zmean = zmean[select] left = zmean - zl right = zu - zmean uperr = u - c downerr = c - l ax.scatter(zmean, c, color='k', edgecolor='None', zorder=2) ax.errorbar(zmean, c, ecolor='k', capsize=0, xerr=np.vstack((left, right)), yerr=np.vstack((uperr, downerr)), fmt='None', zorder=2) zc = np.linspace(0, 7, 500) coeffs = chebfit(zmean + 1, c, 2) print coeffs plt.plot(zc, T(coeffs)(zc + 1), lw=2, c='goldenrod') def func(z, p0, p1, p2): return T([p0, p1, p2])(z) sigma = uperr + downerr popt, pcov = curve_fit(func, zmean + 1, c, sigma=sigma, p0=[coeffs]) print popt plt.plot(zc, func(zc + 1, *popt), lw=2, c='r', dashes=[8, 3]) # zm, cm, uperr, downerr = np.loadtxt('Data/manti.txt', usecols=(0,1,2,3), unpack=True) # ax.scatter(zm, cm, color='k', edgecolor='None', zorder=2) # ax.errorbar(zm, cm, ecolor='k', capsize=0, # yerr=np.vstack((uperr, downerr)), # fmt='None', zorder=2) ax.set_xticks((0, 1, 2, 3, 4, 5, 6, 7)) ax.set_ylabel( r'$\log_{10}\left(\phi_*/\mathrm{mag}^{-1}\mathrm{cMpc}^{-3}\right)$') ax.set_xticklabels('') return
def plot_alpha(fig, composite, sample=False): mpl.rcParams['font.size'] = '14' ax = fig.add_subplot(nplots_x, nplots_y, plot_number + 3) ax.set_xlim(zmin, zmax) ax.set_ylim(-6.5, -3) if composite is not None: bf = composite.bf.x if sample: for theta in composite.samples[np.random.randint(len( composite.samples), size=900)]: params = composite.getparams(theta) alpha = composite.atz(z, params[2]) ax.plot(z, alpha, color='k', alpha=0.02, zorder=3) alpha = composite.atz(z, composite.getparams(bf)[2]) ax.plot(z, alpha, color='k', zorder=4) zmean, zl, zu, u, l, c = np.loadtxt('alpha.dat', unpack=True) select = zmean > 3.6 zl = zl[select] zu = zu[select] u = u[select] l = l[select] c = c[select] zmean = zmean[select] left = zmean - zl right = zu - zmean uperr = u - c downerr = c - l ax.scatter(zmean, c, color='k', edgecolor='None', zorder=2) ax.errorbar(zmean, c, ecolor='k', capsize=0, xerr=np.vstack((left, right)), yerr=np.vstack((uperr, downerr)), fmt='None', zorder=2) # zm, cm, uperr, downerr = np.loadtxt('Data/manti.txt', usecols=(0,10,11,12), unpack=True) # ax.scatter(zm, cm, color='k', edgecolor='None', zorder=2, label='Manti et al.\ 2017') # ax.errorbar(zm, cm, ecolor='k', capsize=0, # yerr=np.vstack((uperr, downerr)), # fmt='None', zorder=2) zc = np.linspace(0, 7, 500) coeffs = chebfit(zmean + 1.0, c, 1) print coeffs plt.plot(zc, T(coeffs)(zc + 1), lw=2, c='goldenrod') def func(z, p0, p1): return T([p0, p1])(z) sigma = uperr + downerr popt, pcov = curve_fit(func, zmean + 1, c, sigma=sigma, p0=[coeffs]) print popt plt.plot(zc, func(zc + 1, *popt), lw=2, c='r', dashes=[8, 3]) # plt.legend(loc='upper left', fontsize=10, handlelength=1, # frameon=False, framealpha=0.0, labelspacing=.1, # handletextpad=0.1, borderpad=0.01, scatterpoints=1) ax.set_xticks((0, 1, 2, 3, 4, 5, 6, 7)) ax.set_ylabel(r'$\alpha$ (bright-end slope)') ax.set_xlabel('$z$') return
def plotParams(zmin, zmax): mpl.rcParams['font.size'] = '14' fig = plt.figure(figsize=(6, 6), dpi=100) K = 4 nplots_x = 2 nplots_y = 2 nplots = 4 factor = 2.0 # size of one side of one panel lbdim = 0.5 * factor # size of left/bottom margin trdim = 0.2 * factor # size of top/right margin whspace = 0.1 # w/hspace size plotdim = factor * K + factor * (K - 1.) * whspace dim = lbdim + plotdim + trdim lb = lbdim / dim tr = (lbdim + plotdim) / dim fig.subplots_adjust(left=lb, bottom=lb, right=tr, top=tr, wspace=whspace, hspace=whspace) zmin = 0 zmax = 15 zc = np.linspace(zmin, zmax, num=500) ax = fig.add_subplot(nplots_x, nplots_y, 1) ax.set_xlim(zmin, zmax) ax.set_ylim(-50, 0) ax.plot(zc, T(p_log10phiStar)(1 + zc), c='k', lw=2) ax.set_ylabel(r'$\log_{10}\phi_*$') ax.set_xticklabels('') ax = fig.add_subplot(nplots_x, nplots_y, 2) ax.yaxis.tick_right() ax.yaxis.set_ticks_position('both') ax.yaxis.set_label_position('right') ax.set_xlim(zmin, zmax) ax.set_ylim(-150, -20) ax.plot(zc, T(p_MStar)(1 + zc), c='k', lw=2) ax.set_ylabel(r'$M_*$') ax.set_xticklabels('') ax = fig.add_subplot(nplots_x, nplots_y, 3) ax.set_xlim(zmin, zmax) ax.set_ylim(-8, -3) ax.plot(zc, T(p_alpha)(1 + zc), c='k', lw=2) ax.set_ylabel(r'$\alpha$') ax = fig.add_subplot(nplots_x, nplots_y, 4) ax.yaxis.tick_right() ax.yaxis.set_ticks_position('both') ax.yaxis.set_label_position('right') ax.set_xlim(zmin, zmax) ax.set_ylim(-2.6, -1.5) h, f0, z0, a, b = p_beta zeta = np.log10((1.0 + zc) / (1.0 + z0)) beta = h + f0 / (10.0**(a * zeta) + 10.0**(b * zeta)) ax.plot(zc, beta, c='k', lw=2) ax.set_ylabel(r'$\beta$') plt.savefig('evolutionFC.pdf', bbox_inches='tight') mpl.rcParams['font.size'] = '22' return