Ejemplo n.º 1
0
def get():
    try:
        xmltools.ensure_empty_dir(path + "/" + "ExoPlanet_data")
        urllib.request.urlretrieve(
            url_exoplanetarchive,
            path + "/" + "Exoplanet_data/Exoplanet_archive_updated.csv")
    except:
        pass
Ejemplo n.º 2
0
def get():
    #xmltools.ensure_empty_dir(path+"/"+"NASA_data")
    xmltools.ensure_empty_dir(
        os.path.join(os.path.curdir, 'extracted', 'NASA_data'))
    #urllib.request.urlretrieve (url_exoplanetarchive, path+"/"+"NASA_data/NASA_archive_updated.csv")
    urllib.request.urlretrieve(
        url_exoplanetarchive,
        os.path.join(os.path.curdir, 'extracted', 'NASA_data',
                     'NASA_archive_updated.csv'))
Ejemplo n.º 3
0
def get():
    try:
        #xmltools.ensure_empty_dir(path+"/"+"ExoPlanet_data")
        xmltools.ensure_empty_dir(
            os.path.join(os.path.curdir, 'extracted', 'ExoPlanet_data'))
        #urllib.request.urlretrieve (url_exoplanetarchive, path+"/"+"ExoPlanet_data/Exoplanet_archive_updated.csv")
        urllib.request.urlretrieve(
            url_exoplanetarchive,
            os.path.join(os.getcwd(), 'extracted', 'ExoPlanet_data',
                         'Exoplanet_archive_updated.csv'))
    except:
        pass
Ejemplo n.º 4
0
def parse():
    # delete old data
    xmltools.ensure_empty_dir("systems_open_exoplanet_catalogue")

    # parse data into default xml format
    ziphandler = zipfile.ZipFile("tmp_data/oec.zip")
    for name in ziphandler.namelist():
        # only keep main systems/ directory
        if name[0:40] == "open_exoplanet_catalogue-master/systems/" and len(name)>40:
            source = ziphandler.open(name)
            target = file("systems_open_exoplanet_catalogue/"+os.path.basename(name), "wb")
            shutil.copyfileobj(source, target)
def parse():
    # delete old data
    xmltools.ensure_empty_dir("systems_open_exoplanet_catalogue")

    # parse data into default xml format
    #ziphandler = zipfile.ZipFile("tmp_data/oec.zip")
    #for name in ziphandler.namelist():
    #    # only keep main systems/ directory
    #    if name[0:40] == "open_exoplanet_catalogue-master/systems/" and len(name)>40:
    #        source = ziphandler.open(name)
    #        target = file("systems_open_exoplanet_catalogue/"+os.path.basename(name), "wb")
    for f in glob.glob("../open_exoplanet_catalogue/systems/*.xml"):
        target = f.split("/")[-1]
        shutil.copyfile(f, "./systems_open_exoplanet_catalogue/" + target)
Ejemplo n.º 6
0
def parse():
    # delete old data
    xmltools.ensure_empty_dir("systems_open_exoplanet_catalogue")

    # parse data into default xml format
    ziphandler = zipfile.ZipFile("tmp_data/oec.zip")
    for name in ziphandler.namelist():
        # only keep main systems/ directory
        if name[0:40] == "open_exoplanet_catalogue-master/systems/" and len(
                name) > 40:
            source = ziphandler.open(name)
            target = file(
                "systems_open_exoplanet_catalogue/" + os.path.basename(name),
                "wb")
            shutil.copyfileobj(source, target)
Ejemplo n.º 7
0
def get():
    try:
        #xmltools.ensure_empty_dir(path+"/"+"ExoPlanet_data")
        xmltools.ensure_empty_dir(os.path.join(os.path.curdir, 'extracted','ExoPlanet_data'))
        #urllib.request.urlretrieve (url_exoplanetarchive, path+"/"+"ExoPlanet_data/Exoplanet_archive_updated.csv")
        fname = "last_commit_date.txt" #textfile containing last commit date
        last_commit_date = str(datetime.date.today())
        if (os.path.isfile(fname) == False): #create file with current date if dne
            file1 = open(fname, "w")
            file1.write(last_commit_date)
            file1.close()
        with open(fname) as f:
            content = f.readlines()
        if (len(content) == 0):
            print("Last updated date has not been set correctly. Aborting extract")
            return -1
        else:
            last_commit_date = content[0].strip()
            url_exoplanetarchive = "http://exoplanet.eu/catalog/csv/?status=&f=updated+%3E%3D+%22"+last_commit_date+"%22"   
            #url_exoplanetarchive = "http://exoplanet.eu/catalog/csv/?status=&f=updated+%3E%3D+%222016-01-01%22&select=*"        
            urllib.request.urlretrieve (url_exoplanetarchive, os.path.join(os.getcwd(), 'extracted', 'ExoPlanet_data', 'Exoplanet_archive_updated.csv'))
    except:
        pass
Ejemplo n.º 8
0
def get():
    try:
        #xmltools.ensure_empty_dir(path+"/"+"NASA_data")
        xmltools.ensure_empty_dir(os.path.join(os.getcwd(), 'extracted','NASA_data'))
        fname = "last_commit_date.txt" #textfile containing last commit date
        last_commit_date = str(datetime.date.today())
        if (os.path.isfile(fname) == False): #create file with current date if dne
            file1 = open(fname, "w")
            file1.write(last_commit_date)
            file1.close()
        with open(fname) as f:
            content = f.readlines()
        if (len(content) == 0):
            print("Last updated date has not been set correctly. Aborting extract")
            return -1
        else:
            last_commit_date = content[0].strip()
            url_exoplanetarchive = "http://exoplanetarchive.ipac.caltech.edu/cgi-bin/nstedAPI/nph-nstedAPI?table=exoplanets&where=rowupdate>=to_date(%27"+last_commit_date+"%27,%27yyyy-mm-dd%27)&order=rowupdate&format=csv&select=*"  
            #url_exoplanetarchive = "http://exoplanet.eu/catalog/csv/?status=&f=updated+%3E%3D+%222016-01-01%22&select=*"    
            #urllib.request.urlretrieve (url_exoplanetarchive, path+"/"+"NASA_data/NASA_archive_updated.csv")
            urllib.request.urlretrieve (url_exoplanetarchive, os.path.join(os.getcwd(), 'extracted', 'NASA_data', 'NASA_archive_updated.csv'))
    except:
        return -1
Ejemplo n.º 9
0
def get():
    xmltools.ensure_empty_dir("tmp_data")
    urllib.urlretrieve (url_oec, "tmp_data/oec.zip")
Ejemplo n.º 10
0
 except:
     print(
         "Extraction from external sources failed. Try closing all opened CSV files and try again"
     )
     success = False
 localRepoPath = repoTools.getLocalRepo()
 if (localRepoPath == ""
     ):  #file is not right, print message and pass if case
     print(
         "Problem in path. Please set the path of local repository using 'repo' command"
     )
     success = False
 extractedXmlsPath = os.path.join(os.getcwd(), 'extracted',
                                  'Extracted_XMLs')
 #clear change_systems of old updates
 xmltools.ensure_empty_dir(os.path.join(os.getcwd(), "Changed_Systems"))
 #if not success, let's save time from going through anything
 if (success):
     for filename in glob.iglob(os.path.join(extractedXmlsPath,
                                             "*.xml")):
         #performance improv: check matchedSystems file to see if there is a previous match of this planetary system
         pairFile = "matchedSystems.txt"  #textfile containing name of matched system in local repo
         #get system name from filename, i.e. remove NASA_ or ExoPlanet_
         systemName = ntpath.basename(filename).split("_", 1)[1]
         matchedSystem = None
         if (os.path.isfile(pairFile) == False):
             #create file if it got deleted
             f = open(pairFile, "w")
             f.write("")
             f.close()
         with open(pairFile) as f:
Ejemplo n.º 11
0
def parse():
    # delete old data
    xmltools.ensure_empty_dir(path + "/" + "Extracted_XMLs")

    # parse data into default xml format
    f = open(path + "/" + "Exoplanet_data/Exoplanet_archive_updated.csv")
    csv_f = csv.reader(f)
    header = [x.strip() for x in f.readline().split(",")]
    for line in csv_f:
        p = dict(zip(header, [x.strip() for x in line]))
        takeLetterOff = -2
        if (len(p["# name"].split(" ")[-1]) !=
                1):  #if there's no letter at end
            takeLetterOff = len(p["# name"])  #take whole item
        host_name = p["# name"][:takeLetterOff].strip(
        )  #remove the last letter
        pl_letter = p["# name"][takeLetterOff:].strip()
        outputfilename = path + "/" + "Extracted_XMLs/" + host_name + ".xml"
        if os.path.exists(outputfilename):
            system = ET.parse(outputfilename).getroot()
            star = system.find(".//star")
        else:
            system = ET.Element("system")
            #TODO: Need to remove letter at the back
            ET.SubElement(system, "name").text = host_name
            ra, dec = p["ra"], p["dec"]
            if len(p["ra"]) > 0:
                ra = float(p["ra"])
            else:
                print(p["name #"])
            if len(p["dec"]) > 0:
                dec = float(p["dec"])
            else:
                print(p["name #"])
            ra_dec = converter.deg2HMS(ra, dec, True)

            ET.SubElement(system, "rightascension").text = ra_dec[0]
            ET.SubElement(system, "declination").text = ra_dec[1]

            ET.SubElement(system,
                          "distance",
                          errorminus=p['star_distance_error_min'],
                          errorplus=p['star_distance_error_max']
                          ).text = p["star_distance"]

            star = ET.SubElement(system, "star")
            ET.SubElement(star, "name").text = host_name
            #QUESTION: Will errorplus be negative?
            ET.SubElement(
                star,
                "radius",
                errorminus=p['star_radius_error_min'],
                errorplus=p['star_radius_error_max']).text = p["star_radius"]
            #ET.SubElement(star, "magV", errorminus=p['st_vjerr'], errorplus=p['st_vjerr']).text = p["st_vj"]
            #Question: no error minus plus on exoplanet
            ET.SubElement(star, "magV").text = p["mag_v"]
            ET.SubElement(star, "magI").text = p["mag_i"]
            ET.SubElement(star, "magJ").text = p["mag_j"]
            ET.SubElement(star, "magH").text = p["mag_h"]
            ET.SubElement(star, "magK").text = p["mag_k"]
            #Upperlimit?
            ET.SubElement(star,
                          "mass",
                          errorminus=p['mass_error_min'],
                          errorplus=p['mass_error_max']).text = p["mass"]
            ET.SubElement(
                star,
                "temperature",
                errorminus=p['star_teff_error_min'],
                errorplus=p['star_teff_error_max']).text = p["star_teff"]
            #ET.SubElement(star, "metallicity").text = p["st_metratio"]
            ET.SubElement(star,
                          "metallicity",
                          errorminus=p['star_metallicity_error_min'],
                          errorplus=(p['star_metallicity_error_max']
                                     )).text = p["star_metallicity"]

            #HL: Add alternate names to file to help comparison across external sources
            alternate_names = p["alternate_names"].split(",")
            for alt_name in alternate_names:
                ET.SubElement(
                    star,
                    "name").text = alt_name[:-2].strip()  #take out letter

        planet = ET.SubElement(star, "planet")
        #HL: Add alternate names to file to help comparison across external sources
        alternate_names = p["alternate_names"].split(",")
        for alt_name in alternate_names:
            ET.SubElement(planet, "name").text = alt_name
        #QUESTION: This site does not separate the letters in columns??
        ET.SubElement(
            planet,
            "name").text = host_name + " " + pl_letter  #+" "+p["pl_letter"]
        #why the switch between errors?
        ET.SubElement(planet,
                      "semimajoraxis",
                      errorminus=(p["semi_major_axis_error_min"]),
                      errorplus=p["semi_major_axis_error_max"]
                      ).text = p["semi_major_axis"]
        ET.SubElement(
            planet,
            "eccentricity",
            errorminus=p['eccentricity_error_min'],
            errorplus=p['eccentricity_error_max']).text = p["eccentricity"]
        ET.SubElement(planet,
                      "periastron",
                      errorminus=p['omega_error_min'],
                      errorplus=p['omega_error_max']).text = p["omega"]
        ET.SubElement(
            planet,
            "inclination",
            errorminus=p['inclination_error_min'],
            errorplus=p['inclination_error_max']).text = p["inclination"]
        ET.SubElement(
            planet,
            "period",
            errorminus=p['orbital_period_error_min'],
            errorplus=p['orbital_period_error_max']).text = p["orbital_period"]
        # check for both kinds of masses
        if p['mass'] == None or p['mass'] == "":
            # use msini
            ET.SubElement(
                planet,
                "mass",
                errorminus=p['mass_sini_error_min'],
                errorplus=p['mass_sini_error_max']).text = p["mass_sini"]
        else:
            # use mass jupiter
            ET.SubElement(planet,
                          "mass",
                          errorminus=p['mass_error_min'],
                          errorplus=p['mass_error_max']).text = p["mass"]
        ET.SubElement(planet,
                      "radius",
                      errorminus=p['radius_error_min'],
                      errorplus=p['radius_error_max']).text = p["radius"]
        #QUESTION: No errorplus/minus???
        ET.SubElement(planet, "temperature").text = p["temp_calculated"]
        ET.SubElement(planet, "discoverymethod").text = p["detection_type"]
        ET.SubElement(planet, "discoveryyear").text = p["discovered"]
        ET.SubElement(planet, "lastupdate").text = p["updated"]

        # Need to check if BJD ?
        # QUESTION: Is BJD the same as JD?
        JD = "JD"
        if len(p["tzero_tr"]) == 0:
            JD = ""
        ET.SubElement(planet,
                      "transittime",
                      errorminus=p['tzero_tr_error_min'],
                      errorplus=p['tzero_tr_error_max'],
                      unit=JD).text = p["tzero_tr"]

        # Cleanup and write file
        xmltools.removeemptytags(system)
        xmltools.indent(system)
        ET.ElementTree(system).write(outputfilename)
Ejemplo n.º 12
0
def parse():
    # delete old data
    xmltools.ensure_empty_dir("systems_exoplanetarchive")

    # parse data into default xml format
    f = open("exoplanetarchive/exoplanetarchive.csv")
    header = [x.strip() for x in f.readline().split(",")]
    for line in f:
        p = dict(zip(header, [x.strip() for x in line.split(",")]))
        outputfilename = "systems_exoplanetarchive/"+p["pl_hostname"]+".xml"
        if os.path.exists(outputfilename):
            system = ET.parse(outputfilename).getroot()
            star = system.find(".//star")
        else:
            system = ET.Element("system")
            ET.SubElement(system, "name").text = p["pl_hostname"]
            
            tempra = ""
            tempra += p["ra_str"].split("h")[0] # hours
            tempra += " " + p["ra_str"].split("h")[1].split("m")[0] # minutes
            tempra += " %.2i" % (round(float(p["ra_str"].split("h")[1].split("m")[1].split("s")[0]))) # seconds
            ET.SubElement(system, "rightascension").text = tempra

            tempdec = ""
            tempdec += p["dec_str"].split("d")[0] # hours
            tempdec += " " + p["dec_str"].split("d")[1].split("m")[0] # minutes
            tempdec += " %.2i" % (round(float(p["dec_str"].split("d")[1].split("m")[1].split("s")[0]))) # seconds
            ET.SubElement(system, "declination").text = tempdec

            star = ET.SubElement(system,"star")
            ET.SubElement(star, "name").text = p["pl_hostname"]
            ET.SubElement(star, "radius", errorminus=p['st_raderr'], errorplus=p['st_raderr']).text = p["st_rad"]
            ET.SubElement(star, "magV", errorminus=p['st_vjerr'], errorplus=p['st_vjerr']).text = p["st_vj"]
            ET.SubElement(star, "magI", errorminus=p['st_icerr'], errorplus=p['st_icerr']).text = p["st_ic"]
            ET.SubElement(star, "magJ", errorminus=p['st_jerr'], errorplus=p['st_jerr']).text = p["st_j"]
            ET.SubElement(star, "magH", errorminus=p['st_herr'], errorplus=p['st_herr']).text = p["st_h"]
            ET.SubElement(star, "magK", errorminus=p['st_kerr'], errorplus=p['st_kerr']).text = p["st_k"]
            ET.SubElement(star, "mass", errorminus=p['st_masserr'], errorplus=p['st_masserr']).text = p["st_mass"]
            ET.SubElement(star, "temperature", errorminus=p['st_tefferr'], errorplus=p['st_tefferr']).text = p["st_teff"]
            ET.SubElement(star, "metallicity").text = p["st_metratio"]

        planet = ET.SubElement(star,"planet")
        ET.SubElement(planet, "name").text = p["pl_hostname"]+" "+p["pl_letter"]
        ET.SubElement(planet, "semimajoraxis", errorminus=p["pl_orbsmaxerr2"], errorplus=p["pl_orbsmaxerr1"]).text = p["pl_orbsmax"]
        ET.SubElement(planet, "eccentricity", errorminus=p['pl_orbeccenerr2'], errorplus=p['pl_orbeccenerr1']).text = p["pl_orbeccen"]
        ET.SubElement(planet, "periastron", errorminus=p['pl_orblpererr2'], errorplus=p['pl_orblpererr1']).text = p["pl_orblper"]
        ET.SubElement(planet, "inclination", errorminus=p['pl_orbinclerr2'], errorplus=p['pl_orbinclerr1']).text = p["pl_orbincl"]
        ET.SubElement(planet, "period", errorminus=p['pl_orbpererr2'], errorplus=p['pl_orbpererr1']).text = p["pl_orbper"]
        # check for both kinds of masses
        if p['pl_massj'] == "" or p['pl_massj'] == None:
            # use msini
            ET.SubElement(planet, "mass", errorminus=p['pl_msinijerr2'], errorplus=p['pl_msinijerr1']).text = p["pl_msinij"]
        else: 
            # use mass jupiter
            ET.SubElement(planet, "mass", errorminus=p['pl_massjerr2'], errorplus=p['pl_massjerr1']).text = p["pl_massj"]
        ET.SubElement(planet, "radius", errorminus=p['pl_radjerr2'], errorplus=p['pl_radjerr1']).text = p["pl_radj"]
        ET.SubElement(planet, "temperature", errorminus=p['pl_eqterr2'], errorplus=p['pl_eqterr1']).text = p["pl_eqt"]
        ET.SubElement(planet, "discoverymethod").text = p["pl_discmethod"]
        ET.SubElement(planet, "discoveryyear").text = p["pl_disc"]
        ET.SubElement(planet, "lastupdate").text = p["rowupdate"]

        # Need to check if BJD
        ET.SubElement(planet, "transittime", errorminus=p['pl_tranmiderr2'], errorplus=p['pl_tranmiderr1']).text = p["pl_tranmid"]

        # Cleanup and write file
        xmltools.removeemptytags(system)
        xmltools.indent(system)
        ET.ElementTree(system).write(outputfilename) 
Ejemplo n.º 13
0
def get():
    xmltools.ensure_empty_dir(path+"/"+"NASA_data")
    urllib.request.urlretrieve (url_exoplanetarchive, path+"/"+"NASA_data/NASA_archive_updated.csv")
Ejemplo n.º 14
0
def get():
    xmltools.ensure_empty_dir("exoplanetarchive")
    urllib.urlretrieve (url_exoplanetarchive, "exoplanetarchive/exoplanetarchive.csv")
def get():
    xmltools.ensure_empty_dir("tmp_data")
    urllib.request.urlretrieve (url_exoplaneteu, "tmp_data/exoplanet.eu_catalog.csv")
Ejemplo n.º 16
0
def get():
    xmltools.ensure_empty_dir("tmp_data")
    urllib.urlretrieve(url_oec, "tmp_data/oec.zip")
Ejemplo n.º 17
0
def get():
    xmltools.ensure_empty_dir("tmp_data")
    urllib.urlretrieve (url_exoplaneteu, "tmp_data/exoplanet.eu_catalog.csv")
def get():
    xmltools.ensure_empty_dir("tmp_data")
Ejemplo n.º 19
0
def parse():
    # delete old data
    xmltools.ensure_empty_dir("systems_exoplaneteu")

    # parse data into default xml format
    f = open("tmp_data/exoplanet.eu_catalog.csv")
    header = [x.strip() for x in f.readline()[1:].replace("# ", "").split(",")]
    reader = csv.reader(f)
    for line in reader:
        p = dict(zip(header, line))
        outputfilename = "systems_exoplaneteu/"+p["star_name"].strip()+".xml"
        if os.path.exists(outputfilename):
            system = ET.parse(outputfilename).getroot()
            star = system.find(".//star")
        else:
            system = ET.Element("system")
            ET.SubElement(system, "name").text = p["star_name"].strip()
          
            # convert the right ascension to hh mm ss
            tempra = ""
            ra = float(p['ra'])
            hours = ra / 360 * 24
            tempra += "%.2i" % (hours)
            minutes = hours % 1 * 60
            tempra += " %.2i" % (minutes)
            seconds = minutes % 1 * 60
            tempra += " %.2i" % (round(seconds))
            ET.SubElement(system, "rightascension").text = tempra

            # convert declination to deg mm ss
            tempdec = ""
            dec = float(p['dec'])
            tempdec += "%+.2i" %(dec) 
            minutes = dec % 1 * 60
            tempdec += " %.2i" % (minutes)
            seconds = round(minutes % 1 * 60)
            tempdec+= " %.2i" % (seconds)
            ET.SubElement(system, "declination").text = tempdec

            ET.SubElement(system, "distance").text = p["star_distance"]
            star = ET.SubElement(system, "star")
            ET.SubElement(star, "name").text = p["star_name"].strip()
            ET.SubElement(star, "age").text = p["star_age"]
            ET.SubElement(star, "radius").text = p["star_radius"]
            ET.SubElement(star, "mass").text = p["star_mass"]
            ET.SubElement(star, "spectraltype").text = p["star_sp_type"]
            ET.SubElement(star, "temperature").text = p["star_teff"]
            ET.SubElement(star, "metallicity").text = p["star_metallicity"]

        planet = ET.SubElement(star, "planet")
        ET.SubElement(planet, "name").text = p["name"].strip()
        ET.SubElement(planet, "semimajoraxis", errorminus=p["semi_major_axis_error_min"], errorplus=p["semi_major_axis_error_max"]).text = p["semi_major_axis"]
        ET.SubElement(planet, "periastron", errorminus=p['omega_error_min'], errorplus=p['omega_error_max']).text = p["omega"]
        ET.SubElement(planet, "eccentricity", errorminus=p['eccentricity_error_min'], errorplus=p['eccentricity_error_max']).text = p["eccentricity"]
        ET.SubElement(planet, "longitude", errorminus=p['lambda_angle_error_min'], errorplus=p['lambda_angle_error_max']).text = p["lambda_angle"]
        ET.SubElement(planet, "inclination", errorminus=p['inclination_error_min'], errorplus=p['inclination_error_max']).text = p["inclination"]
        ET.SubElement(planet, "period", errorminus=p['orbital_period_err_min'], errorplus=p['orbital_period_err_max']).text = p["orbital_period"]
        ET.SubElement(planet, "mass", errorminus=p['mass_error_min'], errorplus=p['mass_error_max']).text = p["mass"]
        ET.SubElement(planet, "radius", errorminus=p['radius_error_min'], errorplus=p['radius_error_max']).text = p["radius"]
        ET.SubElement(planet, "temperature").text = p["temp_measured"]
        # to match OEC 
        if p['detection_type'].find("radial") != -1:
            ET.SubElement(planet, "discoverymethod").text = "RV"
        elif p['detection_type'].find("imaging") != -1:
            ET.SubElement(planet, "discoverymethod").text = "imaging"
        elif p['detection_type'].find("transit") != -1:
            ET.SubElement(planet, "discoverymethod").text = "transit"
        ET.SubElement(planet, "discoveryyear").text = p["discovered"]
        ET.SubElement(planet, "lastupdate").text = p["updated"].replace("-","/")[2:]

        # ET.SubElement(planet, "spinorbitalignment").text = p[""]

        # Cleanup and write file
        xmltools.removeemptytags(system)
        xmltools.indent(system)
        ET.ElementTree(system).write(outputfilename) 
Ejemplo n.º 20
0
def get():
    xmltools.ensure_empty_dir("tmp_data")
    urllib.urlretrieve(url_exoplanetarchive, "tmp_data/exoplanetarchive.csv")
Ejemplo n.º 21
0
def parse():
    # delete old data
    xmltools.ensure_empty_dir("systems_exoplanetarchive")

    # parse data into default xml format
    f = open("tmp_data/exoplanetarchive.csv")
    header = [x.strip() for x in f.readline().split(",")]
    for line in f:
        p = dict(zip(header, [x.strip() for x in line.split(",")]))
        outputfilename = "systems_exoplanetarchive/" + p["pl_hostname"] + ".xml"
        if os.path.exists(outputfilename):
            system = ET.parse(outputfilename).getroot()
            star = system.find(".//star")
        else:
            system = ET.Element("system")
            ET.SubElement(system, "name").text = p["pl_hostname"]

            tempra = ""
            tempra += p["ra_str"].split("h")[0]  # hours
            tempra += " " + p["ra_str"].split("h")[1].split("m")[0]  # minutes
            tempra += " %.2i" % (round(
                float(p["ra_str"].split("h")[1].split("m")[1].split("s")[0]))
                                 )  # seconds
            ET.SubElement(system, "rightascension").text = tempra

            tempdec = ""
            tempdec += p["dec_str"].split("d")[0]  # hours
            tempdec += " " + p["dec_str"].split("d")[1].split("m")[
                0]  # minutes
            tempdec += " %.2i" % (round(
                float(p["dec_str"].split("d")[1].split("m")[1].split("s")[0]))
                                  )  # seconds
            ET.SubElement(system, "declination").text = tempdec

            star = ET.SubElement(system, "star")
            ET.SubElement(star, "name").text = p["pl_hostname"]
            ET.SubElement(star,
                          "radius",
                          errorminus=p['st_raderr'],
                          errorplus=p['st_raderr']).text = p["st_rad"]
            ET.SubElement(star,
                          "magV",
                          errorminus=p['st_vjerr'],
                          errorplus=p['st_vjerr']).text = p["st_vj"]
            ET.SubElement(star,
                          "magI",
                          errorminus=p['st_icerr'],
                          errorplus=p['st_icerr']).text = p["st_ic"]
            ET.SubElement(star,
                          "magJ",
                          errorminus=p['st_jerr'],
                          errorplus=p['st_jerr']).text = p["st_j"]
            ET.SubElement(star,
                          "magH",
                          errorminus=p['st_herr'],
                          errorplus=p['st_herr']).text = p["st_h"]
            ET.SubElement(star,
                          "magK",
                          errorminus=p['st_kerr'],
                          errorplus=p['st_kerr']).text = p["st_k"]
            ET.SubElement(star,
                          "mass",
                          errorminus=p['st_masserr'],
                          errorplus=p['st_masserr']).text = p["st_mass"]
            ET.SubElement(star,
                          "temperature",
                          errorminus=p['st_tefferr'],
                          errorplus=p['st_tefferr']).text = p["st_teff"]
            ET.SubElement(star, "metallicity").text = p["st_metratio"]

        planet = ET.SubElement(star, "planet")
        ET.SubElement(planet,
                      "name").text = p["pl_hostname"] + " " + p["pl_letter"]
        ET.SubElement(planet,
                      "semimajoraxis",
                      errorminus=p["pl_orbsmaxerr2"],
                      errorplus=p["pl_orbsmaxerr1"]).text = p["pl_orbsmax"]
        ET.SubElement(planet,
                      "eccentricity",
                      errorminus=p['pl_orbeccenerr2'],
                      errorplus=p['pl_orbeccenerr1']).text = p["pl_orbeccen"]
        ET.SubElement(planet,
                      "periastron",
                      errorminus=p['pl_orblpererr2'],
                      errorplus=p['pl_orblpererr1']).text = p["pl_orblper"]
        ET.SubElement(planet,
                      "inclination",
                      errorminus=p['pl_orbinclerr2'],
                      errorplus=p['pl_orbinclerr1']).text = p["pl_orbincl"]
        ET.SubElement(planet,
                      "period",
                      errorminus=p['pl_orbpererr2'],
                      errorplus=p['pl_orbpererr1']).text = p["pl_orbper"]
        # check for both kinds of masses
        if p['pl_massj'] == "" or p['pl_massj'] == None:
            # use msini
            ET.SubElement(planet,
                          "mass",
                          errorminus=p['pl_msinijerr2'],
                          errorplus=p['pl_msinijerr1']).text = p["pl_msinij"]
        else:
            # use mass jupiter
            ET.SubElement(planet,
                          "mass",
                          errorminus=p['pl_massjerr2'],
                          errorplus=p['pl_massjerr1']).text = p["pl_massj"]
        ET.SubElement(planet,
                      "radius",
                      errorminus=p['pl_radjerr2'],
                      errorplus=p['pl_radjerr1']).text = p["pl_radj"]
        ET.SubElement(planet,
                      "temperature",
                      errorminus=p['pl_eqterr2'],
                      errorplus=p['pl_eqterr1']).text = p["pl_eqt"]
        ET.SubElement(planet, "discoverymethod").text = p["pl_discmethod"]
        ET.SubElement(planet, "discoveryyear").text = p["pl_disc"]
        ET.SubElement(planet, "lastupdate").text = p["rowupdate"]

        # Need to check if BJD
        ET.SubElement(planet,
                      "transittime",
                      errorminus=p['pl_tranmiderr2'],
                      errorplus=p['pl_tranmiderr1']).text = p["pl_tranmid"]

        # Cleanup and write file
        xmltools.removeemptytags(system)
        xmltools.indent(system)
        ET.ElementTree(system).write(outputfilename)
def parse():
    # delete old data
    xmltools.ensure_empty_dir("systems_exoplaneteu")

    # parse data into default xml format
    f = open("tmp_data/exoplanet.eu_catalog.csv")
    header = [x.strip() for x in f.readline()[1:].replace("# ", "").split(",")]
    reader = csv.reader(f)
    for line in reader:
        p = dict(zip(header, line))
        outputfilename = "systems_exoplaneteu/"+p["star_name"].strip()+".xml"
        if p["planet_status"] != "Confirmed":
            continue
        if os.path.exists(outputfilename):
            system = ET.parse(outputfilename).getroot()
            star = system.find(".//star")
        else:
            system = ET.Element("system")
            ET.SubElement(system, "name").text = p["star_name"].strip()
          
            # convert the right ascension to hh mm ss
            tempra = ""
            ra = float(p['ra'])
            hours = ra / 360 * 24
            tempra += "%.2i" % (hours)
            minutes = hours % 1 * 60
            tempra += " %.2i" % (minutes)
            seconds = minutes % 1 * 60
            tempra += " %.2i" % (round(seconds))
            ET.SubElement(system, "rightascension").text = tempra

            # convert declination to deg mm ss
            tempdec = ""
            dec = float(p['dec'])
            tempdec += "%+.2i" %(dec) 
            minutes = dec % 1 * 60
            tempdec += " %.2i" % (minutes)
            seconds = round(minutes % 1 * 60)
            tempdec+= " %.2i" % (seconds)
            ET.SubElement(system, "declination").text = tempdec

            ET.SubElement(system, "distance").text = p["star_distance"]
            star = ET.SubElement(system, "star")
            ET.SubElement(star, "name").text = p["star_name"].strip()
            ET.SubElement(star, "age").text = p["star_age"]
            ET.SubElement(star, "radius").text = p["star_radius"]
            ET.SubElement(star, "mass").text = p["star_mass"]
            ET.SubElement(star, "spectraltype").text = p["star_sp_type"]
            ET.SubElement(star, "temperature").text = p["star_teff"]
            ET.SubElement(star, "metallicity").text = p["star_metallicity"]

        planet = ET.SubElement(star, "planet")
        ET.SubElement(planet, "name").text = p["name"].strip()
        ET.SubElement(planet, "semimajoraxis", errorminus=p["semi_major_axis_error_min"], errorplus=p["semi_major_axis_error_max"]).text = p["semi_major_axis"]
        ET.SubElement(planet, "periastron", errorminus=p['omega_error_min'], errorplus=p['omega_error_max']).text = p["omega"]
        ET.SubElement(planet, "eccentricity", errorminus=p['eccentricity_error_min'], errorplus=p['eccentricity_error_max']).text = p["eccentricity"]
        ET.SubElement(planet, "longitude", errorminus=p['lambda_angle_error_min'], errorplus=p['lambda_angle_error_max']).text = p["lambda_angle"]
        ET.SubElement(planet, "inclination", errorminus=p['inclination_error_min'], errorplus=p['inclination_error_max']).text = p["inclination"]
        ET.SubElement(planet, "period", errorminus=tofl(p['orbital_period_error_min']), errorplus=tofl(p['orbital_period_error_max'])).text = p["orbital_period"]
        ET.SubElement(planet, "mass", errorminus=p['mass_error_min'], errorplus=p['mass_error_max']).text = p["mass"]
        ET.SubElement(planet, "radius", errorminus=p['radius_error_min'], errorplus=p['radius_error_max']).text = p["radius"]
        try:
            if float(p["radius"])>0.:
                ET.SubElement(planet, "istransiting").text = "1"
        except:
            pass
        if p["detection_type"]=="Radial Velocity":
            ET.SubElement(planet, "discoverymethod").text = "RV"
        elif p["detection_type"]=="Primary Transit":
            ET.SubElement(planet, "discoverymethod").text = "transit"
        elif p["detection_type"]=="Imaging":
            ET.SubElement(planet, "discoverymethod").text = "imaging"


        ET.SubElement(planet, "temperature").text = p["temp_measured"]
        # to match OEC 
        if p['detection_type'].find("radial") != -1:
            ET.SubElement(planet, "discoverymethod").text = "RV"
        elif p['detection_type'].find("imaging") != -1:
            ET.SubElement(planet, "discoverymethod").text = "imaging"
        elif p['detection_type'].find("transit") != -1:
            ET.SubElement(planet, "discoverymethod").text = "transit"
        ET.SubElement(planet, "discoveryyear").text = p["discovered"]
        ET.SubElement(planet, "lastupdate").text = p["updated"].replace("-","/")[2:]
        ET.SubElement(planet, "list").text = "Confirmed planets"
        ET.SubElement(planet, "description").text = "Data for this planet was imported from the exoplanet.eu database."

        # ET.SubElement(planet, "spinorbitalignment").text = p[""]

        # Cleanup and write file
        xmltools.removeemptytags(system)
        xmltools.indent(system)
        ET.ElementTree(system).write(outputfilename) 
Ejemplo n.º 23
0
def get():
    xmltools.ensure_empty_dir("exoplaneteu")
    urllib.urlretrieve (url_exoplaneteu, "exoplaneteu/exoplanet.eu_catalog.csv")