Skip to content

Commit

Permalink
Merge pull request #44 from JuliaGeo/compat71
Browse files Browse the repository at this point in the history
Migrate to Julia 0.7 and 1.0 compatibility
  • Loading branch information
garborg authored Aug 22, 2018
2 parents cbbed57 + 1cf7c3a commit e4bac3b
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 53 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ os:
- osx
- linux
julia:
- 0.6
- 1.0
- nightly
notifications:
email: false
Expand All @@ -12,6 +12,6 @@ matrix:
- julia: nightly
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia --check-bounds=yes -e 'Pkg.clone(pwd()); Pkg.build("Geodesy"); Pkg.test("Geodesy"; coverage=true)'
- julia --check-bounds=yes -e 'using Pkg; Pkg.clone(pwd()); Pkg.build("Geodesy"); Pkg.test("Geodesy"; coverage=true)'
after_success:
- julia -e 'cd(Pkg.dir("Geodesy")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia -e 'using Pkg; cd(Pkg.dir("Geodesy")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
julia 0.6
julia 0.7
CoordinateTransformations 0.5.0
StaticArrays 0.5.0
37 changes: 14 additions & 23 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
- julia_version: 1
- julia_version: nightly

platform:
- x86 # 32-bit
- x64 # 64-bit

# Uncomment the following lines to allow failures on nightly julia
# (tests will run but not make your overall status red)
matrix:
allow_failures:
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
- julia_version: nightly

branches:
only:
Expand All @@ -22,24 +25,12 @@ notifications:
on_build_status_changed: false

install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# If there's a newer build queued for the same PR, cancel this one
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
throw "There are newer queued builds for this pull request, failing early." }
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))

build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"Geodesy\"); Pkg.build(\"Geodesy\")"
- echo "%JL_BUILD_SCRIPT%"
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"Geodesy\")"
- echo "%JL_TEST_SCRIPT%"
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"
1 change: 1 addition & 0 deletions src/Geodesy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ __precompile__()

module Geodesy

using Dates
using CoordinateTransformations
using StaticArrays

Expand Down
2 changes: 1 addition & 1 deletion src/datum_transformations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ datum_shift_ECEF(::GDA94, itrf::ITRF{Y}) where {Y} = GDA94_from_ITRF_Dawson2010(
datum_shift_ECEF(itrf::ITRF{Y}, ::GDA94) where {Y} = inv(GDA94_from_ITRF_Dawson2010(Y, itrf.epoch))

# TODO - time-based transformation!
# make_datum_transform_ECEF{Y}(::ITRF{Y,Void}, ::GDA94) =
# make_datum_transform_ECEF{Y}(::ITRF{Y,Nothing}, ::GDA94) =
10 changes: 5 additions & 5 deletions src/datums.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ struct WGS84{GpsWeek} <: Datum
WGS84{GpsWeek}() where {GpsWeek} = check_wgs84_params(new{GpsWeek}())
end

WGS84() = WGS84{Void}()
WGS84() = WGS84{Nothing}()

check_wgs84_params(wgs84::WGS84{Void}) = wgs84
check_wgs84_params(wgs84::WGS84{Nothing}) = wgs84

@generated function check_wgs84_params(wgs84::WGS84{GpsWeek}) where GpsWeek
if GpsWeek <= WGS84_frames_last_updated && GpsWeek valid_WGS84_frame_weeks
Expand All @@ -69,7 +69,7 @@ check_wgs84_params(wgs84::WGS84{Void}) = wgs84
end
end

Base.show(io::IO, ::WGS84{Void}) = print(io,"WGS84")
Base.show(io::IO, ::WGS84{Nothing}) = print(io,"WGS84")
Base.show(io::IO, ::WGS84{W}) where {W} = print(io,"WGS84 (G$W)")

ellipsoid(::Type{WGS84}) = wgs84_ellipsoid
Expand Down Expand Up @@ -127,10 +127,10 @@ end
end
end

ITRF{Year}() where {Year} = ITRF{Year,Void}(nothing)
ITRF{Year}() where {Year} = ITRF{Year,Nothing}(nothing)
ITRF{Year}(epoch) where {Year} = ITRF{Year,typeof(epoch)}(epoch)

Base.show(io::IO, ::ITRF{Y,Void}) where {Y} = print(io,"ITRF{$Y}")
Base.show(io::IO, ::ITRF{Y,Nothing}) where {Y} = print(io,"ITRF{$Y}")
Base.show(io::IO, itrf::ITRF{Y}) where {Y} = print(io,"ITRF{$Y}($(itrf.epoch))")

ellipsoid(::ITRF) = grs80
Expand Down
4 changes: 3 additions & 1 deletion src/distances.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using LinearAlgebra: norm

"""
distance(a, b, [datum = wgs84])
The Cartesian distance between points `a` and `b`. Uses `datum` to perform
transformations as necessary, and unlike other *Geodesy* functions, this defaults
to use the common WGS-84 datum for convenience.
"""
distance(a::T, b::T) where {T <: AbstractVector} = vecnorm(a-b)
distance(a::T, b::T) where {T <: AbstractVector} = norm(a-b)

# Automatic transformations to ECEF
# Uses wgs84 datum as a default. In most cases, the datum choice will only make
Expand Down
2 changes: 1 addition & 1 deletion src/polar_stereographic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function polarst_inv(northp::Bool, k0::Float64, tm::TransverseMercator, x, y) #
secphi = hypot(1.0, tau)
k = (rho > 0 ? (rho / tm.a) * secphi * sqrt(tm.e2m + tm.e2 / (secphi*secphi)) : k0)
lat = (northp ? 1 : -1) * atand(tau)
lon = atan2(x, northp ? -y : y ) * 180/pi
lon = atan(x, northp ? -y : y ) * 180/pi
gamma = AngNormalize(northp ? lon : -lon)

return (lat, lon, gamma, k)
Expand Down
8 changes: 4 additions & 4 deletions src/transformations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ LLAfromECEF(datum::Datum) = LLAfromECEF(ellipsoid(datum))
h -= trans.a
else # Ellipsoidal
# Treat prolate spheroids by swapping r and z here and by switching
# the arguments to phi = atan2(...) at the end.
# the arguments to phi = atan(...) at the end.
p = (R / trans.a) * (R / trans.a)
q = trans.e2m * (ecef.z / trans.a) * (ecef.z / trans.a)
r = (p + q - trans.e4a) / 6
Expand Down Expand Up @@ -111,7 +111,7 @@ LLAfromECEF(datum::Datum) = LLAfromECEF(ellipsoid(datum))
u += T + (T != 0 ? r2 / T : 0.0)
else
# T is complex, but the way u is defined the result is real.
ang = atan2(sqrt(-disc), -(S + r3))
ang = atan(sqrt(-disc), -(S + r3))
# There are three possible cube roots. We choose the root which
# avoids cancellation. Note that disc < 0 implies that r < 0.
u += 2 * r * cos(ang / 3)
Expand Down Expand Up @@ -151,8 +151,8 @@ LLAfromECEF(datum::Datum) = LLAfromECEF(ellipsoid(datum))
h = - trans.a * (trans.f >= 0 ? trans.e2m : 1.0) * H / trans.e2a
end
end
lat = 180 * atan2(sphi, cphi) / pi
lon = 180 * atan2(slam, clam) / pi
lat = 180 * atan(sphi, cphi) / pi
lon = 180 * atan(slam, clam) / pi

return LLA(lat, lon, h)
end
Expand Down
20 changes: 10 additions & 10 deletions src/transverse_mercator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ end

function atan2d(y, x)
# In order to minimize round-off errors, this function rearranges the
# arguments so that result of atan2 is in the range [-pi/4, pi/4] before
# arguments so that result of atan is in the range [-pi/4, pi/4] before
# converting it to degrees and mapping the result to the correct
# quadrant.
q = 0
Expand All @@ -143,7 +143,7 @@ function atan2d(y, x)
q = q + 1
end
# here x >= 0 and x >= abs(y), so angle is in [-pi/4, pi/4]
ang = atan2(y, x) * 180 / pi
ang = atan(y, x) * 180 / pi
# Note that atan2d(-0.0, 1.0) will return -0. However, we expect that
# atan2d will not be called with y = -0. If need be, include
#
Expand Down Expand Up @@ -364,8 +364,8 @@ function TransverseMercator(a::Float64, f::Float64, ::Type{Val{MaxPow}}) where M
a1 = b1 * a
o = 1
d = n
_alp = Vector{Float64}(MaxPow)
_bet = Vector{Float64}(MaxPow)
_alp = Vector{Float64}(undef, MaxPow)
_bet = Vector{Float64}(undef, MaxPow)
for l = 1:MaxPow
m = MaxPow - l
_alp[l] = d * polyval(alpcoeff[o:o+m], n) / alpcoeff[o + m + 1]
Expand All @@ -375,8 +375,8 @@ function TransverseMercator(a::Float64, f::Float64, ::Type{Val{MaxPow}}) where M
end
# Post condition: o == sizeof(alpcoeff) / sizeof(real) &&
# o == sizeof(betcoeff) / sizeof(real)
alp = (_alp...)
bet = (_bet...)
alp = (_alp...,)
bet = (_bet...,)

return TransverseMercator{MaxPow}(a,f,e2,es,e2m,c,n,a1,b1,alp,bet)
end
Expand Down Expand Up @@ -509,7 +509,7 @@ function transverse_mercator_forward(lon0, lat, lon, k0, tm::TransverseMercator{
if (lat != 90)
tau = sphi / cphi
taup = taupf(tau, tm.e2) # TODO maybe switch to the C++ version of taupf using tm.es?
xip = atan2(taup, clam)
xip = atan(taup, clam)
# Used to be
# etap = Math::atanh(sin(lam) / cosh(psi));
etap = asinh(slam / hypot(taup, clam))
Expand Down Expand Up @@ -731,7 +731,7 @@ function transverse_mercator_reverse(lon0, x, y, k0, tm::TransverseMercator{MaxP
etap = eta + ai * xip0 + ar * etap0

# Convergence and scale for Gauss-Schreiber TM to Gauss-Krueger TM.
gamma = atan2(yi1, yr1) * 180/pi
gamma = atan(yi1, yr1) * 180/pi
k = tm.b1 / hypot(yr1, yi1)
# JHS 154 has
#
Expand All @@ -744,12 +744,12 @@ function transverse_mercator_reverse(lon0, x, y, k0, tm::TransverseMercator{MaxP
r = hypot(s, c)

if (r != 0)
lon = atan2(s, c) * 180/pi # Krueger p 17 (25)
lon = atan(s, c) * 180/pi # Krueger p 17 (25)

# Use Newton's method to solve for tau
sxip = sin(xip)
tau = tauf(sxip/r, tm.e2) # TODO maybe change to C++ es version
gamma += atan2(sxip * tanh(etap), c) * 180/pi # Krueger p 19 (31)
gamma += atan(sxip * tanh(etap), c) * 180/pi # Krueger p 19 (31)
lat = atand(tau)
# Note cos(phi') * cosh(eta') = r
k *= sqrt(tm.e2m + tm.e2 / (1 + tau*tau)) * hypot(1.0, tau) * r
Expand Down
5 changes: 3 additions & 2 deletions test/datum_transformations.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Dates
using LinearAlgebra: I, norm
using CoordinateTransformations
using Base.Dates

@testset "Datum transforms" begin

Expand All @@ -16,7 +17,7 @@ using Base.Dates
# Test inverse
epoch = Date(2010,6,16)
trans = datum_shift_ECEF(ITRF{2008}(epoch), GDA94) datum_shift_ECEF(GDA94, ITRF{2008}(epoch))
@test trans.linear eye(3)
@test trans.linear Matrix(1.0I, 3, 3)
@test isapprox(trans.translation, zeros(3), atol=10*eps())
end

Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Geodesy
using Base.Test
using Test

################################################
### Helpers for testing approximate equality ###
Expand Down
2 changes: 1 addition & 1 deletion test/transverse_mercator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# File has 5000 entries of lon between ±50°, lat between ±90° (with UTM scaling 0.9996)
# Adapted from Charles Karney's test data (http://zenodo.org/record/32470#.VzF-Krp97CI)
f = open("TMcoords_lite.bin") # Binary file, Float64: lat, lon, x, y, γ, k
tmdat = read(f, Float64, (5000, 6))
tmdat = read!(f, Array{Float64}(undef, (5000, 6)))
close(f)

tm = Geodesy.TransverseMercator(wgs84)
Expand Down

0 comments on commit e4bac3b

Please sign in to comment.