Ejemplo n.º 1
0
    def qs0_t(self):
        t = lambda s: F100.tsk if s <= 2*geometry.l() else F100.tsp

        integral = 0.0
        integral2 = 0.0
        for i in range(self.q_t.shape[0]):
            integral += self.d * self.q_t[i]/t(self.p_t[i])
            integral2 += self.d/t(self.p_t[i])
        return integral/integral2
Ejemplo n.º 2
0
    def line_integral_t_z(self, end, ds=0.0001):
        t = lambda s: F100.tsk if s <= 2*geometry.l() else F100.tsp
            
        integral = 0.0
        s = 0.0
        while s < end:
            integral += ds*t(s)*self.x_t(s)
            s += ds

        return integral
Ejemplo n.º 3
0
    def calculate_density_spline(self, n_steps=1000):
        """Calculates and stores a spline of :math:`\\rho(X)`.
        
        Args:
          n_steps (int, optional): number of :math:`X` values
                                   to use for interpolation

        Raises:
            Exception: if :func:`set_theta` was not called before.
        """
        from scipy.integrate import quad
        from time import time
        from scipy.interpolate import UnivariateSpline
        
        if self.theta_deg == None:
            raise Exception('{0}::calculate_density_spline(): ' + 
                            'zenith angle not set'.format(
                             self.__class__.__name__))
        else:
            print ('{0}::calculate_density_spline(): ' + 
                   'Calculating spline of rho(X) for zenith ' + 
                   '{1} degrees.').format(self.__class__.__name__,
                                         self.theta_deg)

        thrad = self.thrad
        path_length = geom.l(thrad)
        vec_rho_l = np.vectorize(
            lambda delta_l: self.get_density(geom.h(delta_l, thrad)))
        dl_vec = np.linspace(0, path_length, n_steps)
        
        now = time()
        
        # Calculate integral for each depth point 
        # functionality could be more efficient :)
        X_int = np.zeros_like(dl_vec, dtype='float64')
        for i, dl in enumerate(dl_vec):
            X_int[i] = quad(vec_rho_l, 0, dl, epsrel=0.01)[0]

        print '.. took {0:1.2f}s'.format(time() - now)

        # Save depth value at h_obs
        self.X_surf = X_int[-1]
        
        # Interpolate with bi-splines without smoothing
        self.s_X2rho = UnivariateSpline(X_int, vec_rho_l(dl_vec),
                                        k=2, s=0.0)
        
        print 'Average spline error:', np.std(vec_rho_l(dl_vec) / 
                                              self.s_X2rho(X_int))
Ejemplo n.º 4
0
    def x_t(self, s):
        if s <= geometry.l():
            return (s*(F100.Ca-F100.h/2)/geometry.l())

        s -= geometry.l()
        if s <= geometry.l():
            return (F100.Ca-F100.h/2)-(s*(F100.Ca-F100.h/2)/geometry.l())
        s -= geometry.l()

        return 0
Ejemplo n.º 5
0
    def y_t(self, s):
        if s <= geometry.l():
            return -F100.h/2+s*(F100.h/2/geometry.l())
        
        s -= geometry.l()
        if s <= geometry.l():
            return s*(F100.h/2/geometry.l())
        s -= geometry.l()

        return -1*(s-F100.h/2)