Python code to fetch astronomy data
Astronomy data can be freely downloaded from the Internet. It is very easy to fetch this data using the astroplan library. So let’s install it.
!pip install astroplan
Code to fetch astronomy data
from astroplan import Observer, FixedTarget
from astroplan.plots import plot_airmass
import matplotlib.pyplot as plt
# Define the observer location
location = Observer(longitude=-0.116 * u.deg, latitude=51.50 * u.deg, elevation=0 * u.m)
# Define the target object
target = FixedTarget.from_name('Vega')
# Plot the airmass plot for the target object
plot_airmass(target, location)
plt.show()
This code uses the astroplan library to define the observer location and the target object. The Observer class is used to define the observer location and the FixedTarget class is used to define the target object. The plot_airmass function is used to plot the airmass plot for the target object and the observer location. The plot is displayed using the matplotlib library.
Note: The example code uses the astropy library’s units module (astropy.units) which is imported as u.
Unit Test
import unittest
from astroplan import Observer, FixedTarget
class TestAstronomyData(unittest.TestCase):
def setUp(self):
self.location = Observer(longitude=-0.116 * u.deg, latitude=51.50 * u.deg, elevation=0 * u.m)
self.target_name = 'Vega'
def test_observer_location(self):
self.assertIsInstance(self.location, Observer)
self.assertEqual(self.location.longitude, -0.116 * u.deg)
self.assertEqual(self.location.latitude, 51.50 * u.deg)
self.assertEqual(self.location.elevation, 0 * u.m)
def test_target_object(self):
target = FixedTarget.from_name(self.target_name)
self.assertIsInstance(target, FixedTarget)
self.assertEqual(target.name, self.target_name)
if __name__ == '__main__':
unittest.main()
This code uses the unittest library to write unit tests for the observer location and target object definitions. The TestAstronomyData class defines the tests and uses the setUp method to initialize the necessary objects and variables. The test_observer_location test checks if the observer location is defined correctly and the test_target_object test checks if the target object is defined correctly.