Skip to content

Commit 9185c76

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent a6787f4 commit 9185c76

File tree

2 files changed

+53
-23
lines changed

2 files changed

+53
-23
lines changed

src/napari_clusters_plotter/_create_sample_data_assets.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
import zipfile
33
from pathlib import Path
44

5+
56
def create_sample_data_zip():
67
import shutil
8+
79
sample_data_dir = Path(__file__).parent / "sample_data"
810
zip_path = Path(__file__).parent / "sample_data.zip"
911

@@ -13,7 +15,7 @@ def create_sample_data_zip():
1315
if os.path.exists(sample_data_dir.parent / "data_registry.txt"):
1416
os.remove(sample_data_dir.parent / "data_registry.txt")
1517

16-
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
18+
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zipf:
1719
for root, _, files in os.walk(sample_data_dir):
1820
for file in files:
1921
file_path = Path(root) / file
@@ -24,8 +26,10 @@ def create_sample_data_zip():
2426
dest_path = sample_data_dir.parent / "sample_data" / "sample_data.zip"
2527
os.replace(zip_path, dest_path)
2628

29+
2730
def create_registry_file():
2831
import hashlib
32+
2933
root_dir = Path(__file__).parent / "sample_data" # Update this path
3034
registry = {}
3135
with open(root_dir / "data_registry.txt", "w") as registry_file:
@@ -36,9 +40,10 @@ def create_registry_file():
3640
with open(fp, "rb") as f:
3741
file_hash = hashlib.sha256(f.read()).hexdigest()
3842
registry[str(rel_path)] = f"sha256:{file_hash}"
39-
registry_file.write(f'{rel_path}: sha256:{file_hash}\n')
43+
registry_file.write(f"{rel_path}: sha256:{file_hash}\n")
44+
4045

4146
if __name__ == "__main__":
4247
create_registry_file()
4348
create_sample_data_zip()
44-
create_registry_file()
49+
create_registry_file()

src/napari_clusters_plotter/_sample_data.py

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
import os
2+
import zipfile
13
from pathlib import Path
24
from typing import List
3-
from skimage import io
5+
46
import numpy as np
57
import pandas as pd
68
import pooch
7-
import os
8-
import zipfile
9-
from pathlib import Path
9+
from skimage import io
10+
1011
from napari_clusters_plotter import __version__
1112

1213
# parse version
13-
if 'dev' in __version__:
14+
if "dev" in __version__:
1415
from packaging.version import parse
16+
1517
major, minor, patch = parse(__version__).release
1618
version = f"{major}.{minor}.{patch-1}"
1719
else:
@@ -20,51 +22,61 @@
2022
DATA_REGISTRY = pooch.create(
2123
path=pooch.os_cache("napari-clusters-plotter"),
2224
base_url=f"https://github.com/biapol/napari-clusters-plotter/releases/download/v{version}/",
23-
registry={"sample_data.zip": "sha256:d21889252cc439b32dacbfb2d4085057da1fe28e3c35f94fee1487804cfe9615"},
25+
registry={
26+
"sample_data.zip": "sha256:d21889252cc439b32dacbfb2d4085057da1fe28e3c35f94fee1487804cfe9615"
27+
},
2428
)
2529

30+
2631
def load_image(fname):
2732
zip_path = DATA_REGISTRY.fetch("sample_data.zip")
2833

2934
# check if has been unzipped before
3035
if not os.path.exists(zip_path.split(".zip")[0]):
31-
with zipfile.ZipFile(zip_path, 'r') as z:
36+
with zipfile.ZipFile(zip_path, "r") as z:
3237
z.extractall(zip_path.split(".zip")[0])
3338

3439
fname = os.path.join(zip_path.split(".zip")[0], fname)
3540
image = io.imread(fname)
3641

3742
return image
3843

44+
3945
def load_tabular(fname, **kwargs):
4046
zip_path = DATA_REGISTRY.fetch("sample_data.zip")
4147

4248
# check if has been unzipped before
4349
if not os.path.exists(zip_path.split(".zip")[0]):
44-
with zipfile.ZipFile(zip_path, 'r') as z:
50+
with zipfile.ZipFile(zip_path, "r") as z:
4551
z.extractall(zip_path.split(".zip")[0])
4652

4753
fname = os.path.join(zip_path.split(".zip")[0], fname)
4854
data = pd.read_csv(fname, **kwargs)
4955
return data
5056

57+
5158
def load_registry():
5259
zip_path = DATA_REGISTRY.fetch("sample_data.zip")
5360

5461
# check if has been unzipped before
5562
if not os.path.exists(zip_path.split(".zip")[0]):
56-
with zipfile.ZipFile(zip_path, 'r') as z:
63+
with zipfile.ZipFile(zip_path, "r") as z:
5764
z.extractall(zip_path.split(".zip")[0])
5865

59-
fname = os.path.join(zip_path.split(".zip")[0], "sample_data/data_registry.txt")
60-
registry = pd.read_csv(fname, sep=': sha256:', header=None)
61-
registry.columns = ['file', 'hash']
66+
fname = os.path.join(
67+
zip_path.split(".zip")[0], "sample_data/data_registry.txt"
68+
)
69+
registry = pd.read_csv(fname, sep=": sha256:", header=None)
70+
registry.columns = ["file", "hash"]
6271
return registry
6372

73+
6474
def skan_skeleton() -> List["LayerData"]: # noqa: F821
6575

6676
df_paths = load_tabular("shapes_skeleton/all_paths.csv")
67-
df_features = load_tabular("shapes_skeleton/skeleton_features.csv", index_col="Unnamed: 0")
77+
df_features = load_tabular(
78+
"shapes_skeleton/skeleton_features.csv", index_col="Unnamed: 0"
79+
)
6880

6981
# skeleton_id column should be categorical
7082
categorical_columns = [
@@ -109,12 +121,13 @@ def skan_skeleton() -> List["LayerData"]: # noqa: F821
109121

110122

111123
def tgmm_mini_dataset() -> List["LayerData"]: # noqa: F821
112-
124+
113125
features = load_tabular(
114126
"tracking_data/tgmm-mini-spot.csv",
115127
skiprows=[1, 2],
116128
low_memory=False,
117-
encoding="utf-8")
129+
encoding="utf-8",
130+
)
118131
data = load_tabular("tracking_data/tgmm-mini-tracks-layer-data.csv")
119132

120133
categorical_columns = [
@@ -154,8 +167,12 @@ def bbbc_1_dataset() -> List["LayerData"]: # noqa: F821
154167
# read data registry file
155168
registry = load_registry()
156169

157-
registry_bbby1 = registry[registry['file'].str.contains("BBBC007_v1_images")]
158-
tif_files = registry_bbby1[registry_bbby1['file'].str.endswith(".tif")]['file'].to_list()
170+
registry_bbby1 = registry[
171+
registry["file"].str.contains("BBBC007_v1_images")
172+
]
173+
tif_files = registry_bbby1[registry_bbby1["file"].str.endswith(".tif")][
174+
"file"
175+
].to_list()
159176
raw_images = [f for f in tif_files if "labels" not in f]
160177

161178
n_rows = np.ceil(np.sqrt(len(raw_images)))
@@ -211,8 +228,14 @@ def bbbc_1_dataset() -> List["LayerData"]: # noqa: F821
211228

212229

213230
def cells3d_curvatures() -> List["LayerData"]: # noqa: F821
214-
vertices = load_tabular("cells3d/vertices.txt", sep=' ', header=None).to_numpy()
215-
faces = load_tabular("cells3d/faces.txt", sep=' ', header=None).to_numpy().astype(int)
231+
vertices = load_tabular(
232+
"cells3d/vertices.txt", sep=" ", header=None
233+
).to_numpy()
234+
faces = (
235+
load_tabular("cells3d/faces.txt", sep=" ", header=None)
236+
.to_numpy()
237+
.astype(int)
238+
)
216239
hks = load_tabular("cells3d/signature.csv")
217240
nuclei = load_image("cells3d/nucleus.tif")
218241

@@ -242,7 +265,9 @@ def granule_compression_vectors() -> List["LayerData"]: # noqa: F821
242265
import numpy as np
243266
from napari.utils import notifications
244267

245-
features = load_tabular("compression_vectors/granular_compression_test.csv")
268+
features = load_tabular(
269+
"compression_vectors/granular_compression_test.csv"
270+
)
246271
features["iterations"] = features["iterations"].astype("category")
247272
features["returnStatus"] = features["returnStatus"].astype("category")
248273
features["Label"] = features["Label"].astype("category")

0 commit comments

Comments
 (0)