-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add all .asd frames as images to img_dict in io.py
- Loading branch information
1 parent
e76cbc5
commit 038b1b3
Showing
2 changed files
with
27 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -919,45 +919,52 @@ def get_data(self) -> None: | |
else: | ||
raise | ||
else: | ||
self._check_image_size_and_add_to_dict() | ||
if suffix == ".asd": | ||
for index, frame in enumerate(self.image): | ||
self._check_image_size_and_add_to_dict(image=frame, filename=f"{self.filename}_{index}") | ||
else: | ||
self._check_image_size_and_add_to_dict(image=self.image, filename=self.filename) | ||
else: | ||
raise ValueError( | ||
f"File type {suffix} not yet supported. Please make an issue at \ | ||
https://github.com/AFM-SPM/TopoStats/issues, or email [email protected] to request support for \ | ||
this file type." | ||
) | ||
|
||
def _check_image_size_and_add_to_dict(self) -> None: | ||
def _check_image_size_and_add_to_dict(self, image: np.ndarray, filename: str) -> None: | ||
"""Check the image is above a minimum size in both dimensions. | ||
Images that do not meet the minimum size are not included for processing. | ||
Parameters | ||
---------- | ||
image: np.ndarray | ||
An array of the extracted AFM image. | ||
filename: str | ||
The name of the file | ||
""" | ||
if self.image.shape[0] < self.MINIMUM_IMAGE_SIZE or self.image.shape[1] < self.MINIMUM_IMAGE_SIZE: | ||
LOGGER.warning(f"[{self.filename}] Skipping, image too small: {self.image.shape}") | ||
if image.shape[0] < self.MINIMUM_IMAGE_SIZE or image.shape[1] < self.MINIMUM_IMAGE_SIZE: | ||
LOGGER.warning(f"[{filename}] Skipping, image too small: {image.shape}") | ||
else: | ||
self.add_to_dict() | ||
LOGGER.info(f"[{self.filename}] Image added to processing.") | ||
self.add_to_dict(image=image, filename=filename) | ||
LOGGER.info(f"[{filename}] Image added to processing.") | ||
|
||
def add_to_dict(self) -> None: | ||
def add_to_dict(self, image: np.ndarray, filename: str) -> None: | ||
"""Adds the image, image path and pixel to nanometre scaling value to the img_dic dictionary under | ||
the key filename. | ||
Parameters | ||
---------- | ||
filename: str | ||
The filename, idealy without an extension. | ||
image: np.ndarray | ||
An array of the extracted AFM image. | ||
img_path: str | ||
The path to the AFM file (with a frame number if applicable) | ||
px_2_nm: float | ||
The length of a pixel in nm. | ||
filename: str | ||
The name of the file | ||
""" | ||
self.img_dict[self.filename] = { | ||
"filename": self.filename, | ||
"img_path": self.img_path.with_name(self.filename), | ||
self.img_dict[filename] = { | ||
"filename": filename, | ||
"img_path": self.img_path.with_name(filename), | ||
"pixel_to_nm_scaling": self.pixel_to_nm_scaling, | ||
"image_original": self.image, | ||
"image_original": image, | ||
"image_flattened": None, | ||
"grain_masks": self.grain_masks, | ||
} | ||
|