Skip to contents
library(astrocoords)
#> 
#> Attaching package: 'astrocoords'
#> The following object is masked from 'package:graphics':
#> 
#>     frame

This vignette shows the basic ideas of the package.

You can create sky coordinates in the ICRS frame or in the Galactic frame.

ra_dec(10, 20)
#> <sky|icrs>[1]
#> [1] 00h40m00.0s +20°00'00"
gal_coord(120, -30)
#> <sky|galactic>[1]
#> [1] +120°00'00" -30°00'00"

The general constructor is sky_coord(). You choose the frame with icrs() or galactic().

sky_coord(c(10, 20), c(30, 40), frame = icrs())
#> <sky|icrs>[2]
#> [1] 00h40m00.0s +30°00'00" 01h20m00.0s +40°00'00"
sky_coord(c(120, 121), c(-30, -31), frame = galactic())
#> <sky|galactic>[2]
#> [1] +120°00'00" -30°00'00" +121°00'00" -31°00'00"

You can measure angular separation between two points. The result is in arcseconds.

x1 <- ra_dec(10, 20)
x2 <- ra_dec(11, 21)

separation(x1, x2)
#> [1] 4932.552

You can also transform coordinates between ICRS and Galactic.

x <- ra_dec(c(10, 20), c(30, 40))
g <- transform_to(x, galactic())
g
#> <sky|galactic>[2]
#> [1] +119°59'08" -32°48'23" +128°50'59" -22°32'36"

transform_to(g, icrs())
#> <sky|icrs>[2]
#> [1] 00h40m00.0s +30°00'00" 01h20m00.0s +40°00'00"

Accessors depend on the frame. Use ra() and dec() for ICRS, and l() and b() for Galactic.

x <- ra_dec(10, 20)
ra(x)
#> [1] 10
dec(x)
#> [1] 20

g <- gal_coord(120, -30)
l(g)
#> [1] 120
b(g)
#> [1] -30

You can also parse compact ICRS strings.

parse_coord("J230631.0+155633")
#> <sky|icrs>[1]
#> [1] 23h06m31.0s +15°56'33"

You can build a simple IAU-style source name from ICRS coordinates.

parse_coord("J230631.0+155633") |>
  iau_name(prefix = "SRGA J")
#> [1] "SRGA J230631.0+155633"