Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: noisy warnings when setting a custom colorbar norm for fields with take_log=False #4502

Closed
neutrinoceros opened this issue Jun 12, 2023 · 1 comment · Fixed by #4503
Closed
Labels
bug UX user-experience viz: 2D

Comments

@neutrinoceros
Copy link
Member

Bug report

Bug summary

The logger filters out immediate repetitions, but when 2 different warnings are hit in a loop, it can quickly get pretty noisy.
The class reponsible for handling colorbar norms (NormHandler) emits warnings when it receives a new constraint that forces dropping of previously set ones (this is by design and still desired). Now, this warning assumes all previous constraint were either set by the user or inherited from a previous rendering of the plot, but there's one place where this rule is violated and we set norm constraint internally ahead of rendering:

if finfo.take_log is False:
# take_log can be `None` so we explicitly compare against a boolean
pnh.norm_type = Normalize
else:
# do nothing, the norm handler is responsible for
# determining a viable norm, and defaults to LogNorm/SymLogNorm
pass

Within the right conditions, this combination of factors generates a lot of noisy and frankly useless warnings.

Code for reproduction

import yt
from yt.testing import fake_amr_ds
from matplotlib.colors import SymLogNorm

yt.set_log_level("warning")
def fake_field(field, data):
    return data["Density"]

field = ("gas", "fake_density")
for _ in range(5):
    ds = fake_amr_ds()
    ds.add_field(
        field,
        function=fake_field,
        sampling_type="cell",
        take_log=False,
    )
    p = yt.SlicePlot(ds, "z", field)
    p.set_norm(field, SymLogNorm(linthresh=1, base=2))
    p.save("/tmp/")

Actual outcome

yt : [WARNING  ] 2023-06-12 17:38:17,408 Field ('gas', 'fake_density') was added without specifying units or dimensions, auto setting units to 'g/cm**3'
yt : [WARNING  ] 2023-06-12 17:38:17,927 Dropping norm constraints (norm_type=<class 'matplotlib.colors.Normalize'>)
yt : [WARNING  ] 2023-06-12 17:38:18,698 Field ('gas', 'fake_density') was added without specifying units or dimensions, auto setting units to 'g/cm**3'
yt : [WARNING  ] 2023-06-12 17:38:18,871 Dropping norm constraints (norm_type=<class 'matplotlib.colors.Normalize'>)
yt : [WARNING  ] 2023-06-12 17:38:19,472 Field ('gas', 'fake_density') was added without specifying units or dimensions, auto setting units to 'g/cm**3'
yt : [WARNING  ] 2023-06-12 17:38:19,707 Dropping norm constraints (norm_type=<class 'matplotlib.colors.Normalize'>)
yt : [WARNING  ] 2023-06-12 17:38:20,313 Field ('gas', 'fake_density') was added without specifying units or dimensions, auto setting units to 'g/cm**3'
yt : [WARNING  ] 2023-06-12 17:38:20,482 Dropping norm constraints (norm_type=<class 'matplotlib.colors.Normalize'>)
yt : [WARNING  ] 2023-06-12 17:38:21,079 Field ('gas', 'fake_density') was added without specifying units or dimensions, auto setting units to 'g/cm**3'
yt : [WARNING  ] 2023-06-12 17:38:21,308 Dropping norm constraints (norm_type=<class 'matplotlib.colors.Normalize'>)

Expected outcome

The log should be limited to the first warning

yt : [WARNING  ] 2023-06-12 17:38:17,408 Field ('gas', 'fake_density') was added without specifying units or dimensions, auto setting units to 'g/cm**3'

Version Information

  • Operating System: macOS
  • Python Version: 3.11.4
  • yt version: 4.2.0
  • Other Libraries (if applicable):
@neutrinoceros
Copy link
Member Author

note that I previously reported this warning as undesired in #4448

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug UX user-experience viz: 2D
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant