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

HIT L0 - data decompression #1169

Merged

Conversation

vmartinez-cu
Copy link
Contributor

@vmartinez-cu vmartinez-cu commented Nov 20, 2024

This PR adds a function to decom_hit.py to decompress rates data from 16-bit integers to 32-bit integers

Updated Files

  • decom_hit.py
    • new function for decompressing rates data
    • consolidated functions that support finding valid indices for science frames
  • constants.py
    • added constants needed for decompressing rates
      -test_decom_hit.py
    • add test for decompression function

Closes issue #1055

@vmartinez-cu vmartinez-cu requested review from sdhoyt, a team, laspsandoval and maxinelasp and removed request for a team November 20, 2024 20:56
@vmartinez-cu vmartinez-cu self-assigned this Nov 20, 2024
@vmartinez-cu vmartinez-cu added Ins: HIT Related to the HIT instrument Level: L0 Level 0 processing labels Nov 20, 2024
@vmartinez-cu vmartinez-cu added this to the Nov 2024 milestone Nov 20, 2024
Copy link
Contributor

@laspsandoval laspsandoval left a comment

Choose a reason for hiding this comment

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

Nicely done. I have a couple of comments.

power = packed >> MANTISSA_BITS

# Decompress the data depending on the value of the exponent
if power > 1:
Copy link
Contributor

Choose a reason for hiding this comment

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

Add comment here to explain what you are doing. You might consider breaking it down into different steps for clarity.

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 just took this code from the algorithm doc where it was written in C and translated it to python. I'm not super familiar with bit shifting, but it seems to be working as expected in my tests. I broke down this section into smaller components for readability. Let me know if this breakdown and the additional comments help.


# Packed is the compressed integer
# Right bit shift to get the exponent
power = packed >> MANTISSA_BITS
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on this, it looks power will only be greater than 1 if packed is >=8192. From the algorithm if the power is less than 1 then the decompressed number = the compressed number. So that makes sense with what you're seeing in the sample data, despite what the algorithm document seems to say

@@ -177,6 +179,10 @@ def parse_count_rates(sci_dataset: xr.Dataset) -> None:
low_gain = data[1::2] # Items at odd indices 1, 3, 5, etc.
parsed_data[i] = [high_gain, low_gain]

# Decompress data where needed
if all(x not in field for x in ["hdr", "spare", "pha"]):
parsed_data = np.vectorize(decompress_rates_16_to_32)(parsed_data)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice use of vectorize!

Add more comments that explain how the decompression algorithm works.
…or loop for the test values and expected values
…nteger. It was added to fix a mypy issue, but now the type is initialized earlier in the function
@vmartinez-cu vmartinez-cu merged commit c5bfa68 into IMAP-Science-Operations-Center:dev Nov 25, 2024
17 checks passed
@vmartinez-cu vmartinez-cu deleted the hit-decompression branch November 25, 2024 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ins: HIT Related to the HIT instrument Level: L0 Level 0 processing
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants