SW1Dto2D 0.0.6__tar.gz → 0.0.7__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 (32) hide show
  1. {SW1Dto2D-0.0.6/SW1Dto2D.egg-info → sw1dto2d-0.0.7}/PKG-INFO +2 -2
  2. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/pyproject.toml +1 -1
  3. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/sw1dto2d/__init__.py +1 -1
  4. sw1dto2d-0.0.7/sw1dto2d/cartesian.py +32 -0
  5. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/sw1dto2d/sw1dto2d.py +35 -12
  6. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7/sw1dto2d.egg-info}/PKG-INFO +2 -2
  7. {SW1Dto2D-0.0.6/SW1Dto2D.egg-info → sw1dto2d-0.0.7/sw1dto2d.egg-info}/SOURCES.txt +6 -5
  8. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/.github/workflows/cicd.yml +0 -0
  9. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/.gitignore +0 -0
  10. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/LICENSE +0 -0
  11. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/README.md +0 -0
  12. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/pytest.ini +0 -0
  13. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/setup.cfg +0 -0
  14. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/setup.py +0 -0
  15. {SW1Dto2D-0.0.6/SW1Dto2D.egg-info → sw1dto2d-0.0.7/sw1dto2d.egg-info}/dependency_links.txt +0 -0
  16. {SW1Dto2D-0.0.6/SW1Dto2D.egg-info → sw1dto2d-0.0.7/sw1dto2d.egg-info}/requires.txt +0 -0
  17. {SW1Dto2D-0.0.6/SW1Dto2D.egg-info → sw1dto2d-0.0.7/sw1dto2d.egg-info}/top_level.txt +0 -0
  18. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/tests/__init__.py +0 -0
  19. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/tests/data/brahmaputra/brahmaputra_results.csv +0 -0
  20. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/tests/data/brahmaputra/centerline.dbf +0 -0
  21. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/tests/data/brahmaputra/centerline.prj +0 -0
  22. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/tests/data/brahmaputra/centerline.shp +0 -0
  23. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/tests/data/brahmaputra/centerline.shx +0 -0
  24. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/tests/data/garonne/Garonne2019_results_selection.csv +0 -0
  25. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/tests/data/garonne/__init__.py +0 -0
  26. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/tests/data/garonne/centerline.dbf +0 -0
  27. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/tests/data/garonne/centerline.prj +0 -0
  28. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/tests/data/garonne/centerline.shp +0 -0
  29. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/tests/data/garonne/centerline.shx +0 -0
  30. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/tests/test_basic_processes.py +0 -0
  31. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/tests/test_brahmaputra.py +0 -0
  32. {SW1Dto2D-0.0.6 → sw1dto2d-0.0.7}/tests/test_garonne.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
- Name: SW1Dto2D
3
- Version: 0.0.6
2
+ Name: sw1dto2d
3
+ Version: 0.0.7
4
4
  Summary: Tool to convert results of a 1D Shallow Water model to 2D geometries
5
5
  Home-page: https://github.com/klarnier/sw1dto2d
6
6
  Author: Kevin Larnier
@@ -14,7 +14,7 @@ profile = 'black'
14
14
  line_length = 120
15
15
 
16
16
  [project]
17
- name = "SW1Dto2D"
17
+ name = "sw1dto2d"
18
18
  dynamic = ["version"]
19
19
 
20
20
  [project.urls]
@@ -31,5 +31,5 @@
31
31
 
32
32
  from .sw1dto2d import SW1Dto2D
33
33
 
34
- __version__ = "0.0.6"
34
+ __version__ = "0.0.7"
35
35
 
@@ -0,0 +1,32 @@
1
+ import numpy as np
2
+ from shapely.geometry import Point
3
+
4
+ class Distance:
5
+
6
+ def __init__(self, meters):
7
+ self._distance = meters
8
+
9
+ def destination(self, center, bearing):
10
+ """
11
+ Compute the destination from center and direction angle (bearing)
12
+
13
+ Parameters
14
+ ----------
15
+ center : (y,x) tuple. Coordinates are y,x to ensure harmonisation with geopy functions where coordinates are expressed in (lat,lon)
16
+ bearing : direction angle in degrees
17
+
18
+ Return
19
+ ------
20
+ point : destination point
21
+ """
22
+
23
+ angle = bearing * np.pi / 180.0
24
+ nx = np.sin(angle)
25
+ ny = np.cos(angle)
26
+
27
+ dest_x = center[1] + nx * self._distance
28
+ dest_y = center[0] + ny * self._distance
29
+
30
+ return Point(dest_x, dest_y)
31
+
32
+ distance = Distance
@@ -39,8 +39,10 @@ from typing import Dict, List, Tuple
39
39
  import geopy.distance
40
40
  import numpy as np
41
41
  import pandas as pd
42
+ import pyproj
42
43
  from pyproj.transformer import Transformer
43
44
  from shapely.geometry import LineString, Point, Polygon
45
+ import sw1dto2d.cartesian
44
46
 
45
47
 
46
48
  class SW1Dto2D:
@@ -53,6 +55,7 @@ class SW1Dto2D:
53
55
  heights_key: str,
54
56
  widths_key: str,
55
57
  centerline: LineString,
58
+ crs=4326
56
59
  ):
57
60
  """
58
61
  Constructor.
@@ -81,6 +84,20 @@ class SW1Dto2D:
81
84
  self._heights = heights.reshape((widths.size // self._curv_abscissa.size, self._curv_abscissa.size))
82
85
 
83
86
  self._centerline = centerline
87
+ if isinstance(crs, int):
88
+ self._crs = pyproj.crs.CRS.from_epsg(crs)
89
+ else:
90
+ self._crs = pyproj.crs.CRS(crs)
91
+
92
+ # Setup distance method from CRS
93
+ if self._crs.to_epsg() == 4326:
94
+ self._distance = geopy.distance.distance
95
+ self._shapely_point = lambda x: Point(x.longitude, x.latitude)
96
+ elif self._crs.axis_info[0].unit_name == "metre" and self._crs.axis_info[1].unit_name == "metre":
97
+ self._distance = sw1dto2d.cartesian.distance
98
+ self._shapely_point = lambda x: x
99
+ else:
100
+ raise RuntimeError("Centerline must have either WGS84 CRS or a CRS with coordinates in meters.")
84
101
 
85
102
  @property
86
103
  def curv_abscissa(self):
@@ -104,6 +121,7 @@ class SW1Dto2D:
104
121
  logging.info("Compute cross-sections parameters (coordinates and normals)")
105
122
  logging.info("-" * 60)
106
123
 
124
+ # Check centerline is set
107
125
  if self._centerline is None:
108
126
  raise RuntimeError("centerline is not set yet")
109
127
 
@@ -283,9 +301,12 @@ class SW1Dto2D:
283
301
  bearing2 = angles[ix] + 180.0
284
302
 
285
303
  center = (xs_coords[ix, 1], xs_coords[ix, 0])
286
- point1 = geopy.distance.distance(meters=Wdemi).destination(center, bearing=bearing1)
287
- point2 = geopy.distance.distance(meters=Wdemi).destination(center, bearing=bearing2)
288
- xs_lines.append(LineString([(point1.longitude, point1.latitude), (point2.longitude, point2.latitude)]))
304
+ point1 = self._shapely_point(self._distance(meters=Wdemi).destination(center, bearing=bearing1))
305
+ point2 = self._shapely_point(self._distance(meters=Wdemi).destination(center, bearing=bearing2))
306
+ # point1 = geopy.distance.distance(meters=Wdemi).destination(center, bearing=bearing1)
307
+ # point2 = geopy.distance.distance(meters=Wdemi).destination(center, bearing=bearing2)
308
+
309
+ xs_lines.append(LineString([(point1.x, point1.y), (point2.x, point2.y)]))
289
310
 
290
311
  # Flag intersecting lines
291
312
  intersect_flag = np.zeros(xs_coords.shape[0], dtype=int)
@@ -344,11 +365,11 @@ class SW1Dto2D:
344
365
  bearing2 = new_angles[ix] + 180.0
345
366
 
346
367
  center = (xs_coords[ix, 1], xs_coords[ix, 0])
347
- point1 = geopy.distance.distance(meters=Wdemi).destination(center, bearing=bearing1)
348
- point2 = geopy.distance.distance(meters=Wdemi).destination(center, bearing=bearing2)
349
- new_lines[ix] = LineString(
350
- [(point1.longitude, point1.latitude), (point2.longitude, point2.latitude)]
351
- )
368
+ point1 = self._shapely_point(self._distance(meters=Wdemi).destination(center, bearing=bearing1))
369
+ point2 = self._shapely_point(self._distance(meters=Wdemi).destination(center, bearing=bearing2))
370
+ # point1 = geopy.distance.distance(meters=Wdemi).destination(center, bearing=bearing1)
371
+ # point2 = geopy.distance.distance(meters=Wdemi).destination(center, bearing=bearing2)
372
+ new_lines[ix] = LineString([(point1.x, point1.y), (point2.x, point2.y)])
352
373
 
353
374
  # Check for remaining intersections
354
375
  nintersect2 = 0
@@ -386,7 +407,7 @@ class SW1Dto2D:
386
407
  Parameters
387
408
  ----------
388
409
  it : index of time occurence (in the H and W arrays)
389
- extend :
410
+ extend : extra extension. Final cutline has length W[it] + extend
390
411
 
391
412
  Return
392
413
  ------
@@ -424,9 +445,11 @@ class SW1Dto2D:
424
445
  bearing2 = angles[ix] + 180.0
425
446
 
426
447
  center = (xs_coords[ix, 1], xs_coords[ix, 0])
427
- point1 = geopy.distance.distance(meters=Wdemi).destination(center, bearing=bearing1)
428
- point2 = geopy.distance.distance(meters=Wdemi).destination(center, bearing=bearing2)
429
- xs_lines.append(LineString([(point1.longitude, point1.latitude), (point2.longitude, point2.latitude)]))
448
+ point1 = self._shapely_point(self._distance(meters=Wdemi).destination(center, bearing=bearing1))
449
+ point2 = self._shapely_point(self._distance(meters=Wdemi).destination(center, bearing=bearing2))
450
+ # point1 = geopy.distance.distance(meters=Wdemi).destination(center, bearing=bearing1)
451
+ # point2 = geopy.distance.distance(meters=Wdemi).destination(center, bearing=bearing2)
452
+ xs_lines.append(LineString([(point1.x, point1.y), (point2.x, point2.y)]))
430
453
 
431
454
  return xs_lines
432
455
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
- Name: SW1Dto2D
3
- Version: 0.0.6
2
+ Name: sw1dto2d
3
+ Version: 0.0.7
4
4
  Summary: Tool to convert results of a 1D Shallow Water model to 2D geometries
5
5
  Home-page: https://github.com/klarnier/sw1dto2d
6
6
  Author: Kevin Larnier
@@ -6,13 +6,14 @@ pytest.ini
6
6
  setup.cfg
7
7
  setup.py
8
8
  .github/workflows/cicd.yml
9
- SW1Dto2D.egg-info/PKG-INFO
10
- SW1Dto2D.egg-info/SOURCES.txt
11
- SW1Dto2D.egg-info/dependency_links.txt
12
- SW1Dto2D.egg-info/requires.txt
13
- SW1Dto2D.egg-info/top_level.txt
14
9
  sw1dto2d/__init__.py
10
+ sw1dto2d/cartesian.py
15
11
  sw1dto2d/sw1dto2d.py
12
+ sw1dto2d.egg-info/PKG-INFO
13
+ sw1dto2d.egg-info/SOURCES.txt
14
+ sw1dto2d.egg-info/dependency_links.txt
15
+ sw1dto2d.egg-info/requires.txt
16
+ sw1dto2d.egg-info/top_level.txt
16
17
  tests/__init__.py
17
18
  tests/test_basic_processes.py
18
19
  tests/test_brahmaputra.py
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes