Skip to content

Commit

Permalink
Merge pull request #121 from dkazanc/libraryci
Browse files Browse the repository at this point in the history
Major Documentation update and some CI changes
  • Loading branch information
dkazanc authored Jan 6, 2025
2 parents 4c60a87 + 7651843 commit 2c9e7c9
Show file tree
Hide file tree
Showing 54 changed files with 2,658 additions and 2,605 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/libtomophantom_conda_upload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: libtomophantom_conda_upload

on:
push:
branches:
- master

jobs:
build-linux:
runs-on: ubuntu-22.04

defaults:
run:
shell: bash -l {0}

steps:
- name: Checkout repository code
uses: actions/checkout@v4

# setup Python 3.10
- name: Setup Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install dependencies with Conda
run: |
$CONDA/bin/conda install -c conda-forge conda-build anaconda-client
$CONDA/bin/conda install --solver=classic conda-forge::conda-libmamba-solver conda-forge::libmamba conda-forge::libmambapy conda-forge::libarchive
$CONDA/bin/conda install -c conda-forge cmake
$CONDA/bin/conda update conda
$CONDA/bin/conda update conda-build
$CONDA/bin/conda list
- name: Decrypt a secret
run: ./.scripts/decrypt_secret.sh
env:
LARGE_SECRET_PASSPHRASE: ${{ secrets.LARGE_SECRET_PASSPHRASE }}

- name: Upload the tested package to conda cloud
run: |
chmod +x ./.scripts/conda_upload_lib.sh
./.scripts/conda_upload_lib.sh
24 changes: 12 additions & 12 deletions .github/workflows/tomophantom_conda_upload.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
name: tomohantom_conda_upload
name: tomophantom_conda_upload

on: [push]
on:
push:
branches:
- master

jobs:
build-linux:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

defaults:
run:
shell: bash -l {0}

steps:
- name: Checkout repository code
uses: actions/checkout@v3
with:
ref: "master"
fetch-depth: 0
uses: actions/checkout@v4

# setup Python 3.9
- name: Setup Python 3.9
uses: actions/setup-python@v2
# setup Python 3.10
- name: Setup Python 3.10
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: '3.10'

- name: Install dependencies with Conda
run: |
$CONDA/bin/conda install -c conda-forge conda-build anaconda-client
$CONDA/bin/conda install -c conda-forge conda-build anaconda-client
$CONDA/bin/conda update conda
$CONDA/bin/conda update conda-build
$CONDA/bin/conda list
Expand Down
4 changes: 2 additions & 2 deletions .scripts/conda_upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ mkdir ~/conda-bld
conda config --set anaconda_upload no
export CONDA_BLD_PATH=~/conda-bld

export CIL_VERSION=3.0
export CIL_VERSION=3.0.1
$CONDA/bin/conda build conda-recipe . -c httomo

# upload packages to conda
find $CONDA_BLD_PATH/$OS -name *.tar.bz2 | while read file
find $CONDA_BLD_PATH/$OS -name '*.tar.bz2' | while read -r file
do
echo $file
$CONDA/bin/anaconda -v --show-traceback --token $CONDA_TOKEN upload $file --force
Expand Down
20 changes: 20 additions & 0 deletions .scripts/conda_upload_lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

PKG_NAME=libtomophantom
USER=httomo-team
OS=linux-64
CONDA_TOKEN=$(cat $HOME/.secrets/my_secret.json)

mkdir ~/conda-bld
conda config --set anaconda_upload no
export CONDA_BLD_PATH=~/conda-bld

export CIL_VERSION=3.0.1
$CONDA/bin/conda build conda-recipe_library . -c httomo

# upload packages to conda
find $CONDA_BLD_PATH/$OS -name '*.tar.bz2' | while read -r file
do
echo $file
$CONDA/bin/anaconda -v --show-traceback --token $CONDA_TOKEN upload $file --force
done
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ChangeLog

## v3.0.1 (2024.12)

* Documentation has been updated in January 2025 with a lot of additional information, API links, tutorials, etc.
* Docstrings of the modules were updated with the references to documentation.


## v3.0 (2023.12)
* Project reorganised into two parts: a library that is build as a shared object using Cmake and Ctypes bindings and pure Python part that can be
installed separately.
Expand Down
199 changes: 100 additions & 99 deletions Demos/2D/Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

model = 4 # select a model number from the library file (Phantom2DLibrary)
N_size = 512 # set the desired dimension of the phantom
# one can specify an exact path to the parameters file
path = os.path.dirname(tomophantom.__file__)
path_library2D = os.path.join(path, "phantomlib", "Phantom2DLibrary.dat")

Expand All @@ -29,6 +28,7 @@
plt.imshow(phantom_2D, vmin=0, vmax=1, cmap="BuPu")
plt.colorbar(ticks=[0, 0.5, 1], orientation="vertical")
plt.title("{}" "{}".format("2D Phantom using model no.", model))
plt.show()

# %%
# Parameters to generate a sinogram
Expand All @@ -51,110 +51,111 @@
plt.imshow(sino_an, vmin=0, vmax=300, cmap="BuPu")
plt.colorbar(ticks=[0, 150, 300], orientation="vertical")
plt.title("{}" "{}".format("Analytical sinogram of model no.", model))
# %%
# generate numerical sinogram
angles_num = int(0.5 * np.pi * N_size)
# angles number
angles = np.linspace(0.0, 179.9, angles_num, dtype="float32")
P = int(np.sqrt(2) * N_size) # detectors

tic = timeit.default_timer()
sino_num = TomoP2D.SinoNum(phantom_2D, P, angles)
toc = timeit.default_timer()
Run_time = toc - tic
print("Numerical sinogram has been generated in {} seconds".format(Run_time))

plt.figure()
plt.rcParams.update({"font.size": 21})
plt.imshow(sino_num, vmin=0, vmax=300, cmap="BuPu")
plt.colorbar(ticks=[0, 150, 300], orientation="vertical")
plt.title("{}" "{}".format("Numerical sinogram of model no.", model))
plt.show()
# # %%
# # generate numerical sinogram
# angles_num = int(0.5 * np.pi * N_size)
# # angles number
# angles = np.linspace(0.0, 179.9, angles_num, dtype="float32")
# P = int(np.sqrt(2) * N_size) # detectors

# tic = timeit.default_timer()
# sino_num = TomoP2D.SinoNum(phantom_2D, P, angles)
# toc = timeit.default_timer()
# Run_time = toc - tic
# print("Numerical sinogram has been generated in {} seconds".format(Run_time))

# plt.figure()
# plt.imshow(abs(sino_an-sino_num), vmin=0, vmax=0.001, cmap="BuPu")
# plt.colorbar(ticks=[0, 0.02, 0.05], orientation='vertical')
# plt.title('Analytical vs Numerical singograms')
# %%


###################################################################
from tomobar.methodsDIR import RecToolsDIR

angles_rad = angles * (np.pi / 180.0)

# get numerical sinogram (ASTRA-toolbox)
Rectools = RecToolsDIR(
DetectorsDimH=P, # DetectorsDimH # detector dimension (horizontal)
DetectorsDimV=None, # DetectorsDimV # detector dimension (vertical) for 3D case only
CenterRotOffset=0.0, # Center of Rotation (CoR) scalar (for 3D case only)
AnglesVec=angles_rad, # array of angles in radians
ObjSize=N_size, # a scalar to define reconstructed object dimensions
device_projector="cpu",
)

tic = timeit.default_timer()
sino_num_ASTRA = Rectools.FORWPROJ(phantom_2D) # generate numerical sino (Ax)
toc = timeit.default_timer()
Run_time = toc - tic
print("Numerical (ASTRA) sinogram has been generated in {} seconds".format(Run_time))

plt.figure()
plt.rcParams.update({"font.size": 21})
plt.imshow(sino_num_ASTRA, vmin=0, vmax=150, cmap="BuPu")
plt.colorbar(ticks=[0, 150, 250], orientation="vertical")
plt.title("{}" "{}".format("Numerical sinogram (ASTRA) of model no.", model))
# %%
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print("Reconstructing analytical sinogram using Fourier Slice method")
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
# plt.rcParams.update({"font.size": 21})
# plt.imshow(sino_num, vmin=0, vmax=300, cmap="BuPu")
# plt.colorbar(ticks=[0, 150, 300], orientation="vertical")
# plt.title("{}" "{}".format("Numerical sinogram of model no.", model))

# # plt.figure()
# # plt.imshow(abs(sino_an-sino_num), vmin=0, vmax=0.001, cmap="BuPu")
# # plt.colorbar(ticks=[0, 0.02, 0.05], orientation='vertical')
# # plt.title('Analytical vs Numerical singograms')
# # %%


# ###################################################################
# from tomobar.methodsDIR import RecToolsDIR

# angles_rad = angles * (np.pi / 180.0)

# # get numerical sinogram (ASTRA-toolbox)
# Rectools = RecToolsDIR(
# DetectorsDimH=P, # DetectorsDimH # detector dimension (horizontal)
# DetectorsDimV=None, # DetectorsDimV # detector dimension (vertical) for 3D case only
# CenterRotOffset=0.0, # Center of Rotation (CoR) scalar (for 3D case only)
# AnglesVec=angles_rad, # array of angles in radians
# ObjSize=N_size, # a scalar to define reconstructed object dimensions
# device_projector="cpu",
# )

# tic = timeit.default_timer()
# sino_num_ASTRA = Rectools.FORWPROJ(phantom_2D) # generate numerical sino (Ax)
# toc = timeit.default_timer()
# Run_time = toc - tic
# print("Numerical (ASTRA) sinogram has been generated in {} seconds".format(Run_time))

RecFourier = Rectools.FOURIER(sino_an, "linear")
# plt.figure()
# plt.rcParams.update({"font.size": 21})
# plt.imshow(sino_num_ASTRA, vmin=0, vmax=150, cmap="BuPu")
# plt.colorbar(ticks=[0, 150, 250], orientation="vertical")
# plt.title("{}" "{}".format("Numerical sinogram (ASTRA) of model no.", model))
# # %%
# print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
# print("Reconstructing analytical sinogram using Fourier Slice method")
# print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")

plt.figure()
plt.imshow(RecFourier, vmin=0, vmax=1, cmap="BuPu")
plt.colorbar(ticks=[0, 0.5, 1], orientation="vertical")
plt.title("Fourier slice reconstruction")
# %%
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print("Reconstructing analytical sinogram using FBP (tomobar)...")
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
# x = Atools.backproj(sino_an) # generate backprojection (A'b)
# RecFourier = Rectools.FOURIER(sino_an, "linear")

plt.figure()
plt.subplot(121)
plt.imshow(sino_an, cmap="BuPu")
plt.title("Analytical sinogram")
plt.subplot(122)
plt.imshow(sino_num_ASTRA, cmap="BuPu")
plt.title("Numerical sinogram")
plt.show()
# calculate norm
# rmse1 = np.linalg.norm(sino_an - sino_num_ASTRA)/np.linalg.norm(sino_num_ASTRA)
# plt.figure()
# plt.imshow(RecFourier, vmin=0, vmax=1, cmap="BuPu")
# plt.colorbar(ticks=[0, 0.5, 1], orientation="vertical")
# plt.title("Fourier slice reconstruction")
# # %%
# print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
# print("Reconstructing analytical sinogram using FBP (tomobar)...")
# print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
# # x = Atools.backproj(sino_an) # generate backprojection (A'b)

print("Reconstructing analytical sinogram using FBP (astra TB)...")
FBPrec1 = Rectools.FBP(sino_an)
plt.figure()
plt.imshow(FBPrec1, vmin=0, vmax=1, cmap="BuPu")
plt.colorbar(ticks=[0, 0.5, 1], orientation="vertical")
plt.title("FBP Reconstructed Phantom (analyt)")
# plt.figure()
# plt.subplot(121)
# plt.imshow(sino_an, cmap="BuPu")
# plt.title("Analytical sinogram")
# plt.subplot(122)
# plt.imshow(sino_num_ASTRA, cmap="BuPu")
# plt.title("Numerical sinogram")
# plt.show()
# # calculate norm
# # rmse1 = np.linalg.norm(sino_an - sino_num_ASTRA)/np.linalg.norm(sino_num_ASTRA)

# print("Reconstructing analytical sinogram using FBP (astra TB)...")
# FBPrec1 = Rectools.FBP(sino_an)
# plt.figure()
# plt.imshow(FBPrec1, vmin=0, vmax=1, cmap="BuPu")
# plt.colorbar(ticks=[0, 0.5, 1], orientation="vertical")
# plt.title("FBP Reconstructed Phantom (analyt)")

print("Reconstructing numerical sinogram using FBP (astra TB)...")
FBPrec2 = Rectools.FBP(sino_num_ASTRA)
# print("Reconstructing numerical sinogram using FBP (astra TB)...")
# FBPrec2 = Rectools.FBP(sino_num_ASTRA)

plt.figure()
plt.imshow(FBPrec2, vmin=0, vmax=1, cmap="BuPu")
plt.colorbar(ticks=[0, 0.5, 1], orientation="vertical")
plt.title("FBP Reconstructed Phantom (numeric)")
# plt.figure()
# plt.imshow(FBPrec2, vmin=0, vmax=1, cmap="BuPu")
# plt.colorbar(ticks=[0, 0.5, 1], orientation="vertical")
# plt.title("FBP Reconstructed Phantom (numeric)")

plt.figure()
plt.imshow(abs(FBPrec1 - FBPrec2), vmin=0, vmax=0.05, cmap="BuPu")
plt.colorbar(ticks=[0, 0.02, 0.05], orientation="vertical")
plt.title("FBP rec differences")
# rmse2 = np.linalg.norm(FBPrec1 - FBPrec2)/np.linalg.norm(FBPrec2)

Qtools = QualityTools(phantom_2D, FBPrec1)
RMSE_FBP1 = Qtools.rmse()
Qtools = QualityTools(phantom_2D, FBPrec2)
RMSE_FBP2 = Qtools.rmse()
print("RMSE for FBP (analyt) {}".format(RMSE_FBP1))
print("RMSE for FBP (numeric) {}".format(RMSE_FBP2))
# plt.figure()
# plt.imshow(abs(FBPrec1 - FBPrec2), vmin=0, vmax=0.05, cmap="BuPu")
# plt.colorbar(ticks=[0, 0.02, 0.05], orientation="vertical")
# plt.title("FBP rec differences")
# # rmse2 = np.linalg.norm(FBPrec1 - FBPrec2)/np.linalg.norm(FBPrec2)

# Qtools = QualityTools(phantom_2D, FBPrec1)
# RMSE_FBP1 = Qtools.rmse()
# Qtools = QualityTools(phantom_2D, FBPrec2)
# RMSE_FBP2 = Qtools.rmse()
# print("RMSE for FBP (analyt) {}".format(RMSE_FBP1))
# print("RMSE for FBP (numeric) {}".format(RMSE_FBP2))
5 changes: 0 additions & 5 deletions Demos/2D/Object2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
Script to generate 2D/3D analytical objects and their sinograms
Recursively adding objects and sinos one can build a required model
>>>>> Optional dependencies (reconstruction mainly): <<<<<
1. ASTRA toolbox: conda install -c astra-toolbox astra-toolbox
2. tomobar: conda install -c dkazanc tomobar
or install from https://github.com/dkazanc/ToMoBAR
@author: Daniil Kazantsev
"""
import numpy as np
Expand Down
Loading

0 comments on commit 2c9e7c9

Please sign in to comment.