Skip to content

Commit

Permalink
Installable using Pip and Conda
Browse files Browse the repository at this point in the history
  • Loading branch information
nghia-vo committed Jun 1, 2021
1 parent cbf3cba commit ed05443
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 13 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
*.project
*.pydevproject
.idea
dev
dev/
doc/build/
doc/source/_static/
doc/source/_templates/
build/
dist/
*egg-info
*egg-info
recipe/
32 changes: 21 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,21 @@ Install
* Open command prompt, navigate to the source folder, run the following
commands:
```commandline
$ conda create -n discorpy
$ conda activate discorpy
$ conda install python
$ python setup.py install
conda create -n discorpy
conda activate discorpy
conda install python
python setup.py install
```
- Using conda:
+ Install Miniconda as instructed above.
+ Open terminal or command prompt and run the following command:
`conda install -c algotom discorpy`

- Using pip:
+ Install Miniconda as instructed above.
+ Open terminal or command prompt and run the following command:
`pip install discorpy`


How to use
==========
Expand All @@ -62,31 +72,31 @@ Demonstrations
- Apply to a visible dot-target collected at [Beamline I12](https://www.diamond.ac.uk/Instruments/Imaging-and-Microscopy/I12/Detectors-at-I12.html),
Diamond Light Source, UK:

![I12_before_after1](data/demo/i12_data_1.jpg)
![I12_before_after1](https://github.com/DiamondLightSource/discorpy/raw/master/data/demo/i12_data_1.jpg)

![I12_before_after2](data/demo/i12_data_2.jpg)
![I12_before_after2](https://github.com/DiamondLightSource/discorpy/raw/master/data/demo/i12_data_2.jpg)

- Apply to an X-ray dot-target collected at [Beamline I13](https://www.diamond.ac.uk/Instruments/Imaging-and-Microscopy/I13/Diamond-Manchester_Imaging_Branchline/Facilities_and_equipment_Imaging.html),
Diamond Light Source, UK:

![I13_before_after1](data/demo/i13_data_1.jpg)
![I13_before_after1](https://github.com/DiamondLightSource/discorpy/raw/master/data/demo/i13_data_1.jpg)

![I13_before_after2](data/demo/i13_data_2.jpg)
![I13_before_after2](https://github.com/DiamondLightSource/discorpy/raw/master/data/demo/i13_data_2.jpg)

- Improvement of a tomographic reconstructed image after distortion correction.
+ Before the correction:

![tomo_before](data/demo/recon_before.jpg)
![tomo_before](https://github.com/DiamondLightSource/discorpy/raw/master/data/demo/recon_before.jpg)

+ After the correction:

![tomo_before](data/demo/recon_after.jpg)
![tomo_before](https://github.com/DiamondLightSource/discorpy/raw/master/data/demo/recon_after.jpg)


- Apply to a hazard camera of the [Mars Perseverance Rover](https://mars.nasa.gov/mars2020/multimedia/raw-images/).
Details of how to estimate distortion coefficients of that camera without using
a calibration target are shown [here](https://github.com/DiamondLightSource/discorpy/blob/master/examples/Perseverance_distortion_correction/Distortion_correction_for_Perseverance_camera.md)

![Mars_rover](data/demo/Mars_Rover_camera.jpg)
![Mars_rover](https://github.com/DiamondLightSource/discorpy/raw/master/data/demo/Mars_Rover_camera.jpg)

108 changes: 108 additions & 0 deletions discorpy/losa/loadersaver.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,114 @@ def _get_key(name, obj):
return key_path


def get_hdf_information(file_path):
"""
Get information of datasets in a hdf/nxs file.
Parameters
----------
file_path : str
Path to the file.
Returns
-------
list_key : str
Keys to the datasets.
list_shape : tuple of int
Shapes of the datasets.
list_type : str
Types of the datasets.
"""
ifile = h5py.File(file_path, 'r')
keys = []
ifile.visit(keys.append)
list_key = []
list_shape = []
list_type = []
for key in keys:
data = ifile[key]
if isinstance(data, h5py.Group):
for key2, _ in list(data.items()):
list_key.append(key + "/" + key2)
else:
list_key.append(data.name)
for i, key in enumerate(list_key):
data = ifile[list_key[i]]
try:
shape = data.shape
except AttributeError:
shape = "None"
try:
dtype = data.dtype
except AttributeError:
dtype = "None"
if isinstance(data, list):
if len(data) == 1:
if not isinstance(data, np.ndarray):
dtype = str(list(data)[0])
dtype = dtype.replace("b'", "'")
list_shape.append(shape)
list_type.append(dtype)
ifile.close()
return list_key, list_shape, list_type


def find_hdf_key(file_path, pattern):
"""
Find datasets matching the pattern in a hdf/nxs file.
Parameters
----------
file_path : str
Path to the file.
pattern : str
Pattern to find the full names of the datasets.
Returns
-------
list_key : str
Keys to the datasets.
list_shape : tuple of int
Shapes of the datasets.
list_type : str
Types of the datasets.
"""
ifile = h5py.File(file_path, 'r')
list_key = []
keys = []
ifile.visit(keys.append)
for key in keys:
data = ifile[key]
if isinstance(data, h5py.Group):
for key2, _ in list(data.items()):
list_key.append(data.name + "/" + key2)
else:
list_key.append(data.name)
list_dkey = []
list_dshape = []
list_dtype = []
for _, key in enumerate(list_key):
if pattern in key:
list_dkey.append(key)
data = ifile[key]
try:
shape = data.shape
except AttributeError:
shape = "None"
list_dshape.append(shape)
try:
dtype = data.dtype
except AttributeError:
dtype = "None"
list_dtype.append(dtype)
if isinstance(data, list):
if len(data) == 1:
dtype = str(list(data)[0])
dtype = dtype.replace("b'", "'")
ifile.close()
return list_dkey, list_dshape, list_dtype


def load_hdf_file(file_path, key_path=None, index=None, axis=0):
"""
Load data from a hdf5/nxs file.
Expand Down
6 changes: 6 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import pathlib
import setuptools

HERE = pathlib.Path(__file__).parent
README = (HERE / "README.md").read_text()

setuptools.setup(
name="discorpy",
version="1.3",
author="Nghia Vo",
author_email="nghia.vo@diamond.ac.uk",
description='Radial lens distortion correction in Python',
long_description=README,
long_description_content_type="text/markdown",
keywords=['Distortion correction', 'Tomography', 'Radial lens distortion',
'Camera calibration'],
url="https://github.com/DiamondLightSource/discorpy",
Expand Down

0 comments on commit ed05443

Please sign in to comment.