Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotations fixed #111

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a8bf78a
set rotation matrix to be formulated as counterclockwise positive
kujaku11 May 4, 2020
054eec1
set rotation matrix to be formulated as counterclockwise positive
kujaku11 May 4, 2020
e4d7265
fixing plotting phase tensor ellipses in correct coordinate system
kujaku11 May 4, 2020
abbf1e0
set rotation angle to be opposite of input in pt.rotate to be consist…
kujaku11 May 4, 2020
d32d084
set rotation angle to be opposite of input in pt.rotate to be consist…
kujaku11 May 4, 2020
6f3bcff
making rotation matrix postitive clockwise and fixing plotting schemes
kujaku11 May 11, 2020
5dd664f
fixed plot_pt, plot_pt_pseudosection
kujaku11 May 11, 2020
4ee148c
fixed plot_pt, plot_pt_maps
kujaku11 May 11, 2020
e303ec3
fixed plot_pt, plot_pt_maps
kujaku11 May 12, 2020
73429f2
added documentation to utils.calculator
kujaku11 May 12, 2020
dbed2d0
fixed plotnresponses
kujaku11 May 12, 2020
0287d70
fixed z_err.setter issue, set z_err as a property
kujaku11 May 21, 2020
17238b7
refactored plot_pt_maps
kujaku11 May 26, 2020
b7388cb
added to plot_strike_rose_plot
kujaku11 May 26, 2020
ec89752
set plot_orthogonal = False as default in plot_strike
kujaku11 May 26, 2020
46b3adb
added to plot_strike_rose_plot
kujaku11 May 26, 2020
6c26507
Merge branch 'develop' into rotation_test
alkirkby May 26, 2020
1ba3aab
fixed error in plot_tensor_pseudosection line 404, needed to be for k…
kujaku11 May 28, 2020
a66237d
Merge branch 'rotation_test' of https://github.com/MTgeophysics/mtpy …
kujaku11 May 28, 2020
e76b74d
fixed error in plot_tensor_pseudosection line 404, needed to be for k…
kujaku11 May 28, 2020
d563ff4
merged with develop
kujaku11 Jun 1, 2020
22be963
changed test_z.test_rotate to positive clockwise rotation matrix
kujaku11 Jun 1, 2020
0a55535
fixed test_geometry.test_eccentricity, had the wrong values for control
kujaku11 Jun 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
223 changes: 48 additions & 175 deletions mtpy/analysis/pt.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ def __init__(self, pt_array=None, pt_err_array=None, z_array=None,
# define get/set functions and properties
# ==========================================================================
# ---phase tensor array----------------------------------------
def _set_pt(self, pt_array):
@property
def pt(self):
return self._pt

@pt.setter
def pt(self, pt_array):
"""
Set the attribute 'pt'.

Expand Down Expand Up @@ -176,13 +181,13 @@ def _set_pt(self, pt_array):
else:
pass

def _get_pt(self):
# ---phase tensor Error-----------------------------------------------------
@property
def pt_err(self):
return self._pt

pt = property(_get_pt, _set_pt, doc="Phase tensor array")

# ---phase tensor Error-----------------------------------------------------
def _set_pt_err(self, pt_err_array):
@pt_err.setter
def pt_err(self, pt_err_array):
"""
Set the attribute 'pt_err'.

Expand Down Expand Up @@ -224,14 +229,13 @@ def _set_pt_err(self, pt_err_array):
else:
pass

def _get_pt_err(self):
return self._pt_err

pt_err = property(_get_pt_err, _set_pt_err,
doc='Phase tensor error array, must be same shape as pt')

# ---freq------------------------------------------------------------
def _set_freq(self, lo_freq):
@property
def freq(self):
return self._freq

@freq.setter
def freq(self, lo_freq):
"""
Set array of freq.

Expand All @@ -253,11 +257,6 @@ def _set_freq(self, lo_freq):
except:
self._freq = None

def _get_freq(self):
return self._freq

freq = property(_get_freq, _set_freq, doc="freq array")

# ---z_object---------------------------------------------------------------

def set_z_object(self, z_object):
Expand All @@ -278,43 +277,27 @@ def set_z_object(self, z_object):
self._pt[idx_f], self._pt_err[idx_f] = z2pt(self._z[idx_f],
self._z_err[idx_f])
except MTex.MTpyError_PT:
try:
print('Singular Matrix at {0:.5g} Hz'.format(
self._freq[idx_f]))
except AttributeError:
print('Computed singular matrix')
print(' --> pt[{0}]=np.zeros((2,2))'.format(idx_f))
pass

# --> if there is not error to the impedance tensor
else:
for idx_f in range(len(self._z)):
try:
self._pt[idx_f] = z2pt(self._z[idx_f])[0]
except MTex.MTpyError_PT:
try:
print('Singular Matrix at {0:.5g}'.format(
self._freq[idx_f]))
except AttributeError:
print('Computed singular matrix')
print(' --> pt[{0}]=np.zeros((2,2))'.format(idx_f))
pass

self.rotation_angle = z_object.rotation_angle

# def _get_z_object(self):
# z_object = MTz.Z(z_array=self._z, z_err_array=self._z_err)
# z_object.freq = self._freq
# z_object.rotation_angle = self.rotation_angle

# return z_object

# _z_object = property(_get_z_object, _set_z_object,
# doc="class mtpy.core.z.Z")


# ---z array---------------------------------------------------------------
def _set_z(self, z_array):
@property
def z(self):
return self._z

@z.setter
def z(self, z_array):
"""
Set Z array as PhaseTensor object attribute.
Set Z array as PhaseTensor object attribute.
"""

self._z = z_array
Expand All @@ -327,33 +310,22 @@ def _set_z(self, z_array):
self._pt[idx_f], self._pt_err[idx_f] = z2pt(self._z[idx_f],
self._z_err[idx_f])
except MTex.MTpyError_PT:
try:
print('Singular Matrix at {0:.5g} Hz'.format(
self._freq[idx_f]))
except AttributeError:
print('Computed singular matrix')
print(' --> pt[{0}]=np.zeros((2,2))'.format(idx_f))
pass

# --> if there is not error to the impedance tensor
elif self._z is not None:
for idx_f in range(len(self._z)):
try:
self._pt[idx_f] = z2pt(self._z[idx_f])[0]
except MTex.MTpyError_PT:
try:
print('Singular Matrix at {0:.5g}'.format(
self._freq[idx_f]))
except AttributeError:
print('Computed singular matrix')
print(' --> pt[{0}]=np.zeros((2,2))'.format(idx_f))

# def _get_z(self):
# return self._z
pass

# z = property(_get_z, _set_z,
# doc="impedance tensor numpy.array((nf, 2, 2))")

# ---Z Error array---------------------------------------------------------------
def z_err(self):
return self._z_err

@z_err.setter
def _set_z_err(self, z_err_array):
"""
Set Z-error array as PhaseTensor object attribute.
Expand All @@ -373,33 +345,15 @@ def _set_z_err(self, z_err_array):
self.pt[idx_f], self.pt_err[idx_f] = z2pt(self._z[idx_f],
self._z_err[idx_f])
except MTex.MTpyError_PT:
try:
print('Singular Matrix at {0:.5g} Hz'.format(
self._freq[idx_f]))
except AttributeError:
print('Computed singular matrix')
print(' --> pt[{0}]=np.zeros((2,2))'.format(idx_f))
pass

# --> if there is not error to the impedance tensor
else:
for idx_f in range(len(self.z)):
try:
self._pt[idx_f] = z2pt(self._z[idx_f])[0]
except MTex.MTpyError_PT:
try:
print('Singular Matrix at {0:.5g}'.format(
self._freq[idx_f]))
except AttributeError:
print('Computed singular matrix')
print(' --> pt[{0}]=np.zeros((2,2))'.format(idx_f))

# def _get_z_err(self):
# return self._z_err

# z_err = property(_get_z_err, _set_z_err,
# doc="impedance tensor numpy.array((nf, 2, 2))")


pass

# ==========================================================================
# define get methods for read only properties
Expand Down Expand Up @@ -571,7 +525,7 @@ def azimuth(self):
@property
def azimuth_err(self):
if self.pt_err is not None:
az_err = np.sqrt(self.alpha+self.beta)
az_err = np.sqrt(self.alpha + self.beta)
else:
az_err = None

Expand Down Expand Up @@ -741,29 +695,26 @@ def phimax(self):
if self.pt is None:
return None

# return self._pi2()[0] + self._pi1()[0]
return np.degrees(np.arctan(self._pi2()[0] + self._pi1()[0]))

@property
def phimax_err(self):
phimaxerr = None
if self.pt_err is not None:
phimaxerr = np.sqrt(self._pi2()[1]**2+self._pi1()[1]**2)
phimaxerr = np.sqrt(self._pi2()[1]**2 + self._pi1()[1]**2)

return np.degrees(np.arctan(phimaxerr))
else:
return None

def rotate(self, alpha):
"""
Rotate PT array. Change the rotation angles attribute respectively.

Rotation angle must be given in degrees. All angles are referenced to
geographic North, positive in clockwise direction.
(Mathematically negative!)
Rotate PT array. Change the rotation angles attribute respectively.

In non-rotated state, X refs to North and Y to East direction.
Rotation angle must be given in degrees. All angles are referenced to
North, positive in clockwise direction. (Mathematically negative!)

In non-rotated state, X refs to North and Y to East direction.

"""

Expand Down Expand Up @@ -820,9 +771,14 @@ def rotate(self, alpha):
angle = 0.

if self.pt_err is not None:
pt_rot[idx_freq], pt_err_rot[idx_freq] = MTcc.rotatematrix_incl_errors(self.pt[idx_freq,:,:], angle, self.pt_err[idx_freq,:,:])
pt_rot[idx_freq], pt_err_rot[idx_freq] = \
MTcc.rotate_matrix_with_errors(self.pt[idx_freq,:,:],
-angle,
self.pt_err[idx_freq,:,:])
else:
pt_rot[idx_freq], pt_err_rot = MTcc.rotatematrix_incl_errors(self.pt[idx_freq,:,:], angle)
pt_rot[idx_freq], pt_err_rot = \
MTcc.rotate_matrix_with_errors(self.pt[idx_freq,:,:],
-angle)

# --> set the rotated tensors as the current attributes
self._pt = pt_rot
Expand Down Expand Up @@ -1307,87 +1263,4 @@ def z2pt(z_array, z_err_array=None):
np.abs( -pt_array[idx_f,1,1] * realz[0,0] * z_err_array[1,1]) + \
np.abs( realz[0,0] * z_err_array[1,1]) + np.abs( -realz[1,0] * z_err_array[0,1]) )

return pt_array, pt_err_array


def z_object2pt(z_object):
"""
Calculate Phase Tensor from Z object (incl. uncertainties)

Input:
- Z-object : instance of the MTpy Z class


Return:
- PT object
"""
# - PT : nx2x2 real valued Numpy array
# - PT-error : nx2x2 real valued Numpy array

# """

try:
p = PhaseTensor(z_object=z_object)
except:
raise MTex.MTpyError_Z('Input argument is not a valid instance of the Z class')

# pt_array = p.pt
# pterr_array = p.pterr

# return pt_array, pterr_array
return p


def _edi_object2pt(edi_object):
"""
Calculate Phase Tensor from Edi object (incl. uncertainties)

Input:
- Edi-object : instance of the MTpy Edi class

Return:
- PT : nx2x2 real valued Numpy array
- PT-error : nx2x2 real valued Numpy array

"""

if not isinstance(edi_object, MTedi.Edi):
raise MTex.MTpyError_EDI('Input argument is not an instance of the Edi class')
p = PhaseTensor(edi_object=edi_object)

pt_array = p.pt

pterr_array = p.pterr

return pt_array, pterr_array


def edi_file2pt(filename):
"""
Calculate Phase Tensor from Edi-file (incl. uncertainties)

Input:
- Edi-file : full path to the Edi-file

Return:
- PT object

"""
# Return:
# - PT : nx2x2 real valued Numpy array
# - PT-error : nx2x2 real valued Numpy array

# """

e = MTedi.Edi()
e.readfile(filename)

p = PhaseTensor(z_object=e.Z)

# pt_array = p.pt

# pterr_array = p.pterr

# return pt_array, pterr_array

return p
return pt_array, pt_err_array
5 changes: 2 additions & 3 deletions mtpy/analysis/zinvariants.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def compute_invariants(self):
**q** : dependent variable suggesting dimensionality

"""
print("computing invariants")
# get the length of z to initialize some empty arrays
nz = self.z.shape[0]

Expand Down Expand Up @@ -184,8 +183,8 @@ def compute_invariants(self):
ex = x1 * e1 - x2 * e2 - x3 * e3 + x4 * e4

if ex == 0.0:
print('Could not compute invariants for {0:5e} Hz'.format(
self.freq[ii]))
# print('Could not compute invariants for {0:5e} Hz'.format(
# self.freq[ii]))
self.inv1[ii] = np.nan
self.inv2[ii] = np.nan
self.inv3[ii] = np.nan
Expand Down
2 changes: 1 addition & 1 deletion mtpy/core/mt.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def rotation_angle(self, theta_r):
self._Tipper.rotate(theta_r)
self.pt.rotate(theta_r)

print(("Rotated Z, Tipper, Phase Tensor and Zinvariants by"
print(("Rotated Z, Tipper, Phase Tensor and Zinvariants by "
"{0:.3f} degrees".format(self._rotation_angle)))

@Z.setter
Expand Down
Loading