Exemplo n.º 1
0
 def setInnerEps(self,inner_eps):
 
     '''
     Set the inner wind epsilon for the T law. Only relevant when self.inner
     is 1. 
     
     Changes the standard T law as well, in case inner eps is different from
     when the instance of the class was created.
     
     @param inner_eps: the epsilon of the inner wind power law. 
     @type inner_eps: float
     
     '''
     
     self.inner_eps = inner_eps
     
     #-- re-initialise some parameters
     self.r = None
     self.T = None
     self.y = None
     self.dTdr = None
     
     #-- Run the class' own eval() method, with r=self.x, which will not be 
     #   equal to the class' self.r attribute (which is now None), and thus 
     #   it will evaluated properly. Reevaluated if epsilon is different upon
     #   eval call.
     self.T = self.eval(self.x,inner_eps=self.inner_eps,warn=0)
     self.y = self.T
     
     #-- Now also redo the derivative method. Then call diff to set the 
     #   standard derivative of the instance
     if self.interp_dfunc: 
         self.dfunc = spline1d(x=self.x,y=op.diff_central(self.y,self.x),\
                               k=self.order)
     
     #-- Evaluate the derivative with the default grid
     self.dydx = self.diff(self.x,inner_eps=self.inner_eps,warn=0)
     
     #-- Now set r and dTdr.
     self.r = self.x
     self.dTdr = self.dydx
Exemplo n.º 2
0
    def setInnerEps(self, inner_eps):
        '''
        Set the inner wind epsilon for the T law. Only relevant when self.inner
        is 1. 
        
        Changes the standard T law as well, in case inner eps is different from
        when the instance of the class was created.
        
        @param inner_eps: the epsilon of the inner wind power law. 
        @type inner_eps: float
        
        '''

        self.inner_eps = inner_eps

        #-- re-initialise some parameters
        self.r = None
        self.T = None
        self.y = None
        self.dTdr = None

        #-- Run the class' own eval() method, with r=self.x, which will not be
        #   equal to the class' self.r attribute (which is now None), and thus
        #   it will evaluated properly. Reevaluated if epsilon is different upon
        #   eval call.
        self.T = self.eval(self.x, inner_eps=self.inner_eps, warn=0)
        self.y = self.T

        #-- Now also redo the derivative method. Then call diff to set the
        #   standard derivative of the instance
        if self.interp_dfunc:
            self.dfunc = spline1d(x=self.x,y=op.diff_central(self.y,self.x),\
                                  k=self.order)

        #-- Evaluate the derivative with the default grid
        self.dydx = self.diff(self.x, inner_eps=self.inner_eps, warn=0)

        #-- Now set r and dTdr.
        self.r = self.x
        self.dTdr = self.dydx
Exemplo n.º 3
0
    def __init__(self,x,func=interp_file,dfunc=None,order=3,*args,\
                 **kwargs):
    
        '''
        Create an instance of the Profiler() class. Requires a coordinate grid 
        and a function object for the profile. A function for the derivative is
        optional. The functions can also be given as an interpolation object.
        
        The optional args and kwargs give the additional arguments for the 
        two function, which are ignored in case func is an interpolation object.
        
        The default coordinate grid is evaluated for both the function and the
        derivative. They are saved in self.y and self.dydx. Alternatively, new
        evaluations can be attained through eval and diff.
        
        Note that if func is an interpolator object, the original input x and y
        grids can be passed as additional keywords xin and yin, which would then
        be arrays. Otherwise, the x and the interpolator(x) are set as xin and 
        yin. xin and yin are ignored if func is a function, even if it returns
        an interpolator (in which case the original grids are known)
        
        @param x: The default coordinate points, minimum three points. In the 
                  case of an interpolation function, this is the default grid
                  returned by the instance. The original x/y of the 
                  interpolated profile are saved as xori/yori in the object.
        @type x: array
        
        @keyword func: The function that describes the profile with respect to 
                       x. Can be given as an interp1d object. Default is a read
                       function that interpolates data and returns the 
                       interpolator object. If interpolation object, x and 
                       eval(x) are assumed to be the original grids, unless
                       xin and yin are given as keywords with arrays as values
                       for the original grids.
                       
                       (default: interp_file)
        @type func: function/interp1d object
        @keyword dfunc: Function that describes the derivative of the profile 
                        with respect to x. Can be given as an interpolation 
                        object. If None, a generic central difference is taken & 
                        interpolated with a spline of which the order can be 
                        chosen.
        
                        (default: None)
        @type dfunc: function/interpolation object
        @keyword order: Order of the spline interpolation of the derivative. 
                        Default is cubic. Not used for the interpolation if func
                        returns an interpolation object. Use read_order in that
                        case.
                        
                        (default: 3)
        @type order: int
        
        @keyword args: Additional parameters passed to the functions when eval
                       or diff are called. 
                       
                       (default: [])
        @type args: tuple
        @keyword kwargs: Additional keywords passed to the functions when eval
                         or diff are called. 
                       
                         (default: {})
        @type kwargs: dict
        
        '''
        
        #-- Check len of coordinate input. Cannot be less than three for the 
        #   derivative.
        if len(x) < 3:
            raise ValueError('Coordinate grid must have more than 2 elements.')
        
        #-- If the function is given as a string, retrieve it from the local 
        #   child module, or from the Profiler module (as parent). If the latter
        #   case then check if the function comes from one of Profiler's 
        #   attributes, such as the loaded DataIO module.
        #   Can also simply be a constant value, so try making a float first.
        if isinstance(func,str):
            try:
                #-- Check if a constant was given, rather than a function
                kwargs['c'] = float(func)
                func = constant

            except ValueError:
                #-- Note that self.module refers to the child, not Profiler
                if hasattr(sys.modules[self.__module__],func):
                    func = getattr(sys.modules[self.__module__],func)

                #-- Recursively find the function of loaded modules in Profiler
                #   or a function of the Profiler module itself if no '.'         
                else:
                    
                    func = DataIO.read(func=func,module=sys.modules[__name__],\
                                       return_func=1)
        
        #-- set functional args, remember spline order. args/kwargs for 
        #   func and dfunc are saved separately. They are removed if either are
        #   interpolation objects. They are always accessible, the _** variables
        #   are passed to the evaluation.
        self.args = args
        self.kwargs = kwargs
        self._args = self.args
        self._dargs = self.args
        self._dkwargs = self.kwargs
        self._kwargs = self.kwargs
        self.order = order
        
        #-- Grab default xin and yin keys in case they are included, and remove
        #   from the arguments dictionary. None if not available. 
        xin = self.kwargs.pop('xin',None)
        yin = self.kwargs.pop('yin',None)
        
        #-- By default no interpolation, so leave this off.
        self.interp_func = 0
        self.interp_dfunc = 0
        
        #-- Defaults for xori/yori, not used in case of normal functions
        self.xin = np.empty(0)
        self.yin = np.empty(0)
        
        #-- Evaluate the default grid with function. Set x as None first so it
        #   can actually evaluate. Set x once derivative has been evaluated. 
        self.x = None
        if not (isinstance(func,interp1d) or isinstance(func,UnivariateSpline)):
            #-- Evaluate the function, and check what is returned: array or 
            #   interpolation object
            y = func(x,*args,**kwargs)
            
            #-- Interpolation object: so set that as this instance's func. In 
            #   this case, the variable x passed to the class is the default x
            #   grid of this instance. The original x/y-grid is saved as xi, yi
            if isinstance(y,tuple):
                self.func = y[2]
                self.xin = y[0]
                self.yin = y[1]
                self._args = []
                self._kwargs = {}
                self.interp_func = 1
                self.y = self.func(x)
            else: 
                self.func = func
                self.y = y
                
        #-- func is an interpolation object, so just run the normal evaluation.
        #   Set _args/_kwargs to empty, so none are ever passed to the interpol
        else:
            self.func = func
            self._args = []
            self._kwargs = {}
            self.interp_func = 1
            self.y = self.func(x)
            self.yin = yin if not yin is None else self.y
            self.xin = xin if not xin is None else x
                                                    
        #-- Set the derivative function, resorting to default if needed
        if not dfunc is None:
            self.dfunc = dfunc
        elif self.func == constant:
            self.dfunc = zero
        else: 
            #-- Extend array slightly to allow odeint to succeed.
            #   Need better fix for this.
            #x0 = x[0]-(x[1]-x[0])#*0.5
            #xn = x[-1]+(x[-1]-x[-2])#*0.5
            #x_ext = np.hstack([[x0],x,[xn]])
            
            #-- Evaluate the function, and set up an interpolator for 
            #   central difference. The interpolator will extrapolate 
            #   beyond the given x range. This is necessary for odeint to work.
            #   Usually x-range is not exceeded much. 
            self.dfunc = spline1d(x=x,y=op.diff_central(self.y,x),\
                                  k=self.order)
        
        if (isinstance(self.dfunc,interp1d) \
                or isinstance(self.dfunc,UnivariateSpline)):
            self._dargs = []
            self._dkwargs = {}
            self.interp_dfunc = 1
        
        #-- Evaluate the derivative with the default grid
        self.dydx = self.dfunc(x,*self._dargs,**self._dkwargs)
        
        #-- Now set x.
        self.x = x
Exemplo n.º 4
0
    def __init__(self,l,func,dfunc=None,order=3,*args,**kwargs):
    
        '''
        Create an instance of the Opacity() class. Requires a wavelength grid.
        
        The function can also be given as an interpolation object.
        
        The optional args and kwargs give the additional arguments for the 
        opacity function, which are ignored in case func is an interpolation 
        object.
        
        Eval and diff work with the mass extinction coefficient in cm2/g. 
        
        In case func refers to an interpolation object in KappaReader, the
        args/kwargs should always contain an index indicating whether extinction
        (default), absorption or scattering is requested:
            - 0: extinction, 
            - 1: absorption, 
            - 2: scattering

        Note that if func is an interpolator object, the original input x and y
        grids can be passed as additional keywords xin/lin and yin, which would 
        then be arrays. Otherwise, the x and the interpolator(x) are set as 
        xin/lin and yin. xin/lin and yin are ignored if func is a function, even
        if it returns an interpolator (in which case the original grids are 
        known)
        
        Extrapolation is done outside of the "original" (depending on if xin/yin
        are given) wavelength ranges according to a power law ~l^-alpha, with 
        alpha given upon eval() calls.
        
        @param l: The wavelength points (cm)
        @type l: array
        @param func: The function that describes the opacity profile. Can be 
                     given as an interpolation object, in which case lin and yin
                     keywords can be passed as arrays for the original grids.
        @type func: function
        
        @keyword dfunc: Function that describes the derivative of the profile 
                        with respect to x. Can be given as an interpolation 
                        object. If None, a generic central difference is taken & 
                        interpolated with a spline of which the order can be 
                        chosen.
        
                        (default: None)
        @type dfunc: function/interpolation object
        @keyword order: Order of the spline interpolation. Default is cubic.
                        
                        (default: 3)
        @type order: int
                
        @keyword args: Additional parameters passed to the functions when eval
                       or diff are called. 
                       
                       (default: [])
        @type args: tuple
        @keyword kwargs: Additional keywords passed to the functions when eval
                         or diff are called. 
                       
                         (default: {})
        @type kwargs: dict

        '''
        
        #-- Make sure lin is recognized
        if kwargs.has_key('lin'): 
            kwargs['xin'] = kwargs['lin']
            del kwargs['lin']
        
        #-- Do not name func, dfunc, etc in function call, or *args won't work
        super(Opacity, self).__init__(l,func,dfunc,order,*args,**kwargs)
        
        
        #-- Remember the index of the opacities file. If relevant.
        if kwargs.has_key('index'):
            self.index = kwargs['index']
        else:
            self.index = 0
        
        #-- Set the default alpha. Not used if func is not an interpolator.
        self.alpha = 2.
        
        #-- If the requested function is not an interpolator of a file, do not
        #   change anything.
        if not self.interp_func:
            self.l = self.x
            self.kappa = self.y
            return
        
        #-- For Opacity(), in case of an interpolator object as function, 
        #   the extrapolation must be re-done for it to be safe.
        #   The eval() method is rewritten here to function with a
        #   power law extrapolation, for which the settings can be chosen. 
        #   The diff method must not be rewritten since it is based on the y
        #   profile.
        self.l = None
        self.kappa = None
        self.y = None
        
        #-- Run the class' own eval() method, with l=self.x, which will not be 
        #   equal to the class' self.l attribute, and thus it will evaluated
        #   properly. Evaluated with alpha==2. Reevaluated if alpha is different
        self.kappa = self.eval(self.x,alpha=2.)
        self.y = self.kappa
        
        #-- Now also redo the derivative method, in case it is an interpolator
        if self.interp_dfunc: 
            self.dfunc = spline1d(x=self.x,y=op.diff_central(self.y,self.x),\
                                  k=self.order)
        
            #-- Evaluate the derivative with the default grid
            self.dydx = self.dfunc(self.x,*self._dargs,**self._dkwargs)
            
        #-- Now set l, dydl.
        self.l = self.x
        self.dydl = self.dydx
Exemplo n.º 5
0
    def __init__(self,x,func=interp_file,dfunc=None,order=3,*args,\
                 **kwargs):
        '''
        Create an instance of the Profiler() class. Requires a coordinate grid 
        and a function object for the profile. A function for the derivative is
        optional. The functions can also be given as an interpolation object.
        
        The optional args and kwargs give the additional arguments for the 
        two function, which are ignored in case func is an interpolation object.
        
        The default coordinate grid is evaluated for both the function and the
        derivative. They are saved in self.y and self.dydx. Alternatively, new
        evaluations can be attained through eval and diff.
        
        Note that if func is an interpolator object, the original input x and y
        grids can be passed as additional keywords xin and yin, which would then
        be arrays. Otherwise, the x and the interpolator(x) are set as xin and 
        yin. xin and yin are ignored if func is a function, even if it returns
        an interpolator (in which case the original grids are known)
        
        @param x: The default coordinate points, minimum three points. In the 
                  case of an interpolation function, this is the default grid
                  returned by the instance. The original x/y of the 
                  interpolated profile are saved as xori/yori in the object.
        @type x: array
        
        @keyword func: The function that describes the profile with respect to 
                       x. Can be given as an interp1d object. Default is a read
                       function that interpolates data and returns the 
                       interpolator object. If interpolation object, x and 
                       eval(x) are assumed to be the original grids, unless
                       xin and yin are given as keywords with arrays as values
                       for the original grids.
                       
                       (default: interp_file)
        @type func: function/interp1d object
        @keyword dfunc: Function that describes the derivative of the profile 
                        with respect to x. Can be given as an interpolation 
                        object. If None, a generic central difference is taken & 
                        interpolated with a spline of which the order can be 
                        chosen.
        
                        (default: None)
        @type dfunc: function/interpolation object
        @keyword order: Order of the spline interpolation of the derivative. 
                        Default is cubic. Not used for the interpolation if func
                        returns an interpolation object. Use read_order in that
                        case.
                        
                        (default: 3)
        @type order: int
        
        @keyword args: Additional parameters passed to the functions when eval
                       or diff are called. 
                       
                       (default: [])
        @type args: tuple
        @keyword kwargs: Additional keywords passed to the functions when eval
                         or diff are called. 
                       
                         (default: {})
        @type kwargs: dict
        
        '''

        #-- Check len of coordinate input. Cannot be less than three for the
        #   derivative.
        if len(x) < 3:
            raise ValueError('Coordinate grid must have more than 2 elements.')

        #-- If the function is given as a string, retrieve it from the local
        #   child module, or from the Profiler module (as parent). If the latter
        #   case then check if the function comes from one of Profiler's
        #   attributes, such as the loaded DataIO module.
        #   Can also simply be a constant value, so try making a float first.
        if isinstance(func, str):
            try:
                #-- Check if a constant was given, rather than a function
                kwargs['c'] = float(func)
                func = constant

            except ValueError:
                #-- Note that self.module refers to the child, not Profiler
                if hasattr(sys.modules[self.__module__], func):
                    func = getattr(sys.modules[self.__module__], func)

                #-- Recursively find the function of loaded modules in Profiler
                #   or a function of the Profiler module itself if no '.'
                else:

                    func = DataIO.read(func=func,module=sys.modules[__name__],\
                                       return_func=1)

        #-- set functional args, remember spline order. args/kwargs for
        #   func and dfunc are saved separately. They are removed if either are
        #   interpolation objects. They are always accessible, the _** variables
        #   are passed to the evaluation.
        self.args = args
        self.kwargs = kwargs
        self._args = self.args
        self._dargs = self.args
        self._dkwargs = self.kwargs
        self._kwargs = self.kwargs
        self.order = order

        #-- Grab default xin and yin keys in case they are included, and remove
        #   from the arguments dictionary. None if not available.
        xin = self.kwargs.pop('xin', None)
        yin = self.kwargs.pop('yin', None)

        #-- By default no interpolation, so leave this off.
        self.interp_func = 0
        self.interp_dfunc = 0

        #-- Defaults for xori/yori, not used in case of normal functions
        self.xin = np.empty(0)
        self.yin = np.empty(0)

        #-- Evaluate the default grid with function. Set x as None first so it
        #   can actually evaluate. Set x once derivative has been evaluated.
        self.x = None
        if not (isinstance(func, interp1d)
                or isinstance(func, UnivariateSpline)):
            #-- Evaluate the function, and check what is returned: array or
            #   interpolation object
            y = func(x, *args, **kwargs)

            #-- Interpolation object: so set that as this instance's func. In
            #   this case, the variable x passed to the class is the default x
            #   grid of this instance. The original x/y-grid is saved as xi, yi
            if isinstance(y, tuple):
                self.func = y[2]
                self.xin = y[0]
                self.yin = y[1]
                self._args = []
                self._kwargs = {}
                self.interp_func = 1
                self.y = self.func(x)
            else:
                self.func = func
                self.y = y

        #-- func is an interpolation object, so just run the normal evaluation.
        #   Set _args/_kwargs to empty, so none are ever passed to the interpol
        else:
            self.func = func
            self._args = []
            self._kwargs = {}
            self.interp_func = 1
            self.y = self.func(x)
            self.yin = yin if not yin is None else self.y
            self.xin = xin if not xin is None else x

        #-- Set the derivative function, resorting to default if needed
        if not dfunc is None:
            self.dfunc = dfunc
        elif self.func == constant:
            self.dfunc = zero
        else:
            #-- Extend array slightly to allow odeint to succeed.
            #   Need better fix for this.
            #x0 = x[0]-(x[1]-x[0])#*0.5
            #xn = x[-1]+(x[-1]-x[-2])#*0.5
            #x_ext = np.hstack([[x0],x,[xn]])

            #-- Evaluate the function, and set up an interpolator for
            #   central difference. The interpolator will extrapolate
            #   beyond the given x range. This is necessary for odeint to work.
            #   Usually x-range is not exceeded much.
            self.dfunc = spline1d(x=x,y=op.diff_central(self.y,x),\
                                  k=self.order)

        if (isinstance(self.dfunc,interp1d) \
                or isinstance(self.dfunc,UnivariateSpline)):
            self._dargs = []
            self._dkwargs = {}
            self.interp_dfunc = 1

        #-- Evaluate the derivative with the default grid
        self.dydx = self.dfunc(x, *self._dargs, **self._dkwargs)

        #-- Now set x.
        self.x = Data.arrayify(x)
Exemplo n.º 6
0
    def __init__(self,r,func,dfunc=None,order=3,inner=0,inner_eps=0.5,\
                 *args,**kwargs):
    
        '''
        Create an instance of the Temperature() class. Requires a radial grid  
        and a temperature function.
        
        The function can also be given as an interp1d object.
        
        The optional args and kwargs give the additional arguments for the 
        temperature function, which are ignored in case func is an interp1d 
        object.
        
        An additional option concerns the extrapolation to smaller radii, e.g.
        in the inner wind between the stellar surface and the dust condensation
        radius. In this case, the eval/diff methods will differ between inner 
        wind (r<r0) and the rest of the wind (r>r0) in terms of evaluation. 
        
        At r>r0: The given func (or interpolator) is used.
        At r<r0: A Teps power law is used, for which 1 out of Tstar or 
        epsilon can be defined. The default sets epsilon == 0.5 (the optically
        thin case), but inner_epsilon can be passed to the initialisation if 
        needed. r0, T0 must be defined in kwargs either for the
        main wind's Teps law, or as an additional argument if a file is read.
        
        @param r: The radial points (cm)
        @type r: array
        @param func: The function that describes the temperature profile. Can be 
                     given as an interp1d object.
        @type func: function
        
        @keyword dfunc: The function that describes the derivative of the  
                        profile with respect to r. Can be given as an interp1d 
                        object. If None, a generic central difference is taken  
                        and interpolated.
        
                        (default: None)
        @type dfunc: function/interp1d object
        @keyword order: Order of the spline interpolation. Default is cubic.
                        
                        (default: 3)
        @type order: int
        @keyword inner: Applies a power law to the inner region, as a means of
                        extrapolation. Off by default, but can be turned on. 
                        In this case, r0 is taken from kwargs, ie the r0 from 
                        the power law of the wind (if Teps is chosen), or as an 
                        additional keyword if a file is read.
                        
                        (default: 0)
        @type inner: bool
        @keyword inner_eps: The exponent for the power law in the inner wind. 
        
                            (default: 0.5)
        @type inner_eps: float
        
        @keyword args: Additional parameters passed to the functions when eval
                       or diff are called. 
                       
                       (default: [])
        @type args: tuple
        @keyword kwargs: Additional keywords passed to the functions when eval
                         or diff are called. 
                       
                         (default: {})
        @type kwargs: dict
        
        '''

        #-- Do not name func, dfunc, etc in function call, or *args won't work        
        super(Temperature, self).__init__(r,func,dfunc,order,*args,**kwargs)
        
        self.inner = inner
        self.inner_eps = inner_eps

        #-- No extrapolation to the inner wind requested
        if not self.inner: 
            self.r = self.x
            self.T = self.y
            self.dTdr = self.dydx
            return
            
        #-- Alternatively, a power law extrapolation is requested. Extract r0,T0
        self.r0 = kwargs.get('r0')
        self.T0 = kwargs.get('T0')
    
        self.r = None
        self.T = None
        self.y = None
        
        #-- Run the class' own eval() method, with l=self.x, which will not be 
        #   equal to the class' self.r attribute, and thus it will evaluated
        #   properly. Evaluated with inner_eps==0.5. Reevaluated if alpha is
        #   different upon eval call.
        self.T = self.eval(self.x,inner_eps=self.inner_eps)
        self.y = self.T
        
        #-- Now also redo the derivative method. Then call diff to set the 
        #   standard derivative of the instance
        if self.interp_dfunc: 
            self.dfunc = spline1d(x=self.x,y=op.diff_central(self.y,self.x),\
                                  k=self.order)
        
        #-- Evaluate the derivative with the default grid
        self.dydx = self.diff(self.x,inner_eps=0.5)
        
        #-- Now set l, dydl.
        self.r = self.x
        self.dTdr = self.dydx
Exemplo n.º 7
0
    def __init__(self, l, func, dfunc=None, order=3, *args, **kwargs):
        '''
        Create an instance of the Opacity() class. Requires a wavelength grid.
        
        The function can also be given as an interpolation object.
        
        The optional args and kwargs give the additional arguments for the 
        opacity function, which are ignored in case func is an interpolation 
        object.
        
        Eval and diff work with the mass extinction coefficient in cm2/g. 
        
        In case func refers to an interpolation object in KappaReader, the
        args/kwargs should always contain an index indicating whether extinction
        (default), absorption or scattering is requested:
            - 0: extinction, 
            - 1: absorption, 
            - 2: scattering

        Note that if func is an interpolator object, the original input x and y
        grids can be passed as additional keywords xin/lin and yin, which would 
        then be arrays. Otherwise, the x and the interpolator(x) are set as 
        xin/lin and yin. xin/lin and yin are ignored if func is a function, even
        if it returns an interpolator (in which case the original grids are 
        known)
        
        Extrapolation is done outside of the "original" (depending on if xin/yin
        are given) wavelength ranges according to a power law ~l^-alpha, with 
        alpha given upon eval() calls.
        
        @param l: The wavelength points (cm)
        @type l: array
        @param func: The function that describes the opacity profile. Can be 
                     given as an interpolation object, in which case lin and yin
                     keywords can be passed as arrays for the original grids.
        @type func: function
        
        @keyword dfunc: Function that describes the derivative of the profile 
                        with respect to x. Can be given as an interpolation 
                        object. If None, a generic central difference is taken & 
                        interpolated with a spline of which the order can be 
                        chosen.
        
                        (default: None)
        @type dfunc: function/interpolation object
        @keyword order: Order of the spline interpolation. Default is cubic.
                        
                        (default: 3)
        @type order: int
                
        @keyword args: Additional parameters passed to the functions when eval
                       or diff are called. 
                       
                       (default: [])
        @type args: tuple
        @keyword kwargs: Additional keywords passed to the functions when eval
                         or diff are called. 
                       
                         (default: {})
        @type kwargs: dict

        '''

        #-- Make sure lin is recognized
        if kwargs.has_key('lin'):
            kwargs['xin'] = kwargs['lin']
            del kwargs['lin']

        #-- Do not name func, dfunc, etc in function call, or *args won't work
        super(Opacity, self).__init__(l, func, dfunc, order, *args, **kwargs)

        #-- Remember the index of the opacities file. If relevant.
        if kwargs.has_key('index'):
            self.index = kwargs['index']
        else:
            self.index = 0

        #-- Set the default alpha. Not used if func is not an interpolator.
        self.alpha = 2.

        #-- If the requested function is not an interpolator of a file, do not
        #   change anything.
        if not self.interp_func:
            self.l = self.x
            self.kappa = self.y
            return

        #-- For Opacity(), in case of an interpolator object as function,
        #   the extrapolation must be re-done for it to be safe.
        #   The eval() method is rewritten here to function with a
        #   power law extrapolation, for which the settings can be chosen.
        #   The diff method must not be rewritten since it is based on the y
        #   profile.
        self.l = None
        self.kappa = None
        self.y = None

        #-- Run the class' own eval() method, with l=self.x, which will not be
        #   equal to the class' self.l attribute, and thus it will evaluated
        #   properly. Evaluated with alpha==2. Reevaluated if alpha is different
        self.kappa = self.eval(self.x, alpha=2.)
        self.y = self.kappa

        #-- Now also redo the derivative method, in case it is an interpolator
        if self.interp_dfunc:
            self.dfunc = spline1d(x=self.x,y=op.diff_central(self.y,self.x),\
                                  k=self.order)

            #-- Evaluate the derivative with the default grid
            self.dydx = self.dfunc(self.x, *self._dargs, **self._dkwargs)

        #-- Now set l, dydl.
        self.l = self.x
        self.dydl = self.dydx