Skip to content

Commit

Permalink
Added files and updated README
Browse files Browse the repository at this point in the history
Added sem_io.py, pyproject.toml, .gitignore and updated README.md
  • Loading branch information
tgwoodcock committed Sep 22, 2022
1 parent 1243a5e commit 836c911
Show file tree
Hide file tree
Showing 4 changed files with 546 additions and 1 deletion.
46 changes: 46 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Distribution / packaging
.Python
bin/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
include/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# mkdocs documentation
/site

85 changes: 84 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,84 @@
# sem_io
# sem_io

Provides some helper functions to extract and view parameters stored in the header of SEM images (.tif) recorded using the software Zeiss SmartSEM V06.

This is a single Python module and can either be installed or easily incorporated into other projects (the license must be retained in this case).

### Installation

Please clone/download the repository and install with pip

```bash
cd sem_io
pip install .
```

### Usage

*Command line*

To print an overview of parameters from the image header in the console, at the command line, you can do:

```bash
sem_io path_to_my_image.tif
```

*Python*

You can also import the module and use the functions directly in Python.

```python
>>> import sem_io
```

To print an overview of parameters from the image header in the console:

```python
>>> my_params = sem_io.SEMparams("path_to_my_image.tif")
```

If you just want to collect and store the parameters and not print them, you can do:

```python
>>> my_params = sem_io.SEMparams("path_to_my_image.tif", verbose=False)
```

Then, to extract a particular parameter, you can then do:

```python
>>> my_params.get_parameter("Aperture Size")
(120.0, 'µm')
>>> my_params.get_parameter("Date")
'25 Nov 2020'
```

Parameters with a value and a unit are returned as a 2-Tuple. Other parameters are returned as a string.

All the functions are staticmethods, so you don't need to instantiate the SEMparams class at all. For example, there is a bespoke function for getting the image pixel size and its unit in one line of code:

```python
>>> pixel_size, unit = sem_io.SEMparams.get_image_pixel_size("path_to_my_image.tif")
```

This is useful if you want to plot the SEM image using [matplotlib](https://matplotlib.org/) and add a scalebar with the correct dimensions using [matplotlib-scalebar](https://github.com/ppinard/matplotlib-scalebar):

```python
>>> import matplotlib.pyplot as plt
>>> from matplotlib_scalebar.scalebar import ScaleBar
>>> import sem_io
>>> my_image = plt.imread("path_to_my_image.tif")
>>> fig, ax = plt.subplots()
>>> ax.imshow(my_image, cmap='gray')
>>> pixel_size, unit = sem_io.SEMparams.get_image_pixel_size("path_to_my_image.tif")
>>> my_scalebar = ScaleBar(pixel_size, units=unit, location='lower right', scale_loc='top')
>>> ax.add_artist(my_scalebar)
```

### Dependencies

* [Pillow](https://python-pillow.org/)

### General

* The parameters defined in SEMparams form a subset of those available in the header of the .tif image. If you are interested in other parameters, the program can be easily customised.
* If there are any issues, please feel free to get in touch using the [issues mechanism](https://github.com/tgwoodcock/sem_io/issues)
42 changes: 42 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "sem_io"
description = 'Python functions for extracting metadata parameters from the header of SEM images'
authors = [{name = "Thomas G. Woodcock"},]
license = {file = "LICENSE"}

classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Development Status :: 4 - Beta',
'Intended Audience :: End Users/Desktop',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Visualization',
'Topic :: Scientific/Engineering :: Image Processing',
'Topic :: Scientific/Engineering :: Physics',
'Topic :: Utilities',
]
keywords = ["research", "data", "electron microscopy", "SEM", "image", "metadata"]
requires-python = ">=3.6"
dependencies = ["Pillow"]
dynamic = ["version"]

[project.readme]
'file' = "README.md"
'content-type' = "text/markdown"

[project.urls]
'Source' = 'https://github.com/tgwoodcock/sem_io.git'
'Bug Tracker' = 'https://github.com/tgwoodcock/sem_io.git/issues'

[project.scripts]
sem_io = "sem_io:main"

[tool.setuptools.dynamic]
version = {attr = "sem_io.__version__"}
Loading

0 comments on commit 836c911

Please sign in to comment.