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

Updates to use Pathlib rather than str or os.path #22

Merged
merged 5 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions hermes_merit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Licensed under Apache License v2 - see LICENSE.rst
import os.path
from pathlib import Path

from hermes_core import log
from hermes_merit.io.file_tools import read_file
Expand All @@ -19,7 +19,7 @@
INST_TO_SHORTNAME = {INST_NAME: INST_SHORTNAME}
INST_TO_TARGETNAME = {INST_NAME: INST_TARGETNAME}

_package_directory = os.path.dirname(os.path.abspath(__file__))
_data_directory = os.path.abspath(os.path.join(_package_directory, "data"))
_package_directory = Path(__file__).parent
_data_directory = _package_directory / "data"

log.info(f"hermes_merit version: {__version__}")
30 changes: 15 additions & 15 deletions hermes_merit/calibration/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""

import random
import os.path
from pathlib import Path

import ccsdspy
Expand Down Expand Up @@ -31,13 +30,14 @@ def process_file(data_filename: Path) -> list:

Parameters
----------
data_filename: str
Fully specificied filename of an input file
data_filename: `pathlib.Path`
Fully specificied filename of an input file.
The file contents: Traditional binary packets in CCSDS format

Returns
-------
output_filenames: list
Fully specificied filenames for the output files.
output_filenames: `list[pathlib.Path]`
Fully specificied filenames for the output CDF files.
"""
log.info(f"Processing file {data_filename}.")
output_files = []
Expand All @@ -58,12 +58,12 @@ def calibrate_file(data_filename: Path) -> Path:

Parameters
----------
data_filename: Path
data_filename: `pathlib.Path`
Fully specificied filename of the input data file.

Returns
-------
output_filename: Path
output_filename: `pathlib.Path`
Fully specificied filename of the output file.

Examples
Expand Down Expand Up @@ -136,7 +136,7 @@ def parse_l0_sci_packets(data_filename: Path) -> dict:

Parameters
----------
data_filename: str
data_filename: `pathlib.Path`
Fully specificied filename

Returns
Expand All @@ -153,7 +153,7 @@ def parse_l0_sci_packets(data_filename: Path) -> dict:
log.info(f"Parsing packets from file:{data_filename}.")

pkt = ccsdspy.FixedLength.from_file(
os.path.join(hermes_merit._data_directory, "MERIT_sci_packet_def.csv")
Path(hermes_merit._data_directory) / "MERIT_sci_packet_def.csv"
)
data = pkt.load(data_filename)
return data
Expand All @@ -167,12 +167,12 @@ def l0_sci_data_to_cdf(data: dict, original_filename: Path) -> Path:
----------
data: dict
A dictionary of arrays which includes the ccsds header fields
original_filename: Path
original_filename: `pathlib.Path`
The Path to the originating file.

Returns
-------
output_filename: Path
output_filename: `pathlib.Path`
Fully specificied filename of cdf file

Examples
Expand Down Expand Up @@ -207,13 +207,13 @@ def get_calibration_file(data_filename: Path, time=None) -> Path:

Parameters
----------
data_filename: str
data_filename: `pathlib.Path`
Fully specificied filename of the non-calibrated file (data level < 2)
time: ~astropy.time.Time

Returns
-------
calib_filename: str
calib_filename: `pathlib.Path`
Fully specificied filename for the appropriate calibration file.

Examples
Expand All @@ -228,12 +228,12 @@ def read_calibration_file(calib_filename: Path):

Parameters
----------
calib_filename: str
calib_filename: `pathlib.Path`
Fully specificied filename of the non-calibrated file (data level < 2)

Returns
-------
output_filename: str
output_filename: `pathlib.Path`
Fully specificied filename of the appropriate calibration file.

Examples
Expand Down
6 changes: 4 additions & 2 deletions hermes_merit/io/file_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
This module provides a generic file reader.
"""

from pathlib import Path

__all__ = ["read_file"]


def read_file(data_filename):
def read_file(data_filename: Path):
"""
Read a file.

Parameters
----------
data_filename: str
data_filename: `pathlib.Path`
A file to read.

Returns
Expand Down
1 change: 0 additions & 1 deletion hermes_merit/tests/test_calibration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
import os.path
from pathlib import Path

import hermes_merit.calibration as calib
Expand Down
3 changes: 2 additions & 1 deletion hermes_merit/tests/test_file_tools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path
from hermes_merit.io.file_tools import read_file


def test_read_file():
assert read_file("test_file.cdf") is None
assert read_file(Path("test_file.cdf")) is None
Loading