Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-39460: Bug-fix for CHARGE_SUM photodiode integration method #266

Merged
merged 4 commits into from May 31, 2023

Conversation

jchiang87
Copy link
Contributor

No description provided.

@jchiang87 jchiang87 requested a review from erykoff May 31, 2023 17:14
Copy link
Contributor

@erykoff erykoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small code change suggestions. And for the tests, I'm wondering if there's a way of adding a pathological point like what triggered this ticket to ensure that it still works with and without one of those problematic points at the rolloff?

index = np.where(current < dy/20. + np.min(current))
bg_current = np.sum(charge[index])/np.sum(dt[index])
signal = np.where(current > dy/20. + np.min(current))
imin = signal[0][0] - 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the first point is at the edge? Do we need to make sure this doesn't go below 0? (Similar for the next line at the max).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both list(range(0, imin)) and list(range( imax, len(current))) return empty lists when imin < 0 and imax > len(current), respectively, which is what we want, I think. Same appears to be true for np.arange.

signal = np.where(current > dy/20. + np.min(current))
imin = signal[0][0] - 2
imax = signal[0][-1] + 2
bg = (np.array(list(range(0, imin)) + list(range(imax, len(current)))),)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm reading this correctly, this is a tuple of an array of a list ....
This should be simpler and I think should work the same. There's no need for the 1d tuple:

bg = np.concatenate([np.arange(0, imin), np.arange(imax, len(current))])

dy = np.max(current) - np.min(current)
index = np.where(current < dy/20. + np.min(current))
bg_current = np.sum(charge[index])/np.sum(dt[index])
signal = np.where(current > dy/20. + np.min(current))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a 1d array, you can do signal, = np.where(current > dy/20. + np.min(current)) and just get the indices and below you can do signal[0] and signal[-1]. And although this is what I still do, the numpy recommendation is instead to do signal, = (current > dy/20. + np.min(current)).nonzero().

@jchiang87
Copy link
Contributor Author

@erykoff I've implemented your suggestions and added some test code for that failure mode.

@jchiang87 jchiang87 merged commit 42cc332 into main May 31, 2023
1 check passed
@jchiang87 jchiang87 deleted the tickets/DM-39460 branch May 31, 2023 22:58
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.

None yet

2 participants