Skip to content
Snippets Groups Projects
Commit a5745cc5 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Initial commit

parents
Branches
Tags
No related merge requests found
__pycache__
venv/
build/
*.whl
*.egg-info/
# Coords Library
Toy Python module for demonstrating GitLab CI features.
## Example usage
```python
import coords
# -- Returns complete name from Astropy observatory identifier --
print(coords.get_location_name('ekar'))
# 'Mt. Ekar 182 cm. Telescope'
print(coords.get_location_name('lbt'))
# 'Large Binocular Telescope'
# -- Returns object coordinates for a given observatory at current time --
print(coords.get_coords('m31', 'lbt'))
# {'Alt': '47d 13m 43.8866s', 'Az': '62d 25m 55.5019s'}
print(coords.get_coords('m31', 'ekar'))
# {'Alt': '41d 59m 31.3084s', 'Az': '290d 28m 01.2741s'}
```
from .coords_library import get_coords
from .coords_library import get_location_name
from astropy.coordinates import AltAz, EarthLocation, SkyCoord
from astropy.time import Time
def get_location_name(location_id):
return EarthLocation.of_site(location_id).info.name
def get_coords(object_name, location_id):
object_coord = SkyCoord.from_name(object_name)
location = EarthLocation.of_site(location_id)
alt_az = AltAz(location=location, obstime=Time.now())
object_coord = object_coord.transform_to(alt_az)
return {'Alt': format_angle(object_coord.alt), 'Az': format_angle(object_coord.az)}
def format_angle(angle):
return angle.to_string().replace('d', 'd ').replace('m', 'm ')
astropy==4.1
numpy==1.19.5
import setuptools
setuptools.setup(
name="coordslib",
version="0.0.1",
packages=['coords']
)
import unittest
import coords
class TestCoordsLib(unittest.TestCase):
def test_get_coords(self):
result = coords.get_coords('M31', 'ekar')
print(result)
self.assertTrue('Alt' in result)
self.assertTrue('Az' in result)
def test_get_location_name(self):
self.assertEqual('Mt. Ekar 182 cm. Telescope', coords.get_location_name('ekar'))
self.assertEqual('Medicina Radio Telescope', coords.get_location_name('medicina'))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment