def read_scalar(el, ns, set_id, step, newdir, wrt_file): grain = np.zeros([ns, el**3]) # nwd = os.getcwd() + '\\' + newdir nwd = os.getcwd() + '/' + newdir # for unix os.chdir(nwd) sn = 0 if set_id == "cal": for filename in os.listdir(nwd): if filename.endswith('%s.vtk' % step): grain[sn, :] = rr.read_vtk_scalar(filename=filename) sn += 1 else: for filename in os.listdir(nwd): if filename.endswith('.vtk'): grain[sn, :] = rr.read_vtk_scalar(filename=filename) sn += 1 # return to the original directory os.chdir('..') np.save('gID_%s%s_s%s' % (ns, set_id, step), grain)
def read_fip(el, ns, set_id, step, newdir, wrt_file): start = time.time() fip = np.zeros([ns, el**3]) nwd = os.getcwd() + '\\' + newdir # nwd = os.getcwd() + '/' + newdir # for unix os.chdir(nwd) sn = 0 for filename in os.listdir(nwd): if filename.endswith('%s.vtk' % step): fip[sn, :] = rr.read_vtk_scalar(filename=filename) sn += 1 """return to the original directory""" os.chdir('..') f = h5py.File("fip_%s%s_s%s.hdf5" % (ns, set_id, step), 'a') f.create_dataset('fip', data=fip) f.close() end = time.time() timeE = np.round((end - start), 3) msg = 'fip values read from .vtk file for %s: %s seconds' % (set_id, timeE) rr.WP(msg, wrt_file)
def read_scalar(el, ns, set_id, step, newdir, wrt_file): start = time.time() grain = np.zeros([ns, el**3]) # nwd = os.getcwd() + '\\' + newdir nwd = os.getcwd() + '/' + newdir # for unix os.chdir(nwd) sn = 0 # for filename in os.listdir(nwd): # if filename.endswith('%s.vtk' % step): # grain[sn, :] = rr.read_vtk_scalar(filename=filename) # sn += 1 for sn in xrange(ns): filename = "Ti64_Dream3D_v01_Output_%s.vtk" % str(sn + 1) grain[sn, :] = rr.read_vtk_scalar(filename=filename) # return to the original directory os.chdir('..') f = h5py.File("data.hdf5", 'a') dset_name = 'gID_%s%s_s%s' % (ns, set_id, step) f.create_dataset(dset_name, data=grain) f.close() end = time.time() timeE = np.round((end - start), 3) msg = 'The scalar of interest has been read from .vtk file for %s: %s seconds' % ( set_id, timeE) rr.WP(msg, wrt_file)
def read_fip(ns, set_id, newdir): start = time.time() C = const() fip = np.zeros([ns, C['el']**3]) # nwd = os.getcwd() + '\\' + newdir nwd = os.getcwd() + '/' + newdir # for unix os.chdir(nwd) sn = 0 for filename in os.listdir(nwd): if filename.endswith('%s.vtk' % C['step']): fip[sn, :] = rr.read_vtk_scalar(filename=filename) sn += 1 """return to the original directory""" os.chdir('..') f = h5py.File("responses.hdf5", 'a') f.create_dataset('fip_%s' % set_id, data=(1e9) * fip) f.close() end = time.time() timeE = np.round((end - start), 3) msg = 'fip values read from .vtk file for %s: %s seconds' % (set_id, timeE) rr.WP(msg, C['wrt_file'])
import os import matplotlib.pyplot as plt from sklearn.preprocessing import PolynomialFeatures from sklearn import linear_model if __name__ == '__main__': newdir = 'cal' pcnt = .0 # nwd = os.getcwd() + '\\' + newdir nwd = os.getcwd() + '/' + newdir # for unix os.chdir(nwd) for filename in os.listdir(nwd): fip = rr.read_vtk_scalar(filename=filename) fip = np.sort(fip) """return to the original directory""" os.chdir('..') """get the data for the fit""" x = fip x = x[np.int64(pcnt * x.size):, None] y = (np.arange(x.size) + 1) / np.float32(x.size) """get the desired fits""" poly = PolynomialFeatures(degree=20) X = poly.fit_transform(np.log(x)) clf = linear_model.LinearRegression() clf.fit(X, y)