Skip to content

Commit 84671d4

Browse files
authored
MAINT: use gls instead of cls for Gaussian cls (#42)
1 parent 54aea6a commit 84671d4

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

glass/fields.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -165,24 +165,24 @@ def lognormal_gls(cls, shift=1., *, lmax=None, ncorr=None, nside=None):
165165
return transform_cls(gls, 'lognormal', (shift,))
166166

167167

168-
def generate_gaussian(cls, nside, *, ncorr=None, rng=None):
168+
def generate_gaussian(gls, nside, *, ncorr=None, rng=None):
169169
'''Iteratively sample Gaussian random fields from Cls.
170170
171171
A generator that iteratively samples HEALPix maps of Gaussian random fields
172-
with the given angular power spectra ``cls`` and resolution parameter
172+
with the given angular power spectra ``gls`` and resolution parameter
173173
``nside``.
174174
175175
The optional argument ``ncorr`` can be used to artificially limit now many
176176
realised fields are correlated. This saves memory, as only `ncorr` previous
177177
fields need to be kept.
178178
179-
The ``cls`` array must contain the auto-correlation of each new field
179+
The ``gls`` array must contain the auto-correlation of each new field
180180
followed by the cross-correlations with all previous fields in reverse
181181
order::
182182
183-
cls = [cl_00,
184-
cl_11, cl_10,
185-
cl_22, cl_21, cl_20,
183+
gls = [gl_00,
184+
gl_11, gl_10,
185+
gl_22, gl_21, gl_20,
186186
...]
187187
188188
Missing entries can be set to ``None``.
@@ -193,21 +193,21 @@ def generate_gaussian(cls, nside, *, ncorr=None, rng=None):
193193
if rng is None:
194194
rng = np.random.default_rng()
195195

196-
# number of cls and number of fields
197-
ncls = len(cls)
198-
ngrf = int((2*ncls)**0.5)
196+
# number of gls and number of fields
197+
ngls = len(gls)
198+
ngrf = int((2*ngls)**0.5)
199199

200200
# number of correlated fields if not specified
201201
if ncorr is None:
202202
ncorr = ngrf - 1
203203

204204
# number of modes
205-
n = max((len(cl) for cl in cls if cl is not None), default=0)
205+
n = max((len(gl) for gl in gls if gl is not None), default=0)
206206
if n == 0:
207-
raise ValueError('all cls are empty')
207+
raise ValueError('all gls are empty')
208208

209209
# generates the covariance matrix for the iterative sampler
210-
cov = cls2cov(cls, n, ngrf, ncorr)
210+
cov = cls2cov(gls, n, ngrf, ncorr)
211211

212212
# working arrays for the iterative sampling
213213
z = np.zeros(n*(n+1)//2, dtype=np.complex128)
@@ -247,9 +247,9 @@ def generate_lognormal(gls, nside, shift=1., *, ncorr=None, rng=None):
247247
'''Iterative sample lognormal random fields from Gaussian Cls.'''
248248
for i, m in enumerate(generate_gaussian(gls, nside, ncorr=ncorr, rng=rng)):
249249
# compute the variance of the auto-correlation
250-
cl = gls[i*(i+1)//2]
251-
ell = np.arange(len(cl))
252-
var = np.sum((2*ell + 1)*cl)/(4*np.pi)
250+
gl = gls[i*(i+1)//2]
251+
ell = np.arange(len(gl))
252+
var = np.sum((2*ell + 1)*gl)/(4*np.pi)
253253

254254
# fix mean of the Gaussian random field for lognormal transformation
255255
m -= var/2

0 commit comments

Comments
 (0)