def ps_lensed_theory_to_dict(filename, output_type, lmax=None, start_at_zero=False):
fields = ["TT", "TE", "TB", "ET", "BT", "EE", "EB", "BE", "BB"]
ps = {}
l, ps["TT"], ps["EE"], ps["BB"], ps["TE"] = np.loadtxt(filename, unpack=True)
ps["ET"] = ps["TE"].copy()
ps["TB"], ps["BT"], ps["EB"], ps["BE"] = np.zeros((4, len(l)))
if lmax is not None:
l = l[:lmax]
scale = l * (l + 1) / (2 * np.pi)
for f in fields:
if lmax is not None:
ps[f] = ps[f][:lmax]
if output_type == "Cl":
ps[f] /= scale
if start_at_zero:
ps[f] = np.append(np.array([0, 0]), ps[f])
if start_at_zero:
l = np.append(np.array([0, 1]), l)
return l, ps
Most other functions in pspy that take lmax as an argument will assume the user wants an array from l = 2 to lmax-1 inclusive, but this function will most likely create arrays from l=2 to lmax+1 inclusive because of the aforementioned design, and more often than not the resulting spectra will create issues when passed on to other functions that expect [2,lmax) arrays.
The function
pspy_utils.ps_lensed_theory_to_dictloads a plaintext file and returns a dictionary containing the power spectra, but the way in which the user-requestedlmaxis handled doesn't work properly. Cf. the code:l = l[:lmax]andps[f] = ps[f][:lmax], both of which work fine if the array is zero-indexed. However, no check is made to see if the arrays actually start at l = 0.Most other functions in pspy that take lmax as an argument will assume the user wants an array from l = 2 to lmax-1 inclusive, but this function will most likely create arrays from l=2 to lmax+1 inclusive because of the aforementioned design, and more often than not the resulting spectra will create issues when passed on to other functions that expect [2,lmax) arrays.