def build_label_database(): db = SkyMapDatabase() db.drop_table("skymap_labels") # Create table db.commit_query("""CREATE TABLE skymap_labels ( label_id INT PRIMARY KEY, label_text TEXT, fontsize TEXT, width REAL, height REAL)""") stars = [ Star(r) for r in db.query( """SELECT * FROM skymap_stars WHERE proper_name is not null""") ] p = Point(0, 0) i = 0 nstars = len(stars) for n, s in enumerate(stars): sys.stdout.write("\r{}%".format(int(round(100 * n / float(nstars))))) sys.stdout.flush() if not s.proper_name.strip() and not s.identifier_string.strip(): continue if s.proper_name: i += 1 if db.query_one( """SELECT * FROM skymap_labels WHERE label_text="{}" AND fontsize="{}" """ .format(s.proper_name, "tiny")) is None: l = Label(p, s.proper_name, fontsize="tiny", render_size=True) size = l.size db.commit_query( """INSERT INTO skymap_labels VALUES ({}, "{}", "{}", {}, {})""" .format(i, s.proper_name, "tiny", size[0], size[1])) if s.identifier_string: i += 1 if db.query_one( """SELECT * FROM skymap_labels WHERE label_text="{}" AND fontsize="{}" """ .format(s.identifier_string, "tiny")) is None: l = Label(p, s.identifier_string.strip(), fontsize="tiny", render_size=True) size = l.size db.commit_query( """INSERT INTO skymap_labels VALUES ({}, "{}", "{}", {}, {})""" .format(i, s.identifier_string, "tiny", size[0], size[1])) db.close()
def get_label_size(text, fontsize): db = SkyMapDatabase() res = db.query_one( """SELECT * FROM skymap_labels WHERE label_text="{}" AND fontsize="{}" """ .format(text, fontsize)) db.close() if res is None: return None return res['width'], res['height']
class ConstellationFinder(object): """ Find the constellation for a given coordinate. """ def __init__(self, epoch=None): self.db = SkyMapDatabase() self.precessor = PointInConstellationPrecession(epoch) def find(self, ra, de): ra, de = self.precessor.precess(ra, de) ra /= 15.0 # Convert to fractional hours of right ascension q = """ SELECT const FROM skymap.cst_id_data WHERE DE_low < {0} AND RA_low <= {1} AND RA_up > {1} ORDER BY pk LIMIT 1 """.format(de, ra) return self.db.query_one(q)['const'].lower()
class StarDatabaseTest(unittest.TestCase): def setUp(self): self.db = SkyMapDatabase() # Unicity def test_hip_unique(self): """Check whether HIP identification is unique within Hipparcos""" q = """ SELECT COUNT(*) AS n FROM ( SELECT HIP FROM hiptyc_hip_main GROUP BY HIP HAVING COUNT(HIP)>1 ) AS h """ self.assertEqual(self.db.query_one(q)['n'], 0) def test_tyc1_unique(self): """Check whether TYC identification is unique within Tycho-1""" q = """ SELECT COUNT(*) AS n FROM ( SELECT tyc FROM ( SELECT CONCAT(TYC1, '-', TYC2, '-', TYC3) as tyc FROM hiptyc_tyc_main ) AS t1 GROUP BY tyc HAVING COUNT(tyc)>1 ) AS t2 """ self.assertEqual(self.db.query_one(q)['n'], 0) def test_tyc2_unique(self): """Check whether TYC identification is unique within Tycho-2. Strangely, 254 duplicates are found, all between main and supplement 1. In all cases except for 1 (there it is the AB-component), the A-component is in the main component, the other (in all but 4 cases the B-component, three times it is the C-component, once the P-component) in supplement 1. Positions differ slightly within each pair. All supplement 1 stars are Hipparcos stars. Stars seem to be in Tycho-1 and Hipparcos as single entries with multiple components (Double/Multiple annex). Not resolved yet! """ # TODO: solve q = """ SELECT COUNT(*) AS n FROM ( SELECT tyc FROM ( SELECT CONCAT(TYC1, '-', TYC2, '-', TYC3) as tyc FROM tyc2_tyc2 UNION ALL SELECT CONCAT(TYC1, '-', TYC2, '-', TYC3) as tyc FROM tyc2_suppl_1 UNION ALL SELECT CONCAT(TYC1, '-', TYC2, '-', TYC3) as tyc FROM tyc2_suppl_2 ) AS t1 GROUP BY tyc HAVING COUNT(tyc)>1 ) AS t2 """ self.assertEqual(self.db.query_one(q)['n'], 254) # Hipparcos - Hipparcos New Reduction def test_hip_hipnew(self): """Check whether all Hipparcos stars are in Hipparcos New Reduction; 263 stars missing (all stars without proper astrometry)""" q = """ SELECT COUNT(*) AS n FROM hiptyc_hip_main AS h LEFT JOIN hipnew_hip2 AS h2 ON h2.HIP=h.HIP WHERE h2.HIP IS NULL """ self.assertEqual(self.db.query_one(q)['n'], 263) def test_hipnew_hip(self): """Check whether all Hipparcos New Reduction Stars are in Hipparcos""" q = """ SELECT COUNT(*) AS n FROM hipnew_hip2 AS h2 LEFT JOIN hiptyc_hip_main AS h ON h2.HIP=h.HIP WHERE h.HIP IS NULL """ self.assertEqual(self.db.query_one(q)['n'], 0) # Hipparcos - Tycho-1 def test_tyc1_hip(self): """Check whether all Tycho-1 stars labeled as Hipparcos stars are in Hipparcos""" q = """ SELECT COUNT(*) AS n FROM hiptyc_tyc_main AS t LEFT JOIN hiptyc_hip_main AS h ON t.HIP=h.HIP WHERE t.HIP IS NOT NULL AND h.HIP IS NULL """ self.assertEqual(self.db.query_one(q)['n'], 0) def test_hip_tyc1(self): """Check whether all Hipparcos stars are in Tycho-1. Only the Hipparcos stars without astrometric solutions (263 stars) are not found in Tycho-1. """ q = """ SELECT COUNT(*) AS n FROM hiptyc_hip_main AS h LEFT JOIN hiptyc_tyc_main AS t ON t.HIP=h.HIP WHERE t.HIP IS NULL """ self.assertEqual(self.db.query_one(q)['n'], 263) def test_hip_to_multiple_tyc1(self): """Check multiple stars between Hipparcos and Tycho-1. These are multiple stars of which the components are recorded in both databases. The query checks for all components of a given HIP star to see if they are found in Tycho-1. Component identifiers should match or if not, the number of components from Hipparcos should be equal to the number of letters in the concatenated Tycho-1 component identifiers.""" q = """ SELECT COUNT(*) AS n FROM ( SELECT t.HIP, t.m_HIP AS T_comp, h.m_HIP AS H_comp, h.Ncomp AS H_ncomp, t.Ncomp AS T_ncomp FROM ( SELECT HIP, GROUP_CONCAT(TRIM(m_HIP) SEPARATOR '') AS m_HIP, COUNT(HIP) AS Ncomp FROM hiptyc_tyc_main GROUP BY HIP HAVING COUNT(HIP)>1 ) AS t LEFT JOIN ( SELECT HIP, m_HIP, Ncomp FROM hiptyc_hip_main ) AS h ON t.HIP=h.HIP WHERE NOT ( (t.m_HIP = h.m_HIP OR t.m_HIP = REVERSE(h.m_HIP)) OR LENGTH(t.m_HIP) = h.Ncomp ) ) AS t """ self.assertEqual(self.db.query_one(q)['n'], 0) # Tycho-1 - Tycho-2 def test_tyc1_tyc2(self): """Check whether all Tycho-1 stars are in Tycho-2 (including supplement 1 and 2). Stars with astrometric quality of 9 are not included in Tycho-2.""" q = """ SELECT COUNT(*) AS n FROM hiptyc_tyc_main AS t1 LEFT JOIN ( SELECT TYC1, TYC2, TYC3 FROM tyc2_tyc2 UNION ALL SELECT TYC1, TYC2, TYC3 FROM tyc2_suppl_1 UNION ALL SELECT TYC1, TYC2, TYC3 FROM tyc2_suppl_2 ) AS t2 ON t1.TYC1=t2.TYC1 AND t1.TYC2=t2.TYC2 AND t1.TYC3=t2.TYC3 WHERE t2.TYC1 IS NULL AND t1.Q != 9 """ self.assertEqual(self.db.query_one(q)['n'], 0) def test_tyc2_tyc1(self): """Check whether all Tycho-2 stars that are labeled as Tycho-1 stars are in Tycho-1. Hipparcos stars that were not measured by Tycho-1 were included in Tycho-1, but are not labeled as Tycho-1 stars in Tycho-2. These stars are labeled in Tycho-1 with an 'H' in the 'Source' field. Tycho-1 stars that are resolved into multiple Tycho-2 stars are all labeled as Tycho-1 stars, but have different Tycho-2 ids. Such multiple stars share the same TYC1 and TYC2. The original Tycho-1 stars has TYC3 equal to 1, so the other components have higher TYC3 numbers. There are 1866 such stars. """ q = """ SELECT COUNT(*) AS n FROM ( SELECT TYC1, TYC2, TYC3 FROM tyc2_tyc2 WHERE TYC='T' UNION ALL SELECT TYC1, TYC2, TYC3 FROM tyc2_suppl_1 WHERE TYC='T' UNION ALL SELECT TYC1, TYC2, TYC3 FROM tyc2_suppl_2 WHERE TYC='T' ) AS t2 LEFT JOIN ( SELECT TYC1, TYC2, TYC3 FROM hiptyc_tyc_main WHERE Source!='H' ) AS t1 ON t1.TYC1=t2.TYC1 AND t1.TYC2=t2.TYC2 AND t1.TYC3=t2.TYC3 WHERE t1.TYC1 IS NULL """ self.assertEqual(self.db.query_one(q)['n'], 1866) # Tycho-2 internal def test_tyc2_supplement1(self): """Check that there is no overlap between Tycho-2 main and Tycho-2 supplement 1. See test_tyc2_unique for more info on the 254 stars that do overlap.""" q = """ SELECT COUNT(*) AS n FROM tyc2_tyc2 as t2 INNER JOIN tyc2_suppl_1 as ts1 ON t2.TYC1=ts1.TYC1 AND t2.TYC2=ts1.TYC2 AND t2.TYC3=ts1.TYC3 """ self.assertEqual(self.db.query_one(q)['n'], 254) def test_tyc2_supplement2(self): """Check that there is no overlap between Tycho-2 main and Tycho-2 supplement 1""" q = """ SELECT COUNT(*) AS n FROM tyc2_tyc2 as t2 INNER JOIN tyc2_suppl_2 as ts2 ON t2.TYC1=ts2.TYC1 AND t2.TYC2=ts2.TYC2 AND t2.TYC3=ts2.TYC3 """ self.assertEqual(self.db.query_one(q)['n'], 0) def test_tyc2_supplement1_supplement2(self): """Check that there is no overlap between Tycho-2 supplement 1 and Tycho-2 supplement 2""" q = """ SELECT COUNT(*) AS n FROM tyc2_suppl_1 as ts1 INNER JOIN tyc2_suppl_2 as ts2 ON ts1.TYC1=ts2.TYC1 AND ts1.TYC2=ts2.TYC2 AND ts1.TYC3=ts2.TYC3 """ self.assertEqual(self.db.query_one(q)['n'], 0) # Hipparcos - Tycho-2 def test_hip_tyc2(self): """Check whether all Hipparcos stars are found in Tycho-2. The 263 Hipparcos star without an astrometric solution are not included in Tycho-2.""" q = """ SELECT COUNT(*) AS n FROM hiptyc_hip_main AS h LEFT JOIN ( SELECT TYC1, TYC2, TYC3, HIP FROM tyc2_tyc2 UNION ALL SELECT TYC1, TYC2, TYC3, HIP FROM tyc2_suppl_1 UNION ALL SELECT TYC1, TYC2, TYC3, HIP FROM tyc2_suppl_2 ) AS t2 ON t2.HIP=h.HIP WHERE t2.HIP IS NULL """ self.assertEqual(self.db.query_one(q)['n'], 263) def test_tyc2_hip(self): """Check whether all Tycho-2 stars labeled as Hipparcos stars are found in Hipparcos""" q = """ SELECT COUNT(*) AS n FROM ( SELECT TYC1, TYC2, TYC3, HIP FROM tyc2_tyc2 UNION ALL SELECT TYC1, TYC2, TYC3, HIP FROM tyc2_suppl_1 UNION ALL SELECT TYC1, TYC2, TYC3, HIP FROM tyc2_suppl_2 ) AS t2 LEFT JOIN hiptyc_hip_main AS h ON t2.HIP=h.HIP WHERE h.HIP IS NULL AND t2.HIP IS NOT NULL """ self.assertEqual(self.db.query_one(q)['n'], 0) def test_hip_to_multiple_tyc2(self): """Check multiple stars between Hipparcos and Tycho-2. These are multiple stars of which the components are recorded in both databases. The query checks for all components of a given HIP star to see if they are found in Tycho-2. Component identifiers should match or if not, the number of components from Hipparcos should be equal to the number of letters in the concatenated Tycho-2 component identifiers.""" q = """ SELECT COUNT(*) AS n FROM ( SELECT t.HIP, t.m_HIP AS T_comp, h.m_HIP AS H_comp, h.Ncomp AS H_ncomp, t.Ncomp AS T_ncomp FROM ( SELECT HIP, GROUP_CONCAT(TRIM(CCDM) SEPARATOR '') AS m_HIP, COUNT(HIP) AS Ncomp FROM ( SELECT HIP, CCDM FROM tyc2_tyc2 UNION ALL SELECT HIP, CCDM FROM tyc2_suppl_1 ) as tt GROUP BY HIP HAVING COUNT(HIP)>1 ) AS t LEFT JOIN ( SELECT HIP, m_HIP, Ncomp FROM hiptyc_hip_main ) AS h ON t.HIP=h.HIP WHERE NOT ( (t.m_HIP = h.m_HIP OR t.m_HIP = REVERSE(h.m_HIP)) OR LENGTH(t.m_HIP) = h.Ncomp ) ) AS t """ self.assertEqual(self.db.query_one(q)['n'], 0) # Tycho-2 supplement 1 - Hipparcos/Tycho-1 def test_tyc2_supplement1_hip(self): """Check whether all Tycho-2 supplement 1 stars are in Tycho-1 and/or Hipparcos""" q = """ SELECT COUNT(*) AS n FROM tyc2_suppl_1 AS ts1 LEFT JOIN hiptyc_hip_main AS h ON ts1.HIP=h.HIP WHERE ts1.flag='H' AND h.HIP IS NULL """ self.assertEqual(self.db.query_one(q)['n'], 0) q = """ SELECT COUNT(*) AS n FROM tyc2_suppl_1 AS ts1 LEFT JOIN hiptyc_tyc_main AS t ON ts1.TYC1=t.TYC1 AND ts1.TYC2=t.TYC2 AND ts1.TYC3=t.TYC3 WHERE ts1.flag='T' AND t.TYC1 IS NULL """ self.assertEqual(self.db.query_one(q)['n'], 0) # Tycho-2 supplement 2 - Hipparcos/Tycho-1 def test_tyc2_supplement2_hip(self): """Check whether all Tycho-2 supplement 2 stars are in Tycho-1 and/or Hipparcos""" q = """ SELECT COUNT(*) AS n FROM tyc2_suppl_2 AS ts2 LEFT JOIN hiptyc_hip_main AS h ON ts2.HIP=h.HIP WHERE ts2.flag='H' AND h.HIP IS NULL """ self.assertEqual(self.db.query_one(q)['n'], 0) q = """ SELECT COUNT(*) AS n FROM tyc2_suppl_2 AS ts2 LEFT JOIN hiptyc_tyc_main AS t ON ts2.TYC1=t.TYC1 AND ts2.TYC2=t.TYC2 AND ts2.TYC3=t.TYC3 WHERE ts2.flag='T' AND t.TYC1 IS NULL """ self.assertEqual(self.db.query_one(q)['n'], 0) def test_hd_hip_tyc1(self): pass def test_hd_tyc1_tyc2(self): pass
from tkinter import * from PIL import Image, ImageTk from astroquery.skyview import SkyView import numpy from skymap.database import SkyMapDatabase if __name__ == "__main__": sv = SkyView() db = SkyMapDatabase() res = db.query_one( """SELECT * FROM ngc_ngc2000 WHERE Name=(SELECT name FROM ngc_names WHERE object LIKE '%{}%')""" .format("M 104")) rah = res['RAh'] ram = res['RAm'] ra = rah * 15.0 + 15 * ram / 60.0 des = res['DE-'] ded = res['DEd'] dem = res['DEm'] dec = ded + dem / 60.0 if des == "-": dec *= -1 print("{}h {}m -> {}".format(rah, ram, ra)) print("{}{}deg {}m -> {}".format(des, ded, dem, dec)) image = sv.get_images(position="{}, {}".format(ra, dec), survey="DSS", pixels=(1000, 1000),