astrocalc.coords.unit_conversion module

Convert coordinates from decimal to sexagesimal units and vice-versa

Author

David Young

class unit_conversion(log, settings=False)[source]

Bases: object

The worker class for the unit_conversion module

Key Arguments

  • log – logger

  • settings – the settings dictionary (prob not required)

Usage

Todo

  • add usage info

  • create a sublime snippet for usage

  • add ra_sexegesimal_to_decimal

usage code
- @review: when complete, clean unit_conversion class
- @review: when complete add logging
- @review: when complete, decide whether to abstract class to another module
get()[source]

get the unit_conversion object

Return

  • unit_conversion

- @review: when complete, clean get method
- @review: when complete add logging
dec_sexegesimal_to_decimal(dec)[source]

Convert a declination from sexegesimal format to decimal degrees.

Precision should be respected. If a float is passed to this method, the same float will be returned (useful if unclear which format coordinates are in).

The code will attempt to read the sexegesimal value in whatever form it is passed. Any of the following should be handled correctly:

  • +1:58:05.45341

  • 01:5:05

  • +1 58 05.45341

  • -23h53m05s

Key Arguments

  • dec - DEC in sexegesimal format.

Return

  • decDeg – declination converted to decimal degrees

Usage

Todo

  • replace dryxPython declination_sexegesimal_to_decimal with this version in all my code

  • replace coords_sex_to_dec in all code

from astrocalc.coords import unit_conversion
converter = unit_conversion(
    log=log
)
dec = converter.dec_sexegesimal_to_decimal(
    dec="-23:45:21.23232"
)
print(dec)

# OUTPUT: -23.7558978667
ra_sexegesimal_to_decimal(ra)[source]

Convert a right-ascension from sexegesimal format to decimal degrees.

Precision should be respected. If a float is passed to this method, the same float will be returned (useful if unclear which format coordinates are in).

The code will attempt to read the sexegesimal value in whatever form it is passed. Any of the following should be handled correctly

  • 23:45:21.23232

  • 23h45m21.23232s

  • 23 45 21.23232

  • 2 04 21.23232

  • 04:45  21

Key Arguments

  • ra – ra in sexegesimal units

Return

  • decimalDegrees

Usage

- replace dryxPython ra_sexegesimal_to_decimal with this version in all my code

from astrocalc.coords import unit_conversion
converter = unit_conversion(
    log=log
)
ra = converter.ra_sexegesimal_to_decimal(
    ra="04:45  21"
)
print(ra)

# OUTPUT: 71.3375
ra_decimal_to_sexegesimal(ra, delimiter=':')[source]

Convert a right-ascension between decimal degrees and sexegesimal.

Precision should be respected.

Key Arguments

  • ra – RA in decimal degrees. Will try and convert to float before performing calculation.

  • delimiter – how to delimit the RA units. Default :

Return

  • sexegesimal – ra in sexegesimal units

Usage

Todo

  • replace ra_to_sex from dryxPython in all code

from astrocalc.coords import unit_conversion
converter = unit_conversion(
    log=log
)
ra = converter.ra_decimal_to_sexegesimal(
    ra="-23.454676456",
    delimiter=":"
)
print(ra)

# OUT: 22:26:10.87
dec_decimal_to_sexegesimal(dec, delimiter=':')[source]

Convert a declination between decimal degrees and sexegesimal.

Precision should be respected.

Key Arguments

  • dec – DEC in decimal degrees. Will try and convert to float before performing calculation.

  • delimiter – how to delimit the RA units. Default :

Return

  • sexegesimal – ra in sexegesimal units

Usage

Todo

  • replace dec_to_sex in dryxPython in all code

from astrocalc.coords import unit_conversion
converter = unit_conversion(
    log=log
)
dec = converter.dec_decimal_to_sexegesimal(
    dec="-3.454676456",
    delimiter=":"
)
print(dec)

# OUT: -03:27:16.8
ra_dec_to_cartesian(ra, dec)[source]

Convert an RA, DEC coordinate set to x, y, z cartesian coordinates

Key Arguments

  • ra – right ascension in sexegesimal or decimal degress.

  • dec – declination in sexegesimal or decimal degress.

Return

  • cartesians – tuple of (x, y, z) coordinates

Todo

  • replace calculate_cartesians in all code

Usage

from astrocalc.coords import unit_conversion
converter = unit_conversion(
    log=log
)
x, y, z = converter.ra_dec_to_cartesian(
    ra="23 45 21.23232",
    dec="+01:58:5.45341"
)
print(x, y, z)

# OUTPUT: 0.9973699780687104, -0.06382462462791459, 0.034344492110465606