Skip to content

Commit

Permalink
Streamplot fix (#44)
Browse files Browse the repository at this point in the history
* Use Float64 range in streamplot

* Bump patch
  • Loading branch information
henry2004y authored Apr 21, 2024
1 parent 4f61889 commit ae3fcb1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Batsrus"
uuid = "e74ebddf-6ac1-4047-a0e5-c32c99e57753"
authors = ["Hongyang Zhou <[email protected]>"]
version = "0.5.4"
version = "0.5.5"

[deps]
FortranFiles = "c58ffaec-ab22-586d-bfc5-781a99fd0b10"
Expand Down
17 changes: 9 additions & 8 deletions src/plot/pyplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ end
Wrapper over `contourf` in matplotlib.
"""
function PyPlot.contourf(bd::BATLData, var::AbstractString, ax=nothing; levels::Int=0,
function PyPlot.contourf(bd::BATLData, var::AbstractString, ax=nothing; levels::Int=0,
plotrange=[-Inf,Inf,-Inf,Inf], plotinterval=0.1, innermask=false, kwargs...)

Xi, Yi, Wi = getdata2d(bd, var, plotrange, plotinterval; innermask)
Expand Down Expand Up @@ -674,8 +674,8 @@ function PyPlot.streamplot(bd::BATLData, var::AbstractString, ax=nothing;
end

# Create grid values first.
xi = range(plotrange[1], stop=plotrange[2], step=plotinterval)
yi = range(plotrange[3], stop=plotrange[4], step=plotinterval)
xi = range(Float64(plotrange[1]), stop=Float64(plotrange[2]), step=plotinterval)
yi = range(Float64(plotrange[3]), stop=Float64(plotrange[4]), step=plotinterval)

# Is there a triangulation method in Julia?
tr = matplotlib.tri.Triangulation(X, Y)
Expand All @@ -688,16 +688,17 @@ function PyPlot.streamplot(bd::BATLData, var::AbstractString, ax=nothing;
v2 = interpolator(Xi, Yi)

else # Cartesian coordinates
xrange = range(x[1,1,1], x[end,1,1], size(x,1))
yrange = range(x[1,1,2], x[1,end,2], size(x,2))
# Convert to Float64 to satisfy the equal space checking in streamplot.py
xrange = range(Float64(x[1,1,1]), Float64(x[end,1,1]), size(x,1))
yrange = range(Float64(x[1,1,2]), Float64(x[1,end,2]), size(x,2))
if all(isinf.(plotrange))
xi = xrange
yi = yrange
v1 = w[:,:,var1_]'
v2 = w[:,:,var2_]'
else
if plotrange[1] == -Inf plotrange[1] = xrange[1] end
if plotrange[2] == Inf plotrange[2] = xrange[end] end
if plotrange[1] == -Inf plotrange[1] = xrange[1] end
if plotrange[2] == Inf plotrange[2] = xrange[end] end
if plotrange[3] == -Inf plotrange[3] = yrange[1] end
if plotrange[4] == Inf plotrange[4] = yrange[end] end

Expand All @@ -706,7 +707,7 @@ function PyPlot.streamplot(bd::BATLData, var::AbstractString, ax=nothing;
yi = range(plotrange[3], stop=plotrange[4], step=plotinterval)
interp1 = cubic_spline_interpolation((xrange, yrange), w1)
v1 = [interp1(i, j) for j in yi, i in xi]

interp2 = cubic_spline_interpolation((xrange, yrange), w2)
v2 = [interp2(i, j) for j in yi, i in xi]
end
Expand Down

2 comments on commit ae3fcb1

@henry2004y
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/105304

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.5 -m "<description of version>" ae3fcb1257aac697ca48cf493aedd754991f9529
git push origin v0.5.5

Please sign in to comment.