-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoperations.py
65 lines (46 loc) · 1.72 KB
/
operations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from .data_structs.dataset import Snapshot
def to_cartesian(data):
''' convert to cartesian coordinate system
Currently only support converting:
grids['x1']
grids['x2']
grids['x3']
fields['vx1']
fields['vx2']
fields['vx3']
Args:
data (Snapshot): data needed to be converted geometry
Returns:
Snapshot: new Snapshot is as the same as the older one,
except for grids and velocity arrays have been transformed to cartesian system
'''
ds = data
ds.grids['x1'], ds.grids['x2'], ds.grids['x3'] = data.grids.to_cartesian()
ds.fields['vx1'], ds.fields['vx2'], ds.fields['vx3'] = data.fields.to_cartesian()
return ds
def slice2d(data, x1=None, x2=None, x3=None):
''' Slice all 3-D field arrays in original data return 2-D
coordinate of one dimension should be specified
Args:
data (Snapshot): 3-D data
x1 (float): rough coordinate (optional)
x2 (float): rough coordinate (optional)
x3 (float): rough coordinate (optional)
'''
if not type(data) is Snapshot:
raise TypeError(f'The input data is a {type(data)}, it should be Snapshot class!')
for var in data.field_list:
data.fields[var] = data.slice2d(var, x1=x1, x2=x3, x3=x3)
def slice1d(data, x1=None, x2=None, x3=None):
''' Slice all 3-D fields array in original data return 1-D
coordinates of two dimensions should be specified
Args:
data (Snapshot): 3-D data
x1 (float): rough coordinate (optional)
x2 (float): rough coordinate (optional)
x3 (float): rough coordinate (optional)
'''
if not type(data) is Snapshot:
raise TypeError('The input data should be Snapshot class!')
for var in data.field_list:
data.fields[var] = data.slice1d(var, x1=x1, x2=x3, x3=x3)