Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d3e4142
Remapped package files
kpwelsh Mar 31, 2025
9d54c29
Update Imports
kpwelsh Mar 31, 2025
eb2164c
fix existing broken import "xrdutils.utils"
kpwelsh Jan 20, 2025
fa992e2
Patch imports
kpwelsh Jan 20, 2025
7abf6de
Add project test dependencies so they can be installed and run easily
kpwelsh Jan 20, 2025
a2b226f
These files need to be moved to resolve circular dependencies
kpwelsh Feb 12, 2025
225f1f3
Create module aliasing based on the generated file map
kpwelsh Jan 20, 2025
c5fd696
black reformatting
kpwelsh Feb 12, 2025
c59627a
remove circular imports
kpwelsh Feb 12, 2025
12eb423
Merge pull request #748 from Verdant-Evolution/reorganization
kpwelsh Feb 14, 2025
697d551
fix minor import issues
kpwelsh Mar 31, 2025
2de0aca
Some files need to be recopied to core to update them.
kpwelsh Mar 31, 2025
57ba9ea
Move file_table to into the package + fix pickled imports
kpwelsh Apr 1, 2025
fac76ae
Major duplicate cleanup
ZackAttack614 Jun 5, 2025
4fd2f74
Complete stage 1 core migration
ZackAttack614 Aug 28, 2025
a51fc2a
Add stray files to core migration
ZackAttack614 Aug 28, 2025
4d75310
Support Python 3.9 type unioning
ZackAttack614 Aug 28, 2025
8199e2e
Merge branch 'master' into master-reorg
ZackAttack614 Oct 1, 2025
1c6491e
Allow module_map to import funcs from disparate files
ZackAttack614 Oct 1, 2025
d3fd89e
Only concern the module_map with py files
ZackAttack614 Oct 1, 2025
2b8861c
Remove merge conflict issue
psavery Oct 1, 2025
e09f301
Fix duplicated function identification in module_map
ZackAttack614 Oct 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build:
number: {{ environ.get('GIT_DESCRIBE_NUMBER', 0) }}
detect_binary_files_with_prefix: true
entry_points:
- hexrd = hexrd.cli.main:main
- hexrd = hexrd.hedm.cli.main:main

requirements:
build:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import os
import sys

from hexrd.constants import __version__ as version
from hexrd.core.constants import __version__ as version

sys.path.insert(0, os.path.abspath('../..'))

Expand Down
29 changes: 22 additions & 7 deletions hexrd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import importlib
import importlib.abc
import importlib.machinery
import sys

from .material import crystallography
from .material import jcpds
from .material import mksupport
from .material import spacegroup
from .material import symbols
from .material import symmetry
from .material import unitcell
from .core.material import crystallography
from .core.material import jcpds
from .core.material import mksupport
from .core.material import spacegroup
from .core.material import symbols
from .core.material import symmetry
from .core.material import unitcell

# These are aliases for import paths, so we don't break old HEXRD scripts.
# We will verify the alias files *do not* exist, to avoid confusion.
Expand All @@ -30,3 +32,16 @@
raise Exception(f'"{alias}" is an alias path and should not exist')

sys.modules[alias] = module


from . import module_map


def __getattr__(name):
# __getattr__ is only called if the attribute doesn't exist
module = module_map.get("hexrd." + name)
if module is not None:
if isinstance(module, str):
return importlib.import_module(module)
return module
raise AttributeError(f"Module `hexrd` has no attribute {name}")
24 changes: 12 additions & 12 deletions hexrd/copyright.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# ============================================================
# Copyright (c) 2012, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
# Written by Joel Bernier <[email protected]> and others.
# LLNL-CODE-529294.
# Copyright (c) 2012, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
# Written by Joel Bernier <[email protected]> and others.
# LLNL-CODE-529294.
# All rights reserved.
#
#
# This file is part of HEXRD. For details on dowloading the source,
# see the file COPYING.
#
#
# Please also see the file LICENSE.
#
#
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License (as published by the Free Software
# Foundation) version 2.1 dated February 1999.
#
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program (see file LICENSE); if not, write to
# the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Expand All @@ -36,4 +36,4 @@

COPYRIGHT_FILE = 'COPYING'
with open(os.path.join(os.path.dirname(__file__), COPYRIGHT_FILE), 'r') as f:
COPYRIGHT_TEXT = f.read()
COPYRIGHT_TEXT = f.read()
File renamed without changes.
2 changes: 1 addition & 1 deletion hexrd/config/beam.py → hexrd/core/config/beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np

from .config import Config
from hexrd import imageseries
from hexrd.core import imageseries


class Beam(Config):
Expand Down
14 changes: 6 additions & 8 deletions hexrd/config/config.py → hexrd/core/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

logger = logging.getLogger('hexrd.config')


class Config(object):
"""Access a level of the YAML configuration file

Expand All @@ -15,6 +16,7 @@ class Config(object):
cfg: Config instance or a (pyyaml) YAMLObject
config representings a level of the YAML input
"""

_dirty = False

def __init__(self, cfg):
Expand All @@ -41,14 +43,12 @@ def get(self, key, default=null):
res = temp[item]
except KeyError:
if default is not null:
logger.info(
'%s not specified, defaulting to %s', key, default
)
logger.info('%s not specified, defaulting to %s', key, default)
res = temp.get(item, default)
else:
raise RuntimeError(
'%s must be specified in configuration file' % key
)
)
return res

def set(self, key, val):
Expand Down Expand Up @@ -80,12 +80,10 @@ def check_filename(fname, wdir):

If fname is an absolute path, use that; otherwise take it as a path
relative to the working directory.
"""
"""
temp = fname
if not os.path.isabs(fname):
temp = os.path.join(wdir, temp)
if os.path.exists(temp):
return temp
raise IOError(
'file: "%s" not found' % temp
)
raise IOError('file: "%s" not found' % temp)
8 changes: 5 additions & 3 deletions hexrd/config/dumper.py → hexrd/core/config/dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def _dict_path_by_id(d, value, path=()):
return path
elif isinstance(d, dict):
for k, v in d.items():
p = _dict_path_by_id(v, value, path + (k, ))
p = _dict_path_by_id(v, value, path + (k,))
if p is not None:
return p
elif isinstance(d, list):
Expand All @@ -32,6 +32,7 @@ class NumPyIncludeDumper(yaml.Dumper):
The ndarray would be saved in foo/bar.npy.

"""

def __init__(self, stream, **kwargs):
super().__init__(stream, **kwargs)

Expand All @@ -58,5 +59,6 @@ def represent(self, data):
return super().represent(data)


NumPyIncludeDumper.add_representer(np.ndarray,
NumPyIncludeDumper.ndarray_representer)
NumPyIncludeDumper.add_representer(
np.ndarray, NumPyIncludeDumper.ndarray_representer
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .config import Config
from hexrd import imageseries
from hexrd.core import imageseries

from hexrd.constants import shared_ims_key
from hexrd.core.constants import shared_ims_key


class ImageSeries(Config):
Expand Down Expand Up @@ -34,7 +34,7 @@ def imageseries(self):
panel = '_'.join(panel)
elif panel is None:
panel = shared_ims_key
except(KeyError):
except KeyError:
panel = shared_ims_key
self._image_dict[panel] = oms

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .config import Config
from .loader import NumPyIncludeLoader

from hexrd import instrument
from hexrd.core import instrument


class Instrument(Config):
Expand All @@ -31,7 +31,7 @@ def hedm(self):

try:
icfg = h5py.File(self.configuration, 'r')
except(OSError):
except OSError:
with open(self.configuration, 'r') as f:
icfg = yaml.load(f, Loader=NumPyIncludeLoader)

Expand All @@ -47,7 +47,7 @@ def hedm(self, icfg_fname):
"""Set the HEDMInstrument class."""
try:
icfg = h5py.File(icfg_fname, 'r')
except(OSError):
except OSError:
with open(icfg_fname, 'r') as f:
icfg = yaml.load(f, Loader=NumPyIncludeLoader)

Expand Down
File renamed without changes.
14 changes: 6 additions & 8 deletions hexrd/config/material.py → hexrd/core/config/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import numpy as np

from hexrd import material
from hexrd.constants import keVToAngstrom
from hexrd.valunits import valWUnit
from hexrd.core import material
from hexrd.core.constants import keVToAngstrom
from hexrd.core.valunits import valWUnit

from .config import Config
from .utils import get_exclusion_parameters


DMIN_DFLT = 0.5 # angstrom
TTHW_DFLT = 0.25 # degrees
DMIN_DFLT = 0.5 # angstrom
TTHW_DFLT = 0.25 # degrees


class MaterialConfig(Config):
Expand All @@ -30,9 +30,7 @@ def definitions(self):
temp = os.path.join(self._cfg.working_dir, temp)
if os.path.exists(temp):
return temp
raise IOError(
f'"material:definitions": "{temp}" does not exist'
)
raise IOError(f'"material:definitions": "{temp}" does not exist')

@property
def active(self):
Expand Down
39 changes: 21 additions & 18 deletions hexrd/config/root.py → hexrd/core/config/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import logging
import multiprocessing as mp

from hexrd.constants import shared_ims_key
from hexrd import imageseries
from hexrd.core.constants import shared_ims_key
from hexrd.core import imageseries

from .config import Config
from .instrument import Instrument
from .findorientations import FindOrientationsConfig
from .fitgrains import FitGrainsConfig

# TODO: Resolve extra-core-dependency
from hexrd.hedm.config.findorientations import FindOrientationsConfig
from hexrd.hedm.config.fitgrains import FitGrainsConfig
from .material import MaterialConfig

logger = logging.getLogger('hexrd.config')
Expand Down Expand Up @@ -67,8 +69,10 @@ def analysis_dir(self):
@property
def analysis_id(self):
return '_'.join(
[self.analysis_name.strip().replace(' ', '-'),
self.material.active.strip().replace(' ', '-')]
[
self.analysis_name.strip().replace(' ', '-'),
self.material.active.strip().replace(' ', '-'),
]
)

@property
Expand Down Expand Up @@ -134,8 +138,9 @@ def multiprocessing(self):
if multiproc > ncpus:
logger.warning(
'Resuested %s processes, %d available',
multiproc, ncpus
)
multiproc,
ncpus,
)
res = ncpus
else:
res = multiproc if multiproc else 1
Expand All @@ -144,17 +149,15 @@ def multiprocessing(self):
if temp < 1:
logger.warning(
'Cannot use less than 1 process, requested %d of %d',
temp, ncpus
)
temp,
ncpus,
)
res = 1
else:
res = temp
else:
temp = ncpus - 1
logger.warning(
"Invalid value %s for multiprocessing",
multiproc
)
logger.warning("Invalid value %s for multiprocessing", multiproc)
res = temp
return res

Expand All @@ -163,13 +166,13 @@ def multiprocessing(self, val):
isint = isinstance(val, int)
if val in ('half', 'all', -1):
self.set('multiprocessing', val)
elif (isint and val >= 0 and val <= mp.cpu_count()):
elif isint and val >= 0 and val <= mp.cpu_count():
self.set('multiprocessing', int(val))
else:
raise RuntimeError(
'"multiprocessing": must be 1:%d, got %s'
% (mp.cpu_count(), val)
)
)

@property
def image_series(self):
Expand All @@ -189,10 +192,10 @@ def image_series(self):
panel = '_'.join(panel)
elif panel is None:
panel = shared_ims_key
except(KeyError):
except KeyError:
try:
panel = oms.metadata['panel']
except(KeyError):
except KeyError:
panel = shared_ims_key
self._image_dict[panel] = oms

Expand Down
Loading
Loading