Skip to content

Commit a231841

Browse files
committed
ENH: Add control for numpy random seed
1 parent 3291b00 commit a231841

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

nibabies/config.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,8 @@ class seeds(_Config):
616616
"""Master random seed to initialize the Pseudorandom Number Generator (PRNG)"""
617617
ants = None
618618
"""Seed used for antsRegistration, antsAI, antsMotionCorr"""
619+
numpy = None
620+
"""Seed used by NumPy"""
619621

620622
@classmethod
621623
def init(cls):
@@ -626,6 +628,7 @@ def init(cls):
626628
random.seed(cls.master) # initialize the PRNG
627629
# functions to set program specific seeds
628630
cls.ants = _set_ants_seed()
631+
cls.numpy = _set_numpy_seed()
629632

630633

631634
def _set_ants_seed():
@@ -635,6 +638,15 @@ def _set_ants_seed():
635638
return val
636639

637640

641+
def _set_numpy_seed():
642+
"""NumPy's random seed is independant from Python's `random` module"""
643+
import numpy as np
644+
645+
val = random.randint(1, 65536)
646+
np.random.seed(val)
647+
return val
648+
649+
638650
def from_dict(settings):
639651
"""Read settings from a flat dictionary."""
640652
nipype.load(settings)

0 commit comments

Comments
 (0)