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 with Makie extension #3727

Closed
navidcy opened this issue Aug 25, 2024 · 5 comments · Fixed by #3730
Closed

Bug with Makie extension #3727

navidcy opened this issue Aug 25, 2024 · 5 comments · Fixed by #3730

Comments

@navidcy
Copy link
Collaborator

navidcy commented Aug 25, 2024

The code snippet below is not working as expected. I explain.

This works fine:

using Oceananigans, CairoMakie

underlying_grid = RectilinearGrid(size = (250, 125),
                                  x = (-1000e3, 1000e3),
                                  z = (-2e3, 0),
                                  halo = (4, 4),
                                  topology = (Periodic, Flat, Bounded))

bottom(x) = - underlying_grid.Lz + 500 * exp(-x^2 / (2*(20e3)^2))

grid = ImmersedBoundaryGrid(underlying_grid, GridFittedBottom(bottom))

lines(grid.immersed_boundary.bottom_height)

and gives:

fig1

which is all good! But:

x, y, z = nodes(grid.immersed_boundary.bottom_height)

lines(x, grid.immersed_boundary.bottom_height)

fig2

Perhaps this is a bit informative

lines(x/1e3, grid.immersed_boundary.bottom_height)

fig3

Originally posted by @navidcy in #3725 (comment)

@glwagner
Copy link
Member

Not sure but I'm guessing to fix this we have to overload lines. It seems like it computes that it's going to be making a 3D plot at some point before convert_arguments is called.. not sure

@glwagner
Copy link
Member

What if you make the axis first?

@navidcy
Copy link
Collaborator Author

navidcy commented Aug 26, 2024

Actually that worked!

using Oceananigans, CairoMakie

underlying_grid = RectilinearGrid(size = (250, 125),
                                  x = (-1000e3, 1000e3),
                                  z = (-2e3, 0),
                                  halo = (4, 4),
                                  topology = (Periodic, Flat, Bounded))

bottom(x) = - underlying_grid.Lz + 500 * exp(-x^2 / (2*(20e3)^2))

grid = ImmersedBoundaryGrid(underlying_grid, GridFittedBottom(bottom))

x, y, z = nodes(grid.immersed_boundary.bottom_height)

fig = Figure()
ax = Axis(fig[1, 1])
lines!(ax, x/1e3, grid.immersed_boundary.bottom_height)
fig

display

OK. I suppose if you don't create the axis Makie thinks this is a 3D field and then creates Axis3 object... So it's good to point out somewhere that to visualize it's better to create axis first?

@glwagner
Copy link
Member

Or we can dig into Makie and maybe try to fix the wrong axis assignment?

@glwagner
Copy link
Member

I think I figured it out, basically there is a function args_preferred_axis that determines which Axis type to use (when it's not specified), and because Field isa AbstractArray{3} it ends up choosing LScene. So the simple fix here is just to say that Field does not have a preferred axis type. As a result, when the axis is not provided, it is determined later on (by the converted arguments, rather than the un-converted Field).

We could in the future attempt to figure out the "effective dimensionality" of a Field and then use that to determine whether it has a preferred axis type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants