From 79a7e66d495579623b4c34453b14bbb355ef92dc Mon Sep 17 00:00:00 2001 From: Cameron Hummels Date: Mon, 12 Jul 2021 16:54:14 -0700 Subject: [PATCH 1/4] Checking if extrema are all None in PhasePlot --- yt/data_objects/profiles.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/yt/data_objects/profiles.py b/yt/data_objects/profiles.py index e031664ef72..06447cc607c 100644 --- a/yt/data_objects/profiles.py +++ b/yt/data_objects/profiles.py @@ -1347,7 +1347,14 @@ def create_profile( else: logs_list.append(data_source.ds.field_info[bin_field].take_log) logs = logs_list - if extrema is None: + + # Are the extrema all Nones? Then treat them as though extrema was set as None + if extrema is not None: + extrema_vals = list(extrema.values()) + flat_list = [item for sublist in extrema_vals for item in sublist] + extrema_all_nones = not any(flat_list) + + if extrema is None or extrema_all_nones: ex = [ data_source.quantities["Extrema"](f, non_zero=l) for f, l in zip(bin_fields, logs) From 672103e5488ae4f70718a1182a0f0bc02114a530 Mon Sep 17 00:00:00 2001 From: Cameron Hummels Date: Tue, 13 Jul 2021 08:27:36 -0700 Subject: [PATCH 2/4] Simplifying logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Robert --- yt/data_objects/profiles.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/yt/data_objects/profiles.py b/yt/data_objects/profiles.py index 06447cc607c..a8863c4ea93 100644 --- a/yt/data_objects/profiles.py +++ b/yt/data_objects/profiles.py @@ -1349,12 +1349,7 @@ def create_profile( logs = logs_list # Are the extrema all Nones? Then treat them as though extrema was set as None - if extrema is not None: - extrema_vals = list(extrema.values()) - flat_list = [item for sublist in extrema_vals for item in sublist] - extrema_all_nones = not any(flat_list) - - if extrema is None or extrema_all_nones: + if extrema is None or not any(collapse(extrema.values())): ex = [ data_source.quantities["Extrema"](f, non_zero=l) for f, l in zip(bin_fields, logs) From 0dfc09e4fd9e82a0a514cb89e5a6d4c5fe56fd81 Mon Sep 17 00:00:00 2001 From: Cameron Hummels Date: Tue, 13 Jul 2021 08:32:09 -0700 Subject: [PATCH 3/4] Adding collapse import --- yt/data_objects/profiles.py | 1 + 1 file changed, 1 insertion(+) diff --git a/yt/data_objects/profiles.py b/yt/data_objects/profiles.py index a8863c4ea93..ee1f9de757d 100644 --- a/yt/data_objects/profiles.py +++ b/yt/data_objects/profiles.py @@ -1,4 +1,5 @@ import numpy as np +from more_itertools import collapse from yt.data_objects.field_data import YTFieldData from yt.fields.derived_field import DerivedField From 2066eb58e5a9d862fe76bdbb362c3ee2c6aeccb0 Mon Sep 17 00:00:00 2001 From: Cameron Hummels Date: Tue, 13 Jul 2021 10:49:13 -0700 Subject: [PATCH 4/4] Adding a test. --- yt/data_objects/tests/test_profiles.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/yt/data_objects/tests/test_profiles.py b/yt/data_objects/tests/test_profiles.py index 148e06d3626..45d028ae666 100644 --- a/yt/data_objects/tests/test_profiles.py +++ b/yt/data_objects/tests/test_profiles.py @@ -642,6 +642,21 @@ def test_unequal_bin_field_profile(self): ("gas", "mass"), ) + def test_set_linear_scaling_for_none_extrema(self): + # See Issue #3431 + # Ensures that extrema are calculated in the same way on subsequent passes + # through the PhasePlot machinery. + ds = fake_sph_orientation_ds() + p = yt.PhasePlot( + ds, + ("all", "particle_position_spherical_theta"), + ("all", "particle_position_spherical_radius"), + ("all", "particle_mass"), + weight_field=None, + ) + p.set_log(("all", "particle_position_spherical_theta"), False) + p.save() + def test_index_field_units(): # see #1849