Skip to content

fix: Fix single-backend bin and empty-epoch bugs in makegp_ecorr#100

Open
Wang-weiYu wants to merge 1 commit intonanograv:mainfrom
Wang-weiYu:main
Open

fix: Fix single-backend bin and empty-epoch bugs in makegp_ecorr#100
Wang-weiYu wants to merge 1 commit intonanograv:mainfrom
Wang-weiYu:main

Conversation

@Wang-weiYu
Copy link

The PR is related to #99
This PR fixes the single-backend bin and empty-epoch bugs in makegp_ecorr.

  • the single-backend bin bugs has been mentioned in
    # TOAs that do not belong to this mask get index zero, which is ignored below.
    # This will fail if there's only one mask that covers all TOAs

    If we try to analyze the ecorr noise in the pulsar which has only one backend, the first backend will be discarded.
    Therefore, we use
    if len(np.unique(masks)) == 1:
        # for those pulsar with only one backend
        first_valid_bin = 0
    else:
        first_valid_bin = 1

and

Umats.append(np.vstack([bins == i for i in range(Add commentMore actions
                first_valid_bin, bins.max() + 1)]).T)

to make sure that we have the correct bins.

  • empty-epoch bugs
    If there is no ToAs observed at the same time and we only consider about the bins that have more than two ToAs. It will arise an error. It has been mentioned ECORR and enterprise=True #96 to modify how many ToAs we need to consider about. But, for now, we can solve it like
            uniques, counts = np.unique(bins, return_counts=True)Add commentMore actions
            epoch_masks = [bins == i for i, cnt in zip(
                uniques[first_valid_bin:],
                counts[first_valid_bin:]) if cnt > 1]

            if epoch_masks:
                U_backend = np.vstack(epoch_masks).T
            else:
                # if there is no ToAs observed at the same time
                U_backend = np.zeros((len(bins), 0))

            Umats.append(U_backend)

to make it aligned with the default setting in enterprise.

Closes #99

@meyers-academic
Copy link
Collaborator

@Wang-weiYu Thank you for adding these changes. I'm sorry it's taken a while to get to. The changes all make sense given the issue you opened. I would like to hold off on merging just for the moment -- I want to create a dummy pulsar object that produces these errors with the old code, and checks that your code fixes it. Then I'll use it as a unittest.

I will try to do this in the next week -- otherwise please feel free to try it yourself.

@Wang-weiYu
Copy link
Author

Hi @meyers-academic,

Thank you so much for looking into this and for planning to add the tests.

Yes, please go ahead and merge it after testing, considering the overall Discovery architecture and the related components.

Thank you for your time!

Best regards,
Wangwei

@meyers-academic
Copy link
Collaborator

Hi @Wang-weiYu I'm sorry, I've done the annoying thing of fixing this and pushing to main instead of accepting the pull request. I will try not to do the in the future. I did it because I was worried that if I wanted to push changes to the pull request, it would change the main branch of your fork (which could have also included a bunch of recent commits, and I wasn't sure whether that would bother you).

However, I have added a unit test that successfully found the single-backend issue, and now passes with your fix, which I implemented. If it's ok, please have a look at the main discovery branch, let me know if there are issues. If not, I will close this.

@Wang-weiYu
Copy link
Author

Hi @meyers-academic,

No worries at all — I'm glad the bug has already been fixed.

I've checked the changes, and everything looks good to me.
Please feel free to close the PR.

Thanks!

Best regards,
Wang-Wei

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The single-backend bin and empty-epoch bugs in makegp_ecorr

2 participants