%load_ext autoreload
%autoreload 1

"""
Explanation: Geological data
March-April, 2018, Mauro Alberti
Last version: 2021-04-24
Last running version: 2021-04-24
Developement code:
End of explanation
"""


from pygsf.geology.faults import *

"""
Explanation: 1. Fault data vs. focal mechanisms
Structural investigations of brittle regimes rock volumes deal with fault data derived from field measurements of meso-fault surfaces. Seismic events, generated by active faults, are generally represented as focal mechanisms.
Due to their common physical origin, meso-fault data and focal mechanisms share common aspects, even if it is useful to treat them as two distinct type structures, also from an algorithmic point of view.
In gsfpy fault data types are stored in the faults submodule:
End of explanation
"""


%matplotlib inline

"""
Explanation: We use also matplotlib inline and mplstereonet for plotting stereonet:
End of explanation
"""


slick_k = Slick(140, 15)  # slickenline with known, downward movement direction

slick_k

"""
Explanation: 2. Fault data
Fault geometry characteristics can be defined using the concept of a geological plane, approximating the local fault surface, and of a slickenline, basically a vector that is parallel to the movement orientation. A slickenline parameters are its orientation and, when recognised, a movement direction.  
In the algorithms, slickenlines are represented by the Slick class, that stores the slickenline orientation and movement direction. A meso-fault datum is represented by the Fault class, that is composed of a Plane instance (i.e., the geological plane), and a Slick instance.
2.1 Slickenlines
A slickenline is created via a Slick instance. The input parameters are: trend, plunge and whether movement direction is known or not.
End of explanation
"""


slick_k.hasKnownSense

"""
Explanation: In the above example, the slickenline movement direction is towards N140°, with a positive dip angle value of 15°, i.e., pointing downward. In the print output, True indicates that the movement sense is known.
End of explanation
"""


slick_u = Slick(210, 60, known=False)  # slickenkline with unknown movement sense

slick_u

slick_u.hasKnownSense

"""
Explanation: We can create a slickenline object with unknown movement sense by explicitely setting the known flag to False (default value is True), as in the following example:
End of explanation
"""


flt = Fault(90, 45, slickenlines=[Slick(90, 45, known=False)])

"""
Explanation: It is possible to convert an unknown movement to a known movement or viceversa, and, when the movement is known, to invert it, with the setKnownSense() and setUnknownSense() methods.
2.2 Fault planes with slickenlines
Having described slickenlines, we can now consider how to represent fault planes presenting slickenlines.
An example is:
End of explanation
"""


type(flt)  # we check the type

"""
Explanation: A fault instance is created by using the Fault class, initialized with two parameters:
- the geological plane: a Plane instance
- the slickenlines: zero, one or more Slick instances
Note that there is no required 1 : 1 relationship between a fault plane and a slickenline. A fault plane can contain no slickeline at all, or even more than a single slickenline, for instance because the movements on it were curvilinear or because the history of movements is polyphasic.
End of explanation
"""


flt.knownSense

"""
Explanation: We check if this fault instance has a known movement sense:
End of explanation
"""


from pygsf.geology.ptbaxes import *

"""
Explanation: Since the slickenline orientation was defined via a Axis instance, the movement sense is not known.
3. Focal mechanisms and P-T-B axes
Classes for P-T-B axes are defined in the ptbaxes submodule:
End of explanation
"""


ptbx_from_axes = PTBAxes(p_axis=Axis(0, 0), t_axis=Axis(90, 0))

print(ptbx_from_axes)

"""
Explanation: P-T axes instances can be created using the PTBAxes class.
We can initialize an instance in four ways: 
- by providing a couple of Axis, representing the T and P axes
- by giving a Fault** instance as input parameter
- defining a couple of Cartesian vectors, representing the P and T axes
- by providing a quaternion.
Creation of a P-T axes instance from a couple of Axis:
End of explanation
"""


ptbx_from_fltsl = PTBAxes.fromFaultSlick(Fault(90, 45, slickenlines=[Slick(90, 45)]))

print(ptbx_from_fltsl)

"""
Explanation: Creation of a P-T axes instance from a FaultSlick instance:
End of explanation
"""


ptbx_from_vects = PTBAxes.fromVects(t_vector=Vect3D(1,0,0), p_vector=Vect3D(0,1,0))

print(ptbx_from_vects)

"""
Explanation: An example of creating a P-T axes instance from a couple of Vect instances is:
End of explanation
"""


ptbx_from_vects.almostEqual(ptbx_from_axes)

ptbx_from_vects.almostEqual(ptbx_from_fltsl)

"""
Explanation: It is possible to compare two PTBAxes instances for being almost equal:
End of explanation
"""


quat = ptbx_from_vects.toQuatern()

print(quat)

"""
Explanation: A PTBAxes instance can be converted to a matrix or to a quaternion, for being further processed (e.g., rotated)
End of explanation
"""


