From 229f6139c837d79321b13bc11a8039dcfafa9a5b Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 26 Aug 2020 23:54:56 +0200 Subject: [PATCH] better user experience - no meaningless warnings regarding floating point precision - meaningful error message for invalid header --- python/damask/_geom.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/python/damask/_geom.py b/python/damask/_geom.py index 08b0b8757..1570c3a9f 100644 --- a/python/damask/_geom.py +++ b/python/damask/_geom.py @@ -300,13 +300,16 @@ class Geom: f = fname f.seek(0) - header_length,keyword = f.readline().split()[:2] - header_length = int(header_length) - content = f.readlines() - + try: + header_length,keyword = f.readline().split()[:2] + header_length = int(header_length) + except ValueError: + header_length,keyword = (-1, 'invalid') if not keyword.startswith('head') or header_length < 3: raise TypeError('Header length information missing or invalid') + content = f.readlines() + comments = [] for i,line in enumerate(content[:header_length]): items = line.split('#')[0].lower().strip().split() @@ -584,7 +587,7 @@ class Geom: - ((np.ones(3)-(1./self.grid if np.array(center).dtype in np.sctypes['int'] else 0))*0.5 if periodic else c) # periodic center is always at CoG coords_rot = R.broadcast_to(tuple(self.grid))@coords - with np.errstate(over='ignore',under='ignore'): + with np.errstate(over='ignore',under='ignore',invalid='ignore'): mask = np.where(np.sum(np.power(coords_rot/r,2.0**exponent),axis=-1) <= 1.0,False,True) if periodic: # translate back to center