diff --git a/python/damask/_geom.py b/python/damask/_geom.py index 8fa0b533a..60f7b90a5 100644 --- a/python/damask/_geom.py +++ b/python/damask/_geom.py @@ -453,8 +453,6 @@ class Geom: Parameters ---------- - geom : Geom object - Geometry to write. fname : str or file handle Geometry file to write with extension '.geom'. pack : bool, optional @@ -526,8 +524,6 @@ class Geom: Parameters ---------- - geom : Geom object - Geometry to write with extension '.vtr'. fname : str, optional Filename to write. If no file is given, a string is returned. Valid extension is .vtr, it will be appended if not given. diff --git a/python/damask/_table.py b/python/damask/_table.py index 987233153..3215cd8db 100644 --- a/python/damask/_table.py +++ b/python/damask/_table.py @@ -66,7 +66,7 @@ class Table: @staticmethod def load_ASCII(fname): """ - Create table from ASCII file. + Load ASCII table file. In legacy style, the first line indicates the number of subsequent header lines as "N header", with the last header line being @@ -124,7 +124,7 @@ class Table: @staticmethod def load_ang(fname): """ - Create table from TSL ang file. + Load ang file. A valid TSL ang file needs to contains the following columns: * Euler angles (Bunge notation) in radians, 3 floats, label 'eu'. @@ -341,14 +341,12 @@ class Table: return dup - def save_ASCII(table,fname,legacy=False): + def save_ASCII(self,fname,legacy=False): """ - Store as plain text file. + Save as plain text file. Parameters ---------- - table : Table object - Table to write. fname : file, str, or pathlib.Path Filename or file for writing. legacy : Boolean, optional @@ -358,23 +356,23 @@ class Table: """ seen = set() labels = [] - for l in [x for x in table.data.columns if not (x in seen or seen.add(x))]: - if table.shapes[l] == (1,): + for l in [x for x in self.data.columns if not (x in seen or seen.add(x))]: + if self.shapes[l] == (1,): labels.append(f'{l}') - elif len(table.shapes[l]) == 1: + elif len(self.shapes[l]) == 1: labels += [f'{i+1}_{l}' \ - for i in range(table.shapes[l][0])] + for i in range(self.shapes[l][0])] else: - labels += [f'{util.srepr(table.shapes[l],"x")}:{i+1}_{l}' \ - for i in range(np.prod(table.shapes[l]))] + labels += [f'{util.srepr(self.shapes[l],"x")}:{i+1}_{l}' \ + for i in range(np.prod(self.shapes[l]))] - header = ([f'{len(table.comments)+1} header'] + table.comments) if legacy else \ - [f'# {comment}' for comment in table.comments] + header = ([f'{len(self.comments)+1} header'] + self.comments) if legacy else \ + [f'# {comment}' for comment in self.comments] try: - f = open(fname,'w') + fhandle = open(fname,'w') except TypeError: - f = fname + fhandle = fname - for line in header + [' '.join(labels)]: f.write(line+'\n') - table.data.to_csv(f,sep=' ',na_rep='nan',index=False,header=False) + for line in header + [' '.join(labels)]: fhandle.write(line+'\n') + self.data.to_csv(fhandle,sep=' ',na_rep='nan',index=False,header=False) diff --git a/python/tests/test_Orientation.py b/python/tests/test_Orientation.py index bee3c8c59..3a7425ddb 100644 --- a/python/tests/test_Orientation.py +++ b/python/tests/test_Orientation.py @@ -106,7 +106,7 @@ class TestOrientation: coords = np.array([(1,i+1) for i,x in enumerate(eu)]) table = Table(eu,{'Eulers':(3,)}) table = table.add('pos',coords) - table.write(reference) + table.save_ASCII(reference) assert np.allclose(eu,Table.load_ASCII(reference).get('Eulers')) @pytest.mark.parametrize('lattice',Lattice.lattices)