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

grdimage shows strange lines #357

Closed
htyeim opened this issue Apr 29, 2020 · 8 comments
Closed

grdimage shows strange lines #357

htyeim opened this issue Apr 29, 2020 · 8 comments

Comments

@htyeim
Copy link
Contributor

htyeim commented Apr 29, 2020

Below is an example of the problem.

GMTjl_tmp

The code that can reproduce the figure can be found below (in macOS 10.15.4 and GMT was installed using brew)

using Libdl
push!(Libdl.DL_LOAD_PATH, "/usr/local/Cellar/gmt/6.0.0_5/lib")
using GMT
function peaks_test(; N = 49, grid = true) # modified from GMT.peaks
	x, y = GMT.meshgrid(range(-3, stop = 3, length = N))

	z =  3 * (1 .- x).^2 .* exp.(-(x.^2) - (y .+ 1).^2) - 10 * (x ./ 5 - x.^3 - y.^5) .* exp.(-x.^2 - y.^2)
	   - 1 / 3 * exp.(-(x .+ 1).^2 - y.^2)

	if (grid)
		x = collect(range(-30, stop = 30, length = N)) 
        y = deepcopy(x) 
        x .+= 100
        y .+= 25
	z = Float32.(z)
	G = GMT.GMTgrid("", "", 0, [x[1], x[end], y[1], y[end], minimum(z), maximum(z)], [x[2] - x[1], y[2] - y[1]],
					0, NaN, "", "", "", "", x, y, z, "x", "y", "z", "")
		return G
	else
		return x, y, z
	end
end
G = peaks_test(N = 200)

# no problem
grdimage(G, region =  (70, 130, -5, 55),nan_alpha = true, figsize = 15,
        proj = :Mercator ,color = :jet,fmt = :png, show = true)

# has problem
grdimage(G, region =  (65, 130, 15, 47), figsize = 15,
        proj = :Mercator ,color = :jet,fmt = :png, show = true)

# has problem
grdimage(G, region =  (70, 130, 5, 47),nan_alpha = true, figsize = 15,
        proj = :Mercator ,color = :jet,fmt = :png, show = true)

The only difference is the region of basemap and that of grid data. Is it a bug or did I misuse the function?

@joa-quim
Copy link
Member

Right, I can reproduce this but I think it's a bug in GMT itself because I can reproduce it in the equivalent Matlab wrapper too.

One other thing, since you installed GMT with homebrew and it stores the libs on standard places, you should not need to do the step

using Libdl
push!(Libdl.DL_LOAD_PATH, "/usr/local/Cellar/gmt/6.0.0_5/lib")

could you please confirm that?

@joa-quim
Copy link
Member

joa-quim commented Apr 29, 2020

Opened an issue in GMT
And, BTW, thanks for the report.

@htyeim
Copy link
Contributor Author

htyeim commented Apr 29, 2020

Thanks!


One other thing, since you installed GMT with homebrew and it stores the libs on standard places, you should not need to do the step

using Libdl
push!(Libdl.DL_LOAD_PATH, "/usr/local/Cellar/gmt/6.0.0_5/lib")

could you please confirm that?

Before I upgraded GMT/julia using brew upgrade/brew cu --all, I didn't need to add these two lines. However, at some point (I don't know what happened exactly...), if I don't add these two lines I will get some errors. Below is a example (code from gallery):

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.4.1 (2020-04-14)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using GMT

julia> bar(rand(15),              # Generate the dataset
           color=:rainbow,        # The color scale
           figsize=(14,8),        # The fig size (14 x 8 cm)
           title="Colored bars",  # The fig title
           fmt=:png,              # The image format
           show=true)
ERROR: could not load library "libgmt"
dlopen(libgmt.dylib, 1): image not found
Stacktrace:
 [1] GMT_Create_Session at /Users/t/.julia/packages/GMT/VY9y7/src/libgmt.jl:6 [inlined] (repeats 2 times)
 [2] gmt(::String, ::Array{Float64,2}) at /Users/t/.julia/packages/GMT/VY9y7/src/gmt_main.jl:125
 [3] read_data(::Dict{Symbol,Any}, ::String, ::String, ::Array{Float64,2}, ::String, ::Bool, ::Bool) at /Users/t/.julia/packages/GMT/VY9y7/src/common_options.jl:2154
 [4] read_data at /Users/t/.julia/packages/GMT/VY9y7/src/common_options.jl:2121 [inlined]
 [5] common_plot_xyz(::String, ::Array{Float64,2}, ::String, ::Bool, ::Bool, ::Pair{Symbol,Any}, ::Vararg{Pair{Symbol,Any},N} where N) at /Users/t/.julia/packages/GMT/VY9y7/src/psxy.jl:50
 [6] #bar#174 at /Users/t/.julia/packages/GMT/VY9y7/src/plot.jl:351 [inlined]
 [7] top-level scope at REPL[2]:1
caused by [exception 1]
UndefVarError: API not defined
Stacktrace:
 [1] gmt(::String, ::Array{Float64,2}) at /Users/user/.julia/packages/GMT/VY9y7/src/gmt_main.jl:122
 [2] read_data(::Dict{Symbol,Any}, ::String, ::String, ::Array{Float64,2}, ::String, ::Bool, ::Bool) at /Users/user/.julia/packages/GMT/VY9y7/src/common_options.jl:2154
 [3] read_data at /Users/user/.julia/packages/GMT/VY9y7/src/common_options.jl:2121 [inlined]
 [4] common_plot_xyz(::String, ::Array{Float64,2}, ::String, ::Bool, ::Bool, ::Pair{Symbol,Any}, ::Vararg{Pair{Symbol,Any},N} where N) at /Users/user/.julia/packages/GMT/VY9y7/src/psxy.jl:50
 [5] #bar#174 at /Users/user/.julia/packages/GMT/VY9y7/src/plot.jl:351 [inlined]
 [6] top-level scope at REPL[2]:1

julia>

I think the problem might be the path /gmt/6.0.0_5/ isn't in lib [?]. At first, I though the problem might be the updated path, and If I remember correctly, I removed, reinstalled, rebuilt GMT.jl several times, but I still get the errors. Then I googled it and found this solution. I didn't report it since it can be solved by adding two lines of code.

@joa-quim
Copy link
Member

joa-quim commented Apr 29, 2020

Yes, that's a general problem in unix when the shared libs are not stored in standard places. But homebrew makes symbolic links to /usr/local/lib and that is a standard place so the shared libs there should be findable without further help. Don't you have a (symbolic link) libgmt.dylib in /usr/local/lib?

Ah, and BTW, you don't need to repeat those 2 lies all the time, just add them to the startup.jl file

@htyeim
Copy link
Contributor Author

htyeim commented Apr 30, 2020

I will add the lines in startup.jl, thanks!

libgmt.dylib is in /usr/local/lib

 /usr/local/lib  ls |grep gmt
gmt
libgmt.6.0.0.dylib
libgmt.6.dylib
libgmt.dylib

 /usr/local/lib  ls -l libgmt.dylib
lrwxr-xr-x  1 t  staff  38 Apr  8 09:08 libgmt.dylib -> ../Cellar/gmt/6.0.0_5/lib/libgmt.dylib

 /usr/local/lib  ls -l ../Cellar/gmt/6.0.0_5/lib/libgmt.dylib
lrwxr-xr-x  1 t  staff  14 Oct 31 11:25 ../Cellar/gmt/6.0.0_5/lib/libgmt.dylib -> libgmt.6.dylib

 /usr/local/lib  ls -l ../Cellar/gmt/6.0.0_5/lib/libgmt.6.dylib
lrwxr-xr-x  1 t  staff  18 Oct 31 11:25 ../Cellar/gmt/6.0.0_5/lib/libgmt.6.dylib -> libgmt.6.0.0.dylib

  /usr/local/lib  ls -l ../Cellar/gmt/6.0.0_5/lib/libgmt.6.0.0.dylib
-r--r--r--  1 t  staff  3677296 Apr  8 09:08 ../Cellar/gmt/6.0.0_5/lib/libgmt.6.0.0.dylib

Then I have no idea what happens when julia says ERROR: could not load library "libgmt".

@joa-quim
Copy link
Member

Don't know either. Unix is very complicated and Macs even more.

@htyeim
Copy link
Contributor Author

htyeim commented Apr 30, 2020

Yes, they are complicated (I would like to add GMT and julia as well...). I tested some julia code that used GMT.jl about one month ago and it ran perfectly. Then I ran the same code without any modification three days ago, I got tons of errors. Anyway, it's OK since it's very easy to solve.

@joa-quim
Copy link
Member

joa-quim commented May 4, 2020

BTW, this issue was fixed upstream so I'm closing it

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

No branches or pull requests

2 participants