Skip to content

Commit edd8fd6

Browse files
authored
Merge pull request #18 from fjprichard/dev
Update SpatialData.py
2 parents e7c337d + c449bd1 commit edd8fd6

1 file changed

Lines changed: 12 additions & 22 deletions

File tree

afbf/Classes/SpatialData.py

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def DefineNonUniformLocations(self, xy):
207207
self.N = amax(self.xy, axis=None)
208208
self.grid = False
209209
else:
210-
print("DefineNonUniform...: provide xy as an ndarray (M, 2).")
210+
raise("DefineNonUniform...: provide xy as an ndarray (M, 2).")
211211

212212
def ApplyAffineTransform(self, A):
213213
r"""Apply an affine transform A to coordinates.
@@ -249,7 +249,7 @@ def ApplyAffineTransform(self, A):
249249
self.xy = matmul(self.xy, A)
250250
self.N = amax(self.xy, axis=None)
251251
else:
252-
print("ApplyAffine...: provide A as ndarray of size (2, 2).")
252+
raise("ApplyAffine...: provide A as ndarray of size (2, 2).")
253253

254254
def ProjectOnAxis(self, u, v):
255255
r"""Project coordinates on an axis oriented in (u, v).
@@ -331,8 +331,7 @@ def __init__(self, coord=None, name="undefined"):
331331
self.name = "Image"
332332
self.values = zeros((coord.xy.shape[0], 1))
333333
else:
334-
print("sdata.__init__: provide coord as coordinates.")
335-
return None
334+
raise("sdata.__init__: provide coord as coordinates.")
336335
else:
337336
self.coord = None
338337
self.values = None
@@ -377,7 +376,7 @@ def Display(self, nfig=1):
377376
plt.colorbar(v, cax=cax)
378377
plt.show()
379378
else:
380-
print("SpatialData.Display: not available on non-uniform sites.")
379+
raise("SpatialData.Display: not available on non-uniform sites.")
381380

382381
def ImportImage(self, filename):
383382
"""Import an image.
@@ -417,8 +416,7 @@ def CreateImage(self, M):
417416
self.coord.Ny = M[0]
418417
self.coord.grid = True
419418
else:
420-
print("CreateImage: size of image should be an array of size 2.")
421-
return 0
419+
raise("CreateImage: size of image should be an array of size 2.")
422420

423421
def ComputeIncrements(self, hx, hy, order=0):
424422
r"""Compute increments of an image.
@@ -449,14 +447,12 @@ def ComputeIncrements(self, hx, hy, order=0):
449447
hy = int(hy)
450448

451449
if not self.coord.grid:
452-
print("sdata.ComputeIncrements: only applies to an image.")
453-
return 0
450+
raise("sdata.ComputeIncrements: only applies to an image.")
454451

455452
N = self.coord.N
456453

457454
if (abs(hx) >= self.M[1]) or (abs(hy) >= self.M[0]):
458-
print("ComputeIncrements: lags are too large for image size.")
459-
return 0
455+
raise("ComputeIncrements: lags are too large for image size.")
460456

461457
valincre = reshape(self.values, self.M)
462458

@@ -519,8 +515,7 @@ def ComputeLaplacian(self, scale=1):
519515
:rtype: sdata
520516
"""
521517
if not self.coord.grid:
522-
print("data.ComputeLaplacian: only applies to an image.")
523-
return 0
518+
raise("data.ComputeLaplacian: only applies to an image.")
524519

525520
# Second-order discrete derivative with respect to x and y variables.
526521
dx2 = self.ComputeIncrements(scale, 0, 1)
@@ -539,7 +534,6 @@ def ComputeLaplacian(self, scale=1):
539534
dx2.values.reshape(Mdx2)[0:my, 0:mx] +
540535
dy2.values.reshape(Mdy2)[0:my, 0:mx]
541536
)
542-
543537
return laplacian
544538

545539
def ComputeImageSign(self):
@@ -550,8 +544,7 @@ def ComputeImageSign(self):
550544
:rtype: sdata
551545
"""
552546
if not self.coord.grid:
553-
print("data.ComputeImageSign: only applies to an image.")
554-
return 0
547+
raise("data.ComputeImageSign: only applies to an image.")
555548

556549
simage = sdata()
557550
simage.CreateImage(self.M)
@@ -578,12 +571,10 @@ def ComputeQuadraticVariations(self, lags, order=0):
578571
This method only applies to an image.
579572
"""
580573
if not self.coord.grid:
581-
print("ComputeQuadraticVariations: only applies to an image.")
582-
return 0
574+
raise("ComputeQuadraticVariations: only applies to an image.")
583575

584576
if not isinstance(lags, coordinates):
585-
print("ComputeQuadraticVariations: provide lags as coordinates.")
586-
return None
577+
raise("ComputeQuadraticVariations: provide lags as coordinates.")
587578

588579
qvar = sdata(lags)
589580
qvar.name = "Quadratic variations."
@@ -615,8 +606,7 @@ def ComputeEmpiricalSemiVariogram(self, lags):
615606
616607
"""
617608
if not self.coord.grid:
618-
print("ComputeEmpiricalSemiVariogram: only applies to an image.")
619-
return 0
609+
raise("ComputeEmpiricalSemiVariogram: only applies to an image.")
620610

621611
# Compute quadratic variations
622612
evario = self.ComputeQuadraticVariations(lags)

0 commit comments

Comments
 (0)