#NEWLINE# def ndintegrate( data , unit_conv , limits , unit = 'ppm' , noise_limits = None ) : #NEWLINE# #INDENT# '\n    Integrate one nD data array within limits given in units. Data points must\n    be equally spaced. Can only integrate one region per function call.\n\n    The integration error due to baseline noise is calculated as:\n\n    .. math::\n        error = \\sigma_{vol} = \\sigma \\sqrt{\\prod_i^{d} n_{i}},\n\n    if the noise_limits are set.\n\n    Where:\n    sigma is the standard deviation of the baseline noise. n is the number\n    of bins in the integration range for each d dimensions.\n\n    See integrate for more information.\n\n    Parameters\n    ----------\n    data: array like\n        1d array of intensity\n    unit_convs: [`fileiobase.unit_conversion`, ] list\n        list of unit_conversion object associated with each dim of data.\n    limits: array like\n        With shape (2,) or (d, 2). 1D Array with lower and upper integration\n        limits for 1D . Or array with d rows of lower and upper integration\n        limits for each dimension.\n    noise_limits: Optional[array like]\n        With shape(2, ). Array with lower and upper limits to section of data\n        with only noise. A larger range will likely yield a more accurate\n        estimate. It is unwise to use the very end of the spectrum for the\n        noise range.\n\n    Returns\n    -------\n    array\n        [value, ...] integration values\n\n    if noise_limits is given:\n\n    array\n        [[value, error], ...] where error a one sigma estimate of the error\n        only from the spectrum noise\n    ' #NEWLINE# d = np . ndim ( data ) #NEWLINE# try : #NEWLINE# #INDENT# iter ( unit_conv ) #NEWLINE# #UNINDENT# except TypeError : #NEWLINE# #INDENT# unit_conv = [ unit_conv ] #NEWLINE# #UNINDENT# if ( d != len ( unit_conv ) ) : #NEWLINE# #INDENT# mesg = 'A unit_conversion object is needed for each dimension.' #NEWLINE# raise ValueError ( mesg ) #NEWLINE# #UNINDENT# limits = np . array ( limits ) #NEWLINE# if ( limits . ndim == 1 ) : #NEWLINE# #INDENT# limits = np . expand_dims ( limits , axis = 0 ) #NEWLINE# #UNINDENT# if ( ( limits . shape [ 0 ] != d ) and ( limits . shape [ 1 ] != 2 ) ) : #NEWLINE# #INDENT# mesg = 'A lower and upper limit is needed for each dimension.' #NEWLINE# raise ValueError ( mesg ) #NEWLINE# #UNINDENT# inds = [ ( uc ( x [ 0 ] , unit ) , uc ( x [ 1 ] , unit ) ) for ( uc , x ) in zip ( unit_conv , limits ) ] #NEWLINE# inds = [ sorted ( x ) for x in inds ] #NEWLINE# ppm_scales = [ x . ppm_scale ( ) for x in unit_conv ] #NEWLINE# dx = np . prod ( np . array ( [ abs ( ( x [ 1 ] - x [ 0 ] ) ) for x in ppm_scales ] ) ) #NEWLINE# slice_sum = data [ [ slice ( x [ 0 ] , x [ 1 ] ) for x in np . flipud ( inds ) ] ] . sum ( ) #NEWLINE# value = ( slice_sum * dx ) #NEWLINE# if ( noise_limits is None ) : #NEWLINE# #INDENT# return value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# noise_limits = np . array ( noise_limits ) #NEWLINE# if ( noise_limits . size == 2 ) : #NEWLINE# #INDENT# noise_limits = np . expand_dims ( noise_limits , axis = 0 ) #NEWLINE# #UNINDENT# if ( ( noise_limits . shape [ 0 ] != d ) and ( noise_limits . shape [ 1 ] != 2 ) ) : #NEWLINE# #INDENT# mesg = 'If given, a noise limit is needed for each dimension.' #NEWLINE# raise ValueError ( mesg ) #NEWLINE# #UNINDENT# noise_inds = [ ( uc ( x [ 0 ] , unit ) , uc ( x [ 1 ] , unit ) ) for ( uc , x ) in zip ( unit_conv , noise_limits ) ] #NEWLINE# noise_inds = [ sorted ( x ) for x in noise_inds ] #NEWLINE# nm = np . prod ( np . array ( [ abs ( ( x [ 1 ] - x [ 0 ] ) ) for x in noise_inds ] ) ) #NEWLINE# std = np . std ( data [ [ slice ( x [ 0 ] , x [ 1 ] ) for x in np . flipud ( noise_inds ) ] ] ) #NEWLINE# error = ( std * np . sqrt ( nm ) ) #NEWLINE# return np . hstack ( ( value , error ) )