Example #1
0
 def test_shapes_scalarvalue_derivative(self):
     P = KroghInterpolator(self.xs,self.ys)
     n = P.n
     assert_array_equal(np.shape(P.derivatives(0)), (n,))
     assert_array_equal(np.shape(P.derivatives(np.array(0))), (n,))
     assert_array_equal(np.shape(P.derivatives([0])), (n,1))
     assert_array_equal(np.shape(P.derivatives([0,1])), (n,2))
Example #2
0
 def test_wrapper(self):
     P = KroghInterpolator(self.xs, self.ys)
     ki = krogh_interpolate
     assert_almost_equal(P(self.test_xs), ki(self.xs, self.ys, self.test_xs))
     assert_almost_equal(P.derivative(self.test_xs, 2),
                         ki(self.xs, self.ys, self.test_xs, der=2))
     assert_almost_equal(P.derivatives(self.test_xs, 2),
                         ki(self.xs, self.ys, self.test_xs, der=[0, 1]))
Example #3
0
    def test_int_inputs(self):
        # Check input args are cast correctly to floats, gh-3669
        x = [0, 234,468,702,936,1170,1404,2340,3744,6084,8424,13104,60000]
        offset_cdf = np.array([-0.95, -0.86114777, -0.8147762, -0.64072425, -0.48002351,
                               -0.34925329, -0.26503107, -0.13148093, -0.12988833, -0.12979296,
                               -0.12973574, -0.08582937, 0.05])
        f = KroghInterpolator(x, offset_cdf)

        assert_allclose(abs((f(x) - offset_cdf) / f.derivative(x, 1)), 0, atol=1e-10)
Example #4
0
 def test_hermite(self):
     xs = [0,0,0,1,1,1,2]
     ys = [self.true_poly(0),
           self.true_poly.deriv(1)(0),
           self.true_poly.deriv(2)(0),
           self.true_poly(1),
           self.true_poly.deriv(1)(1),
           self.true_poly.deriv(2)(1),
           self.true_poly(2)]
     P = KroghInterpolator(self.xs,self.ys)
     assert_almost_equal(self.true_poly(self.test_xs),P(self.test_xs))
Example #5
0
def parametres(r, interpolation):

    FaCO = [0.172, 0.345, 0.689, 1.03, 1.38, 2.07, 3.45, 5.17, 6.89]
    e = [0.19, 0.22, 0.26, 0.28, 0.30, 0.34, 0.38, 0.42, 0.44]
    Y = [2.30, 1.99, 1.71, 1.55, 1.45, 1.31, 1.15, 1.04, 1.00]

    if interpolation == "lineaire":
        f = interpolate.interp1d(FaCO, e)
        g = interpolate.interp1d(FaCO, Y)

    if interpolation == "cubique":
        f = KroghInterpolator(FaCO, e)
        g = KroghInterpolator(FaCO, Y)

    if interpolation == "cubique":
        f = interpolate.interp1d(FaCO, e, kind='cubic')
        g = interpolate.interp1d(FaCO, Y, kind='cubic')

    e = f(r)
    y = g(r)
    X = 1 - e * y

    return float(e), float(X), float(y)
Example #6
0
def cutoff(x, a=1, b=2, radius=0.2, L=3, deg=3):
    a0 = a
    b0 = b
    a1 = a0 + radius
    b1 = b0 - radius

    assert a1 <= b1, 'a + radius must be less than b - radius'

    pts1 = np.concatenate((a0 * np.ones(deg), a1 * np.ones(deg)))
    vals1 = np.zeros(2 * deg)
    vals1[deg] = 1
    krogh1 = KroghInterpolator(pts1, vals1)

    pts2 = np.concatenate((b1 * np.ones(deg), b0 * np.ones(deg)))
    vals2 = np.zeros(2 * deg)
    vals2[0] = 1
    krogh2 = KroghInterpolator(pts2, vals2)

    return np.piecewise(x, [
        np.logical_and(x > a0, x < a1),
        np.logical_and(x >= a1, x <= b1),
        np.logical_and(x > b1, x < b0)
    ], [krogh1, 1, krogh2, 0])
Example #7
0
def _poly(xx, yy):
    """
    Uses polynomial interpolation to find a function matching
    a dataset.

    Args:
        xx (1darray): X-coordinates sorted in increasing order.
        yy (1darray): Corresponding y-coordinates.

    Returns:
        intfunc (PPoly): The interpolated function.

    """
    intfunc = KroghInterpolator(xx, yy)
    return intfunc
Example #8
0
def kroghInterpolation():
    sample_rate, sample = wavfile.read('songs/hakuna_matata.wav')
    sample = sample[5000000:5000100]

    sample_rateBAD, sampleBAD = wavfile.read(
        'songs/bad_songs/not_good_song.wav')
    sampleBAD = sampleBAD[5000000:5000100]

    BadSample = sample.copy()

    dz.theEvilMethod(BadSample, 0.5)
    matches = recognize.cheat(sample, BadSample)
    x, y = utils.tovalidxy(BadSample, matches)
    f = KroghInterpolator(x, y)

    utils.repair(BadSample, matches, f)
    IwannaSee(sample, BadSample, sampleBAD)
Example #9
0
def calculate_and_save_results(inputpath, outputpath):
    """
    Docstring
    """
    rd.load_data(inputpath)
    mass = rd.particle_mass()
    x_min = rd.x_minimum()
    x_max = rd.x_maximum()
    npoint = rd.n_point()
    fval = rd.first_eigenvalue()
    lval = rd.last_eigenvalue()
    inter_type = rd.interpolation_type()
    x_pot = rd.x_potential()
    y_pot = rd.y_potential()
    delta = (x_max-x_min)/npoint
    const_a = 1/(mass*delta**2)
    x_axis = np.linspace(x_min, x_max, npoint)

    #interpolating
    y_pot_inter = []
    if inter_type == "polynomial":
        y_pot_inter = KroghInterpolator(x_pot, y_pot)
    else:
        y_pot_inter = interp1d(x_pot, y_pot, kind=inter_type)

    #calculating
    expected_x = np.array([])
    uncertainties = np.array([])
    energies = np.array([])
    norm_eigenvecs = np.array([])
    maindiag = y_pot_inter(x_axis)+const_a
    seconddiag = np.full(npoint-1, -1/2*const_a)
    selectrange = (fval-1, lval-1)
    ev = eigh_tridiagonal(maindiag, seconddiag, select="i", select_range=selectrange)
    (energies, eigenvecs) = ev
    norm_eigenvecs = np.array([normalize(eigenvec, delta) for eigenvec in eigenvecs.T])
    expected_x = np.array([exp_x(eigenvec, delta, x_axis) for eigenvec in norm_eigenvecs])
    uncertaintylist = [uncertainty(eigenvec, delta, x_axis) for eigenvec in norm_eigenvecs]
    uncertainties = np.array(uncertaintylist)

    rd.save_xyformat(outputpath + "/potential.dat", x_axis, y_pot_inter(x_axis))
    rd.save_nxyformat(outputpath + "/wavefuncs.dat", x_axis, norm_eigenvecs.T)
    rd.save_xyformat(outputpath + "/energies.dat", energies, ["" for _ in energies])
    rd.save_xyformat(outputpath + "/expvalues.dat", expected_x, uncertainties)
    def data_to_function(self):
        '''
        Uses the KroghInterpolator to make a function from our
        data and uses that function to predict the prices at
        the wanted dates.

        returns: wanted dates (self.intra_x_values)
        and their associated predicted prices (self.intra_y_values)
        '''
        print(self.x_values)
        print(self.y_values)
        poly_func = KroghInterpolator(self.x_values, self.y_values)
        self.creating_wanted_days(self.n_days)
        #self.intra_x_values= [1477492378020,1477492378030]
        #self.intra_x_values = self.intra_x_values[:-1]
        self.intra_x_values = np.asarray(self.intra_x_values)
        #print(self.intra_x_values)
        print(self.intra_x_values)
        self.intra_y_values = poly_func.__call__(self.intra_x_values)
        print(self.intra_y_values)
        return self.intra_x_values, self.intra_y_values
Example #11
0
 def test_shapes_scalarvalue(self):
     P = KroghInterpolator(self.xs, self.ys)
     assert_array_equal(np.shape(P(0)), ())
     assert_array_equal(np.shape(P(np.array(0))), ())
     assert_array_equal(np.shape(P([0])), (1, ))
     assert_array_equal(np.shape(P([0, 1])), (2, ))
Example #12
0
 def test_hermite(self):
     P = KroghInterpolator(self.xs, self.ys)
     assert_almost_equal(self.true_poly(self.test_xs), P(self.test_xs))
Example #13
0
 def test_empty(self):
     P = KroghInterpolator(self.xs, self.ys)
     assert_array_equal(P([]), [])
Example #14
0
 def test_derivative(self):
     P = KroghInterpolator(self.xs, self.ys)
     m = 10
     r = P.derivatives(self.test_xs, m)
     for i in range(m):
         assert_almost_equal(P.derivative(self.test_xs, i), r[i])
Example #15
0
 def test_high_derivative(self):
     P = KroghInterpolator(self.xs, self.ys)
     for i in range(len(self.xs), 2 * len(self.xs)):
         assert_almost_equal(P.derivative(self.test_xs, i),
                             np.zeros(len(self.test_xs)))
Example #16
0
 def test_shapes_vectorvalue_derivative(self):
     P = KroghInterpolator(self.xs, np.outer(self.ys, np.arange(3)))
     n = P.n
     assert_array_equal(np.shape(P.derivatives(0)), (n, 3))
     assert_array_equal(np.shape(P.derivatives([0])), (n, 1, 3))
     assert_array_equal(np.shape(P.derivatives([0, 1])), (n, 2, 3))
Example #17
0
def interpolate(x0, x1, m0, m1, t0, t1):
    x = np.repeat([t0, t1], 2)
    y = np.ravel(np.dstack(([x0, x1], [m0, m1])))
    return KroghInterpolator(x, y)
Example #18
0
def main():
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--Tmin',
                        type=float,
                        default=.050,
                        help='minimum temperature')
    parser.add_argument('--Ta',
                        type=float,
                        default=.165,
                        help='connection range minimum temperature')
    parser.add_argument('--Tb',
                        type=float,
                        default=.200,
                        help='connection range maximum temperature')
    parser.add_argument('--Tmax',
                        type=float,
                        default=.500,
                        help='maximum temperature')
    parser.add_argument('--nsteps',
                        type=int,
                        default=10**5,
                        help='number of energy density steps')
    parser.add_argument('--species',
                        choices=['all', 'urqmd', 'id'],
                        default='urqmd',
                        help='HRG species')
    parser.add_argument('--res-width-off',
                        action='store_false',
                        dest='res_width',
                        help='do not account for finite width of resonances')
    parser.add_argument('--plot',
                        nargs='?',
                        metavar='FILE',
                        const='<show>',
                        default=False,
                        help='plot EoS instead of printing table')
    parser.add_argument('--music_output_format',
                        action='store_true',
                        dest='music_output_format',
                        default=False,
                        help='EOS format expected by MUSIC')
    parser.add_argument('--write-bin',
                        metavar='FILE',
                        help='write binary file instead of printing table')
    args = parser.parse_args()

    hrg_kwargs = dict(species=args.species, res_width=args.res_width)

    # split full temperature range into three parts:
    #   low-T (l):  Tmin < T < Ta  (HRG)
    #   mid-T (m):  Ta < T < Tb  (connection)
    #   high-T (h):  Tb < T < Tmax  (lattice)

    # number of extra temperature points below Tmin and above Tmax
    # (helps cubic interpolation)
    nextrapts = 2

    # compute low-T (HRG) trace anomaly
    Tl = T_points(args.Tmin, args.Ta, 200, extra_low=nextrapts)
    e3p_T4_l = HRGEOS(Tl, **hrg_kwargs).e3p_T4()

    # compute mid-T (connection) using an interpolating polynomial that
    # matches the function values and first several derivatives at the
    # connection endpoints (Ta, Tb)
    nd = 5

    # use Krogh interpolation near the endpoints to estimate derivatives
    def derivatives(f, T0, dT=.001):
        # evaluate function at Chebyshev zeros as suggested by docs
        T = T0 + dT * np.cos(np.linspace(0, np.pi, nd))
        return KroghInterpolator(T, f(T)).derivatives(T0)

    # use another Krogh interpolation for the connection polynomial
    # skip (Ta, Tb) endpoints in Tm since they are already in (Tl, Th)
    Tm = T_points(args.Ta, args.Tb, 100, extra_low=-1, extra_high=-1)
    e3p_T4_m = KroghInterpolator(
        nd * [args.Ta] + nd * [args.Tb],
        np.concatenate([
            derivatives(lambda T: HRGEOS(T, **hrg_kwargs).e3p_T4(), args.Ta),
            derivatives(e3p_T4_lattice, args.Tb)
        ]))(Tm)

    # compute high-T part (lattice)
    Th = T_points(args.Tb, args.Tmax, 1000, extra_high=nextrapts)
    e3p_T4_h = e3p_T4_lattice(Th)

    # join temperature ranges together
    T = np.concatenate([Tl, Tm, Th])
    e3p_T4 = np.concatenate([e3p_T4_l, e3p_T4_m, e3p_T4_h])

    # pressure is integral of trace anomaly over temperature starting from some
    # reference temperature, Eq. (12) in HotQCD paper:
    #   p/T^4(T) = p/T^4(T_0) + \int_{T_0}^T dT (e - 3p)/T^5
    delta_p_T4_spline = CubicSpline(T, e3p_T4 / T).antiderivative()
    p_T4_0 = HRGEOS(T[:1], **hrg_kwargs).p_T4()[0]

    def compute_p_T4(T):
        p_T4 = delta_p_T4_spline(T)
        p_T4 += p_T4_0
        return p_T4

    p_T4 = compute_p_T4(T)
    e_T4 = e3p_T4 + 3 * p_T4

    if args.plot:
        plot(T, e3p_T4, p_T4, e_T4, args, hrg_kwargs)
        return

    # energy density at original temperature points
    e_orig = e_T4 * T**4 / HBARC**3

    # compute thermodynamic quantities at evenly-spaced energy density points
    # as required by osu-hydro
    e = np.linspace(e_orig[nextrapts], e_orig[-nextrapts - 1], args.nsteps)
    T = CubicSpline(e_orig, T)(e)
    p = compute_p_T4(T) * T**4 / HBARC**3
    s = (e + p) / T

    if args.write_bin:
        with open(args.write_bin, 'wb') as f:
            if (args.music_output_format):
                for x in zip(e, p, s, T):
                    f.write(x[0])
                    f.write(x[1])
                    f.write(x[2])
                    f.write(x[3])
            else:
                for x in [e[0], e[-1], p, s, T]:
                    f.write(x.tobytes())
    else:
        # output table
        fmt = 4 * '{:24.16e}'
        for row in zip(e, p, s, T):
            print(fmt.format(*row))
Example #19
0
 def derivatives(f, T0, dT=.001):
     # evaluate function at Chebyshev zeros as suggested by docs
     T = T0 + dT * np.cos(np.linspace(0, np.pi, nd))
     return KroghInterpolator(T, f(T)).derivatives(T0)
Example #20
0
 def test_high_degree_warning(self):
     with pytest.warns(UserWarning, match="40 degrees provided,"):
         KroghInterpolator(np.arange(40), np.ones(40))
Example #21
0
def calculate_and_save_results(inputpath, outputpath):
    """
    this function does three things:
        -interpolating the given points of the potential defined by the user
        -solving the schrodinger equation and calculating the eigenstates,
    eigenvalues, expected values and uncertainties
        -saving the results in .dat files

    :type inputpath: string
    :param inputpath: path of the schrodinger.inp file containing the input information

    :type outputpath: string
    :param outputpath: path of the directory the .dat files will be stored in
    """
    rd.load_data(inputpath)
    mass = rd.particle_mass()
    x_min = rd.x_minimum()
    x_max = rd.x_maximum()
    npoint = rd.n_point()
    fval = rd.first_eigenvalue()
    lval = rd.last_eigenvalue()
    inter_type = rd.interpolation_type()
    x_pot = rd.x_potential()
    y_pot = rd.y_potential()
    delta = (x_max - x_min) / npoint
    const_a = 1 / (mass * delta**2)
    x_axis = np.linspace(x_min, x_max, npoint)
    y_pot_inter = []
    expected_x = np.array([])
    uncertainties = np.array([])
    energies = np.array([])
    norm_eigenvecs = np.array([])

    #interpolating
    if inter_type == "polynomial":
        y_pot_inter = KroghInterpolator(x_pot, y_pot)
    else:
        y_pot_inter = interp1d(x_pot, y_pot, kind=inter_type)

    #calculating
    maindiag = y_pot_inter(x_axis) + const_a
    seconddiag = np.full(npoint - 1, -1 / 2 * const_a)
    selectrange = (fval - 1, lval - 1)
    ev = eigh_tridiagonal(maindiag,
                          seconddiag,
                          select="i",
                          select_range=selectrange)
    (energies, eigenvecs) = ev
    norm_eigenvecs = np.array(
        [normalize(eigenvec, delta) for eigenvec in eigenvecs.T])
    expected_x = np.array(
        [exp_x(eigenvec, delta, x_axis) for eigenvec in norm_eigenvecs])
    uncertaintylist = [
        uncertainty(eigenvec, delta, x_axis) for eigenvec in norm_eigenvecs
    ]
    uncertainties = np.array(uncertaintylist)

    #saving
    if not outputpath.endswith("/"):
        outputpath = outputpath + "/"
    rd.save_xyformat(outputpath + "potential.dat", x_axis, y_pot_inter(x_axis))
    rd.save_nxyformat(outputpath + "wavefuncs.dat", x_axis, norm_eigenvecs.T)
    rd.save_xyformat(outputpath + "energies.dat", energies,
                     ["" for _ in energies])
    rd.save_xyformat(outputpath + "expvalues.dat", expected_x, uncertainties)

    print("The results have been saved succesfully into the folder \"" +
          outputpath + "\".")
# 埃尔米特插值
from scipy.interpolate import KroghInterpolator
import numpy as np
import matplotlib.pyplot as plt


def f(x):
    return x**3 + 1


xs = np.linspace(-5, 5, 100)
nodes = np.array([0, 1, 2, 3])
xi = np.array([0, 1, 2, 3])
yi = np.array([1, 2, 9, 28])
interpolant = KroghInterpolator(xi, yi)
plt.figure()

plt.subplot(121)
plt.plot(xs, interpolant(xs), "b--", label="Hermite interpolation")
plt.plot(nodes, f(nodes), "ro", label="nodes")
# 显示图中的标签
plt.legend(loc=9)
# 设定坐标上下限
plt.xlim(-10.5, 10.5)
plt.title("$f(x) = x^3 + 1$")
# 1行 2列
plt.subplot(122)
plt.plot(xs, f(xs), "g--", label="original")
plt.plot(xi, f(xi), "ro", label="nodes")
plt.legend(loc=9)
Example #23
0
plt.plot(FaCO, e, 'o', x, f(x), '-')  #courbe (FaCO,e) et (x,f(x))
plt.xlabel('FaCO')  #nomme l'axe des x puis apres y
plt.ylabel('e')
plt.title('interpolation_lineaire,e=f(FaCO)')  #on nomme le graphique
plt.show()  #on affiche

g = interpolate.interp1d(FaCO, Y)
x = np.linspace(0.172, 6.89, 100)
y = g(x)
plt.plot(FaCO, Y, 'o', x, g(x), '-')
plt.xlabel('Y')
plt.ylabel('e')
plt.title('interpolation_lineaire,Y=f(Faco)')
plt.show()

f = KroghInterpolator(FaCO, e)  #interpolation polynomiale
x = np.linspace(0.172, 6.89, 100)
y = f(x)
plt.plot(FaCO, e, 'o', x, f(x), '-')
plt.xlabel('FaCO')
plt.ylabel('e')
plt.title('interpolation_polynomiale,e=f(FaCO)')
plt.show()

g = KroghInterpolator(FaCO, Y)
x = np.linspace(0.172, 6.89, 100)
y = g(x)
plt.plot(FaCO, Y, 'o', x, g(x), '-')
plt.xlabel('Y')
plt.ylabel('e')
plt.title('interpolation_polynomiale,Y=f(Faco)')
Example #24
0
def main():
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter
    )
    parser.add_argument(
        '--Tmin', type=float, default=.050,
        help='minimum temperature'
    )
    parser.add_argument(
        '--Ta', type=float, default=.165,
        help='connection range minimum temperature'
    )
    parser.add_argument(
        '--Tb', type=float, default=.200,
        help='connection range maximum temperature'
    )
    parser.add_argument(
        '--Tmax', type=float, default=.500,
        help='maximum temperature'
    )
    parser.add_argument(
        '--nsteps', type=int, default=10**5,
        help='number of energy density steps'
    )
    parser.add_argument(
        '--species', choices=['all', 'urqmd', 'id'], default='urqmd',
        help='HRG species'
    )
    parser.add_argument(
        '--res-width-off', action='store_false', dest='res_width',
        help='do not account for finite width of resonances'
    )
    parser.add_argument(
        '--plot', nargs='?', metavar='FILE', const='<show>', default=False,
        help='plot EoS instead of printing table'
    )
    parser.add_argument(
        '--write-bin', metavar='FILE',
        help='write binary file instead of printing table'
    )
    args = parser.parse_args()

    hrg_kwargs = dict(species=args.species, res_width=args.res_width)

    # split full temperature range into three parts:
    #   low-T (l):  Tmin < T < Ta  (HRG)
    #   mid-T (m):  Ta < T < Tb  (connection)
    #   high-T (h):  Tb < T < Tmax  (lattice)

    # number of extra temperature points below Tmin and above Tmax
    # (helps cubic interpolation)
    nextrapts = 2

    # compute low-T (HRG) trace anomaly
    Tl = T_points(args.Tmin, args.Ta, 200, extra_low=nextrapts)
    e3p_T4_l = HRGEOS(Tl, **hrg_kwargs).e3p_T4()

    # compute mid-T (connection) using an interpolating polynomial that
    # matches the function values and first several derivatives at the
    # connection endpoints (Ta, Tb)
    nd = 5

    # use Krogh interpolation near the endpoints to estimate derivatives
    def derivatives(f, T0, dT=.001):
        # evaluate function at Chebyshev zeros as suggested by docs
        T = T0 + dT*np.cos(np.linspace(0, np.pi, nd))
        return KroghInterpolator(T, f(T)).derivatives(T0)

    # use another Krogh interpolation for the connection polynomial
    # skip (Ta, Tb) endpoints in Tm since they are already in (Tl, Th)
    Tm = T_points(args.Ta, args.Tb, 100, extra_low=-1, extra_high=-1)
    e3p_T4_m = KroghInterpolator(
        nd*[args.Ta] + nd*[args.Tb],
        np.concatenate([
            derivatives(lambda T: HRGEOS(T, **hrg_kwargs).e3p_T4(), args.Ta),
            derivatives(e3p_T4_lattice, args.Tb)
        ])
    )(Tm)

    # compute high-T part (lattice)
    Th = T_points(args.Tb, args.Tmax, 1000, extra_high=nextrapts)
    e3p_T4_h = e3p_T4_lattice(Th)

    # join temperature ranges together
    T = np.concatenate([Tl, Tm, Th])
    e3p_T4 = np.concatenate([e3p_T4_l, e3p_T4_m, e3p_T4_h])

    # pressure is integral of trace anomaly over temperature starting from some
    # reference temperature, Eq. (12) in HotQCD paper:
    #   p/T^4(T) = p/T^4(T_0) + \int_{T_0}^T dT (e - 3p)/T^5
    delta_p_T4_spline = CubicSpline(T, e3p_T4/T).antiderivative()
    p_T4_0 = HRGEOS(T[:1], **hrg_kwargs).p_T4()[0]

    def compute_p_T4(T):
        p_T4 = delta_p_T4_spline(T)
        p_T4 += p_T4_0
        return p_T4

    p_T4 = compute_p_T4(T)
    e_T4 = e3p_T4 + 3*p_T4

    # energy density at original temperature points
    e_orig = e_T4 * T**4 / HBARC**3

    # compute thermodynamic quantities at evenly-spaced energy density points
    # as required by osu-hydro
    e = np.linspace(e_orig[nextrapts], e_orig[-nextrapts - 1], args.nsteps)
    T = CubicSpline(e_orig, T)(e)
    p = compute_p_T4(T) * T**4 / HBARC**3
    s = (e + p)/T
    
    Tc = 0.270
    tlat = Tc*np.array([0.7, 0.74, 0.78, 0.82, 0.86, 0.9, 0.94, 0.98, 1, 1.02, 1.06, 1.10, 1.14, 1.18, 1.22, 1.26, 1.30, 1.34, 1.38, 1.42, 1.46, 1.5, 2, 2.5, 3, 3.5, 4.0, 4.5, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 80, 100, 200, 300, 400, 500, 600, 800, 1000])
    Ilat = np.array([.0104, .0162, .0232, .0318, .0433, .0594, .0859, .1433, 1.0008, 2.078, 2.4309, 2.4837, 2.4309, 2.3426, 2.2342, 2.1145, 1.998, 1.8867, 1.7809, 1.6810, 1.5872, 1.4995, 0.8038, 0.5057, 0.3589, 0.2736, 0.2207, 0.1855, 0.1606, 0.1266, 0.1050, 0.0903, 0.0798, 0.0720, 0.0375, 0.0265, 0.0216, 0.0191, 0.0174, 0.0154, 0.0142, 0.0112, 0.01, 0.0091, 0.0085, 0.0080, 0.0073, 0.0068])
    plat = np.array([0.0015, 0.0023, 0.0033, 0.0046, 0.0064, 0.0087, 0.0118, 0.0164, 0.0222, 0.0571, 0.1455, 0.237, 0.325, 0.4074, 0.4837, 0.5539, 0.6181, 0.677, 0.7309, 0.7804, 0.8258, 0.8675, 1.189, 1.3319, 1.4098, 1.4582, 1.491, 1.5149, 1.533, 1.5591, 1.5768, 1.5898, 1.5998, 1.6078, 1.6444, 1.6572, 1.6641, 1.6686, 1.672, 1.6767, 1.68, 1.6887, 1.693, 1.6958, 1.6977, 1.6992, 1.7014, 1.703])

    e3p_T4_gluon = CubicSpline(tlat,Ilat)
    delta_p_T4_spline_gluon = CubicSpline(tlat, Ilat/tlat).antiderivative()
    p_T4_0_gluon = HRGEOS(tlat[:1], **hrg_kwargs).p_T4()[0]

    def compute_p_T4_gluon(T):
        p_T4 = delta_p_T4_spline_gluon(T)
        p_T4 += p_T4_0_gluon
        return p_T4

    p_T4_gluon = compute_p_T4_gluon(tlat)
    e_T4_gluon = Ilat + 3*plat

    # energy density at original temperature points
    e_orig_gluon = e_T4_gluon * tlat**4 / HBARC**3

    # compute thermodynamic quantities at evenly-spaced energy density points
    # as required by osu-hydro
    e_gluon = np.linspace(e_orig_gluon[nextrapts], e_orig_gluon[-nextrapts - 1], args.nsteps)
    T_gluon = CubicSpline(e_orig_gluon, tlat)(e)
    p_gluon = compute_p_T4_gluon(T) * T_gluon**4 / HBARC**3
    s_gluon = (e_gluon + p_gluon)/T_gluon
    
    plot(T, e3p_T4, p_T4, e_T4, T_gluon, e3p_T4_gluon, p_T4_gluon, e_T4_gluon, args, hrg_kwargs)
    return
Example #25
0
 def test_shapes_vectorvalue(self):
     P = KroghInterpolator(self.xs, np.outer(self.ys, np.arange(3)))
     assert_array_equal(np.shape(P(0)), (3, ))
     assert_array_equal(np.shape(P([0])), (1, 3))
     assert_array_equal(np.shape(P([0, 1])), (2, 3))
Example #26
0
 def test_scalar(self):
     P = KroghInterpolator(self.xs, self.ys)
     assert_almost_equal(self.true_poly(7), P(7))
     assert_almost_equal(self.true_poly(np.array(7)), P(np.array(7)))
Example #27
0
 def test_shapes_1d_vectorvalue(self):
     P = KroghInterpolator(self.xs, np.outer(self.ys, [1]))
     assert_array_equal(np.shape(P(0)), (1, ))
     assert_array_equal(np.shape(P([0])), (1, 1))
     assert_array_equal(np.shape(P([0, 1])), (2, 1))
Example #28
0
 def test_low_derivatives(self):
     P = KroghInterpolator(self.xs, self.ys)
     D = P.derivatives(self.test_xs, len(self.xs) + 2)
     for i in range(D.shape[0]):
         assert_almost_equal(self.true_poly.deriv(i)(self.test_xs), D[i])
Example #29
0
 def krogh_deriv(x, y, axis=0):
     return KroghInterpolator(x, y, axis).derivative
Example #30
0
from scipy.interpolate import KroghInterpolator

#from format_data import Formatter
import matplotlib.pyplot as plt
import time
import numpy as np

x_values = [1,2,3,4,5]
y_values = [6,7,8,9,10]
intra_x_values = [6,7,8]

poly_func = KroghInterpolator(x_values,y_values)
intra_x_values = np.asarray(intra_x_values)
intra_y_values = poly_func.__call__(intra_x_values)
print(intra_y_values)