diff --git a/identify_unknown_sptypes.py b/identify_unknown_sptypes.py index 15506a3..e6930b8 100644 --- a/identify_unknown_sptypes.py +++ b/identify_unknown_sptypes.py @@ -1,5 +1,10 @@ from astroquery.simbad import Simbad +from astroquery.vizier import Vizier +from astropy.coordinates import Angle import pandas as pd +import numpy as np + +from main.astrodatagui.db.StarsDB import StarDB class bcolors: HEADER = '\033[95m' @@ -13,6 +18,8 @@ class bcolors: 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"] jhcStars = ["2MASS J18524052+4156057", "2MASS J18534407+4208274", "2MASS J18535462+4135227", "2MASS J19335656+4010546"] @@ -20,6 +27,9 @@ filters = ["U", "B", "V", "R", "I", "J", "H", "K", "u", "g", "r", "i", "z", "G", for f in filters: 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") weights = {"SpType": 0.0, @@ -34,7 +44,45 @@ weights = {"SpType": 0.0, "V-M": 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) U_B = star["FLUX_U"] - star["FLUX_B"] B_V = star["FLUX_B"] - star["FLUX_V"] @@ -77,15 +125,55 @@ for star in bvStars: .sum(axis=1) ) bestMatchIndexUBVonlyWeighted = distancesUBVonlyWeighted.idxmin() - bestMatchNameUBVonlyWeighted = spTypeTable.iloc[bestMatchIndexUBVonlyWeighted, 0] + bestMatchNameUBVonlyWeighted = spTypeTable.iloc[bestMatchIndexUBVonlyWeighted, 0] if (not np.isnan(U_B) or not np.isnan(B_V)) else "" - print(f"--- {bcolors.BOLD}{bcolors.OKGREEN}{star['MAIN_ID'].value[0]}{bcolors.ENDC} ---") - print(f"Best no weights match: {bcolors.FAIL}{bestMatchNameUBV}{bcolors.ENDC}") - print(spTypeTable.iloc[bestMatchIndexUBVIJHK:bestMatchIndexUBVIJHK+1]) - print(f"Best weights match: {bcolors.FAIL}{bestMatchNameUBVweighted}{bcolors.ENDC}") - print(spTypeTable.iloc[bestMatchIndexUBVIJHKweighted:bestMatchIndexUBVIJHKweighted+1]) - print(f"Best UBV match: {bcolors.FAIL}{bestMatchNameUBVonlyWeighted}{bcolors.ENDC}") - print(spTypeTable.iloc[bestMatchIndexUBVonlyWeighted:bestMatchIndexUBVonlyWeighted+1]) - print(f"Star: ") - print(fluxDiff) - print("-------------------------------------------------------------------------------------") \ No newline at end of file + 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()) \ No newline at end of file