Skip to content

Commit 2d94e8b

Browse files
Merge pull request #7 from rosalindfranklininstitute/docs
Docs
2 parents d6d00e0 + a5b4c38 commit 2d94e8b

File tree

4 files changed

+165
-117
lines changed

4 files changed

+165
-117
lines changed

GeoLlama/calc_by_slice.py

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Copyright 2023 Rosalind Franklin Institute
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +16,7 @@
1716
## Module : GeoLlama.calc_by_slice ##
1817
## Created : Neville Yee ##
1918
## Date created : 02-Oct-2023 ##
20-
## Date last modified : 09-Oct-2023 ##
19+
## Date last modified : 19-Apr-2024 ##
2120
##################################################
2221

2322
import itertools
@@ -88,7 +87,20 @@ def create_slice_views(volume: npt.NDArray[any],
8887
coords: list,
8988
std_window: int=15,
9089
gaussian_sigma: int=None,
91-
) -> (npt.NDArray[any], npt.NDArray[any], npt.NDArray[any]):
90+
) -> (npt.NDArray[any], npt.NDArray[any]):
91+
"""
92+
Create slice views from full tomogram for downstream processes
93+
94+
Args:
95+
volume (ndarray) : input 3D image (tomogram)
96+
coords (list) : list of coordinates for creation of 2D slice views
97+
std_window (int) : width of window for metric calculation for 2D slices
98+
gaussian_sigma (int) : Sigma parameter for Gaussian blurring kernal
99+
100+
Returns:
101+
ndarray, ndarray
102+
"""
103+
92104
std_half = std_window // 2
93105
z_range = (max(0, coords[0]-std_half), min(coords[0]+std_window-std_half, volume.shape[0]-1))
94106
x_range = (max(0, coords[1]-std_half), min(coords[1]+std_window-std_half, volume.shape[1]-1))
@@ -233,6 +245,20 @@ def evaluate_slice(slice_coords: list,
233245
) -> (float, float, float, int,
234246
npt.NDArray, npt.NDArray, npt.NDArray, npt.NDArray,
235247
):
248+
"""
249+
Function for creation and evaluation of one 2D slice from tomogram given coordinates of intersection point
250+
251+
Args:
252+
slice_coords (list) : list containing coordinates of intersection point for image slicing
253+
volume (ndarray) : tomogram for evaluation
254+
pixel_size_nm (float) : pixel size of tomogram (internally binned)
255+
use_view (str) : view (orientation of slice) used for evaluation
256+
pt_thres (int) : acceptance limit (number of feature pixels) of slices
257+
autocontrast (bool) : whether to apply autocontrast on slices before evaluation
258+
259+
Returns:
260+
float, float, float, int, ndarray, ndarray, ndarray, ndarray
261+
"""
236262

237263
view_zy, view_zx = create_slice_views(
238264
volume=volume,
@@ -367,11 +393,26 @@ def evaluate_slice(slice_coords: list,
367393
surface_bottom_1, surface_bottom_2)
368394

369395

370-
def evaluate_full_lamella(volume,
371-
pixel_size_nm,
372-
autocontrast,
373-
cpu=1,
396+
def evaluate_full_lamella(volume: npt.NDArray[any],
397+
pixel_size_nm: float,
398+
autocontrast: bool,
399+
cpu: int=1,
400+
) -> (
401+
npt.NDArray, npt.NDArray, float, float, float, float, tuple
374402
):
403+
"""
404+
Evaluation of full lamella geometry
405+
406+
Args:
407+
volume (ndarray) : Tomogram to be evaluated
408+
pixel_size_nm (float) : Pixel size (after binning) of tomogram
409+
autocontrast (bool) : whether to apply autocontrast on slices before evaluation
410+
cpu (int) : number of cores used in parallel calculation of slices
411+
412+
Returns:
413+
ndarray, ndarray, float, float, float, float, tuple
414+
415+
"""
375416
x_slice_list = np.arange(int(volume.shape[1]*0.2),
376417
int(volume.shape[1]*0.8),
377418
int(volume.shape[1]*0.025))

GeoLlama/evaluate.py

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
## Module : GeoLlama.evaluate ##
1717
## Created : Neville Yee ##
1818
## Date created : 05-Oct-2023 ##
19-
## Date last modified : 05-Oct-2023 ##
19+
## Date last modified : 19-Apr-2024 ##
2020
#############################################
2121

2222

@@ -38,7 +38,13 @@
3838

3939
def find_files(path: str) -> list:
4040
"""
41-
Some docstrings
41+
Function to find appropriate files from given path
42+
43+
Args:
44+
path (str) : Path to folder holding tomograms
45+
46+
Returns:
47+
list
4248
"""
4349

4450
criterion = Path(path).glob("**/*.mrc")
@@ -48,6 +54,15 @@ def find_files(path: str) -> list:
4854

4955

5056
def save_figure(surface_info, save_path, binning):
57+
"""
58+
Export data and interpolated surfaces as PNG file
59+
60+
Args:
61+
surface_info (tuple) : Outputs (tuple) of GeoLlama evaluation module
62+
save_path (str) : Path to PNG file being exported
63+
binning (int) : Internal binning factor of tomogram
64+
"""
65+
5166
xx_top, yy_top, surface_top, xx_bottom, yy_bottom, surface_bottom, _, _ = surface_info
5267

5368
fig, ax = plt.subplots(subplot_kw={"projection": "3d"},
@@ -72,6 +87,14 @@ def save_figure(surface_info, save_path, binning):
7287

7388

7489
def save_text_model(surface_info, save_path, binning):
90+
"""
91+
Export data and interpolated model as text file for conversion and visualisation in IMOD.
92+
93+
Args:
94+
surface_info (tuple) : Outputs (tuple) of GeoLlama evaluation module
95+
save_path (str) : Path to text file being exported
96+
binning (int) : Internal binning factor of tomogram
97+
"""
7598
xx_top, yy_top, surface_top, xx_bottom, yy_bottom, surface_bottom, model_top, model_bottom = surface_info
7699

77100
contour_top = np.full((len(model_top),1), 1, dtype=int)
@@ -101,7 +124,18 @@ def eval_single(
101124
autocontrast: bool,
102125
):
103126
"""
104-
Some docstring
127+
Evaluate geometry of a single tomogram given source file
128+
129+
Args:
130+
fname (str) : Path to tomogram file
131+
pixel_size (float) : Pixel size of tomogram in nm
132+
binning (int) : Internal binning factor for GeoLlama evaluation
133+
cpu (int) : Number of cores used for parallel calculations
134+
bandpass (bool) : Whether to include bandpass as a preprocessing step
135+
autocontrast (bool) : Whether to include autocontrast as a preprocessing step
136+
137+
Returns:
138+
ndarray, ndarray, ndarray, ndarray, ndarray, ndarray, ndarray
105139
"""
106140

107141
tomo, pixel_size = io.read_mrc(
@@ -138,7 +172,18 @@ def eval_batch(
138172
autocontrast: bool,
139173
) -> (pd.DataFrame, pd.DataFrame):
140174
"""
141-
Some docstring
175+
Evaluate geometry of tomograms given path to folder containing tomograms, then output statistics as pandas DataFrames.
176+
177+
Args:
178+
filelist (list) : List containing paths to tomograms
179+
pixel_size (float) : Pixel size of tomogram in nm
180+
binning (int) : Internal binning factor for GeoLlama evaluation
181+
cpu (int) : Number of cores used for parallel calculations
182+
bandpass (bool) : Whether to include bandpass as a preprocessing step
183+
autocontrast (bool) : Whether to include autocontrast as a preprocessing step
184+
185+
Returns:
186+
DataFrame, DataFrame
142187
"""
143188

144189
thickness_mean_list = []

GeoLlama/io.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@
3030
def read_mrc(fname: str,
3131
px_size_nm: float,
3232
downscale: int=2) -> (npt.NDArray[any], float):
33+
"""
34+
Function to read in MRC image file.
35+
36+
Args:
37+
fname (str) : Path to image file
38+
px_size_nm (float) : Pixel size of original tomogram in nm
39+
downscale (int) : Internal binning factor
40+
41+
Returns:
42+
ndarray, float
43+
"""
3344

3445
with mrcfile.open(fname) as f:
3546
data = f.data

0 commit comments

Comments
 (0)