Skip to content

Commit

Permalink
completing setup, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dkazanc committed Mar 21, 2023
1 parent e9b9895 commit d06aea2
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 81 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/tomobar_conda_upload.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: tomobar_conda_upload

on: [push, pull_request, pull_request_target]
on: [push]

jobs:
build-linux:
Expand All @@ -20,8 +20,6 @@ jobs:
- name: Install dependencies with Conda
run: |
$CONDA/bin/conda env update --file conda-recipe/environment/environment.yml --name base
conda config --set anaconda_upload no
export VERSION=`date +%Y.%m`
- name: Decrypt a secret
run: ./.scripts/decrypt_secret.sh
Expand Down
23 changes: 15 additions & 8 deletions .scripts/conda_upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ CONDA_TOKEN=$(cat $HOME/.secrets/my_secret.json)
mkdir ~/conda-bld
conda config --set anaconda_upload no
export CONDA_BLD_PATH=~/conda-bld
export VERSION=`date +%Y.%m`
conda install --yes anaconda-client
conda build . --numpy=1.20 --python=3.9
conda build . --numpy=1.21 --python=3.9
conda build . --numpy=1.22 --python=3.9
conda build . --numpy=1.20 --python=3.10
conda build . --numpy=1.21 --python=3.10
conda build . --numpy=1.22 --python=3.10
#export VERSION=`date +%Y.%m`
#conda install --yes anaconda-client
#conda build . --numpy=1.20 --python=3.9
#conda build . --numpy=1.21 --python=3.9
#conda build . --numpy=1.22 --python=3.9
#conda build . --numpy=1.20 --python=3.10
#conda build . --numpy=1.21 --python=3.10
#conda build . --numpy=1.22 --python=3.10

for python_ver in 3.9 3.10; do
for numpy_ver in 1.21 1.22 1.23 1.24; do
export VERSION=`date +%Y.%m`"-py"$python_ver"_np"$numpy_ver
conda build . --numpy $numpy_ver --python $python_ver
done
done

# upload packages to conda
find $CONDA_BLD_PATH/$OS -name *.tar.bz2 | while read file
Expand Down
27 changes: 0 additions & 27 deletions Demos/Python/DemoFISTA_artifacts3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,33 +255,6 @@
plt.title('3D Huber Rec, sagittal')
plt.show()

# adding RING minimisation component (better model for data with rings - different from GH!)
#data.update({'huber_threshold' : None})
_data_.update({'ring_weights_threshold' : 2.0})
_data_.update({'ring_tuple_halfsizes' : (9,7,9)})

# Run FISTA reconstrucion algorithm with 3D regularisation and a better ring model
RecFISTA_HuberRING_TV = Rectools.FISTA(_data_, _algorithm_, _regularisation_)

Qtools = QualityTools(phantom_tm, RecFISTA_HuberRING_TV)
RMSE_FISTA_HUBER_RING_TV = Qtools.rmse()
print("RMSE for FISTA-OS-Huber-Ring-TV is {}".format(RMSE_FISTA_HUBER_RING_TV))

sliceSel = int(0.5*N_size)
max_val = 1
plt.figure()
plt.subplot(131)
plt.imshow(RecFISTA_HuberRING_TV[sliceSel,:,:],vmin=0, vmax=max_val)
plt.title('3D HuberRing Rec, axial')

plt.subplot(132)
plt.imshow(RecFISTA_HuberRING_TV[:,sliceSel,:],vmin=0, vmax=max_val)
plt.title('3D HuberRing Rec, coronal')

plt.subplot(133)
plt.imshow(RecFISTA_HuberRING_TV[:,:,sliceSel],vmin=0, vmax=max_val)
plt.title('3D HuberRing Rec, sagittal')
plt.show()
#%%
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print ("Reconstructing with FISTA-OS-SWLS-TV using tomobar")
Expand Down
1 change: 0 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ conda install -c savu-dep tomobar
export VERSION=`date +%Y.%m` (unix) / set VERSION=2020.10 (Windows)
conda build conda-recipe/ --numpy 1.15 --python 3.7
conda install -c file://${CONDA_PREFIX}/conda-bld/ tomobar --force-reinstall
conda install tomobar --use-local --force-reinstall # if Python2
```

### Python development environment
Expand Down
2 changes: 1 addition & 1 deletion conda-recipe/bld.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ ECHO VERSION Not Defined.
exit 1
)

"%PYTHON%" -m pip install -e .
"%PYTHON%" -m pip install .
if errorlevel 1 exit 1
2 changes: 1 addition & 1 deletion conda-recipe/build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

python -m pip install -e .
python -m pip install .
4 changes: 2 additions & 2 deletions conda-recipe/conda_build_config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
python:
- 3.10
numpy:
- 1.22
numpy:
- 1.24
24 changes: 13 additions & 11 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@ package:
version: {{ environ['VERSION'] }}

source:
path: ..
path: ../

build:
preserve_egg_dir: False
number: 0

test:
requires:
- pip
- pytest
source_files:
- tests/*
commands:
- pip check
- pytest

requirements:
host:
- python
Expand All @@ -24,15 +34,7 @@ requirements:
- pillow
- scikit-image
- pytest
# test:
# requires:
# - pip
# - pytest
# source_files:
# - tests/*
# commands:
# - pip check
# - pytest


about:
home: https://github.com/dkazanc/ToMoBAR
Expand All @@ -41,4 +43,4 @@ about:
A collection of direct and iterative methods for parallel beam tomography
extra:
recipe-maintainers:
- dkazanc
- dkazanc
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools>=42", "wheel", "setuptools-git-versioning"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
packages = ["tomobar"]
packages = ["tomobar", "tomobar.supp"]

[tool.setuptools-git-versioning]
enabled = true
Expand Down Expand Up @@ -45,7 +45,6 @@ dev = [
"h5py"
]


[project.urls]
"Repository" = "https://github.com/dkazanc/ToMoBAR"

Expand Down
Binary file removed tomobar/__init__.pyc
Binary file not shown.
26 changes: 1 addition & 25 deletions tomobar/methodsIR.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,9 @@ def dict_check(self, _data_, _algorithm_, _regularisation_):
# Students#t data model to supress artifacts
if 'studentst_threshold' not in _data_:
_data_['studentst_threshold'] = None
# threshold to produce additional weights to supress ring artifacts
if 'ring_weights_threshold' not in _data_:
_data_['ring_weights_threshold'] = None
# defines the strength of Huber penalty to supress artifacts 1 = Huber, > 1 more strength
if 'ring_huber_power' not in _data_:
_data_['ring_huber_power'] = 1.75
# a tuple for half window sizes as [detector, angles, number of projections]
if 'ring_tuple_halfsizes' not in _data_:
_data_['ring_tuple_halfsizes'] = (9,7,9)
# Group-Huber data model to supress full rings of the same intensity
if 'ringGH_lambda' not in _data_:
_data_['ringGH_lambda'] = None
Expand Down Expand Up @@ -278,9 +272,7 @@ class RecToolsIR:
--OS_number # the number of subsets, if None or 1 - classical (full data) algorithm
--huber_threshold # threshold for Huber function to apply to data model (supress outliers)
--studentst_threshold # threshold for Students't function to apply to data model (supress outliers)
--ring_weights_threshold # threshold to produce additional weights to supress ring artifacts
--ring_huber_power # defines the strength of Huber penalty to supress artifacts 1 = Huber, > 1 more penalising
--ring_tuple_halfsizes # a tuple for half window sizes as [detector, angles, num of projections]
--ringGH_lambda # a parameter for Group-Huber data model to supress full rings of the same intensity
--ringGH_accelerate # Group-Huber data model acceleration factor (use carefully to avoid divergence, 50 default)
--beta_SWLS # a regularisation parameter for stripe-weighted LS model (given as a vector size of DetectorsDimH)
Expand Down Expand Up @@ -482,12 +474,6 @@ def FISTA(self, _data_, _algorithm_, _regularisation_):
else:
r = r_x - np.multiply(L_const_inv,vec)

if ((_data_['OS_number'] != 1) and (_data_['ring_weights_threshold'] is not None) and (iter_no > 0)):
# Ordered subset approach for a better ring model
res_full = self.Atools.forwproj(X_t) - _data_['projection_norm_data']
rings_weights = RING_WEIGHTS(np.float32(res_full), _data_['ring_tuple_halfsizes'][0], _data_['ring_tuple_halfsizes'][1], _data_['ring_tuple_halfsizes'][2])
ring_function_weight = np.ones(np.shape(res_full))
ring_function_weight[(np.where(np.abs(rings_weights) > _data_['ring_weights_threshold']))] = np.divide(_data_['ring_weights_threshold'], np.abs(rings_weights[(np.where(np.abs(rings_weights) > _data_['ring_weights_threshold']))])**_data_['ring_huber_power'])
# loop over subsets (OS)
for sub_ind in range(_data_['OS_number']):
X_old = X
Expand Down Expand Up @@ -519,8 +505,6 @@ def FISTA(self, _data_, _algorithm_, _regularisation_):
# ring removal part for Group-Huber (GH) fidelity (2D)
if ((_data_['ringGH_lambda'] is not None) and (iter_no > 0)):
res[:,0:None] = res[:,0:None] + _data_['ringGH_accelerate']*r_x[:,0]
if ((_data_['ring_weights_threshold'] is not None) and (iter_no > 0)):
res = np.multiply(ring_function_weight[indVec,:],res)
else: # 3D
if (self.datafidelity == 'LS'):
# 3D Least-squares (LS) data fidelity - OS (linear)
Expand All @@ -543,8 +527,6 @@ def FISTA(self, _data_, _algorithm_, _regularisation_):
if ((_data_['ringGH_lambda'] is not None) and (iter_no > 0)):
for ang_index in range(len(indVec)):
res[:,ang_index,:] = res[:,ang_index,:] + _data_['ringGH_accelerate']*r_x
if ((_data_['ring_weights_threshold'] is not None) and (iter_no > 0)):
res = np.multiply(ring_function_weight[:,indVec,:],res)
else: # CLASSICAL all-data approach
if (self.datafidelity == 'LS'):
# full residual for LS fidelity
Expand All @@ -566,12 +548,6 @@ def FISTA(self, _data_, _algorithm_, _regularisation_):
res[:,ang_index,:] = res[:,ang_index,:] + _data_['ringGH_accelerate']*r_x
vec = res.sum(axis = 1)
r = r_x - np.multiply(L_const_inv,vec)
if ((_data_['ring_weights_threshold'] is not None) and (iter_no > 0)):
# Approach for a better ring model
rings_weights = RING_WEIGHTS(np.float32(res), _data_['ring_tuple_halfsizes'][0], _data_['ring_tuple_halfsizes'][1], _data_['ring_tuple_halfsizes'][2])
ring_function_weight = np.ones(np.shape(res))
ring_function_weight[(np.where(np.abs(rings_weights) > _data_['ring_weights_threshold']))] = np.divide(_data_['ring_weights_threshold'], np.abs(rings_weights[(np.where(np.abs(rings_weights) > _data_['ring_weights_threshold']))])**_data_['ring_huber_power'])
res = np.multiply(ring_function_weight,res)
if (self.datafidelity == 'SWLS'):
res = self.Atools.forwproj(X_t) - _data_['projection_norm_data']
if (self.geom == '2D'):
Expand Down Expand Up @@ -681,7 +657,7 @@ def ADMM_Atb(b):
if (_algorithm_['nonnegativity'] == 'ENABLE'):
X[X < 0.0] = 0.0
# z-update with relaxation
zold = z.copy();
zold = z.copy()
x_hat = _algorithm_['ADMM_relax_par']*X + (1.0 - _algorithm_['ADMM_relax_par'])*zold;
if (self.geom == '2D'):
x_prox_reg = (x_hat + u).reshape([self.ObjSize, self.ObjSize])
Expand Down
Binary file removed tomobar/supp/__init__.pyc
Binary file not shown.
Binary file removed tomobar/supp/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file removed tomobar/supp/__pycache__/astraOP.cpython-310.pyc
Binary file not shown.

0 comments on commit d06aea2

Please sign in to comment.