Utils.writer(文件保存函数) 模块¶
ppsci.utils.writer
¶
save_csv_file(filename, data_dict, keys, alias_dict=None, use_header=True, delimiter=',', encoding='utf-8')
¶
Write numpy or tensor data into csv file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
Dump file path. |
required |
data_dict |
Dict[str, Union[ndarray, Tensor]]
|
Numpy or tensor data in dict. |
required |
keys |
Tuple[str, ...]
|
Keys for data_dict to be fetched. |
required |
alias_dict |
Optional[Dict[str, str]]
|
Alias dict for keys, i.e. {dump_key: dict_key}. Defaults to None. |
None
|
use_header |
bool
|
Whether save csv with header. Defaults to True. |
True
|
delimiter |
str
|
Delemiter for splitting different data field. Defaults to ",". |
','
|
encoding |
str
|
Encoding. Defaults to "utf-8". |
'utf-8'
|
Examples:
>>> import numpy as np
>>> from ppsci.utils import save_csv_file
>>> data_dict = {
... "a": np.array([[1], [2], [3]]).astype("int64"), # [3, 1]
... "b": np.array([[4.12], [5.25], [6.3370]]).astype("float32"), # [3, 1]
... }
>>> save_csv_file(
... "test.csv",
... data_dict,
... ("A", "B"),
... alias_dict={"A": "a", "B": "b"},
... use_header=True,
... delimiter=",",
... encoding="utf-8",
... )
Source code in ppsci/utils/writer.py
save_tecplot_file(filename, data_dict, keys, num_x, num_y, alias_dict=None, delimiter=' ', encoding='utf-8', num_timestamps=1)
¶
Write numpy or tensor data into tecplot file(s).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
Tecplot file path. |
required |
data_dict |
Dict[str, Union[ndarray, Tensor]]
|
Numpy or Tensor data in dict. |
required |
keys |
Tuple[str, ...]
|
Target keys to be dumped. |
required |
num_x |
int
|
The number of discrete points of the grid in the X-axis. Assuming the discrete grid size is 20 x 30, then num_x=20. |
required |
num_y |
int
|
The number of discrete points of the grid in the Y-axis. Assuming the discrete grid size is 20 x 30, then num_y=30. |
required |
alias_dict |
Optional[Dict[str, str]]
|
Alias dict for keys, i.e. {dump_key: dict_key}. Defaults to None. |
None
|
delimiter |
str
|
Delemiter for splitting different data field. Defaults to " ". |
' '
|
encoding |
str
|
Encoding. Defaults to "utf-8". |
'utf-8'
|
num_timestamps |
int
|
Number of timestamp over coord and value. Defaults to 1. |
1
|
Examples:
>>> import numpy as np
>>> from ppsci.utils import save_tecplot_file
>>> data_dict = {
... "x": np.array([[-1.0], [-1.0], [-1.0], [-1.0], [-1.0], [-1.0]]), # [6, 1]
... "y": np.array([[1.0], [2.0], [3.0], [1.0], [2.0], [3.0]]), # [6, 1]
... "value": np.array([[3], [33], [333], [3333], [33333], [333333]]), # [6, 1]
... }
>>> save_tecplot_file(
... "./test.dat",
... data_dict,
... ("X", "Y", "value"),
... num_x=1,
... num_y=3,
... alias_dict={"X": "x", "Y": "y"},
... num_timestamps=2,
... )
>>> # == test_t-0.dat ==
>>> # title = "./test_t-0.dat"
>>> # variables = "X", "Y"
>>> # Zone I = 3, J = 1, F = POINT
>>> # -1.0 1.0 3.0
>>> # -1.0 2.0 33.0
>>> # -1.0 3.0 333.0
>>> # == test_t-1.dat ==
>>> # title = "./test_t-1.dat"
>>> # variables = "X", "Y"
>>> # Zone I = 3, J = 1, F = POINT
>>> # -1.0 1.0 3333.0
>>> # -1.0 2.0 33333.0
>>> # -1.0 3.0 333333.0
Source code in ppsci/utils/writer.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
|