<s> import numpy as np <EOL> import dask . async <EOL> import scipy . stats as stats <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> FEATURES_LIST = [ <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] <EOL> def double_to_single_step ( cads ) : <EOL> """<STR_LIT>""" <EOL> return ( cads [ <NUM_LIT:1> : ] + cads [ : - <NUM_LIT:1> ] ) / cads [ <NUM_LIT:1> : ] <EOL> def cad_prob ( cads , time ) : <EOL> """<STR_LIT>""" <EOL> return stats . percentileofscore ( cads , float ( time ) / ( <NUM_LIT> * <NUM_LIT> ) ) / <NUM_LIT> <EOL> def delta_t_hist ( t , nbins = <NUM_LIT:50> ) : <EOL> """<STR_LIT>""" <EOL> hist = np . zeros ( nbins , dtype = '<STR_LIT:int>' ) <EOL> bins = np . linspace ( <NUM_LIT:0> , max ( t ) - min ( t ) , nbins + <NUM_LIT:1> ) <EOL> for i in range ( len ( t ) ) : <EOL> hist += np . histogram ( t [ i ] - t [ : i ] , bins = bins ) [ <NUM_LIT:0> ] <EOL> hist += np . histogram ( t [ i + <NUM_LIT:1> : ] - t [ i ] , bins = bins ) [ <NUM_LIT:0> ] <EOL> return hist / <NUM_LIT:2> <EOL> def normalize_hist ( hist , total_time ) : <EOL> """<STR_LIT>""" <EOL> return hist / ( total_time * np . mean ( hist ) ) <EOL> def find_sorted_peaks ( x ) : <EOL> """<STR_LIT>""" <EOL> peak_inds = [ ] <EOL> nbins = len ( x ) <EOL> for i in range ( nbins ) : <EOL> if i == <NUM_LIT:0> or x [ i ] > x [ i - <NUM_LIT:1> ] : <EOL> if i == nbins - <NUM_LIT:1> or x [ i ] > x [ i + <NUM_LIT:1> ] : <EOL> peak_inds . append ( i ) <EOL> elif x [ i ] == x [ i + <NUM_LIT:1> ] : <EOL> for j in range ( i + <NUM_LIT:1> , nbins ) : <EOL> if x [ j ] != x [ i ] : <EOL> if x [ j ] < x [ i ] : <EOL> peak_inds . append ( i ) <EOL> break <EOL> if j == nbins - <NUM_LIT:1> and x [ i ] == x [ j ] : <EOL> peak_inds . append ( i ) <EOL> sorted_peak_inds = sorted ( peak_inds , key = lambda i : x [ i ] , reverse = True ) <EOL> return list ( zip ( sorted_peak_inds , x [ sorted_peak_inds ] ) ) <EOL> def peak_ratio ( peaks , i , j ) : <EOL> """<STR_LIT>""" <EOL> if len ( peaks ) > i and len ( peaks ) > j : <EOL> return peaks [ i ] [ <NUM_LIT:1> ] / peaks [ j ] [ <NUM_LIT:1> ] <EOL> else : <EOL> return None <EOL> def peak_bin ( peaks , i ) : <EOL> """<STR_LIT>""" <EOL> if len ( peaks ) > i : <EOL> return peaks [ i ] [ <NUM_LIT:0> ] <EOL> else : <EOL> return None <EOL> def generate_obs_features ( t , m , e , features_to_compute = FEATURES_LIST ) : <EOL> """<STR_LIT>""" <EOL> features_to_compute = [ f for f in features_to_compute <EOL> if f in FEATURES_LIST ] <EOL> feature_graph = { <EOL> '<STR_LIT>' : ( len , t ) , <EOL> '<STR_LIT>' : ( np . mean , e ) , <EOL> '<STR_LIT>' : ( np . median , e ) , <EOL> '<STR_LIT>' : ( np . std , e ) , <EOL> '<STR_LIT>' : ( lambda x : np . max ( x ) - np . min ( x ) , t ) , <EOL> '<STR_LIT>' : ( np . mean , t ) , <EOL> '<STR_LIT>' : ( np . diff , t ) , <EOL> '<STR_LIT>' : ( np . std , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( np . mean , m ) , <EOL> '<STR_LIT>' : ( np . mean , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( np . median , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( cad_prob , '<STR_LIT>' , <NUM_LIT:1> ) , <EOL> '<STR_LIT>' : ( cad_prob , '<STR_LIT>' , <NUM_LIT:10> ) , <EOL> '<STR_LIT>' : ( cad_prob , '<STR_LIT>' , <NUM_LIT:20> ) , <EOL> '<STR_LIT>' : ( cad_prob , '<STR_LIT>' , <NUM_LIT:30> ) , <EOL> '<STR_LIT>' : ( cad_prob , '<STR_LIT>' , <NUM_LIT> ) , <EOL> '<STR_LIT>' : ( cad_prob , '<STR_LIT>' , <NUM_LIT:50> ) , <EOL> '<STR_LIT>' : ( cad_prob , '<STR_LIT>' , <NUM_LIT:100> ) , <EOL> '<STR_LIT>' : ( cad_prob , '<STR_LIT>' , <NUM_LIT> ) , <EOL> '<STR_LIT>' : ( cad_prob , '<STR_LIT>' , <NUM_LIT:1000> ) , <EOL> '<STR_LIT>' : ( cad_prob , '<STR_LIT>' , <NUM_LIT> ) , <EOL> '<STR_LIT>' : ( cad_prob , '<STR_LIT>' , <NUM_LIT> ) , <EOL> '<STR_LIT>' : ( cad_prob , '<STR_LIT>' , <NUM_LIT> ) , <EOL> '<STR_LIT>' : ( cad_prob , '<STR_LIT>' , <NUM_LIT> ) , <EOL> '<STR_LIT>' : ( cad_prob , '<STR_LIT>' , <NUM_LIT> ) , <EOL> '<STR_LIT>' : ( cad_prob , '<STR_LIT>' , <NUM_LIT> ) , <EOL> '<STR_LIT>' : ( cad_prob , '<STR_LIT>' , <NUM_LIT> ) , <EOL> '<STR_LIT>' : ( cad_prob , '<STR_LIT>' , <NUM_LIT> ) , <EOL> '<STR_LIT>' : ( double_to_single_step , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( np . mean , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( np . median , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( np . std , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( delta_t_hist , t ) , <EOL> '<STR_LIT>' : ( normalize_hist , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( find_sorted_peaks , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( np . max , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( lambda x : int ( np . argmax ( x ) ) , <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( len , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( np . max , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( peak_ratio , '<STR_LIT>' , <NUM_LIT:1> , <NUM_LIT:2> ) , <EOL> '<STR_LIT>' : ( peak_ratio , '<STR_LIT>' , <NUM_LIT:1> , <NUM_LIT:3> ) , <EOL> '<STR_LIT>' : ( peak_ratio , '<STR_LIT>' , <NUM_LIT:2> , <NUM_LIT:3> ) , <EOL> '<STR_LIT>' : ( peak_ratio , '<STR_LIT>' , <NUM_LIT:1> , <NUM_LIT:4> ) , <EOL> '<STR_LIT>' : ( peak_ratio , '<STR_LIT>' , <NUM_LIT:2> , <NUM_LIT:4> ) , <EOL> '<STR_LIT>' : ( peak_ratio , '<STR_LIT>' , <NUM_LIT:3> , <NUM_LIT:4> ) , <EOL> '<STR_LIT>' : ( peak_bin , '<STR_LIT>' , <NUM_LIT:1> ) , <EOL> '<STR_LIT>' : ( peak_bin , '<STR_LIT>' , <NUM_LIT:2> ) , <EOL> '<STR_LIT>' : ( peak_bin , '<STR_LIT>' , <NUM_LIT:3> ) , <EOL> '<STR_LIT>' : ( peak_bin , '<STR_LIT>' , <NUM_LIT:4> ) <EOL> } <EOL> values = dask . async . get_sync ( feature_graph , features_to_compute ) <EOL> return dict ( zip ( features_to_compute , values ) ) </s>
