Merge branch 'python-improvements' into 'development'

Python improvements

See merge request damask/DAMASK!343
This commit is contained in:
Sharan Roongta 2021-02-22 12:22:02 +00:00
commit 23a3354ac1
7 changed files with 28 additions and 32 deletions

View File

@ -84,7 +84,7 @@ for executable in python python3; do
done
secondLevel "Details on $DEFAULT_PYTHON:"
echo $(ls -la $(which $DEFAULT_PYTHON))
for module in numpy scipy pandas;do
for module in numpy scipy pandas matplotlib yaml h5py;do
thirdLevel $module
$DEFAULT_PYTHON -c "import $module; \
print('Version: {}'.format($module.__version__)); \
@ -94,10 +94,6 @@ thirdLevel vtk
$DEFAULT_PYTHON -c "import vtk; \
print('Version: {}'.format(vtk.vtkVersion.GetVTKVersion())); \
print('Location: {}'.format(vtk.__file__))"
thirdLevel h5py
$DEFAULT_PYTHON -c "import h5py; \
print('Version: {}'.format(h5py.version.version)); \
print('Location: {}'.format(h5py.__file__))"
firstLevel "GNU Compiler Collection"
for executable in gcc g++ gfortran ;do

View File

@ -103,7 +103,6 @@ class ConfigMaterial(Config):
"""Check for completeness."""
ok = True
for top_level in ['homogenization','phase','material']:
# ToDo: With python 3.8 as prerequisite we can shorten with :=
ok &= top_level in self
if top_level not in self: print(f'{top_level} entry missing')
@ -203,7 +202,7 @@ class ConfigMaterial(Config):
"""
dup = self.copy()
for i,m in enumerate(dup['material']):
if ID and i not in ID: continue
if ID is not None and i not in ID: continue
for c in m['constituents']:
if constituent is not None and c not in constituent: continue
try:
@ -227,7 +226,7 @@ class ConfigMaterial(Config):
"""
dup = self.copy()
for i,m in enumerate(dup['material']):
if ID and i not in ID: continue
if ID is not None and i not in ID: continue
try:
m['homogenization'] = mapping[m['homogenization']]
except KeyError:

View File

@ -202,7 +202,7 @@ class Grid:
Geometry file to read.
"""
warnings.warn('Support for ASCII-based geom format will be removed in DAMASK 3.1.0', DeprecationWarning)
warnings.warn('Support for ASCII-based geom format will be removed in DAMASK 3.1.0', DeprecationWarning,2)
try:
f = open(fname)
except TypeError:
@ -541,7 +541,7 @@ class Grid:
Compress geometry with 'x of y' and 'a to b'.
"""
warnings.warn('Support for ASCII-based geom format will be removed in DAMASK 3.1.0', DeprecationWarning)
warnings.warn('Support for ASCII-based geom format will be removed in DAMASK 3.1.0', DeprecationWarning,2)
header = [f'{len(self.comments)+4} header'] + self.comments \
+ ['grid a {} b {} c {}'.format(*self.cells),
'size x {} y {} z {}'.format(*self.size),
@ -760,7 +760,7 @@ class Grid:
"""
if fill is None: fill = np.nanmax(self.material) + 1
dtype = float if np.isnan(fill) or int(fill) != fill or self.material.dtype==np.float else int
dtype = float if isinstance(fill,float) or self.material.dtype in np.sctypes['float'] else int
material = self.material
# These rotations are always applied in the reference coordinate system, i.e. (z,x,z) not (z,x',z'')

View File

@ -246,8 +246,8 @@ class VTK:
raise ValueError('No label defined for numpy.ndarray')
N_data = data.shape[0]
d = np_to_vtk((data.astype(np.float32) if data.dtype in [np.float64, np.float128]
else data).reshape(N_data,-1),deep=True) # avoid large files
d = np_to_vtk((data.astype(np.single) if data.dtype in [np.double, np.longdouble] else
data).reshape(N_data,-1),deep=True) # avoid large files
d.SetName(label)
if N_data == N_points:

View File

@ -183,7 +183,7 @@ def scale_to_coprime(v):
# Python 3.9 provides math.lcm, see https://stackoverflow.com/questions/51716916.
return a * b // np.gcd(a, b)
m = (np.array(v) * reduce(lcm, map(lambda x: int(get_square_denominator(x)),v)) ** 0.5).astype(np.int)
m = (np.array(v) * reduce(lcm, map(lambda x: int(get_square_denominator(x)),v)) ** 0.5).astype(int)
m = m//reduce(np.gcd,m)
with np.errstate(invalid='ignore'):

View File

@ -6,28 +6,29 @@ with open(Path(__file__).parent/'damask/VERSION') as f:
version = re.sub(r'(-([^-]*)).*$',r'.\2',re.sub(r'^v(\d+\.\d+(\.\d+)?)',r'\1',f.readline().strip()))
setuptools.setup(
name="damask",
name='damask',
version=version,
author="The DAMASK team",
author_email="damask@mpie.de",
description="DAMASK library",
long_description="Python library for pre and post processing of DAMASK simulations",
url="https://damask.mpie.de",
author='The DAMASK team',
author_email='damask@mpie.de',
description='DAMASK library',
long_description='Python library for pre and post processing of DAMASK simulations',
url='https://damask.mpie.de',
packages=setuptools.find_packages(),
include_package_data=True,
python_requires = '>=3.6',
install_requires = [
"pandas", # requires numpy
"scipy",
"h5py", # requires numpy
"vtk",
"matplotlib", # requires numpy, pillow
"pyaml"
'pandas>=0.24', # requires numpy
'scipy>=1.2',
'h5py>=2.9', # requires numpy
'vtk>=8.1',
'matplotlib>=3.0', # requires numpy, pillow
'pyaml>=3.12'
],
classifiers = [
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Operating System :: OS Independent",
'Intended Audience :: Science/Research',
'Topic :: Scientific/Engineering',
'Programming Language :: Python :: 3',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'Operating System :: OS Independent',
],
)

View File

@ -347,7 +347,7 @@ class TestGrid:
@pytest.mark.parametrize('approach',['Laguerre','Voronoi'])
def test_tessellate_bicrystal(self,approach):
cells = np.random.randint(5,10,3)*2
size = cells.astype(np.float)
size = cells.astype(float)
seeds = np.vstack((size*np.array([0.5,0.25,0.5]),size*np.array([0.5,0.75,0.5])))
material = np.zeros(cells)
material[:,cells[1]//2:,:] = 1