From d42f8d5fd4958bbc1015f4db495995e814fbf823 Mon Sep 17 00:00:00 2001 From: Zhuowen Zhao Date: Thu, 17 Mar 2016 17:40:40 -0400 Subject: [PATCH] added possibility to read real numbers as microstructure indices (not only integers) --- lib/damask/asciitable.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/damask/asciitable.py b/lib/damask/asciitable.py index 4abe4297d..5212ef00c 100644 --- a/lib/damask/asciitable.py +++ b/lib/damask/asciitable.py @@ -517,21 +517,25 @@ class ASCIItable(): # ------------------------------------------------------------------ def microstructure_read(self, - grid): + grid, + type = 'i'): """read microstructure data (from .geom format)""" - N = grid.prod() # expected number of microstructure indices in data - microstructure = np.zeros(N,'i') # initialize as flat array + def datatype(item): + return int(item) if type.lower() == 'i' else float(item) + + N = grid.prod() # expected number of microstructure indices in data + microstructure = np.zeros(N,type) # initialize as flat array i = 0 while i < N and self.data_read(): items = self.data if len(items) > 2: - if items[1].lower() == 'of': items = [int(items[2])]*int(items[0]) - elif items[1].lower() == 'to': items = range(int(items[0]),1+int(items[2])) - else: items = map(int,items) - else: items = map(int,items) + if items[1].lower() == 'of': items = np.ones(datatype(items[0]))*datatype(items[2]) + elif items[1].lower() == 'to': items = np.arange(datatype(items[0]),1+datatype(items[2])) + else: items = map(datatype,items) + else: items = map(datatype,items) - s = min(len(items), N-i) # prevent overflow of microstructure array + s = min(len(items), N-i) # prevent overflow of microstructure array microstructure[i:i+s] = items[:s] i += s