Skip to content

Instantly share code, notes, and snippets.

Created July 23, 2015 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5351f6185e8473a3c002 to your computer and use it in GitHub Desktop.
Save anonymous/5351f6185e8473a3c002 to your computer and use it in GitHub Desktop.
from __future__ import division
from operator import mul
from math import pi, sqrt
NUM_TERMS = 4 # Number of properties used in computing ESI
G = 6.674e-11 # m**3/(kg * s**2) (Gravitational constant)
TERM_WEIGHTS = {
'radius': 0.57,
'density': 1.07,
'escape_velocity': 0.70,
'temperature': 5.58
}
EARTH_VALUES = {
'radius': 1, # the Earth is 1 earth in radius
'density': 1, # the Earth is 1 earth in density
'escape_velocity': 1, # the Earth is 1 earth in escape velocity
'temperature': 288, # Kelvins
}
def calculate_term(other_val, earth_val, term_weight):
abs_diff = abs((other_val - earth_val)/(other_val + earth_val))
return (1 - abs_diff)**(term_weight/NUM_TERMS)
def calculate_esi(**kwargs):
"""
kwargs must contain:
radius (in meters)
density (in kilograms/meter**3)
escape_velocity (in meters/second)
temperature (in degrees Kelvin)
"""
terms = [calculate_term(v, EARTH_VALUES[k], TERM_WEIGHTS[k])
for k,v in kwargs.items()]
return reduce(mul, terms)
# Le petit test
assert (1.0 - calculate_esi(**EARTH_VALUES)) < 0.0000001
# Values will be used to compute value of chucks
# in reference units from EARTH_VALUES
earth = {
'radius': 6371000, # m
'density': 5514.0, # kg/m**3
'escape_velocity': 11186000, # m/s
'temperature': 288, # K
}
chuck = {
'mass': 88.45, # kg
'density': 1062.0, # kg/m**3
'temperature': 310.15, # K
}
chuck['volume'] = chuck['mass'] / chuck['density'] # kg/(kg/m**3) => m**3
chuck['radius'] = 3 * (chuck['volume']/(4*pi))**(1/3) # m
chuck['escape_velocity'] = sqrt(2 * G * chuck['mass'] / chuck['radius']) # sqrt((m**3)/(kg * s**2) * kg * m**-1) = sqrt(m**2/kg**2) = m/s
# values for chuck, measured in EARTH_VALUES units
earth_chuck = {
'density': chuck['density'] / earth['density'],
'radius': chuck['radius'] / earth['radius'],
'escape_velocity': chuck['escape_velocity'] / earth['escape_velocity'],
'temperature': chuck['temperature']
}
print calculate_esi(**earth_chuck)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment