def tophat(ic, struct=None): """ Top-hat baseline correction on Ion Chromatogram :param ic: The input ion chromatogram :type ic: pyms.IonChromatogram.IonChromatogram :param struct: Top-hat structural element as time string :type struct: int or str or NoneType, optional :return: Top-hat corrected ion chromatogram :rtype: pyms.IonChromatogram.IonChromatogram :author: Woon Wai Keen :author: Vladimir Likic :author: Dominic Davis-Foster (type assertions) """ if not isinstance(ic, IonChromatogram): raise TypeError("'ic' must be an IonChromatogram object") ia = copy.deepcopy(ic.intensity_array) if struct: struct_pts = ic_window_points(ic, struct) else: struct_pts = int(round(ia.size * _STRUCT_ELM_FRAC)) # print(" -> Top-hat: structural element is %d point(s)" % ( struct_pts )) str_el = numpy.repeat([1], struct_pts) ia = ndimage.white_tophat(ia, footprint=str_el) ic_bc = copy.deepcopy(ic) ic_bc.intensity_array = ia return ic_bc
def tophat(ic: IonChromatogram, struct: Union[int, str, None] = None): """ Top-hat baseline correction on Ion Chromatogram. :param ic: The input ion chromatogram. :param struct: Top-hat structural element as time string. The structural element needs to be larger than the features one wants to retain in the spectrum after the top-hat transform. :return: Top-hat corrected ion chromatogram. :authors: Woon Wai Keen, Vladimir Likic, Dominic Davis-Foster (type assertions) """ if not isinstance(ic, IonChromatogram): raise TypeError("'ic' must be an IonChromatogram object") ia = copy.deepcopy(ic.intensity_array) if struct: struct_pts = ic_window_points(ic, struct) else: struct_pts = int(round(ia.size * _STRUCT_ELM_FRAC)) # print(f" -> Top-hat: structural element is {struct_pts:d} point(s)") str_el = numpy.repeat([1], struct_pts) ia = ndimage.white_tophat(ia, footprint=str_el) ic_bc = copy.deepcopy(ic) ic_bc.intensity_array = ia return ic_bc
def savitzky_golay(ic: IonChromatogram, window: Union[int, str] = __DEFAULT_WINDOW, degree=__DEFAULT_POLYNOMIAL_DEGREE) -> IonChromatogram: """ Applies Savitzky-Golay filter on ion chromatogram :param ic: The input ion chromatogram :type ic: pyms.IonChromatogram.IonChromatogram :param window: The window selection parameter. This can be an integer or time string. If integer, taken as the number of points. If a string, must of the form "<NUMBER>s" or "<NUMBER>m", specifying a time in seconds or minutes, respectively :type window: int or str, optional :param degree: degree of the fitting polynomial for the Savitzky-Golay filter :type degree: int, optional :return: Smoothed ion chromatogram :rtype: pyms.IonChromatogram.IonChromatogram :author: Uwe Schmitt :author: Vladimir Likic :author: Dominic Davis-Foster """ if not isinstance(ic, IonChromatogram): raise TypeError("'ic' must be an IonChromatogram object") if not isinstance(window, (int, str)): raise TypeError("'window' must be either an int or a string") if not isinstance(degree, int): raise TypeError("'degree' must be an integer") ia = ic.intensity_array wing_length = ic_window_points(ic, window, half_window=True) # print(" -> Applying Savitzky-Golay filter") # print(" Window width (points): %d" % ( 2*wing_length+1 )) # print(" Polynomial degree: %d" % ( degree )) coeff = __calc_coeff(wing_length, degree) ia_denoise = __smooth(ia, coeff) ic_denoise = copy.deepcopy(ic) ic_denoise.intensity_array = ia_denoise return ic_denoise
def window_smooth(ic: IonChromatogram, window: Union[int, str] = __DEFAULT_WINDOW, use_median: bool = False) -> IonChromatogram: """ Applies window smoothing on ion chromatogram :param ic: The input ion chromatogram :type ic: pyms.IonChromatogram.IonChromatogram :param window: The window selection parameter. This can be an integer or time string. If integer, taken as the number of points. If a string, must of the form "<NUMBER>s" or "<NUMBER>m", specifying a time in seconds or minutes, respectively :type window: int or str, optional :param use_median: An indicator whether the mean or median window smoothing to be used :type use_median: bool, optional :return: Smoothed ion chromatogram :rtype: pyms.IonChromatogram.IonChromatogram :author: Vladimir Likic :author: Dominic Davis-Foster (type assertions) """ if not isinstance(ic, IonChromatogram): raise TypeError("'ic' must be an IonChromatogram object") if not isinstance(window, (int, str)): raise TypeError("'window' must be a int or string") if not isinstance(use_median, bool): raise TypeError("'median' must be a Boolean") ia = ic.intensity_array wing_length = ic_window_points(ic, window, half_window=True) if use_median: ia_denoise = __median_window(ia, wing_length) else: ia_denoise = __mean_window(ia, wing_length) ic_denoise = copy.deepcopy(ic) ic_denoise.intensity_array = ia_denoise return ic_denoise
def savitzky_golay(ic, window=__DEFAULT_WINDOW, \ degree=__DEFAULT_POLYNOMIAL_DEGREE): """ @summary: Applies Savitzky-Golay filter on ion chromatogram @param ic: The input ion chromatogram @type ic: pyms.GCMS.Class.IonChromatogram @param window: The window selection parameter. This can be an integer or time string. If integer, taken as the number of points. If a string, must of the form "<NUMBER>s" or "<NUMBER>m", specifying a time in seconds or minutes, respectively @type window: IntType or StringType @param degree: degree of the fitting polynomial for the Savitzky-Golay filter @type degree: IntType @return: Smoothed ion chromatogram @rtype: pyms.GCMS.Class.IonChromatogram @author: Uwe Schmitt @author: Vladimir Likic """ if not is_ionchromatogram(ic): error("'ic' not an IonChromatogram object") if not is_int(degree): error("'degree' not an integer") ia = ic.get_intensity_array() wing_length = ic_window_points(ic, window, half_window=True) #print " -> Applying Savitzky-Golay filter" #print " Window width (points): %d" % ( 2*wing_length+1 ) #print " Polynomial degree: %d" % ( degree ) coeff = __calc_coeff(wing_length, degree) ia_denoise = __smooth(ia, coeff) ic_denoise = copy.deepcopy(ic) ic_denoise.set_intensity_array(ia_denoise) return ic_denoise
def window_smooth(ic, window=__DEFAULT_WINDOW, median=False): """ @summary: Applies window smoothing on ion chromatogram @param ic: The input ion chromatogram @type ic: pyms.GCMS.Class.IonChromatogram @param window: The window selection parameter. This can be an integer or time string. If integer, taken as the number of points. If a string, must of the form "<NUMBER>s" or "<NUMBER>m", specifying a time in seconds or minutes, respectively @type window: IntType or StringType @param median: An indicator whether the mean or median window smoothing to be used @type median: Booleantype @return: Smoothed ion chromatogram @rtype: pyms.GCMS.Class.IonChromatogram @author: Vladimir Likic """ if not is_ionchromatogram(ic): error("'ic' not an IonChromatogram object") ia = ic.get_intensity_array() wing_length = ic_window_points(ic, window, half_window=True) if median: ia_denoise = __median_window(ia, wing_length) else: ia_denoise = __mean_window(ia, wing_length) ic_denoise = copy.deepcopy(ic) ic_denoise.set_intensity_array(ia_denoise) return ic_denoise
def tophat(ic, struct=None): """ @summary: Top-hat baseline correction on Ion Chromatogram @param ic: The input ion chromatogram @type ic: pyms.GCMS.Class.IonChromatogram @param struct: Top-hat structural element as time string @type struct: StringType @return: Top-hat corrected ion chromatogram @rtype: pyms.IO.Class.IonChromatogram @author: Woon Wai Keen @author: Vladimir Likic """ if not is_ionchromatogram(ic): error("'ic' not an IonChromatogram object") else: ia = copy.deepcopy(ic.get_intensity_array()) if struct == None: struct_pts = int(round(ia.size * _STRUCT_ELM_FRAC)) else: struct_pts = ic_window_points(ic, struct) # print " -> Top-hat: structural element is %d point(s)" % ( struct_pts ) str_el = numpy.repeat([1], struct_pts) ia = ndimage.white_tophat(ia, None, str_el) ic_bc = copy.deepcopy(ic) ic_bc.set_intensity_array(ia) return ic_bc
def tophat(ic, struct=None): """ @summary: Top-hat baseline correction on Ion Chromatogram @param ic: The input ion chromatogram @type ic: pyms.GCMS.Class.IonChromatogram @param struct: Top-hat structural element as time string @type struct: StringType @return: Top-hat corrected ion chromatogram @rtype: pyms.IO.Class.IonChromatogram @author: Woon Wai Keen @author: Vladimir Likic """ if not is_ionchromatogram(ic): error("'ic' not an IonChromatogram object") else: ia = copy.deepcopy(ic.get_intensity_array()) if struct == None: struct_pts = int(round(ia.size * _STRUCT_ELM_FRAC)) else: struct_pts = ic_window_points(ic,struct) # print " -> Top-hat: structural element is %d point(s)" % ( struct_pts ) str_el = numpy.repeat([1], struct_pts) ia = ndimage.white_tophat(ia, None, str_el) ic_bc = copy.deepcopy(ic) ic_bc.set_intensity_array(ia) return ic_bc