-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from JuliaAstro/ml/pythoncall
- Loading branch information
Showing
21 changed files
with
81 additions
and
13,124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ jobs: | |
fail-fast: false | ||
matrix: | ||
version: | ||
- '1.3' | ||
- '1.6' | ||
- '1' | ||
- 'nightly' | ||
os: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,4 @@ docs/site/ | |
Manifest.toml | ||
|
||
# End of https://www.gitignore.io/api/julia | ||
.CondaPkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[deps] | ||
astropy = ">=4,<6" # 4, 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.