-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmake_EU_database.py
executable file
·64 lines (48 loc) · 2.12 KB
/
make_EU_database.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
import pandas as pd
import numpy as np
import warnings
from clint.textui import colored
warnings.simplefilter("ignore")
class Sweetcat:
"""Load SWEET-Cat database"""
def __init__(self):
# self.fname_sc = 'WEBSITE_online_EU-NASA_full_database.rdb'
self.fname_sc = 'WEBSITE_online_EU-NASA_full_database_clean.rdb'
# Loading the SweetCat database
self.readSC()
def readSC(self):
# TODO: Use the ra and dec, and match with coordinates instead of name
# stored in self.coordinates.
# Read the current version of SWEET-Cat
names_ = ['name', 'hd', 'ra', 'dec', 'V', 'Verr', 'p', 'perr',
'pflag', 'Teff', 'Tefferr', 'logg', 'logger',
'n1', 'n2', 'vt', 'vterr', 'feh', 'feherr', 'M', 'Merr',
'author', 'link', 'source', 'update', 'comment', 'database',
'n3']
# SC = pd.read_csv('WEBSITE_online.rdb', delimiter='\t', names=names_)
SC = pd.read_csv(self.fname_sc, delimiter='\t', names=names_)
# Clean star names
self.sc_names = [x.lower().replace(' ', '').replace('-', '') for x in SC.name]
self.sc_names = list(map(str.strip, self.sc_names))
# Original star names
self.sc_names_orig = [x.strip() for x in SC.name]
# Coordinates of the stars in SWEET-Cat
self.coordinates = SC.loc[:, ['ra', 'dec']]
# SWEET-Cat (used to automatically update the database label)
self.SC = SC
if __name__ == '__main__':
# Loading SWEET Cat
sc = Sweetcat()
# Select only the EU data
sc_only_EU = sc.SC[sc.SC['database'].str.contains('EU')]
# Drop the database column
sc_EU = sc_only_EU.drop(columns=['database'])
# Convert Tefferr column to integers
sc_EU['Tefferr'] = sc_EU['Tefferr'].fillna('-111111')
sc_EU['Tefferr'] = sc_EU['Tefferr'].astype(int).replace(-111111, 'NULL')
# Replace NaN by NULL
sc_EU.fillna(value='NULL', inplace=True)
# Write to CSV file
print('Write WEBSITE_online_EU.rdb')
sc_EU.to_csv('WEBSITE_online_EU.rdb',
sep='\t', index=False, header=False)