Skip to content

Commit

Permalink
Clean
Browse files Browse the repository at this point in the history
  • Loading branch information
ecomodeller committed Jun 25, 2024
1 parent f910153 commit cf68173
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions mikeio/dfsu/_dfsu.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ def write_dfsu(filename: str | Path, data: Dataset) -> None:
"""
filename = str(filename)

# TODO warnings that this is not universally supported
# if not data.is_equidistant:
# raise ValueError("Non-equidistant time axis is not supported.")

dt = data.timestep
n_time_steps = len(data.time)

geometry = data.geometry
Expand All @@ -75,22 +70,16 @@ def write_dfsu(filename: str | Path, data: Dataset) -> None:
factory = DfsFactory()
proj = factory.CreateProjection(geometry.projection_string)
builder.SetProjection(proj)
# builder.SetTimeInfo(data.time[0], dt)

if data.is_equidistant:
if len(data.time) == 1:
dt = data.timestep
else:
dt = (data.time[1] - data.time[0]).total_seconds()

temporal_axis = factory.CreateTemporalEqCalendarAxis(
TimeStepUnit.SECOND, data.time[0], 0, dt
TimeStepUnit.SECOND, data.time[0], 0, data.timestep
)
else:
temporal_axis = factory.CreateTemporalNonEqCalendarAxis(
TimeStepUnit.SECOND, data.time[0]
)
builder.SetTemporalAxis(timeAxis=temporal_axis)
builder.SetTemporalAxis(temporal_axis)
builder.SetZUnit(eumUnit.eumUmeter)

if dfsu_filetype != DfsuFileType.Dfsu2D:
Expand Down Expand Up @@ -469,7 +458,7 @@ def read(

shape: Tuple[int, ...]

t_seconds = np.zeros(len(time_steps))
t_rel = np.zeros(len(time_steps))

n_steps = len(time_steps)
shape = (
Expand Down Expand Up @@ -497,7 +486,7 @@ def read(
error_bad_data=error_bad_data,
fill_bad_data_value=fill_bad_data_value,
)
t_seconds[i] = t
t_rel[i] = t

if elements is not None:
d = d[elements]
Expand All @@ -507,7 +496,7 @@ def read(
else:
data_list[item][i] = d

time = pd.to_datetime(t_seconds, unit="s", origin=self.start_time)
time = pd.to_datetime(t_rel, unit="s", origin=self.start_time)

dfs.Close()

Expand Down

0 comments on commit cf68173

Please sign in to comment.