Skip to content

Commit

Permalink
issue fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ziphead authored Jan 24, 2017
1 parent 92d6114 commit 8fde0ca
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 49 deletions.
6 changes: 4 additions & 2 deletions oec_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def isHabitable(xmlPair):
return False # no binary systems (yet)
spectralTypeMain = getText(star,"./spectraltype","G")[0]
if spectralTypeMain not in spectraltypes_temp_radii :
return False # unsupported spectral type
return False # unsupported spectral type
semimajoraxis = getFloat(planet,"./semimajoraxis")
if semimajoraxis is None:
hostmass = getFloat(star,"./mass",1.)
Expand All @@ -40,9 +40,11 @@ def isHabitable(xmlPair):

stellarRadius = getFloat(star,"./radius")
if stellarRadius is None or stellarRadius<0.01:
stellarRadius = 1.
#stellarRadius = 1.
if spectralTypeMain in spectraltypes_temp_radii:
stellarRadius = spectraltypes_temp_radii[spectralTypeMain][1]
else:
return False


if stellarMass>2.:
Expand Down
81 changes: 34 additions & 47 deletions visualizations.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
from math import *
from numberformat import getFloat, getText, renderFloat
from oec_filters import spectraltypes_temp_radii # importing default values

width = 480
height= 200

def getRadius(planet):
print planet
radius = getFloat(planet,"./radius")
if radius is not None:
print radius
return radius
m = getFloat(planet,"./mass")
if m is not None:
m *= 317.894
# This is based on Lissauer et al 2011 b
if m>30.:
print m
return pow(m,1./3.)*0.0911302
else:
print m
return pow(m,1./2.06)*0.0911302
print 'none'
return None

pl_i=0
Expand All @@ -42,7 +48,7 @@ def plotplanet(radius,name,ss,todooooooo=1):
style = "fill:url(#g1); stroke:none"
svg += '<circle cx="%f" cy="%f" r="%f" style="%s" />' %(
pl_i+earth*radius+1,
y,
y,
earth*radius,
style)
svg += '<line x1="%f" y1="%f" x2="%f" y2="%f" fill="none" stroke="lightgrey" />'%(
Expand All @@ -60,7 +66,7 @@ def plotplanet(radius,name,ss,todooooooo=1):

def size(xmlPair):
global earth,pl_i,texty
system, planet, star, filename = xmlPair
system, planet, star, filename = xmlPair
planets = system.findall(".//planet")
maxr = max(map(getRadius,planets))
pl_i=0
Expand Down Expand Up @@ -111,13 +117,13 @@ def size(xmlPair):
radius = getRadius(p)
if radius is not None:
svg += plotplanet(radius, p.find("./name").text, False)

svg += " </g>"
return svg


def habitable(xmlPair):
system, planet, star, filename = xmlPair
system, planet, star, filename = xmlPair

if star is None:
return None # cannot draw diagram for binary systems yet
Expand All @@ -130,57 +136,38 @@ def habitable(xmlPair):
if semimajoraxis is None:
hostmass = getFloat(star,"./mass",1.)
period = getFloat(planet,"./period",265.25)
semimajoraxis = pow(pow(period/6.283/365.25,2)*39.49/hostmass,1.0/3.0)
semimajoraxis = pow(pow(period/6.283/365.25,2)*39.49/hostmass,1.0/3.0)
if semimajoraxis>maxa:
maxa = semimajoraxis

temperature = getFloat(star,"./temperature")
spectralTypeMain = getText(star,"./spectraltype","G")[0]
if temperature is None:
if spectralTypeMain=="O":
temperature = 40000
if spectralTypeMain=="B":
temperature = 20000
if spectralTypeMain=="A":
temperature = 8500
if spectralTypeMain=="F":
temperature = 6500
if spectralTypeMain=="G":
temperature = 5500
if spectralTypeMain=="K":
temperature = 4000
if spectralTypeMain=="M":
temperature = 3000

try:
temperature = spectraltypes_temp_radii[spectralTypeMain][0]
except:
return None # cannot draw diagram unsupported spectral type


rel_temp = temperature - 5700.

stellarMass = getFloat(star,"./mass")
if stellarMass is None:
stellarMass = 1.

stellarRadius = getFloat(star,"./radius")
if stellarRadius is None or stellarRadius<0.01:
stellarRadius = 1.
if spectralTypeMain=='O':
stellarRadius=10.
if spectralTypeMain=='B':
stellarRadius=3.0
if spectralTypeMain=='A':
stellarRadius=1.5
if spectralTypeMain=='F':
stellarRadius=1.3
if spectralTypeMain=='G':
stellarRadius=1.0
if spectralTypeMain=='K':
stellarRadius=0.8
if spectralTypeMain=='M':
stellarRadius=0.5

if spectralTypeMain in spectraltypes_temp_radii:
stellarRadius = spectraltypes_temp_radii[spectralTypeMain][1]
else:
return None


if stellarMass>2.:
luminosity = pow(stellarMass,3.5)
else:
luminosity = pow(stellarMass,4.)

# Ref: http://adsabs.harvard.edu/abs/2007A%26A...476.1373S
HZinner2 = (0.68-2.7619e-5*rel_temp-3.8095e-9*rel_temp*rel_temp) *sqrt(luminosity);
HZouter2 = (1.95-1.3786e-4*rel_temp-1.4286e-9*rel_temp*rel_temp) *sqrt(luminosity);
Expand All @@ -196,13 +183,13 @@ def habitable(xmlPair):

svg = """
<defs>
<radialGradient id="habitablegradient" >
<radialGradient id="habitablegradient" >
<stop id="stops0" offset=".0" stop-color="lightgreen" stop-opacity="0"/>
<stop id="stops1" offset="%f" stop-color="lightgreen" stop-opacity="0"/>
<stop id="stops2" offset="%f" stop-color="lightgreen" stop-opacity="1"/>
<stop id="stops3" offset="%f" stop-color="lightgreen" stop-opacity="1"/>
<stop id="stops4" offset="1" stop-color="lightgreen" stop-opacity="0"/>
</radialGradient>
</radialGradient>
</defs>
""" %(HZinner2/HZouter2, HZinner/HZouter2,HZouter/HZouter2 )
if HZinner2<maxa*2:
Expand All @@ -215,20 +202,20 @@ def habitable(xmlPair):
au*HZinner2,
height-1)


svg += '<ellipse cx="%f" cy="%f" rx="%f" ry="%f" style="fill:red" />' %(
0.,
height/2,
au*stellarRadius*0.0046524726,
au*stellarRadius*0.0046524726)

svg += '<g style="stroke:black;">'
for planet in planets:
semimajoraxis = getFloat(planet,"./semimajoraxis")
if semimajoraxis is None:
hostmass = getFloat(star,"./mass",1.)
period = getFloat(planet,"./period",265.25)
semimajoraxis = pow(pow(period/6.283/365.25,2)*39.49/hostmass,1.0/3.0)
semimajoraxis = pow(pow(period/6.283/365.25,2)*39.49/hostmass,1.0/3.0)
size= 12
textx=semimajoraxis*au+2
texty=last_text_y+size
Expand All @@ -246,7 +233,7 @@ def habitable(xmlPair):
size,
getText(planet,"./name"))
svg += '</g>'

return svg

def textArchitecture(o,stype=0):
Expand All @@ -269,11 +256,11 @@ def textArchitecture(o,stype=0):
else:
architecture += ", "+renderFloat(period)+" days"
architecture += textArchitecture(b,2)

ss = o.findall("./star")
for s in ss:
architecture += "<li><img src=\"/static/img/star.png\" width=\"16\" height=\"16\" />&nbsp;"+s.find("./name").text+", stellar object"
architecture += textArchitecture(s)
architecture += textArchitecture(s)

ps = o.findall("./planet")
for p in ps:
Expand Down

0 comments on commit 8fde0ca

Please sign in to comment.