Add type check for point finding
This commit is contained in:
parent
1b04152337
commit
f75e2e2af9
1 changed files with 24 additions and 1 deletions
25
utils.py
25
utils.py
|
@ -1,6 +1,8 @@
|
|||
from astropy.io.fits import open
|
||||
import numpy as np
|
||||
|
||||
global_i = 0
|
||||
|
||||
def load( filename ):
|
||||
"""
|
||||
retrieve data from naroo fits
|
||||
|
@ -78,7 +80,7 @@ def check_side( data , point , tolerance ):
|
|||
if not isinstance( tolerance , int ) and not isinstance( tolerance , float ):
|
||||
raise ValueError( 'tolerance must be a number, ' + type( tolerance ) + ' given' )
|
||||
|
||||
positions , intensity = [] , data[ *point ]
|
||||
positions , intensity = [] , data[ tuple( point ) ]
|
||||
if 0 <= point[0] < data.shape[0] - 1 and intensity - tolerance <= data[ point[0] + 1 , point[1] ] <= intensity + tolerance:
|
||||
positions.append( [ point[0] + 1 , point[1] ] )
|
||||
if 0 < point[0] < data.shape[0] and intensity - tolerance <= data[ point[0] - 1 , point[1] ] <= intensity + tolerance:
|
||||
|
@ -93,6 +95,8 @@ def fill( data , point , tolerance , limit = 100000 ):
|
|||
"""
|
||||
give the coordinate of all points that fill the area with the given tolerance
|
||||
"""
|
||||
global global_i
|
||||
global_i += 1
|
||||
if not isinstance( data , np.ndarray ) and not isinstance( data , list ):
|
||||
raise ValueError( 'data must be a list, ' + type( data ) + ' given' )
|
||||
if not isinstance( point , np.ndarray ) and not isinstance( point , tuple ) and not isinstance( point , list ):
|
||||
|
@ -118,6 +122,14 @@ def point( index_1 , index_2 , axis = 'x' ):
|
|||
"""
|
||||
reorder coordinate
|
||||
"""
|
||||
if not isinstance( index_1 , int ):
|
||||
raise ValueError( 'index_1 must be an integer, ' + type( index_1 ) + ' given' )
|
||||
if not isinstance( index_2 , int ):
|
||||
raise ValueError( 'index_2 must be an integer, ' + type( index_2 ) + ' given' )
|
||||
if not isinstance( axis , str ):
|
||||
raise ValueError( 'axis must be a string, ' + type( axis ) + ' given' )
|
||||
if axis not in [ 'x' , 'y' ]:
|
||||
raise ValueError( 'axis must be "x" or "y", ' + axis + ' given' )
|
||||
if axis == 'x':
|
||||
return [ index_2 , index_1 ]
|
||||
return [ index_1 , index_2 ]
|
||||
|
@ -126,6 +138,17 @@ def find_point( list_ , index , axis = 'x' , threshold = 0.5 ):
|
|||
"""
|
||||
find the index where to fill in a side
|
||||
"""
|
||||
if not isinstance( list_ , list ) and not isinstance( list_ , np.ndarray ):
|
||||
raise ValueError( 'list_ must be a list, ' + type( list_ ) + ' given' )
|
||||
if not isinstance( index , int ):
|
||||
raise ValueError( 'index must be an integer, ' + type( index ) + ' given' )
|
||||
if not isinstance( axis , str ):
|
||||
raise ValueError( 'axis must be a string, ' + type( axis ) + ' given' )
|
||||
if axis not in [ 'x' , 'y' ]:
|
||||
raise ValueError( 'axis must be "x" or "y", ' + axis + ' given' )
|
||||
if not isinstance( threshold , float ):
|
||||
raise ValueError( 'threshold must be a float, ' + type( threshold ) + ' given' )
|
||||
|
||||
mean = np.mean( list_ )
|
||||
ampl = np.max( list_ ) - np.min( list_ )
|
||||
|
||||
|
|
Loading…
Reference in a new issue