Add functions and fix
- Add near_value function
This commit is contained in:
parent
b3b1bb843b
commit
3b3329fe74
2 changed files with 14 additions and 1 deletions
2
ETA.py
2
ETA.py
|
@ -442,7 +442,7 @@ else:
|
||||||
if verbose:
|
if verbose:
|
||||||
print( 'main ETA curved' )
|
print( 'main ETA curved' )
|
||||||
|
|
||||||
if not cache_file.exists():
|
if not cache_file.exists() and not no_cache:
|
||||||
if verbose:
|
if verbose:
|
||||||
print( 'writing result in cache' )
|
print( 'writing result in cache' )
|
||||||
with shelve.open( str( cache_file ) ) as cache:
|
with shelve.open( str( cache_file ) ) as cache:
|
||||||
|
|
13
utils.py
13
utils.py
|
@ -276,3 +276,16 @@ def retrieve_peaks( data , window_size = 5 , error_coef = 1.05 , max_window_size
|
||||||
peaks = new_peaks
|
peaks = new_peaks
|
||||||
window_size += 1
|
window_size += 1
|
||||||
return peaks
|
return peaks
|
||||||
|
def near_value( list_ , value ):
|
||||||
|
"""
|
||||||
|
return indexes of the list whith a value nearest of the given
|
||||||
|
one when crossing it
|
||||||
|
"""
|
||||||
|
change = np.where( np.diff( np.sign( list_ - value ) ) != 0 ) # sign change
|
||||||
|
index = change + (
|
||||||
|
value - list_[ change ]
|
||||||
|
) / (
|
||||||
|
list_[ change + np.ones_like( change ) ] - list_[ change ]
|
||||||
|
) # interpolation
|
||||||
|
index = np.append( index , np.where( list_ == value ) )
|
||||||
|
return np.round( np.sort( index ) ).astype( int ) # triage
|
||||||
|
|
Loading…
Reference in a new issue