Skip to content
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

Fix time stamp error #20 #21

Merged
merged 3 commits into from
Mar 4, 2024
Merged
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
3 changes: 1 addition & 2 deletions tests/io_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_from_scratch(tmp_path):
x = np.random.rand(100)
y = np.random.rand(100)

ikle = Delaunay(np.vstack((x, y)).T).simplices
ikle = Delaunay(np.vstack((x, y)).T).simplices + 1 # IKLE tables are 1-indexed

# Creating a minimal dataset
ds = xr.Dataset(
Expand All @@ -145,7 +145,6 @@ def test_from_scratch(tmp_path):
"x": ("node", x),
"y": ("node", y),
"time": pd.date_range("2020-01-01", periods=10),
# Add "ikle2" or "ikle3" as required by your mesh
},
)
ds.attrs["ikle2"] = ikle
Expand Down
2 changes: 1 addition & 1 deletion xarray_selafin/Serafin.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def _set_file_format_and_precision(self, file_format):
if file_format in ("SERAFIND", " D"):
self._set_as_double_precision()
else:
if file_format not in ("SERAFIN ", "SERAFINS", "SERAPHIN"):
if file_format not in (" ", "SERAFIN ", "SERAFINS", "SERAPHIN"):
logger.warning(
'Format "%s" is unknown and is forced to "SERAFIN "' % file_format
)
Expand Down
7 changes: 6 additions & 1 deletion xarray_selafin/xarray_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
from xarray_selafin import Serafin


DEFAULT_DATE_START = (1900, 1, 1, 0, 0, 0)


def compute_duration_between_datetime(t0, time_serie):
return (time_serie - t0).astype("timedelta64[s]").astype(float)

Expand Down Expand Up @@ -69,7 +72,7 @@ def write_serafin(fout, ds):
date = datetime.strptime(first_date_str, '%Y-%m-%dT%H:%M:%S.%f')
slf_header.date = attrgetter("year", "month", "day", "hour", "minute", "second")(date)
except ValueError:
slf_header.date = (1900, 1, 1, 0, 0, 0)
slf_header.date = DEFAULT_DATE_START

# Variables
try:
Expand Down Expand Up @@ -269,6 +272,8 @@ def open_dataset(
is_2d = slf.header.is_2d

# Prepare dimensions, coordinates, and data variables
if slf.header.date is None:
slf.header.date = DEFAULT_DATE_START
times = [datetime(*slf.header.date) + timedelta(seconds=t) for t in slf.time]
npoin2 = slf.header.nb_nodes_2d
ndp3 = slf.header.nb_nodes_per_elem
Expand Down
Loading