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-43514: Fix bug in APDB bit flag unpacking #201

Merged
merged 1 commit into from Mar 26, 2024
Merged

Conversation

parejkoj
Copy link
Contributor

No description provided.

Copy link
Contributor

@mrawls mrawls left a comment

Choose a reason for hiding this comment

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

As best I can tell this fixes the bug and passes the tests, thank you, all my comments are for clarity and not functionality.

for bit_idx, (bit_name, dtypes) in enumerate(bit_names_types):
masked_bits = np.bitwise_and(input_flag_values, 2**bit_idx)
output_flags[bit_name] = masked_bits
for name in self.output_flag_columns[flag_name]:
Copy link
Contributor

Choose a reason for hiding this comment

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

You're basically iterating over column names, right? This might be clearer if the iterable were, accordingly, columnName, here and in the list comp above, as it is in the flagExists method below

Of course, camelCase vs snake_case is rearing its head, maybe it should be column_name throughout...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They're the name of the thing in the dictionary, so it's just name. It's generally better to keep iterator variables short.

And yeah, Chris was unconsistent with camel vs. snakes. 🤷

bit_names_types = self.output_flag_columns[flag_name]
output_flags = np.zeros(len(input_flag_values), dtype=bit_names_types)
output_flags = np.zeros(len(input_flag_values),
dtype=[(name, bool) for name in self.output_flag_columns[flag_name]])
Copy link
Contributor

Choose a reason for hiding this comment

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

I figured out what this does after falling down a dtype rabbit hole, but, possibly silly question, aren't they all required (by virtue of being flags) to just be bool? Is there a reason we bend over backwards to assign the dtypes one at a time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have no idea why Chris originally made this a dict of tuples of (name, bool), because they're all booleans because this is a bit field. That's why I changed that part of it.

I put in a dtype for the numpy array, so that it is a structured array with column names, each one a bool.

python/lsst/ap/association/transformDiaSourceCatalog.py Outdated Show resolved Hide resolved
output_flags[bit_name] = masked_bits
for name in self.output_flag_columns[flag_name]:
masked_bits = np.bitwise_and(input_flag_values,
2**self.output_flag_columns[flag_name][name])
Copy link
Contributor

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 clearer if you defined bit_idx = self.output_flag_columns[flag_name][name] first and then set masked_bits using bit_idx, but I don't insist on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not bit_idx, though, it's the bit. It's not an index.

* We explicitly number the bits, so enumerating them gives the wrong
answer if bits are removed from the map.
* Change test flag map to trigger bug.
* Fix explicit numeric tests, given new flag map.
@parejkoj
Copy link
Contributor Author

I tried to cleanup some of the docstrings to help clarify unpack.

@parejkoj parejkoj merged commit 0542d4b into main Mar 26, 2024
2 checks passed
@parejkoj parejkoj deleted the tickets/DM-43514 branch March 26, 2024 22:31
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