From d404e618d19938fce78236040c5e77f578e99cdf Mon Sep 17 00:00:00 2001 From: Andrew Robbertz <24920994+Alrobbertz@users.noreply.github.com> Date: Tue, 28 May 2024 20:22:00 +0000 Subject: [PATCH 1/5] Updates to use Pathlib rather than str or os.path --- hermes_merit/calibration/calibration.py | 34 ++++++++++++------------- hermes_merit/io/file_tools.py | 2 +- hermes_merit/tests/test_calibration.py | 1 - hermes_merit/tests/test_file_tools.py | 3 ++- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/hermes_merit/calibration/calibration.py b/hermes_merit/calibration/calibration.py index 99d8e8a..19b1b11 100644 --- a/hermes_merit/calibration/calibration.py +++ b/hermes_merit/calibration/calibration.py @@ -3,7 +3,6 @@ """ import random -import os.path from pathlib import Path import ccsdspy @@ -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 = [] @@ -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 @@ -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 @@ -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 @@ -167,12 +167,13 @@ 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. - + destination_dir: `pathlib.Path` + The directory where the output file will be written. Returns ------- - output_filename: Path + output_filename: `pathlib.Path` Fully specificied filename of cdf file Examples @@ -204,16 +205,15 @@ def l0_sci_data_to_cdf(data: dict, original_filename: Path) -> Path: def get_calibration_file(data_filename: Path, time=None) -> Path: """ Given a time, return the appropriate calibration file. - 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 @@ -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 diff --git a/hermes_merit/io/file_tools.py b/hermes_merit/io/file_tools.py index 3f2f943..2ca9314 100644 --- a/hermes_merit/io/file_tools.py +++ b/hermes_merit/io/file_tools.py @@ -11,7 +11,7 @@ def read_file(data_filename): Parameters ---------- - data_filename: str + data_filename: `pathlib.Path` A file to read. Returns diff --git a/hermes_merit/tests/test_calibration.py b/hermes_merit/tests/test_calibration.py index d7660fc..554b1f9 100644 --- a/hermes_merit/tests/test_calibration.py +++ b/hermes_merit/tests/test_calibration.py @@ -1,5 +1,4 @@ import pytest -import os.path from pathlib import Path import hermes_merit.calibration as calib diff --git a/hermes_merit/tests/test_file_tools.py b/hermes_merit/tests/test_file_tools.py index 3b146e4..cc01859 100644 --- a/hermes_merit/tests/test_file_tools.py +++ b/hermes_merit/tests/test_file_tools.py @@ -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 From a371c2b78bc4531065401055dd41693a011989a9 Mon Sep 17 00:00:00 2001 From: Andrew Robbertz <24920994+Alrobbertz@users.noreply.github.com> Date: Tue, 28 May 2024 20:34:40 +0000 Subject: [PATCH 2/5] Updates to use Pathlib rather than str or os.path --- hermes_merit/calibration/calibration.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hermes_merit/calibration/calibration.py b/hermes_merit/calibration/calibration.py index 19b1b11..22fb2e9 100644 --- a/hermes_merit/calibration/calibration.py +++ b/hermes_merit/calibration/calibration.py @@ -167,10 +167,9 @@ 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: `pathlib.Path` + original_filename: `pathlib.Path` The Path to the originating file. - destination_dir: `pathlib.Path` - The directory where the output file will be written. + Returns ------- output_filename: `pathlib.Path` @@ -205,6 +204,7 @@ def l0_sci_data_to_cdf(data: dict, original_filename: Path) -> Path: def get_calibration_file(data_filename: Path, time=None) -> Path: """ Given a time, return the appropriate calibration file. + Parameters ---------- data_filename: `pathlib.Path` From 28796c1b5850440c496e4727deea344379bf3c18 Mon Sep 17 00:00:00 2001 From: Andrew Robbertz <24920994+Alrobbertz@users.noreply.github.com> Date: Tue, 28 May 2024 20:35:07 +0000 Subject: [PATCH 3/5] Updates to use Pathlib rather than str or os.path --- hermes_merit/calibration/calibration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hermes_merit/calibration/calibration.py b/hermes_merit/calibration/calibration.py index 22fb2e9..e9e1057 100644 --- a/hermes_merit/calibration/calibration.py +++ b/hermes_merit/calibration/calibration.py @@ -204,7 +204,7 @@ def l0_sci_data_to_cdf(data: dict, original_filename: Path) -> Path: def get_calibration_file(data_filename: Path, time=None) -> Path: """ Given a time, return the appropriate calibration file. - + Parameters ---------- data_filename: `pathlib.Path` From 16c588faaf1266b1217c7fffb1cbff1cfb7693be Mon Sep 17 00:00:00 2001 From: Andrew Robbertz <24920994+Alrobbertz@users.noreply.github.com> Date: Tue, 28 May 2024 20:38:26 +0000 Subject: [PATCH 4/5] Updates to use Pathlib rather than str or os.path --- hermes_merit/io/file_tools.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hermes_merit/io/file_tools.py b/hermes_merit/io/file_tools.py index 2ca9314..525235d 100644 --- a/hermes_merit/io/file_tools.py +++ b/hermes_merit/io/file_tools.py @@ -2,10 +2,12 @@ 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. From b41a70e1833fba22dd0a88ae3ffb97b4f4d88579 Mon Sep 17 00:00:00 2001 From: Andrew Robbertz <24920994+Alrobbertz@users.noreply.github.com> Date: Tue, 4 Jun 2024 18:13:20 +0000 Subject: [PATCH 5/5] More Updates for Pathlib --- hermes_merit/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hermes_merit/__init__.py b/hermes_merit/__init__.py index 50c39cf..553cf83 100644 --- a/hermes_merit/__init__.py +++ b/hermes_merit/__init__.py @@ -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 @@ -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__}")