Skip to content

Commit

Permalink
Merge pull request #2 from SarthakJariwala/v0.3.x
Browse files Browse the repository at this point in the history
Improve test coverage
  • Loading branch information
SarthakJariwala authored Jul 24, 2020
2 parents f65aa07 + fd0c2c6 commit 5cdbb5d
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 6 deletions.
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,27 @@
<div class="row">

<a>
<img src="./examples/image_0.png" height="135" width="145">
<img src="./examples/image_0.png" height="180" width="200">
</a>

<a>
<img src="./examples/image_1.png" height="135" width="145">
<img src="./examples/image_1.png" height="180" width="200">
</a>

<a>
<img src="./examples/image_3.png" height="165" width="400">
</a>

</div>

<div class="row">

<a>
<img src="./examples/image_2.png" height="300" width="300">
<img src="./examples/image_4.png" height="400" width="400">
</a>

<a>
<img src="./examples/image_2.png" height="400" width="400">
</a>

</div>
Expand Down Expand Up @@ -52,8 +60,14 @@ import seaborn_image as isns
isns.imgplot(data)

"""Plot image with scalebar"""
isns.imgplot(data, dx=1, units="um")
isns.imgplot(data, dx=0.01, units="um")

"""Add colorbar label"""
isns.imgplot(data, dx=0.01, units="um", cbar_label="Height (nm)")
```
<a>
<img src="./examples/image_0.png" height="275" width="300">
</a>

### Set context like seaborn

Expand All @@ -70,8 +84,12 @@ isns.set_context("notebook") # Other options include paper, talk, presentation,

import seaborn_image as isns

isns.filterplot(data, filter="gaussian")
isns.filterplot(data, filter="gaussian", sigma=5, cbar_label="Height (nm)")
```

<a>
<img src="./examples/image_3.png" height="260" width="600">
</a>

## Documentation
Check out the docs [here](https://seaborn-image.readthedocs.io/)
Binary file added examples/image_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/seaborn_image/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def _check_dict(dictionary):
if not isinstance(dictionary, dict):
raise ValueError(f"{dictionary} must be a dictionary")
raise TypeError(f"{dictionary} must be a dictionary")


class _SetupImage(object):
Expand Down
88 changes: 88 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import pytest

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.axes import Axes
from matplotlib.figure import Figure

import seaborn_image as isns

data = np.random.random(2500).reshape((50, 50))


def test_setup_figure():
img_setup = isns._core._SetupImage(data)
f, ax = img_setup._setup_figure()

assert isinstance(f, Figure)
assert isinstance(ax, Axes)


def test_setup_figure_check_title_dict():
with pytest.raises(TypeError):
img_setup = isns._core._SetupImage(data, title_dict=[{"fontsize": 20}])
f, ax = img_setup._setup_figure()


def test_setup_scalebar():
with pytest.raises(AttributeError):
img_setup = isns._core._SetupImage(data, dx=1)
f, ax = img_setup._setup_figure()
img_setup._setup_scalebar(ax)


def test_plot_check_cbar_dict():
with pytest.raises(TypeError):
img_setup = isns._core._SetupImage(
data, cbar=True, cbar_fontdict=[{"fontsize": 20}]
)
f, ax = img_setup.plot()


@pytest.mark.parametrize("cmap", [None, "acton"])
@pytest.mark.parametrize("vmin", [None])
@pytest.mark.parametrize("vmax", [None])
@pytest.mark.parametrize("title", [None, "My Title"])
@pytest.mark.parametrize("fontdict", [None, {"fontsize": 20}])
@pytest.mark.parametrize("dx", [None, 1])
@pytest.mark.parametrize(
"units", ["m", "um"]
) # units can't be None when dx is not None
@pytest.mark.parametrize("cbar", [None, True, False])
@pytest.mark.parametrize("cbar_fontdict", [None, {"fontsize": 20}])
@pytest.mark.parametrize("cbar_label", [None, "Cbar Label"])
@pytest.mark.parametrize("cbar_ticks", [None, [0, 1, 2]])
@pytest.mark.parametrize("showticks", [None, True, False])
def test_plot_w_all_inputs(
cmap,
vmin,
vmax,
title,
fontdict,
dx,
units,
cbar,
cbar_fontdict,
cbar_label,
cbar_ticks,
showticks,
):
img_setup = isns._core._SetupImage(
data,
cmap=cmap,
vmin=vmin,
vmax=vmax,
title=title,
fontdict=fontdict,
dx=dx,
units=units,
cbar=cbar,
cbar_fontdict=cbar_fontdict,
cbar_label=cbar_label,
cbar_ticks=cbar_ticks,
showticks=showticks,
)
f, ax = img_setup.plot()

assert isinstance(f, Figure)
assert isinstance(ax, Axes)

0 comments on commit 5cdbb5d

Please sign in to comment.