Skip to content

Commit

Permalink
fixes from pull request review
Browse files Browse the repository at this point in the history
  • Loading branch information
donald e. boyce committed Dec 10, 2024
1 parent 3fa1d8c commit a4bf898
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 34 deletions.
16 changes: 6 additions & 10 deletions hexrd/cli/find_orientations.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from __future__ import print_function, division, absolute_import

import os
import logging
import sys

import numpy as np

from hexrd import constants as const
from hexrd import config
from hexrd import instrument
from hexrd.transforms import xfcapi
from hexrd.findorientations import find_orientations, write_scored_orientations


descr = 'Process rotation image series to find grain orientations'
Expand Down Expand Up @@ -52,10 +57,7 @@ def configure_parser(sub_parsers):

def write_results(results, cfg):
# Write scored orientations.
np.savez_compressed(
cfg.find_orientations.orientation_maps.scored_orientations_file,
**results['scored_orientations']
)
write_scored_orientations(results, cfg)

# Write accepted orientations.
qbar_filename = str(cfg.find_orientations.accepted_orientations_file)
Expand All @@ -73,12 +75,6 @@ def write_results(results, cfg):


def execute(args, parser):
import logging
import sys

from hexrd import config
from hexrd.findorientations import find_orientations

# make sure hkls are passed in as a list of ints
try:
if args.hkls is not None:
Expand Down
1 change: 0 additions & 1 deletion hexrd/cli/fit_grains.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ def execute(args, parser):
raise(RuntimeError,
"error loading indexing results '%s'" % quats_f)
else:
quats_f = cfg.find_orientations.accepted_orientations_file
logger.info("Missing %s, running find-orientations", quats_f)
logger.removeHandler(ch)
results = find_orientations(cfg)
Expand Down
4 changes: 1 addition & 3 deletions hexrd/config/fitgrains.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ def tth(self):

class FitGrainsConfig(Config):

_fit_grains = "fit-grains"

def _active_material_str(self):
return self.parent.material.active.strip().replace(' ', '-')

Expand All @@ -47,7 +45,7 @@ def __init__(self, cfg):
@property
def logfile(self):
"""Name of log file"""
return self.parent.analysis_dir / f"fit-grains.log"
return self.parent.analysis_dir / "fit-grains.log"

@property
def grains_file(self):
Expand Down
33 changes: 17 additions & 16 deletions hexrd/config/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,23 @@ class RootConfig(Config):
def working_dir(self):
"""Working directory, either specified in file or current directory
This directory is certain to exist. If the specified directory does
not exist, it defaults to the current working directory.
If the directory is not specified in the config file, then it will
default to the current working directory. If it is specified, the
director must exist, or it will throw and IOError.
"""
try:
temp = Path(self.get('working_dir'))
if not temp.exists():
raise IOError(f'"working_dir": {temp} does not exist')
return temp

except RuntimeError:
temp = Path.cwd()
self.working_dir = temp
wdir = self.get('working_dir', default=None)
if wdir is not None:
wdir = Path(wdir)
if not wdir.exists():
raise IOError(f'"working_dir": {str(wdir)} does not exist')
else:
# Working directory has not been specified, so we use current
# directory.
wdir = Path.cwd()
logger.info(
'"working_dir" not specified, defaulting to "%s"' % temp
)
return temp
'"working_dir" not specified, defaulting to "%s"' % wdir
)
return wdir

@working_dir.setter
def working_dir(self, val):
Expand All @@ -47,7 +48,7 @@ def working_dir(self, val):

@property
def analysis_name(self):
"""Name (Path) of the analysis
"""Name of the analysis
This will be used to set up the output directory. The name can
contain slash ("/") characters, which will generate a subdirectory
Expand All @@ -64,7 +65,7 @@ def analysis_dir(self):
"""Analysis directory, where output files go
The name is derived from `working_dir` and `analysis_name`. This
propetry returns a Path object. The directory and any intermediate
property returns a Path object. The directory and any intermediate
directories can be created with the `mkdir()` method, e.g.
>>> analysis_dir.mkdir(parents=True, exist_ok=True)
Expand Down
27 changes: 23 additions & 4 deletions hexrd/findorientations.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@
# =============================================================================


def write_scored_orientations(results, fname):
"""Write scored orientations to a file
PARAMETERS
----------
results: dict
output of main `find_orientations` function
cfg: Config instance
the main Config input file for `find-orientations`
"""
np.savez_compressed(
cfg.find_orientations.orientation_maps.scored_orientations_file,
**results['scored_orientations']
)


def _process_omegas(omegaimageseries_dict):
"""Extract omega period and ranges from an OmegaImageseries dictionary."""
oims = next(iter(omegaimageseries_dict.values()))
Expand Down Expand Up @@ -384,7 +400,10 @@ def quat_distance(x, y):

def load_eta_ome_maps(cfg, pd, image_series, hkls=None, clean=False):
"""
Load the eta-ome maps specified by the config and CLI flags.
Load the eta-ome maps specified by the config and CLI flags. If the
maps file exists, it will return those values. If the file does not exist,
it will generate them using the passed HKLs (if not None) or the HKLs
specified in the config file (if passed HKLs are Noe).
Parameters
----------
Expand All @@ -395,7 +414,7 @@ def load_eta_ome_maps(cfg, pd, image_series, hkls=None, clean=False):
image_series: ImageSeries instance
stack of images
hkls: list, default = None
list of HKLs used in the eta-omega maps.
list of HKLs used to generate the eta-omega maps
clean: bool, default = False
flag indicating whether (if True) to overwrite existing maps file
Expand All @@ -415,7 +434,7 @@ def load_eta_ome_maps(cfg, pd, image_series, hkls=None, clean=False):
try:
res = EtaOmeMaps(str(fn))
pd = res.planeData
logger.info(f'loaded eta/ome orientation maps from {str(fn)}')
logger.info(f'loaded eta/ome orientation maps from {fn}')
shkls = pd.getHKLs(*res.iHKLList, asStr=True)
logger.info(
'hkls used to generate orientation maps: %s',
Expand All @@ -429,7 +448,7 @@ def load_eta_ome_maps(cfg, pd, image_series, hkls=None, clean=False):
)
res = generate_eta_ome_maps(cfg, hkls=hkls)

filter_maps_if_requested(res, cfg)
filter_maps_if_requested(res, cfg)
return res


Expand Down

0 comments on commit a4bf898

Please sign in to comment.