better readable

- more explicit reporting
- always relative import for DAMASK
This commit is contained in:
Martin Diehl 2020-08-24 09:55:41 +02:00
parent b393da4955
commit 9d505c8518
10 changed files with 45 additions and 33 deletions

View File

@ -10,7 +10,7 @@ import matplotlib.pyplot as plt
from matplotlib import cm
from PIL import Image
import damask
from . import util
from . import Table
_eps = 216./24389.
@ -280,7 +280,7 @@ class Colormap(mpl.colors.ListedColormap):
colors+=[i]+c
out = [{
'Creator':f'damask.Colormap v{damask.version}',
'Creator':util.version_date('Colormap'),
'ColorSpace':'RGB',
'Name':colormap.name,
'DefaultMap':True,
@ -296,7 +296,7 @@ class Colormap(mpl.colors.ListedColormap):
def _export_ASCII(colormap,fhandle=None):
"""Write colormap to ASCII table."""
labels = {'RGBA':4} if colormap.colors.shape[1] == 4 else {'RGB': 3}
t = Table(colormap.colors,labels,f'Creator: damask.Colormap v{damask.version}')
t = Table(colormap.colors,labels,f'Creator: {util.version_date("Colormap")}')
if fhandle is None:
with open(colormap.name.replace(' ','_')+'.txt', 'w') as f:

View File

@ -1,6 +1,5 @@
import sys
import copy
import inspect
import multiprocessing
from io import StringIO
from functools import partial
@ -399,7 +398,7 @@ class Geom:
else:
microstructure = microstructure.reshape(grid)
creator = util.edit_info('damask.Geom.'+inspect.stack()[0][3])
creator = util.version_date('Geom','from_Laguerre_tessellation')
return Geom(microstructure+1,size,homogenization=1,comments=creator)
@ -424,7 +423,7 @@ class Geom:
KDTree = spatial.cKDTree(seeds,boxsize=size) if periodic else spatial.cKDTree(seeds)
devNull,microstructure = KDTree.query(coords)
creator = util.edit_info('damask.Geom.'+inspect.stack()[0][3])
creator = util.version_date('Geom','from_Voronoi_tessellation')
return Geom(microstructure.reshape(grid)+1,size,homogenization=1,comments=creator)
@ -576,7 +575,7 @@ class Geom:
fill_ = np.full_like(self.microstructure,np.nanmax(self.microstructure)+1 if fill is None else fill)
ms = np.ma.MaskedArray(fill_,np.logical_not(mask) if inverse else mask)
self.add_comments(util.edit_info('damask.Geom.'+inspect.stack()[0][3]))
self.add_comments(util.version_date('Geom','add_primitive'))
return self.update(ms)
@ -607,7 +606,7 @@ class Geom:
if 'x' in directions:
ms = np.concatenate([ms,ms[limits[0]:limits[1]:-1,:,:]],0)
self.add_comments(util.edit_info('damask.Geom.'+inspect.stack()[0][3]))
self.add_comments(util.version_date('Geom','mirror'))
return self.update(ms,rescale=True)
@ -623,7 +622,7 @@ class Geom:
Assume geometry to be periodic. Defaults to True.
"""
self.add_comments(util.edit_info('damask.Geom.'+inspect.stack()[0][3]))
self.add_comments(util.version_date('Geom','scale'))
return self.update(
ndimage.interpolation.zoom(
self.microstructure,
@ -658,7 +657,7 @@ class Geom:
else:
return me
self.add_comments(util.edit_info('damask.Geom.'+inspect.stack()[0][3]))
self.add_comments(util.version_date('Geom','clean'))
return self.update(ndimage.filters.generic_filter(
self.microstructure,
mostFrequent,
@ -675,7 +674,7 @@ class Geom:
for i, oldID in enumerate(np.unique(self.microstructure)):
renumbered = np.where(self.microstructure == oldID, i+1, renumbered)
self.add_comments(util.edit_info('damask.Geom.'+inspect.stack()[0][3]))
self.add_comments(util.version_date('Geom','renumber'))
return self.update(renumbered)
@ -710,7 +709,7 @@ class Geom:
origin = self.origin-(np.asarray(microstructure_in.shape)-self.grid)*.5 * self.size/self.grid
self.add_comments(util.edit_info('damask.Geom.'+inspect.stack()[0][3]))
self.add_comments(util.version_date('Geom','rotate'))
return self.update(microstructure_in,origin=origin,rescale=True)
@ -743,7 +742,7 @@ class Geom:
canvas[ll[0]:ur[0],ll[1]:ur[1],ll[2]:ur[2]] = self.microstructure[LL[0]:UR[0],LL[1]:UR[1],LL[2]:UR[2]]
self.add_comments(util.edit_info('damask.Geom.'+inspect.stack()[0][3]))
self.add_comments(util.version_date('Geom','canvas'))
return self.update(canvas,origin=self.origin+offset*self.size/self.grid,rescale=True)
@ -763,7 +762,7 @@ class Geom:
for from_ms,to_ms in zip(from_microstructure,to_microstructure):
substituted[self.microstructure==from_ms] = to_ms
self.add_comments(util.edit_info('damask.Geom.'+inspect.stack()[0][3]))
self.add_comments(util.version_date('Geom','substitute'))
return self.update(substituted)
@ -809,5 +808,5 @@ class Geom:
extra_keywords={'trigger':trigger})
microstructure = np.ma.MaskedArray(self.microstructure + offset_, np.logical_not(mask))
self.add_comments(util.edit_info('damask.Geom.'+inspect.stack()[0][3]))
self.add_comments(util.version_date('Geom','vicinity_offset'))
return self.update(microstructure)

View File

@ -8,7 +8,8 @@ from vtk.util.numpy_support import numpy_to_vtk as np_to_vtk
from vtk.util.numpy_support import numpy_to_vtkIdTypeArray as np_to_vtkIdTypeArray
from vtk.util.numpy_support import vtk_to_numpy as vtk_to_np
import damask
from . import util
from . import environment
from . import Table
@ -314,7 +315,7 @@ class VTK:
def __repr__(self):
"""ASCII representation of the VTK data."""
writer = vtk.vtkDataSetWriter()
writer.SetHeader(f'# damask.VTK v{damask.version}')
writer.SetHeader(f'# {util.version_date("VTK")}')
writer.WriteToOutputStringOn()
writer.SetInputData(self.geom)
writer.Write()
@ -340,7 +341,7 @@ class VTK:
ren.AddActor(actor)
ren.SetBackground(0.2,0.2,0.2)
window.SetSize(damask.environment.screen_size[0],damask.environment.screen_size[1])
window.SetSize(environment.screen_size[0],environment.screen_size[1])
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(window)

View File

@ -3,12 +3,12 @@ import shlex
import string
from pathlib import Path
import damask
from .. import environment
class Marc:
"""Wrapper to run DAMASK with MSCMarc."""
def __init__(self,version=damask.environment.options['MARC_VERSION']):
def __init__(self,version=environment.options['MARC_VERSION']):
"""
Create a Marc solver object.
@ -24,7 +24,7 @@ class Marc:
@property
def library_path(self):
path_MSC = damask.environment.options['MSC_ROOT']
path_MSC = environment.options['MSC_ROOT']
path_lib = Path(f'{path_MSC}/mentat{self.version}/shlib/linux64')
return path_lib if path_lib.is_dir() else None
@ -33,7 +33,7 @@ class Marc:
@property
def tools_path(self):
path_MSC = damask.environment.options['MSC_ROOT']
path_MSC = environment.options['MSC_ROOT']
path_tools = Path(f'{path_MSC}/marc{self.version}/tools')
return path_tools if path_tools.is_dir() else None
@ -49,7 +49,7 @@ class Marc:
):
usersub = damask.environment.root_dir/'src/DAMASK_marc'
usersub = environment.root_dir/'src/DAMASK_marc'
usersub = usersub.parent/(usersub.name + ('.f90' if compile else '.marc'))
if not usersub.is_file():
raise FileNotFoundError("DAMASK4Marc ({}) '{}' not found".format(('source' if compile else 'binary'),usersub))

View File

@ -9,7 +9,7 @@ from optparse import Option
import numpy as np
import damask
from . import version
# limit visibility
__all__=[
@ -22,7 +22,7 @@ __all__=[
'scale_to_coprime',
'return_message',
'extendableOption',
'edit_info'
'version_date'
]
####################################################################################################
@ -178,9 +178,11 @@ def scale_to_coprime(v):
return m
def edit_info(who):
def version_date(class_name,function_name=None):
"""tbd."""
_function_name = '' if function_name is None else f'.{function_name}'
now = datetime.datetime.now().astimezone().strftime('%Y-%m-%d %H:%M:%S%z')
return f'{who} v{damask.version} ({now})'
return f'damask.{class_name}{_function_name} v{version} ({now})'
####################################################################################################

View File

@ -25,6 +25,15 @@ def patch_datetime_now(monkeypatch):
monkeypatch.setattr(datetime, 'datetime', mydatetime)
@pytest.fixture
def version_date(monkeypatch):
"""Set damask.util.version_date for reproducible tests results."""
def version_date(class_name,function_name=None):
_function_name = '' if function_name is None else f'.{function_name}'
return f'damask.{class_name}{_function_name} v{patched_version} ({patched_date})'
monkeypatch.setattr(damask.util, 'version_date', version_date)
def pytest_addoption(parser):
parser.addoption("--update",

View File

@ -1,6 +1,6 @@
[
{
"Creator": "damask.Colormap v99.99.99-9999-pytest",
"Creator": "damask.Colormap v99.99.99-9999-pytest (2019-11-02 11:58:00)",
"ColorSpace": "RGB",
"Name": "binary",
"DefaultMap": true,

View File

@ -1,4 +1,4 @@
# Creator: damask.Colormap v99.99.99-9999-pytest
# Creator: damask.Colormap v99.99.99-9999-pytest (2019-11-02 11:58:00)
1_RGBA 2_RGBA 3_RGBA 4_RGBA
1.0 1.0 1.0 1.0
0.996078431372549 0.996078431372549 0.996078431372549 1.0

View File

@ -17,8 +17,8 @@ def reference_dir(reference_dir_base):
class TestColormap:
@pytest.fixture(autouse=True)
def _patch_damask_version(self, patch_damask_version):
print('patched damask.version')
def _version_date(self, version_date):
print('patched damask.util.version_date')
def test_conversion(self):
specials = np.array([[0.,0.,0.],

View File

@ -4,6 +4,7 @@ from itertools import permutations
import pytest
import numpy as np
from damask import Table
from damask import Rotation
from damask import Orientation
from damask import Lattice
@ -103,10 +104,10 @@ class TestOrientation:
eu = np.array([o.rotation.as_Eulers(degrees=True) for o in ori.related(model)])
if update:
coords = np.array([(1,i+1) for i,x in enumerate(eu)])
table = damask.Table(eu,{'Eulers':(3,)})
table = Table(eu,{'Eulers':(3,)})
table.add('pos',coords)
table.to_ASCII(reference)
assert np.allclose(eu,damask.Table.from_ASCII(reference).get('Eulers'))
assert np.allclose(eu,Table.from_ASCII(reference).get('Eulers'))
@pytest.mark.parametrize('lattice',Lattice.lattices)
def test_disorientation360(self,lattice):