<s> from cesium import obs_feature_tools as oft <EOL> import itertools <EOL> import numpy as np <EOL> import numpy . testing as npt <EOL> def irregular_random ( seed = <NUM_LIT:0> , size = <NUM_LIT:50> ) : <EOL> """<STR_LIT>""" <EOL> state = np . random . RandomState ( seed ) <EOL> times = np . sort ( state . uniform ( <NUM_LIT:0> , <NUM_LIT:10> , size ) ) <EOL> values = state . normal ( <NUM_LIT:1> , <NUM_LIT:1> , size ) <EOL> errors = state . exponential ( <NUM_LIT:0.1> , size ) <EOL> return times , values , errors <EOL> def test_delta_t_hist ( ) : <EOL> """<STR_LIT>""" <EOL> times , values , errors = irregular_random ( ) <EOL> delta_ts = [ pair [ <NUM_LIT:1> ] - pair [ <NUM_LIT:0> ] for pair in itertools . combinations ( times , <NUM_LIT:2> ) ] <EOL> nbins = <NUM_LIT:50> <EOL> bins = np . linspace ( <NUM_LIT:0> , max ( times ) - min ( times ) , nbins + <NUM_LIT:1> ) <EOL> npt . assert_allclose ( oft . delta_t_hist ( times , nbins ) , np . histogram ( delta_ts , <EOL> bins = bins ) [ <NUM_LIT:0> ] ) <EOL> def test_normalize_hist ( ) : <EOL> """<STR_LIT>""" <EOL> times , values , errors = irregular_random ( ) <EOL> delta_ts = [ pair [ <NUM_LIT:1> ] - pair [ <NUM_LIT:0> ] for pair in itertools . combinations ( times , <NUM_LIT:2> ) ] <EOL> nbins = <NUM_LIT:50> <EOL> bins = np . linspace ( <NUM_LIT:0> , max ( times ) - min ( times ) , nbins + <NUM_LIT:1> ) <EOL> nhist = oft . normalize_hist ( oft . delta_t_hist ( times , nbins ) , max ( times ) - <EOL> min ( times ) ) <EOL> npt . assert_allclose ( nhist , np . histogram ( delta_ts , <EOL> bins = bins , density = True ) [ <NUM_LIT:0> ] ) <EOL> def test_find_sorted_peaks ( ) : <EOL> """<STR_LIT>""" <EOL> x = np . array ( [ <NUM_LIT:0> , <NUM_LIT:5> , <NUM_LIT:3> , <NUM_LIT:1> ] ) <EOL> npt . assert_allclose ( oft . find_sorted_peaks ( x ) , np . array ( [ [ <NUM_LIT:1> , <NUM_LIT:5> ] ] ) ) <EOL> x = np . array ( [ <NUM_LIT:0> , <NUM_LIT:5> , <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:1> ] ) <EOL> npt . assert_allclose ( oft . find_sorted_peaks ( x ) , np . array ( [ [ <NUM_LIT:3> , <NUM_LIT:6> ] , [ <NUM_LIT:1> , <NUM_LIT:5> ] ] ) ) <EOL> x = np . array ( [ <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:3> ] ) <EOL> npt . assert_allclose ( oft . find_sorted_peaks ( x ) , np . array ( [ [ <NUM_LIT:0> , <NUM_LIT:3> ] , [ <NUM_LIT:2> , <NUM_LIT:3> ] ] ) ) <EOL> x = np . array ( [ <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:0> ] ) <EOL> npt . assert_allclose ( oft . find_sorted_peaks ( x ) , np . array ( [ [ <NUM_LIT:1> , <NUM_LIT:3> ] ] ) ) <EOL> x = np . array ( [ <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:0> ] ) <EOL> npt . assert_allclose ( oft . find_sorted_peaks ( x ) , np . array ( [ [ <NUM_LIT:3> , <NUM_LIT:5> ] ] ) ) </s>
