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

XTCE decom with CoDICE example #72

Merged
merged 7 commits into from
Aug 23, 2023
Merged

XTCE decom with CoDICE example #72

merged 7 commits into from
Aug 23, 2023

Conversation

GFMoraga
Copy link
Contributor

Change Summary

You will notice a few commits, which were organizing, formatting, and editing code. This is the Python script to generate an XTCE formatted XML file, as well as tests and decom using space-packet-parser.

Overview

Matthew and I went through and formatted the directories to match swe. Organized for simplicity and renamed for clarity.

New Files

  • make_xtce.py

    • This is the script that extracts an excel sheet and uses it to build the xtce file
  • p_cod_aut_test.xml

    • This is the xtce formatted file which is the output of make_xtce.py
  • decom.py

    • This uses the space-packet-parser to parse the data with the xtce
  • test_decom.py

    • This is a decom to test the data for ccsds headers
  • test_bin_data.py

    • This tests the data bin and will output the bin size in bytes, as well as print the data in hexagon
  • decom_python_example.py

    • This is an example of how to hard code parse

Testing

  • We tested this in a poetry environment with python 3.11

@GFMoraga GFMoraga added enhancement New feature or request Ins: CoDICE Related to the CoDICE instrument Level: L0 Level 0 processing labels Aug 22, 2023
@GFMoraga GFMoraga self-assigned this Aug 22, 2023
Copy link
Collaborator

@bourque bourque left a comment

Choose a reason for hiding this comment

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

At first glance, I think this all looks pretty good and is well on its way!

Just a few overarching 'best practices' / good habits suggestions:

  1. It is good for every function (with a few exceptions) to have docstrings that describe what the function does, and what parameters/returns it has (if any). These docstrings should go just below the function definition (see example here), instead of before or after the function.
  2. Within the function docstrings, make sure they are using the numpydocs convention, for example:
Parameters
----------

instead of

Parameters:

I believe this is actually necessary in order for Sphinx/ReadTheDocs to render properly.

  1. Though PEP8 doesn't talk about this, I think it is convention within the python community to order functions within a module in alphabetical order (e.g. decommute_packet() should go before extract_bits())

Copy link
Collaborator

@bourque bourque left a comment

Choose a reason for hiding this comment

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

Nice work here @GFMoraga! Thank you for pioneering this effort for CoDICE!

I have a few suggestions that I think should be immediately resolved (mostly using relative directory paths instead of absolute), but many of them are 'future considerations' that I think could be done in a future PR.

imap_processing/codice/L0/p_cod_aut_test.xml Outdated Show resolved Hide resolved
imap_processing/codice/L0/p_cod_aut_test.xml Show resolved Hide resolved
imap_processing/codice/L0/decom_python_example.py Outdated Show resolved Hide resolved
imap_processing/codice/decom.py Outdated Show resolved Hide resolved
imap_processing/codice/make_xtce.py Outdated Show resolved Hide resolved
imap_processing/codice/make_xtce.py Outdated Show resolved Hide resolved
imap_processing/codice/tests/test_bin_data.py Outdated Show resolved Hide resolved
imap_processing/codice/tests/test_bin_data.py Outdated Show resolved Hide resolved
imap_processing/codice/tests/test_bin_data.py Show resolved Hide resolved
imap_processing/codice/tests/test_decom.py Outdated Show resolved Hide resolved
@bourque bourque changed the title Xtce decom with codice example XTCE decom with CoDICE example Aug 23, 2023
Copy link
Contributor

@maxinelasp maxinelasp left a comment

Choose a reason for hiding this comment

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

Overall, the logic looks good! I suggested some things to rearrange the way the code is laid out, to help make this code more useful for other instruments.

imap_processing/codice/L0/decom_python_example.py Outdated Show resolved Hide resolved
imap_processing/codice/L0/p_cod_aut_test.xml Show resolved Hide resolved
imap_processing/codice/decom.py Outdated Show resolved Hide resolved
imap_processing/codice/decom.py Outdated Show resolved Hide resolved
imap_processing/codice/make_xtce.py Outdated Show resolved Hide resolved
imap_processing/codice/make_xtce.py Show resolved Hide resolved
if __name__ == "__main__":
# ET.register_namespace is important! Make sure you use the correct namespace for the xtce file you are using.This
# is the namespace for the IMAP xtce files currently.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is best practice to have the main function be really small and call out to other methods (IMO). Ideally, this would look something like:

df = parse_excel_file(filename)
header = generate_header()
integer_parameter_types = generate_integer_parameter_types()
codice_parameters = generate_codice_parameters()
tree = generate_xml_tree(df, header, integer_parameter_types, codice_parameters)
tree.write(...)

This is just an example, split out the code in methods that make sense to you and produce nice code. By splitting everything up into methods, you make it easy for me to create a make_mag_xtce.py which uses all the common tools you created. It also makes it a lot more clear what you're actually running when you run this file.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree here.

imap_processing/codice/make_xtce.py Outdated Show resolved Hide resolved
imap_processing/codice/make_xtce.py Show resolved Hide resolved
imap_processing/codice/tests/test_bin_data.py Show resolved Hide resolved
Copy link
Contributor

@tech3371 tech3371 left a comment

Choose a reason for hiding this comment

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

I want to say, this looks really promising. It seems to what we want with minor changes. Nice work! If you need any help with refactoring, let us know.

imap_processing/codice/tests/test_bin_data.py Outdated Show resolved Hide resolved
imap_processing/codice/tests/test_bin_data.py Outdated Show resolved Hide resolved
imap_processing/codice/tests/test_decom.py Outdated Show resolved Hide resolved
imap_processing/codice/make_xtce.py Outdated Show resolved Hide resolved
if __name__ == "__main__":
# ET.register_namespace is important! Make sure you use the correct namespace for the xtce file you are using.This
# is the namespace for the IMAP xtce files currently.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree here.

imap_processing/codice/make_xtce.py Outdated Show resolved Hide resolved
"""

# Create integer parameter types for all numbers between 0-32
for size in range(33): # Range goes up to 33 to include 0-32
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there way to go through each row in lengthInBits column and use that to create IntegerParameterType? That way, if there are int size greater than 32 or unique value after that, they would get created.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. I agree. In general we want this to be more generic (not hard-coded).

"""
import xml.etree.ElementTree as ET

import pandas as pd
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to add pandas, openpyxl to poetry dependency list.

imap_processing/codice/make_xtce.py Show resolved Hide resolved
imap_processing/codice/make_xtce.py Outdated Show resolved Hide resolved
@laspsandoval
Copy link
Contributor

Update pyproject.toml to include pandas (maybe others too).


import pandas as pd

sheet_name = "P_COD_AUT" # Assuming the sheet name is correct
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to have a list of sheet names here.

@GFMoraga
Copy link
Contributor Author

@maxinelasp @tech3371 @laspsandoval @bourque I love all of these comments and suggestions. I worked in a lot of them. I did NOT get to some because this is a beginning, not a final version. I added some new files and took away the test_decom because it was not useful.
I plan to reopen a new PR to add more classes, move things around and update code for a broader use of instruments.

@GFMoraga GFMoraga requested review from maxinelasp and bourque August 23, 2023 21:20
Copy link
Contributor

@maxinelasp maxinelasp left a comment

Choose a reason for hiding this comment

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

This looks good for a first pass! Make sure you comment on your issue or create a new issue with any follow ups that you didn't finish from this code review, so we can track that.

@GFMoraga GFMoraga dismissed bourque’s stale review August 23, 2023 21:28

You already reviewed it

@GFMoraga
Copy link
Contributor Author

pre-commit.ci autofix

Copy link
Collaborator

@bourque bourque left a comment

Choose a reason for hiding this comment

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

I agree with Maxine -- nice work, and let's keep track of what improvements we can make.

A few off the top of my head:

  1. Making the tests more in the style of unit tests, and maybe adding more of them if there are more areas we can test
  2. Moving docstrings around to be compliant with PEP257/numpydocs
  3. Adding said documentation to the imap_processing docs (as well as any other outward-facing docs we want to add)
  4. Utilizing classes, config files, or argument parsing to abstract out parameters from the code
  5. Make the code more generalized, generally speaking

@GFMoraga GFMoraga merged commit 208e554 into IMAP-Science-Operations-Center:dev Aug 23, 2023
@greglucas
Copy link
Collaborator

Nice work, @GFMoraga 🎉

Just an FYI that we shouldn't merge code unless all of the checks are green (unless you leave an explicit note in the PR saying "test X is failing and that is a known failure due to Y" or something like that). This now causes failures for everyone working on dev, so don't hesitate to reach out if you need help fixing linting problems. A more minor thing is that there are now a bunch of commit messages saying "fixed formatting" which aren't super helpful, so it'd be nice to squash merge if you have a bunch of unnecessary commits https://github.com/IMAP-Science-Operations-Center/imap_processing/commits/dev Let me know if any of this doesn't make sense and I'm happy to help out too!

Great work on your first PR, these are minor issues I'm mentioning that can be addressed in follow-ups.

laspsandoval pushed a commit to laspsandoval/imap_processing that referenced this pull request Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Ins: CoDICE Related to the CoDICE instrument Level: L0 Level 0 processing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants