Visualize(可视化) 模块¶
ppsci.visualize
¶
Visualizer
¶
Base class for visualizer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dict |
Dict[str, ndarray]
|
Input dict. |
required |
output_expr |
Dict[str, Callable]
|
Output expression. |
required |
batch_size |
int
|
Batch size of data when computing result in visu.py. |
required |
num_timestamps |
int
|
Number of timestamps. |
required |
prefix |
str
|
Prefix for output file. |
required |
Source code in ppsci/visualize/base.py
VisualizerScatter1D
¶
Bases: Visualizer
Visualizer for 1d scatter data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dict |
Dict[str, ndarray]
|
Input dict. |
required |
coord_keys |
Tuple[str, ...]
|
Coordinate keys, such as ("x", "y"). |
required |
output_expr |
Dict[str, Callable]
|
Output expression. |
required |
batch_size |
int
|
Batch size of data when computing result in visu.py. Defaults to 64. |
64
|
num_timestamps |
int
|
Number of timestamps. Defaults to 1. |
1
|
prefix |
str
|
Prefix for output file. Defaults to "plot". |
'plot'
|
Examples:
>>> import ppsci
>>> visu_mat = {"t_f": np.random.randn(16, 1), "eta": np.random.randn(16, 1)}
>>> visualizer_eta = ppsci.visualize.VisualizerScatter1D(
... visu_mat,
... ("t_f",),
... {"eta": lambda d: d["eta"]},
... num_timestamps=1,
... prefix="viv_pred",
... )
Source code in ppsci/visualize/visualizer.py
VisualizerScatter3D
¶
Bases: Visualizer
Visualizer for 3d scatter data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dict |
Dict[str, ndarray]
|
Input dict. |
required |
output_expr |
Dict[str, Callable]
|
Output expression. |
required |
batch_size |
int
|
Batch size of data when computing result in visu.py. Defaults to 64. |
64
|
num_timestamps |
int
|
Number of timestamps. Defaults to 1. |
1
|
prefix |
str
|
Prefix for output file. Defaults to "plot3d_scatter". |
'plot3d_scatter'
|
Examples:
>>> import ppsci
>>> vis_data = {"states": np.random.randn(16, 1)}
>>> visualizer = ppsci.visualize.VisualizerScatter3D(
... vis_data,
... {"states": lambda d: d["states"]},
... num_timestamps=1,
... prefix="result_states",
... )
Source code in ppsci/visualize/visualizer.py
VisualizerVtu
¶
Bases: Visualizer
Visualizer for 2D points data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dict |
Dict[str, ndarray]
|
Input dict. |
required |
output_expr |
Dict[str, Callable]
|
Output expression. |
required |
batch_size |
int
|
Batch size of data when computing result in visu.py. Defaults to 64. |
64
|
num_timestamps |
int
|
Number of timestamps |
1
|
prefix |
str
|
Prefix for output file. |
'vtu'
|
Examples:
>>> import ppsci
>>> vis_points = {
... "x": np.random.randn(128, 1),
... "y": np.random.randn(128, 1),
... "u": np.random.randn(128, 1),
... "v": np.random.randn(128, 1),
... }
>>> visualizer_u_v = ppsci.visualize.VisualizerVtu(
... vis_points,
... {"u": lambda d: d["u"], "v": lambda d: d["v"]},
... num_timestamps=1,
... prefix="result_u_v",
... )
Source code in ppsci/visualize/visualizer.py
Visualizer2D
¶
Bases: Visualizer
Visualizer for 2D data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dict |
Dict[str, ndarray]
|
Input dict. |
required |
output_expr |
Dict[str, Callable]
|
Output expression. |
required |
batch_size |
int
|
Batch size of data when computing result in visu.py. Defaults to 64. |
64
|
num_timestamps |
int
|
Number of timestamps. Defaults to 1. |
1
|
prefix |
str
|
Prefix for output file. Defaults to "plot2d". |
'plot2d'
|
Examples:
>>> import ppsci
>>> vis_points = {
... "x": np.random.randn(128, 1),
... "y": np.random.randn(128, 1),
... "u": np.random.randn(128, 1),
... "v": np.random.randn(128, 1),
... }
>>> visualizer_u_v = ppsci.visualize.Visualizer2D(
... vis_points,
... {"u": lambda d: d["u"], "v": lambda d: d["v"]},
... num_timestamps=1,
... prefix="result_u_v",
... )
Source code in ppsci/visualize/visualizer.py
Visualizer2DPlot
¶
Bases: Visualizer2D
Visualizer for 2D data use matplotlib.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dict |
Dict[str, ndarray]
|
Input dict. |
required |
output_expr |
Dict[str, Callable]
|
Output expression. |
required |
batch_size |
int
|
Batch size of data when computing result in visu.py. Defaults to 64. |
64
|
num_timestamps |
int
|
Number of timestamps. |
1
|
stride |
int
|
The time stride of visualization. Defaults to 1. |
1
|
xticks |
Optional[Tuple[float, ...]]
|
The list of xtick locations. Defaults to None. |
None
|
yticks |
Optional[Tuple[float, ...]]
|
The list of ytick locations. Defaults to None. |
None
|
prefix |
str
|
Prefix for output file. Defaults to "plot2d". |
'plot2d'
|
Examples:
>>> import ppsci
>>> vis_data = {
... "target_ux": np.random.randn(128, 20, 1),
... "pred_ux": np.random.randn(128, 20, 1),
... }
>>> visualizer_states = ppsci.visualize.Visualizer2DPlot(
... vis_data,
... {
... "target_ux": lambda d: d["states"][:, :, 0],
... "pred_ux": lambda d: output_transform(d)[:, :, 0],
... },
... batch_size=1,
... num_timestamps=10,
... stride=20,
... xticks=np.linspace(-2, 14, 9),
... yticks=np.linspace(-4, 4, 5),
... prefix="result_states",
... )
Source code in ppsci/visualize/visualizer.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
|
Visualizer3D
¶
Bases: Visualizer
Visualizer for 3D plot data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dict |
Dict[str, ndarray]
|
Input dict. |
required |
output_expr |
Dict[str, Callable]
|
Output expression. |
required |
batch_size |
int
|
Batch size of data when computing result in visu.py. Defaults to 64. |
64
|
label_dict |
Dict[str, ndarray]
|
Label dict. |
None
|
time_list |
Optional[Tuple[float, ...]]
|
Time list. |
None
|
prefix |
str
|
Prefix for output file. |
'vtu'
|
Source code in ppsci/visualize/visualizer.py
VisualizerWeather
¶
Bases: Visualizer
Visualizer for weather data use matplotlib.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dict |
Dict[str, ndarray]
|
Input dict. |
required |
output_expr |
Dict[str, Callable]
|
Output expression. |
required |
xticks |
Tuple[float, ...]
|
The list of xtick locations. |
required |
xticklabels |
Tuple[str, ...]
|
The x-axis' tick labels. |
required |
yticks |
Tuple[float, ...]
|
The list of ytick locations. |
required |
yticklabels |
Tuple[str, ...]
|
The y-axis' tick labels. |
required |
vmin |
float
|
Minimum value that the colormap covers. |
required |
vmax |
float
|
Maximal value that the colormap covers. |
required |
colorbar_label |
str
|
The color-bar label. Defaults to "". |
''
|
log_norm |
bool
|
Whether use log norm. Defaults to False. |
False
|
batch_size |
int
|
: Batch size of data when computing result in visu.py. Defaults to 1. |
1
|
num_timestamps |
int
|
Number of timestamps. Defaults to 1. |
1
|
prefix |
str
|
Prefix for output file. Defaults to "plot_weather". |
'plot_weather'
|
Examples:
>>> import ppsci
>>> import numpy as np
>>> vis_data = {
... "output_6h": np.random.randn(1, 720, 1440),
... "target_6h": np.random.randn(1, 720, 1440),
... }
>>> visualizer_weather = ppsci.visualize.VisualizerWeather(
... vis_data,
... {
... "output_6h": lambda d: d["output_6h"],
... "target_6h": lambda d: d["target_6h"],
... },
... xticks=np.linspace(0, 1439, 13),
... xticklabels=[str(i) for i in range(360, -1, -30)],
... yticks=np.linspace(0, 719, 7),
... yticklabels=[str(i) for i in range(90, -91, -30)],
... vmin=0,
... vmax=25,
... prefix="result_states",
... )
Source code in ppsci/visualize/visualizer.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
|
VisualizerRadar
¶
Bases: Visualizer
Visualizer for NowcastNet Radar Dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dict |
Dict[str, ndarray]
|
Input dict. |
required |
output_expr |
Dict[str, Callable]
|
Output expression. |
required |
batch_size |
int
|
Batch size of data when computing result in visu.py. Defaults to 64. |
64
|
num_timestamps |
int
|
Number of timestamps |
1
|
prefix |
str
|
Prefix for output file. |
'vtu'
|
case_type |
str
|
Case type. |
'normal'
|
total_length |
str
|
Total length. |
29
|
Examples:
>>> import ppsci
>>> import paddle
>>> frames_tensor = paddle.randn([1, 29, 512, 512, 2])
>>> visualizer = ppsci.visualize.VisualizerRadar(
... {"input": frames_tensor},
... {"output": lambda out: out["output"]},
... num_timestamps=1,
... prefix="v_nowcastnet",
... )
Source code in ppsci/visualize/radar.py
save_vtu_from_dict(filename, data_dict, coord_keys, value_keys, num_timestamps=1)
¶
Save dict data to '*.vtu' file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
Output filename. |
required |
data_dict |
Dict[str, ndarray]
|
Data in dict. |
required |
coord_keys |
Tuple[str, ...]
|
Tuple of coord key. such as ("x", "y"). |
required |
value_keys |
Tuple[str, ...]
|
Tuple of value key. such as ("u", "v"). |
required |
num_timestamps |
int
|
Number of timestamp in data_dict. Defaults to 1. |
1
|
Examples:
>>> import ppsci
>>> import numpy as np
>>> filename = "path/to/file.vtu"
>>> data_dict = {
... "x": np.array([[1], [2], [3],[4]]),
... "y": np.array([[2], [3], [4],[4]]),
... "z": np.array([[3], [4], [5],[4]]),
... "u": np.array([[4], [5], [6],[4]]),
... "v": np.array([[5], [6], [7],[4]]),
... }
>>> coord_keys = ("x","y","z")
>>> value_keys = ("u","v")
>>> ppsci.visualize.save_vtu_from_dict(filename, data_dict, coord_keys, value_keys)
Source code in ppsci/visualize/vtu.py
save_vtu_to_mesh(filename, data_dict, coord_keys, value_keys)
¶
Save data into .vtu format by meshio.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
File name. |
required |
data_dict |
Dict[str, ndarray]
|
Data in dict. |
required |
coord_keys |
Tuple[str, ...]
|
Tuple of coord key. such as ("x", "y"). |
required |
value_keys |
Tuple[str, ...]
|
Tuple of value key. such as ("u", "v"). |
required |
Examples:
>>> import ppsci
>>> import numpy as np
>>> filename = "path/to/file.vtu"
>>> data_dict = {
... "x": np.array([[1], [2], [3],[4]]),
... "y": np.array([[2], [3], [4],[4]]),
... "z": np.array([[3], [4], [5],[4]]),
... "u": np.array([[4], [5], [6],[4]]),
... "v": np.array([[5], [6], [7],[4]]),
... }
>>> coord_keys = ("x","y","z")
>>> value_keys = ("u","v")
>>> ppsci.visualize.save_vtu_to_mesh(filename, data_dict, coord_keys, value_keys)
Source code in ppsci/visualize/vtu.py
save_plot_from_1d_dict(filename, data_dict, coord_keys, value_keys, num_timestamps=1)
¶
Plot dict data as file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
Output filename. |
required |
data_dict |
Dict[str, Union[ndarray, Tensor]]
|
Data in dict. |
required |
coord_keys |
Tuple[str, ...]
|
Tuple of coord key. such as ("x", "y"). |
required |
value_keys |
Tuple[str, ...]
|
Tuple of value key. such as ("u", "v"). |
required |
num_timestamps |
int
|
Number of timestamp in data_dict. Defaults to 1. |
1
|
Examples:
>>> import ppsci
>>> import numpy as np
>>> filename = "path/to/file"
>>> data_dict = {
... "x": np.array([[1], [2], [3],[4]]),
... "u": np.array([[4], [5], [6],[4]]),
... }
>>> coord_keys = ("x",)
>>> value_keys = ("u",)
>>> ppsci.visualize.save_plot_from_1d_dict(filename, data_dict, coord_keys, value_keys)
Source code in ppsci/visualize/plot.py
save_plot_from_3d_dict(filename, data_dict, visu_keys, num_timestamps=1)
¶
Plot dict data as file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
Output filename. |
required |
data_dict |
Dict[str, Union[ndarray, Tensor]]
|
Data in dict. |
required |
visu_keys |
Tuple[str, ...]
|
Keys for visualizing data. such as ("u", "v"). |
required |
num_timestamps |
int
|
Number of timestamp in data_dict. Defaults to 1. |
1
|
Examples:
>>> data_dict = {
... "u": np.array([[[10], [20], [30], [40], [50]]]),
... "v": np.array([[[5], [15], [25], [35], [45]]]),
... }
>>> ppsci.visualize.save_plot_from_3d_dict(
... "path/to/file",
... data_dict,
... ("u", "v"),
... 1,
... )