戻る

Gaiaカタログダウンロードスクリプト

位置天文衛星「ガイア」の観測から作られた10億個以上の星のカタログをダウンロードし、
Source、RA_ICRS、DE_ICRS、GmagをCSVファイルに出力します。

ESA Gaia

import urllib.request
import re
import gzip
import csv
from bs4 import BeautifulSoup

url = 'http://cdn.gea.esac.esa.int/Gaia/gaia_source/csv/'
html = urllib.request.urlopen(url).read()
soup = BeautifulSoup(html,'lxml')
links = soup.findAll(href=re.compile('.+.gz'))

for link in links:
    filename = link.text
    urllib.request.urlretrieve(url+filename,filename)

    with gzip.open(filename,'rt') as gzip_file:
        print('start:'+filename)
        rows = csv.reader(gzip_file)
        next(rows)
        log_file = open(filename+'.csv','w')
        str = ''

        for row in rows:
            str += row[1]+','+row[4]+','+row[6]+','+row[51]+'\n'

        log_file.write(str)
        log_file.close()
        print('end:'+filename)

戻る