Skip navigation

Astropy

Astropy i astroquery

Necessites descarregar el Editor Mu de python a https://codewith.mu

Un cop descarregat i instal.lat necessites clicar a la part inferior dreta on trobaràs un engranatge que significa configuració i allà clicar a "Third party packages" per tal d'instal.lar paquets (nom de python per les biblioteques o llibreries informàtiques), concreteament necessites instal.lar: astropy (càlcul i anàlisi de dades astronòmiques), astoquery (consulta de dades astrononòmiques online), entre altres.

from astropy.coordinates import SkyCoord,EarthLocation  
betelgeuse=SkyCoord.from_name('Betelgeuse') 
print(betelgeuse)
from astroquery.simbad import Simbad
result_table = Simbad.query_object("betelgeuse")
result_table.pprint(show_unit=True)

Stephen-Boltzman law

Calculating temperatures from luminosities using the Stephan-Boltzman law

law


from math import pi
from scipy.constants import sigma # Stefan-Boltzmann constant
"""
    computes luminosity of a star
    using the Stefan-Boltzmann law
    args: R - radius in m
    Teff - effective temperature in K
    returns: luminosity in W
"""
print("Enter star radius in metres:")
R = int(input())
print("Enter star effective temperature in Kelvin:")
Teff = int(input())
def luminosity(R, Teff):
    A = 4*pi * R**2 # local variable for surface area
    return A * sigma * Teff**4
    
print("Luminosity is",luminosity(R,Teff),"W for R=", R, "metres and T=", Teff, "Kelvin using the Stefan Boltzman law")

Black body formula

Intensity depending on wavelengh and temperature

black body
import numpy as np
from scipy.constants import h,c,k
print("Enter star wavelength in metres:")
wavelength= int(input())
print("Enter star temperature in Kelvin:")
T= int(input())
"""
function computes Planck spectrum of a black body
args: numpy arrays
wavelength - wavelength in m
T - temperature in K
returns: intensity in W/m^2/m/sr
"""
def planck_spectrum(wavelength, T):
    return 2*h*c**2 / (wavelength**5 *
    (np.exp(h*c/(wavelength*k*T)) - 1))
print("The intensity following the Planck spectrum formula is" ,planck_spectrum(wavelength,T),"W/m^2/m/sr")