Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • empyre/empyre
  • weber/empyre
  • wessels/empyre
  • bryan/empyre
4 results
Show changes
demos/files/mask.png

2.37 KiB

File added
[.ShellClassInfo]
IconResource=C:\Users\Jan\PhD Thesis\Pyramid\icon.ico,0
[ViewState]
Mode=
Vid=
FolderType=Generic
docs/EMPyRe Logo.png

30.5 KiB

# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# http://www.sphinx-doc.org/en/master/config
# Use command in docs to generate stubs and make html afterwards:
# > sphinx-apidoc -o api ../src/empyre
# > make html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join('..', 'src')))
# -- Project information -----------------------------------------------------
project = 'EMPyRe'
copyright = '2020, Jan Caron'
author = 'Jan Caron'
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.viewcode',
'numpydoc',
'nbsphinx',
'nbsphinx_link']
numpydoc_show_class_members = False
add_module_names = False
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'sphinx_rtd_theme'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
# html_static_path = ['_static']
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
html_logo = 'EMPyRe Logo.png'
# The name of an image file (relative to this directory) to use as a favicon of
# the doc. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
html_favicon = 'icon.ico'
# cannot cache unpickable configuration value: 'nbsphinx_custom_formats
# See https://github.com/sphinx-doc/sphinx/issues/12300
suppress_warnings = ["config.cache"]
Demos
-----
.. toctree::
demos/demo1
demos/demo2
demos/demo3
{
"path": "../../demos/demo1_first_steps.ipynb"
}
\ No newline at end of file
{
"path": "../../demos/demo2_handling_3d_fields.ipynb"
}
\ No newline at end of file
{
"path": "../../demos/demo3_io_and_field_manipulation.ipynb"
}
\ No newline at end of file
The Field container class
=========================
General empyre.fields docu here!
All functions implemented in the subpackages can be accessed directly in the ``empyre.fields`` namespace.
The field module
----------------
.. automodule:: empyre.fields.field
:members:
:show-inheritance:
The shapes module
-----------------
.. automodule:: empyre.fields.shapes
:members:
:show-inheritance:
The vectors module
------------------
.. automodule:: empyre.fields.vectors
:members:
:show-inheritance:
docs/icon.ico

66.1 KiB

.. EMPyRe documentation master file, created by
sphinx-quickstart on Mon Feb 17 14:19:01 2020.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
EMPyRe - Electron Microscopy Reconstruction
===========================================
.. include:: ../README.rst
.. toctree::
:maxdepth: 2
:caption: Contents:
fields
vis
io
demos
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
The io visualization submodule
===============================
General empyre.io docu here!
The io_field module
-------------------
.. automodule:: empyre.io.io_field
:members:
:show-inheritance:
The field_plugins module
------------------------
.. automodule:: empyre.io.field_plugins
:members:
:show-inheritance:
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build
if "%1" == "" goto help
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
:end
popd
The vis visualization submodule
===============================
General empyre.vis docu here!
All functions implemented in the subpackages can be accessed directly in the ``empyre.io`` namespace, with the exception
of the ``color`` module, whose methods are accessible via ``empyre.vis.colors``.
Note that the y-axis of all image plots is flipped in comparison to ``matplotlib.pyplot.imshow``, i.e. that the
origin is `'lower'` in this case instead of `'upper'`.
Please note that 3D plots only work in your Jupyter notebook after first installing and then enabling the corresponding
mayavi extension:
.. code-block:: bash
$ jupyter nbextension install --py mayavi --user
$ jupyter nbextension enable mayavi --user --py
If you'd like to utilize 3D plots in your Jupyter Notebook or in the Python Interactive Window
.. code-block:: Python
>>> from mayavi import mlab
>>> mlab.init_notebook('x3d')
The backend, chosen by the `init_notebook` function can be `ipy` (the default, produces static images in Juypter
Notebook and does not work in VSCode), `x3d` (produces interactive plots in Jupyter Noteboo, but seems to not work with
VSCode), or `png` (produces png-images, which work in both Jupyter Notebooks and VSCode).
For more information and a quick introduction visit the `mayavi tips & tricks section <https://docs.enthought.com/mayavi/mayavi/tips.html>`_.
The plot2d module
-----------------
.. automodule:: empyre.vis.plot2d
:members:
:show-inheritance:
The decorators module
---------------------
.. automodule:: empyre.vis.decorators
:members:
:show-inheritance:
The colors module
-----------------
.. automodule:: empyre.vis.colors
:members:
:show-inheritance:
The tools module
----------------
.. automodule:: empyre.vis.tools
:members:
:show-inheritance:
icon.ico

132 KiB

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "empyre"
dynamic = ["version"]
description = "Electron Microscopy Python Reconstruction"
readme = "README.rst"
license = "GPL-3.0-or-later"
requires-python = ">=3.6"
authors = [
{ name = "Jan Caron", email = "j.caron@fz-juelich.de" },
]
keywords = [
"Electron Microscopy",
"Inverse Problem Solving",
"Model-based Reconstrution",
]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Scientific/Engineering",
]
dependencies = [
"matplotlib >= 3.2",
"numpy >= 1.17",
"Pillow",
"scikit-image",
"scipy",
"tqdm",
]
[project.optional-dependencies]
3d = [
"mayavi >= 4.7",
]
all = [
"cmocean",
"pyfftw",
]
colors = [
"cmocean",
]
docs = [
"nbsphinx",
"nbsphinx_link",
"numpydoc",
"pandoc",
"sphinx",
"sphinx_rtd_theme",
]
fftw = [
"pyfftw",
]
io = [
"hyperspy",
"tvtk",
]
tests = [
"coverage",
"pyroma",
"pytest",
"pytest-cov",
"pytest-flake8",
"pytest-runner",
]
[project.urls]
Homepage = "https://iffgit.fz-juelich.de/empyre/empyre"
[tool.hatch.version]
path = "src/empyre/__init__.py"
[tool.hatch.build.targets.sdist]
include = [
"/src",
"/tests",
]
# -*- coding: utf-8 -*-
"""Create simple phasemaps from analytic solutions."""
# TODO: Currently just for projections along the z-axis!
import numpy as np
from numpy import pi
PHI_0 = -2067.83 # magnetic flux in T*nm²
def phase_mag_slab(dim, res, beta, center, width, b_0=1):
'''Get the analytic solution for a phase map of a slab of specified dimensions
Arguments:
dim - the dimensions of the grid, shape(z, y, x)
center - the center of the slab in pixel coordinates, shape(z, y, x)
width - the width of the slab in pixel coordinates, shape(z, y, x)
b_0 - magnetic induction corresponding to a magnetization Mo in T (default: 1)
Returns:
the analytic solution for the phase map
'''
# Function for the phase:
def phiMag(x, y):
def F0(x, y):
a = np.log(x**2 + y**2 + 1E-30)
b = np.arctan(x / (y+1E-30))
return x*a - 2*x + 2*y*b
return coeff * Lz * (- np.cos(beta) * (F0(x-x0-Lx/2, y-y0-Ly/2)
- F0(x-x0+Lx/2, y-y0-Ly/2)
- F0(x-x0-Lx/2, y-y0+Ly/2)
+ F0(x-x0+Lx/2, y-y0+Ly/2))
+ np.sin(beta) * (F0(y-y0-Ly/2, x-x0-Lx/2)
- F0(y-y0+Ly/2, x-x0-Lx/2)
- F0(y-y0-Ly/2, x-x0+Lx/2)
+ F0(y-y0+Ly/2, x-x0+Lx/2)))
# Process input parameters:
z_dim, y_dim, x_dim = dim
y0 = res * (center[1] + 0.5) # y0, x0 have to be in the center of a pixel,
x0 = res * (center[2] + 0.5) # hence: cellindex + 0.5
Lz, Ly, Lx = res * width[0], res * width[1], res * width[2]
coeff = b_0 / (4*PHI_0)
# Create grid:
x = np.linspace(res/2, x_dim*res-res/2, num=x_dim)
y = np.linspace(res/2, y_dim*res-res/2, num=y_dim)
xx, yy = np.meshgrid(x, y)
# Return phase:
return phiMag(xx, yy)
def phase_mag_disc(dim, res, beta, center, radius, height, b_0=1):
'''Get the analytic solution for a phase map of a disc of specified dimensions
Arguments:
dim - the dimensions of the grid, shape(z, y, x)
center - the center of the disc in pixel coordinates, shape(z, y, x)
radius - the radius of the disc in pixel coordinates (scalar value)
height - the height of the disc in pixel coordinates (scalar value)
b_0 - magnetic induction corresponding to a magnetization Mo in T (default: 1)
Returns:
the analytic solution for the phase map
'''
# Function for the phase:
def phiMag(x, y):
r = np.hypot(x - x0, y - y0)
r[center[1], center[2]] = 1E-30
result = coeff * Lz * ((y - y0) * np.cos(beta) - (x - x0) * np.sin(beta))
result *= np.where(r <= R, 1, (R / r) ** 2)
return result
# Process input parameters:
z_dim, y_dim, x_dim = dim
y0 = res * (center[1] + 0.5) # y0, x0 have to be in the center of a pixel,
x0 = res * (center[2] + 0.5) # hence: cellindex + 0.5
Lz = res * height
R = res * radius
coeff = - pi * b_0 / (2*PHI_0)
# Create grid:
x = np.linspace(res/2, x_dim*res-res/2, num=x_dim)
y = np.linspace(res/2, y_dim*res-res/2, num=y_dim)
xx, yy = np.meshgrid(x, y)
# Return phase:
return phiMag(xx, yy)
def phase_mag_sphere(dim, res, beta, center, radius, b_0=1):
'''Get the analytic solution for a phase map of a sphere of specified dimensions
Arguments:
dim - the dimensions of the grid, shape(z, y, x)
center - the center of the sphere in pixel coordinates, shape(z, y, x)
radius - the radius of the sphere in pixel coordinates (scalar value)
b_0 - magnetic induction corresponding to a magnetization Mo in T (default: 1)
Returns:
the analytic solution for the phase map
'''
# Function for the phase:
def phiMag(x, y):
r = np.hypot(x - x0, y - y0)
r[center[1], center[2]] = 1E-30
result = coeff * R ** 3 / r ** 2 * ((y - y0) * np.cos(beta) - (x - x0) * np.sin(beta))
result *= np.where(r > R, 1, (1 - (1 - (r / R) ** 2) ** (3. / 2.)))
return result
# Process input parameters:
z_dim, y_dim, x_dim = dim
y0 = res * (center[1] + 0.5) # y0, x0 have to be in the center of a pixel,
x0 = res * (center[2] + 0.5) # hence: cellindex + 0.5
R = res * radius
coeff = - 2./3. * pi * b_0 / PHI_0
# Create grid:
x = np.linspace(res / 2, x_dim * res - res / 2, num=x_dim)
y = np.linspace(res / 2, y_dim * res - res / 2, num=y_dim)
xx, yy = np.meshgrid(x, y)
# Return phase:
return phiMag(xx, yy)
# -*- coding: utf-8 -*-
"""Display holography images with the gradient direction encoded in color"""
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from pyramid.phasemap import PhaseMap
from numpy import pi
from PIL import Image
CDICT = {'red': [(0.00, 1.0, 0.0),
(0.25, 1.0, 1.0),
(0.50, 1.0, 1.0),
(0.75, 0.0, 0.0),
(1.00, 0.0, 1.0)],
'green': [(0.00, 0.0, 0.0),
(0.25, 0.0, 0.0),
(0.50, 1.0, 1.0),
(0.75, 1.0, 1.0),
(1.00, 0.0, 1.0)],
'blue': [(0.00, 1.0, 1.0),
(0.25, 0.0, 0.0),
(0.50, 0.0, 0.0),
(0.75, 0.0, 0.0),
(1.00, 1.0, 1.0)]}
HOLO_CMAP = mpl.colors.LinearSegmentedColormap('my_colormap', CDICT, 256)
def holo_image(phase_map, density=1):
'''Returns a holography image with color-encoded gradient direction.
Arguments:
phase_map - a PhaseMap object storing the phase informations
density - the gain factor for determining the number of contour lines (default: 1)
Returns:
holography image
'''
assert isinstance(phase_map, PhaseMap), 'phase_map has to be a PhaseMap object!'
# Calculate the holography image intensity:
img_holo = (1 + np.cos(density * phase_map.phase * pi/2)) / 2
# Calculate the phase gradients, expressed by magnitude and angle:
phase_grad_y, phase_grad_x = np.gradient(phase_map.phase, phase_map.res, phase_map.res)
phase_angle = (1 - np.arctan2(phase_grad_y, phase_grad_x)/pi) / 2
phase_magnitude = np.hypot(phase_grad_x, phase_grad_y)
phase_magnitude = np.sin(phase_magnitude/phase_magnitude.max() * pi / 2)
# Color code the angle and create the holography image:
rgba = HOLO_CMAP(phase_angle)
rgb = (255.999 * img_holo.T * phase_magnitude.T * rgba[:, :, :3].T).T.astype(np.uint8)
holo_image = Image.fromarray(rgb)
return holo_image
def make_color_wheel():
'''Display a color wheel for the gradient direction.
Arguments:
None
Returns:
None
'''
x = np.linspace(-256, 256, num=512)
y = np.linspace(-256, 256, num=512)
xx, yy = np.meshgrid(x, y)
r = np.sqrt(xx ** 2 + yy ** 2)
# Create the wheel:
color_wheel_magnitude = (1 - np.cos(r * pi/360)) / 2
color_wheel_magnitude *= 0 * (r > 256) + 1 * (r <= 256)
color_wheel_angle = (1 - np.arctan2(xx, -yy)/pi) / 2
# Color code the angle and create the holography image:
rgba = HOLO_CMAP(color_wheel_angle)
rgb = (255.999 * color_wheel_magnitude.T * rgba[:, :, :3].T).T.astype(np.uint8)
color_wheel = Image.fromarray(rgb)
# Plot the color wheel:
fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')
ax.imshow(color_wheel)
ax.set_title('Color Wheel')
ax.set_xlabel('x-axis')
ax.set_ylabel('y-axis')
def display(holo_image, title='Holography Image', axis=None):
'''Display the color coded holography image resulting from a given phase map.
Arguments:
holo_image - holography image created with the holo_image function of this module
title - the title of the plot (default: 'Holography Image')
axis - the axis on which to display the plot (default: None, a new figure is created)
Returns:
None
'''
# If no axis is specified, a new figure is created:
if axis is None:
fig = plt.figure()
axis = fig.add_subplot(1, 1, 1, aspect='equal')
# Plot the image and set axes:
axis.imshow(holo_image)
axis.set_title(title)
axis.set_xlabel('x-axis')
axis.set_ylabel('y-axis')
def display_combined(phase_map, density, title='Combined Plot'):
'''Display a given phase map and the resulting color coded holography image in one plot.
Arguments:
phase_map - the PhaseMap object from which the holography image is calculated
density - the factor for determining the number of contour lines
title - the title of the combined plot (default: 'Combined Plot')
Returns:
None
'''
# Create combined plot and set title:
fig = plt.figure(figsize=(14, 7))
fig.suptitle(title, fontsize=20)
# Plot holography image:
holo_axis = fig.add_subplot(1, 2, 1, aspect='equal')
display(holo_image(phase_map, density), axis=holo_axis)
# Plot phase map:
phase_axis = fig.add_subplot(1, 2, 2, aspect='equal')
phase_map.display(axis=phase_axis)