Skip to content

Commit

Permalink
Change black code style to default, to reduce potential conflicts
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 Jun 20, 2021
1 parent c083b5c commit 0f46f34
Show file tree
Hide file tree
Showing 77 changed files with 553 additions and 1,236 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
repos:
- repo: https://github.com/psf/black
rev: 21.5b1
rev: 21.6b0
hooks:
- id: black
17 changes: 14 additions & 3 deletions doc/_static/image/doc_reference_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
s.remove_dynamic_background()
s.rescale_intensity(percentiles=(0.5, 99.5))

det = EBSDDetector(shape=(60, 60), pc=[0.4210, 0.2206, 0.5049],)
det = EBSDDetector(
shape=(60, 60),
pc=[0.4210, 0.2206, 0.5049],
)
fig, ax = det.plot(
coordinates="detector",
pattern=s.inav[0, 0].data,
Expand All @@ -58,10 +61,18 @@
ax.set_xlabel(ax.get_xlabel(), color=x_color)
ax.set_ylabel(ax.get_ylabel(), color=y_color)
ax.arrow(
dx=arrow_length, dy=0, fc=x_color, ec=x_color, **arrow_dict1,
dx=arrow_length,
dy=0,
fc=x_color,
ec=x_color,
**arrow_dict1,
)
ax.arrow(
dx=0, dy=arrow_length, fc=y_color, ec=y_color, **arrow_dict1,
dx=0,
dy=arrow_length,
fc=y_color,
ec=y_color,
**arrow_dict1,
)
fig.savefig(
os.path.join(refframe_dir, "detector_coordinates.png"),
Expand Down
4 changes: 2 additions & 2 deletions kikuchipy/_util/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def foo(n):
with pytest.warns(np.VisibleDeprecationWarning) as record:
assert foo(4) == 5
desired_msg = (
"Function `foo()` is deprecated and will be removed in version 0.8. "
"Use `bar()` instead."
"Function `foo()` is deprecated and will be removed in version 0.8. Use "
"`bar()` instead."
)
assert str(record[0].message) == desired_msg
assert foo.__doc__ == (
Expand Down
10 changes: 3 additions & 7 deletions kikuchipy/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ def assert_dictionary(dict1, dict2):
dict1 = dict1.as_dictionary()
dict2 = dict2.as_dictionary()
for key in dict2.keys():
if key in ["is_binned", "binned"] and version.parse(
hs_version
) > version.parse(
if key in ["is_binned", "binned"] and version.parse(hs_version) > version.parse(
"1.6.2"
): # pragma: no cover
continue
Expand Down Expand Up @@ -241,14 +239,12 @@ def r_tsl2bruker():


@pytest.fixture
def nickel_ebsd_simulation_generator(
nickel_phase, detector, nickel_rotations,
):
def nickel_ebsd_simulation_generator(nickel_phase, detector, nickel_rotations):
"""Generator for EBSD simulations of Kikuchi bands for the Nickel
data set referenced above.
"""
return kp.generators.EBSDSimulationGenerator(
detector=detector, phase=nickel_phase, rotations=nickel_rotations,
detector=detector, phase=nickel_phase, rotations=nickel_rotations
)


Expand Down
11 changes: 3 additions & 8 deletions kikuchipy/crystallography/_computations.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,15 @@ def _get_hkl_family(
return families, families_idx


def _is_equivalent(
this_hkl: list, that_hkl: list, reduce: bool = False
) -> bool:
def _is_equivalent(this_hkl: list, that_hkl: list, reduce: bool = False) -> bool:
"""Determine whether two Miller index 3-tuples are equivalent.
Symmetry is not considered.
"""
if reduce:
this_hkl, _ = _reduce_hkl(this_hkl)
that_hkl, _ = _reduce_hkl(that_hkl)
return np.allclose(
np.sort(np.abs(this_hkl).astype(int)),
np.sort(np.abs(that_hkl).astype(int)),
np.sort(np.abs(this_hkl).astype(int)), np.sort(np.abs(that_hkl).astype(int))
)


Expand Down Expand Up @@ -127,9 +124,7 @@ def _get_colors_for_allowed_bands(
"""
if highest_hkl is None:
highest_hkl = [9, 9, 9]
rlp = ReciprocalLatticePoint.from_highest_hkl(
phase=phase, highest_hkl=highest_hkl,
)
rlp = ReciprocalLatticePoint.from_highest_hkl(phase=phase, highest_hkl=highest_hkl)

rlp2 = rlp[rlp.allowed]
# TODO: Replace this ordering with future ordering method in
Expand Down
17 changes: 10 additions & 7 deletions kikuchipy/crystallography/matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ def get_reciprocal_metric_tensor(lattice: Lattice) -> np.ndarray:
terms_12_21 = a * b * (c ** 2) * (ca * cb - cg)
terms_13_31 = a * (b ** 2) * c * (cg * ca - cb)
terms_23_32 = (a ** 2) * b * c * (cb * cg - ca)
return np.array(
[
[(b * c * sa) ** 2, terms_12_21, terms_13_31],
[terms_12_21, (a * c * sb) ** 2, terms_23_32],
[terms_13_31, terms_23_32, (a * b * sg) ** 2],
]
) / np.linalg.det(lattice.metrics)
return (
np.array(
[
[(b * c * sa) ** 2, terms_12_21, terms_13_31],
[terms_12_21, (a * c * sb) ** 2, terms_23_32],
[terms_13_31, terms_23_32, (a * b * sg) ** 2],
]
)
/ np.linalg.det(lattice.metrics)
)
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ def test_get_uvw_from_hkl(self, hkl, desired_uvw):
assert np.allclose(_get_uvw_from_hkl(hkl), desired_uvw)

@pytest.mark.parametrize(
(
"hkl, desired_family_keys, desired_family_values, desired_indices, "
"reduce"
),
("hkl, desired_family_keys, desired_family_values, desired_indices, " "reduce"),
[
([1, 1, 1], [[1, 1, 1]], [1, 1, 1], [0], False),
([1, 1, 1], [[1, 1, 1]], [1, 1, 1], [0], True),
Expand All @@ -57,9 +54,7 @@ def test_get_uvw_from_hkl(self, hkl, desired_uvw):
False,
),
(
ReciprocalLatticePoint(
phase=Phase(space_group=225), hkl=[1, 1, 1]
)
ReciprocalLatticePoint(phase=Phase(space_group=225), hkl=[1, 1, 1])
.symmetrise()
.hkl.data,
[1, 1, 1],
Expand Down Expand Up @@ -141,12 +136,7 @@ def test_get_uvw_from_hkl(self, hkl, desired_uvw):
],
)
def test_get_hkl_family(
self,
hkl,
desired_family_keys,
desired_family_values,
desired_indices,
reduce,
self, hkl, desired_family_keys, desired_family_values, desired_indices, reduce
):
"""Desired sets of families and indices."""
families, families_idx = _get_hkl_family(hkl, reduce=reduce)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,11 @@ def test_direct_structure_matrix(self, lattice, desired_matrix):
(Lattice(3.52, 3.52, 3.52, 90, 90, 90), np.eye(3) * 0.080),
(
Lattice(3.52, 3.52, 10.5, 90, 90, 120),
np.array(
[[0.107, 0.053, -0], [0.053, 0.107, -0], [-0, -0, 0.009]]
),
np.array([[0.107, 0.053, -0], [0.053, 0.107, -0], [-0, -0, 0.009]]),
),
],
)
def test_reciprocal_metric_tensor(self, lattice, desired_matrix):
recip_metrics = get_reciprocal_metric_tensor(lattice)
assert np.allclose(
recip_metrics, lattice.reciprocal().metrics, atol=1e-3
)
assert np.allclose(recip_metrics, lattice.reciprocal().metrics, atol=1e-3)
assert np.allclose(recip_metrics, desired_matrix, atol=1e-3)
18 changes: 6 additions & 12 deletions kikuchipy/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@ def nickel_ebsd_large(allow_download: bool = False, **kwargs) -> EBSD:
)


def silicon_ebsd_moving_screen_in(
allow_download: bool = False, **kwargs
) -> EBSD:
def silicon_ebsd_moving_screen_in(allow_download: bool = False, **kwargs) -> EBSD:
"""One EBSD pattern of (480, 480) detector pixels from a single
crystal Silicon sample, acquired on a NORDIF UF-420 detector.
Expand All @@ -195,7 +193,7 @@ def silicon_ebsd_moving_screen_in(
-------
signal : EBSD
EBSD signal.
See Also
--------
silicon_ebsd_moving_screen_out5mm
Expand All @@ -208,9 +206,7 @@ def silicon_ebsd_moving_screen_in(
)


def silicon_ebsd_moving_screen_out5mm(
allow_download: bool = False, **kwargs
) -> EBSD:
def silicon_ebsd_moving_screen_out5mm(allow_download: bool = False, **kwargs) -> EBSD:
"""One EBSD pattern of (480, 480) detector pixels from a single
crystal Silicon sample, acquired on a NORDIF UF-420 detector.
Expand All @@ -234,7 +230,7 @@ def silicon_ebsd_moving_screen_out5mm(
-------
signal : EBSD
EBSD signal.
See Also
--------
silicon_ebsd_moving_screen_in
Expand All @@ -247,9 +243,7 @@ def silicon_ebsd_moving_screen_out5mm(
)


def silicon_ebsd_moving_screen_out10mm(
allow_download: bool = False, **kwargs
) -> EBSD:
def silicon_ebsd_moving_screen_out10mm(allow_download: bool = False, **kwargs) -> EBSD:
"""One EBSD pattern of (480, 480) detector pixels from a single
crystal Silicon sample, acquired on a NORDIF UF-420 detector.
Expand All @@ -273,7 +267,7 @@ def silicon_ebsd_moving_screen_out10mm(
-------
signal : EBSD
EBSD signal.
See Also
--------
silicon_ebsd_moving_screen_in
Expand Down
28 changes: 7 additions & 21 deletions kikuchipy/data/bruker/create_bruker_h5ebsd_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@
ebsd_header.create_dataset("NCOLS", dtype=np.int32, data=nx)
ebsd_header.create_dataset("NROWS", dtype=np.int32, data=ny)
ebsd_header.create_dataset("NPoints", dtype=np.int32, data=n)
original_file = ebsd_header.create_dataset(
"OriginalFile", shape=(1,), dtype="|S50"
)
original_file = ebsd_header.create_dataset("OriginalFile", shape=(1,), dtype="|S50")
original_file[()] = b"/a/home/for/your/data.h5"
ebsd_header.create_dataset("PatternHeight", dtype=np.int32, data=sy)
ebsd_header.create_dataset("PatternWidth", dtype=np.int32, data=sx)
Expand All @@ -110,9 +108,7 @@
formula[()] = b"Ni"
phase.create_dataset("IT", dtype=np.int32, data=225)
phase.create_dataset(
"LatticeConstants",
dtype=np.float32,
data=np.array([3.56, 3.56, 3.56, 90, 90, 90]),
"LatticeConstants", dtype=np.float32, data=np.array([3.56, 3.56, 3.56, 90, 90, 90])
)
name = phase.create_dataset("Name", shape=(1,), dtype="|S6")
name[()] = b"Nickel"
Expand Down Expand Up @@ -193,12 +189,8 @@
# Header
ebsd_header = ebsd.create_group("Header")
ebsd_header.create_dataset("CameraTilt", dtype=float, data=0)
ebsd_header.create_dataset(
"DetectorFullHeightMicrons", dtype=np.int32, data=23700
)
ebsd_header.create_dataset(
"DetectorFullWidthMicrons", dtype=np.int32, data=31600
)
ebsd_header.create_dataset("DetectorFullHeightMicrons", dtype=np.int32, data=23700)
ebsd_header.create_dataset("DetectorFullWidthMicrons", dtype=np.int32, data=31600)
grid_type = ebsd_header.create_dataset("Grid Type", shape=(1,), dtype="|S9")
grid_type[()] = b"isometric"
ebsd_header.create_dataset("KV", dtype=float, data=20)
Expand All @@ -210,9 +202,7 @@
ebsd_header.create_dataset("NCOLS", dtype=np.int32, data=nx)
ebsd_header.create_dataset("NROWS", dtype=np.int32, data=ny)
ebsd_header.create_dataset("NPoints", dtype=np.int32, data=n)
original_file = ebsd_header.create_dataset(
"OriginalFile", shape=(1,), dtype="|S50"
)
original_file = ebsd_header.create_dataset("OriginalFile", shape=(1,), dtype="|S50")
original_file[()] = b"/a/home/for/your/data.h5"
ebsd_header.create_dataset("PatternHeight", dtype=np.int32, data=sy)
ebsd_header.create_dataset("PatternWidth", dtype=np.int32, data=sx)
Expand Down Expand Up @@ -324,9 +314,7 @@
ebsd_header.create_dataset("NCOLS", dtype=np.int32, data=nx)
ebsd_header.create_dataset("NROWS", dtype=np.int32, data=ny)
ebsd_header.create_dataset("NPoints", dtype=np.int32, data=n)
original_file = ebsd_header.create_dataset(
"OriginalFile", shape=(1,), dtype="|S50"
)
original_file = ebsd_header.create_dataset("OriginalFile", shape=(1,), dtype="|S50")
original_file[()] = b"/a/home/for/your/data.h5"
ebsd_header.create_dataset("PatternHeight", dtype=np.int32, data=sy)
ebsd_header.create_dataset("PatternWidth", dtype=np.int32, data=sx)
Expand All @@ -350,9 +338,7 @@
formula[()] = b"Ni"
phase.create_dataset("IT", dtype=np.int32, data=225)
phase.create_dataset(
"LatticeConstants",
dtype=np.float32,
data=np.array([3.56, 3.56, 3.56, 90, 90, 90]),
"LatticeConstants", dtype=np.float32, data=np.array([3.56, 3.56, 3.56, 90, 90, 90])
)
name = phase.create_dataset("Name", shape=(1,), dtype="|S6")
name[()] = b"Nickel"
Expand Down
4 changes: 1 addition & 3 deletions kikuchipy/data/emsoft_ebsd/create_dummy_emsoft_ebsd_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
},
"NMLparameters": {
"EBSDNameList": {
"Ftensor": np.array(
[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
),
"Ftensor": np.array([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]),
"L": 2123.3,
"alphaBD": 0.0,
"anglefile": "pattern/ni/2020/1/ni1_sda_eulers.txt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
mp_sp = kp.load(
filename=os.path.join(datadir, phase, fname),
hemisphere=hemisphere,
projection="spherical",
projection="stereographic",
)

# Rescale to uint8
Expand All @@ -56,24 +56,14 @@

# Overwrite master patterns in original data
lp_shape = (1, 1) + mp_lp.axes_manager.signal_shape[::-1]
orig_data["EMData"]["EBSDmaster"]["mLPNH"] = mp_lp.inav[0].data.reshape(
lp_shape
)
orig_data["EMData"]["EBSDmaster"]["mLPSH"] = mp_lp.inav[1].data.reshape(
lp_shape
)
orig_data["EMData"]["EBSDmaster"]["mLPNH"] = mp_lp.inav[0].data.reshape(lp_shape)
orig_data["EMData"]["EBSDmaster"]["mLPSH"] = mp_lp.inav[1].data.reshape(lp_shape)
sp_shape = (1,) + mp_sp.axes_manager.signal_shape[::-1]
orig_data["EMData"]["EBSDmaster"]["masterSPNH"] = mp_sp.inav[0].data.reshape(
sp_shape
)
orig_data["EMData"]["EBSDmaster"]["masterSPSH"] = mp_sp.inav[1].data.reshape(
sp_shape
)
orig_data["EMData"]["EBSDmaster"]["masterSPNH"] = mp_sp.inav[0].data.reshape(sp_shape)
orig_data["EMData"]["EBSDmaster"]["masterSPSH"] = mp_sp.inav[1].data.reshape(sp_shape)

# Create new HDF5 file (included in the kikuchipy.data module)
f2 = File(
os.path.join(datadir, phase, "ni_mc_mp_20kv_uint8_gzip_opts9.h5"), mode="w"
)
f2 = File(os.path.join(datadir, phase, "ni_mc_mp_20kv_uint8_gzip_opts9.h5"), mode="w")
kp.io.plugins.h5ebsd.dict2h5ebsdgroup(
dictionary=orig_data, group=f2, compression="gzip", compression_opts=9
)
Expand Down
Loading

0 comments on commit 0f46f34

Please sign in to comment.