Skip to content

Commit

Permalink
Merge pull request #1 from harripj/development
Browse files Browse the repository at this point in the history
Deploy
  • Loading branch information
harripj authored Apr 12, 2024
2 parents 0362cec + ce0b822 commit a356c57
Show file tree
Hide file tree
Showing 107 changed files with 1,234 additions and 1,055 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: publish_conda

on:
push:
branches:
- main

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: publish-to-conda
uses: fcakyon/[email protected]
with:
subdir: 'conda'
anacondatoken: ${{ secrets.ANACONDA_TOKEN }}
platforms: 'win osx linux'
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
1 change: 1 addition & 0 deletions KED/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.2
9 changes: 3 additions & 6 deletions KED/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
__name__ = "KED"
__version__ = "0.1"
__author__ = "harripj"
__author_email__ = "[email protected]"
__description__ = "Kinematic Electron Diffraction simulation."
__credits__ = ["Patrick Harrison"]
from pathlib import Path

__version__ = open(Path(__file__).parent.joinpath("VERSION")).read().strip()
49 changes: 43 additions & 6 deletions KED/coupling.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
from typing import List, Optional, Tuple

from IPython.display import display
from ipywidgets import IntSlider, interactive
from matplotlib import pyplot as plt
import numpy as np
from numpy.typing import ArrayLike, NDArray
import pandas as pd
from scipy.optimize import linear_sum_assignment
from scipy.spatial.distance import cdist


def filter_matches_xy(matches, xy1, xy2, dx=None, dy=50, abs=True):
def filter_matches_xy(
matches: List[NDArray],
xy1: NDArray,
xy2: NDArray,
dx: Optional[float] = None,
dy: Optional[float] = 50,
abs: bool = True,
) -> List[NDArray]:
"""
Filter matches between datasets by spatial displacement.
Expand Down Expand Up @@ -40,18 +51,20 @@ def filter_matches_xy(matches, xy1, xy2, dx=None, dy=50, abs=True):
if abs:
val = np.abs(val)
mask = val <= dx
matches = tuple(idx[mask] for idx in matches)
matches = [idx[mask] for idx in matches]
if dy is not None:
val = delta[:, 1]
if abs:
val = np.abs(val)
mask = val <= dy
matches = tuple(idx[mask] for idx in matches)
matches = [idx[mask] for idx in matches]

return matches


def sort_matches_multiple_couples(matches, comp1, comp2):
def sort_matches_multiple_couples(
matches: List[NDArray], comp1: pd.DataFrame, comp2: pd.DataFrame
) -> Tuple[NDArray]:
"""
Sort coupling between component sets by minimum distance.
In some cases many components are found on one component image.
Expand Down Expand Up @@ -109,7 +122,14 @@ def sort_matches_multiple_couples(matches, comp1, comp2):
) # keep same format as from linear_sum_assignment (tuple)


def plot_matches(xy1, xy2, image1, image2, cmap="gray", color="k"):
def plot_matches(
xy1: NDArray,
xy2: NDArray,
image1: NDArray,
image2: NDArray,
cmap: str = "gray",
color: str = "k",
) -> plt.Figure:
"""
Plot matches between datasets.
Expand All @@ -124,6 +144,9 @@ def plot_matches(xy1, xy2, image1, image2, cmap="gray", color="k"):
color: str
Colour for coupling lines.
Returns
-------
fig: plt.Figure
"""
fig, ax = plt.subplots()

Expand All @@ -138,8 +161,17 @@ def plot_matches(xy1, xy2, image1, image2, cmap="gray", color="k"):
for _xy1, _xy2 in zip(xy1, xy2):
ax.plot([_xy1[0], _xy2[0] + x_offset], [_xy1[1], _xy2[1]], color=color)

return fig


def plot_matches(coords1, coords2, im1, im2, matches, _interactive=False):
def plot_matches(
coords1: NDArray,
coords2: NDArray,
im1: NDArray,
im2: NDArray,
matches: Tuple[ArrayLike],
_interactive: bool = False,
) -> plt.Figure:
"""
Plot coupled points and links (edges) on the same axes.
Expand All @@ -155,6 +187,9 @@ def plot_matches(coords1, coords2, im1, im2, matches, _interactive=False):
If True then only one edge is shown at a time.
A slider is presented to select the edge.
Returns
-------
fig: plt.Figure
"""
fig, ax = plt.subplots()
ax.matshow(im1, extent=[0, im1.shape[1], im1.shape[0], 0])
Expand Down Expand Up @@ -186,3 +221,5 @@ def update(i):
"k",
alpha=0.5,
)

return fig
78 changes: 0 additions & 78 deletions KED/data/testing/Ni4W original.cif

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit a356c57

Please sign in to comment.