Skip to content

Commit d32d0db

Browse files
committed
some reconfigurations, and making ready for pip
1 parent 34078ed commit d32d0db

10 files changed

Lines changed: 142 additions & 44 deletions

File tree

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
.ipynb_checkpoints/
2-
.data/
1+
.dist/
2+
.saibr.egg-info/
File renamed without changes.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# saibr_python
1+
# SAIBR (python)
22

33
Python implementation of SAIBR

environment.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

saibr/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .saibr import *
2-
from .funcs import *
2+
from .misc import *
33
from .roi import *
44
from .legacy import *

saibr/funcs.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

saibr/misc.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import numpy as np
2+
from skimage import io
3+
from typing import Optional
4+
import glob
5+
import matplotlib.pyplot as plt
6+
import copy
7+
8+
9+
def load_image(filename: str) -> np.ndarray:
10+
"""
11+
Given the filename of a TIFF, creates numpy array with pixel intensities
12+
13+
Args:
14+
filename: full path to the file to import (including extension)
15+
16+
Returns:
17+
A numpy array of the image
18+
19+
"""
20+
21+
return io.imread(filename).astype(float)
22+
23+
24+
def save_img(img: np.ndarray, direc: str):
25+
"""
26+
Saves 2D array as .tif file
27+
28+
Args:
29+
img: numpy array of the image to save
30+
direc: file path to save to (including '.tif' extension)
31+
32+
"""
33+
34+
io.imsave(direc, img.astype('float32'))
35+
36+
37+
def save_img_jpeg(img: np.ndarray, direc: str, cmin: Optional[float] = None, cmax: Optional[float] = None,
38+
cmap: str = 'gray'):
39+
"""
40+
Saves 2D array as jpeg, according to min and max pixel intensities
41+
42+
Args:
43+
img: numpy array of the image to save
44+
direc: file path to save to (including '.jpeg' extension)
45+
cmin: optional, sets intensity scaling (along with cmax)
46+
cmax: optional, sets intensity scaling (along with cmin)
47+
cmap: colour map (use string corresponding to matplotlib colormap)
48+
49+
"""
50+
51+
plt.imsave(direc, img, vmin=cmin, vmax=cmax, cmap=cmap)
52+
53+
54+
def _direcslist(dest: str, levels: int = 0, exclude: Optional[tuple] = ('!',),
55+
exclusive: Optional[tuple] = None) -> list:
56+
lis = sorted(glob.glob(f'{dest}/*/'))
57+
58+
for level in range(levels):
59+
newlis = []
60+
for e in lis:
61+
newlis.extend(sorted(glob.glob(f'{e}/*/')))
62+
lis = newlis
63+
lis = [x[:-1] for x in lis]
64+
65+
# Excluded directories
66+
lis_copy = copy.deepcopy(lis)
67+
if exclude is not None:
68+
for x in lis:
69+
for i in exclude:
70+
if i in x:
71+
lis_copy.remove(x)
72+
break
73+
74+
# Exclusive directories
75+
if exclusive is not None:
76+
lis2 = []
77+
for x in lis_copy:
78+
for i in exclusive:
79+
if i in x:
80+
lis2.append(x)
81+
else:
82+
lis2 = lis_copy
83+
84+
return sorted(lis2)
85+
86+
87+
def direcslist(dest: str, levels: int = 0, exclude: Optional[tuple] = ('!',),
88+
exclusive: Optional[tuple] = None) -> list:
89+
"""
90+
Gives a list of directories within a given directory (full path)
91+
Todo: os.walk
92+
93+
Args:
94+
dest: path of parent directory
95+
levels: number of levels to go down. E.g. if 0, only return folders within the parent folder; if 1, return
96+
folders within folders within the parent folder
97+
exclude: exclude directories containing any strings within this tuple
98+
exclusive: exclude directories that don't contain all the strings within this tuple
99+
100+
Returns:
101+
list of directories
102+
103+
"""
104+
105+
if type(dest) is list:
106+
out = []
107+
for d in dest:
108+
out.extend(_direcslist(d, levels, exclude, exclusive))
109+
return out
110+
else:
111+
return _direcslist(dest, levels, exclude, exclusive)

saibr/saibr.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
import scipy.odr as odr
77
from sklearn.metrics import r2_score
88
from sklearn.linear_model import LinearRegression
9-
from .funcs import load_image, make_mask
9+
from .misc import load_image
1010
from .roi import offset_coordinates
1111
from typing import Tuple, Optional
12+
import cv2
1213

1314

1415
class SaibrCalibrate:
@@ -471,3 +472,7 @@ def saibr_correct_3channel(ch1: np.ndarray, ch2: np.ndarray, ch3: np.ndarray, m1
471472
af = m1 * ch2 + m2 * ch3 + c
472473
signal = ch1 - af
473474
return signal
475+
476+
477+
def make_mask(shape: tuple, roi: np.ndarray) -> np.ndarray:
478+
return cv2.fillPoly(np.zeros(shape) * np.nan, [np.int32(roi)], 1)

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[metadata]
2+
description-file=README.md
3+
license_files=LICENSE.txt

setup.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
from setuptools import find_packages, setup
2+
from pathlib import Path
3+
4+
this_directory = Path(__file__).parent
5+
long_description = (this_directory / "README.md").read_text()
26

37
setup(
48
name='saibr',
5-
version='1.0',
9+
version='0.1.0',
610
license="CC BY 4.0",
711
author='Tom Bland',
12+
author_email='tom_bland@hotmail.co.uk',
813
packages=find_packages(),
14+
url='https://github.com/goehringlab/saibr_python',
15+
install_requires=['numpy',
16+
'matplotlib',
17+
'scipy',
18+
'ipywidgets',
19+
'scikit-learn',
20+
'scikit-image',
21+
'jupyter',
22+
'opencv-python'],
23+
description='Python implementation of SAIBR: a tool for performing spectral autofluorescence correction on biological images',
24+
long_description=long_description,
25+
long_description_content_type='text/markdown'
926
)

0 commit comments

Comments
 (0)