Compare commits

...

4 Commits

+136 -26
View File
@@ -1,8 +1,25 @@
from astroquery.simbad import Simbad from astroquery.simbad import Simbad
from astroquery.vizier import Vizier
from astropy.coordinates import Angle
import pandas as pd import pandas as pd
import numpy as np
from main.astrodatagui.db.StarsDB import StarDB
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
simbad = Simbad() simbad = Simbad()
starDB: StarDB = StarDB.getInstance("stars.db")
bvStars = ["1RXS J064643.6-770027", "BD-08 995", "CPD-19 878", "PM J07058-5848", "TYC 1360-957-1", "TYC 4595-107-1"] bvStars = ["1RXS J064643.6-770027", "BD-08 995", "CPD-19 878", "PM J07058-5848", "TYC 1360-957-1", "TYC 4595-107-1"]
jhcStars = ["2MASS J18524052+4156057", "2MASS J18534407+4208274", "2MASS J18535462+4135227", "2MASS J19335656+4010546"] jhcStars = ["2MASS J18524052+4156057", "2MASS J18534407+4208274", "2MASS J18535462+4135227", "2MASS J19335656+4010546"]
@@ -10,21 +27,62 @@ filters = ["U", "B", "V", "R", "I", "J", "H", "K", "u", "g", "r", "i", "z", "G",
for f in filters: for f in filters:
simbad.add_votable_fields(f"flux({f})") simbad.add_votable_fields(f"flux({f})")
vizierTIC = Vizier(catalog="IV/38/tic",
columns=["TIC", "HIP", "TYC", "UCAC4", "2MASS", "GAIA", "KIC", "S/G", "Teff", "Rad", "Mass", "LClass", "Dist"])
spTypeTable = pd.read_csv("cousins.cols") spTypeTable = pd.read_csv("cousins.cols")
weights = {"SpType": 0.0, weights = {"SpType": 0.0,
"U-B": 1.0, "U-B": 2.0,
"B-V": 1.0, "B-V": 2.0,
"V-R": 0.0, "V-R": 0.8,
"V-I": 0.0, "V-I": 0.7,
"V-J": 0.0, "V-J": 0.6,
"V-H": 0.0, "V-H": 0.5,
"V-K": 0.0, "V-K": 0.4,
"V-L": 0.0, "V-L": 0.0,
"V-M": 0.0, "V-M": 0.0,
"V-N": 0.0} "V-N": 0.0}
for star in bvStars: spTypeTeffMinTable = {2700: "M",
4000: "K",
5440: "G",
6300: "F",
7920: "A"}
def getSpTypeFromTeff(Teff):
if(Teff >= 30000):
return "O"
elif(Teff >= 10000):
return "B"
elif(Teff >= 7500):
return "A"
elif(Teff >= 6000):
return "F"
elif(Teff >= 5200):
return "G"
elif(Teff >= 3700):
return "K"
elif(Teff >= 2400):
return "M"
else:
return "L"
resTable = {"StarID": [],
"simbad B-V": [],
"simbad SpType": [],
"vizier Teff": [],
"vizier Mass": [],
"vizier Radius": [],
"vizier SpType": [],
"vizier Lum. Class": [],
"Final SpType": []}
resTable = pd.DataFrame(resTable)
allStars = []
allStars.extend(bvStars)
allStars.extend(jhcStars)
for star in allStars:
star = simbad.query_object(star) star = simbad.query_object(star)
U_B = star["FLUX_U"] - star["FLUX_B"] U_B = star["FLUX_U"] - star["FLUX_B"]
B_V = star["FLUX_B"] - star["FLUX_V"] B_V = star["FLUX_B"] - star["FLUX_V"]
@@ -44,26 +102,78 @@ for star in bvStars:
fluxDiff = pd.DataFrame(fluxDiff) fluxDiff = pd.DataFrame(fluxDiff)
fluxDiffValColumns = fluxDiff.columns[fluxDiff.notna().iloc[0]] fluxDiffValColumns = fluxDiff.columns[fluxDiff.notna().iloc[0]]
matchingColumnsUBV = spTypeTable.columns.intersection(fluxDiffValColumns) matchingColumnsUBVIJHK = spTypeTable.columns.intersection(fluxDiffValColumns)
distancesUBV = spTypeTable[matchingColumnsUBV].sub(fluxDiff.iloc[0]).pow(2).sum(axis=1) distancesUBV = spTypeTable[matchingColumnsUBVIJHK].sub(fluxDiff.iloc[0]).pow(2).sum(axis=1)
bestMatchIndexUBV = distancesUBV.idxmin() bestMatchIndexUBVIJHK = distancesUBV.idxmin()
bestMatchNameUBV = spTypeTable.iloc[bestMatchIndexUBV, 0] bestMatchNameUBV = spTypeTable.iloc[bestMatchIndexUBVIJHK, 0]
distancesUBVweighted = ( distancesUBVIJHKweighted = (
spTypeTable[matchingColumnsUBV] spTypeTable[matchingColumnsUBVIJHK]
.sub(fluxDiff.iloc[0][matchingColumnsUBV]) .sub(fluxDiff.iloc[0][matchingColumnsUBVIJHK])
.pow(2) .pow(2)
.multiply([weights[col] for col in matchingColumnsUBV], axis=1) .multiply([weights[col] for col in matchingColumnsUBVIJHK], axis=1)
.sum(axis=1) .sum(axis=1)
) )
bestMatchIndexUBVweighted = distancesUBVweighted.idxmin() bestMatchIndexUBVIJHKweighted = distancesUBVIJHKweighted.idxmin()
bestMatchNameUBVweighted = spTypeTable.iloc[bestMatchIndexUBVweighted, 0] bestMatchNameUBVweighted = spTypeTable.iloc[bestMatchIndexUBVIJHKweighted, 0]
print(f"{star['MAIN_ID'].value[0]}: {bestMatchNameUBV}/{bestMatchNameUBVweighted} type star") distancesUBVonlyWeighted = (
print("Table entry: ") spTypeTable[matchingColumnsUBVIJHK]
print(spTypeTable.iloc[bestMatchIndexUBV:bestMatchIndexUBV+1]) .sub(fluxDiff.iloc[0][matchingColumnsUBVIJHK])
print("Weighted Table entry:") .pow(2)
print(spTypeTable.iloc[bestMatchIndexUBVweighted:bestMatchIndexUBVweighted+1]) .multiply([1.0 if(col == "U-B" or col == "B-V") else 0.0 for col in matchingColumnsUBVIJHK], axis=1)
print("Star: ") .sum(axis=1)
print(fluxDiff) )
print("-------------------------------------------------------------------------------------") bestMatchIndexUBVonlyWeighted = distancesUBVonlyWeighted.idxmin()
bestMatchNameUBVonlyWeighted = spTypeTable.iloc[bestMatchIndexUBVonlyWeighted, 0] if (not np.isnan(U_B) or not np.isnan(B_V)) else ""
starName = star['MAIN_ID'].value[0]
regionResults = vizierTIC.query_region(starName,
radius=Angle(5, "arcsec"))
altNames = [an[0] for an in starDB.getStarAltNames(starName)[:-1]]
vizierTable = None
for reg in regionResults:
for row in reg:
for aN in altNames:
if((str(row["TIC"]) in aN or
str(row["GAIA"]) in aN or
str(row["_2MASS"]) in aN) and
row["LClass"] == "DWARF"):
vizierTable = row
break
else:
continue
break
else:
continue
break
Teff = vizierTable["Teff"]
vizierSpType = getSpTypeFromTeff(Teff)
finalSpType = ""
if(bestMatchNameUBVonlyWeighted == "" or
bestMatchNameUBVonlyWeighted[0] == vizierSpType):
finalSpType = vizierSpType
else:
if(bestMatchNameUBVonlyWeighted[1] == "0"):
finalSpType = vizierSpType
else:
finalSpType = bestMatchNameUBVonlyWeighted[0]
if(vizierTable is None):
resTable = pd.concat([resTable,
pd.DataFrame([[starName, B_V[0], bestMatchNameUBVonlyWeighted,
"", "", "", "", "",
finalSpType]],
columns=resTable.columns)],
ignore_index=True)
else:
resTable = pd.concat([resTable,
pd.DataFrame([[starName, B_V[0], bestMatchNameUBVonlyWeighted,
vizierTable["Teff"], vizierTable["Mass"], vizierTable["Rad"], vizierSpType, vizierTable["LClass"],
finalSpType]],
columns=resTable.columns)],
ignore_index=True)
print(resTable.to_string())