-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now includes the submodule constants for astropy like constants
- Loading branch information
1 parent
41da3b0
commit c1e06fe
Showing
18 changed files
with
387 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .functions import * | ||
from .classes import * |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
wiens_displacement_const = 2.897771955*10**(-3) # m K | ||
boltzmans_const = 1.380649*10**(-23) # J/K | ||
speed_light = 299792458 # m/s | ||
plancks_const = 6.62607015*10**(-34) # Js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .constants import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import numpy as np | ||
|
||
class Constant: | ||
''' Class for defining all constants | ||
For more functionality use astropy's constant instead | ||
https://docs.astropy.org/en/stable/constants/ | ||
Most of the constants were taken from the page above | ||
Example: | ||
>>> c = Constant('c', 299792458, 'm/s', 'Speed of light') | ||
>>> c | ||
299792458 | ||
''' | ||
|
||
def __init__(self, symbol, value, unit, name): | ||
self.symbol = symbol | ||
self.value = value | ||
self.unit = unit | ||
self.name = name | ||
|
||
def __repr__(self): | ||
return f'Constant({self.symbol}, {self.value}, {self.unit}, {self.name})' | ||
|
||
def __str__(self): | ||
return f'Name = {self.name}\nValue = {self.value}\nUnit = {self.unit}' | ||
|
||
def __add__(self, other): | ||
if isinstance(other, Constant): | ||
return self.value + other.value | ||
else: | ||
return self.value + other | ||
|
||
def __sub__(self, other): | ||
if isinstance(other, Constant): | ||
return self.value - other.value | ||
else: | ||
return self.value - other | ||
|
||
def __mul__(self, other): | ||
if isinstance(other, Constant): | ||
return self.value * other.value | ||
else: | ||
return self.value * other | ||
|
||
def __truediv__(self, other): | ||
if isinstance(other, Constant): | ||
return self.value / other.value | ||
else: | ||
return self.value / other | ||
|
||
def __pow__(self, other): | ||
if isinstance(other, Constant): | ||
return self.value ** other.value | ||
else: | ||
return self.value ** other | ||
|
||
atm = Constant('atm', 101325, 'Pa', 'Standard Atmosphere') | ||
|
||
au = Constant('AU', 1.49597871e+11, 'm', 'Astronomical Unit') | ||
|
||
b_wien = Constant('b', 2.897771955e-3, 'm K', 'Wiens Displacement constant') | ||
|
||
c = Constant('c', 299792458, 'm/s', 'Speed of light') | ||
|
||
e = Constant('e', 1.60217663e-19, 'C', 'Electron Charge') | ||
|
||
g0 = Constant('g', 9.80665, 'm/s2', 'Standard acceleration of gravity') | ||
|
||
G = Constant('G', 6.6743e-11, 'm3 / (kg s2)', 'Gravitational constant') | ||
|
||
h = Constant('h', 6.62607015e-34, 'Js', 'Planck constant') | ||
|
||
hbar = Constant('hbar', 1.05457182e-34, 'Js', 'Reduced Planck constant') | ||
|
||
k_B = Constant('kB', 1.380649e-23, 'J/K', 'Boltzman constant') | ||
|
||
L_bol0 = Constant('L_bol0', 3.0128e+28, 'W', 'Luminosity for absolute bolometric magnitude 0') | ||
|
||
L_sun = Constant('L_sun', 3.828e+26, 'W', 'Nominal Solar Luminosity') | ||
|
||
m_e = Constant('m_e', 9.1093837e-31, 'kg', 'Electron mass') | ||
|
||
m_n = Constant('m_n', 1.6749275e-27, 'kg', 'Neutron mass') | ||
|
||
m_p = Constant('m_p', 1.67262192e-27, 'kg', 'Proton mass') | ||
|
||
M_earth = Constant('M_earth', 5.97216787e+24, 'kg', 'Earth mass') | ||
|
||
M_jup = Constant('M_jup', 1.8981246e+27, 'kg', 'Jupiter mass') | ||
|
||
M_sun = Constant('M_sun', 1.98840987e+30, 'kg', 'Solar mass') | ||
|
||
pc = Constant('pc', 3.08567758e+16, 'm', 'Parsec') | ||
|
||
R_earth = Constant('R_earth', 5.97216787e+24, 'm', 'Nominal Earth equatorial radius') | ||
|
||
R_jup = Constant('R_jup', 1.8981246e+27, 'm', 'Nominal Jupiter equatorial radius') | ||
|
||
R_sun = Constant('R_sun', 1.98840987e+30, 'm', 'Nominal solar radius') | ||
|
||
sigma_sb = Constant('sigma_sb', 5.67037442e-08, 'W / (K4 m2)', 'Stefan-Boltzmann constant') | ||
|
||
u = Constant('u', 1.66053907e-27, 'kg', 'Atomic mass unit') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import numpy as np | ||
from astroedu import constants as const | ||
|
||
def wiens_law(a): | ||
''' Computes the peak wavelengths if temperatures are passed | ||
Computes the temperatures if peak wavelengths are passed | ||
0 must not be passed as an argument since 1/0 will fail | ||
Args: | ||
a -- float or 1D np.ndarray, peak wavelength or temperature | ||
Returns: | ||
float or 1D np.ndarray, peak wavelength or temperature | ||
Example: | ||
To get peak wavelengths pass the temperatures to arg a | ||
>>> T = np.arange(0.1, 3000, 10) # K | ||
>>> wiens_law(T) | ||
To get a temperature pass a wavelength | ||
>>> l = 500*10**(-9) # m | ||
>>> wiens_law(l) | ||
''' | ||
return const.b_wien/a | ||
|
||
def plancks_law(T, l): | ||
''' Computes the blackbody curve over wavelength range l for temp T | ||
using Planck's law | ||
Args: | ||
T -- float, temperature of blackbody | ||
l -- float or 1D np.ndarray, wavelengths | ||
Returns: | ||
float or 1D np.ndarray, intensity in units: 10^4 W sr^-1 m^-2 nm^-1 | ||
Example: | ||
>>> plancks_law(300, 560*10**-9) | ||
''' | ||
return 2*const.h*const.c**2/l**5 * 1/(np.exp(const.h*const.c/(l*const.k_B*T))-1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[metadata] | ||
# replace with your username: | ||
name = astroedu | ||
version = 0.1.1a1 | ||
version = 0.2.0a1 | ||
author = Dimitrios Theodorakis | ||
author_email = [email protected] | ||
description = A python package for astronomy educators | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .functions import * | ||
from .classes import * |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .constants import * |
Oops, something went wrong.