/** Library to perform calculations with stellar magnitudes. Stellar
magnitudes use a logarithmic scale in which a decrease in 5 magnitudes
corresponds to a increase of 100 in brightness. This means that a
decrease of 1 magnitude corresponds to exactly 100^(1/5) (that is, the
fifth root of 100) or about 2.5118864.
Smaller numbers are brighter, and the brightest stars have negative
magnitudes.
For absolute magnitude system (AB magnitudes,) see:
https://en.wikipedia.org/wiki/AB_magnitude
*/
/** This returns the ratio by which star 1 is brighter than star 2,
given their magnitudes. */
brightnessRatio[mag1, mag2] := magnitudeDifferenceToRatio[mag1 - mag2]
/** Returns the magnitude you have to *subtract* from star 1 to get the
brightness of star 2. The brightnesses form a true ratio of brightness. */
magnitudeDifference[brightness1, brightness2] := ratioToMagnitudeDifference[brightness1 / brightness2]
/** Given a brightness ratio, this returns the magnitude difference
between the two stars. For example, if you pass in the ratio 100, meaning
100 times brighter, this function returns -5, which is the number you have
to *add* to the magnitude of the original star to get the magnitude that's
100 times brighter. */
ratioToMagnitudeDifference[ratio] := ln[1/ratio] / ln[100^(1/5)]
/** Given a difference in magnitudes, this returns the ratio of their
brightnesses as star1 / star2. For example, if you have star1 with
magnitude of -4, and a dimmer star2 with magnitude of 1, pass in
(mag1 - mag2) (which is -5) which gives a ratio of 100. */
magnitudeDifferenceToRatio[difference] := (100^(1/5))^-difference
/** We can use the sun's irradiance and stated magnitude to allow us to
calculate the flux-to-magnitude relation. Given the following magnitude
(although it's unclear what distance this magnitude was quoted at; the
earth's orbit is eccentric and the sun's output is variable:)
*/
// http://nssdc.gsfc.nasa.gov/planetary/factsheet/sunfact.html
sunMagnitude := -26.74
/** This is the sun's irradiance value at 1 au
See: http://lasp.colorado.edu/home/sorce/data/tsi-data/
Unfortunately, the SORCE satellite is not collecting data since 2013-07-30
due to a battery cell failure.
*/
sunIrradiance := 1361.5 W/m^2
/** Calculate the received power flux (that is, power/area) given its apparent
magnitude (as a dimensionless number.) */
flux[magnitude] := sunIrradiance brightnessRatio[magnitude, sunMagnitude]
/** The inverse of the previous calculation. Given a flux given in power/area,
calculate the apparent magnitude. */
magnitude[flux is heat_flux_density] := sunMagnitude - magnitudeDifference[sunIrradiance, flux]
/** Calculate the flux at distance2 given the flux (flux1) at distance1. */
flux[flux1, distance1, distance2] := flux1 distance1^2 / distance2^2
/** Calculate the apparent magnitude at distance2 given the magnitude at
distance1. */
magnitude[mag1, distance1, distance2] := magnitude[flux[flux[mag1], distance1, distance2]]
/** Calculate the so-called "absolute magnitude" given an apparent magnitude
and the distance it was measured at. Absolute magnitude is a magnitude
measured at a common distance, generally taken to be 10 parsecs.
For example, to calculate the absolute magnitude of the sun, given that
its apparent magnitude is (sunMagnitude, see above) as seen from earth,
you could write:
absoluteMagnitude[sunMagnitude, earthdist]
which gives an absolute magnitude of about 4.83
*/
absoluteMagnitude[mag1, distance1] := magnitude[mag1, distance1, 10 parsecs]
/** Calculate the total emitted power from a spherically-symmetrically
radiating object, given the observed flux (that is, power/area) at the
specified distance.
(This just sums the flux over the surface of a sphere at the specified
distance.)
*/
totalEmittedPowerFromFlux[flux is heat_flux_density, distance] := flux 4 pi distance^2
/** Estimate the total emitted power from a spherically-symmetrically
radiating object, given the apparent magnitude at the specified distance.
*/
totalEmittedPowerFromMagnitude[magnitude, distance] := totalEmittedPowerFromFlux[flux[magnitude], distance]
/** Calculate the flux (that is, power/area) at a given distance emitted by a
spherically-symmetrically radiating object, given its total power.
(This just divides the total power over the surface of a sphere at the
specified distance.)
*/
fluxFromTotalEmittedPower[power is power, distance] := power / (4 pi distance^2)
/** Calculate the apparent magnitude at a given distance emitted by a
spherically-symmetrically radiating object, given its total power. */
magnitudeFromTotalEmittedPower[power is power, distance] := magnitude[fluxFromTotalEmittedPower[power, distance]]
/** Calculate the energy of a photon given one of either:
wavelength
frequency
energy
In the following equation, as in physics, h is Planck's constant and
c is the speed of light.
*/
photonEnergy[x] :=
{
if x conforms frequency // given frequency
return h x
if x conforms length // given wavelength
return h (c / x)
if x conforms energy // given energy
return x
return "photonEnergy: No energy known for $x"
}
/** Calculate the frequency of a photon given one of either:
wavelength
frequency
energy
In the following equation, as in physics, h is Planck's constant and
c is the speed of light.
*/
photonFrequency[x] :=
{
if x conforms frequency // given frequency
return x
if x conforms length // given wavelength
return (c / x)
if x conforms energy // given energy
return x / h
return "photonFrequency: No frequency known for $x"
}
/** Calculate the wavelength of a photon given one of either:
wavelength
frequency
energy
In the following equation, as in physics, h is Planck's constant and
c is the speed of light.
*/
photonWavelength[x] :=
{
if x conforms frequency // given frequency
return c / x
if x conforms length // given wavelength
return x
if x conforms energy // given energy
return c h / x
return "photonWavelength: No wavelength known for $x"
}
/** Roughly calculate a stellar lifetime given its mass. See:
http://hyperphysics.phy-astr.gsu.edu/hbase/Astro/startime.html
*/
stellarLifetime[m0 is mass] :=
{
return 10^10 years (sunmass/m0)^2.5
}
/** Roughly calculate a stellar luminosity (that is, the total power radiated)
given its mass. See:
http://hyperphysics.phy-astr.gsu.edu/hbase/Astro/startime.html
http://hyperphysics.phy-astr.gsu.edu/hbase/Astro/herrus.html#c3
*/
stellarLuminosity[m0 is mass] :=
{
return sunpower (m0 / sunmass)^3.5
}
"stellarMagnitude.frink included OK"