Skip to content

Commit 81bcd6a

Browse files
authored
Copy duplicate frames rather than rerendering so progress tracker starts sooner (#276)
1 parent 023af7c commit 81bcd6a

File tree

1 file changed

+36
-22
lines changed

1 file changed

+36
-22
lines changed

src/data_morph/morpher.py

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import shutil
56
from contextlib import nullcontext
67
from functools import partial
78
from numbers import Number
@@ -223,31 +224,44 @@ def _record_frames(
223224
int
224225
The next frame number available for recording.
225226
"""
226-
if self.write_images or self.write_data:
227+
if (self.write_images or self.write_data) and count > 0:
227228
is_start = frame_number == 0
228-
for _ in range(count):
229-
if self.write_images:
230-
plot(
231-
data,
232-
save_to=(
229+
img_file = (
230+
self.output_dir / f'{base_file_name}-image-{frame_number:03d}.png'
231+
)
232+
data_file = (
233+
self.output_dir / f'{base_file_name}-data-{frame_number:03d}.csv'
234+
)
235+
if self.write_images:
236+
plot(
237+
data,
238+
save_to=img_file,
239+
decimals=self.decimals,
240+
x_bounds=bounds.x_bounds,
241+
y_bounds=bounds.y_bounds,
242+
dpi=150,
243+
)
244+
if (
245+
self.write_data and not is_start
246+
): # don't write data for the initial frame (input data)
247+
data.to_csv(data_file, index=False)
248+
frame_number += 1
249+
if (duplicate_count := count - 1) > 0:
250+
for _ in range(duplicate_count):
251+
if data_file.exists():
252+
shutil.copy(
253+
data_file,
233254
self.output_dir
234-
/ f'{base_file_name}-image-{frame_number:03d}.png'
235-
),
236-
decimals=self.decimals,
237-
x_bounds=bounds.x_bounds,
238-
y_bounds=bounds.y_bounds,
239-
dpi=150,
240-
)
241-
if (
242-
self.write_data and not is_start
243-
): # don't write data for the initial frame (input data)
244-
data.to_csv(
245-
self.output_dir
246-
/ f'{base_file_name}-data-{frame_number:03d}.csv',
247-
index=False,
248-
)
255+
/ f'{base_file_name}-data-{frame_number:03d}.csv',
256+
)
257+
if img_file.exists():
258+
shutil.copy(
259+
img_file,
260+
self.output_dir
261+
/ f'{base_file_name}-image-{frame_number:03d}.png',
262+
)
263+
frame_number += 1
249264

250-
frame_number += 1
251265
return frame_number
252266

253267
def _is_close_enough(self, df1: pd.DataFrame, df2: pd.DataFrame) -> bool:

0 commit comments

Comments
 (0)