Skip to content
Snippets Groups Projects
Commit db95b171 authored by s214735's avatar s214735
Browse files

Checked docstrings for minor errors w main focus on example code

parent 33c9b1b4
No related branches found
No related tags found
No related merge requests found
Showing
with 89 additions and 79 deletions
......@@ -37,13 +37,14 @@ def blobs(
Example:
```python
import qim3d
import qim3d.detection
# Get data
vol = qim3d.examples.cement_128x128x128
vol_blurred = qim3d.processing.gaussian(vol, sigma=2)
vol_blurred = qim3d.filters.gaussian(vol, sigma=2)
# Detect blobs, and get binary mask
blobs, mask = qim3d.processing.blob_detection(
blobs, mask = qim3d.detection.blobs(
vol_blurred,
min_sigma=1,
max_sigma=8,
......
......@@ -27,8 +27,8 @@ def volume(obj: np.ndarray|trimesh.Trimesh,
mesh = qim3d.io.load_mesh('path/to/mesh.obj')
# Compute the volume of the mesh
volume = qim3d.processing.volume(mesh)
print('Volume:', volume)
vol = qim3d.features.volume(mesh)
print('Volume:', vol)
```
Compute volume from a np.ndarray:
......@@ -36,10 +36,10 @@ def volume(obj: np.ndarray|trimesh.Trimesh,
import qim3d
# Generate a 3D blob
synthetic_blob = qim3d.generate.blob(noise_scale = 0.015)
synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015)
# Compute the volume of the blob
volume = qim3d.processing.volume(synthetic_blob, level=0.5)
volume = qim3d.features.volume(synthetic_blob, level=0.5)
print('Volume:', volume)
```
......@@ -73,7 +73,7 @@ def area(obj: np.ndarray|trimesh.Trimesh,
mesh = qim3d.io.load_mesh('path/to/mesh.obj')
# Compute the surface area of the mesh
area = qim3d.processing.area(mesh)
area = qim3d.features.area(mesh)
print(f"Area: {area}")
```
......@@ -82,16 +82,16 @@ def area(obj: np.ndarray|trimesh.Trimesh,
import qim3d
# Generate a 3D blob
synthetic_blob = qim3d.generate.blob(noise_scale = 0.015)
synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015)
# Compute the surface area of the blob
volume = qim3d.processing.area(synthetic_blob, level=0.5)
volume = qim3d.features.area(synthetic_blob, level=0.5)
print('Area:', volume)
```
"""
if isinstance(obj, np.ndarray):
log.info("Converting volume to mesh.")
obj = qim3d.processing.create_mesh(obj, **mesh_kwargs)
obj = qim3d.mesh.from_volume(obj, **mesh_kwargs)
return obj.area
......@@ -122,7 +122,7 @@ def sphericity(obj: np.ndarray|trimesh.Trimesh,
mesh = qim3d.io.load_mesh('path/to/mesh.obj')
# Compute the sphericity of the mesh
sphericity = qim3d.processing.sphericity(mesh)
sphericity = qim3d.features.sphericity(mesh)
```
Compute sphericity from a np.ndarray:
......@@ -130,10 +130,10 @@ def sphericity(obj: np.ndarray|trimesh.Trimesh,
import qim3d
# Generate a 3D blob
synthetic_blob = qim3d.generate.blob(noise_scale = 0.015)
synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015)
# Compute the sphericity of the blob
sphericity = qim3d.processing.sphericity(synthetic_blob, level=0.5)
sphericity = qim3d.features.sphericity(synthetic_blob, level=0.5)
```
!!! info "Limitations due to pixelation"
......@@ -143,10 +143,10 @@ def sphericity(obj: np.ndarray|trimesh.Trimesh,
"""
if isinstance(obj, np.ndarray):
log.info("Converting volume to mesh.")
obj = qim3d.processing.create_mesh(obj, **mesh_kwargs)
obj = qim3d.mesh.from_volume(obj, **mesh_kwargs)
volume = qim3d.processing.volume(obj)
area = qim3d.processing.area(obj)
volume = qim3d.features.volume(obj)
area = qim3d.features.area(obj)
if area == 0:
log.warning("Surface area is zero, sphericity is undefined.")
......
......@@ -116,13 +116,13 @@ class Pipeline:
Example:
```python
import qim3d
from qim3d.processing import Pipeline, Median, Gaussian, Maximum, Minimum
from qim3d.filters import Pipeline, Median, Gaussian, Maximum, Minimum
# Get data
vol = qim3d.examples.fly_150x256x256
# Show original
qim3d.viz.slices_grid(vol, axis=0, show=True)
fig1 = qim3d.viz.slices_grid(vol, num_slices=5, display_figure=True)
# Create filter pipeline
pipeline = Pipeline(
......@@ -137,7 +137,7 @@ class Pipeline:
vol_filtered = pipeline(vol)
# Show filtered
qim3d.viz.slices_grid(vol_filtered, axis=0)
fig2 = qim3d.viz.slices_grid(vol_filtered, num_slices=5, display_figure=True)
```
![original volume](assets/screenshots/filter_original.png)
![filtered volume](assets/screenshots/filter_processed.png)
......@@ -185,7 +185,7 @@ class Pipeline:
Example:
```python
import qim3d
from qim3d.processing import Pipeline, Maximum, Median
from qim3d.filters import Pipeline, Maximum, Median
# Create filter pipeline
pipeline = Pipeline(
......
......@@ -189,10 +189,10 @@ def noise_object_collection(
# Generate synthetic collection of objects
num_objects = 15
synthetic_collection, labels = qim3d.generate.collection(num_objects = num_objects)
synthetic_collection, labels = qim3d.generate.noise_object_collection(num_objects = num_objects)
# Visualize synthetic collection
qim3d.viz.vol(synthetic_collection)
qim3d.viz.volumetric(synthetic_collection)
```
<iframe src="https://platform.qim.dk/k3d/synthetic_collection_default.html" width="100%" height="500" frameborder="0"></iframe>
......@@ -203,8 +203,8 @@ def noise_object_collection(
```python
# Visualize labels
cmap = qim3d.viz.colormaps.objects(nlabels=num_objects)
qim3d.viz.slicer(labels, cmap=cmap, vmax=num_objects)
cmap = qim3d.viz.colormaps.segmentation(num_labels=num_objects)
qim3d.viz.slicer(labels, color_map=cmap, value_max=num_objects)
```
![synthetic_collection](assets/screenshots/synthetic_collection_default_labels.gif)
......@@ -233,7 +233,7 @@ def noise_object_collection(
import qim3d
# Generate synthetic collection of cylindrical structures
vol, labels = qim3d.generate.collection(num_objects = 40,
vol, labels = qim3d.generate.noise_object_collection(num_objects = 40,
collection_shape = (300, 150, 150),
min_shape = (280, 10, 10),
max_shape = (290, 15, 15),
......@@ -248,14 +248,14 @@ def noise_object_collection(
)
# Visualize synthetic collection
qim3d.viz.vol(vol)
qim3d.viz.volumetric(vol)
```
<iframe src="https://platform.qim.dk/k3d/synthetic_collection_cylinder.html" width="100%" height="500" frameborder="0"></iframe>
```python
# Visualize slices
qim3d.viz.slices_grid(vol, n_slices=15)
qim3d.viz.slices_grid(vol, num_slices=15)
```
![synthetic_collection_cylinder](assets/screenshots/synthetic_collection_cylinder_slices.png)
......@@ -264,7 +264,7 @@ def noise_object_collection(
import qim3d
# Generate synthetic collection of tubular (hollow) structures
vol, labels = qim3d.generate.collection(num_objects = 10,
vol, labels = qim3d.generate.noise_object_collection(num_objects = 10,
collection_shape = (200, 200, 200),
min_shape = (180, 25, 25),
max_shape = (190, 35, 35),
......@@ -279,13 +279,13 @@ def noise_object_collection(
)
# Visualize synthetic collection
qim3d.viz.vol(vol)
qim3d.viz.volumetric(vol)
```
<iframe src="https://platform.qim.dk/k3d/synthetic_collection_tube.html" width="100%" height="500" frameborder="0"></iframe>
```python
# Visualize slices
qim3d.viz.slices_grid(vol, n_slices=15, axis=1)
qim3d.viz.slices_grid(vol, num_slices=15, slice_axis=1)
```
![synthetic_collection_tube](assets/screenshots/synthetic_collection_tube_slices.png)
"""
......
......@@ -43,16 +43,16 @@ def noise_object(
import qim3d
# Generate synthetic blob
synthetic_blob = qim3d.generate.blob(noise_scale = 0.015)
synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015)
# Visualize 3D volume
qim3d.viz.vol(synthetic_blob)
qim3d.viz.volumetric(synthetic_blob)
```
<iframe src="https://platform.qim.dk/k3d/synthetic_blob.html" width="100%" height="500" frameborder="0"></iframe>
```python
# Visualize slices
qim3d.viz.slices_grid(synthetic_blob, vmin = 0, vmax = 255, n_slices = 15)
qim3d.viz.slices_grid(synthetic_blob, value_min = 0, value_max = 255, num_slices = 15)
```
![synthetic_blob](assets/screenshots/synthetic_blob_slices.png)
......@@ -61,7 +61,7 @@ def noise_object(
import qim3d
# Generate tubular synthetic blob
vol = qim3d.generate.blob(base_shape = (10, 300, 300),
vol = qim3d.generate.noise_object(base_shape = (10, 300, 300),
final_shape = (100, 100, 100),
noise_scale = 0.3,
gamma = 2,
......@@ -70,13 +70,13 @@ def noise_object(
)
# Visualize synthetic object
qim3d.viz.vol(vol)
qim3d.viz.volumetric(vol)
```
<iframe src="https://platform.qim.dk/k3d/synthetic_blob_cylinder.html" width="100%" height="500" frameborder="0"></iframe>
```python
# Visualize slices
qim3d.viz.slices_grid(vol, n_slices=15, axis=1)
qim3d.viz.slices_grid(vol, num_slices=15, slice_axis=1)
```
![synthetic_blob_cylinder_slice](assets/screenshots/synthetic_blob_cylinder_slice.png)
......@@ -85,7 +85,7 @@ def noise_object(
import qim3d
# Generate tubular synthetic blob
vol = qim3d.generate.blob(base_shape = (200, 100, 100),
vol = qim3d.generate.noise_object(base_shape = (200, 100, 100),
final_shape = (400, 100, 100),
noise_scale = 0.03,
gamma = 0.12,
......@@ -94,13 +94,13 @@ def noise_object(
)
# Visualize synthetic blob
qim3d.viz.vol(vol)
qim3d.viz.volumetric(vol)
```
<iframe src="https://platform.qim.dk/k3d/synthetic_blob_tube.html" width="100%" height="500" frameborder="0"></iframe>
```python
# Visualize
qim3d.viz.slices_grid(vol, n_slices=15)
qim3d.viz.slices_grid(vol, num_slices=15)
```
![synthetic_blob_tube_slice](assets/screenshots/synthetic_blob_tube_slice.png)
"""
......@@ -178,7 +178,7 @@ def noise_object(
axis = np.argmax(volume.shape) # Fade along the dimension where the object is the largest
target_max_normalized_distance = 1.4 # This value ensures that the object will become cylindrical
volume = qim3d.processing.operations.fade_mask(volume,
volume = qim3d.operations.fade_mask(volume,
geometry = geometry,
axis = axis,
target_max_normalized_distance = target_max_normalized_distance
......@@ -193,7 +193,7 @@ def noise_object(
target_max_normalized_distance = 1.4 # This value ensures that the object will become cylindrical
# Fade once for making the object cylindrical
volume = qim3d.processing.operations.fade_mask(volume,
volume = qim3d.operations.fade_mask(volume,
geometry = geometry,
axis = axis,
decay_rate = decay_rate,
......@@ -202,7 +202,7 @@ def noise_object(
)
# Fade again with invert = True for making the object a tube (i.e. with a hole in the middle)
volume = qim3d.processing.operations.fade_mask(volume,
volume = qim3d.operations.fade_mask(volume,
geometry = geometry,
axis = axis,
decay_rate = decay_rate,
......
......@@ -43,9 +43,9 @@ class Interface(BaseInterface):
"""
Parameters:
-----------
show_header (bool, optional): If true, prints starting info into terminal. Default is False
verbose (bool, optional): If true, prints info during session into terminal. Defualt is False.
figsize (int, optional): Sets the size of plots displaying the slices. Default is 8.
display_saturation_percentile (int, optional): Sets the display saturation percentile. Defaults to 99.
"""
super().__init__(
title = "Data Explorer",
......
......@@ -74,7 +74,6 @@ class Convert:
Args:
tif_path (str): path to the tiff file
zarr_path (str): path to the zarr file
chunks (tuple, optional): chunk size for the zarr file. Defaults to (64, 64, 64).
Returns:
zarr.core.Array: zarr array containing the data from the tiff file
......
......@@ -52,7 +52,7 @@ class Downloader:
downloader = qim3d.io.Downloader()
data = downloader.Cowry_Shell.Cowry_DOWNSAMPLED(load_file=True)
qim3d.viz.orthogonal(data, cmap = "magma")
qim3d.viz.slicer_orthogonal(data, color_map="magma")
```
![cowry shell](assets/screenshots/cowry_shell_slicer.gif)
"""
......
......@@ -570,6 +570,10 @@ class DataLoader:
Args:
path (str): Directory path
returns:
numpy.ndarray, numpy.memmap or tuple: The loaded volume.
If 'self.return_metadata' is True, returns a tuple (volume, metadata).
"""
import pydicom
......
......@@ -7,7 +7,7 @@ Example:
import qim3d
# Generate synthetic blob
synthetic_blob = qim3d.generate.blob(noise_scale = 0.015)
synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015)
qim3d.io.save("fly.tif", synthetic_blob)
```
......@@ -17,7 +17,7 @@ Example:
import qim3d
# Generate synthetic blob
synthetic_blob = qim3d.generate.blob(noise_scale = 0.015)
synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015)
qim3d.io.save("slices", synthetic_blob, basename="fly-slices", sliced_dim=0)
```
......@@ -438,9 +438,9 @@ def save(
import qim3d
# Generate synthetic blob
synthetic_blob = qim3d.generate.blob(noise_scale = 0.015)
vol = qim3d.generate.noise_object(noise_scale = 0.015)
qim3d.io.save("blob.tif", synthetic_blob, replace=True)
qim3d.io.save("blob.tif", vol, replace=True)
```
Volumes can also be saved with one file per slice:
......@@ -448,9 +448,9 @@ def save(
import qim3d
# Generate synthetic blob
synthetic_blob = qim3d.generate.blob(noise_scale = 0.015)
vol = qim3d.generate.noise_object(noise_scale = 0.015)
qim3d.io.save("slices", synthetic_blob, basename="blob-slices", sliced_dim=0)
qim3d.io.save("slices", vol, basename="blob-slices", sliced_dim=0)
```
"""
......@@ -479,14 +479,14 @@ def save_mesh(
```python
import qim3d
vol = qim3d.generate.blob(base_shape=(32, 32, 32),
vol = qim3d.generate.noise_object(base_shape=(32, 32, 32),
final_shape=(32, 32, 32),
noise_scale=0.05,
order=1,
gamma=1.0,
max_value=255,
threshold=0.5)
mesh = qim3d.processing.create_mesh(vol)
mesh = qim3d.mesh.from_volume(vol)
qim3d.io.save_mesh("mesh.obj", mesh)
```
"""
......
......@@ -31,7 +31,7 @@ def from_volume(
Example:
```python
import qim3d
vol = qim3d.generate.blob(base_shape=(128,128,128),
vol = qim3d.generate.noise_object(base_shape=(128,128,128),
final_shape=(128,128,128),
noise_scale=0.03,
order=1,
......@@ -40,7 +40,7 @@ def from_volume(
threshold=0.5,
dtype='uint8'
)
mesh = qim3d.processing.create_mesh(vol, step_size=3)
mesh = qim3d.mesh.from_volume(vol, step_size=3)
qim3d.viz.mesh(mesh.vertices, mesh.faces)
```
<iframe src="https://platform.qim.dk/k3d/mesh_visualization.html" width="100%" height="500" frameborder="0"></iframe>
......
......@@ -40,18 +40,21 @@ def train_model(
val_loss (dict): Dictionary with average losses and batch losses for validation loop.
Example:
import qim3d
from qim3d.ml import train_model
# defining the model.
model = qim3d.utils.UNet()
model = qim3d.ml.UNet()
# choosing the hyperparameters
hyperparameters = qim3d.utils.hyperparameters(model)
hyperparameters = qim3d.ml.models.Hyperparameters(model)
# DataLoaders
train_loader = MyTrainLoader()
val_loader = MyValLoader()
# training the model.
train_loss,val_loss = train_model(model, hyperparameters, train_loader, val_loader)
train_loss,val_loss = qim3d.ml.train_model(model, hyperparameters, train_loader, val_loader)
"""
params_dict = hyperparameters()
n_epochs = params_dict["n_epochs"]
......@@ -186,9 +189,10 @@ def inference(data: torch.utils.data.Dataset, model: torch.nn.Module) -> tuple[t
- The function does not assume the model is already in evaluation mode (model.eval()).
Example:
import qim3d
dataset = MySegmentationDataset()
model = MySegmentationModel()
inference(data,model)
qim3d.ml.inference(data,model)
"""
# Get device
......
......@@ -104,10 +104,10 @@ class Hyperparameters:
# This examples shows how to define a UNet model and its hyperparameters.
# Defining the model
my_model = qim3d.models.UNet(size='medium')
my_model = qim3d.ml.UNet(size='medium')
# Choosing the hyperparameters
hyperparams = qim3d.models.Hyperparameters(model=my_model, n_epochs=20, learning_rate=0.001)
hyperparams = qim3d.ml.Hyperparameters(model=my_model, n_epochs=20, learning_rate=0.001)
params_dict = hyperparams() # Get the hyperparameters
optimizer = params_dict['optimizer']
......
......@@ -30,15 +30,15 @@ def remove_background(
import qim3d
vol = qim3d.examples.cement_128x128x128
qim3d.viz.slices_grid(vol, vmin=0, vmax=255)
fig1 = qim3d.viz.slices_grid(vol, value_min=0, value_max=255, num_slices=5, display_figure=True)
```
![operations-remove_background_before](assets/screenshots/operations-remove_background_before.png)
```python
vol_filtered = qim3d.processing.operations.remove_background(vol,
vol_filtered = qim3d.operations.remove_background(vol,
min_object_radius=3,
background="bright")
qim3d.viz.slices_grid(vol_filtered, vmin=0, vmax=255)
fig2 = qim3d.viz.slices_grid(vol_filtered, value_min=0, value_max=255, num_slices=5, display_figure=True)
```
![operations-remove_background_after](assets/screenshots/operations-remove_background_after.png)
"""
......@@ -81,15 +81,16 @@ def fade_mask(
Example:
```python
import qim3d
qim3d.viz.vol(vol)
vol = qim3d.io.load('yourVolume.tif')
qim3d.viz.volumetric(vol)
```
Image before edge fading has visible artifacts from the support. Which obscures the object of interest.
![operations-edge_fade_before](assets/screenshots/operations-edge_fade_before.png)
```python
import qim3d
vol_faded = qim3d.processing.operations.edge_fade(vol, decay_rate=4, ratio=0.45, geometric='cylindrical')
qim3d.viz.vol(vol_faded)
vol_faded = qim3d.operations.fade_mask(vol, decay_rate=4, ratio=0.45, geometric='cylindrical')
qim3d.viz.volumetrics(vol_faded)
```
Afterwards the artifacts are faded out, making the object of interest more visible for visualization purposes.
![operations-edge_fade_after](assets/screenshots/operations-edge_fade_after.png)
......
......@@ -40,7 +40,7 @@ def segment_layers(data: np.ndarray,
layers = qim3d.processing.segment_layers(layers_image, n_layers = 2)
layer_lines = qim3d.processing.get_lines(layers)
from matplotlib import pyplot as plt
import matplotlib.pyplot as plt
plt.imshow(layers_image, cmap='gray')
plt.axis('off')
......
......@@ -50,7 +50,7 @@ def local_thickness(
# Generate synthetic collection of blobs
num_objects = 15
synthetic_collection, labels = qim3d.generate.collection(num_objects = num_objects)
synthetic_collection, labels = qim3d.generate.noise_object_collection(num_objects = num_objects)
# Extract one slice to show that localthickness works on 2D slices too
slice = synthetic_collection[:,:,50]
......
......@@ -24,17 +24,17 @@ def watershed(bin_vol: np.ndarray, min_distance: int = 5) -> tuple[np.ndarray, i
import qim3d
vol = qim3d.examples.cement_128x128x128
binary = qim3d.processing.filters.gaussian(vol, sigma = 2)<60
bin_vol = qim3d.filters.gaussian(vol, sigma = 2)<60
qim3d.viz.slices_grid(binary, axis=1)
fig1 = qim3d.viz.slices_grid(bin_vol, slice_axis=1, display_figure=True)
```
![operations-watershed_before](assets/screenshots/operations-watershed_before.png)
```python
labeled_volume, num_labels = qim3d.processing.operations.watershed(binary)
labeled_volume, num_labels = qim3d.segmentation.watershed(bin_vol)
cmap = qim3d.viz.colormaps.objects(num_labels)
qim3d.viz.slices_grid(labeled_volume, axis = 1, cmap = cmap)
cmap = qim3d.viz.colormaps.segmentation(num_labels)
fig2 = qim3d.viz.slices_grid(labeled_volume, slice_axis=1, color_map=cmap, display_figure=True)
```
![operations-watershed_after](assets/screenshots/operations-watershed_after.png)
......
......@@ -83,7 +83,7 @@ def get_3d_cc(image: np.ndarray) -> CC:
```python
import qim3d
vol = qim3d.examples.cement_128x128x128[50:150]<60
cc = qim3d.processing.get_3d_cc(vol)
cc = qim3d.segmentation.get_3d_cc(vol)
```
"""
connected_components, num_connected_components = label(image)
......
from . import _doi
from ._doi import *
from ._system import Memory
from ._misc import (
......
......@@ -59,10 +59,11 @@ def get_bibtex(doi: str):
def custom_header(doi: str, header: str) -> str:
"""Allows a custom header to be passed
For example:
Example:
import qim3d
doi = "https://doi.org/10.1101/2022.11.08.515664"
header = {"Accept": "text/bibliography"}
response = qim3d.utils.doi.cusom_header(doi, header)
custom_header = qim3d.utils.custom_header(doi, header)
"""
return _log_and_get_text(doi, header)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment