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: fix a bug where 2D plots in spherical geometries would always use code-units in plot axes #3618

Merged
merged 2 commits into from
Oct 22, 2021

Conversation

neutrinoceros
Copy link
Member

@neutrinoceros neutrinoceros commented Oct 21, 2021

PR Summary

fix #2913

import yt

file = "KeplerianDisk/disk.out1.00000.athdf"
for us in ("cgs", "code"):
    ds = yt.load(file, unit_system=us)
    for normal in ("phi", "theta"):
        p = yt.SlicePlot(ds, normal, "density")
        p.plots["density"].figure.suptitle(f"unit system = {us}")
        p.save(f"/tmp/disk_slice_{us}.png")

gives
disK_slice_cgs
disK_slice_code

disk_slice_theta_cgs
disk_slice_theta_code

Marking this as draft because I ended up removing initialization code that was problematic in this specific case but I'd expect the tests to reveal why it was necessary.
In any cases, the code in question is duplicated in a lot of plot classes, so I'd need to apply consistent changes everywhere even if it turns out that it doesn't break anything.

@@ -2530,7 +2530,7 @@ def __call__(self, plot):
un = self.time_unit.latex_representation()
time_unit = r"$\ \ (" + un + r")$"
except AttributeError as err:
if plot.ds.unit_system._code_flag == "code":
if plot.ds.unit_system._code_flag:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't strictly necessary here but this looks like a different bug I stumbled upon while working here. The bug is that the _code_flag attribute is defined as a boolean, so this condition seems impossible to satisfy and probably dates back from an earlier implementation.

@@ -998,7 +998,7 @@ def _setup_plots(self):
axis_index = self.data_source.axis

xc, yc = self._setup_origin()
if self.ds.unit_system._code_flag or self.ds.no_cgs_equiv_length:
if self.ds.unit_system._code_flag:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this is a breaking change in other cases:
self.ds.no_cgs_equiv_length was apparently used as a proxy to detect some cartopy operations, but it happens to collide with how spherical dataset behave. Possibly the real bug is that this flag shouldn't be true for spherical datasets.

@neutrinoceros
Copy link
Member Author

some cartopy tests failed, let's try again step by step

@neutrinoceros
Copy link
Member Author

I think the bug dates back from #2378

@neutrinoceros
Copy link
Member Author

neutrinoceros commented Oct 21, 2021

so the current patch is still not satisfactory because it breaks units conversion for 'r-normal' plots where both axes are angular coordinates. It's starting to look like we need a replacement for the single no_cgs_equiv_length boolean, which seems to be too limited to work in every situations we want to support.
I believe the real issue is that we always store coordinates as lengths, even for angles, and this boolean is a workaround. Solving the deep underlying problem is just too much for me right now, so I'll try to develop somewhat more flexible workaround.

@neutrinoceros
Copy link
Member Author

neutrinoceros commented Oct 21, 2021

I think the current iteration is now stable in all cases I know of 🤞🏻
Note that I still expect one specific failure in an image comparison test that uses spherical coordinates because its current baseline contains the bug I'm trying to fix here


self.unit_system = us
self.unit_registry.unit_system = self.unit_system

@property
def _code_length(self):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm making this a property because self.no_cgs_equiv_length's value seems to be updated (True -> False) at some point during initialisation that I can not decipher

Copy link
Member Author

@neutrinoceros neutrinoceros Oct 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment still relevant even though GH marks it as "outdated" because I've changed the name of the property

@neutrinoceros
Copy link
Member Author

got exactly the "error" I expected/hoped for on Jenkins

expected (wrong)

tmpcsx30umo

actual (correct)

tmpo5_u63gm

diff

tmpcsx30umo-failed-diff

@neutrinoceros neutrinoceros changed the title BUG: fix a bug where sliceplots with spherical geometries would always use code-units in plot axes BUG: fix a bug where 2D plots in spherical geometries would always use code-units in plot axes Oct 21, 2021
@neutrinoceros
Copy link
Member Author

pinging for reviews:
@matthewturk as the author of #2378 that I'm partially reverting here
and @n-claes as the reporter for this bug

@matthewturk
Copy link
Member

@neutrinoceros Do you have an example where code_units != cm ?

@neutrinoceros
Copy link
Member Author

Unfortunately I don't. The only spherical data sets I know of are from the Athena++ and AMRVAC formats, none of which outputs unit metadata (I think ?) so both frontends default to cgs.

@matthewturk
Copy link
Member

matthewturk commented Oct 22, 2021 via email

@neutrinoceros
Copy link
Member Author

I don't know what you mean. What's identical to what ?

@matthewturk
Copy link
Member

I'd like to see the difference before and after where it's also changing the values, not just the displayed units. If you can force this to happen by setting the unit system to be one where code_length does not correspond to cgs, that would be helpful.

@neutrinoceros
Copy link
Member Author

I could just provide units to the AMRVAC frontend at load time, would that work ?

@neutrinoceros
Copy link
Member Author

import yt
blast = "amrvac/bw_2d0000.dat"

units = ("cm", "AU")
for length_unit in units:
    us = {"length_unit": (1, length_unit)}
    ds = yt.load(blast, units_override=us)
    p = yt.SlicePlot(ds, "phi", "density")
    p.save(f"/tmp/slice_cgs_{length_unit}.png")
main branch

slice_cgs_AU
(x2)

this work

slice_cgs_cm
slice_cgs_AU

@matthewturk
Copy link
Member

Thanks -- this satisfies me!

@neutrinoceros
Copy link
Member Author

great, now let's bump this bad boy :)

@neutrinoceros
Copy link
Member Author

@matthewturk I'm not sure you meant to do that: it seems like you set up auto merge but didn't approve

@matthewturk
Copy link
Member

@neutrinoceros yeah, I like to withhold my approval

@matthewturk matthewturk merged commit 28c08fe into yt-project:main Oct 22, 2021
@neutrinoceros neutrinoceros deleted the hotfix_2913 branch October 22, 2021 20:10
@neutrinoceros
Copy link
Member Author

@meeseeksdev backport to yt-4.0.x

meeseeksmachine pushed a commit to meeseeksmachine/yt that referenced this pull request Nov 6, 2021
…al geometries would always use code-units in plot axes
matthewturk added a commit that referenced this pull request Nov 10, 2021
…8-on-yt-4.0.x

Backport PR #3618 on branch yt-4.0.x (BUG: fix a bug where 2D plots in spherical geometries would always use code-units in plot axes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Axes labels always in code for spherical datasets, independent of "unit_system"
2 participants