def eigenvects(self): """ Returns Group of three eigenvectors represented as ``Vec3`` """ return Group([Vec3(self.vects.T[0]), Vec3(self.vects.T[1]), Vec3(self.vects.T[2])])
def eigenvects(self): """ Return ```Group``` of principal eigenvectors as ``Vec3`` objects. """ U, _, _ = np.linalg.svd(self) return Group([Vec3(U.T[0]), Vec3(U.T[1]), Vec3(U.T[2])])
def eigenvects(self) -> Group: """ Return the group of eigenvectors. If scaled property is `True` their length is scaled by eigenvalues, otherwise unit length. """ if self.scaled: e1, e2, e3 = self.E1, self.E2, self.E3 else: e1 = e2 = e3 = 1.0 return Group([ e1 * Vec3(self._evects[0]), e2 * Vec3(self._evects[1]), e3 * Vec3(self._evects[2]), ])
def pca(self, kind='geo', origin=False): data = getattr(self, kind) if origin: data.append(Vec3([0, 0, 0])) r = data.R / len(data) dv = Group([v - r for v in data]) ot = dv.ortensor pca = ot.eigenvects[0] if pca.angle(r) > 90: pca = -pca mad = np.degrees(np.arctan(np.sqrt((ot.E2 + ot.E3) / ot.E1))) return pca, mad
def cauchy(self, n): """ Return stress vector associated with plane given by normal vector. Args: n: normal given as ``Vec3`` or ``Fol`` object Example: >>> S = Stress.from_comp(xx=-5, yy=-2, zz=10, xy=1) >>> S.cauchy(Fol(160, 30)) V(-2.520, 0.812, 8.660) """ return Vec3(np.dot(self, n))
def axisangle(self): """Return rotation part of ``DefGrad`` axis, angle tuple.""" from scipy.linalg import polar R, _ = polar(self) w, W = np.linalg.eig(R.T) i = np.where(abs(np.real(w) - 1.0) < 1e-8)[0] if not len(i): raise ValueError("no unit eigenvector corresponding to eigenvalue 1") axis = Vec3(np.real(W[:, i[-1]]).squeeze()) # rotation angle depending on direction cosa = (np.trace(R) - 1.0) / 2.0 if abs(axis[2]) > 1e-8: sina = (R[1, 0] + (cosa - 1.0) * axis[0] * axis[1]) / axis[2] elif abs(axis[1]) > 1e-8: sina = (R[0, 2] + (cosa - 1.0) * axis[0] * axis[2]) / axis[1] else: sina = (R[2, 1] + (cosa - 1.0) * axis[1] * axis[2]) / axis[0] angle = np.rad2deg(np.arctan2(sina, cosa)) return axis, angle
def from_pmd(cls, filename): """Return ``Core`` instance generated from PMD file. Args: filename: PMD file Example: >>> d = Core.from_pmd('K509A2-1.PMD') """ with open(filename, encoding="latin1") as f: d = f.read().splitlines() data = {} fields = { "Xc": slice(5, 14), "Yc": slice(15, 24), "Zc": slice(25, 34), "a95": slice(69, 73), } data["info"] = d[0].strip() vline = d[1].strip() data["filename"] = filename data["name"] = vline[:10].strip() data["alpha"] = float(vline[10:20].strip().split("=")[1]) data["beta"] = float(vline[20:30].strip().split("=")[1]) data["strike"] = float(vline[30:40].strip().split("=")[1]) data["dip"] = float(vline[40:50].strip().split("=")[1]) data["volume"] = float(vline[50:63].strip().split("=")[1].strip("m3")) data["date"] = datetime.strptime(vline[63:].strip(), "%m-%d-%Y %H:%M") data["steps"] = [ln[:4].strip() for ln in d[3:-1]] data["comments"] = [ln[73:].strip() for ln in d[3:-1]] data["a95"] = [float(ln[fields["a95"]].strip()) for ln in d[3:-1]] data["vectors"] = [] for ln in d[3:-1]: x = float(ln[fields["Xc"]].strip()) y = float(ln[fields["Yc"]].strip()) z = float(ln[fields["Zc"]].strip()) data["vectors"].append(Vec3((x, y, z))) return cls(**data)
def format_coord(self, x, y): if np.hypot(x, y) > 1: return "" else: v = Vec3(*getldd(x, y)) return repr(v.asfol) + " " + repr(v.aslin)
def from_rs3(cls, filename): """Return ``Core`` instance generated from PMD file. Args: filename: Remasoft rs3 file """ with open(filename, encoding="latin1") as f: d = f.read().splitlines() import io headspec = [ [0, 9], [10, 19], [20, 29], [30, 40], [41, 50], [51, 65], [66, 70], [71, 73], [74, 79], [80, 85], [86, 91], [92, 97], [98, 103], [104, 109], [110, 112], [113, 115], [116, 118], [119, 121], [122, 126], ] bodyspec = [ [0, 2], [3, 13], [14, 27], [28, 33], [34, 39], [40, 45], [46, 51], [52, 57], [58, 63], [64, 69], [70, 75], [76, 81], [82, 95], [96, 105], [106, 115], [116, 126], ] head = pd.read_fwf(io.StringIO('\n'.join(d[:2])), colspecs=headspec) body = pd.read_fwf(io.StringIO('\n'.join(d[2:])), colspecs=bodyspec) data = {} vline = d[1] data["site"] = head['Site'][0] if not pd.isna(head['Site'][0]) else '' data["filename"] = filename data["name"] = head['Name'][0] if not pd.isna(head['Name'][0]) else '' data["longitude"] = (float(head['Longitude'][0]) if not pd.isna(head['Longitude'][0]) else None) data["latitude"] = (float(head['Latitude'][0]) if not pd.isna(head['Latitude'][0]) else None) data["height"] = (float(head['Height'][0]) if not pd.isna(head['Height'][0]) else None) data["rock"] = head['Rock'][0] if not pd.isna(head['Rock'][0]) else '' data["age"] = head['Age'][0] if not pd.isna(head['Age'][0]) else '' data["formation"] = head['Fm'][0] if not pd.isna(head['Fm'][0]) else '' data["sref"] = Pair(180, 0, 180, 0) data["gref"] = Pair( float(head['SDec'][0]), float(head['SInc'][0]), float(head['SDec'][0]), float(head['SInc'][0]), ) data["bedding"] = (Fol(float(head['BDec'][0]), float(head['BInc'][0])) if not pd.isna(head['BDec'][0]) and not pd.isna(head['BInc'][0]) else None) data["foldaxis"] = (Lin(float(head['FDec'][0]), float(head['FInc'][0])) if not pd.isna(head['FDec'][0]) and not pd.isna(head['FInc'][0]) else None) data["date"] = datetime.now() #ix = (body.iloc[:, 0] == 'T') | (body.iloc[:, 0] == 'N') ix = body.iloc[:, 0] != 'C' data["steps"] = body[ix].iloc[:, 1].to_list() data["comments"] = body[ix]['Note'].to_list() data["a95"] = body[ix]['Prec'].to_list() data["vectors"] = [] for n, r in body[ix].iterrows(): data["vectors"].append(r['M[A/m]'] * Vec3(r['Dsp'], r['Isp'])) return cls(**data)