Skip to content

Commit 5ea7043

Browse files
Merge pull request #5123 from neutrinoceros/rfc/clarify_setup_fluid_aliases_logic
RFC: clarify aliasing logic for non-cartesian geometries in `FieldInfoContainer.setup_fluid_aliases`
2 parents db7f623 + 1050038 commit 5ea7043

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

yt/fields/field_info_container.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -280,21 +280,13 @@ def setup_fluid_aliases(self, ftype: FieldType = "gas") -> None:
280280
for alias in aliases:
281281
match self.ds.geometry:
282282
case Geometry.POLAR | Geometry.CYLINDRICAL | Geometry.SPHERICAL:
283-
if alias[-2:] not in ["_x", "_y", "_z"]:
284-
to_convert = False
285-
else:
286-
for suffix in ["x", "y", "z"]:
287-
if f"{alias[:-2]}_{suffix}" not in aliases_gallery:
288-
to_convert = False
289-
break
290-
to_convert = True
291-
if to_convert:
292-
if alias[-2:] == "_x":
293-
alias = f"{alias[:-2]}_{axis_names[0]}"
294-
elif alias[-2:] == "_y":
295-
alias = f"{alias[:-2]}_{axis_names[1]}"
296-
elif alias[-2:] == "_z":
297-
alias = f"{alias[:-2]}_{axis_names[2]}"
283+
KNOWN_SUFFIXES = ("x", "y", "z")
284+
stem, _, suffix = alias.rpartition("_")
285+
if suffix in KNOWN_SUFFIXES and all(
286+
f"{stem}_{s}" in aliases_gallery for s in KNOWN_SUFFIXES
287+
):
288+
new_suffix = axis_names[KNOWN_SUFFIXES.index(suffix)]
289+
alias = f"{stem}_{new_suffix}"
298290
case (
299291
Geometry.CARTESIAN
300292
| Geometry.GEOGRAPHIC

0 commit comments

Comments
 (0)