library(xrayr)
library(tibble)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

Creating RADEC vectors

To create RADEC vector using values in deg use ra_dec function.

n <- 5
x <- ra_dec(ra = runif(n, 0, 360), 
            dec = runif(n, -90, 90))

y <- ra_dec(ra = runif(n, 0, 360), 
            dec = runif(n, -90, 90))
x
#> <astro_radec[5]>
#> [1] 01h56m16.8s -06°02'57" 20h01m26.4s -00°24'00" 14h25m05.7s -37°50'31"
#> [4] 03h46m22.8s +41°55'08" 00h10m39.3s +49°03'14"

Also we can create RADEC vectors using radec function. Coords in the ‘hms dms’ format

coords <- c("21h16m19.6s -16d30m31.2s", "12 14 19.6 34 1 1.2s", "J112233.44+551122.33")
radec(coords)
#> <astro_radec[3]>
#> [1] 21h16m19.6s -16°30'31" 12h14m19.6s +34°01'01" 11h22m33.4s +55°11'22"

At the current time NAs support is limited.

ra_dec(c(NA, 2), dec=c(NA, 29))
#> <astro_radec[2]>
#> [1] <NA>                   00h08m00.0s +29°00'00"

Show in tibble

t <- tibble(x = x) %>% 
  bind_cols(tibble(y = y))
t
#> # A tibble: 5 × 2
#>   x                      y                     
#>   <RA DEC>               <RA DEC>              
#> 1 01h56m16.8s -06°02'57" 20h59m25.5s -54°46'46"
#> 2 20h01m26.4s -00°24'00" 04h11m54.9s -17°21'47"
#> 3 14h25m05.7s -37°50'31" 00h49m18.4s -78°32'27"
#> 4 03h46m22.8s +41°55'08" 07h41m21.3s -20°02'02"
#> 5 00h10m39.3s +49°03'14" 09h39m21.2s +85°35'55"

Calc separation between two points

x <- ra_dec(ra = 0,   dec = -29)
y <- ra_dec(ra = 180, dec =  29)
z <- c(x, y)

sep_vinc <- x |> 
  separation(y)

sep_hav <- x |> 
  separation(y, metric = distance_haversine)

waldo::compare(sep_vinc, sep_hav)
#> `old`: 648000.0000
#> `new`: 647999.9939

Convert to galactic

to_galactic(z)
#> $l
#> [1]  20.56922 200.56922
#> 
#> $b
#> [1] -78.50533  78.50533

to_galactic(z, obs_epoch = "B1950")
#> $l
#> [1]  21.69863 201.69863
#> 
#> $b
#> [1] -79.09132  79.09132