Skip to content

Draft: Add example of color in x-y plots#688

Merged
rjleveque merged 4 commits intoclawpack:masterfrom
kbarnhart:add_xy_color_example
Jan 21, 2026
Merged

Draft: Add example of color in x-y plots#688
rjleveque merged 4 commits intoclawpack:masterfrom
kbarnhart:add_xy_color_example

Conversation

@kbarnhart
Copy link
Contributor

@rjleveque
Copy link
Member

Thanks @kbarnhart, nice example.

It works fine, but does throw a warning about divide by zeros (later overwritten by nan's). If you want to avoid this, you could use:

    def r_surface_and_vel(current_data):
        from numpy import sqrt, nan, divide, zeros
        x = current_data.x
        y = current_data.y
        h = current_data.q[0,:,:]
        dry_tol = 1e-3
        u = divide(current_data.q[1,:,:], h,
                   where=h>dry_tol, out=zeros(h.shape))
        v = divide(current_data.q[2,:,:], h,
                   where=h>dry_tol, out=zeros(h.shape))
        eta = current_data.q[3,:,:]
        vel = sqrt(u**2 + v**2)
        vel[h<dry_tol] = nan
        eta[h<dry_tol] = nan
        r = sqrt(x**2 + y**2)
        return r,eta,vel

This sets u,v to 0 where h <= dry_tol, which is generally what's wanted instead of inf.
Or you could use out=nan*zeros(h.shape) in divide() to set u,v to nan more directly whereever h <= dry_tol.

@kbarnhart
Copy link
Contributor Author

@rjleveque - I've revised to incorporate your suggestions. Thanks!

@rjleveque
Copy link
Member

Thanks again!

@rjleveque rjleveque merged commit 77ee8e0 into clawpack:master Jan 21, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants