Skip to content

Commit

Permalink
Update SpatialData.py
Browse files Browse the repository at this point in the history
add i/o utilities
  • Loading branch information
fjprichard authored Apr 3, 2024
1 parent 0b3fb47 commit c6aa0df
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion afbf/Classes/SpatialData.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from afbf.utilities import amin, amax, mean, matmul, floor, linspace, sign
from afbf.utilities import power, plt, sqrt
from afbf.utilities import make_axes_locatable, ndarray
from afbf.utilities import imread
from afbf.utilities import imread, pickle


class coordinates:
Expand Down Expand Up @@ -418,6 +418,18 @@ def CreateImage(self, M):
else:
raise("CreateImage: size of image should be an array of size 2.")

def Save(self, filename):
"""Save an image in a file
:param str filename: File name (without extension).
"""

if self.coord.grid:
with open(filename + ".pickle", "wb") as f:
pickle.dump([self.M, self.values], f)
else:
print("sdata.Save: only available for images.")

def ComputeIncrements(self, hx, hy, order=0):
r"""Compute increments of an image.
Expand Down Expand Up @@ -616,3 +628,20 @@ def ComputeEmpiricalSemiVariogram(self, lags):
evario.values[:, 0] = 0.5 * evario.values[:, 0]

return evario


def LoadSdata(filename):
"""Load an image from a file.
:param str filename: File name (without extension).
:returns: The image.
:rtype: sdata
"""
with open(filename + ".pickle", "rb") as f:
Z = pickle.load(f)
image = sdata()
image.CreateImage(Z[0])
image.values = Z[1]

return(image)

0 comments on commit c6aa0df

Please sign in to comment.