def subexp_eff(attenc, axis, scalec=None):
    """
    This function calculates an efficiency from a subtracted exponential of the
    form: c(1 - exp(-|k| * x)).

    @param attenc: The attentuation constant k in the exponential.
    @type attenc: L{hlr_utils.DrParameter}

    @param axis: The axis from which to calculate the efficiency
    @type axis: C{nessi_list.NessiList}

    @param scalec: The scaling constant c applied to the subtracted
                   exponential.
    @type scalec: L{hlr_utils.DrParameter}
    

    @return: The calculated efficiency
    @rtype: C{nessi_list.NessiList}
    """
    import array_manip
    import phys_corr
    import utils

    if scalec is None:
        import hlr_utils
        scalec = hlr_utils.DrParameter(1.0, 0.0)
    
    axis_bc = utils.calc_bin_centers(axis)
    temp = phys_corr.exp_detector_eff(axis_bc[0], scalec.getValue(),
                                      scalec.getError(), attenc.getValue())
    return array_manip.sub_ncerr(scalec.getValue(), scalec.getError(),
                                 temp[0], temp[1])
Exemple #2
0
def create_det_eff(obj, **kwargs):
    """
    This function creates detector efficiency spectra based on the wavelength
    spectra from the given object. The efficiency spectra are created based on
    the following formalism: Ci*exp(-di*lambda) where i represents the
    constants for a given detector pixel.

    @param obj: Object containing spectra that will create the detector
                efficiency spectra.
    @type obj: C{SOM.SOM} or C{SOM.SO}
    
    @param kwargs: A list of keyword arguments that the function accepts:

    @keyword inst_name: The short name of an instrument.
    @type inst_name: C{string}
    
    @keyword eff_scale_const: Use this provided efficiency scaling constant.
    @type eff_scale_const: L{hlr_utils.DrParameter}

    @keyword eff_atten_const: Use this provided efficiency attenuation
                              constant.
    @type eff_atten_const: L{hlr_utils.DrParameter}    


    @return: Object containing the detector efficiency spectra
    @rtype: C{SOM.SOM} or C{SOM.SO}


    @raise TypeError: Incoming object is not a C{SOM} or a C{SO}
    @raise RuntimeError: The C{SOM} x-axis units are not I{Angstroms}
    """
    # Check keywords
    inst_name = kwargs.get("inst_name")
    eff_scale_const = kwargs.get("eff_scale_const")
    eff_atten_const = kwargs.get("eff_atten_const")

    # set up for working through data
    (result, res_descr) = hlr_utils.empty_result(obj)
    o_descr = hlr_utils.get_descr(obj)

    if o_descr != "SOM" and o_descr != "SO":
        raise TypeError("Only SOM or SO objects permitted to create "\
                        +"efficiency spectra!")

    # Check units on SOM, SO is assumed to be correct
    if o_descr == "SOM":
        if not obj.hasAxisUnits("Angstroms"):
            raise RuntimeError("Incoming object must has a wavelength axis "\
                               +"with units of Angstroms!")

    result = hlr_utils.copy_som_attr(result, res_descr, obj, o_descr)

    # iterate through the values
    import dr_lib
    import phys_corr
    import utils

    # Get object length
    len_obj = hlr_utils.get_length(obj)
    for i in xrange(len_obj):
        map_so = hlr_utils.get_map_so(obj, None, i)
        axis = hlr_utils.get_value(obj, i, o_descr, "x", 0)

        if inst_name is None:
            axis_bc = utils.calc_bin_centers(axis)
            (eff,
             eff_err2) = phys_corr.exp_detector_eff(axis_bc[0], 1.0, 0.0, 1.0)
        else:
            if inst_name == "SANS":
                (eff, eff_err2) = dr_lib.subexp_eff(eff_atten_const, axis,
                                                    eff_scale_const)
            else:
                raise RuntimeError("Do not know how to handle %s instrument" \
                                   % inst_name)

        hlr_utils.result_insert(result, res_descr, (eff, eff_err2), map_so)

    return result
def create_det_eff(obj, **kwargs):
    """
    This function creates detector efficiency spectra based on the wavelength
    spectra from the given object. The efficiency spectra are created based on
    the following formalism: Ci*exp(-di*lambda) where i represents the
    constants for a given detector pixel.

    @param obj: Object containing spectra that will create the detector
                efficiency spectra.
    @type obj: C{SOM.SOM} or C{SOM.SO}
    
    @param kwargs: A list of keyword arguments that the function accepts:

    @keyword inst_name: The short name of an instrument.
    @type inst_name: C{string}
    
    @keyword eff_scale_const: Use this provided efficiency scaling constant.
    @type eff_scale_const: L{hlr_utils.DrParameter}

    @keyword eff_atten_const: Use this provided efficiency attenuation
                              constant.
    @type eff_atten_const: L{hlr_utils.DrParameter}    


    @return: Object containing the detector efficiency spectra
    @rtype: C{SOM.SOM} or C{SOM.SO}


    @raise TypeError: Incoming object is not a C{SOM} or a C{SO}
    @raise RuntimeError: The C{SOM} x-axis units are not I{Angstroms}
    """
    # Check keywords
    inst_name = kwargs.get("inst_name")
    eff_scale_const = kwargs.get("eff_scale_const")
    eff_atten_const = kwargs.get("eff_atten_const")

    # set up for working through data
    (result, res_descr) = hlr_utils.empty_result(obj)
    o_descr = hlr_utils.get_descr(obj)

    if o_descr != "SOM" and o_descr != "SO":
        raise TypeError("Only SOM or SO objects permitted to create "\
                        +"efficiency spectra!")

    # Check units on SOM, SO is assumed to be correct
    if o_descr == "SOM":
        if not obj.hasAxisUnits("Angstroms"):
            raise RuntimeError("Incoming object must has a wavelength axis "\
                               +"with units of Angstroms!")

    result = hlr_utils.copy_som_attr(result, res_descr, obj, o_descr)

    # iterate through the values
    import dr_lib
    import phys_corr
    import utils

    # Get object length
    len_obj = hlr_utils.get_length(obj)
    for i in xrange(len_obj):
        map_so = hlr_utils.get_map_so(obj, None, i)
        axis = hlr_utils.get_value(obj, i, o_descr, "x", 0)

        if inst_name is None:
            axis_bc = utils.calc_bin_centers(axis)
            (eff, eff_err2) = phys_corr.exp_detector_eff(axis_bc[0], 1.0,
                                                         0.0, 1.0)
        else:
            if inst_name == "SANS":
                (eff, eff_err2) = dr_lib.subexp_eff(eff_atten_const, axis,
                                                    eff_scale_const)
            else:
                raise RuntimeError("Do not know how to handle %s instrument" \
                                   % inst_name)
        
        hlr_utils.result_insert(result, res_descr, (eff, eff_err2), map_so)
    
    return result