Skip to content

Commit

Permalink
Format some files using Black 24.2
Browse files Browse the repository at this point in the history
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
  • Loading branch information
hakonanes committed May 30, 2024
1 parent 03c0870 commit 08aab67
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 49 deletions.
10 changes: 8 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.4.2
hooks:
- id: black
language_version: python3.11
- id: black
language_version: python3.11
- id: black-jupyter
files: \.ipynb
args: [--line-length=77]
# https://pycqa.github.io/isort/
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
args:
[--profile=black, --filter-files, --force-sort-within-sections]
4 changes: 3 additions & 1 deletion doc/tutorials/esteem2022_diffraction_workshop.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2178,7 +2178,9 @@
}
],
"source": [
"fig = simulator.plot(hemisphere=\"upper\", mode=\"lines\", return_figure=True, color=\"w\")\n",
"fig = simulator.plot(\n",
" hemisphere=\"upper\", mode=\"lines\", return_figure=True, color=\"w\"\n",
")\n",
"fig.axes[0].scatter(ref, c=hkl_rgb, s=50)\n",
"\n",
"fig.axes[0].imshow(mp_sp.data, cmap=\"gray\", extent=(-1, 1, -1, 1));"
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/feature_maps.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@
" colorbar=True,\n",
" colorbar_label=\"Average dot product\",\n",
" remove_padding=True,\n",
" return_figure=True\n",
" return_figure=True,\n",
")\n",
"fig.axes[0].scatter(x, y, c=\"r\");"
]
Expand Down
10 changes: 5 additions & 5 deletions doc/tutorials/hough_indexing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@
" [[1, 1, 1], [2, 0, 0], [2, 2, 0], [3, 1, 1]],\n",
" nBands=10,\n",
" tSigma=2,\n",
" rSigma=2\n",
" rSigma=2,\n",
")\n",
"\n",
"print(indexer.vendor)\n",
Expand Down Expand Up @@ -475,7 +475,7 @@
" [[1, 1, 1], [2, 0, 0], [2, 2, 0], [3, 1, 1]],\n",
" nBands=10,\n",
" tSigma=2,\n",
" rSigma=2\n",
" rSigma=2,\n",
")\n",
"indexer.PC"
]
Expand Down Expand Up @@ -527,14 +527,14 @@
"metadata": {},
"outputs": [],
"source": [
"#io.save(\"xmap_ni.h5\", xmap)\n",
"#io.save(\n",
"# io.save(\"xmap_ni.h5\", xmap)\n",
"# io.save(\n",
"# \"xmap_ni.ang\",\n",
"# xmap,\n",
"# image_quality_prop=\"pq\",\n",
"# confidence_index_prop=\"cm\",\n",
"# extra_prop=\"nmatch\",\n",
"#)"
"# )"
]
},
{
Expand Down
16 changes: 8 additions & 8 deletions doc/tutorials/hybrid_indexing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@
"from orix.vector import Vector3d\n",
"\n",
"\n",
"plt.rcParams.update({\n",
" \"figure.facecolor\": \"w\",\n",
" \"font.size\": 15,\n",
" \"figure.dpi\": 75,\n",
"})"
"plt.rcParams.update(\n",
" {\n",
" \"figure.facecolor\": \"w\",\n",
" \"font.size\": 15,\n",
" \"figure.dpi\": 75,\n",
" }\n",
")"
]
},
{
Expand Down Expand Up @@ -1335,9 +1337,7 @@
"\n",
"# Place color key in bottom right corner, coordinates are\n",
"# [left, bottom, width, height]\n",
"ax_ckey = fig.add_axes(\n",
" [0.76, 0.08, 0.2, 0.2], projection=\"ipf\", symmetry=pg\n",
")\n",
"ax_ckey = fig.add_axes([0.76, 0.08, 0.2, 0.2], projection=\"ipf\", symmetry=pg)\n",
"ax_ckey.plot_ipf_color_key(show_title=False)\n",
"ax_ckey.patch.set_facecolor(\"None\")"
]
Expand Down
4 changes: 3 additions & 1 deletion doc/tutorials/kinematical_ebsd_simulations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,9 @@
"ni_kin_data[mask] = np.nan\n",
"\n",
"fig, axes = plt.subplots(ncols=2, layout=\"tight\")\n",
"for ax, data, title in zip(axes, [ni_kin_data, ni_dyn_data], [\"kinematical\", \"dynamical\"]):\n",
"for ax, data, title in zip(\n",
" axes, [ni_kin_data, ni_dyn_data], [\"kinematical\", \"dynamical\"]\n",
"):\n",
" ax.imshow(data, cmap=\"gray\")\n",
" ax.axis(\"off\")\n",
" ax.set(title=f\"Ni {title} 20 kV\")"
Expand Down
16 changes: 10 additions & 6 deletions doc/tutorials/pattern_matching.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,9 @@
" alpha=0.5,\n",
" label=ncc_after_ori_ref_label,\n",
")\n",
"ax.set(xlabel=\"Normalized cross correlation (NCC) scores\", ylabel=\"Frequency\")\n",
"ax.set(\n",
" xlabel=\"Normalized cross correlation (NCC) scores\", ylabel=\"Frequency\"\n",
")\n",
"ax.legend()\n",
"fig.tight_layout();"
]
Expand Down Expand Up @@ -1200,9 +1202,7 @@
"\n",
"# Place color key in bottom right corner,\n",
"# coordinates are [left, bottom, width, height]\n",
"ax_ckey = fig.add_axes(\n",
" [0.75, 0.08, 0.2, 0.2], projection=\"ipf\", symmetry=pg\n",
")\n",
"ax_ckey = fig.add_axes([0.75, 0.08, 0.2, 0.2], projection=\"ipf\", symmetry=pg)\n",
"ax_ckey.plot_ipf_color_key(show_title=False)\n",
"ax_ckey.patch.set_facecolor(\"None\")\n",
"_ = [text.set_color(\"w\") for text in ax_ckey.texts] # White [uvw]"
Expand Down Expand Up @@ -1418,7 +1418,9 @@
" alpha=0.5,\n",
" label=ncc_after_pc_ref_label,\n",
")\n",
"ax.set(xlabel=\"Normalized cross correlation (NCC) scores\", ylabel=\"Frequency\")\n",
"ax.set(\n",
" xlabel=\"Normalized cross correlation (NCC) scores\", ylabel=\"Frequency\"\n",
")\n",
"ax.legend()\n",
"fig.tight_layout();"
]
Expand Down Expand Up @@ -1643,7 +1645,9 @@
" alpha=0.5,\n",
" label=ncc_after_ori_pc_ref_label,\n",
")\n",
"ax.set(xlabel=\"Normalized cross correlation (NCC) scores\", ylabel=\"Frequency\")\n",
"ax.set(\n",
" xlabel=\"Normalized cross correlation (NCC) scores\", ylabel=\"Frequency\"\n",
")\n",
"ax.legend()\n",
"fig.tight_layout();"
]
Expand Down
4 changes: 3 additions & 1 deletion doc/tutorials/pattern_processing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,9 @@
"metadata": {},
"outputs": [],
"source": [
"s11 = s3.inav[0, 0].normalize_intensity(num_std=1, dtype_out=np.float32, inplace=False)\n",
"s11 = s3.inav[0, 0].normalize_intensity(\n",
" num_std=1, dtype_out=np.float32, inplace=False\n",
")\n",
"np.mean(s11.data)"
]
},
Expand Down
8 changes: 6 additions & 2 deletions doc/tutorials/pc_calibration_moving_screen_technique.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@
"metadata": {},
"outputs": [],
"source": [
"fig, axes = plt.subplots(ncols=2, sharex=True, sharey=True, figsize=(14, 7), layout=\"tight\")\n",
"fig, axes = plt.subplots(\n",
" ncols=2, sharex=True, sharey=True, figsize=(14, 7), layout=\"tight\"\n",
")\n",
"for ax, data in zip(axes, [s_in.data, s_out5mm.data]):\n",
" ax.imshow(data, cmap=\"gray\")"
]
Expand Down Expand Up @@ -276,7 +278,9 @@
"metadata": {},
"outputs": [],
"source": [
"det_ref = s_in.hough_indexing_optimize_pc(pc0=det.pc, indexer=indexer, method=\"PSO\")\n",
"det_ref = s_in.hough_indexing_optimize_pc(\n",
" pc0=det.pc, indexer=indexer, method=\"PSO\"\n",
")\n",
"\n",
"print(det.pc - det_ref.pc)"
]
Expand Down
8 changes: 6 additions & 2 deletions doc/tutorials/pc_extrapolate_plane.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@
"metadata": {},
"outputs": [],
"source": [
"r_pattern = kp.filters.distance_to_origin(s_cal.axes_manager.signal_shape[::-1], origin=(230, 220))\n",
"r_pattern = kp.filters.distance_to_origin(\n",
" s_cal.axes_manager.signal_shape[::-1], origin=(230, 220)\n",
")\n",
"signal_mask = r_pattern > 310 # Exclude pixels set to True"
]
},
Expand Down Expand Up @@ -1272,7 +1274,9 @@
"source": [
"fig, axes = plt.subplots(ncols=3, nrows=3, figsize=(12, 12))\n",
"for i, ax in enumerate(axes.ravel()):\n",
" ax.imshow(s_cal2.inav[i].data * ~signal_mask, cmap=\"gray\", vmin=-3, vmax=3)\n",
" ax.imshow(\n",
" s_cal2.inav[i].data * ~signal_mask, cmap=\"gray\", vmin=-3, vmax=3\n",
" )\n",
" ax.axis(\"off\")\n",
"\n",
" # Affine\n",
Expand Down
8 changes: 6 additions & 2 deletions doc/tutorials/pc_fit_plane.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,9 @@
"source": [
"fig, axes = plt.subplots(*grid_shape, figsize=(15, 15))\n",
"for i in np.ndindex(grid_shape):\n",
" axes[i].imshow((s_grid2.data[i] * ~signal_mask), cmap=\"gray\", vmin=-3, vmax=3)\n",
" axes[i].imshow(\n",
" (s_grid2.data[i] * ~signal_mask), cmap=\"gray\", vmin=-3, vmax=3\n",
" )\n",
" axes[i].axis(\"off\")\n",
"\n",
" lines = sim.as_collections(i)[0]\n",
Expand Down Expand Up @@ -1434,7 +1436,9 @@
" xmap_grid_ref2.orientations, degrees=True\n",
")\n",
"print(angles.max())\n",
"xmap_grid_ref2.plot(angles, colorbar=True, colorbar_label=\"Misorientation angle [deg]\")"
"xmap_grid_ref2.plot(\n",
" angles, colorbar=True, colorbar_label=\"Misorientation angle [deg]\"\n",
")"
]
},
{
Expand Down
4 changes: 3 additions & 1 deletion doc/tutorials/pc_orientation_dependence.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,9 @@
"# Make an array of full map size of zeros (black), and fill colors from\n",
"# successfully indexed nickel in the correct points\n",
"rgb = np.zeros((xmap.size, 3))\n",
"rgb[xmap.is_indexed] = ckey_m3m.orientation2color(xmap[\"indexed\"].orientations)\n",
"rgb[xmap.is_indexed] = ckey_m3m.orientation2color(\n",
" xmap[\"indexed\"].orientations\n",
")\n",
"fig = xmap.plot(rgb, remove_padding=True, return_figure=True)\n",
"\n",
"# Place color key next to map\n",
Expand Down
4 changes: 3 additions & 1 deletion doc/tutorials/reference_frames.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,9 @@
" Gr_hi = Rotation(data[0][\"quat\"]) * Gr_sample[vendor]\n",
" G_hi = Orientation(Gr_hi, mp.phase.point_group)\n",
"\n",
" print(f\"Average misorientation angle to ground truth: {G_hi.angle_with(G, degrees=True).mean():.4f}\")\n",
" print(\n",
" f\"Average misorientation angle to ground truth: {G_hi.angle_with(G, degrees=True).mean():.4f}\"\n",
" )\n",
" fig = G.scatter(\n",
" \"ipf\",\n",
" direction=v_sample,\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class NormalizedCrossCorrelationMetric(SimilarityMetric):
description of the initialization parameters and the list of
attributes.
"""

_allowed_dtypes: List[type] = [np.float32, np.float64]
_sign: int = 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class NormalizedDotProductMetric(SimilarityMetric):
description of the initialization parameters and the list of
attributes.
"""

_allowed_dtypes: List[type] = [np.float32, np.float64]
_sign: int = 1

Expand Down
13 changes: 5 additions & 8 deletions kikuchipy/io/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
from pathlib import Path
from typing import List, Optional, Union

from h5py import File, Group, is_hdf5
from hyperspy.io_plugins import hspy
from hyperspy.misc.io.tools import overwrite as overwrite_method
from hyperspy.misc.utils import strlist2enumeration, find_subclasses
from hyperspy.misc.utils import find_subclasses, strlist2enumeration
from hyperspy.signal import BaseSignal
from h5py import File, is_hdf5, Group
import numpy as np

import kikuchipy.signals
from kikuchipy.io._util import _ensure_directory, _get_input_bool
from kikuchipy.io.plugins import (
bruker_h5ebsd,
ebsd_directory,
Expand All @@ -43,8 +43,7 @@
oxford_binary,
oxford_h5ebsd,
)
from kikuchipy.io._util import _get_input_bool, _ensure_directory

import kikuchipy.signals

plugins = [
bruker_h5ebsd,
Expand All @@ -69,9 +68,7 @@
default_write_ext.add(plugin.file_extensions[plugin.default_extension])


def load(
filename: Union[str, Path], lazy: bool = False, **kwargs
) -> Union[
def load(filename: Union[str, Path], lazy: bool = False, **kwargs) -> Union[
"EBSD",
"EBSDMasterPattern",
"ECPMasterPattern",
Expand Down
10 changes: 3 additions & 7 deletions kikuchipy/io/plugins/bruker_h5ebsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
from orix.crystal_map import CrystalMap

from kikuchipy.detectors import EBSDDetector
from kikuchipy.io.plugins._h5ebsd import _hdf5group2dict, H5EBSDReader

from kikuchipy.io.plugins._h5ebsd import H5EBSDReader, _hdf5group2dict

__all__ = ["file_reader"]

Expand Down Expand Up @@ -169,30 +168,27 @@ def scan2dict(self, group: h5py.Group, lazy: bool = False) -> dict:
)
scan_dict["data"] = data

# --- Axes
scan_dict["axes"] = self.get_axes_list((ny, nx, sy, sx), (dy, dx, px_size))

# --- Original metadata
scan_dict["original_metadata"] = {
"manufacturer": self.manufacturer,
"version": self.version,
}
scan_dict["original_metadata"].update(hd)

# --- Crystal map
# TODO: Use reader from orix
xmap = CrystalMap.empty(shape=(ny, nx), step_sizes=(dy, dx))
scan_dict["xmap"] = xmap

# --- Static background
scan_dict["static_background"] = hd.get("StaticBackground")

# --- Detector
pc = np.column_stack(
(dd.get("PCX", 0.5), dd.get("PCY", 0.5), dd.get("DD", 0.5))
)
if pc.size > 3:
pc = pc.reshape((ny, nx, 3))
tilt = hd.get("CameraTilt", 0.0)
sample_tilt = hd.get("SampleTilt", 0.0)
scan_dict["detector"] = EBSDDetector(
shape=(sy, sx),
px_size=px_size,
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# along with kikuchipy. If not, see <http://www.gnu.org/licenses/>.

from itertools import chain
from setuptools import setup, find_packages

from setuptools import find_packages, setup

# Get release information without importing anything from the project
with open("kikuchipy/release.py") as fid:
Expand Down Expand Up @@ -84,6 +84,7 @@
# Create a development project including all extra dependencies
extra_feature_requirements["dev"] = [
"black[jupyter] >= 23.1",
"isort",
"manifix",
"outdated",
"pre-commit >= 1.16",
Expand Down

0 comments on commit 08aab67

Please sign in to comment.