|
1 | 1 | """For decoding and loading .asd AFM file format into Python Numpy arrays.""" |
2 | 2 |
|
3 | 3 | from __future__ import annotations |
| 4 | +import errno |
| 5 | +import os |
4 | 6 | from pathlib import Path |
5 | 7 | import sys |
6 | 8 |
|
7 | | -if sys.version_info.minor < 11: |
8 | | - from typing import Any, BinaryIO |
9 | | - from typing_extensions import Self |
10 | | -else: |
11 | | - from typing import Any, BinaryIO, Self |
12 | | - |
13 | 9 |
|
14 | 10 | import numpy as np |
15 | 11 | import numpy.typing as npt |
|
32 | 28 | skip_bytes, |
33 | 29 | ) |
34 | 30 |
|
| 31 | + |
| 32 | +if sys.version_info.minor < 11: |
| 33 | + from typing import Any, BinaryIO |
| 34 | + from typing_extensions import Self |
| 35 | +else: |
| 36 | + from typing import Any, BinaryIO, Self |
| 37 | + |
| 38 | + |
35 | 39 | logger.enable(__package__) |
36 | 40 |
|
37 | 41 | # mypy: disable-error-code="assignment" |
@@ -181,7 +185,7 @@ def calculate_scaling_factor( |
181 | 185 | raise ValueError(f"channel {channel} not known for .asd file type.") |
182 | 186 |
|
183 | 187 |
|
184 | | -def load_asd(file_path: Path, channel: str): |
| 188 | +def load_asd(file_path: str | Path, channel: str): |
185 | 189 | """ |
186 | 190 | Load a .asd file. |
187 | 191 |
|
@@ -209,6 +213,11 @@ def load_asd(file_path: Path, channel: str): |
209 | 213 | """ |
210 | 214 | # Ensure the file path is a Path object |
211 | 215 | file_path = Path(file_path) |
| 216 | + filename = file_path.stem |
| 217 | + # Check the file exists and raise an error if not |
| 218 | + if not file_path.is_file(): |
| 219 | + logger.error(f"[{filename}] File not found : {file_path}") |
| 220 | + raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), file_path) |
212 | 221 | # Open the file in binary mode |
213 | 222 | with Path.open(file_path, "rb", encoding=None) as open_file: # pylint: disable=unspecified-encoding |
214 | 223 | file_version = read_file_version(open_file) |
|
0 commit comments