Skip to content

Commit

Permalink
Merge pull request #571 from GenericMappingTools/v031
Browse files Browse the repository at this point in the history
Prepare to v.0.31
  • Loading branch information
joa-quim authored Apr 14, 2021
2 parents b86dcae + 33551de commit 9a80df1
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 34 deletions.
61 changes: 61 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Documentation: http://docs.travis-ci.com/user/languages/julia/
language: julia

sudo: false

os:
- linux
dist: eoan
julia:
- 1.6
matrix:
allow_failures:
- julia: nightly
notifications:
email: true
before_install:
#- if [ `uname` = "linux" ]; then sudo apt-get install gmt gmt-dcw gmt-gshhg; fi
# Get Miniconda from Continuum
# Need to source the script to set the PATH variable in this environment
#- source install-miniconda.sh
#- conda update conda -c conda-forge --yes --quiet
# Install dependencies
#- conda install python=3.6 pip -c conda-forge --yes --quiet
#- conda install --file requirements-dev.txt -c conda-forge --yes --quiet
# Need the dev channel to get development builds of GMT 6
#- conda install --file requirements.txt -c conda-forge/label/dev -c conda-forge --yes --quiet
# Show installed pkg information for postmortem diagnostic
#- conda list
# Install GMT trunk
- pwd
- sudo apt-get install subversion build-essential cmake libcurl4-gnutls-dev libnetcdf-dev libgdal-dev gdal-bin libfftw3-dev libpcre3-dev liblapack-dev ghostscript
- git clone --depth=10 https://github.com/GenericMappingTools/gmt.git $HOME/gmt
#- git clone --depth=10 -b external-lib-access --single-branc https://github.com/joa-quim/gmt.git $HOME/gmt
- PATH="$HOME/gmt/bin:$PATH"
- export PATH
- echo 'export PATH="$HOME/gmt/bin:$PATH"' >>~/.bash_profile
- cd $HOME/gmt
- gdalinfo --version
#- wget ftp://ftp.soest.hawaii.edu/gshhg/gshhg-gmt-2.3.7.tar.gz
#- wget http://w3.ualg.pt/~jluis/ftp/gshhg-gmt-2.3.7.tar.gz
- wget https://github.com/GenericMappingTools/gshhg-gmt/releases/download/2.3.7/gshhg-gmt-2.3.7.tar.gz
- tar -xvzf gshhg-gmt-2.3.7.tar.gz
#- wget http://w3.ualg.pt/~jluis/ftp/dcw-gmt-1.1.4.tar.gz
- wget https://github.com/GenericMappingTools/dcw-gmt/releases/download/1.1.4/dcw-gmt-1.1.4.tar.gz
- tar -xvzf dcw-gmt-1.1.4.tar.gz
- mkdir build
- cd build
- cmake --config Release .. -DSUPPORT_EXEC_IN_BINARY_DIR=TRUE -DGMT_ENABLE_OPENMP=ON -DCMAKE_INSTALL_PREFIX=$HOME/gmt -DGSHHG_ROOT=$HOME/gmt/gshhg-gmt-2.3.7
- make -j && make install
#- export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$HOME/gmt/lib"
- cd /home/travis/build/GenericMappingTools/GMT.jl
#- if [ `uname` = "Darwin" ]; then brew update && brew upgrade && brew install gmt; fi

# uncomment the following lines to override the default test script
script:
#- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'using Pkg; Pkg.build(); Pkg.test(; coverage=true);'
after_success:
- julia -e 'using Pkg; cd(Pkg.dir("GMT")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'
- julia -e 'using Pkg; ps=Pkg.PackageSpec(name="Documenter"); Pkg.add(ps); Pkg.pin(ps)'
- julia -e 'using Pkg; cd(Pkg.dir("GMT")); include(joinpath("docs", "make.jl"))'
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GMT"
uuid = "5752ebe1-31b9-557e-87aa-f909b540aa54"
authors = ["Joaquim Luis <[email protected]>"]
version = "0.30.1"
version = "0.31.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
41 changes: 18 additions & 23 deletions src/common_options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ function opt_R2num(opt_R::String)
if (endswith(opt_R, "Rg")) return [0.0, 360., -90., 90.] end
if (endswith(opt_R, "Rd")) return [-180.0, 180., -90., 90.] end
if (findfirst("/", opt_R) !== nothing)
isdiag = false
if ((ind = findfirst("+r", opt_R)) !== nothing) # Diagonal mode
opt_R = opt_R[1:ind[1]-1]; isdiag = true # Strip the "+r"
else isdiag = false
end
rs = split(opt_R, '/')
limits = zeros(length(rs))
Expand Down Expand Up @@ -1126,8 +1126,7 @@ function add_opt_pen(d::Dict, symbs, opt::String="", sub::Bool=true, del::Bool=t
d2 = nt2dict(val) # Decompose the NT and feed into this-self
t = add_opt_pen(d2, symbs, "", true, false)
if (t == "")
d = nt2dict(val)
out[1] = opt
d, out[1] = nt2dict(val), opt
else
out[1] = opt * t
d = Dict{Symbol,Any}() # Just let it go straight to end. Returning here seems bugged
Expand Down Expand Up @@ -1282,15 +1281,13 @@ function arg2str(arg, sep='/')::String
end

# ---------------------------------------------------------------------------------------------------
function finish_PS_nested(d::Dict, cmd::Vector{String}, K::Bool)
function finish_PS_nested(d::Dict, cmd::Vector{String}, K::Bool=true)
# Finish the PS creating command, but check also if we have any nested module calls like 'coast', 'colorbar', etc
cmd2 = add_opt_module(d)
if (!isempty(cmd2))
K = true
if (startswith(cmd2[1], "clip")) # Deal with the particular psclip case (Tricky)
if (isa(CTRL.pocket_call[1], Symbol) || isa(CTRL.pocket_call[1], String)) # Assume it's a clip=end
cmd = [cmd; "psclip -C"]
CTRL.pocket_call[1] = nothing
cmd, CTRL.pocket_call[1] = [cmd; "psclip -C"], nothing
else
ind = findfirst(" -R", cmd[1]); opt_R = strtok(cmd[1][ind[1]:end])[1]
ind = findfirst(" -J", cmd[1]); opt_J = strtok(cmd[1][ind[1]:end])[1]
Expand Down Expand Up @@ -1326,9 +1323,9 @@ function finish_PS(d::Dict, cmd::Vector{String}, output::String, K::Bool, O::Boo
# Finish a PS creating command. All PS creating modules should use this.
IamModern[1] && return cmd # In Modern mode this fun does not play
for k = 1:length(cmd)
KK, OO = K, O
if (!occursin(" >", cmd[k])) # Nested calls already have the redirection set
if (k > 1) KK = true; OO = true end
KK, OO = K, O
if (k > 1) KK, OO = true, true end
cmd[k] = finish_PS(d, cmd[k], output, KK, OO)
end
end
Expand Down Expand Up @@ -2539,10 +2536,11 @@ function fname_out(d::Dict, del::Bool=false)
(EXT == "" && !Sys.iswindows()) && error("Return an image is only for Windows")
(1 == length(EXT) > 3) && error("Bad graphics file extension")

ret_ps = false # To know if we want to return or save PS in mem
if (haskey(d, :ps)) # In any case this means we want the PS sent back to Julia
fname = ""; EXT = "ps"; ret_ps = true
fname, EXT, ret_ps = "", "ps", true
(del) && delete!(d, :ps)
else
ret_ps = false # To know if we want to return or save PS in mem
end

opt_T = "";
Expand Down Expand Up @@ -2614,8 +2612,7 @@ function read_data(d::Dict, fname::String, cmd::String, arg, opt_R::String="", i
arg[:,1] = Dates.value.(arg[:,1]) ./ 1000; cmd *= " --TIME_SYSTEM=dr0001"
t = Array{Float64, 2}(undef, size(arg))
[t[k] = arg[k] for k in eachindex(arg)]
arg = t
got_datetime = true
arg, got_datetime = t, true
end

have_info = false
Expand Down Expand Up @@ -2815,13 +2812,12 @@ function find_data(d::Dict, cmd0::String, cmd::String, args...)
elseif (tipo == 2) # Two inputs (but second can be optional in some modules)
# Accepts "input1 input2"; "input1", arg1; "input1", data=input2; arg1, arg2; data=(input1,input2)
if (got_fname != 0)
if (args[1] === nothing && data_kw === nothing)
(args[1] === nothing && data_kw === nothing) &&
return cmd, 1, args[1], args[2] # got_fname = 1 => all data is in cmd
elseif (args[1] !== nothing)
(args[1] !== nothing) &&
return cmd, 2, args[1], args[2] # got_fname = 2 => data is in cmd and arg1
elseif (data_kw !== nothing && length(data_kw) == 1)
return cmd, 2, data_kw, args[2] # got_fname = 2 => data is in cmd and arg1
end
(data_kw !== nothing && length(data_kw) == 1) &&
return cmd, 2, data_kw, args[2] # got_fname = 2 => data is in cmd and arg1
else
if (args[1] !== nothing && args[2] !== nothing)
return cmd, 0, args[1], args[2] # got_fname = 0 => all data is in arg1,2
Expand All @@ -2840,13 +2836,12 @@ function find_data(d::Dict, cmd0::String, cmd::String, args...)
(args[1] !== nothing || data_kw !== nothing) && error("Cannot mix input as file names and numeric data.")
return cmd, 1, args[1], args[2], args[3] # got_fname = 1 => all data is in cmd
else
if (args[1] === nothing && args[2] === nothing && args[3] === nothing)
(args[1] === nothing && args[2] === nothing && args[3] === nothing) &&
return cmd, 0, args[1], args[2], args[3] # got_fname = 0 => ???
elseif (data_kw !== nothing && length(data_kw) == 3)
(data_kw !== nothing && length(data_kw) == 3) &&
return cmd, 0, data_kw[1], data_kw[2], data_kw[3] # got_fname = 0 => all data in arg1,2,3
else
return cmd, 0, args[1], args[2], args[3]
end

return cmd, 0, args[1], args[2], args[3]
end
end
end
Expand Down
9 changes: 4 additions & 5 deletions src/gdal_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,7 @@ end
function trim_SUBDATASET_str(sds::String)
# If present, trim the initial "SUBDATASET_X_NAME=" som a subdataset string name
ind = 0
if (startswith(sds, "SUBDATASET_"))
((ind = findfirst('=', sds)) === nothing) && error("Badly formed SUBDATASET string")
end
(startswith(sds, "SUBDATASET_") && (ind = findfirst('=', sds)) === nothing) && error("Badly formed SUBDATASET string")
sds_name = sds[ind+1:end]
end

Expand Down Expand Up @@ -680,7 +678,7 @@ Example:
I = gdalshade("hawaii_south.grd", C="faa.cpt", zfactor=4);
### Returns
A GMT Image
A GMT RGB Image
"""
function gdalshade(fname; kwargs...)
d = KW(kwargs)
Expand Down Expand Up @@ -711,11 +709,12 @@ http://www.textureshading.com/Home.html
image is more handy.
### Returns
A UInt16 GMT Image
A UInt8 (or 16) GMT Image
"""
function texture_img(G::GMTgrid; detail=1.0, contrast=2.0, uint16=false)
texture = deepcopy(G.z)
terrain_filter(texture, detail, size(G,1), size(G,2), G.inc[1], G.inc[2], 0)
(startswith(G.proj4, "+proj=merc")) && fix_mercator(texture, detail, size(G,1), size(G,2), G.range[3], G.range[4])
terrain_image_data(texture, contrast, size(G,1), size(G,2), 0.0, (uint16) ? 65535.0 : 255.0)
mat = (uint16) ? round.(UInt16, texture) : round.(UInt8, texture)
Go = mat2img(mat, hdr=grid2pix(G), proj4=G.proj4, wkt=G.wkt, noconv=true, layout=G.layout*"a")
Expand Down
12 changes: 8 additions & 4 deletions src/libgmt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,14 @@ function get_common_R(API::Ptr{Cvoid})
end
=#

function terrain_filter(data, detail, nrows, ncols, xinc, yinc, coord_type, center_lat=0.0, progress=C_NULL)
terrain_filter(data, detail, nrows, ncols, xinc, yinc, coord_type, center_lat=0.0, progress=C_NULL) =
ccall((:terrain_filter, thelib), Cint, (Ptr{Cfloat}, Cdouble, Cint, Cint, Cdouble, Cdouble, Cint, Cdouble, Ptr{Cvoid}), data, detail, nrows, ncols, xinc, yinc, coord_type, center_lat, progress)
end

function terrain_image_data(data, contrast, nrows, ncols, image_min=0., image_max=65535.0)
terrain_image_data(data, contrast, nrows, ncols, image_min=0., image_max=65535.0) =
ccall((:terrain_image_data, thelib), Cint, (Ptr{Cfloat}, Cint, Cint, Cdouble, Cdouble, Cdouble), data, nrows, ncols, contrast, image_min, image_max)
end

fix_mercator(data, detail, nrows, ncols, lat1, lat2) =
ccall((:fix_mercator, thelib), Cvoid, (Ptr{Cfloat}, Cdouble, Cint, Cint, Cdouble, Cdouble), data, nrows, ncols, detail, lat1, lat2)

fix_polar_stereographic(data, detail, nrows, ncols, center_res) =
ccall((:fix_polar_stereographic, thelib), Cvoid, (Ptr{Cfloat}, Cdouble, Cint, Cint, Cdouble), data, nrows, ncols, detail, center_res)
2 changes: 2 additions & 0 deletions test/test_avatars.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#plot([0.0 0; 1.1 1], theme=(name=:modern,), Vd=dbg2)
plot(1:4, rand(4,4), theme=(name=:none, save=true), leg=true) # Resets default conf and delete the theme_jl file
#@test startswith(plot!([1 1], marker=(:r, [2 3]), Vd=dbg2), "psxy -R -J -Sr")
xy = [0. 0.; 1 1; 2 1; 0 0];
plot(xy, region=(-1,3,-1,2), clip=xy, frame=(axes=:WEsn, grid=0.2, fill=:darkgray), Vd=dbg2);
@test occursin(" -Sr", plot!([1 1], marker=(:r, [2 3]), Vd=dbg2))
@test_throws ErrorException("Wrong number of extra columns for marker (r). Got 3 but expected 2") plot!([1 1], marker=(:r, [2 3 4]), Vd=dbg2)
@test_throws ErrorException("Unknown graphics file extension (.ppf)") plot(rand(5,2), savefig="la.ppf")
Expand Down
4 changes: 3 additions & 1 deletion test/test_gdal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Gdal.GDALDestroyDriverManager()
gdalinfo(ds_small, [""]);
#gdaldem("utmsmall.tif", "hillshade", ["-q"], save="lixo.nc");
#rm("lixo.nc")
gdaldem(ds_small, "hillshade", ["-q"]);
gdaldem(ds_small, "hillshade", ["-q", "-s", "1"]);
gdaltranslate(ds_small, [""]);
gdaltranslate("utmsmall.tif", R="442000/445000/3747000/3750000");
try # Stupid Macports gdal does not have AAIGrid driver
Expand All @@ -86,6 +86,7 @@ Gdal.GDALDestroyDriverManager()
end

gdalwarp(ds_small, [""]);
ds_warped = gdalwarp("utmsmall.tif", ["-of","MEM","-t_srs","EPSG:4326"], I=0.005, gdataset=true)
ds_warped = gdalwarp("utmsmall.tif", ["-of","MEM","-t_srs","EPSG:4326"], gdataset=true)
@test Gdal.width(ds_warped) == 109
@test Gdal.height(ds_warped) == 91
Expand Down Expand Up @@ -227,5 +228,6 @@ Gdal.GDALDestroyDriverManager()
GMT.blendimg!(I1, I2)
I1 = mat2img(reshape(collect(UInt8(1):UInt8(60)), 4, 5, 3))
I1.layout = "TRPa"
I2.image[end] = UInt8(200) # to make tests visit another if branch
GMT.blendimg!(I1, I2)
end

0 comments on commit 9a80df1

Please sign in to comment.