A package containing small interactives, datasets, functions etc for teaching astronomy.
Contributors:
- Dimitrios Theodorakis
- Ankit Barik, planetMagFields module, , github.com/AnkitBarik/planetMagFields
To install astroedu run
pip install astroedu
or with conda
conda install -c conda-forge astroedu
astroedu interactive wiens_law
Loads the interactive notebook file exploring Wien's Law. Jupyter lab arguments can be passed after the interactive name for instance:
astroedu interactive wiens_law --port 9999
To use a data set import the utitlity function load_data
from the datasets module:
from astroedu.datasets import load_data
Then you can load a data set by passing its name as a string to load_data
.
planets = load_data('planets')
The function returns a Pandas dataframe.
If the optional keyword argument info
is True
then a brief explanation of the data is printed before the dataframe is loaded.
Astropy like constants for ease of access. For full functionality use the astropy constants submodule.
>>> from astroedu.constants import c
>>> c
Constant(c, 299792458, m/s, Speed of light)
or
>>> import astroedu.constants as const
>>> print(const.c)
Name = Speed of light
Value = 299792458
Unit = m/s
Constants can perform simple maths with other constants or int/float/np.array. The returned value is an int/float/np.array not a Constant class instance:
>>> from astroedu.constants import c, m_e
>>> c*m_e
2.7309245302881346e-22
Some basic functions have been implemented:
>>> from astroedu.functions import wiens_law
>>> wiens_law(1000)
2.897771955e-06
You can use the get_sun() function to quickly display images of the Sun if you have SunPy installed.
# From the command line:
astroedu get_sun # plots today's Sun
astroedu get_sun 2022/02/02 # plots Sun on diff date than today
astroedu get_sun save # plots then saves image
astroedu get_sun 2022/02/02 save
# In .py or IPython
>>> from astroedu.functions import get_sun
>>> get_sun() # plots today's Sun
>>> get_sun('2022/02/02') # plots Sun on diff date than today
>>> get_sun('2022/02/02', save=True) # plots then saves image
Before you can save anything run:
astroedu build
in the terminal. This creates a config.ini file which contains paths to your astroedu install and Documents directory. The get_sun() function will create the directory astroedu in your Documents directory if it doesn't exist and save files there.
Some classes which are hopefully useful!
The Body2D class is the main body class for planets and other objects.
Usage - Body2D(str-name, float-x pos in AU, float-y pos in AU, float-radius in km, float-mass in kg)
for instance:
>>> from astroedu.classes import Body2D
>>> moon = Body2D('Moon', 0, 0, 1737.4, 0.07346*10**24)
>>> print(moon)
Moon at (0.00, 0.00) AU with r = 1.74E+03 km and m = 7.35E+22 kg
There are pre-defined class methods for the Earth, Sun, and Moon:
>>> from astroedu.classes import Body2D
>>> moon = Body2D.Moon(0, 0)
>>> print(moon)
Moon at (0.00, 0.00) AU with r = 1.74E+03 km and m = 7.35E+22 kg
The class has built in methods. For instance to calculate the tides on the Earth due to the Moon:
>>> from astroedu.classes import Body2D
>>> earth = Body2D.Earth(0, 0)
>>> moon = Body2D.Moon(384400000/au, 0)
>>> forces = earth.tides(moon, step=0.25, scale=5.972*10**24)
Documentation coming soon. More methods will be added at a later date including calculating gravitational potentials and plotting tides & potentials.
planetMagFields by Ankit Barik. , github.com/AnkitBarik/planetMagFields
See Ankit's GitHub for usage. Note: cartopy is required for some plots which requires these packages to be installed, GEOS and PROJ. Some functions also require other libraries such as SHTns (no Windows version) and PyEVTK, see Ankit's GitHub for more info.
Since the dataset location is defined relative to the astroedu install there is no need to specify a datDir for instance:
>>> import matplotlib.pyplot as plt
>>> from astroedu.planetmagfields import *
>>> p = planet(name='jupiter')
>>> # not p = planet(name='jupiter',datDir='planetmagfields/data/')
>>> p.plot(r=0.85,proj='Mollweide')
>>> plt.show()