Skip to content

Commit d7e20df

Browse files
rename 'num_timestamp' to 'num_timestamps'
1 parent 6319d55 commit d7e20df

File tree

4 files changed

+60
-60
lines changed

4 files changed

+60
-60
lines changed

ppsci/geometry/timedomain.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ def __init__(
6464
if time_step is not None:
6565
if time_step <= 0:
6666
raise ValueError(f"time_step({time_step}) must be larger than 0.")
67-
self.num_timestamp = int(np.ceil((t1 - t0) / time_step)) + 1
67+
self.num_timestamps = int(np.ceil((t1 - t0) / time_step)) + 1
6868
elif timestamps is not None:
69-
self.num_timestamp = len(timestamps)
69+
self.num_timestamps = len(timestamps)
7070

7171
def on_initial(self, t):
7272
return np.isclose(t, self.t0).flatten()
@@ -120,7 +120,7 @@ def uniform_points(self, n, boundary=True):
120120
nx = int(np.ceil(n / nt))
121121
elif self.timedomain.timestamps is not None:
122122
# exclude start time t0
123-
nt = self.timedomain.num_timestamp - 1
123+
nt = self.timedomain.num_timestamps - 1
124124
nx = int(np.ceil(n / nt))
125125
else:
126126
nx = int(
@@ -216,7 +216,7 @@ def random_points(self, n, random="pseudo", criteria=None):
216216
tx = tx[:n]
217217
return tx
218218
elif self.timedomain.timestamps is not None:
219-
nt = self.timedomain.num_timestamp - 1
219+
nt = self.timedomain.num_timestamps - 1
220220
t = self.timedomain.timestamps[1:]
221221
nx = int(np.ceil(n / nt))
222222

@@ -431,7 +431,7 @@ def random_boundary_points(self, n, random="pseudo", criteria=None):
431431
return t_x
432432
elif self.timedomain.timestamps is not None:
433433
# exclude start time t0
434-
nt = self.timedomain.num_timestamp - 1
434+
nt = self.timedomain.num_timestamps - 1
435435
t = self.timedomain.timestamps[1:]
436436
nx = int(np.ceil(n / nt))
437437

ppsci/validate/geo_validator.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,19 @@ def __init__(
9292
self.output_keys = list(label_dict.keys())
9393

9494
nx = dataloader_cfg["total_size"]
95-
self.num_timestamp = 1
95+
self.num_timestamps = 1
9696
# TODO(sensen): simplify code below
9797
if isinstance(geom, geometry.TimeXGeometry):
98-
if geom.timedomain.num_timestamp is not None:
98+
if geom.timedomain.num_timestamps is not None:
9999
if with_initial:
100100
# include t0
101-
self.num_timestamp = geom.timedomain.num_timestamp
101+
self.num_timestamps = geom.timedomain.num_timestamps
102102
assert (
103-
nx % self.num_timestamp == 0
104-
), f"{nx} % {self.num_timestamp} != 0"
105-
nx //= self.num_timestamp
103+
nx % self.num_timestamps == 0
104+
), f"{nx} % {self.num_timestamps} != 0"
105+
nx //= self.num_timestamps
106106
input = geom.sample_interior(
107-
nx * (geom.timedomain.num_timestamp - 1),
107+
nx * (geom.timedomain.num_timestamps - 1),
108108
random,
109109
criteria,
110110
evenly,
@@ -115,13 +115,13 @@ def __init__(
115115
}
116116
else:
117117
# exclude t0
118-
self.num_timestamp = geom.timedomain.num_timestamp - 1
118+
self.num_timestamps = geom.timedomain.num_timestamps - 1
119119
assert (
120-
nx % self.num_timestamp == 0
121-
), f"{nx} % {self.num_timestamp} != 0"
122-
nx //= self.num_timestamp
120+
nx % self.num_timestamps == 0
121+
), f"{nx} % {self.num_timestamps} != 0"
122+
nx //= self.num_timestamps
123123
input = geom.sample_interior(
124-
nx * (geom.timedomain.num_timestamp - 1),
124+
nx * (geom.timedomain.num_timestamps - 1),
125125
random,
126126
criteria,
127127
evenly,

ppsci/visualize/plot.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,21 @@
6666
]
6767

6868

69-
def _save_plot_from_1d_array(filename, coord, value, value_keys, num_timestamp=1):
69+
def _save_plot_from_1d_array(filename, coord, value, value_keys, num_timestamps=1):
7070
"""Save plot from given 1D data.
7171
7272
Args:
7373
filename (str): Filename.
7474
coord (np.ndarray): Coordinate array.
7575
value (Dict[str, np.ndarray]): Dict of value array.
7676
value_keys (Tuple[str, ...]): Value keys.
77-
num_timestamp (int, optional): Number of timestamps coord/value contains. Defaults to 1.
77+
num_timestamps (int, optional): Number of timestamps coord/value contains. Defaults to 1.
7878
"""
79-
fig, a = plt.subplots(len(value_keys), num_timestamp, squeeze=False)
79+
fig, a = plt.subplots(len(value_keys), num_timestamps, squeeze=False)
8080
fig.subplots_adjust(hspace=0.8)
8181

82-
len_ts = len(coord) // num_timestamp
83-
for t in range(num_timestamp):
82+
len_ts = len(coord) // num_timestamps
83+
for t in range(num_timestamps):
8484
st = t * len_ts
8585
ed = (t + 1) * len_ts
8686
coord_t = coord[st:ed]
@@ -93,29 +93,29 @@ def _save_plot_from_1d_array(filename, coord, value, value_keys, num_timestamp=1
9393
color=cnames[i],
9494
label=key,
9595
)
96-
if num_timestamp > 1:
96+
if num_timestamps > 1:
9797
a[i][t].set_title(f"{key}(t={t})")
9898
else:
9999
a[i][t].set_title(f"{key}")
100100
a[i][t].grid()
101101
a[i][t].legend()
102102

103-
if num_timestamp == 1:
103+
if num_timestamps == 1:
104104
fig.savefig(filename, dpi=300)
105105
else:
106106
fig.savefig(f"{filename}_{t}", dpi=300)
107107

108-
if num_timestamp == 1:
108+
if num_timestamps == 1:
109109
logger.info(f"1D result is saved to {filename}.png")
110110
else:
111111
logger.info(
112112
f"1D result is saved to {filename}_0.png"
113-
f" ~ {filename}_{num_timestamp - 1}.png"
113+
f" ~ {filename}_{num_timestamps - 1}.png"
114114
)
115115

116116

117117
def save_plot_from_1d_dict(
118-
filename, data_dict, coord_keys, value_keys, num_timestamp=1
118+
filename, data_dict, coord_keys, value_keys, num_timestamps=1
119119
):
120120
"""Plot dict data as file.
121121
@@ -124,7 +124,7 @@ def save_plot_from_1d_dict(
124124
data_dict (Dict[str, Union[np.ndarray, paddle.Tensor]]): Data in dict.
125125
coord_keys (Tuple[str, ...]): Tuple of coord key. such as ("x", "y").
126126
value_keys (Tuple[str, ...]): Tuple of value key. such as ("u", "v").
127-
num_timestamp (int, optional): Number of timestamp in data_dict. Defaults to 1.
127+
num_timestamps (int, optional): Number of timestamp in data_dict. Defaults to 1.
128128
"""
129129
space_ndim = len(coord_keys) - int("t" in coord_keys)
130130
if space_ndim not in [1, 2, 3]:
@@ -146,14 +146,14 @@ def save_plot_from_1d_dict(
146146
value = [x for x in value]
147147
value = np.concatenate(value, axis=1)
148148

149-
_save_plot_from_1d_array(filename, coord, value, value_keys, num_timestamp)
149+
_save_plot_from_1d_array(filename, coord, value, value_keys, num_timestamps)
150150

151151

152152
def _save_plot_from_2d_array(
153153
filename: str,
154154
visu_data: Tuple[np.ndarray, ...],
155155
visu_keys: Tuple[str, ...],
156-
num_timestamp: int = 1,
156+
num_timestamps: int = 1,
157157
stride: int = 1,
158158
xticks: Optional[Tuple[float, ...]] = None,
159159
yticks: Optional[Tuple[float, ...]] = None,
@@ -164,7 +164,7 @@ def _save_plot_from_2d_array(
164164
filename (str): Filename.
165165
visu_data (Tuple[np.ndarray, ...]): Data that requires visualization.
166166
visu_keys (Tuple[str, ...]]): Keys for visualizing data. such as ("u", "v").
167-
num_timestamp (int, optional): Number of timestamps coord/value contains. Defaults to 1.
167+
num_timestamps (int, optional): Number of timestamps coord/value contains. Defaults to 1.
168168
stride (int, optional): The time stride of visualization. Defaults to 1.
169169
xticks (Optional[Tuple[float, ...]]): Tuple of xtick locations. Defaults to None.
170170
yticks (Optional[Tuple[float, ...]]): Tuple of ytick locations. Defaults to None.
@@ -176,10 +176,10 @@ def _save_plot_from_2d_array(
176176

177177
fig, ax = plt.subplots(
178178
len(visu_keys),
179-
num_timestamp,
179+
num_timestamps,
180180
squeeze=False,
181181
sharey=True,
182-
figsize=(num_timestamp, len(visu_keys)),
182+
figsize=(num_timestamps, len(visu_keys)),
183183
)
184184
fig.subplots_adjust(hspace=0.3)
185185
target_flag = any(["target" in key for key in visu_keys])
@@ -188,7 +188,7 @@ def _save_plot_from_2d_array(
188188
c_max = np.amax(data)
189189
c_min = np.amin(data)
190190

191-
for t_idx in range(num_timestamp):
191+
for t_idx in range(num_timestamps):
192192
t = t_idx * stride
193193
ax[i, t_idx].imshow(
194194
data[t, :, :],
@@ -223,7 +223,7 @@ def save_plot_from_2d_dict(
223223
filename: str,
224224
data_dict: Dict[str, Union[np.ndarray, paddle.Tensor]],
225225
visu_keys: Tuple[str, ...],
226-
num_timestamp: int = 1,
226+
num_timestamps: int = 1,
227227
stride: int = 1,
228228
xticks: Optional[Tuple[float, ...]] = None,
229229
yticks: Optional[Tuple[float, ...]] = None,
@@ -234,7 +234,7 @@ def save_plot_from_2d_dict(
234234
filename (str): Output filename.
235235
data_dict (Dict[str, Union[np.ndarray, paddle.Tensor]]): Data in dict.
236236
visu_keys (Tuple[str, ...]): Keys for visualizing data. such as ("u", "v").
237-
num_timestamp (int, optional): Number of timestamp in data_dict. Defaults to 1.
237+
num_timestamps (int, optional): Number of timestamp in data_dict. Defaults to 1.
238238
stride (int, optional): The time stride of visualization. Defaults to 1.
239239
xticks (Optional[Tuple[float,...]]): The list of xtick locations. Defaults to None.
240240
yticks (Optional[Tuple[float,...]]): The list of ytick locations. Defaults to None.
@@ -243,7 +243,7 @@ def save_plot_from_2d_dict(
243243
if isinstance(visu_data[0], paddle.Tensor):
244244
visu_data = [x.numpy() for x in visu_data]
245245
_save_plot_from_2d_array(
246-
filename, visu_data, visu_keys, num_timestamp, stride, xticks, yticks
246+
filename, visu_data, visu_keys, num_timestamps, stride, xticks, yticks
247247
)
248248

249249

@@ -305,21 +305,21 @@ def _save_plot_from_3d_array(
305305
filename: str,
306306
visu_data: Tuple[np.ndarray, ...],
307307
visu_keys: Tuple[str, ...],
308-
num_timestamp: int = 1,
308+
num_timestamps: int = 1,
309309
):
310310
"""Save plot from given 3D data.
311311
312312
Args:
313313
filename (str): Filename.
314314
visu_data (Tuple[np.ndarray, ...]): Data that requires visualization.
315315
visu_keys (Tuple[str, ...]]): Keys for visualizing data. such as ("u", "v").
316-
num_timestamp (int, optional): Number of timestamps coord/value contains. Defaults to 1.
316+
num_timestamps (int, optional): Number of timestamps coord/value contains. Defaults to 1.
317317
"""
318318

319319
fig = plt.figure(figsize=(10, 10))
320-
len_ts = len(visu_data[0]) // num_timestamp
321-
for t in range(num_timestamp):
322-
ax = fig.add_subplot(1, num_timestamp, t + 1, projection="3d")
320+
len_ts = len(visu_data[0]) // num_timestamps
321+
for t in range(num_timestamps):
322+
ax = fig.add_subplot(1, num_timestamps, t + 1, projection="3d")
323323
st = t * len_ts
324324
ed = (t + 1) * len_ts
325325
visu_data_t = [data[st:ed] for data in visu_data]
@@ -340,37 +340,37 @@ def _save_plot_from_3d_array(
340340
loc="upper right",
341341
framealpha=0.95,
342342
)
343-
if num_timestamp == 1:
343+
if num_timestamps == 1:
344344
fig.savefig(filename, dpi=300)
345345
else:
346346
fig.savefig(f"{filename}_{t}", dpi=300)
347347

348-
if num_timestamp == 1:
348+
if num_timestamps == 1:
349349
logger.info(f"3D result is saved to {filename}.png")
350350
else:
351351
logger.info(
352352
f"3D result is saved to {filename}_0.png"
353-
f" ~ {filename}_{num_timestamp - 1}.png"
353+
f" ~ {filename}_{num_timestamps - 1}.png"
354354
)
355355

356356

357357
def save_plot_from_3d_dict(
358358
filename: str,
359359
data_dict: Dict[str, Union[np.ndarray, paddle.Tensor]],
360360
visu_keys: Tuple[str, ...],
361-
num_timestamp: int = 1,
361+
num_timestamps: int = 1,
362362
):
363363
"""Plot dict data as file.
364364
365365
Args:
366366
filename (str): Output filename.
367367
data_dict (Dict[str, Union[np.ndarray, paddle.Tensor]]): Data in dict.
368368
visu_keys (Tuple[str, ...]): Keys for visualizing data. such as ("u", "v").
369-
num_timestamp (int, optional): Number of timestamp in data_dict. Defaults to 1.
369+
num_timestamps (int, optional): Number of timestamp in data_dict. Defaults to 1.
370370
"""
371371

372372
visu_data = [data_dict[k] for k in visu_keys]
373373
if isinstance(visu_data[0], paddle.Tensor):
374374
visu_data = [x.numpy() for x in visu_data]
375375

376-
_save_plot_from_3d_array(filename, visu_data, visu_keys, num_timestamp)
376+
_save_plot_from_3d_array(filename, visu_data, visu_keys, num_timestamps)

ppsci/visualize/vtu.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
from ppsci.utils import logger
2020

2121

22-
def _save_vtu_from_array(filename, coord, value, value_keys, num_timestamp=1):
22+
def _save_vtu_from_array(filename, coord, value, value_keys, num_timestamps=1):
2323
"""Save data to '*.vtu' file(s).
2424
2525
Args:
2626
filename (str): Output filename.
2727
coord (np.ndarray): Coordinate points with shape of [N, 2] or [N, 3].
2828
value (np.ndarray): Value of each coord points with shape of [N, M].
2929
value_keys (Tuple[str, ...]): Names of each dimension of value, such as ("u", "v").
30-
num_timestamp (int, optional): Number of timestamp over coord and value.
30+
num_timestamps (int, optional): Number of timestamp over coord and value.
3131
Defaults to 1.
3232
"""
3333
if not isinstance(coord, np.ndarray):
@@ -38,10 +38,10 @@ def _save_vtu_from_array(filename, coord, value, value_keys, num_timestamp=1):
3838
raise ValueError(
3939
f"coord length({len(coord)}) should be equal to value length({len(value)})"
4040
)
41-
if len(coord) % num_timestamp != 0:
41+
if len(coord) % num_timestamps != 0:
4242
raise ValueError(
4343
f"coord length({len(coord)}) should be an integer multiple of "
44-
f"num_timestamp({num_timestamp})"
44+
f"num_timestamps({num_timestamps})"
4545
)
4646
if coord.shape[1] not in [2, 3]:
4747
raise ValueError(f"ndim of coord({coord.shape[1]}) should be 2 or 3.")
@@ -57,8 +57,8 @@ def _save_vtu_from_array(filename, coord, value, value_keys, num_timestamp=1):
5757
value_keys = ["dummy_key"]
5858

5959
data_ndim = value.shape[1]
60-
nx = npoint // num_timestamp
61-
for t in range(num_timestamp):
60+
nx = npoint // num_timestamps
61+
for t in range(num_timestamps):
6262
# NOTE: each array in data_vtu should be 1-dim, i.e. [N, 1] will occur error.
6363
if coord_ndim == 2:
6464
axis_x = np.ascontiguousarray(coord[t * nx : (t + 1) * nx, 0])
@@ -75,28 +75,28 @@ def _save_vtu_from_array(filename, coord, value, value_keys, num_timestamp=1):
7575
value[t * nx : (t + 1) * nx, j]
7676
)
7777

78-
if num_timestamp > 1:
78+
if num_timestamps > 1:
7979
hl.pointsToVTK(f"{filename}_t-{t}", axis_x, axis_y, axis_z, data=data_vtu)
8080
else:
8181
hl.pointsToVTK(filename, axis_x, axis_y, axis_z, data=data_vtu)
8282

83-
if num_timestamp > 1:
83+
if num_timestamps > 1:
8484
logger.info(
85-
f"Visualization results are saved to {filename}_t-0 ~ {filename}_t-{num_timestamp - 1}"
85+
f"Visualization results are saved to {filename}_t-0 ~ {filename}_t-{num_timestamps - 1}"
8686
)
8787
else:
8888
logger.info(f"Visualization result is saved to {filename}")
8989

9090

91-
def save_vtu_from_dict(filename, data_dict, coord_keys, value_keys, num_timestamp=1):
91+
def save_vtu_from_dict(filename, data_dict, coord_keys, value_keys, num_timestamps=1):
9292
"""Save dict data to '*.vtu' file.
9393
9494
Args:
9595
filename (str): Output filename.
9696
data_dict (Dict[str, Union[np.ndarray, paddle.Tensor]]): Data in dict.
9797
coord_keys (Tuple[str, ...]): Tuple of coord key. such as ("x", "y").
9898
value_keys (Tuple[str, ...]): Tuple of value key. such as ("u", "v").
99-
num_timestamp (int, optional): Number of timestamp in data_dict. Defaults to 1.
99+
num_timestamps (int, optional): Number of timestamp in data_dict. Defaults to 1.
100100
"""
101101
if len(coord_keys) not in [2, 3, 4]:
102102
raise ValueError(f"ndim of coord ({len(coord_keys)}) should be 2, 3 or 4")
@@ -117,4 +117,4 @@ def save_vtu_from_dict(filename, data_dict, coord_keys, value_keys, num_timestam
117117
value = [x for x in value]
118118
value = np.concatenate(value, axis=1)
119119

120-
_save_vtu_from_array(filename, coord, value, value_keys, num_timestamp)
120+
_save_vtu_from_array(filename, coord, value, value_keys, num_timestamps)

0 commit comments

Comments
 (0)