Skip to content

Commit 053e780

Browse files
authored
adding precommit hook (#132)
undefined
1 parent 83b05be commit 053e780

File tree

19 files changed

+152
-100
lines changed

19 files changed

+152
-100
lines changed

.github/workflows/conda_upload.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929

3030
# install dependencies with conda
3131
- name: Install dependencies with conda
32-
run: |
32+
run: |
3333
$CONDA/bin/conda env create --name httomolibgpu --file conda/environment.yml
3434
$CONDA/bin/conda run -n httomolibgpu pip install -e .
3535
$CONDA/bin/conda list

.github/workflows/tests_run.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ jobs:
4141
micromamba list
4242
4343
- name: Run tests
44-
run: |
44+
run: |
4545
pytest tests/

.pre-commit-config.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 23.12.1
4+
hooks:
5+
- id: black
6+
language_version: python3
7+
exclude: ^docs/source/examples/
8+
- repo: https://github.com/pre-commit/pre-commit-hooks
9+
rev: v4.5.0
10+
hooks:
11+
- id: trailing-whitespace # This hook trims trailing whitespace.
12+
- id: check-docstring-first # Checks a common error of defining a docstring after code.
13+
- id: check-merge-conflict # Check for files that contain merge conflict strings.
14+
- id: check-yaml # This hook checks yaml files for parseable syntax.
15+
- id: detect-private-key # Detects the presence of private keys.
16+
- id: check-symlinks
17+
- id: check-toml
18+
- repo: https://github.com/pre-commit/pygrep-hooks
19+
rev: v1.10.0
20+
hooks:
21+
- id: python-use-type-annotations
22+
- repo: https://github.com/kynan/nbstripout
23+
rev: 0.6.1
24+
hooks:
25+
- id: nbstripout
26+
exclude: ^docs/source/examples/
27+
- repo: https://github.com/asottile/blacken-docs
28+
rev: 1.16.0
29+
hooks:
30+
- id: blacken-docs
31+
- repo: https://github.com/nbQA-dev/nbQA
32+
rev: 1.7.1
33+
hooks:
34+
- id: nbqa-black

README.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ HTTomolibGPU is a library of GPU accelerated methods for tomography
22
--------------------------------------------------------------------
33

44
**HTTomolibGPU** is a collection of image processing methods in Python for computed tomography.
5-
The methods are GPU-accelerated with the open-source Python library `CuPy <https://cupy.dev/>`_. Most of the
5+
The methods are GPU-accelerated with the open-source Python library `CuPy <https://cupy.dev/>`_. Most of the
66
methods migrated from `TomoPy <https://tomopy.readthedocs.io/en/stable/>`_ and `Savu <https://savu.readthedocs.io/en/latest/>`_ software packages.
77
Some of the methods also have been optimised to ensure higher computational efficiency, before ported to CuPy.
88

99
The purpose of HTTomolibGPU
1010
===========================
1111

12-
**HTTomolibGPU** can be used as a stand-alone library, see Examples section in `Documentation <https://diamondlightsource.github.io/httomolibgpu/>`_.
13-
However, it has been specifically developed to work together with the `HTTomo <https://diamondlightsource.github.io/httomo/>`_ package as
14-
its backend for data processing. HTTomo is a user interface (UI) written in Python for fast big tomographic data processing using
15-
MPI protocols.
12+
**HTTomolibGPU** can be used as a stand-alone library, see Examples section in `Documentation <https://diamondlightsource.github.io/httomolibgpu/>`_.
13+
However, it has been specifically developed to work together with the `HTTomo <https://diamondlightsource.github.io/httomo/>`_ package as
14+
its backend for data processing. HTTomo is a user interface (UI) written in Python for fast big tomographic data processing using
15+
MPI protocols.
1616

1717
Install HTTomolibGPU as a pre-built conda Python package
1818
=========================================================
@@ -28,7 +28,7 @@ Setup the development environment:
2828
==================================
2929

3030
.. code-block:: console
31-
31+
3232
$ git clone [email protected]:DiamondLightSource/httomolibgpu.git # clone the repo
3333
$ conda env create --name httomolibgpu --file conda/environment.yml # install dependencies
3434
$ conda activate httomolibgpu # activate the environment

docs/source/examples/Cor_largesino.ipynb

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@
4343
"\n",
4444
"# Load the sinogram data\n",
4545
"path_lib = os.path.dirname(httomolibgpu.__file__)\n",
46-
"in_file = os.path.abspath(os.path.join(path_lib, '..', \"tests/test_data/\",\"3600proj_sino.npz\"))\n",
46+
"in_file = os.path.abspath(\n",
47+
" os.path.join(path_lib, \"..\", \"tests/test_data/\", \"3600proj_sino.npz\")\n",
48+
")\n",
4749
"l_infile = np.load(in_file)\n",
48-
"sinogram = l_infile['sinogram']\n",
49-
"angles = l_infile['angles']\n",
50+
"sinogram = l_infile[\"sinogram\"]\n",
51+
"angles = l_infile[\"angles\"]\n",
5052
"sinogram = cp.asarray(sinogram)\n",
5153
"\n",
5254
"print(\"The shape of the sinogram is {}\".format(cp.shape(sinogram)))"
@@ -95,7 +97,8 @@
9597
],
9698
"source": [
9799
"from httomolibgpu.recon.rotation import find_center_vo\n",
98-
"print (\"Finding the Center of Rotation for the reconstruction\")\n",
100+
"\n",
101+
"print(\"Finding the Center of Rotation for the reconstruction\")\n",
99102
"cor = find_center_vo(sinogram)\n",
100103
"print(\"The found Center of Rotation is {}\".format(cor))"
101104
]
@@ -126,15 +129,18 @@
126129
],
127130
"source": [
128131
"from httomolibgpu.prep.stripe import remove_all_stripe\n",
129-
"print (\"Remove stripes using remove_all_stripe\")\n",
130132
"\n",
131-
"sino3d = cp.ascontiguousarray(cp.ones((sinogram.shape[0], 3, sinogram.shape[1])), dtype=cp.float32)\n",
132-
"sino3d[:,1,:] = sinogram\n",
133+
"print(\"Remove stripes using remove_all_stripe\")\n",
134+
"\n",
135+
"sino3d = cp.ascontiguousarray(\n",
136+
" cp.ones((sinogram.shape[0], 3, sinogram.shape[1])), dtype=cp.float32\n",
137+
")\n",
138+
"sino3d[:, 1, :] = sinogram\n",
133139
"\n",
134140
"sino3d = remove_all_stripe(sino3d)\n",
135141
"\n",
136142
"plt.figure()\n",
137-
"plt.imshow(sino3d[:,1,:].get())\n",
143+
"plt.imshow(sino3d[:, 1, :].get())\n",
138144
"plt.title(\"Sinogram after stripes removal\")\n",
139145
"plt.show()"
140146
]
@@ -164,14 +170,14 @@
164170
}
165171
],
166172
"source": [
167-
"print (\"Perform Reconstruction using FBP\")\n",
173+
"print(\"Perform Reconstruction using FBP\")\n",
168174
"from httomolibgpu.recon.algorithm import FBP\n",
169175
"\n",
170176
"reconFBP = FBP(sino3d, angles=angles, center=cor)\n",
171177
"reconFBP_np = reconFBP.get()\n",
172178
"\n",
173179
"plt.figure()\n",
174-
"plt.imshow(reconFBP_np[500:2000,1,500:2000],vmin=0,vmax=0.01)\n",
180+
"plt.imshow(reconFBP_np[500:2000, 1, 500:2000], vmin=0, vmax=0.01)\n",
175181
"plt.title(\"Reconstruction with FBP\")\n",
176182
"plt.show()"
177183
]

docs/source/examples/DistortionCorr.ipynb

Lines changed: 21 additions & 13 deletions
Large diffs are not rendered by default.

docs/source/examples/pipeline1_FBP.ipynb

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,25 @@
5151
"\n",
5252
"# Load the projection data\n",
5353
"path_lib = os.path.dirname(httomolibgpu.__file__)\n",
54-
"in_file = os.path.abspath(os.path.join(path_lib, '..', \"tests/test_data/\",'tomo_standard.npz'))\n",
54+
"in_file = os.path.abspath(\n",
55+
" os.path.join(path_lib, \"..\", \"tests/test_data/\", \"tomo_standard.npz\")\n",
56+
")\n",
5557
"datafile = np.load(in_file)\n",
56-
"host_data = datafile['data']\n",
57-
"host_flats = datafile['flats']\n",
58-
"host_darks = datafile['darks']\n",
58+
"host_data = datafile[\"data\"]\n",
59+
"host_flats = datafile[\"flats\"]\n",
60+
"host_darks = datafile[\"darks\"]\n",
5961
"\n",
60-
"print(\"The shape of the data is {} as (projections, detector Y, detector X)\".format(np.shape(host_data)))\n",
62+
"print(\n",
63+
" \"The shape of the data is {} as (projections, detector Y, detector X)\".format(\n",
64+
" np.shape(host_data)\n",
65+
" )\n",
66+
")\n",
6167
"\n",
6268
"print(\"Normalising the data\")\n",
6369
"data = cp.asarray(host_data)\n",
6470
"flats = cp.asarray(host_flats)\n",
6571
"darks = cp.asarray(host_darks)\n",
66-
"data_normalised = normalize(data, flats, darks, cutoff = 10, minus_log = False)\n",
72+
"data_normalised = normalize(data, flats, darks, cutoff=10, minus_log=False)\n",
6773
"\n",
6874
"sliceSel = 64\n",
6975
"data_normalised_np = data_normalised.get()\n",
@@ -100,7 +106,7 @@
100106
"source": [
101107
"from httomolibgpu.recon.rotation import find_center_vo\n",
102108
"\n",
103-
"print (\"Finding the Center of Rotation for the reconstruction\")\n",
109+
"print(\"Finding the Center of Rotation for the reconstruction\")\n",
104110
"cor = find_center_vo(data_normalised, ind=64)\n",
105111
"print(\"The found Center of Rotation is {}\".format(cor))"
106112
]
@@ -131,8 +137,10 @@
131137
"source": [
132138
"from httomolibgpu.prep.phase import paganin_filter_tomopy\n",
133139
"\n",
134-
"print (\"Applying Paganin filter\")\n",
135-
"phase_contrast_data = paganin_filter_tomopy(data_normalised, pixel_size=0.1, dist=50, energy=53, alpha=1e-5)\n",
140+
"print(\"Applying Paganin filter\")\n",
141+
"phase_contrast_data = paganin_filter_tomopy(\n",
142+
" data_normalised, pixel_size=0.1, dist=50, energy=53, alpha=1e-5\n",
143+
")\n",
136144
"\n",
137145
"sliceSel = 64\n",
138146
"phase_contrast_data_np = phase_contrast_data.get()\n",
@@ -176,12 +184,12 @@
176184
}
177185
],
178186
"source": [
179-
"print (\"Perform Reconstruction using FBP\")\n",
187+
"print(\"Perform Reconstruction using FBP\")\n",
180188
"\n",
181189
"from httomolibgpu.recon.algorithm import FBP\n",
182190
"\n",
183191
"angles = np.linspace(0.0 * np.pi / 180.0, 180.0 * np.pi / 180.0, data.shape[0])\n",
184-
" \n",
192+
"\n",
185193
"reconFBP = FBP(phase_contrast_data, angles=angles, center=cor)\n",
186194
"\n",
187195
"reconFBP_np = reconFBP.get()\n",
@@ -226,12 +234,12 @@
226234
}
227235
],
228236
"source": [
229-
"print (\"Perform Reconstruction using Fourier (LPRec)\")\n",
237+
"print(\"Perform Reconstruction using Fourier (LPRec)\")\n",
230238
"\n",
231239
"from httomolibgpu.recon.algorithm import LPRec\n",
232240
"\n",
233241
"angles = np.linspace(0.0 * np.pi / 180.0, 180.0 * np.pi / 180.0, data.shape[0])\n",
234-
" \n",
242+
"\n",
235243
"reconLPRec = LPRec(phase_contrast_data, angles=angles, center=cor)\n",
236244
"\n",
237245
"reconLPRec_np = reconLPRec.get()\n",

docs/source/examples/pipeline2_iterative.ipynb

Lines changed: 26 additions & 16 deletions
Large diffs are not rendered by default.

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
examples/pipeline1_FBP
2020
examples/pipeline2_iterative
2121
examples/Cor_largesino
22-
examples/DistortionCorr
22+
examples/DistortionCorr
2323

2424
.. _reference_content:
2525

httomolibgpu/cuda_kernels/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
from typing import List, Optional, Tuple
33

44
from httomolibgpu import cupywrapper
5+
56
cp = cupywrapper.cp
67

8+
79
def load_cuda_module(
810
file: str,
911
name_expressions: Optional[List[str]] = None,

0 commit comments

Comments
 (0)