#NEWLINE# def test_img_to_relative_xyi( random_seed = None ) : #NEWLINE# #INDENT# from skbeam.core.utils import img_to_relative_xyi #NEWLINE# if ( random_seed is not None ) : #NEWLINE# #INDENT# np . random . seed ( 42 ) #NEWLINE# #UNINDENT# maxx = 2000 #NEWLINE# maxy = 2000 #NEWLINE# nx = int ( ( np . random . rand ( ) * maxx ) ) #NEWLINE# ny = int ( ( np . random . rand ( ) * maxy ) ) #NEWLINE# cx = ( np . random . rand ( ) * nx ) #NEWLINE# cy = ( np . random . rand ( ) * ny ) #NEWLINE# img = np . ones ( ( nx , ny ) ) #NEWLINE# cx_lst = [ 0 , cx , nx ] #NEWLINE# cy_lst = [ 0 , cy , ny ] #NEWLINE# for ( cx , cy ) in zip ( cx_lst , cy_lst ) : #NEWLINE# #INDENT# ( x , y , i ) = img_to_relative_xyi ( img = img , cx = cx , cy = cy ) #NEWLINE# logger . debug ( 'y {0}' . format ( y ) ) #NEWLINE# logger . debug ( 'sum(y) {0}' . format ( sum ( y ) ) ) #NEWLINE# expected_total_y = ( sum ( ( np . arange ( ny , dtype = np . int64 ) - cy ) ) * nx ) #NEWLINE# logger . debug ( 'expected_total_y {0}' . format ( expected_total_y ) ) #NEWLINE# logger . debug ( 'x {0}' . format ( x ) ) #NEWLINE# logger . debug ( 'sum(x) {0}' . format ( sum ( x ) ) ) #NEWLINE# expected_total_x = ( sum ( ( np . arange ( nx , dtype = np . int64 ) - cx ) ) * ny ) #NEWLINE# logger . debug ( 'expected_total_x {0}' . format ( expected_total_x ) ) #NEWLINE# expected_total_intensity = ( nx * ny ) #NEWLINE# try : #NEWLINE# #INDENT# assert_almost_equal ( sum ( x ) , expected_total_x , decimal = 0 ) #NEWLINE# assert_almost_equal ( sum ( y ) , expected_total_y , decimal = 0 ) #NEWLINE# assert_equal ( sum ( i ) , expected_total_intensity ) #NEWLINE# #UNINDENT# except AssertionError as ae : #NEWLINE# #INDENT# logger . error ( 'img dims: ({0}, {1})' . format ( nx , ny ) ) #NEWLINE# logger . error ( 'img center: ({0}, {1})' . format ( cx , cy ) ) #NEWLINE# logger . error ( 'sum(returned_x): {0}' . format ( sum ( x ) ) ) #NEWLINE# logger . error ( 'expected_x: {0}' . format ( expected_total_x ) ) #NEWLINE# logger . error ( 'sum(returned_y): {0}' . format ( sum ( y ) ) ) #NEWLINE# logger . error ( 'expected_y: {0}' . format ( expected_total_y ) ) #NEWLINE# logger . error ( 'sum(returned_i): {0}' . format ( sum ( i ) ) ) #NEWLINE# logger . error ( 'expected_x: {0}' . format ( expected_total_intensity ) ) #NEWLINE# six . reraise ( AssertionError , ae , sys . exc_info ( ) [ 2 ] )