Skip to content

Improper ell cuts when loading spectrum from file #119

@HTJense

Description

@HTJense

The function pspy_utils.ps_lensed_theory_to_dict loads a plaintext file and returns a dictionary containing the power spectra, but the way in which the user-requested lmax is handled doesn't work properly. Cf. the code:

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
  1. The lmax cuts are parsed as l = l[:lmax] and ps[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.
  2. If the user desires the arrays start at l = 0 instead of l = 2, then two zeros are prepended before the array, but no check is done whether this is needed.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions