-
Notifications
You must be signed in to change notification settings - Fork 7
/
oec_fields.py
186 lines (182 loc) · 7.69 KB
/
oec_fields.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import urllib
import lxml.etree as ET
from numberformat import renderFloat, renderText, notAvailableString
""" Array of title of propoerties """
titles = {
"name": "Primary planet name",
"namelink": "Primary planet name",
"alternativenames": "Alternative planet names",
"starname": "Star name",
"staralternativenames": "Alternative star names",
"systemname": "Primary system name",
"systemalternativenames": "Alternative system names",
"distance": "Distance [parsec]",
"distancelightyears": "Distance [lightyears]",
"numberofplanets": "Number of planets in system",
"numberofstars": "Number of stars in system",
"rightascension": "Right ascension",
"declination": "Declination",
"image": "Image",
"imagedescription": "Image description",
"starmass": "Mass [M<sub>Sun</sub>]",
"starradius": "Radius [R<sub>Sun</sub>]",
"starage": "Age [Gyr]",
"starmetallicity": "Metallicity [Fe/H]",
"starspectraltype": "Spectral type",
"startemperature": "Temperature [K]",
"starmagV": "Visual magnitude",
"period": "Orbital period [days]",
"semimajoraxis": "Semi-major axis [AU]",
"eccentricity": "Eccentricity",
"temperature": "Equilibrium temperature [K]",
"lists": "Lists",
"description": "Description",
"discoveryyear": "Discovery year",
"discoverymethod": "Discovery method",
"lastupdate": "Last updated [yy/mm/dd]",
"mass": "Mass [M<sub>jup</sub>]",
"radius": "Radius [R<sub>jup</sub>]",
"massEarth": "Mass [M<sub>earth</sub>]",
"radiusEarth": "Radius [R<sub>earth</sub>]",
}
def getEditButton(xmlPair,o):
if o is None:
return ""
else:
system, planet, star, filename = xmlPair
path = ET.ElementTree(system).getpath(o)
if path is not None:
return "<a class='editbutton' href='/edit/form/"+filename+path[7:]+"'>edit</a>"
return ""
def render(xmlPair,type,editbutton=True):
editbutton = False ## Manual override (June 21 2020)
system, planet, star, filename = xmlPair
if type=="numberofplanets":
return "%d"%len(system.findall(".//planet"))
if type=="numberofstars":
return "%d"%len(system.findall(".//star"))
if type in ["distance"]:
o = system.find("./"+type)
html = renderFloat(o)
if editbutton:
html += getEditButton(xmlPair,o)
return html
if type=="distancelightyears":
return renderFloat(system.find("./distance"),3.2615638)
if type=="massEarth":
return renderFloat(planet.find("./mass"),317.82841)
if type in ["mass","radius","period","eccentricity","temperature","semimajoraxis"]:
o = planet.find("./"+type)
html = renderFloat(o)
if editbutton:
html += getEditButton(xmlPair,o)
return html
if type=="radiusEarth":
return renderFloat(planet.find("./radius"),11.208981)
# Text based object
if type=="rightascension":
return renderText(system.find("./rightascension"))
if type=="declination":
return renderText(system.find("./declination"))
if type=="image":
try:
return planet.find("./image").text
except:
return None
if type=="imagedescription":
try:
return planet.find("./imagedescription").text
except:
return None
if type=="description":
o = planet.find("./description")
html = renderText(o)
if editbutton:
html += getEditButton(xmlPair,o)
return html
if type=="name":
return renderText(planet.find("./name"))
if type=="namelink":
planetname = planet.find("./name").text
return "<a href=\"/planet/%s/\"><span class=\"numericvalue\">%s</span></a>"%(urllib.parse.quote(planetname.encode('utf8')),planetname)
if type=="discoveryyear":
return renderText(planet.find("./discoveryyear"))
if type=="discoverymethod":
return renderText(planet.find("./discoverymethod"))
if type=="lastupdate":
return renderText(planet.find("./lastupdate"))
if type=="systemname":
return renderText(system.find("./name"))
if type=="alternativenames":
alternativenames = notAvailableString
names = planet.findall("./name")
for i,name in enumerate(names[1:]):
if i==0:
alternativenames = ""
else:
alternativenames += ", "
alternativenames += name.text
return alternativenames
if type=="systemalternativenames":
systemalternativenames = notAvailableString
systemnames = system.findall("./name")
for i,name in enumerate(systemnames[1:]):
if i==0:
systemalternativenames = ""
else:
systemalternativenames += ", "
systemalternativenames += name.text
return systemalternativenames
if type=="lists":
lists = notAvailableString
ls = planet.findall("./list")
for i,l in enumerate(ls):
if i==0:
lists = ""
else:
lists += "; "
lists += l.text
return lists
# Host star fields
if type[0:4]=="star":
if star is None:
return notAvailableString
type = type[4:]
# Text based object
if type=="spectraltype":
return renderText(star.find("./spectraltype"))
if type=="name":
return renderText(star.find("./name"))
if type=="alternativenames":
alternativenames = notAvailableString
names = star.findall("./name")
for i,name in enumerate(names[1:]):
if i==0:
alternativenames = ""
else:
alternativenames += ", "
alternativenames += name.text
return alternativenames
if type in ["mass","radius","age","metallicity","temperature","magV"]:
o = star.find("./"+type)
html = renderFloat(o)
if editbutton:
html += getEditButton(xmlPair,o)
return html
# Default: just search for the property in the planet xml.
return renderFloat(star.find("./"+type))
# Long texts
if type=="systemcategory":
systemcategory = ""
systemname = renderText(system.find("./name"))
if len(system.findall(".//planet"))==1:
systemcategory += "The planetary system "+systemname+" hosts at least one planet. "
elif len(system.findall(".//planet"))>1:
systemcategory += "The planetary system "+systemname+" hosts at least %d planets. " % len(system.findall(".//planet"))
if len(system.findall(".//star"))>1:
systemcategory += "Note that the system is a multiple star system. It hosts at least %d stellar components. "% len(system.findall(".//star"))
elif len(system.findall(".//star"))==0:
systemcategory += "The planet is a so called orphan planet and not associated with any star. "
return systemcategory
# Default: just search for the property in the planet xml.
return renderFloat(planet.find("./"+type))