Skip to content

Commit deecfab

Browse files
authored
Updates to use Pathlib rather than str or os.path (#27)
* Updates to use Pathlib rather than str or os.path * More Updates for Pathlib
1 parent 8c94710 commit deecfab

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

hermes_spani/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Licensed under Apache License v2 - see LICENSE.rst
2-
import os.path
2+
from pathlib import Path
33

44
from hermes_core import log
55
from hermes_spani.io.file_tools import read_file
@@ -19,7 +19,7 @@
1919
INST_TO_SHORTNAME = {INST_NAME: INST_SHORTNAME}
2020
INST_TO_TARGETNAME = {INST_NAME: INST_TARGETNAME}
2121

22-
_package_directory = os.path.dirname(os.path.abspath(__file__))
23-
_data_directory = os.path.abspath(os.path.join(_package_directory, "data"))
22+
_package_directory = Path(__file__).parent
23+
_data_directory = _package_directory / "data"
2424

2525
log.info(f"hermes_spani version: {__version__}")

hermes_spani/calibration/calibration.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44

55
import random
6-
import os.path
76
from pathlib import Path
87

98
import ccsdspy
@@ -31,13 +30,14 @@ def process_file(data_filename: Path) -> list:
3130
3231
Parameters
3332
----------
34-
data_filename: str
35-
Fully specificied filename of an input file
33+
data_filename: `pathlib.Path`
34+
Fully specificied filename of an input file.
35+
The file contents: Traditional binary packets in CCSDS format
3636
3737
Returns
3838
-------
39-
output_filenames: list
40-
Fully specificied filenames for the output files.
39+
output_filenames: `list[pathlib.Path]`
40+
Fully specificied filenames for the output CDF files.
4141
"""
4242
log.info(f"Processing file {data_filename}.")
4343
output_files = []
@@ -58,12 +58,12 @@ def calibrate_file(data_filename: Path) -> Path:
5858
5959
Parameters
6060
----------
61-
data_filename: Path
61+
data_filename: `pathlib.Path`
6262
Fully specificied filename of the input data file.
6363
6464
Returns
6565
-------
66-
output_filename: Path
66+
output_filename: `pathlib.Path`
6767
Fully specificied filename of the output file.
6868
6969
Examples
@@ -136,7 +136,7 @@ def parse_l0_sci_packets(data_filename: Path) -> dict:
136136
137137
Parameters
138138
----------
139-
data_filename: str
139+
data_filename: `pathlib.Path`
140140
Fully specificied filename
141141
142142
Returns
@@ -151,11 +151,11 @@ def parse_l0_sci_packets(data_filename: Path) -> dict:
151151
>>> data = calib.parse_spani_sci_packets(data_filename) # doctest: +SKIP
152152
"""
153153
log.info(f"Parsing packets from file:{data_filename}.")
154-
data = {}
155-
# pkt = ccsdspy.FixedLength.from_file(
156-
# os.path.join(hermes_spani._data_directory, "SPANI_sci_packet_def.csv")
157-
# )
158-
# data = pkt.load(data_filename)
154+
155+
pkt = ccsdspy.FixedLength.from_file(
156+
Path(hermes_spani._data_directory) / "SPANI_sci_packet_def.csv"
157+
)
158+
data = pkt.load(data_filename)
159159
return data
160160

161161

@@ -167,12 +167,12 @@ def l0_sci_data_to_cdf(data: dict, original_filename: Path) -> Path:
167167
----------
168168
data: dict
169169
A dictionary of arrays which includes the ccsds header fields
170-
original_filename: Path
170+
original_filename: `pathlib.Path`
171171
The Path to the originating file.
172172
173173
Returns
174174
-------
175-
output_filename: Path
175+
output_filename: `pathlib.Path`
176176
Fully specificied filename of cdf file
177177
178178
Examples
@@ -207,13 +207,13 @@ def get_calibration_file(data_filename: Path, time=None) -> Path:
207207
208208
Parameters
209209
----------
210-
data_filename: str
210+
data_filename: `pathlib.Path`
211211
Fully specificied filename of the non-calibrated file (data level < 2)
212212
time: ~astropy.time.Time
213213
214214
Returns
215215
-------
216-
calib_filename: str
216+
calib_filename: `pathlib.Path`
217217
Fully specificied filename for the appropriate calibration file.
218218
219219
Examples
@@ -228,12 +228,12 @@ def read_calibration_file(calib_filename: Path):
228228
229229
Parameters
230230
----------
231-
calib_filename: str
231+
calib_filename: `pathlib.Path`
232232
Fully specificied filename of the non-calibrated file (data level < 2)
233233
234234
Returns
235235
-------
236-
output_filename: str
236+
output_filename: `pathlib.Path`
237237
Fully specificied filename of the appropriate calibration file.
238238
239239
Examples

hermes_spani/io/file_tools.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
This module provides a generic file reader.
33
"""
44

5+
from pathlib import Path
6+
57
__all__ = ["read_file"]
68

79

8-
def read_file(data_filename):
10+
def read_file(data_filename: Path):
911
"""
1012
Read a file.
1113
1214
Parameters
1315
----------
14-
data_filename: str
16+
data_filename: `pathlib.Path`
1517
A file to read.
1618
1719
Returns

hermes_spani/tests/test_calibration.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import pytest
2-
import os.path
32
from pathlib import Path
43

54
import hermes_spani.calibration as calib

hermes_spani/tests/test_file_tools.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from pathlib import Path
12
from hermes_spani.io.file_tools import read_file
23

34

45
def test_read_file():
5-
assert read_file("test_file.cdf") is None
6+
assert read_file(Path("test_file.cdf")) is None

0 commit comments

Comments
 (0)