Skip to content

Commit 325371d

Browse files
committed
Use FieldXmf.field_subdomains in read_field_h5
1 parent 118308e commit 325371d

File tree

1 file changed

+35
-41
lines changed

1 file changed

+35
-41
lines changed

stagpy/stagyyparsers.py

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,47 +1089,41 @@ def read_field_h5(
10891089
flds = np.zeros(_flds_shape(fieldname, header))
10901090
data_found = False
10911091

1092-
for elt_subdomain in xdmf.get_snap(snapshot).findall("Grid"):
1093-
elt_name = _try_get(xdmf.path, elt_subdomain, "Name")
1094-
ibk = int(elt_name.startswith("meshYang"))
1095-
for data_attr in elt_subdomain.findall("Attribute"):
1096-
if data_attr.get("Name") != fieldname:
1097-
continue
1098-
icore, fld = _get_field(
1099-
xdmf.path, _try_find(xdmf.path, data_attr, "DataItem")
1100-
)
1101-
# for some reason, the field is transposed
1102-
fld = fld.T
1103-
shp = fld.shape
1104-
if shp[-1] == 1 and header["nts"][0] == 1: # YZ
1105-
fld = fld.reshape((shp[0], 1, shp[1], shp[2]))
1106-
if header["rcmb"] < 0:
1107-
fld = fld[(2, 0, 1), ...]
1108-
elif shp[-1] == 1: # XZ
1109-
fld = fld.reshape((shp[0], shp[1], 1, shp[2]))
1110-
if header["rcmb"] < 0:
1111-
fld = fld[(1, 2, 0), ...]
1112-
elif fieldname in SFIELD_FILES_H5:
1113-
fld = fld.reshape((1, npc[0], npc[1], 1))
1114-
elif header["nts"][1] == 1: # cart XZ
1115-
fld = fld.reshape((1, shp[0], 1, shp[1]))
1116-
ifs = [
1117-
icore // np.prod(header["ncs"][:i]) % header["ncs"][i] * npc[i]
1118-
for i in range(3)
1119-
]
1120-
if fieldname in SFIELD_FILES_H5:
1121-
ifs[2] = 0
1122-
npc[2] = 1
1123-
if header["zp"]: # remove top row
1124-
fld = fld[:, :, :, :-1]
1125-
flds[
1126-
:,
1127-
ifs[0] : ifs[0] + npc[0] + header["xp"],
1128-
ifs[1] : ifs[1] + npc[1] + header["yp"],
1129-
ifs[2] : ifs[2] + npc[2],
1130-
ibk,
1131-
] = fld
1132-
data_found = True
1092+
for fsub in xdmf[snapshot].field_subdomains(xdmf.path.parent, fieldname):
1093+
fld = _read_group_h5(fsub.file, fsub.dataset).reshape(fsub.shape)
1094+
# for some reason, the field is transposed
1095+
fld = fld.T
1096+
shp = fld.shape
1097+
1098+
if shp[-1] == 1 and header["nts"][0] == 1: # YZ
1099+
fld = fld.reshape((shp[0], 1, shp[1], shp[2]))
1100+
if header["rcmb"] < 0:
1101+
fld = fld[(2, 0, 1), ...]
1102+
elif shp[-1] == 1: # XZ
1103+
fld = fld.reshape((shp[0], shp[1], 1, shp[2]))
1104+
if header["rcmb"] < 0:
1105+
fld = fld[(1, 2, 0), ...]
1106+
elif fieldname in SFIELD_FILES_H5:
1107+
fld = fld.reshape((1, npc[0], npc[1], 1))
1108+
elif header["nts"][1] == 1: # cart XZ
1109+
fld = fld.reshape((1, shp[0], 1, shp[1]))
1110+
ifs = [
1111+
fsub.icore // np.prod(header["ncs"][:i]) % header["ncs"][i] * npc[i]
1112+
for i in range(3)
1113+
]
1114+
if fieldname in SFIELD_FILES_H5:
1115+
ifs[2] = 0
1116+
npc[2] = 1
1117+
if header["zp"]: # remove top row
1118+
fld = fld[:, :, :, :-1]
1119+
flds[
1120+
:,
1121+
ifs[0] : ifs[0] + npc[0] + header["xp"],
1122+
ifs[1] : ifs[1] + npc[1] + header["yp"],
1123+
ifs[2] : ifs[2] + npc[2],
1124+
fsub.iblock,
1125+
] = fld
1126+
data_found = True
11331127

11341128
if flds.shape[0] == 3 and flds.shape[-1] == 2: # YinYang vector
11351129
# Yang grid is rotated compared to Yin grid

0 commit comments

Comments
 (0)