Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
mthiboust committed Nov 21, 2023
1 parent 7aafc27 commit ebefa32
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Publish

on:
push:
tags:
- v**

jobs:
pypi-publish:
name: upload release to PyPI
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v3
- uses: pdm-project/setup-pdm@v3
- name: Publish package distributions to PyPI
run: pdm publish
8 changes: 8 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Ruff
on: [pull_request]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: chartboost/ruff-action@v1
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Requires python 3.10+.
```python
def array_to_image(
arr,
spatial_dims: tuple[int] | tuple[int, int] | None = None,
spatial_dims: tuple[int, ...] | None = None,
channel_dim: int | None = None,
cmap: Callable | None = None,
inverted_colors: bool = False,
Expand Down
3 changes: 1 addition & 2 deletions src/array2image/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _guess_spatial_channel_dims(shape: tuple[int, ...]) -> tuple[tuple[int], int

def array_to_image(
arr,
spatial_dims: tuple[int] | tuple[int, int] | None = None,
spatial_dims: tuple[int, ...] | None = None,
channel_dim: int | None = None,
cmap: Callable | None = None,
inverted_colors: bool = False,
Expand Down Expand Up @@ -212,7 +212,6 @@ def array_to_image(
elif cmap is None and channel_dim == 2:
# Add a third channel filled with 1s and consider those values as HSV values.
arr = np.concatenate((arr, np.ones(spatial_dims + (1,))), axis=-1)
arr = matplotlib.colors.hsv_to_rgb(arr)

if bin_size is None:
# Try to guess a convenient scale_factor
Expand Down
20 changes: 18 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
"""Tests the plotting utility functions."""
"""Tests the plotting utility functions.
Todo:
* array_to_image tests
* add_grid tests
"""

# ruff: noqa: D103

from array2image.core import _grid_image, _guess_spatial_channel_dims, array_to_image
import numpy as np
from array2image.core import _add_grid, _guess_spatial_channel_dims, array_to_image


def test_guess_spatial_channel_dimensions():
Expand All @@ -18,3 +24,13 @@ def test_guess_spatial_channel_dimensions():

assert _guess_spatial_channel_dims((3, 3)) == ((3,), 3)
assert _guess_spatial_channel_dims((3, 3, 1)) == ((3, 3), 1)


def test_array_to_image():
array = np.ones((10, 10, 1))
array_to_image(array)


def test_add_grid():
array = np.ones((10, 10, 1))
_add_grid(array, spacing=1, thickness=1)

0 comments on commit ebefa32

Please sign in to comment.