Helpers

Note

The contents of this module are placed here for organisational reasons. They should be imported from astrodynamics.utils.

astrodynamics.utils.helper.format_size(value, binary=False, gnu=False, format='%.1f')

Format a number of bytes like a human readable file size (e.g. 10 kB). By default, decimal suffixes (kB, MB) are used. Passing binary=true will use binary suffixes (KiB, MiB) are used and the base will be 2**10 instead of 10**3. If gnu is True, the binary argument is ignored and GNU-style (ls -sh style) prefixes are used (K, M) with the 2**10 definition. Non-gnu modes are compatible with jinja2’s filesizeformat filter.

Copyright (c) 2010 Jason Moiron and Contributors.

astrodynamics.utils.helper.prefix(prefix, iterable)

Prepend items from iterable with prefix string.

astrodynamics.utils.helper.qisclose(a, b, rel_tol=1e-09, abs_tol=0.0)

Helper function for using math.isclose() with Quantity objects.

astrodynamics.utils.helper.read_only_property(name, docstring=None)

Return property for accessing attribute with name name

Parameters:
  • name – Attribute name
  • docstring – Optional docstring for getter.

Example

class Circle:
    def __init__(self, radius):
        self._radius = radius

    radius = read_only_property('_radius')
astrodynamics.utils.helper.suppress_file_exists_error()

Compatibility function for catching FileExistsError on Python 2

astrodynamics.utils.helper.verify_unit(quantity, unit)

Verify unit of passed quantity and return it.

Parameters:
  • quantityQuantity to be verified. Bare numbers are valid if the unit is dimensionless.
  • unit – Equivalent unit, or string parsable by astropy.units.Unit
Raises:

ValueError – Units are not equivalent.

Returns:

quantity unchanged. Bare numbers will be converted to a dimensionless Quantity.

Example

def __init__(self, a):
    self.a = verify_unit(a, astropy.units.m)