Skip to content

Commit

Permalink
timeAngle and sexagesimalAngle.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornbm committed Oct 22, 2014
1 parent bf9e816 commit 44ee2a3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
26 changes: 25 additions & 1 deletion Astro/Util.hs
Expand Up @@ -3,6 +3,7 @@
module Astro.Util ( r_GEO -- From Astrodynamics
, perfectGEO, perfectGEO'
, coerceUt1ToUTC, coerceUtcToUT1
, timeAngle, sexagesimalAngle, dmsAngle
) where

import Astro.Coords
Expand All @@ -11,7 +12,8 @@ import Astro.Time
import Astro.Time.Interop
import Astrodynamics (r_GEO)
import Numeric.Units.Dimensional.Prelude
import Numeric.Units.Dimensional.LinearAlgebra -- (fromTuple)
import Numeric.Units.Dimensional.NonSI (revolution)
import Numeric.Units.Dimensional.LinearAlgebra

import Data.Time.Clock
import Data.Time.Clock.TAI
Expand Down Expand Up @@ -46,3 +48,25 @@ coerceUt1ToUTC (E t) = taiToUTCTime (const 0) $ toAbsoluteTime (E t)
coerceUtcToUT1 :: RealFloat a => UTCTime -> E UT1 a
coerceUtcToUT1 = coerce . fromAbsoluteTime . utcToTAITime (const 0)
where coerce (E t) = E t


-- Angle representations
-- ---------------------

-- | @timeAngle hours minutes seconds@ interprets the given time as an
-- angle, where 24 h corresponds to 360°.
timeAngle :: Floating a => a -> a -> a -> Angle a
timeAngle h m s = h *~ hour + m *~ minute + s *~ second
where
hour = prefix (1 Prelude./ 24) revolution
minute = prefix (1 Prelude./ 60) hour
second = prefix (1 Prelude./ 60) minute

-- | @sexagesimalAngle degrees arcminutes arcseconds@ returns the
-- corresponding angle.
sexagesimalAngle :: Floating a => a -> a -> a -> Angle a
sexagesimalAngle d m s = d *~ degree + m *~ arcminute + s *~ arcsecond

-- | @dmsAngle@ is a synonym for `sexagesimalAngle`.
dmsAngle :: Floating a => a -> a -> a -> Angle a
dmsAngle = sexagesimalAngle
4 changes: 2 additions & 2 deletions examples/Biases.hs
Expand Up @@ -24,7 +24,7 @@ import Astro.Coords
import Astro.Place
import Astro.Place.ReferenceEllipsoid
import Astro.Place.Topocentric
import Astro.Util (perfectGEO, r_GEO)
import Astro.Util (perfectGEO, r_GEO, sexagesimalAngle)
import Numeric.Units.Dimensional.Prelude
import Numeric.Units.Dimensional.LinearAlgebra
import Numeric.Units.Dimensional.AD
Expand Down Expand Up @@ -83,7 +83,7 @@ stations =
, station "Ashgabat" 38.14 58.37 0.134
]

cibinong = GeodeticPlace wgs84 (negate $ 6*~degree + 26*~arcminute + 52*~arcsecond) (106*~degree + 56*~arcminute + 10*~arcsecond) _0
cibinong = GeodeticPlace wgs84 (negate $ sexagesimalAngle 6 26 52) (sexagesimalAngle 106 56 10) _0

-- | Computes sensitivities for a list of ground stations.
-- If the SC is below the GS's horizon Nothing is returned.
Expand Down
6 changes: 3 additions & 3 deletions test/Astro/Place/TestTopocentric.hs
Expand Up @@ -9,7 +9,7 @@ import Astro.Coords
import Astro.Place
import Astro.Place.Topocentric
import Astro.Place.ReferenceEllipsoid
import Astro.Util (perfectGEO)
import Astro.Util (perfectGEO, sexagesimalAngle)
import Test.QuickCheck
import TestUtil
import TestInstances
Expand All @@ -24,8 +24,8 @@ prop_va long f x = cmpE e (f cibinong $ perfectGEO $ long*~degree) (x*~degree)
where
e = 0.1 *~ degree
cibinong = GeodeticPlace wgs84
(negate $ 6*~degree + 26*~arcminute + 52*~arcsecond)
(106*~degree + 56*~arcminute + 10*~arcsecond)
(negate $ sexagesimalAngle 6 26 52)
(sexagesimalAngle 106 56 10)
(0*~meter)

-- | Converting geocentric to topocentric and back should be identity function.
Expand Down
14 changes: 5 additions & 9 deletions test/Astro/Time/SiderealSpec.hs
Expand Up @@ -14,6 +14,7 @@ import Numeric.Units.Dimensional.AD (diff)
import Numeric.Units.Dimensional.NonSI (revolution)
import qualified Prelude

import Astro.Util
import Astro.Util.Cyclic
import Astro.Time
import Astro.Time.Sidereal
Expand All @@ -31,11 +32,11 @@ spec_era = describe "Earth Rotation Angle (era)" $ do

it "is consistent with AsA2009 on 2009-01-01" $
(zeroTwoPi $ era $ clock' 2009 1 1 0 0 0 :: Angle D)
~== 100 *~ degree + 39 *~ arcminute + 39.6557 *~ arcsecond
~== sexagesimalAngle 100 39 39.6557

it "is consistent with AsA2009 on 2010-01-01" $
(zeroTwoPi $ era $ clock' 2010 1 1 0 0 0 :: Angle D)
~== 100 *~ degree + 24 *~ arcminute + 34.2022 *~ arcsecond
~== sexagesimalAngle 100 24 34.2022


spec_phi = describe "Earth's adopted mean angular velocity (phi)" $ do
Expand All @@ -48,13 +49,8 @@ spec_gmst = describe "GMST" $ do

it "is consistent with AsA2009 on 2009-01-01" $
(zeroTwoPi $ gmst' $ clock' 2009 1 1 0 0 0 :: Angle D)
~== 6 *~ h + 43 *~ m + 6.3205 *~ s
~== timeAngle 6 43 6.3205

it "is consistent with AsA2009 on 2010-01-01" $
(zeroTwoPi $ gmst' $ clock' 2010 1 1 0 0 0 :: Angle D)
~== 6 *~ h + 42 *~ m + 9.0298 *~ s

where
h = prefix (1 Prelude./ 24) revolution
m = prefix (1 Prelude./ 60) h
s = prefix (1 Prelude./ 60) m
~== timeAngle 6 42 9.0298

0 comments on commit 44ee2a3

Please sign in to comment.