Skip to content

Additions to hdr module.#100

Open
IanTBlack wants to merge 3 commits into
joefutrelle:masterfrom
IanTBlack:master
Open

Additions to hdr module.#100
IanTBlack wants to merge 3 commits into
joefutrelle:masterfrom
IanTBlack:master

Conversation

@IanTBlack
Copy link
Copy Markdown

Hi Joe,

I am interested in contributing to pyifcb. In this PR I've updated some of the typing hints and added two functions to the hdr module. One function for discovering the IFCB software version and another for parsing the hdr file as a yaml. I am not familiar with older versions of .hdr files, but if the software version always exists and the .hdr files always act as yaml files, then I think the parsing function could reduced to a few lines. The eventual intention is to be able to use pyifcb in script form with the OOI Raw Data Archive and to make connections with other OOI data products.

I've included three test .hdr files in this PR. Would you mind uploading some other, older .hdr files with different software versions so that I could make sure my changes are compatible and update the PR?

Thanks,
Ian

- Updates file to conform more with PEP8.
- Adds typing hints.
- Adds non-public functions for seeking software version and parsing an hdr file as a yaml.
@joefutrelle
Copy link
Copy Markdown
Owner

Thanks for your contribution. I'll run the workflows, have copilot do an initial review, review it myself, and test against large datasets with variations in the hdr formats.

@joefutrelle joefutrelle requested a review from Copilot July 2, 2025 10:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the hdr module by refactoring the header parser with type hints, adding two helper functions for software‐version extraction and YAML‐based parsing, and supplying three sample .hdr test files covering various formats.

  • Added type annotations to parse_alt_header and parse_hdr
  • Introduced _get_software_version and _parse_hdr for YAML parsing
  • Included three .hdr test fixtures spanning old and new header conventions

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

File Description
ifcb/data/hdr.py Refactored imports, added PathLike typing, new YAML parsing and version‐extraction functions
ifcb/tests/test_files/D20231021T154635_IFCB199.hdr New sample header (IFCB199, modern keys)
ifcb/tests/test_files/D20230521T210245_IFCB174.hdr New sample header (IFCB174, modern keys)
ifcb/tests/test_files/D20190929T185847_IFCB122.hdr New sample header (IFCB122, legacy keys)
Comments suppressed due to low confidence (3)

ifcb/data/hdr.py:94

  • There are no unit tests for the newly added _get_software_version function. Consider adding tests to verify correct version extraction across different header formats.
def _get_software_version(hdr_filepath: PathLike) -> str:

ifcb/data/hdr.py:48

  • The function parse_hdr invokes cast(...) from the removed ast import. Please restore the ast import or explicitly define cast (e.g., from ast import literal_eval as cast) to prevent a NameError.
def parse_hdr(lines: list) -> dict:

ifcb/tests/test_files/D20190929T185847_IFCB122.hdr:103

  • The key TemperatureAdjust appears twice (lines 103 and 104), which can lead to one entry silently overwriting the other when parsed. Please remove the duplicate or consolidate them.
TemperatureAdjust: 0

@joefutrelle joefutrelle self-assigned this Jul 2, 2025
@joefutrelle
Copy link
Copy Markdown
Owner

Again, thanks, and I have a few questions:

  • it looks like parse_hdr and _parse_hdr are alternatives to each other, why not merge them so that a single function handles all use cases, and that your new hdr parsing code is used by the rest of the library's APIs?
  • _get_software_version parses the hdr file as well--why not have it accept the output of parse_hdr_file or _parse_hdr_file?
  • why start the function names with _? I would generally use that for private functions, not ones that would be called from outside the module.

@joefutrelle
Copy link
Copy Markdown
Owner

Also please note that there are already a variety of .hdr files here.

@IanTBlack
Copy link
Copy Markdown
Author

IanTBlack commented Jul 2, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants