Skip to content

Commit

Permalink
Try to fix tests (#1125)
Browse files Browse the repository at this point in the history
* Try to fix tests

* Attack some of the warnings

* Support older mpl/python
  • Loading branch information
ksunden committed Jun 21, 2023
1 parent b0d8290 commit 65f11a2
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 36 deletions.
3 changes: 2 additions & 1 deletion WrightTools/artists/_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ def grayify_cmap(cmap):
__ https://jakevdp.github.io/blog/2014/10/16/how-bad-is-your-colormap/
"""
cmap = plt.cm.get_cmap(cmap)
if not isinstance(cmap, matplotlib.colors.Colormap):
cmap = matplotlib.colormaps[cmap]
colors = cmap(np.arange(cmap.N))
# convert RGBA to perceived greyscale luminance
# cf. http://alienryderflex.com/hsp.html
Expand Down
8 changes: 4 additions & 4 deletions WrightTools/data/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def source(self):
if "source" not in self.attrs.keys():
self.attrs["source"] = "None"
value = self.attrs["source"]
return value if not value == "None" else None
return value if isinstance(value, str) and not value == "None" else None

@property
def units(self) -> tuple:
Expand Down Expand Up @@ -2029,7 +2029,7 @@ def zoom(self, factor, order=1, verbose=True):
See `scipy ndimage`__ for more info.
__ http://docs.scipy.org/doc/scipy/reference/
generated/scipy.ndimage.interpolation.zoom.html
generated/scipy.ndimage.zoom.html
Parameters
----------
Expand All @@ -2045,10 +2045,10 @@ def zoom(self, factor, order=1, verbose=True):

# axes
for axis in self._axes:
axis[:] = scipy.ndimage.interpolation.zoom(axis[:], factor, order=order)
axis[:] = scipy.ndimage.zoom(axis[:], factor, order=order)
# channels
for channel in self.channels:
channel[:] = scipy.ndimage.interpolation.zoom(channel[:], factor, order=order)
channel[:] = scipy.ndimage.zoom(channel[:], factor, order=order)
# return
if verbose:
print("data zoomed to new shape:", self.shape)
2 changes: 1 addition & 1 deletion WrightTools/kit/_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def orthogonal(*args) -> bool:
if hasattr(arg, "shape"):
args[i] = arg.shape
for s in zip(*args):
if np.product(s) != max(s):
if np.prod(s) != max(s):
return False
return True

Expand Down
6 changes: 3 additions & 3 deletions WrightTools/kit/_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def zoom2D(xi, yi, zi, xi_zoom=3.0, yi_zoom=3.0, order=3, mode="nearest", cval=0
cval : scalar (optional)
Value used for constant mode. Default is 0.0.
"""
xi = ndimage.interpolation.zoom(xi, xi_zoom, order=order, mode="nearest")
yi = ndimage.interpolation.zoom(yi, yi_zoom, order=order, mode="nearest")
zi = ndimage.interpolation.zoom(zi, (xi_zoom, yi_zoom), order=order, mode=mode, cval=cval)
xi = ndimage.zoom(xi, xi_zoom, order=order, mode="nearest")
yi = ndimage.zoom(yi, yi_zoom, order=order, mode="nearest")
zi = ndimage.zoom(zi, (xi_zoom, yi_zoom), order=order, mode=mode, cval=cval)
return xi, yi, zi


Expand Down
5 changes: 2 additions & 3 deletions WrightTools/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@

ureg.define("wavenumber = 1 / cm = cm^{-1} = wn")


# Aliases for backwards compatability
ureg.define("@alias s = s_t")
ureg.define("@alias min = m_t")
Expand Down Expand Up @@ -149,7 +148,7 @@ def get_symbol(units) -> str:
string
LaTeX formatted symbol.
"""
quantity = ureg.Quantity(1, ureg[units])
quantity = ureg.Quantity(1, ureg(units))
if quantity.check("[length]"):
return r"\lambda"
elif quantity.check("1 / [length]"):
Expand All @@ -164,7 +163,7 @@ def get_symbol(units) -> str:
return r"\mathcal{F}"
elif quantity.check("[temperature]"):
return "T"
elif ureg[units] in (ureg.deg, ureg.radian):
elif ureg(units) in (ureg.deg, ureg.radian):
return r"\omega"
else:
return None
Expand Down
21 changes: 10 additions & 11 deletions tests/artists/test_interact2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ def test_perovskite():
break
except:
pass
return wt.artists.interact2D(data, xaxis=2, yaxis=1)
wt.artists.interact2D(data, xaxis=2, yaxis=1)


def test_MoS2():
p = datasets.wt5.v1p0p1_MoS2_TrEE_movie # axes w2, w1=wm, d2
data = wt.open(p)
data.convert("eV")
data.level(0, 2, -4)
return wt.artists.interact2D(data, xaxis=0, yaxis=1, local=True)
wt.artists.interact2D(data, xaxis=0, yaxis=1, local=True)


def test_asymmetric():
Expand All @@ -37,7 +37,7 @@ def test_asymmetric():
data.create_variable("x", values=x[:, None], units="wn")
data.create_variable("y", values=y[None, :], units="wn")
data.transform("x", "y")
return wt.artists.interact2D(data, xaxis=1, yaxis=0)
wt.artists.interact2D(data, xaxis=1, yaxis=0)


def test_skewed():
Expand All @@ -46,7 +46,7 @@ def test_skewed():
data = wt.data.from_PyCMDS(p)
data.convert("wn", convert_variables=True)
data.transform("wm", "w1") # wm = w1 + 2*w2
return wt.artists.interact2D(data, xaxis=0, yaxis=1)
wt.artists.interact2D(data, xaxis=0, yaxis=1)


def test_4D():
Expand Down Expand Up @@ -82,17 +82,16 @@ def test_4D():
data.create_variable("d1", values=tau[None, None, None, :], units="ps")

data.transform("w1", "w2", "w3", "d1")
return wt.artists.interact2D(data, xaxis=0, yaxis=1, local=True)
wt.artists.interact2D(data, xaxis=0, yaxis=1, local=True)


if __name__ == "__main__":
import matplotlib.pyplot as plt

plt.close("all")
# store to variable to prevent garbage collection
t0 = test_perovskite()
t1 = test_MoS2()
t2 = test_asymmetric()
t3 = test_skewed()
t4 = test_4D()
test_perovskite()
test_MoS2()
test_asymmetric()
test_skewed()
test_4D()
plt.show()
9 changes: 4 additions & 5 deletions tests/artists/test_quick1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_perovskite():
break
except:
pass
return wt.artists.quick1D(data, axis=0, at={"w2": [1.7, "eV"], "d2": [0, "fs"]})
wt.artists.quick1D(data, axis=0, at={"w2": [1.7, "eV"], "d2": [0, "fs"]})


def test_2D():
Expand All @@ -27,14 +27,13 @@ def test_2D():
data.create_variable("w1", values=w1[:, None], units="wn", label="1")
data.create_variable("w2", values=w2[None, :], units="wn", label="2")
data.transform("w1", "w2")
return wt.artists.quick1D(data)
wt.artists.quick1D(data)


if __name__ == "__main__":
import matplotlib.pyplot as plt

plt.close("all")
# store to variable to prevent garbage collection
t0 = test_perovskite()
t1 = test_2D()
test_perovskite()
test_2D()
plt.show()
9 changes: 4 additions & 5 deletions tests/artists/test_quick2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_perovskite():
break
except:
pass
return wt.artists.quick2D(data, xaxis=0, yaxis=2, at={"w2": [1.7, "eV"]})
wt.artists.quick2D(data, xaxis=0, yaxis=2, at={"w2": [1.7, "eV"]})


def test_4D():
Expand All @@ -36,14 +36,13 @@ def test_4D():
data.create_variable("w3", values=w3[None, None, :, None], units="wn", label="3")
data.create_variable("d1", values=tau[None, None, None, :], units="ps")
data.transform("w1", "w2", "w3", "d1")
return wt.artists.quick2D(data, xaxis=0, yaxis=1)
wt.artists.quick2D(data, xaxis=0, yaxis=1)


if __name__ == "__main__":
import matplotlib.pyplot as plt

plt.close("all")
# store to variable to prevent garbage collection
t0 = test_perovskite()
t1 = test_4D()
test_perovskite()
test_4D()
plt.show()
4 changes: 1 addition & 3 deletions tests/data/from_spcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ def test_test_data_full_metadata():
p = datasets.spcm.test_data_full_metadata
data = wt.data.from_spcm(p)
assert data.size == data.attrs["SP_ADC_RE"]
if __name__ == "__main__":
return data
data.close()


Expand All @@ -33,4 +31,4 @@ def test_test_data_full_metadata():

if __name__ == "__main__":
test_test_data()
data = test_test_data_full_metadata()
test_test_data_full_metadata()

0 comments on commit 65f11a2

Please sign in to comment.