xbgears 0.1.0__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.
- xbgears-0.1.0/LICENSE +21 -0
- xbgears-0.1.0/MANIFEST.in +3 -0
- xbgears-0.1.0/PKG-INFO +62 -0
- xbgears-0.1.0/README.md +46 -0
- xbgears-0.1.0/pyproject.toml +34 -0
- xbgears-0.1.0/requirements.txt +1 -0
- xbgears-0.1.0/setup.cfg +4 -0
- xbgears-0.1.0/xbgears/__init__.py +17 -0
- xbgears-0.1.0/xbgears/cli.py +44 -0
- xbgears-0.1.0/xbgears/describe.py +62 -0
- xbgears-0.1.0/xbgears/xb2xyz.py +142 -0
- xbgears-0.1.0/xbgears/xyz2xb.py +96 -0
- xbgears-0.1.0/xbgears.egg-info/PKG-INFO +62 -0
- xbgears-0.1.0/xbgears.egg-info/SOURCES.txt +16 -0
- xbgears-0.1.0/xbgears.egg-info/dependency_links.txt +1 -0
- xbgears-0.1.0/xbgears.egg-info/entry_points.txt +5 -0
- xbgears-0.1.0/xbgears.egg-info/requires.txt +1 -0
- xbgears-0.1.0/xbgears.egg-info/top_level.txt +1 -0
xbgears-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 aaronchh
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
xbgears-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: xbgears
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A collection of tools for converting between XBeach grid files and XYZ point files
|
|
5
|
+
Author-email: aaronchh <aaronhsu219@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/AaronOET/xbgears
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: numpy
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# XBGEARS
|
|
18
|
+
|
|
19
|
+
A collection of Python tools for converting between XBeach grid files (x.grd / y.grd / *.dep) and simple XYZ point files.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install xbgears
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Features
|
|
28
|
+
|
|
29
|
+
- **xb2xyz**: Convert XBeach x.grd / y.grd / *.dep grid files into a *.xyz point file
|
|
30
|
+
- **xyz2xb**: Convert a *.xyz point file back into x.grd / y.grd / bed.dep files
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
### Command-line
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# List all available commands
|
|
38
|
+
xbgears-info
|
|
39
|
+
|
|
40
|
+
# Convert XBeach grid files to a *.xyz point file
|
|
41
|
+
xb2xyz --dep bed.dep --xgrd x.grd --ygrd y.grd --out 001.xyz
|
|
42
|
+
|
|
43
|
+
# Convert a *.xyz point file back to XBeach grid files
|
|
44
|
+
xyz2xb --xyz 001.xyz --outdir XBGRID
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Python API
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from xbgears import xb2xyz, xyz2xb
|
|
51
|
+
|
|
52
|
+
# Convert XBeach grid files to a *.xyz point file (written to XYZ/001.xyz)
|
|
53
|
+
xb2xyz.xb_to_xyz(dep="bed.dep", xgrd="x.grd", ygrd="y.grd", out="001.xyz")
|
|
54
|
+
|
|
55
|
+
# Convert a *.xyz point file back to XBeach grid files (written to XBGRID/)
|
|
56
|
+
xyz2xb.xyz_to_xb(xyz="001.xyz", outdir="XBGRID")
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Notes
|
|
60
|
+
|
|
61
|
+
- `xb2xyz` reads `xori`/`yori` from `params.txt` in the working directory (if present) and adds them to the x/y coordinates; grid rotation (`alfa`) is not applied.
|
|
62
|
+
- `xb2xyz` writes its output to the `XYZ/` directory by default; `xyz2xb` writes its output to the `XBGRID/` directory by default.
|
xbgears-0.1.0/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# XBGEARS
|
|
2
|
+
|
|
3
|
+
A collection of Python tools for converting between XBeach grid files (x.grd / y.grd / *.dep) and simple XYZ point files.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install xbgears
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **xb2xyz**: Convert XBeach x.grd / y.grd / *.dep grid files into a *.xyz point file
|
|
14
|
+
- **xyz2xb**: Convert a *.xyz point file back into x.grd / y.grd / bed.dep files
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
### Command-line
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# List all available commands
|
|
22
|
+
xbgears-info
|
|
23
|
+
|
|
24
|
+
# Convert XBeach grid files to a *.xyz point file
|
|
25
|
+
xb2xyz --dep bed.dep --xgrd x.grd --ygrd y.grd --out 001.xyz
|
|
26
|
+
|
|
27
|
+
# Convert a *.xyz point file back to XBeach grid files
|
|
28
|
+
xyz2xb --xyz 001.xyz --outdir XBGRID
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Python API
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from xbgears import xb2xyz, xyz2xb
|
|
35
|
+
|
|
36
|
+
# Convert XBeach grid files to a *.xyz point file (written to XYZ/001.xyz)
|
|
37
|
+
xb2xyz.xb_to_xyz(dep="bed.dep", xgrd="x.grd", ygrd="y.grd", out="001.xyz")
|
|
38
|
+
|
|
39
|
+
# Convert a *.xyz point file back to XBeach grid files (written to XBGRID/)
|
|
40
|
+
xyz2xb.xyz_to_xb(xyz="001.xyz", outdir="XBGRID")
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Notes
|
|
44
|
+
|
|
45
|
+
- `xb2xyz` reads `xori`/`yori` from `params.txt` in the working directory (if present) and adds them to the x/y coordinates; grid rotation (`alfa`) is not applied.
|
|
46
|
+
- `xb2xyz` writes its output to the `XYZ/` directory by default; `xyz2xb` writes its output to the `XBGRID/` directory by default.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "xbgears"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "aaronchh", email = "aaronhsu219@gmail.com" },
|
|
10
|
+
]
|
|
11
|
+
description = "A collection of tools for converting between XBeach grid files and XYZ point files"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
license = { text = "MIT" }
|
|
14
|
+
requires-python = ">=3.9"
|
|
15
|
+
dependencies = [
|
|
16
|
+
"numpy",
|
|
17
|
+
]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"License :: OSI Approved :: MIT License",
|
|
21
|
+
"Operating System :: OS Independent",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://github.com/AaronOET/xbgears"
|
|
26
|
+
|
|
27
|
+
[tool.setuptools]
|
|
28
|
+
packages = ["xbgears"]
|
|
29
|
+
|
|
30
|
+
[project.scripts]
|
|
31
|
+
xbgears = "xbgears.cli:main"
|
|
32
|
+
xbgears-info = "xbgears.describe:main"
|
|
33
|
+
xb2xyz = "xbgears.xb2xyz:main"
|
|
34
|
+
xyz2xb = "xbgears.xyz2xb:main"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
numpy
|
xbgears-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""
|
|
2
|
+
XBGEARS - A collection of tools for converting between XBeach grid files
|
|
3
|
+
(x.grd / y.grd / *.dep) and simple XYZ point files.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
__version__ = '0.1.0'
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
'describe',
|
|
10
|
+
'xb2xyz',
|
|
11
|
+
'xyz2xb',
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
from . import describe
|
|
15
|
+
from . import xb2xyz
|
|
16
|
+
from . import xyz2xb
|
|
17
|
+
from . import cli
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
"""
|
|
3
|
+
Top-level `xbgears` command. Running `xbgears -h` (or with no arguments)
|
|
4
|
+
prints the same information shown by `xbgears-info`. Running `xbgears -v`
|
|
5
|
+
prints the installed xbgears version.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
from . import __version__, describe
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _print_info(tool=None):
|
|
14
|
+
argv_backup = sys.argv
|
|
15
|
+
try:
|
|
16
|
+
sys.argv = ['xbgears-info'] + ([tool] if tool else [])
|
|
17
|
+
describe.main()
|
|
18
|
+
finally:
|
|
19
|
+
sys.argv = argv_backup
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def main():
|
|
23
|
+
args = sys.argv[1:]
|
|
24
|
+
|
|
25
|
+
if not args or args[0] in ('-h', '--help'):
|
|
26
|
+
_print_info()
|
|
27
|
+
return
|
|
28
|
+
|
|
29
|
+
if args[0] in ('-v', '--version'):
|
|
30
|
+
print(f"xbgears {__version__}")
|
|
31
|
+
return
|
|
32
|
+
|
|
33
|
+
tool = args[0]
|
|
34
|
+
if tool in describe.TOOL_DESCRIPTIONS:
|
|
35
|
+
_print_info(tool)
|
|
36
|
+
return
|
|
37
|
+
|
|
38
|
+
print(f"Unknown option or tool: {tool}", file=sys.stderr)
|
|
39
|
+
print("Run 'xbgears -h' to see available tools.", file=sys.stderr)
|
|
40
|
+
sys.exit(2)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if __name__ == "__main__":
|
|
44
|
+
main()
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
"""
|
|
3
|
+
Command-line utility to display descriptions of xbgears functionality.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import sys
|
|
8
|
+
from textwrap import dedent
|
|
9
|
+
|
|
10
|
+
TOOL_DESCRIPTIONS = {
|
|
11
|
+
'xb2xyz': """
|
|
12
|
+
Convert XBeach x.grd / y.grd / *.dep grid files into a *.xyz point file.
|
|
13
|
+
|
|
14
|
+
x.grd and y.grd must have the same shape as the *.dep file (rows =
|
|
15
|
+
ny+1, columns = nx+1, whitespace-separated floats, XBeach grid
|
|
16
|
+
format). If params.txt exists in the working directory, xori/yori
|
|
17
|
+
are read from it and added to the x/y coordinates.
|
|
18
|
+
|
|
19
|
+
Examples:
|
|
20
|
+
xb2xyz # Use defaults, write XYZ/001.xyz
|
|
21
|
+
xb2xyz --dep bed.dep --out 001.xyz # Explicit file names
|
|
22
|
+
""",
|
|
23
|
+
'xyz2xb': """
|
|
24
|
+
Convert a *.xyz point file into x.grd / y.grd / bed.dep files.
|
|
25
|
+
|
|
26
|
+
Reverse of xb2xyz. The *.xyz file must contain whitespace-separated
|
|
27
|
+
"x y z" rows; each row becomes one line in x.grd, y.grd and bed.dep.
|
|
28
|
+
|
|
29
|
+
Examples:
|
|
30
|
+
xyz2xb # Use defaults, write XBGRID/{x.grd,y.grd,bed.dep}
|
|
31
|
+
xyz2xb --xyz 001.xyz --outdir XBGRID # Explicit file names
|
|
32
|
+
""",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def main():
|
|
37
|
+
parser = argparse.ArgumentParser(
|
|
38
|
+
prog='xbgears-info',
|
|
39
|
+
description='Display descriptions of xbgears commands',
|
|
40
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
41
|
+
)
|
|
42
|
+
parser.add_argument(
|
|
43
|
+
'tool',
|
|
44
|
+
nargs='?',
|
|
45
|
+
choices=list(TOOL_DESCRIPTIONS.keys()),
|
|
46
|
+
help='Tool name to describe (omit to list all tools)',
|
|
47
|
+
)
|
|
48
|
+
args = parser.parse_args()
|
|
49
|
+
|
|
50
|
+
if args.tool:
|
|
51
|
+
print(f"\n--- {args.tool} ---")
|
|
52
|
+
print(dedent(TOOL_DESCRIPTIONS[args.tool]))
|
|
53
|
+
else:
|
|
54
|
+
print("\nXBGEARS — XBeach grid / XYZ point file conversion commands\n")
|
|
55
|
+
for tool, desc in TOOL_DESCRIPTIONS.items():
|
|
56
|
+
first_line = dedent(desc).strip().splitlines()[0]
|
|
57
|
+
print(f" {tool:<14} {first_line}")
|
|
58
|
+
print("\nRun 'xbgears-info <tool>' for details on a specific command.")
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
if __name__ == "__main__":
|
|
62
|
+
main()
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
"""
|
|
3
|
+
xb2xyz - Convert XBeach x.grd / y.grd / *.dep grid files into a simple *.xyz point file.
|
|
4
|
+
|
|
5
|
+
x.grd and y.grd must have the same shape as the *.dep file (rows = ny+1,
|
|
6
|
+
columns = nx+1, whitespace-separated floats, XBeach grid format).
|
|
7
|
+
|
|
8
|
+
If params.txt exists in the current folder, xori and yori are read from it
|
|
9
|
+
and added to the x/y coordinates. Otherwise xori = yori = 0.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import argparse
|
|
13
|
+
import re
|
|
14
|
+
import sys
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
import numpy as np
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def read_params(params_path: Path) -> tuple[float, float]:
|
|
21
|
+
"""Return (xori, yori) from params.txt, defaulting to (0, 0) if absent."""
|
|
22
|
+
xori, yori = 0.0, 0.0
|
|
23
|
+
if not params_path.is_file():
|
|
24
|
+
print(f"No params.txt found at {params_path}; assuming xori=0, yori=0.")
|
|
25
|
+
return xori, yori
|
|
26
|
+
|
|
27
|
+
text = params_path.read_text(errors="ignore")
|
|
28
|
+
xori_match = re.search(r"^\s*xori\s*=\s*([-\d.eE+]+)", text, re.MULTILINE)
|
|
29
|
+
yori_match = re.search(r"^\s*yori\s*=\s*([-\d.eE+]+)", text, re.MULTILINE)
|
|
30
|
+
|
|
31
|
+
if xori_match:
|
|
32
|
+
xori = float(xori_match.group(1))
|
|
33
|
+
else:
|
|
34
|
+
print(f"xori not found in {params_path}; assuming xori=0.")
|
|
35
|
+
|
|
36
|
+
if yori_match:
|
|
37
|
+
yori = float(yori_match.group(1))
|
|
38
|
+
else:
|
|
39
|
+
print(f"yori not found in {params_path}; assuming yori=0.")
|
|
40
|
+
|
|
41
|
+
alfa_match = re.search(r"^\s*alfa\s*=\s*([-\d.eE+]+)", text, re.MULTILINE)
|
|
42
|
+
if alfa_match and float(alfa_match.group(1)) != 0:
|
|
43
|
+
print(
|
|
44
|
+
f"Warning: params.txt has alfa={alfa_match.group(1)} (grid rotation). "
|
|
45
|
+
"This tool only applies the xori/yori translation, not the rotation."
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
return xori, yori
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def xb_to_xyz(
|
|
52
|
+
dep="bed.dep",
|
|
53
|
+
out="001.xyz",
|
|
54
|
+
xgrd="x.grd",
|
|
55
|
+
ygrd="y.grd",
|
|
56
|
+
outdir="XYZ",
|
|
57
|
+
params="params.txt",
|
|
58
|
+
cwd=None,
|
|
59
|
+
) -> Path:
|
|
60
|
+
"""
|
|
61
|
+
Convert XBeach x.grd / y.grd / *.dep grid files into a *.xyz point file.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
dep (str): Input *.dep file name
|
|
65
|
+
out (str): Output *.xyz file name
|
|
66
|
+
xgrd (str): Input x-grid file name
|
|
67
|
+
ygrd (str): Input y-grid file name
|
|
68
|
+
outdir (str): Output folder name
|
|
69
|
+
params (str): params.txt file name (used to read xori/yori)
|
|
70
|
+
cwd (Path): Working directory to resolve relative paths against
|
|
71
|
+
(defaults to the current directory)
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
Path: Path to the written *.xyz file
|
|
75
|
+
"""
|
|
76
|
+
cwd = Path(cwd) if cwd is not None else Path.cwd()
|
|
77
|
+
xgrd_path = cwd / xgrd
|
|
78
|
+
ygrd_path = cwd / ygrd
|
|
79
|
+
dep_path = cwd / dep
|
|
80
|
+
params_path = cwd / params
|
|
81
|
+
|
|
82
|
+
for p in (xgrd_path, ygrd_path, dep_path):
|
|
83
|
+
if not p.is_file():
|
|
84
|
+
sys.exit(f"Error: required input file not found: {p}")
|
|
85
|
+
|
|
86
|
+
x = np.loadtxt(xgrd_path)
|
|
87
|
+
y = np.loadtxt(ygrd_path)
|
|
88
|
+
z = np.loadtxt(dep_path)
|
|
89
|
+
|
|
90
|
+
if not (x.shape == y.shape == z.shape):
|
|
91
|
+
sys.exit(
|
|
92
|
+
f"Error: shape mismatch - x.grd {x.shape}, y.grd {y.shape}, "
|
|
93
|
+
f"{dep} {z.shape} must all match."
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
xori, yori = read_params(params_path)
|
|
97
|
+
|
|
98
|
+
x_out = x + xori
|
|
99
|
+
y_out = y + yori
|
|
100
|
+
|
|
101
|
+
outdir_path = cwd / outdir
|
|
102
|
+
outdir_path.mkdir(parents=True, exist_ok=True)
|
|
103
|
+
out_path = outdir_path / out
|
|
104
|
+
|
|
105
|
+
xyz = np.column_stack((x_out.ravel(), y_out.ravel(), z.ravel()))
|
|
106
|
+
np.savetxt(out_path, xyz, fmt="%.6f %.6f %.6f")
|
|
107
|
+
|
|
108
|
+
print(f"Wrote {xyz.shape[0]} points to {out_path}")
|
|
109
|
+
return out_path
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def main():
|
|
113
|
+
parser = argparse.ArgumentParser(
|
|
114
|
+
prog="xb2xyz",
|
|
115
|
+
description="Convert XBeach x.grd / y.grd / *.dep grid files into a *.xyz point file",
|
|
116
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
117
|
+
epilog="""
|
|
118
|
+
Examples:
|
|
119
|
+
xb2xyz # Use defaults (bed.dep, x.grd, y.grd -> XYZ/001.xyz)
|
|
120
|
+
xb2xyz --dep bed.dep --out 001.xyz # Explicit file names
|
|
121
|
+
""",
|
|
122
|
+
)
|
|
123
|
+
parser.add_argument("--dep", default="bed.dep", help="Input *.dep file name (default: bed.dep)")
|
|
124
|
+
parser.add_argument("--out", default="001.xyz", help="Output *.xyz file name (default: 001.xyz)")
|
|
125
|
+
parser.add_argument("--xgrd", default="x.grd", help="Input x-grid file name (default: x.grd)")
|
|
126
|
+
parser.add_argument("--ygrd", default="y.grd", help="Input y-grid file name (default: y.grd)")
|
|
127
|
+
parser.add_argument("--outdir", default="XYZ", help="Output folder name (default: XYZ)")
|
|
128
|
+
parser.add_argument("--params", default="params.txt", help="params.txt file name (default: params.txt)")
|
|
129
|
+
args = parser.parse_args()
|
|
130
|
+
|
|
131
|
+
xb_to_xyz(
|
|
132
|
+
dep=args.dep,
|
|
133
|
+
out=args.out,
|
|
134
|
+
xgrd=args.xgrd,
|
|
135
|
+
ygrd=args.ygrd,
|
|
136
|
+
outdir=args.outdir,
|
|
137
|
+
params=args.params,
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
if __name__ == "__main__":
|
|
142
|
+
main()
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
"""
|
|
3
|
+
xyz2xb - Convert a simple *.xyz point file into x.grd / y.grd / bed.dep files.
|
|
4
|
+
|
|
5
|
+
Reverse of xb2xyz. The *.xyz file must contain whitespace-separated "x y z"
|
|
6
|
+
rows. Each line of the input file becomes one line in x.grd, y.grd and
|
|
7
|
+
bed.dep (same line order, same line count) - i.e. the three output files are
|
|
8
|
+
just the x, y and z columns of the *.xyz file split back out. Values are
|
|
9
|
+
written as "%16.7e", matching the formatting used in the original
|
|
10
|
+
x.grd/y.grd/bed.dep files.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import sys
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
import numpy as np
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def xyz_to_xb(
|
|
21
|
+
xyz="001.xyz",
|
|
22
|
+
dep="bed.dep",
|
|
23
|
+
xgrd="x.grd",
|
|
24
|
+
ygrd="y.grd",
|
|
25
|
+
outdir="XBGRID",
|
|
26
|
+
cwd=None,
|
|
27
|
+
) -> Path:
|
|
28
|
+
"""
|
|
29
|
+
Convert a *.xyz point file into x.grd / y.grd / bed.dep files.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
xyz (str): Input *.xyz file name
|
|
33
|
+
dep (str): Output *.dep file name
|
|
34
|
+
xgrd (str): Output x-grid file name
|
|
35
|
+
ygrd (str): Output y-grid file name
|
|
36
|
+
outdir (str): Output folder name
|
|
37
|
+
cwd (Path): Working directory to resolve relative paths against
|
|
38
|
+
(defaults to the current directory)
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
Path: Path to the output folder containing x.grd, y.grd and bed.dep
|
|
42
|
+
"""
|
|
43
|
+
cwd = Path(cwd) if cwd is not None else Path.cwd()
|
|
44
|
+
xyz_path = cwd / xyz
|
|
45
|
+
|
|
46
|
+
if not xyz_path.is_file():
|
|
47
|
+
sys.exit(f"Error: input file not found: {xyz_path}")
|
|
48
|
+
|
|
49
|
+
xyz_data = np.loadtxt(xyz_path)
|
|
50
|
+
if xyz_data.ndim != 2 or xyz_data.shape[1] != 3:
|
|
51
|
+
sys.exit(f"Error: expected 3 columns (x y z) in {xyz}, got shape {xyz_data.shape}")
|
|
52
|
+
|
|
53
|
+
x = xyz_data[:, 0]
|
|
54
|
+
y = xyz_data[:, 1]
|
|
55
|
+
z = xyz_data[:, 2]
|
|
56
|
+
|
|
57
|
+
outdir_path = cwd / outdir
|
|
58
|
+
outdir_path.mkdir(parents=True, exist_ok=True)
|
|
59
|
+
|
|
60
|
+
np.savetxt(outdir_path / xgrd, x, fmt="%16.7e")
|
|
61
|
+
np.savetxt(outdir_path / ygrd, y, fmt="%16.7e")
|
|
62
|
+
np.savetxt(outdir_path / dep, z, fmt="%16.7e")
|
|
63
|
+
|
|
64
|
+
print(f"Wrote {xgrd}, {ygrd}, {dep} ({x.shape[0]} lines) to {outdir_path}")
|
|
65
|
+
return outdir_path
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def main():
|
|
69
|
+
parser = argparse.ArgumentParser(
|
|
70
|
+
prog="xyz2xb",
|
|
71
|
+
description="Convert a *.xyz point file into x.grd / y.grd / bed.dep files",
|
|
72
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
73
|
+
epilog="""
|
|
74
|
+
Examples:
|
|
75
|
+
xyz2xb # Use defaults (001.xyz -> XBGRID/{x.grd,y.grd,bed.dep})
|
|
76
|
+
xyz2xb --xyz 001.xyz --outdir XBGRID # Explicit file names
|
|
77
|
+
""",
|
|
78
|
+
)
|
|
79
|
+
parser.add_argument("--xyz", default="001.xyz", help="Input *.xyz file name (default: 001.xyz)")
|
|
80
|
+
parser.add_argument("--dep", default="bed.dep", help="Output *.dep file name (default: bed.dep)")
|
|
81
|
+
parser.add_argument("--xgrd", default="x.grd", help="Output x-grid file name (default: x.grd)")
|
|
82
|
+
parser.add_argument("--ygrd", default="y.grd", help="Output y-grid file name (default: y.grd)")
|
|
83
|
+
parser.add_argument("--outdir", default="XBGRID", help="Output folder name (default: XBGRID)")
|
|
84
|
+
args = parser.parse_args()
|
|
85
|
+
|
|
86
|
+
xyz_to_xb(
|
|
87
|
+
xyz=args.xyz,
|
|
88
|
+
dep=args.dep,
|
|
89
|
+
xgrd=args.xgrd,
|
|
90
|
+
ygrd=args.ygrd,
|
|
91
|
+
outdir=args.outdir,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
if __name__ == "__main__":
|
|
96
|
+
main()
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: xbgears
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A collection of tools for converting between XBeach grid files and XYZ point files
|
|
5
|
+
Author-email: aaronchh <aaronhsu219@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/AaronOET/xbgears
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: numpy
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# XBGEARS
|
|
18
|
+
|
|
19
|
+
A collection of Python tools for converting between XBeach grid files (x.grd / y.grd / *.dep) and simple XYZ point files.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install xbgears
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Features
|
|
28
|
+
|
|
29
|
+
- **xb2xyz**: Convert XBeach x.grd / y.grd / *.dep grid files into a *.xyz point file
|
|
30
|
+
- **xyz2xb**: Convert a *.xyz point file back into x.grd / y.grd / bed.dep files
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
### Command-line
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# List all available commands
|
|
38
|
+
xbgears-info
|
|
39
|
+
|
|
40
|
+
# Convert XBeach grid files to a *.xyz point file
|
|
41
|
+
xb2xyz --dep bed.dep --xgrd x.grd --ygrd y.grd --out 001.xyz
|
|
42
|
+
|
|
43
|
+
# Convert a *.xyz point file back to XBeach grid files
|
|
44
|
+
xyz2xb --xyz 001.xyz --outdir XBGRID
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Python API
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from xbgears import xb2xyz, xyz2xb
|
|
51
|
+
|
|
52
|
+
# Convert XBeach grid files to a *.xyz point file (written to XYZ/001.xyz)
|
|
53
|
+
xb2xyz.xb_to_xyz(dep="bed.dep", xgrd="x.grd", ygrd="y.grd", out="001.xyz")
|
|
54
|
+
|
|
55
|
+
# Convert a *.xyz point file back to XBeach grid files (written to XBGRID/)
|
|
56
|
+
xyz2xb.xyz_to_xb(xyz="001.xyz", outdir="XBGRID")
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Notes
|
|
60
|
+
|
|
61
|
+
- `xb2xyz` reads `xori`/`yori` from `params.txt` in the working directory (if present) and adds them to the x/y coordinates; grid rotation (`alfa`) is not applied.
|
|
62
|
+
- `xb2xyz` writes its output to the `XYZ/` directory by default; `xyz2xb` writes its output to the `XBGRID/` directory by default.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
requirements.txt
|
|
6
|
+
xbgears/__init__.py
|
|
7
|
+
xbgears/cli.py
|
|
8
|
+
xbgears/describe.py
|
|
9
|
+
xbgears/xb2xyz.py
|
|
10
|
+
xbgears/xyz2xb.py
|
|
11
|
+
xbgears.egg-info/PKG-INFO
|
|
12
|
+
xbgears.egg-info/SOURCES.txt
|
|
13
|
+
xbgears.egg-info/dependency_links.txt
|
|
14
|
+
xbgears.egg-info/entry_points.txt
|
|
15
|
+
xbgears.egg-info/requires.txt
|
|
16
|
+
xbgears.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
numpy
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
xbgears
|