From 2f718da06f40ce474d68b771f876cf5757b8aa21 Mon Sep 17 00:00:00 2001 From: linarphy Date: Tue, 22 Aug 2023 23:19:10 +0200 Subject: [PATCH] Update plate rotation --- classes/science/border.py | 1 - classes/science/plate.py | 55 ++++++++++++++++++++++++++++++--------- main.py | 11 ++------ 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/classes/science/border.py b/classes/science/border.py index be8b2ff..39cf1fb 100644 --- a/classes/science/border.py +++ b/classes/science/border.py @@ -21,7 +21,6 @@ class Border: """ Return rectangular slice """ - print( self ) return ( slice( self.y.min , self.y.max diff --git a/classes/science/plate.py b/classes/science/plate.py index 1af28ef..43a0936 100644 --- a/classes/science/plate.py +++ b/classes/science/plate.py @@ -1,4 +1,5 @@ -from numpy import ndarray +from numpy import ndarray, argmax, max, quantile, arange, where, convolve, ones +from scipy.optimize import curve_fit from classes.science.border import Border from function.utils import find_point, fill @@ -7,13 +8,13 @@ class Plate: Matrix of pixel """ - def __init__( self , image ): - if not isinstance( image , ndarray ): - raise ValueError( 'image must be a ndarray' ) - self.image = image + def __init__( self , data ): + if not isinstance( data , ndarray ): + raise TypeError( 'data must be a ndarray' ) + self.data = data self.set_border() - def set_border( self , factor = 5 ): + def set_border( self , factor = 10 ): """ Set current border (without area outside the plate) """ @@ -57,14 +58,14 @@ class Plate: if self.border.y.max > min( y ): self.border.y.max = min( y ) # same - offset = 3 + offset = 3 - self.border.x.min += offset - self.border.y.min += offset - self.border.x.max -= offset - self.border.y.min -= offset + self.border.x.min += offset + self.border.y.min += offset + self.border.x.max -= offset + self.border.y.min -= offset - self.border.scale( factor ) + self.border.scale( factor ) def get_points( self , compressed ): first_column = find_point( @@ -116,7 +117,35 @@ class Plate: return first_column + last_column + first_line + last_line def compress( self , factor ): - return self.image[ + return self.data[ : : factor, : : factor, ] + + def rotate( self ): + """ + Auto-rotate to be vertically and horizontally aligned + """ + maxes = max( + self.data[ self.border.slice() ], + axis = 0 , + ) + indexes = where( + maxes > quantile( maxes , 0.5 ) + ) + abciss = arange( + self.border.x.min, + self.border.x.max + )[ indexes ] + indexes_max = argmax( + self.data[ self.border.slice() ], + axis = 0 , + )[ indexes ] + indexes_max = convolve( + indexes_max , + ones( 100 ) , + 'same' , + ) / 100 + import matplotlib.pyplot as plt + plt.plot( abciss , indexes_max ) + plt.show() diff --git a/main.py b/main.py index 0882388..a2c6c9b 100755 --- a/main.py +++ b/main.py @@ -5,17 +5,10 @@ from classes.utils.settings import Settings from astropy.io.fits import open from sys import argv as arguments -settings = Settings( arguments[ 1 : ] ) - -print( settings ) +settings = Settings( arguments[ 1 : ] ) # remove the "main.py" part hdul = open( settings.input ) plate = Plate( hdul[0].data ) -head = hdul[0].header +plate.rotate() hdul.close() - -import matplotlib.pyplot as plt - -plt.imshow( plate.image[ plate.border.slice() ] ) -plt.show()