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
|
Return rectangular slice
|
||||||
"""
|
"""
|
||||||
print( self )
|
|
||||||
return (
|
return (
|
||||||
slice(
|
slice(
|
||||||
self.y.min , self.y.max
|
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 classes.science.border import Border
|
||||||
from function.utils import find_point, fill
|
from function.utils import find_point, fill
|
||||||
|
|
||||||
|
@ -7,13 +8,13 @@ class Plate:
|
||||||
Matrix of pixel
|
Matrix of pixel
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__( self , image ):
|
def __init__( self , data ):
|
||||||
if not isinstance( image , ndarray ):
|
if not isinstance( data , ndarray ):
|
||||||
raise ValueError( 'image must be a ndarray' )
|
raise TypeError( 'data must be a ndarray' )
|
||||||
self.image = image
|
self.data = data
|
||||||
self.set_border()
|
self.set_border()
|
||||||
|
|
||||||
def set_border( self , factor = 5 ):
|
def set_border( self , factor = 10 ):
|
||||||
"""
|
"""
|
||||||
Set current border (without area outside the plate)
|
Set current border (without area outside the plate)
|
||||||
"""
|
"""
|
||||||
|
@ -116,7 +117,35 @@ class Plate:
|
||||||
return first_column + last_column + first_line + last_line
|
return first_column + last_column + first_line + last_line
|
||||||
|
|
||||||
def compress( self , factor ):
|
def compress( self , factor ):
|
||||||
return self.image[
|
return self.data[
|
||||||
: : factor,
|
: : factor,
|
||||||
: : 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 astropy.io.fits import open
|
||||||
from sys import argv as arguments
|
from sys import argv as arguments
|
||||||
|
|
||||||
settings = Settings( arguments[ 1 : ] )
|
settings = Settings( arguments[ 1 : ] ) # remove the "main.py" part
|
||||||
|
|
||||||
print( settings )
|
|
||||||
|
|
||||||
hdul = open( settings.input )
|
hdul = open( settings.input )
|
||||||
plate = Plate( hdul[0].data )
|
plate = Plate( hdul[0].data )
|
||||||
head = hdul[0].header
|
plate.rotate()
|
||||||
|
|
||||||
hdul.close()
|
hdul.close()
|
||||||
|
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
|
|
||||||
plt.imshow( plate.image[ plate.border.slice() ] )
|
|
||||||
plt.show()
|
|
||||||
|
|
Loading…
Reference in a new issue