Skip to content

Commit

Permalink
add save/load functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alasdair Wilson committed Jul 1, 2024
1 parent 12f1836 commit 3477e40
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ripplemapper/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,5 @@ def _load(self, file: str):
"""Load the image series from a file."""
with gzip.open(file, 'rb') as f:
image_files = pickle.load(f)

self.images = [RippleImage(image_file) for image_file in image_files]
base_path = Path(file).parent
self.images = [RippleImage(str(base_path / image_file.split("/")[-1])) for image_file in image_files] # TODO Path ojets should be accepted by RippleImage, etc.
Binary file modified ripplemapper/data/example/rimgs/1_00052_sample.rimg
Binary file not shown.
Binary file modified ripplemapper/data/example/rimgs/1_00205_sample.rimg
Binary file not shown.
Binary file modified ripplemapper/data/example/rimgs/1_00375_sample.rimg
Binary file not shown.
Binary file modified ripplemapper/data/example/rimgs/1_00443_sample.rimg
Binary file not shown.
Binary file modified ripplemapper/data/example/rimgs/image_series.rimgs
Binary file not shown.
19 changes: 18 additions & 1 deletion ripplemapper/visualisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,24 @@ def plot_image(ripple_image, include_contours: bool=True, *args, **kwargs):
include_contours : bool, optional
whether to include all the RippleContours on the plot, by default True
"""
plt.imshow(ripple_image.image, cmap='gray')
if ripple_image.image is None:
if ripple_image.contours is None:
raise ValueError("RippleImage object must have an image or contours to plot.")
warnings.warn(f"Image not loaded for image: {ripple_image.source_file} plotting contours only.")
x_max = y_max = 150
x_min = y_min = np.Inf
for contour in ripple_image.contours:
x_max = max(x_max, np.max(contour.values[1]))
x_min = min(x_min, np.min(contour.values[1]))
y_max = max(y_max, np.max(contour.values[0]))
y_min = min(y_min, np.min(contour.values[0]))
x_min, x_max, y_min, y_max = int(np.floor(x_min)), int(np.ceil(x_max)), int(np.floor(y_min)), int(np.ceil(y_max))
plt.imshow(np.zeros((y_max, x_max)), cmap='gray')
plt.xlim(x_min, x_max)
plt.ylim(y_min, y_max)
plt.gca().invert_yaxis()
else:
plt.imshow(ripple_image.image, cmap='gray')
if include_contours:
if len(ripple_image.contours) == 0:
warnings.warn(f"No contours found for image: {ripple_image.source_file} but you selected include_contours=True.")
Expand Down

0 comments on commit 3477e40

Please sign in to comment.