Beispiel #1
0
 def mu(self, T, p):
     """Expecting T in Kelvin, p in bar"""
     if self.gas:
         kboltzmann_in_eVK = 8.6173324e-5
         # interpolate given grid
         try:
             val =  interp1d(T, self.T_grid, self.G_grid) + \
                    kboltzmann_in_eVK * T * log(p)
         except Exception, e:
             raise Exception('Could not find JANAF tables for %s.'
                             % self.name)
         else:
             return val
Beispiel #2
0
 def mu(self, T, p):
     """Expecting T in Kelvin, p in bar"""
     if self.gas:
         kboltzmann_in_eVK = 8.6173324e-5
         # interpolate given grid
         try:
             val =  interp1d(T, self.T_grid, self.G_grid) + \
                    kboltzmann_in_eVK * T * log(p)
         except Exception, e:
             print('Did you install JANAF tables?')
             raise
         else:
             return val
Beispiel #3
0
def adaptive_density_grid(grid,x,k=10,eps=0.01,fill=None):
    '''
    Follow the knn_1d_density estimation with interpolation of the
    density on a grid

    fill: if not given will fill with the mean rate
    '''
    centers,density = knn_1d_density(x,k,eps=eps)
    if len(centers)!=len(density):
        warn('something is wrong')
        warn(len(centers),len(density))
        N = min(len(centers),len(density))
        centers = centers[:N]
        density = density[:N]
    if fill is None: fill=mean(density)
    y = np.interp1d(centers,density,bounds_error=0,fill_value=fill)(grid)
    return y
Beispiel #4
0
    def timeseries_at(self, variable, t):
        """
        Return the value of a time series at the given time.

        :param variable: Variable name.
        :param t: Time.

        :returns: The interpolated value of the time series.

        :raises: KeyError
        """
        values = self.__timeseries_import_dict[variable]
        t_idx = bisect.bisect_left(self.__timeseries_import_times, t)
        if self.__timeseries_import_times[t_idx] == t:
            return values[t_idx]
        else:
            return np.interp1d(t, self.__timeseries_import_times, values)