simonsobs / simonsobs/pspy

Improper ell cuts when loading spectrum from file

Open
#119 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10
Forks
8
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at pspy_utils.ps_lensed_theory_to_dict and compare its lmax and array-start conventions with the other pspy functions that accept lmax. Trace inputs beginning at l=0 or l=2, including start_at_zero, and verify that the returned multipoles and spectra consistently cover the requested range without unintended prepending or shifting.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.