#NEWLINE# def test_integral( self ) : #NEWLINE# #INDENT# x = [ 1 , 1 , 1 , 2 , 2 , 2 , 4 , 4 , 4 ] #NEWLINE# y = [ 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 ] #NEWLINE# z = array ( [ 0 , 7 , 8 , 3 , 4 , 7 , 1 , 3 , 4 ] ) #NEWLINE# with warnings . catch_warnings ( ) : #NEWLINE# #INDENT# warnings . simplefilter ( 'ignore' , UserWarning ) #NEWLINE# lut = SmoothBivariateSpline ( x , y , z , kx = 1 , ky = 1 , s = 0 ) #NEWLINE# #UNINDENT# tx = [ 1 , 2 , 4 ] #NEWLINE# ty = [ 1 , 2 , 3 ] #NEWLINE# tz = lut ( tx , ty ) #NEWLINE# trpz = ( 0.25 * ( ( diff ( tx ) [ : , None ] * diff ( ty ) [ None , : ] ) * ( ( ( tz [ : ( - 1 ) , : ( - 1 ) ] + tz [ 1 : , : ( - 1 ) ] ) + tz [ : ( - 1 ) , 1 : ] ) + tz [ 1 : , 1 : ] ) ) . sum ( ) ) #NEWLINE# assert_almost_equal ( lut . integral ( tx [ 0 ] , tx [ ( - 1 ) ] , ty [ 0 ] , ty [ ( - 1 ) ] ) , trpz ) #NEWLINE# lut2 = SmoothBivariateSpline ( x , tz , z , kx = 2 , ky = 2 , s = 0 ) #NEWLINE# assert_almost_equal ( lut2 . integral ( tx [ 0 ] , tx [ ( - 1 ) ] , ty [ 0 ] , ty [ ( - 1 ) ] ) , trpz , decimal = 0 ) #NEWLINE# tz = lut ( tx [ : ( - 1 ) ] , ty [ : ( - 1 ) ] ) #NEWLINE# trpz = ( 0.25 * ( ( diff ( tx [ : ( - 1 ) ] ) [ : , None ] * diff ( ty [ : ( - 1 ) ] ) [ None , : ] ) * ( ( ( tz [ : ( - 1 ) , : ( - 1 ) ] + tz [ 1 : , : ( - 1 ) ] ) + tz [ : ( - 1 ) , 1 : ] ) + tz [ 1 : , 1 : ] ) ) . sum ( ) ) #NEWLINE# assert_almost_equal ( lut . integral ( tx [ 0 ] , tx [ ( - 2 ) ] , ty [ 0 ] , ty [ ( - 2 ) ] ) , trpz )