From fcb317239993fab0f8d90065f97be252c0d51181 Mon Sep 17 00:00:00 2001 From: linarphy Date: Fri, 5 May 2023 17:05:28 +0200 Subject: [PATCH] Add first ETA automated processing Start of the transition from jupyter to plain python. Still WIP ! For now, only give the cropped image. --- ETA.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 ETA.py diff --git a/ETA.py b/ETA.py new file mode 100644 index 0000000..153bf03 --- /dev/null +++ b/ETA.py @@ -0,0 +1,69 @@ +import numpy as np +import utils +import sys + +data = utils.load( sys.argv[1] ) + +""" +find fill points +""" +points = [] + +points += utils.find_point( data[ : , 0 ] , 0 ) # x_min +points += utils.find_point( + data[ : , data.shape[1] - 1 ], + data.shape[1] - 1 , +) # x_max + +index_min = 0 +while data.shape[0] - 1 > index_min: + index_min += 1 + if len( utils.find_point( data[ index_min , : ] , index_min , 'y' ) ) == 3: + break + +points.append( + utils.find_point( data[ index_min , : ] , index_min , 'y' )[1] +) # y_min + +index_max = data.shape[0] - 1 +while index_min < index_max: + index_max -= 1 + if len( utils.find_point( data[ index_max , : ] , index_max , 'y' ) ) == 3: + break + + +points.append( + utils.find_point( data[ index_max , : ] , index_max , 'y' )[1] +) # y_max + +small_data = utils.compress( data , 5 ) + +points = utils.big_to_small( points , 5 ) + +points[ 1 ][ 1 ] -= 1 +points[ 3 ][ 0 ] -= 1 + +extremum = [] +for point in points: + taken_points = utils.small_to_big( utils.fill( small_data , point , 1000 ) , 5 ) + extremum.append( [ + np.min( taken_points[ : , 1 ] ), + np.max( taken_points[ : , 1 ] ), + np.min( taken_points[ : , 0 ] ), + np.max( taken_points[ : , 0 ] ), + ] ) + +border = { + 'x': { + 'min': extremum[0][1] + 1, + 'max': extremum[1][0] , + }, + 'y': { + 'min': extremum[2][3] + 1, + 'max': extremum[3][2] , + }, +} + +import matplotlib.pyplot as plt +plt.imshow( data[ border[ 'y' ][ 'min' ] : border[ 'y' ][ 'max' ] , border[ 'x' ][ 'min' ] : border[ 'x' ][ 'max' ] ] ) +plt.savefig( 'test.png' )