Skip to content

Courtesy of Eva: Add µm support for .top, .stp files #145

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions AFMReader/stp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@


# pylint: disable=too-many-locals
# pylint: disable=too-many-statements
def load_stp( # noqa: C901 (ignore too complex)
file_path: Path | str, header_encoding: str = "latin-1"
) -> tuple[np.ndarray, float]:
Expand Down Expand Up @@ -69,14 +70,18 @@ def load_stp( # noqa: C901 (ignore too complex)
if cols_match is None:
raise ValueError(f"[{filename}] : 'cols' not found in file header.")
cols = int(cols_match.group(1))
x_real_size_match = re.search(r"X Amplitude: (\d+\.?\d*) nm", header_decoded)
x_real_size_match = re.search(r"X Amplitude: (\d+\.?\d*) (µm|nm)", header_decoded)
if x_real_size_match is None:
raise ValueError(f"[{filename}] : 'X Amplitude' not found in file header.")
x_real_size = float(x_real_size_match.group(1))
y_real_size_match = re.search(r"Y Amplitude: (\d+\.?\d*) nm", header_decoded)
x_units = x_real_size_match.group(2)
x_real_size = x_real_size * 1000 if x_units == "µm" else x_real_size
y_real_size_match = re.search(r"Y Amplitude: (\d+\.?\d*) (µm|nm)", header_decoded)
if y_real_size_match is None:
raise ValueError(f"[{filename}] : 'Y Amplitude' not found in file header.")
y_real_size = float(y_real_size_match.group(1))
y_units = y_real_size_match.group(2)
y_real_size = y_real_size * 1000 if y_units == "µm" else y_real_size
if x_real_size != y_real_size:
raise NotImplementedError(
f"[{filename}] : X scan size (nm) does not equal Y scan size (nm) ({x_real_size}, {y_real_size})"
Expand Down
9 changes: 7 additions & 2 deletions AFMReader/top.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# pylint: disable=too-many-locals
# pylint: disable=too-many-statements
# pylint: disable=too-many-branches
def load_top( # noqa: C901 (ignore too complex)
file_path: Path | str, header_encoding: str = "latin-1"
) -> tuple[np.ndarray, float]:
Expand Down Expand Up @@ -70,14 +71,18 @@ def load_top( # noqa: C901 (ignore too complex)
if cols_match is None:
raise ValueError(f"[{filename}] : 'cols' not found in file header.")
cols = int(cols_match.group(1))
x_real_size_match = re.search(r"X Amplitude: (\d+\.?\d*) nm", header_decoded)
x_real_size_match = re.search(r"X Amplitude: (\d+\.?\d*) (µm|nm)", header_decoded)
if x_real_size_match is None:
raise ValueError(f"[{filename}] : 'X Amplitude' not found in file header.")
x_real_size = float(x_real_size_match.group(1))
y_real_size_match = re.search(r"Y Amplitude: (\d+\.?\d*) nm", header_decoded)
x_units = x_real_size_match.group(2)
x_real_size = x_real_size * 1000 if x_units == "µm" else x_real_size
y_real_size_match = re.search(r"Y Amplitude: (\d+\.?\d*) (µm|nm)", header_decoded)
if y_real_size_match is None:
raise ValueError(f"[{filename}] : 'Y Amplitude' not found in file header.")
y_real_size = float(y_real_size_match.group(1))
y_units = y_real_size_match.group(2)
y_real_size = y_real_size * 1000 if y_units == "µm" else y_real_size
if x_real_size != y_real_size:
raise NotImplementedError(
f"[{filename}] : X scan size (nm) does not equal Y scan size (nm) ({x_real_size}, {y_real_size})"
Expand Down