Esempio n. 1
0
def dNdz_model(sample='qso', z_low=0.1, kind=1):

    if sample == 'qso':

        dNdz, z = np.loadtxt(
            f'/fs/ess/PHS0336/data/dr9v0.57.0/p38fnl/RF_g.txt').T
        dNdz_interp = IUS(z, dNdz)
        dNdz_interp.set_smoothing_factor(2.0)

        z_high = 4.0
        nz_low = lambda z: z**kind * dNdz_interp(z_low) / z_low**kind
        nz_high = lambda z: np.exp(-z**1.65) * dNdz_interp(z_high) / np.exp(
            -z_high**1.65)

        z_g = np.linspace(0.0, 10.0, 500)
        dNdz_g = dNdz_interp(z_g)
        dNdz_g[(z_g < z_low)] = nz_low(z_g[z_g < z_low])
        dNdz_g[(z_g > z_high)] = nz_high(z_g[z_g > z_high])

        #plt.plot(z, dNdz, 'b--', lw=4, alpha=0.3)
        #plt.plot(z_g, dNdz_g, 'r-')
        # plt.semilogy()
        # plt.ylim(1.0e-8, 1.e3)
        return z_g, dNdz_g

    elif sample == 'lrg':

        zmin, zmax, dNdz = np.loadtxt(
            '/fs/ess/PHS0336/data/rongpu/sv3_lrg_dndz_denali.txt',
            usecols=(0, 1, 2),
            unpack=True)
        zmid = 0.5 * (zmin + zmax)
        dNdz_interp = IUS(zmid, dNdz, ext=1)
        dNdz_interp.set_smoothing_factor(2.0)
        z_g = np.linspace(0.0, 5.0, 500)
        dNdz_g = dNdz_interp(z_g)

        return z_g, dNdz_g

    elif sample == 'mock':

        z = np.arange(0.0, 3.0, 0.001)
        i_lim = 26.  # Limiting i-band magnitude
        z0 = 0.0417 * i_lim - 0.744
        Ngal = 46. * 100.31 * (i_lim - 25.)  # Normalisation, galaxies/arcmin^2
        pz = 1. / (2. * z0) * (z / z0)**2. * np.exp(
            -z / z0)  # Redshift distribution, p(z)
        dNdz = Ngal * pz  # Number density distribution

        return z, dNdz
    else:
        raise NotImplemented(f'{sample}')
Esempio n. 2
0
def noisefilter(t, signal, avgpts=30, smoothfac=1600):
    smooth = rolling_mean(signal[::-1], avgpts)[::-1]
    fspline = InterpolatedUnivariateSpline(t[:-avgpts], smooth[:-avgpts], k=4)
    fspline.set_smoothing_factor(smoothfac)
    return fspline(t)
Esempio n. 3
0
ax00.axhline(0, color='black', linestyle='--')


def movingaverage(values, window):
    weights = np.repeat(1.0, window) / window
    sma = np.convolve(values, weights, 'valid')
    return sma


# Calculate the mean
mean = movingaverage(var, 12 * 10)
mean_time = movingaverage(time, 12 * 10)

# Smooth the line
mean = InterpolatedUnivariateSpline(mean_time, mean)
mean.set_smoothing_factor(0.2)
mean = mean(mean_time)

# to convert num2date in days sine ..
# since it does not have month as a timedelta
mean_time = mean_time * 30

# Format time axis
mean_time_format = num2date(mean_time[:], units='days since 1856-01-01')
time = num2date(time[:] * 30, units='days since 1856-01-01')

# plot all data
ax00.fill_between(time[:],
                  var[:],
                  0,
                  where=var >= 0.,
Esempio n. 4
0
print(arr_rho)

# form array -> 1D
arr_r = np.asarray(arr_r)
arr_r = np.asarray(arr_r).squeeze()
arr_rho = np.asarray(arr_rho).squeeze()

# define axis
x = arr_r
y = arr_rho

# generate spline
xs = np.logspace(0, 100, 10000)
# spl = UnivariateSpline(x, y)
spl = InterpolatedUnivariateSpline(x, y, k=3)
spl.set_smoothing_factor(0.00001)

# get value from spline
# def spline_val(pos):
#     return spl.__call__(1, nu=0, ext=None)

# for x in range(1, 2, 0.1):
# print(spline_val(x))

# Plot firts term of rho
# plt.plot(listb)

# Plot raw_data
# plt.plot(x, y, 'ro', ms=5)

# Plot spline
Esempio n. 5
0
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import InterpolatedUnivariateSpline
from scipy import integrate
k = np.inf

file = np.loadtxt('podaci.txt')
tal = file[:,0]
inte = file[:,1] 

spl = InterpolatedUnivariateSpline(tal, inte, k=3)
spl.set_smoothing_factor(0.1)
xs = file[:,0]
ys = spl(xs)
plt.plot(tal, inte, '.-')
plt.plot(xs, ys)
plt.show()

print (spl.integral(0, np.inf))