From 5a234f1ba0bc1599772e4e446930ff348a5ebf9c Mon Sep 17 00:00:00 2001 From: Britton Smith Date: Mon, 22 Aug 2022 14:32:11 +0100 Subject: [PATCH 1/3] Make sure positions are in code_length in get_radius function. --- yt/fields/field_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yt/fields/field_functions.py b/yt/fields/field_functions.py index 4b68d00c2aa..9f7eede448c 100644 --- a/yt/fields/field_functions.py +++ b/yt/fields/field_functions.py @@ -19,7 +19,7 @@ def get_radius(data, field_prefix, ftype): rdw = radius2.v for i, ax in enumerate("xyz"): np.subtract( - data[ftype, f"{field_prefix}{ax}"].d, + data[ftype, f"{field_prefix}{ax}"].to("code_length").d, center[i].d, r, ) From 6239c55484a09502b00524299c643acf32221376 Mon Sep 17 00:00:00 2001 From: Britton Smith Date: Mon, 22 Aug 2022 20:03:16 +0100 Subject: [PATCH 2/3] Only convert units if we need to. --- yt/fields/field_functions.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/yt/fields/field_functions.py b/yt/fields/field_functions.py index 9f7eede448c..469c9b4abe0 100644 --- a/yt/fields/field_functions.py +++ b/yt/fields/field_functions.py @@ -18,8 +18,11 @@ def get_radius(data, field_prefix, ftype): if any(data.ds.periodicity): rdw = radius2.v for i, ax in enumerate("xyz"): + pos = data[ftype, f"{field_prefix}{ax}"] + if str(pos.units) != "code_length": + pos.convert_to_units("code_length") np.subtract( - data[ftype, f"{field_prefix}{ax}"].to("code_length").d, + pos.d, center[i].d, r, ) From 98cab40bf1d566fb4e0cc5fa4a35e238607a60f4 Mon Sep 17 00:00:00 2001 From: Britton Smith Date: Thu, 25 Aug 2022 19:12:28 +0100 Subject: [PATCH 3/3] Make a copy when converting position units. --- yt/fields/field_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yt/fields/field_functions.py b/yt/fields/field_functions.py index 469c9b4abe0..2acb949c819 100644 --- a/yt/fields/field_functions.py +++ b/yt/fields/field_functions.py @@ -20,7 +20,7 @@ def get_radius(data, field_prefix, ftype): for i, ax in enumerate("xyz"): pos = data[ftype, f"{field_prefix}{ax}"] if str(pos.units) != "code_length": - pos.convert_to_units("code_length") + pos = pos.to("code_length") np.subtract( pos.d, center[i].d,