From d77d28998f19afffe35f56e3d1f7f04f3daae65b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= <jon.haitz.legarreta@gmail.com> Date: Sun, 24 Mar 2024 12:07:50 -0400 Subject: [PATCH] ENH: Use NumPy's `Generator` class as a replacement for `RandomState` Use NumPy's `Generator` class as a replacement for `RandomState` for random variarte generation methods. `RandomState` was deprecated in NumPy 1.17.0. Take advantage of the commit to document better the use of the `seed` parameter. Documentation: https://numpy.org/doc/stable/reference/random/new-or-different.html#what-s-new-or-different https://numpy.org/doc/stable/reference/random/generated/numpy.random.seed.html --- src/eddymotion/estimator.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/eddymotion/estimator.py b/src/eddymotion/estimator.py index 8e812b67..31721c27 100644 --- a/src/eddymotion/estimator.py +++ b/src/eddymotion/estimator.py @@ -86,8 +86,11 @@ def fit( """ align_kwargs = align_kwargs or {} + _seed = None if seed or seed == 0: - np.random.seed(20210324 if seed is True else seed) + _seed = 20210324 if seed is True else seed + + rng = np.random.default_rng(_seed) if "num_threads" not in align_kwargs and omp_nthreads is not None: align_kwargs["num_threads"] = omp_nthreads @@ -120,7 +123,7 @@ def fit( kwargs["xlim"] = dwdata.total_duration index_order = np.arange(len(dwdata)) - np.random.shuffle(index_order) + rng.shuffle(index_order) single_model = model.lower() in ( "b0",