From c1b7400c8e3b319d1d2ac3d7abe09230ee6c4f06 Mon Sep 17 00:00:00 2001 From: Sukhdeep Date: Mon, 28 Jan 2019 14:52:06 -0800 Subject: [PATCH 1/4] ADD numpy random state argument to synalm --- healpy/sphtfunc.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/healpy/sphtfunc.py b/healpy/sphtfunc.py index 6a4b515d0..a4e98f57b 100644 --- a/healpy/sphtfunc.py +++ b/healpy/sphtfunc.py @@ -347,7 +347,7 @@ def alm2map( return np.array(output) -def synalm(cls, lmax=None, mmax=None, new=False, verbose=True): +def synalm(cls, lmax=None, mmax=None, new=False, RNG=None, verbose=True): """Generate a set of alm given cl. The cl are given as a float array. Corresponding alm are generated. If lmax is None, it is assumed lmax=cl.size-1 @@ -369,6 +369,11 @@ def synalm(cls, lmax=None, mmax=None, new=False, verbose=True): (e.g. TT, EE, BB, TE, EB, TB or TT, EE, BB, TE if 4 cl as input). If False, use the old ordering, ie by row (e.g. TT, TE, TB, EE, EB, BB or TT, TE, EE, BB if 4 cl as input). + + RNG: numpy random number generator state. Useful when generating multiple + maps in parallel. Typically, RNG = np.random.RandomState(seed) + see: + https://stackoverflow.com/questions/29854398/seeding-random-number-generators-in-parallel-programs Returns ------- @@ -408,8 +413,14 @@ def synalm(cls, lmax=None, mmax=None, new=False, verbose=True): cls_list = [np.asarray(cls, dtype=np.float64)] szalm = Alm.getsize(lmax, mmax) alm = np.zeros(szalm, "D") - alm.real = np.random.standard_normal(szalm) - alm.imag = np.random.standard_normal(szalm) + + if RNG is None: + alm.real = np.random.standard_normal(szalm) + alm.imag = np.random.standard_normal(szalm) + else: + alm.real = RNG.standard_normal(szalm) + alm.imag = RNG..standard_normal(szalm) + alms_list = [alm] sphtlib._synalm(cls_list, alms_list, lmax, mmax) return alm @@ -442,8 +453,14 @@ def synalm(cls, lmax=None, mmax=None, new=False, verbose=True): alms_list = [] for i in six.moves.xrange(Nspec): alm = np.zeros(szalm, "D") - alm.real = np.random.standard_normal(szalm) - alm.imag = np.random.standard_normal(szalm) + + if RNG is None: + alm.real = np.random.standard_normal(szalm) + alm.imag = np.random.standard_normal(szalm) + else: + alm.real = RNG.standard_normal(szalm) + alm.imag = RNG.standard_normal(szalm) + alms_list.append(alm) if new: # new input order: input given by diagonal, should be given by row cls_list = new_to_old_spectra_order(cls_list) @@ -467,6 +484,7 @@ def synfast( fwhm=0.0, sigma=None, new=False, + RNG=None, verbose=True, ): """Create a map(s) from cl(s). @@ -497,6 +515,7 @@ def synfast( sigma : float, scalar, optional The sigma of the Gaussian used to smooth the map (applied on alm) [in radians] + RNG: Numpy random number generator state, passed to synalm. Returns ------- @@ -524,7 +543,7 @@ def synfast( cls_lmax = cb.len_array_or_arrays(cls) - 1 if lmax is None or lmax < 0: lmax = min(cls_lmax, 3 * nside - 1) - alms = synalm(cls, lmax=lmax, mmax=mmax, new=new, verbose=verbose) + alms = synalm(cls, lmax=lmax, mmax=mmax, new=new, RNG=RNG, verbose=verbose) maps = alm2map( alms, nside, From 799ef4e650a3dd5e386bc7005965a84b65d012cf Mon Sep 17 00:00:00 2001 From: Sukhdeep Date: Mon, 28 Jan 2019 14:59:41 -0800 Subject: [PATCH 2/4] fixed typo --- healpy/sphtfunc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/healpy/sphtfunc.py b/healpy/sphtfunc.py index a4e98f57b..2ef9c5315 100644 --- a/healpy/sphtfunc.py +++ b/healpy/sphtfunc.py @@ -419,7 +419,7 @@ def synalm(cls, lmax=None, mmax=None, new=False, RNG=None, verbose=True): alm.imag = np.random.standard_normal(szalm) else: alm.real = RNG.standard_normal(szalm) - alm.imag = RNG..standard_normal(szalm) + alm.imag = RNG.standard_normal(szalm) alms_list = [alm] sphtlib._synalm(cls_list, alms_list, lmax, mmax) From 72d9d1214534656bf35c764ede0aeb21dbead0b9 Mon Sep 17 00:00:00 2001 From: Sukhdeep Date: Mon, 28 Jan 2019 15:05:14 -0800 Subject: [PATCH 3/4] changed from caps to lower case --- healpy/sphtfunc.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/healpy/sphtfunc.py b/healpy/sphtfunc.py index 2ef9c5315..1c40f0948 100644 --- a/healpy/sphtfunc.py +++ b/healpy/sphtfunc.py @@ -347,7 +347,7 @@ def alm2map( return np.array(output) -def synalm(cls, lmax=None, mmax=None, new=False, RNG=None, verbose=True): +def synalm(cls, lmax=None, mmax=None, new=False, rng=None, verbose=True): """Generate a set of alm given cl. The cl are given as a float array. Corresponding alm are generated. If lmax is None, it is assumed lmax=cl.size-1 @@ -370,8 +370,8 @@ def synalm(cls, lmax=None, mmax=None, new=False, RNG=None, verbose=True): If False, use the old ordering, ie by row (e.g. TT, TE, TB, EE, EB, BB or TT, TE, EE, BB if 4 cl as input). - RNG: numpy random number generator state. Useful when generating multiple - maps in parallel. Typically, RNG = np.random.RandomState(seed) + rng: numpy random number generator state. Useful when generating multiple + maps in parallel. Typically, `rng=np.random.RandomState(seed)` see: https://stackoverflow.com/questions/29854398/seeding-random-number-generators-in-parallel-programs @@ -414,12 +414,12 @@ def synalm(cls, lmax=None, mmax=None, new=False, RNG=None, verbose=True): szalm = Alm.getsize(lmax, mmax) alm = np.zeros(szalm, "D") - if RNG is None: + if rng is None: alm.real = np.random.standard_normal(szalm) alm.imag = np.random.standard_normal(szalm) else: - alm.real = RNG.standard_normal(szalm) - alm.imag = RNG.standard_normal(szalm) + alm.real = rng.standard_normal(szalm) + alm.imag = rng.standard_normal(szalm) alms_list = [alm] sphtlib._synalm(cls_list, alms_list, lmax, mmax) @@ -454,12 +454,12 @@ def synalm(cls, lmax=None, mmax=None, new=False, RNG=None, verbose=True): for i in six.moves.xrange(Nspec): alm = np.zeros(szalm, "D") - if RNG is None: + if rng is None: alm.real = np.random.standard_normal(szalm) alm.imag = np.random.standard_normal(szalm) else: - alm.real = RNG.standard_normal(szalm) - alm.imag = RNG.standard_normal(szalm) + alm.real = rng.standard_normal(szalm) + alm.imag = rng.standard_normal(szalm) alms_list.append(alm) if new: # new input order: input given by diagonal, should be given by row @@ -484,7 +484,7 @@ def synfast( fwhm=0.0, sigma=None, new=False, - RNG=None, + rng=None, verbose=True, ): """Create a map(s) from cl(s). @@ -515,7 +515,7 @@ def synfast( sigma : float, scalar, optional The sigma of the Gaussian used to smooth the map (applied on alm) [in radians] - RNG: Numpy random number generator state, passed to synalm. + rng: Numpy random number generator state, passed to synalm. Returns ------- @@ -543,7 +543,7 @@ def synfast( cls_lmax = cb.len_array_or_arrays(cls) - 1 if lmax is None or lmax < 0: lmax = min(cls_lmax, 3 * nside - 1) - alms = synalm(cls, lmax=lmax, mmax=mmax, new=new, RNG=RNG, verbose=verbose) + alms = synalm(cls, lmax=lmax, mmax=mmax, new=new, rng=rng, verbose=verbose) maps = alm2map( alms, nside, From b5f2add87916b9ebc23e88c5ab5836029ab4d21f Mon Sep 17 00:00:00 2001 From: Sukhdeep Date: Mon, 28 Jan 2019 15:13:06 -0800 Subject: [PATCH 4/4] removed stack overflow link --- healpy/sphtfunc.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/healpy/sphtfunc.py b/healpy/sphtfunc.py index 1c40f0948..4bb49d299 100644 --- a/healpy/sphtfunc.py +++ b/healpy/sphtfunc.py @@ -372,8 +372,7 @@ def synalm(cls, lmax=None, mmax=None, new=False, rng=None, verbose=True): rng: numpy random number generator state. Useful when generating multiple maps in parallel. Typically, `rng=np.random.RandomState(seed)` - see: - https://stackoverflow.com/questions/29854398/seeding-random-number-generators-in-parallel-programs + Returns -------