Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hexrd/core/imageseries/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _process_frame(self, key):

# Apply fancy indexing after all operations
if rest:
img = img[*rest]
img = img[tuple(rest)]

return img

Expand Down
6 changes: 5 additions & 1 deletion hexrd/core/instrument/hedm_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
from functools import partial
from pathlib import Path
from typing import Any, Literal, Optional, Union, TypedDict, NotRequired
from typing import Any, Literal, Optional, Union, TypedDict
try:
from typing import NotRequired
except ImportError:
from typing_extensions import NotRequired
from tqdm import tqdm

import yaml
Expand Down
149 changes: 148 additions & 1 deletion hexrd/hedm/config/findorientations.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,22 @@ def range(self):

class SeedSearchConfig(Config):

candidate_generators = [
'discrete-fibers',
'pairwise',
'pairwise-greedy',
'pairwise-consensus',
]

@property
def hkl_seeds(self):
key = 'find_orientations:seed_search:hkl_seeds'
try:
temp = self._cfg.get(key)
temp = self._cfg.get(key, None)
if temp is None:
if self.hkl_seed_selection == 'auto':
return None
raise KeyError(key)
if isinstance(temp, int):
temp = [
temp,
Expand All @@ -197,6 +208,48 @@ def hkl_seeds(self):
if self._cfg.find_orientations.use_quaternion_grid is None:
raise RuntimeError('"%s" must be defined for seeded search' % key)

@property
def hkl_seed_selection(self) -> str:
key = 'find_orientations:seed_search:hkl_seed_selection'
raw = self._cfg.get(key, None)
if raw is None:
if bool(
self._cfg.get(
'find_orientations:seed_search:auto_select_hkls',
False,
)
):
return 'auto'
return 'manual'

mode = str(raw).strip().lower()
if mode in ('manual', 'auto'):
return mode

raise RuntimeError(
'"%s": "%s" not recognized, must be one of ["manual", "auto"]'
% (key, raw)
)

@property
def auto_select_hkls(self) -> bool:
return self.hkl_seed_selection == 'auto'

@property
def auto_select_count(self) -> int:
key = 'find_orientations:seed_search:auto_select_count'
raw = self._cfg.get(key, None)
if raw is not None:
return max(int(raw), 1)

manual = self._cfg.get('find_orientations:seed_search:hkl_seeds', None)
if isinstance(manual, int):
return 1
if manual is not None:
return max(len(manual), 1)

return 3

@property
def fiber_step(self):
return self._cfg.get(
Expand All @@ -223,13 +276,107 @@ def method(self):
def fiber_ndiv(self):
return int(360.0 / self.fiber_step)

@property
def candidate_generator(self) -> str:
key = 'find_orientations:seed_search:candidate_generator'
temp = self._cfg.get(key, 'discrete-fibers').lower()
if temp in self.candidate_generators:
return temp

raise RuntimeError(
'"%s": "%s" not recognized, must be one of %s'
% (key, temp, self.candidate_generators)
)

@property
def pairwise_tolerance(self) -> float:
return self._cfg.get(
'find_orientations:seed_search:pairwise_tolerance',
max(
self._cfg.find_orientations.eta.tolerance,
self._cfg.find_orientations.omega.tolerance,
),
)

@property
def pairwise_max_candidates(self) -> int:
return int(
self._cfg.get(
'find_orientations:seed_search:pairwise_max_candidates',
10000,
)
)

@property
def pairwise_max_partners(self) -> int:
return int(
self._cfg.get(
'find_orientations:seed_search:pairwise_max_partners',
64,
)
)

@property
def friedel_pairing(self) -> bool:
return bool(
self._cfg.get(
'find_orientations:seed_search:friedel_pairing',
True,
)
)

@property
def reflection_statistics_samples(self) -> int:
return int(
self._cfg.get(
'find_orientations:seed_search:reflection_statistics_samples',
200,
)
)

@property
def reflection_statistics_percentile(self) -> float:
return float(
self._cfg.get(
'find_orientations:seed_search:reflection_statistics_percentile',
10.0,
)
)

@property
def reflection_statistics_seed(self) -> int:
return int(
self._cfg.get(
'find_orientations:seed_search:reflection_statistics_seed',
0,
)
)


class OrientationMapsConfig(Config):
@property
def active_hkl_selection(self) -> str:
key = 'find_orientations:orientation_maps:active_hkl_selection'
raw = self._cfg.get(key, None)
if raw is None:
return 'manual'

mode = str(raw).strip().lower()
if mode in ('manual', 'auto'):
return mode

raise RuntimeError(
'"%s": "%s" not recognized, must be one of ["manual", "auto"]'
% (key, raw)
)

@property
def active_hkls(self) -> list[int] | None:
hkls: list[int] | int | Literal['all'] | None = self._cfg.get(
'find_orientations:orientation_maps:active_hkls', default='all'
)
if self.active_hkl_selection == 'auto' and (hkls == 'all' or hkls is None):
return None
if isinstance(hkls, int):
return [hkls]
elif hkls == 'all' or hkls is None:
Expand Down
Loading