apsg 2.0.4__tar.gz → 2.0.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. {apsg-2.0.4/src/apsg.egg-info → apsg-2.0.6}/PKG-INFO +1 -1
  2. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/__init__.py +1 -1
  3. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/feature/_container.py +3 -3
  4. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/feature/_geodata.py +2 -1
  5. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/feature/_tensor3.py +15 -8
  6. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/helpers/_notation.py +16 -8
  7. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/math/_vector.py +5 -3
  8. {apsg-2.0.4 → apsg-2.0.6/src/apsg.egg-info}/PKG-INFO +1 -1
  9. {apsg-2.0.4 → apsg-2.0.6}/tests/test_apsg.py +23 -0
  10. {apsg-2.0.4 → apsg-2.0.6}/tests/test_containers.py +2 -2
  11. {apsg-2.0.4 → apsg-2.0.6}/tests/test_tensors.py +14 -2
  12. {apsg-2.0.4 → apsg-2.0.6}/LICENSE +0 -0
  13. {apsg-2.0.4 → apsg-2.0.6}/README.md +0 -0
  14. {apsg-2.0.4 → apsg-2.0.6}/pyproject.toml +0 -0
  15. {apsg-2.0.4 → apsg-2.0.6}/setup.cfg +0 -0
  16. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/config.py +0 -0
  17. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/database/__init__.py +0 -0
  18. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/database/_sdbmodels.py +0 -0
  19. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/database/_sdbsession.py +0 -0
  20. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/database/_websdbsession.py +0 -0
  21. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/database/_webtransport.py +0 -0
  22. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/feature/__init__.py +0 -0
  23. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/feature/_paleomag.py +0 -0
  24. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/feature/_statistics.py +0 -0
  25. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/feature/_tensor2.py +0 -0
  26. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/helpers/__init__.py +0 -0
  27. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/helpers/_helper.py +0 -0
  28. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/helpers/_math.py +0 -0
  29. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/math/__init__.py +0 -0
  30. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/math/_matrix.py +0 -0
  31. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/pandas/__init__.py +0 -0
  32. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/pandas/_accessors.py +0 -0
  33. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/pandas/_gbfunctions.py +0 -0
  34. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/pandas/_pandas_api.py +0 -0
  35. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/plotting/__init__.py +0 -0
  36. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/plotting/_fabricplot.py +0 -0
  37. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/plotting/_paleomagplots.py +0 -0
  38. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/plotting/_plot_artists.py +0 -0
  39. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/plotting/_roseplot.py +0 -0
  40. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/plotting/_stereo_engine/__init__.py +0 -0
  41. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/plotting/_stereo_engine/_axes.py +0 -0
  42. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/plotting/_stereo_engine/_stereogrid.py +0 -0
  43. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/plotting/_stereo_engine/_transforms.py +0 -0
  44. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/plotting/_stereo_engine/_utils.py +0 -0
  45. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/plotting/_stereogrid.py +0 -0
  46. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/plotting/_stereonet.py +0 -0
  47. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/plotting/_styles.py +0 -0
  48. {apsg-2.0.4 → apsg-2.0.6}/src/apsg/shell.py +0 -0
  49. {apsg-2.0.4 → apsg-2.0.6}/src/apsg.egg-info/SOURCES.txt +0 -0
  50. {apsg-2.0.4 → apsg-2.0.6}/src/apsg.egg-info/dependency_links.txt +0 -0
  51. {apsg-2.0.4 → apsg-2.0.6}/src/apsg.egg-info/entry_points.txt +0 -0
  52. {apsg-2.0.4 → apsg-2.0.6}/src/apsg.egg-info/requires.txt +0 -0
  53. {apsg-2.0.4 → apsg-2.0.6}/src/apsg.egg-info/top_level.txt +0 -0
  54. {apsg-2.0.4 → apsg-2.0.6}/tests/test_pandas.py +0 -0
  55. {apsg-2.0.4 → apsg-2.0.6}/tests/test_plotting.py +0 -0
  56. {apsg-2.0.4 → apsg-2.0.6}/tests/test_websdb.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: apsg
3
- Version: 2.0.4
3
+ Version: 2.0.6
4
4
  Summary: APSG - The package for structural geologists
5
5
  Author-email: Ondrej Lexa <lexa.ondrej@gmail.com>
6
6
  Maintainer-email: Ondrej Lexa <lexa.ondrej@gmail.com>
@@ -195,6 +195,6 @@ __all__ = (
195
195
  "velgrad2",
196
196
  )
197
197
 
198
- __version__ = "2.0.4"
198
+ __version__ = "2.0.6"
199
199
  __author__ = "Ondrej Lexa"
200
200
  __email__ = "lexa.ondrej@gmail.com"
@@ -2731,10 +2731,10 @@ class Stress3Set(FeatureSet):
2731
2731
  return np.array([e.I3 for e in self])
2732
2732
 
2733
2733
  @property
2734
- def shape_ratio(self) -> np.ndarray:
2735
- """Return the array of shape ratios (Gephart & Forsyth, 1984)."""
2734
+ def stress_ratio(self) -> np.ndarray:
2735
+ """Return the array of stress ratios R = (σ2 - σ3) / (σ1 - σ3)."""
2736
2736
 
2737
- return np.array([e.shape_ratio for e in self])
2737
+ return np.array([e.stress_ratio for e in self])
2738
2738
 
2739
2739
  def mean_tensor(self, level=0.95, normalize=False, anisoft=False):
2740
2740
  """Return mean tensor and confidence ellipses of its principal axes.
@@ -5,6 +5,7 @@ import numpy as np
5
5
  from apsg.helpers._helper import is_jsonable
6
6
  from apsg.helpers._math import atan2d
7
7
  from apsg.helpers._notation import (
8
+ _fmt_deg,
8
9
  fol2vec_rhr,
9
10
  format_linear,
10
11
  format_planar,
@@ -45,7 +46,7 @@ class Direction(Axial2):
45
46
  """
46
47
 
47
48
  def __repr__(self):
48
- return f"D:{self.direction:.0f}"
49
+ return f"D:{_fmt_deg(self.direction, azimuth=True)}"
49
50
 
50
51
 
51
52
  class Lineation(Axial3):
@@ -840,10 +840,11 @@ class Stress3(Tensor3):
840
840
  @classmethod
841
841
  def from_ratio(cls, r=0.5, mag=1):
842
842
  """
843
- Return ``Stress`` tensor with given shape ration.
843
+ Return ``Stress`` tensor with given stress ratio.
844
844
 
845
845
  Keyword Args:
846
- r (float): shape ratio between 0 and 1. Default 0.5
846
+ r (float): stress ratio R = (σ2 - σ3) / (σ1 - σ3) between 0 and 1.
847
+ Default 0.5
847
848
  mag (float): magnitude of differential stress. Default 1.
848
849
 
849
850
  Examples:
@@ -851,15 +852,16 @@ class Stress3(Tensor3):
851
852
  >>> S
852
853
  Stress3
853
854
  [[ 5. 0. 0. ]
854
- [ 0. 2.5 0. ]
855
+ [ 0. -2.5 0. ]
855
856
  [ 0. 0. -5. ]]
856
857
 
857
858
  Returns:
858
- Stress3: ``Stress`` tensor with given shape ration.
859
+ Stress3: ``Stress`` tensor with given stress ratio.
859
860
  """
860
861
 
861
862
  xx = mag / 2
862
- yy = xx - r * mag
863
+ # sigma2 placed so that (σ2 - σ3) / (σ1 - σ3) == r in either convention
864
+ yy = stress_sign() * (xx - r * mag)
863
865
  zz = -mag / 2
864
866
  return cls([[xx, 0, 0], [0, yy, 0], [0, 0, zz]])
865
867
 
@@ -1092,9 +1094,14 @@ class Stress3(Tensor3):
1092
1094
  return np.where(np.isclose(denom, 0), np.nan, (Se.sigma1 - sn) / denom)
1093
1095
 
1094
1096
  @property
1095
- def shape_ratio(self):
1096
- """Return shape ratio R (Gephart & Forsyth 1984)."""
1097
- return float((self.sigma1 - self.sigma2) / (self.sigma1 - self.sigma3))
1097
+ def stress_ratio(self):
1098
+ """Return stress ratio R = (σ2 - σ3) / (σ1 - σ3).
1099
+
1100
+ Structural geology definition: R = 0 for σ2 = σ3 (prolate) and
1101
+ R = 1 for σ2 = σ1 (oblate). Note that the seismological definition
1102
+ (σ1 - σ2) / (σ1 - σ3) equals 1 - R.
1103
+ """
1104
+ return float((self.sigma2 - self.sigma3) / (self.sigma1 - self.sigma3))
1098
1105
 
1099
1106
 
1100
1107
  class Ellipsoid(Tensor3):
@@ -171,16 +171,24 @@ _LINEAR_QUADRANT_RE = re.compile(
171
171
  )
172
172
 
173
173
 
174
+ def _fmt_deg(value, azimuth=False):
175
+ """Format angle rounded to whole degrees, without '-0' (and '360' for azimuths)."""
176
+ v = round(value) # int, so no negative zero; same round-half-even as :.0f
177
+ if azimuth:
178
+ v %= 360
179
+ return str(v)
180
+
181
+
174
182
  def azi2bearing(azi):
175
183
  """Format azimuth (0-360 degrees) as quadrant bearing string, e.g. 45 -> 'N45E'."""
176
184
  azi = azi % 360
177
185
  if azi <= 90:
178
- return f"N{azi:.0f}E"
186
+ return f"N{_fmt_deg(azi)}E"
179
187
  if azi <= 180:
180
- return f"S{180 - azi:.0f}E"
188
+ return f"S{_fmt_deg(180 - azi)}E"
181
189
  if azi <= 270:
182
- return f"S{azi - 180:.0f}W"
183
- return f"N{360 - azi:.0f}W"
190
+ return f"S{_fmt_deg(azi - 180)}W"
191
+ return f"N{_fmt_deg(360 - azi)}W"
184
192
 
185
193
 
186
194
  def bearing2azi(s):
@@ -228,7 +236,7 @@ def format_quadrant_planar(strike, dip):
228
236
  """
229
237
  dip_azi = (strike + 90) % 360
230
238
  display_strike = strike if (strike <= 90 or strike > 270) else strike - 180
231
- return f"{azi2bearing(display_strike)},{dip:.0f}{_dip_qualifier(dip_azi)}"
239
+ return f"{azi2bearing(display_strike)},{_fmt_deg(dip)}{_dip_qualifier(dip_azi)}"
232
240
 
233
241
 
234
242
  def parse_quadrant_linear(s):
@@ -242,18 +250,18 @@ def parse_quadrant_linear(s):
242
250
 
243
251
  def format_quadrant_linear(azi, inc):
244
252
  """Format (trend, plunge) as quadrant linear measurement string."""
245
- return f"{azi2bearing(azi)},{inc:.0f}"
253
+ return f"{azi2bearing(azi)},{_fmt_deg(inc)}"
246
254
 
247
255
 
248
256
  def format_planar(azi, inc):
249
257
  """Format a planar geo-tuple according to the active `apsg_conf.notation`."""
250
258
  if apsg_conf.notation == "quadrant":
251
259
  return format_quadrant_planar(azi, inc)
252
- return f"{azi:.0f}/{inc:.0f}"
260
+ return f"{_fmt_deg(azi, azimuth=True)}/{_fmt_deg(inc)}"
253
261
 
254
262
 
255
263
  def format_linear(azi, inc):
256
264
  """Format a linear geo-tuple according to the active `apsg_conf.notation`."""
257
265
  if apsg_conf.notation == "quadrant":
258
266
  return format_quadrant_linear(azi, inc)
259
- return f"{azi:.0f}/{inc:.0f}"
267
+ return f"{_fmt_deg(azi, azimuth=True)}/{_fmt_deg(inc)}"
@@ -7,6 +7,7 @@ from apsg.config import apsg_conf
7
7
  from apsg.helpers._helper import is_jsonable
8
8
  from apsg.helpers._math import acosd, atan2d, cosd, sind
9
9
  from apsg.helpers._notation import (
10
+ _fmt_deg,
10
11
  geo2vec_linear,
11
12
  vec2geo_linear_signed,
12
13
  )
@@ -213,7 +214,7 @@ class Vector2(Vector):
213
214
 
214
215
  def __repr__(self):
215
216
  n = apsg_conf.ndigits
216
- return f"Vector2({round(self.x, n):g}, {round(self.y, n):g})"
217
+ return f"Vector2({round(self.x, n) + 0.0:g}, {round(self.y, n) + 0.0:g})"
217
218
 
218
219
  def __len__(self):
219
220
  return 2
@@ -427,10 +428,11 @@ class Vector3(Vector):
427
428
  def __repr__(self):
428
429
  if apsg_conf.vec2geo:
429
430
  azi, inc = self.geo
430
- return f"V:{azi:.0f}/{inc:.0f}"
431
+ return f"V:{_fmt_deg(azi, azimuth=True)}/{_fmt_deg(inc)}"
431
432
  else:
432
433
  n = apsg_conf.ndigits
433
- return f"Vector3({round(self.x, n):g}, {round(self.y, n):g}, {round(self.z, n):g})"
434
+ x, y, z = (round(c, n) + 0.0 for c in (self.x, self.y, self.z))
435
+ return f"Vector3({x:g}, {y:g}, {z:g})"
434
436
 
435
437
  def __len__(self):
436
438
  return 3
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: apsg
3
- Version: 2.0.4
3
+ Version: 2.0.6
4
4
  Summary: APSG - The package for structural geologists
5
5
  Author-email: Ondrej Lexa <lexa.ondrej@gmail.com>
6
6
  Maintainer-email: Ondrej Lexa <lexa.ondrej@gmail.com>
@@ -1274,3 +1274,26 @@ class TestJSONRoundtrip:
1274
1274
  j = a.to_json()
1275
1275
  a2 = feature_from_json(j)
1276
1276
  assert a == a2
1277
+
1278
+
1279
+ # Repr formatting: no "-0" and no "360"
1280
+
1281
+
1282
+ def test_repr_no_negative_zero():
1283
+ assert repr(-lin(219, 0)) == "L:39/0"
1284
+ assert repr(lin(Vector3(1, 1, -0.0))) == "L:45/0"
1285
+ assert repr(Vector3(1, 0, -0.0)) == "Vector3(1, 0, 0)"
1286
+ assert repr(Vector2(-0.0, 1)) == "Vector2(0, 1)"
1287
+
1288
+
1289
+ def test_repr_azimuth_wraps_to_zero():
1290
+ assert repr(lin(359.8, 10)) == "L:0/10"
1291
+ assert repr(fol(359.7, 30)) == "S:0/30"
1292
+ assert repr(dir2(359.7)) == "D:0"
1293
+ with apsg_conf_context(notation="rhr"):
1294
+ assert repr(fol(359.7, 30)) == "S:0/30"
1295
+
1296
+
1297
+ def test_repr_quadrant_no_negative_zero():
1298
+ with apsg_conf_context(notation="quadrant"):
1299
+ assert repr(-lin(219, 0)) == "L:N39E,0"
@@ -1510,14 +1510,14 @@ class TestStress3Set:
1510
1510
  assert isinstance(s.I3, np.ndarray)
1511
1511
  assert len(s.I1) == len(s.I2) == len(s.I3) == 2
1512
1512
 
1513
- def test_shape_ratio_property(self):
1513
+ def test_stress_ratio_property(self):
1514
1514
  s = Stress3Set(
1515
1515
  [
1516
1516
  Stress3([[10, 2, -3], [2, 5, 1], [-3, 1, -2]]),
1517
1517
  Stress3([[8, 0, 0], [0, 5, 0], [0, 0, 1]]),
1518
1518
  ]
1519
1519
  )
1520
- r = s.shape_ratio
1520
+ r = s.stress_ratio
1521
1521
  assert isinstance(r, np.ndarray)
1522
1522
  assert len(r) == 2
1523
1523
 
@@ -1139,9 +1139,21 @@ class TestStress3:
1139
1139
  t = S.dilation_tendency(Foliation(160, 30))
1140
1140
  assert 0 <= t <= 1
1141
1141
 
1142
- def test_shape_ratio(self):
1142
+ def test_stress_ratio(self):
1143
1143
  S = Stress3.from_ratio(r=0.5, mag=1)
1144
- assert 0 <= S.shape_ratio <= 1
1144
+ assert 0 <= S.stress_ratio <= 1
1145
+
1146
+ def test_stress_ratio_structural_definition(self):
1147
+ # R = (s2 - s3) / (s1 - s3)
1148
+ S = Stress3([[8, 0, 0], [0, 5, 0], [0, 0, 1]])
1149
+ assert math.isclose(S.stress_ratio, 4 / 7)
1150
+
1151
+ def test_from_ratio_roundtrip(self):
1152
+ for convention in ("geological", "mechanical"):
1153
+ with apsg_conf_context(stress_convention=convention):
1154
+ for r in (0.0, 0.25, 0.5, 0.8, 1.0):
1155
+ S = Stress3.from_ratio(r=r, mag=10)
1156
+ assert math.isclose(S.stress_ratio, r, abs_tol=1e-12)
1145
1157
 
1146
1158
  def test_eigenlins(self):
1147
1159
  S = Stress3.from_comp(xx=5, yy=2, zz=-10, xy=1)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes