Skip to content
Snippets Groups Projects
Commit 2f7845ff authored by koronima's avatar koronima :baby_chick:
Browse files

Upload New File

parent 821e5914
Branches main
No related tags found
No related merge requests found
tools.py 0 → 100644
import typing
import numpy as np
import xarray as xr
def _parse_lines(lines: typing.List[str]):
return np.fromstring(
"".join(lines).replace("\n", "").replace("-", " -").strip(), sep=" "
)
def read_velomod(filename: str) -> xr.DataArray:
"""
Read a velomod file and return an xarray DataArray.
Args:
filename: The filename to read.
Returns:
A DataArray.
"""
with open(filename, mode="r") as fh:
lines = fh.readlines()
x = _parse_lines(lines[1:4]) * -1000.0
y = _parse_lines(lines[4:7]) * 1000.0
z = _parse_lines(lines[7:8]) * -1000.0
v = _parse_lines(lines[9:]) * 1000.0
nx, ny, nz = len(x), len(y), len(z)
# Reference locations HERE IN ED50 N32, epsg23032: 462069.582191081, 5205484.598682921
rx, ry = (462069.582191081, 5205484.598682921)
# reference location in epsg32632:
#(461987.2450072905, 5205285.41538475)
return xr.DataArray(
np.reshape(v, (nz, ny, nx), order="C"), [("z", z), ("y", y + ry), ("x", x + rx)]
).transpose("x", "y", "z")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment