Update plate rotation
This commit is contained in:
parent
12d0c703a7
commit
2f718da06f
3 changed files with 44 additions and 23 deletions
|
@ -21,7 +21,6 @@ class Border:
|
|||
"""
|
||||
Return rectangular slice
|
||||
"""
|
||||
print( self )
|
||||
return (
|
||||
slice(
|
||||
self.y.min , self.y.max
|
||||
|
|
|
@ -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()
|
||||
|
|
11
main.py
11
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()
|
||||
|
|
Loading…
Reference in a new issue