Skip to content

Sync some fix from latest PyTelTools commits #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- uses: "actions/setup-python@v2"
with:
python-version: "${{ matrix.python }}"
- uses: "actions/cache@v2"
- uses: "actions/cache@v3"
id: "cache"
with:
path: "${{ env.pythonLocation }}"
Expand Down
18 changes: 11 additions & 7 deletions xarray_selafin/Serafin.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class SerafinHeader:
- nb_nodes_per_elem <int>: number of nodes per element (= 3 in 2D and 6 in 3D)
- nb_nodes_2d <int>: number of 2D nodes (equals to `nb_nodes` in 2D)

- mesh_origin <(float, float)>: x and y shift to apply to written coordinates (set by `set_mesh_origin`)
- mesh_origin <(int, int)>: x and y shift to apply to written coordinates (set by `set_mesh_origin`)
- x_stored <numpy.1D-array>: east written coordinates [shape = nb_nodes]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we not specify decimal lat/lon coordinates ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mesh_origin is a tuple of 2 integers in PyTelTools, corresponding to x-coordinate and y-coordinate of the origin of the model.
It is excepted to be integers in the Selafin file format (IPARAM is a vector of 10 integers), see for example:

I do not know if a lat/long is possible, but it has to be an integer, due to the Selafin binary file format.

- y_stored <numpy.1D-array>: north written coordinates [shape = nb_nodes]
- x <numpy.1D-array>: east coordinates [shape = nb_nodes] (set by `_compute_mesh_coordinates`)
Expand Down Expand Up @@ -177,7 +177,7 @@ def __init__(self, title="", format_type="SERAFIN ", lang=LANG, endian=">"):
self.nb_nodes_per_elem = -1
self.nb_nodes_2d = -1

self.mesh_origin = (0.0, 0.0)
self.mesh_origin = (0, 0)
self.x_stored = None
self.y_stored = None
self.x = None
Expand Down Expand Up @@ -210,10 +210,10 @@ def _set_file_format_and_precision(self, file_format):
If file format is not recognized, the file is expected to be simple precision
"""
self.file_format = bytes(file_format, SLF_EIT).ljust(8)
if file_format in ("SERAFIND", " D"):
if file_format in ("SERAFIND", "SELAFIND", " D"):
self._set_as_double_precision()
else:
if file_format not in (" ", "SERAFIN ", "SERAFINS", "SERAPHIN"):
if file_format not in ("SERAFIN ", "SERAFINS", "SELAFIN ", "SERAPHIN"):
logger.warning(
'Format "%s" is unknown and is forced to "SERAFIN "' % file_format
)
Expand All @@ -240,13 +240,13 @@ def build_params(self):
1,
0,
self.mesh_origin[0],
self.mesh_origin[0],
self.mesh_origin[1],
0,
0,
self.nb_planes,
self.nb_elements,
0,
1,
0,
0 if self.date is None else 1,
)

def _build_ikle_2d(self):
Expand Down Expand Up @@ -803,6 +803,7 @@ def from_triangulation(self, nodes, ikle, ipobo=None):
self._compute_mesh_coordinates()
self.ikle = ikle.flatten()
self._build_ikle_2d()
self.build_params()
if ipobo is None:
self.build_ipobo()
else:
Expand Down Expand Up @@ -912,6 +913,9 @@ def from_file(self, file, file_size):
file.read(4 * self.nb_nodes),
dtype=np.dtype(np.int32).newbyteorder(self.endian),
)
# A valid IPOBO should not be equal to zero array
if not np.any(self.ipobo):
logger.warning("The IPOBO array seems corrupted (zeros array). Try to rebuild it with `build_ipobo()`.")
file.read(4)

# x coordinates
Expand Down
Loading