-
Notifications
You must be signed in to change notification settings - Fork 16
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
864 hi l1b compute coincidence type and time deltas #995
864 hi l1b compute coincidence type and time deltas #995
Conversation
a7c06ec
to
87215f8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Just hoping to get some clarification on how to read those tables in the comments
imap_processing/hi/l1b/hi_l1b.py
Outdated
# | 2 | B | A | C1 | C2 | | ||
# | 3 | C1 | A | B | C2 | | ||
# Set coincidence type bitmask | ||
out_ds.coincidence_type[a_mask | tof_1_valid_mask] |= CoincidenceBitmap.A.value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think because you're using an IntEnum
you can do CoincidenceBitmap.A
instead of CoincidenceBitmap.A.value
def synthetic_trigger_id_and_tof_data(): | ||
"""Create synthetic minimum dataset for testing the | ||
coincidence_type_and_time_deltas algorithm.""" | ||
# The following coincidence type table shows possible values to consider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This table is really helpful! I should add something similar for Lo's coincidence types
tof2s = np.array(np.concatenate((HiConstants.TOF2_BAD_VALUES, [2]))) | ||
tof3s = np.array(np.concatenate((HiConstants.TOF3_BAD_VALUES, [3]))) | ||
var_names = ["trigger_id", "tof_1", "tof_2", "tof_3"] | ||
data = np.meshgrid(ids, tof1s, tof2s, tof3s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea to more easily cover the combinations!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't quite take credit... found it on SO.
Simplify C1 coincidence type mask logic Remove .value from IntEnums where not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that programmatically everything looks in order. My suggestion would be to add more docstrings, but you can take it or leave it.
imap_processing/hi/l1b/hi_l1b.py
Outdated
-out_ds.tof_1.values[b_mask & tof_1_valid_mask].astype(np.float32) | ||
* HiConstants.TOF1_TICK_PER_NS | ||
) | ||
out_ds.delta_t_ab.values[c_mask & tof_1and2_valid_mask] = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this could be split into two separate steps for clarity:
delta_t_2 = out_ds.tof_2.values[c_mask & tof_1and2_valid_mask].astype(np.float32) * HiConstants.TOF2_TICK_PER_NS
delta_t_1 = out_ds.tof_1.values[c_mask & tof_1and2_valid_mask].astype(np.float32) * HiConstants.TOF1_TICK_PER_NS
out_ds.delta_t_ab.values[c_mask & tof_1and2_valid_mask] = delta_t_2 - delta_t_1
imap_processing/hi/l1b/hi_l1b.py
Outdated
out_ds.tof_2.values[a_mask & tof_2_valid_mask].astype(np.float32) | ||
* HiConstants.TOF2_TICK_PER_NS | ||
) | ||
out_ds.delta_t_ac1.values[b_mask & tof_1and2_valid_mask] = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be split for clarity:
delta_t_2 = out_ds.tof_2.values[b_mask & tof_1and2_valid_mask] * HiConstants.TOF2_TICK_PER_NS
delta_t_1 = out_ds.tof_1.values[b_mask & tof_1and2_valid_mask] * HiConstants.TOF1_TICK_PER_NS
out_ds.delta_t_ac1.values[b_mask & tof_1and2_valid_mask] = delta_t_2 - delta_t_1
imap_processing/hi/l1b/hi_l1b.py
Outdated
) | ||
|
||
# delta_t_bc1 | ||
out_ds.delta_t_bc1.values[a_mask & tof_1_valid_mask & tof_2_valid_mask] = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here I would split it up:
delta_t_2 = out_ds.tof_2.values[a_mask & tof_1and2_valid_mask] * HiConstants.TOF2_TICK_PER_NS
delta_t_1 = out_ds.tof_1.values[a_mask & tof_1and2_valid_mask] * HiConstants.TOF1_TICK_PER_NS
out_ds.delta_t_bc1.values[a_mask & tof_1_valid_mask & tof_2_valid_mask] = delta_t_2 - delta_t_1
imap_processing/hi/l1b/hi_l1b.py
Outdated
# | 2 | B | A,B | B,C1 | C1,C2 | | ||
# | 3 | C1 | A,C1 | B,C1 | C1,C2 | | ||
# Set coincidence type bitmask | ||
out_ds.coincidence_type[a_mask | tof_1_valid_mask] |= CoincidenceBitmap.A |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me personally I would really appreciate a docstring on each bitmask. Maybe it's overkill for some people, but it helps me to immediately understand the purpose.
Example:
Set the 'A' bit in the 'coincidence_type' variable where:
- The trigger is 'A' (using
a_mask
), OR tof_1
is valid (usingtof_1_valid_mask
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My philosophy is that if you need a bunch of comments to explain your code, then the code is not written in a way that it can be clearly understood. IMO, the comments you wrote are exactly what the code says with a slightly different order. For this instance, I think the comment is redundant.
Rework some of the code to make it more readable
@laspsandoval, I took your feedback about needing more comments to mean that my code was not easily understandable. I made some minor tweaks that make it much more readable, IMO. I also added some comments and think that it should be very clear now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the walkthrough of all this. I think everything looks good!
cbb9132
into
IMAP-Science-Operations-Center:dev
Change Summary
Overview
Adds the Hi L1B algorithm for computing coincidence type and delta_t values. These fields share enough commonality in computation that I decided to implement them in a single function.
Updated Files
Closes: #864