diff --git a/yt/frontends/ramses/fields.py b/yt/frontends/ramses/fields.py index 4669235a57a..e9fc96078e2 100644 --- a/yt/frontends/ramses/fields.py +++ b/yt/frontends/ramses/fields.py @@ -6,6 +6,7 @@ from yt import units from yt._typing import KnownFieldsT +from yt.fields.field_detector import FieldDetector from yt.fields.field_info_container import FieldInfoContainer from yt.frontends.ramses.io import convert_ramses_conformal_time_to_physical_age from yt.utilities.cython_fortran_utils import FortranFile @@ -218,12 +219,16 @@ def _temperature(field, data): else: def _temperature(field, data): - warnings.warn( - "Trying to calculate temperature but the cooling tables couldn't be found or read. " - "yt will return T/µ instead of T — this is equivalent to assuming µ=1.0", - category=RuntimeWarning, - stacklevel=1, - ) + if not isinstance(data, FieldDetector): + warnings.warn( + "Trying to calculate temperature but the cooling tables " + "couldn't be found or read. yt will return T/µ instead of " + "T — this is equivalent to assuming µ=1.0. To suppress this, " + "derive the temperature from temperature_over_mu with " + "some values for mu.", + category=RuntimeWarning, + stacklevel=1, + ) return data["gas", "temperature_over_mu"] self.add_field( diff --git a/yt/frontends/ramses/tests/test_outputs_pytest.py b/yt/frontends/ramses/tests/test_outputs_pytest.py index 40b100fe5d9..668c78e2d0e 100644 --- a/yt/frontends/ramses/tests/test_outputs_pytest.py +++ b/yt/frontends/ramses/tests/test_outputs_pytest.py @@ -55,3 +55,28 @@ def test_field_config_2(custom_ramses_fields_conf): assert ("ramses", f) in ds.field_list for f in custom_grav: assert ("gravity", f) in ds.field_list + + +@requires_file(output_00080) +@requires_file(ramses_new_format) +def test_warning_T2(): + ds1 = yt.load(output_00080) + ds2 = yt.load(ramses_new_format) + + # Should not raise warnings + ds1.r["gas", "temperature_over_mu"] + ds2.r["gas", "temperature_over_mu"] + + # We cannot read the cooling tables of output_00080 + # so this should raise a warning + with pytest.warns( + RuntimeWarning, + match=( + "Trying to calculate temperature but the cooling tables couldn't be " + r"found or read\. yt will return T/µ instead of T.*" + ), + ): + ds1.r["gas", "temperature"] + + # But this one should not + ds2.r["gas", "temperature"]