Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Add 'orbit' unit for orbital period
Browse files Browse the repository at this point in the history
  • Loading branch information
lpsinger committed Apr 27, 2021
1 parent bcc389a commit 690d11b
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Modules
orbit
fov
skygrid
units
21 changes: 21 additions & 0 deletions doc/reference/units.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Units (`dorado.scheduling.units`)
=================================
.. automodule:: dorado.scheduling.units

Examples
--------

First, some imports:

>>> from astropy import units as u
>>> from dorado.scheduling import data
>>> from dorado.scheduling import Orbit
>>> from dorado.scheduling.units import equivalencies
>>> from importlib import resources

Load an example two-line element:

>>> with resources.path(data, 'dorado-625km-sunsync.tle') as p:
... orbit = Orbit(p)

>>> u.Quantity('2 orbit').to(u.s, equivalencies=equivalencies.orbital(orbit))
11 changes: 11 additions & 0 deletions dorado/scheduling/units/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Copyright © 2020 United States Government as represented by the Administrator
# of the National Aeronautics and Space Administration. No copyright is claimed
# in the United States under Title 17, U.S. Code. All Other Rights Reserved.
#
# SPDX-License-Identifier: NASA-1.3
#
from .orbital import orbit
from . import equivalencies

__all__ = ('equivalencies', 'orbit')
17 changes: 17 additions & 0 deletions dorado/scheduling/units/equivalencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Copyright © 2020 United States Government as represented by the Administrator
# of the National Aeronautics and Space Administration. No copyright is claimed
# in the United States under Title 17, U.S. Code. All Other Rights Reserved.
#
# SPDX-License-Identifier: NASA-1.3
#
from astropy.units.equivalencies import Equivalency

from .orbital import orbit as _orbit


def orbital(orbit):
return Equivalency([(_orbit, orbit.period.unit,
lambda x: x * orbit.period.value,
lambda x: x / orbit.period.value)],
name='orbital')
24 changes: 24 additions & 0 deletions dorado/scheduling/units/orbital.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Copyright © 2020 United States Government as represented by the Administrator
# of the National Aeronautics and Space Administration. No copyright is claimed
# in the United States under Title 17, U.S. Code. All Other Rights Reserved.
#
# SPDX-License-Identifier: NASA-1.3
#
from astropy.units import def_unit

_ns = globals()

def_unit('orbit', namespace=_ns,
doc='a unit of time equal to one orbital period')

del _ns, def_unit


def _enable():
import inspect
from astropy.units import add_enabled_units
add_enabled_units(inspect.getmodule(_enable))


_enable()

0 comments on commit 690d11b

Please sign in to comment.