Skip to content

Commit

Permalink
reformatted with 'black'
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenioLR committed Feb 25, 2024
1 parent 0396110 commit 2f089f7
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/seaborn_image/_colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"sunset": Sunset_7_r,
}


# Extra color maps for various purposes like showing RGB channels of an image
_CMAP_EXTRA = {
"R": mpl.colors.LinearSegmentedColormap.from_list("R", ["#000000", "#FF0000"]),
Expand All @@ -69,4 +69,4 @@
"C": mpl.colors.LinearSegmentedColormap.from_list("C", ["#00FFFF", "#FFFFFF"]),
"M": mpl.colors.LinearSegmentedColormap.from_list("M", ["#FF00FF", "#FFFFFF"]),
"Y": mpl.colors.LinearSegmentedColormap.from_list("Y", ["#FFFF00", "#FFFFFF"]),
}
}
5 changes: 2 additions & 3 deletions src/seaborn_image/_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,17 @@ def set_image(cmap="deep", origin="upper", interpolation="nearest", despine=Fals
"""

# Load colormap from palletable
# Load colormap from palletable
if isinstance(cmap, str) and cmap in _CMAP_QUAL.keys():
cmap_qual_mpl = _CMAP_QUAL.get(cmap).mpl_colormap
if cmap not in mpl.colormaps.keys():
mpl.colormaps.register(name=cmap, cmap=cmap_qual_mpl)

# Load extra colormap
if isinstance(cmap, str) and cmap in _CMAP_EXTRA.keys():
cmap_channel_mpl = _CMAP_EXTRA.get(cmap)
if cmap not in mpl.colormaps.keys():
mpl.colormaps.register(name=cmap, cmap=cmap_channel_mpl)


# change the axes spines
# "not" is required because of the despine parameter name
Expand Down
16 changes: 8 additions & 8 deletions src/seaborn_image/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(
cbar_ticks=None,
showticks=False,
despine=None,
extent=None
extent=None,
):

self.data = data
Expand Down Expand Up @@ -110,7 +110,7 @@ def plot(self):

if isinstance(self.cmap, str) and self.cmap in _CMAP_QUAL.keys():
self.cmap = _CMAP_QUAL.get(self.cmap).mpl_colormap

if isinstance(self.cmap, str) and self.cmap in _CMAP_EXTRA.keys():
self.cmap = _CMAP_EXTRA.get(self.cmap)

Expand All @@ -123,13 +123,13 @@ def plot(self):
self.vmin = np.nanpercentile(self.data, self.perc[0])
if self.vmax is None:
# remember that vmax was None and now set to new value
max_robust = True
max_robust = True
self.vmax = np.nanpercentile(self.data, self.perc[1])
if self.diverging:

if self.diverging:
# Force vmin to have the same absolute value as vmax so that 0 is in the middle.

if self.vmaxabs is None:
if self.vmaxabs is None:
if self.vmin is None or self.vmax is None:
vmaxabs = np.abs(self.data).max()
else:
Expand All @@ -138,7 +138,7 @@ def plot(self):
vmaxabs = self.vmaxabs

self.vmin = -vmaxabs
self.vmax = vmaxabs
self.vmax = vmaxabs

if self.norm == "cbar_log":
self.norm = colors.LogNorm(vmin=self.vmin, vmax=self.vmax)
Expand All @@ -153,7 +153,7 @@ def plot(self):
alpha=self.alpha,
interpolation=self.interpolation,
norm=self.norm,
extent=self.extent
extent=self.extent,
)

if self.dx:
Expand Down
4 changes: 2 additions & 2 deletions src/seaborn_image/_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def filterplot(
If True, vmax and vmin are adjusted so they have the same absolute value, making the diverging
color maps show 0 at the middle.
vmaxabs : float, optional
If `diverging` is True, sets vmax to vmaxabs and vmin to -vmaxabs.
If `diverging` is True, sets vmax to vmaxabs and vmin to -vmaxabs.
units : str, optional
Units of `dx`, by default None
dimension : str, optional
Expand Down Expand Up @@ -238,7 +238,7 @@ def filterplot(
cbar_ticks=cbar_ticks,
showticks=showticks,
despine=despine,
extent=extent
extent=extent,
)

# Provide basic statistical results
Expand Down
10 changes: 5 additions & 5 deletions src/seaborn_image/_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def imgplot(
If True, vmax and vmin are adjusted so they have the same absolute value, making the diverging
color maps show 0 at the middle.
vmaxabs : float, optional
If `diverging` is True, sets vmax to vmaxabs and vmin to -vmaxabs.
If `diverging` is True, sets vmax to vmaxabs and vmin to -vmaxabs.
dx : float, optional
Size per pixel of the image data. Specifying `dx` and `units` adds a scalebar
to the image, by default None
Expand Down Expand Up @@ -287,10 +287,10 @@ def imgplot(
if robust is True:
assert len(perc) == 2
assert perc[0] < perc[1] # order should be (min, max)

if diverging:
if vmaxabs is not None:
assert vmaxabs > 0
assert vmaxabs > 0

if not isinstance(cbar, bool):
raise TypeError
Expand Down Expand Up @@ -358,7 +358,7 @@ def imgplot(
cbar_ticks=cbar_ticks,
showticks=showticks,
despine=despine,
extent=extent
extent=extent,
)

f, ax, cax = img_plotter.plot()
Expand Down Expand Up @@ -454,7 +454,7 @@ def imghist(
If True, vmax and vmin are adjusted so they have the same absolute value, making the diverging
color maps show 0 at the middle.
vmaxabs : float, optional
If `diverging` is True, sets vmax to vmaxabs and vmin to -vmaxabs.
If `diverging` is True, sets vmax to vmaxabs and vmin to -vmaxabs.
dx : float, optional
Size per pixel of the image data. Specifying `dx` and `units` adds a scalebar
to the image, by default None
Expand Down
10 changes: 5 additions & 5 deletions src/seaborn_image/_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ImageGrid:
If True, vmax and vmin are adjusted so they have the same absolute value, making the diverging
color maps show 0 at the middle.
vmaxabs : float or list, optional
If `diverging` is True, sets vmax to vmaxabs and vmin to -vmaxabs.
If `diverging` is True, sets vmax to vmaxabs and vmin to -vmaxabs.
alpha : float or array-like, optional
`matplotlib.pyplot.imshow` alpha blending value from 0 (transparent) to 1 (opaque),
by default None
Expand Down Expand Up @@ -577,7 +577,7 @@ def _map_img_to_grid(self):
if isinstance(self.robust, (list, tuple)):
self._check_len_wrt_n_images(self.robust)
_robust = self.robust[i]

if isinstance(self.diverging, (list, tuple)):
self._check_len_wrt_n_images(self.diverging)
_diverging = self.diverging[i]
Expand All @@ -589,7 +589,7 @@ def _map_img_to_grid(self):
if isinstance(self.vmax, (list, tuple)):
self._check_len_wrt_n_images(self.vmax)
_vmax = self.vmax[i]

if isinstance(self.vmaxabs, (list, tuple)):
self._check_len_wrt_n_images(self.vmaxabs)
_vmaxabs = self.vmaxabs[i]
Expand Down Expand Up @@ -791,7 +791,7 @@ def rgbplot(
cbar_ticks=None,
showticks=False,
despine=None,
extent=None
extent=None,
):
"""Split and plot the red, green and blue channels of an
RGB image.
Expand Down Expand Up @@ -946,7 +946,7 @@ def rgbplot(
cbar_ticks=cbar_ticks,
showticks=showticks,
despine=despine,
extent=extent
extent=extent,
)

return g
Expand Down
6 changes: 3 additions & 3 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def test_data_plotted_is_same_as_input():
@pytest.mark.parametrize("robust", [True, False])
@pytest.mark.parametrize("diverging", [True, False])
@pytest.mark.parametrize("vmaxabs", [None, 1])
@pytest.mark.parametrize("extent", [(0,1,0,1), (20, 30, 0, 10)])
@pytest.mark.parametrize("extent", [(0, 1, 0, 1), (20, 30, 0, 10)])
def test_plot_w_all_inputs(
cmap,
vmin,
Expand All @@ -202,7 +202,7 @@ def test_plot_w_all_inputs(
robust,
diverging,
vmaxabs,
extent
extent,
):
img_setup = isns._core._SetupImage(
data,
Expand All @@ -222,7 +222,7 @@ def test_plot_w_all_inputs(
cbar_ticks=[],
showticks=showticks,
despine=despine,
extent=extent
extent=extent,
)
f, ax, cax = img_setup.plot()

Expand Down
7 changes: 5 additions & 2 deletions tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_robust_type():
with pytest.raises(TypeError):
isns.imgplot(data, robust="True")


def test_diverging_value():
with pytest.raises(AssertionError):
isns.imgplot(data, diverging=True, vmaxabs=-1)
Expand Down Expand Up @@ -120,8 +121,9 @@ def test_imgplot_gray_conversion_for_rgb():

np.testing.assert_array_equal(ax.images[0].get_array().data, rgb2gray(astronaut()))


def test_imgplot_extent():
extent = (0,1,0,1)
extent = (0, 1, 0, 1)
ax = isns.imgplot(astronaut(), gray=True, extent=extent)
np.testing.assert_array_equal(ax.images[0].get_extent(), extent)

Expand All @@ -133,7 +135,7 @@ def test_imgplot_extent():
@pytest.mark.parametrize("gray", [True, False])
@pytest.mark.parametrize("cmap", [None, "ice"])
@pytest.mark.parametrize("data", [data, astronaut()])
@pytest.mark.parametrize("extent", [(0,1,0,1), (20, 30, 0, 10)])
@pytest.mark.parametrize("extent", [(0, 1, 0, 1), (20, 30, 0, 10)])
def test_gray_cmap_interplay(data, gray, cmap, extent):
_ = isns.imgplot(data, cmap=cmap, gray=gray, extent=extent)
plt.close("all")
Expand Down Expand Up @@ -275,6 +277,7 @@ def test_imghist_diverging_hist_cmap():

plt.close()


@pytest.mark.parametrize("cmap", [None, "acton"])
@pytest.mark.parametrize("bins", [None, 100])
@pytest.mark.parametrize("orientation", ["horizontal", "h", "vertical", "v"])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ def test_robust(self):
with pytest.raises(AssertionError):
isns.ImageGrid(self.img_3d, perc=[(2, 98), (1, 99)])
plt.close()

def test_diverging(self):
isns.ImageGrid(self.img_list, diverging=True)
plt.close()
Expand Down

0 comments on commit 2f089f7

Please sign in to comment.