Skip to content

Commit

Permalink
Merge pull request #47 from JuliaAstro/ml/pythoncall
Browse files Browse the repository at this point in the history
  • Loading branch information
mileslucas authored Dec 29, 2022
2 parents 4c2f0fe + 74fa7ad commit 6c8849b
Show file tree
Hide file tree
Showing 21 changed files with 81 additions and 13,124 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1.3'
- '1.6'
- '1'
- 'nightly'
os:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ docs/site/
Manifest.toml

# End of https://www.gitignore.io/api/julia
.CondaPkg
2 changes: 2 additions & 0 deletions CondaPkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[deps]
astropy = ">=4,<6" # 4, 5
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SkyCoords"
uuid = "fc659fc5-75a3-5475-a2ea-3da92c065361"
authors = "Kyle Barbary, Mosé Giordano, and contributors"
version = "1.1.0"
version = "1.2.0"

[deps]
AstroAngles = "5c4adb95-c1fc-4c53-b4ea-2a94080c53d2"
Expand All @@ -13,4 +13,4 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
AstroAngles = "0.1"
ConstructionBase = "1"
StaticArrays = "0.8, 0.9, 1"
julia = "1.3"
julia = "1.6"
4 changes: 3 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[deps]
AstroAngles = "5c4adb95-c1fc-4c53-b4ea-2a94080c53d2"
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
56 changes: 56 additions & 0 deletions test/astropy.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using PythonCall

## python imports
apc = pyimport("astropy.coordinates")

## data generation
N = 1000
const lons = 2pi .* rand(rng, N) # (0, 2π)
const lats = pi .* (rand(rng, N) .- 0.5) # (-π, π)

# get the astropy frames from the julia type
astropy_conversion(::Type{<:ICRSCoords}) = apc.ICRS
astropy_conversion(::Type{<:FK5Coords{F}}) where {F} = apc.FK5(equinox="J$F")
astropy_conversion(::Type{<:GalCoords}) = apc.Galactic

function test_against_astropy(intype, outtype)
## get julia values
output_coords = map((lon, lat) -> convert(outtype, intype(lon, lat)), lons, lats)
output_lons = map(lon, output_coords)
output_lats = map(lat, output_coords)

## get astropy values
ap_input_coord = astropy_conversion(intype)
ap_output_coord = astropy_conversion(outtype)
input_coord_list = apc.SkyCoord(lons, lats, unit=("rad", "rad"), frame=ap_input_coord)
output_coord_list = input_coord_list.transform_to(ap_output_coord)
# have to copy data from python
ap_output_lons = pyconvert(Vector, output_coord_list.spherical.lon.rad)
ap_output_lats = pyconvert(Vector, output_coord_list.spherical.lat.rad)

@test output_lons ap_output_lons
@test output_lats ap_output_lats

end

# Float32 has a large tolerance compared to Float64 and BigFloat, but here we
# are more interested in making sure that the infrastructure works for different
# floating types.
@testset "Testing $F" for (F, TOL) in (
(Float32, 0.2),
(Float64, 0.0001),
(BigFloat, 0.0001),
)

systems = (
ICRSCoords{F},
FK5Coords{2000,F},
FK5Coords{1975,F},
GalCoords{F},
)

@testset "$IN_SYS --> $OUT_SYS"for IN_SYS in systems, OUT_SYS in systems
test_against_astropy(IN_SYS, OUT_SYS)

end
end
Loading

0 comments on commit 6c8849b

Please sign in to comment.