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 feff_correct_mon(obj, **kwargs): """ This function takes in a monitor spectra, calculates efficiencies based on the montior's wavelength axis and divides the monitor counts by the calculated efficiencies. The function is a M{constant * wavelength}. @param obj: Object containing monitor spectra @type obj: C{SOM.SOM} or C{SOM.SO} @param kwargs: A list of keyword arguments that the function accepts: @keyword units: The expected units for this function. The default for this function is I{Angstroms}. @type units: C{string} @keyword eff_const: Use this provided effieciency constant. The default is (0.00000085 / 1.8) Angstroms^-1. @type eff_const: L{hlr_utils.DrParameter} @keyword inst_name: The short name of an instrument. @type inst_name: C{string} @return: Efficiency corrected monitor spectra @rtype: C{SOM.SOM} or C{SOM.SO} """ # import the helper functions import hlr_utils if obj is None: return obj # set up for working through data (result, res_descr) = hlr_utils.empty_result(obj) o_descr = hlr_utils.get_descr(obj) # Setup keyword arguments try: units = kwargs["units"] except KeyError: units = "Angstroms" try: eff_const = kwargs["eff_const"] except KeyError: # This is for SNS (specifically BASIS) monitors eff_const = hlr_utils.DrParameter((0.00000085 / 1.8), 0.0, "Angstroms^-1") # A^-1 inst_name = kwargs.get("inst_name") # Primary axis for transformation. If a SO is passed, the function, will # assume the axis for transformation is at the 0 position if o_descr == "SOM": axis = hlr_utils.one_d_units(obj, units) else: axis = 0 result = hlr_utils.copy_som_attr(result, res_descr, obj, o_descr) # iterate through the values import array_manip import nessi_list import dr_lib for i in xrange(hlr_utils.get_length(obj)): val = hlr_utils.get_value(obj, i, o_descr, "x", axis) map_so = hlr_utils.get_map_so(obj, None, i) if inst_name is None: eff = nessi_list.NessiList() for j in xrange(len(val) - 1): bin_center = (val[j + 1] + val[j]) / 2.0 eff.append(eff_const.getValue() * bin_center) eff_err2 = nessi_list.NessiList(len(eff)) else: if inst_name == "SANS": (eff, eff_err2) = dr_lib.subexp_eff(eff_const, val) else: raise RuntimeError("Do not know how to handle %s instrument" \ % inst_name) y_val = hlr_utils.get_value(obj, i, o_descr, "y") y_err2 = hlr_utils.get_err2(obj, i, o_descr, "y") value = array_manip.div_ncerr(y_val, y_err2, eff, eff_err2) hlr_utils.result_insert(result, res_descr, value, map_so, "y") return result
def feff_correct_mon(obj, **kwargs): """ This function takes in a monitor spectra, calculates efficiencies based on the montior's wavelength axis and divides the monitor counts by the calculated efficiencies. The function is a M{constant * wavelength}. @param obj: Object containing monitor spectra @type obj: C{SOM.SOM} or C{SOM.SO} @param kwargs: A list of keyword arguments that the function accepts: @keyword units: The expected units for this function. The default for this function is I{Angstroms}. @type units: C{string} @keyword eff_const: Use this provided effieciency constant. The default is (0.00000085 / 1.8) Angstroms^-1. @type eff_const: L{hlr_utils.DrParameter} @keyword inst_name: The short name of an instrument. @type inst_name: C{string} @return: Efficiency corrected monitor spectra @rtype: C{SOM.SOM} or C{SOM.SO} """ # import the helper functions import hlr_utils if obj is None: return obj # set up for working through data (result, res_descr) = hlr_utils.empty_result(obj) o_descr = hlr_utils.get_descr(obj) # Setup keyword arguments try: units = kwargs["units"] except KeyError: units = "Angstroms" try: eff_const = kwargs["eff_const"] except KeyError: # This is for SNS (specifically BASIS) monitors eff_const = hlr_utils.DrParameter((0.00000085 / 1.8), 0.0, "Angstroms^-1") # A^-1 inst_name = kwargs.get("inst_name") # Primary axis for transformation. If a SO is passed, the function, will # assume the axis for transformation is at the 0 position if o_descr == "SOM": axis = hlr_utils.one_d_units(obj, units) else: axis = 0 result = hlr_utils.copy_som_attr(result, res_descr, obj, o_descr) # iterate through the values import array_manip import nessi_list import dr_lib for i in xrange(hlr_utils.get_length(obj)): val = hlr_utils.get_value(obj, i, o_descr, "x", axis) map_so = hlr_utils.get_map_so(obj, None, i) if inst_name is None: eff = nessi_list.NessiList() for j in xrange(len(val)-1): bin_center = (val[j+1] + val[j]) / 2.0 eff.append(eff_const.getValue() * bin_center) eff_err2 = nessi_list.NessiList(len(eff)) else: if inst_name == "SANS": (eff, eff_err2) = dr_lib.subexp_eff(eff_const, val) else: raise RuntimeError("Do not know how to handle %s instrument" \ % inst_name) y_val = hlr_utils.get_value(obj, i, o_descr, "y") y_err2 = hlr_utils.get_err2(obj, i, o_descr, "y") value = array_manip.div_ncerr(y_val, y_err2, eff, eff_err2) hlr_utils.result_insert(result, res_descr, value, map_so, "y") return result