def test_interp(): # logger = piff.config.setup_logger(verbose=3, log_file='test_knn_interp.log') logger = None # make sure we can put in the data star_list = generate_data() knn = piff.kNNInterp(keys, n_neighbors=1) knn.initialize(star_list, logger=logger) knn.solve(star_list, logger=logger) # make prediction on first 10 items of star_list star_list_predict = star_list[:10] star_list_predicted = knn.interpolateList(star_list_predict, logger=logger) # also on a single star star_predict = star_list_predict[0] star_predicted = knn.interpolate(star_predict) # predicted stars should find their exact partner here, so they have the same data np.testing.assert_array_equal(star_predicted.fit.params, star_predict.fit.params) for attr in keys: np.testing.assert_equal(star_predicted.data[attr], star_predict.data[attr]) # repeat for a star with its starfit removed star_predict = star_list_predict[0] star_predict.fit = None star_predicted = knn.interpolate(star_predict) # predicted stars should find their exact partner here, so they have the same data # removed the fit, so don't check that # np.testing.assert_array_equal(star_predicted.fit.params, star_predict.fit.params) for attr in keys: np.testing.assert_equal(star_predicted.data[attr], star_predict.data[attr])
def test_disk(): # make sure reading and writing of data works star_list = generate_data() knn = piff.kNNInterp(keys, n_neighbors=2) knn.initialize(star_list) knn.solve(star_list) knn_file = os.path.join('output','knn_interp.fits') with fitsio.FITS(knn_file,'rw',clobber=True) as f: knn.write(f, 'knn') knn2 = piff.kNNInterp.read(f, 'knn') np.testing.assert_array_equal(knn.locations, knn2.locations) np.testing.assert_array_equal(knn.targets, knn2.targets) np.testing.assert_array_equal(knn.kwargs['keys'], knn2.kwargs['keys']) np.testing.assert_equal(knn.knr_kwargs['n_neighbors'], knn2.knr_kwargs['n_neighbors']) np.testing.assert_equal(knn.knr_kwargs['algorithm'], knn2.knr_kwargs['algorithm'])
def test_init(): # make sure we can init the interpolator knn = piff.kNNInterp(keys)
def test_init(): # make sure we can init the interpolator knn = piff.kNNInterp(keys) assert knn.property_names == keys