Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ Documentation = "https://wsidata.readthedocs.io"
repository = "https://github.com/rendeirolab/wsidata"
dynamic = ["version"]
dependencies = [
"spatialdata>=0.5.0",
"spatialdata>=0.6.0",
"opencv-python-headless",
"openslide-python>=1.4.1",
"openslide-bin>=4.0.0.2",
"tiffslide",
"rich",
"torch>=2.0.0",
]
Expand All @@ -41,6 +40,7 @@ dependencies = [
stain = ["torchstain"]
bioformats = ["scyjava"]
cucim = ["cucim"]
tiffslide = ["tiffslide"]
plot = ["matplotlib", "legendkit"]

[tool.hatch.version]
Expand Down Expand Up @@ -106,6 +106,8 @@ dev = [
"jupyter-cache>=1.0.1",
"notebook>=7.3.3",
"pandas-stubs>=2.3.0.250703",
"tiffslide>=2.4.0",
"scyjava>=1.10.1",
]
docs = [
"sphinx>=8.1.3",
Expand All @@ -119,9 +121,8 @@ docs = [
"sphinx-design>=0.6.1",
"sphinxext-opengraph[social-cards]>=0.10.0",
]
readers = [
cucim = [
"cucim-cu12>=25.6.0; sys_platform == 'linux'",
"scyjava>=1.10.1",
]
datasets = [
"torch-geometric>=2.6.1",
Expand Down
28 changes: 14 additions & 14 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 45 additions & 11 deletions wsidata/accessors/iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,30 @@ def _normalize_polygon(polygon, bbox):
)


def _html_attributes(attrs):
def _html_attributes(obj, attrs, masked_attrs=None):
"""Max 4 attributes per line, show in card style"""
n = 4
n_attr = len(attrs)
n_row = n_attr // n + 1
rows = []
if masked_attrs is None:
masked_attrs = {}
else:
masked_attrs = set(masked_attrs)
for i in range(n_row):
row = attrs[i * n : (i + 1) * n]
row = "".join(
f"<p style='border: 1px solid #C68FE6; padding: 3pt; "
f"border-radius: 4px; text-align: center; margin-bottom: 2pt;'>"
f"{attr}</p>"
for attr in row
)
rows.append(row)
raw_html = ""
for attr in row:
base = (
"<p style='border: 1px solid #C68FE6; padding: 3pt; "
"border-radius: 4px; text-align: center; margin-bottom: 2pt;'>"
)
if attr in masked_attrs:
base += f"{attr}</p>"
else:
base += f"{attr}: {getattr(obj, attr)}</p>"
raw_html += base
rows.append(raw_html)
return "".join(f"<div style='display: inline-block;'>{row}</div>" for row in rows)


Expand Down Expand Up @@ -174,7 +183,7 @@ def _repr_html_(self):
<strong style="font-size: 1.1em; color: #C68FE6;">TissueContour</strong>
<p style="margin-bottom: 0">Attributes:</p>
<div style="display: flex; gap: 10px;">
{_html_attributes(self._attrs)}
{_html_attributes(self, self._attrs, masked_attrs=["shape", "contour", "holes"])}
{svg_shape}
</div>

Expand Down Expand Up @@ -345,7 +354,20 @@ def _repr_html_(self):
<strong style="font-size: 1.1em; color: #C68FE6;">TissueImage</strong>
<p style="margin-bottom: 0">Attributes:</p>
<div style="display: flex; gap: 10px;">
{_html_attributes(self._attrs)}
{
_html_attributes(
self,
self._attrs,
masked_attrs=[
"image",
"mask",
"masked_image",
"shape",
"contour",
"holes",
],
)
}
<img src="data:image/png;base64,{self._html_thumbnail}"
style="width: 130px; border-radius: 8px;">
</div>
Expand Down Expand Up @@ -513,7 +535,19 @@ def _repr_html_(self):
<strong style="font-size: 1.1em; color: #C68FE6;">TileImage</strong>
<p style="margin-bottom: 0">Attributes:</p>
<div style="display: flex; gap: 10px;">
{_html_attributes(self._attrs)}
{
_html_attributes(
self,
self._attrs,
masked_attrs=[
"image",
"annot_mask",
"annot_shapes",
"annot_labels",
"norm_annot_shapes",
],
)
}
<img src="data:image/png;base64,{self._html_thumbnail}"
style="width: 150px; border-radius: 8px;">
</div>
Expand Down
Loading