def calc_substrate_trans(obj, subtrans_coeff, substrate_diam, **kwargs): """ This function calculates substrate transmission via the following formula: T = exp[-(A + B * wavelength) * d] where A is a constant with units of cm^-1, B is a constant with units of cm^-2 and d is the substrate diameter in units of cm. @param obj: The data object that contains the TOF axes to calculate the transmission from. @type obj: C{SOM.SOM} or C{SOM.SO} @param subtrans_coeff: The two coefficients for substrate transmission calculation. @type subtrans_coeff: C{tuple} of two C{float}s @param substrate_diam: The diameter of the substrate. @type substrate_diam: C{float} @param kwargs: A list of keyword arguments that the function accepts: @keyword pathlength: The pathlength and its associated error^2 @type pathlength: C{tuple} or C{list} of C{tuple}s @keyword units: The expected units for this function. The default for this function is I{microsecond}. @type units: C{string} @return: The calculate transmission for the given substrate parameters @rtype: C{SOM.SOM} or C{SOM.SO} @raise TypeError: The object used for calculation is not a C{SOM} or a C{SO} @raise RuntimeError: The C{SOM} x-axis units are not I{microsecond} @raise RuntimeError: A C{SOM} does not contain an instrument and no pathlength was provided @raise RuntimeError: No C{SOM} is provided and no pathlength given """ # import the helper functions import hlr_utils # set up for working through data (result, res_descr) = hlr_utils.empty_result(obj) o_descr = hlr_utils.get_descr(obj) if o_descr == "number" or o_descr == "list": raise TypeError("Do not know how to handle given type: %s" % o_descr) else: pass # Setup keyword arguments try: pathlength = kwargs["pathlength"] except KeyError: pathlength = None try: units = kwargs["units"] except KeyError: units = "microsecond" # 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 if pathlength is not None: p_descr = hlr_utils.get_descr(pathlength) else: if o_descr == "SOM": try: obj.attr_list.instrument.get_primary() inst = obj.attr_list.instrument except RuntimeError: raise RuntimeError("A detector was not provided") else: raise RuntimeError("If no SOM is provided, then pathlength "\ +"information must be provided") result = hlr_utils.copy_som_attr(result, res_descr, obj, o_descr) if res_descr == "SOM": result.setYLabel("Transmission") # iterate through the values import array_manip import axis_manip import nessi_list import utils import math len_obj = hlr_utils.get_length(obj) for i in xrange(len_obj): val = hlr_utils.get_value(obj, i, o_descr, "x", axis) err2 = hlr_utils.get_err2(obj, i, o_descr, "x", axis) map_so = hlr_utils.get_map_so(obj, None, i) if pathlength is None: (pl, pl_err2) = hlr_utils.get_parameter("total", map_so, inst) else: pl = hlr_utils.get_value(pathlength, i, p_descr) pl_err2 = hlr_utils.get_err2(pathlength, i, p_descr) value = axis_manip.tof_to_wavelength(val, err2, pl, pl_err2) value1 = utils.calc_bin_centers(value[0]) del value # Convert Angstroms to centimeters value2 = array_manip.mult_ncerr(value1[0], value1[1], subtrans_coeff[1]*1.0e-8, 0.0) del value1 # Calculate the exponential value3 = array_manip.add_ncerr(value2[0], value2[1], subtrans_coeff[0], 0.0) del value2 value4 = array_manip.mult_ncerr(value3[0], value3[1], -1.0*substrate_diam, 0.0) del value3 # Calculate transmission trans = nessi_list.NessiList() len_trans = len(value4[0]) for j in xrange(len_trans): trans.append(math.exp(value4[0][j])) trans_err2 = nessi_list.NessiList(len(trans)) hlr_utils.result_insert(result, res_descr, (trans, trans_err2), map_so) return result
def tof_to_wavelength(obj, **kwargs): """ This function converts a primary axis of a C{SOM} or C{SO} from time-of-flight to wavelength. The wavelength axis for a C{SOM} must be in units of I{microseconds}. The primary axis of a C{SO} is assumed to be in units of I{microseconds}. A C{tuple} of C{(tof, tof_err2)} (assumed to be in units of I{microseconds}) can be converted to C{(wavelength, wavelength_err2)}. @param obj: Object to be converted @type obj: C{SOM.SOM}, C{SOM.SO} or C{tuple} @param kwargs: A list of keyword arguments that the function accepts: @keyword pathlength: The pathlength and its associated error^2 @type pathlength: C{tuple} or C{list} of C{tuple}s @keyword inst_param: The type of parameter requested from an associated instrument. For this function the acceptable parameters are I{primary}, I{secondary} and I{total}. Default is I{primary}. @type inst_param: C{string} @keyword lojac: A flag that allows one to turn off the calculation of the linear-order Jacobian. The default action is I{True} for histogram data. @type lojac: C{boolean} @keyword units: The expected units for this function. The default for this function is I{microseconds}. @type units: C{string} @return: Object with a primary axis in time-of-flight converted to wavelength @rtype: C{SOM.SOM}, C{SOM.SO} or C{tuple} @raise TypeError: The incoming object is not a type the function recognizes @raise RuntimeError: The C{SOM} x-axis units are not I{microseconds} @raise RuntimeError: A C{SOM} does not contain an instrument and no pathlength was provided @raise RuntimeError: No C{SOM} is provided and no pathlength given """ # import the helper functions import hlr_utils # 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: inst_param = kwargs["inst_param"] except KeyError: inst_param = "primary" try: pathlength = kwargs["pathlength"] except KeyError: pathlength = None try: units = kwargs["units"] except KeyError: units = "microseconds" try: lojac = kwargs["lojac"] except KeyError: lojac = hlr_utils.check_lojac(obj) # 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) if res_descr == "SOM": result = hlr_utils.force_units(result, "Angstroms", axis) result.setAxisLabel(axis, "wavelength") result.setYUnits("Counts/A") result.setYLabel("Intensity") else: pass if pathlength is not None: p_descr = hlr_utils.get_descr(pathlength) else: if o_descr == "SOM": try: obj.attr_list.instrument.get_primary() inst = obj.attr_list.instrument except RuntimeError: raise RuntimeError("A detector was not provided") else: raise RuntimeError("If no SOM is provided, then pathlength "\ +"information must be provided") # iterate through the values import axis_manip if lojac: import utils for i in xrange(hlr_utils.get_length(obj)): val = hlr_utils.get_value(obj, i, o_descr, "x", axis) err2 = hlr_utils.get_err2(obj, i, o_descr, "x", axis) map_so = hlr_utils.get_map_so(obj, None, i) if pathlength is None: (pl, pl_err2) = hlr_utils.get_parameter(inst_param, map_so, inst) else: pl = hlr_utils.get_value(pathlength, i, p_descr) pl_err2 = hlr_utils.get_err2(pathlength, i, p_descr) value = axis_manip.tof_to_wavelength(val, err2, pl, pl_err2) if lojac: y_val = hlr_utils.get_value(obj, i, o_descr, "y") y_err2 = hlr_utils.get_err2(obj, i, o_descr, "y") counts = utils.linear_order_jacobian(val, value[0], y_val, y_err2) hlr_utils.result_insert(result, res_descr, counts, map_so, "all", axis, [value[0]]) else: hlr_utils.result_insert(result, res_descr, value, map_so, "x", axis) return result
def calc_substrate_trans(obj, subtrans_coeff, substrate_diam, **kwargs): """ This function calculates substrate transmission via the following formula: T = exp[-(A + B * wavelength) * d] where A is a constant with units of cm^-1, B is a constant with units of cm^-2 and d is the substrate diameter in units of cm. @param obj: The data object that contains the TOF axes to calculate the transmission from. @type obj: C{SOM.SOM} or C{SOM.SO} @param subtrans_coeff: The two coefficients for substrate transmission calculation. @type subtrans_coeff: C{tuple} of two C{float}s @param substrate_diam: The diameter of the substrate. @type substrate_diam: C{float} @param kwargs: A list of keyword arguments that the function accepts: @keyword pathlength: The pathlength and its associated error^2 @type pathlength: C{tuple} or C{list} of C{tuple}s @keyword units: The expected units for this function. The default for this function is I{microsecond}. @type units: C{string} @return: The calculate transmission for the given substrate parameters @rtype: C{SOM.SOM} or C{SOM.SO} @raise TypeError: The object used for calculation is not a C{SOM} or a C{SO} @raise RuntimeError: The C{SOM} x-axis units are not I{microsecond} @raise RuntimeError: A C{SOM} does not contain an instrument and no pathlength was provided @raise RuntimeError: No C{SOM} is provided and no pathlength given """ # import the helper functions import hlr_utils # set up for working through data (result, res_descr) = hlr_utils.empty_result(obj) o_descr = hlr_utils.get_descr(obj) if o_descr == "number" or o_descr == "list": raise TypeError("Do not know how to handle given type: %s" % o_descr) else: pass # Setup keyword arguments try: pathlength = kwargs["pathlength"] except KeyError: pathlength = None try: units = kwargs["units"] except KeyError: units = "microsecond" # 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 if pathlength is not None: p_descr = hlr_utils.get_descr(pathlength) else: if o_descr == "SOM": try: obj.attr_list.instrument.get_primary() inst = obj.attr_list.instrument except RuntimeError: raise RuntimeError("A detector was not provided") else: raise RuntimeError("If no SOM is provided, then pathlength "\ +"information must be provided") result = hlr_utils.copy_som_attr(result, res_descr, obj, o_descr) if res_descr == "SOM": result.setYLabel("Transmission") # iterate through the values import array_manip import axis_manip import nessi_list import utils import math len_obj = hlr_utils.get_length(obj) for i in xrange(len_obj): val = hlr_utils.get_value(obj, i, o_descr, "x", axis) err2 = hlr_utils.get_err2(obj, i, o_descr, "x", axis) map_so = hlr_utils.get_map_so(obj, None, i) if pathlength is None: (pl, pl_err2) = hlr_utils.get_parameter("total", map_so, inst) else: pl = hlr_utils.get_value(pathlength, i, p_descr) pl_err2 = hlr_utils.get_err2(pathlength, i, p_descr) value = axis_manip.tof_to_wavelength(val, err2, pl, pl_err2) value1 = utils.calc_bin_centers(value[0]) del value # Convert Angstroms to centimeters value2 = array_manip.mult_ncerr(value1[0], value1[1], subtrans_coeff[1] * 1.0e-8, 0.0) del value1 # Calculate the exponential value3 = array_manip.add_ncerr(value2[0], value2[1], subtrans_coeff[0], 0.0) del value2 value4 = array_manip.mult_ncerr(value3[0], value3[1], -1.0 * substrate_diam, 0.0) del value3 # Calculate transmission trans = nessi_list.NessiList() len_trans = len(value4[0]) for j in xrange(len_trans): trans.append(math.exp(value4[0][j])) trans_err2 = nessi_list.NessiList(len(trans)) hlr_utils.result_insert(result, res_descr, (trans, trans_err2), map_so) return result