def testMacho(self): # RESULTS_NUM = 1 queries = [{"Field": 1, "Tile": 3441, "Seqn": 25}] client = StarsProvider().getProvider(obtain_method="Macho", obtain_params=queries) stars = client.getStars() self.failUnless(len(stars) == RESULTS_NUM) self.failUnless(isinstance(stars[0], Star))
def test_OgleIII(): que1 = {"ra": 72.798405, "dec": -69.00918, "delta": 5, "nearest": True} que3 = {"field": "LMC135.5", "starid": 19670} client = StarsProvider().getProvider("OgleIII", [que1, que3]) stars = client.getStars() assert len(stars) == 2 assert isinstance(stars[0], Star) check_lc(stars)
def test_CorotBright(): RESULTS_NUM = 4 queries = [{"ra": 102.707, "dec": -0.54089, "delta": 10}, {"CoRot": 116}] client = StarsProvider().getProvider("CorotBright", queries) stars = client.getStars(max_bins=100) assert len(stars) == RESULTS_NUM assert isinstance(stars[0], Star) check_lc(stars, 4)
def testCorotFaint(self): queries = [{ "Corot": "102706554" }, { "ra": 100.94235, "dec": -00.89651, "delta": 10 }] client = StarsProvider().getProvider(obtain_method="CorotFaint", obtain_params=queries) stars = client.getStars(max_bins=10000)
def test_Macho(): RESULTS_NUM = 1 queries = [{"Field": 1, "Tile": 3441, "Seqn": 25}] client = StarsProvider().getProvider("Macho", queries) stars = client.getStars() assert len(stars) == RESULTS_NUM assert isinstance(stars[0], Star) check_lc(stars) assert len(stars) == 1 assert len(stars[0].light_curves) == 2 assert len(stars[0].light_curves[0].mag) == 1188 assert len(stars[0].light_curves[1].mag) == 676
def test_OgleIII(): que1 = {"ra": 72.798405, "dec": -69.00918, "delta": 5, "nearest": True} que3 = {"field": "LMC135.5", "starid": 19670} client = StarsProvider().getProvider("OgleIII", [que1, que3]) stars = client.getStars() assert len(stars) == 2 assert len(stars[0].lightCurve.mag) == 370 assert len(stars[1].lightCurve.mag) == 370
def setUp(self): days_per_bin = 10 alphabet_size = 15 s_queries = [{"path": "quasars"}] client = StarsProvider().getProvider( obtain_method="FileManager", obtain_params=s_queries) self.s_stars = client.getStars() c_queries = [{"path": "some_stars"}] client = StarsProvider().getProvider( obtain_method="FileManager", obtain_params=c_queries) self.c_stars = client.getStars() self.N = int(np.mean([len(self.s_stars), len(self.c_stars)])) self.lc_shape_descriptor = CurvesShapeDescr(self.s_stars[:self.N / 3], days_per_bin, alphabet_size) self.hist_shape_descriptor = HistShapeDescr( self.s_stars[:self.N / 3], 10, alphabet_size) self.qda_decider = SVCDec()
def test_CorotFaint(): queries = [{ "Corot": "102706554" }, { "ra": 100.94235, "dec": -00.89651, "delta": 10 }] client = StarsProvider().getProvider("CorotFaint", queries) stars = client.getStars(max_bins=1000) assert len(stars) > 0 assert isinstance(stars[0], Star) check_lc(stars)
def testCorotBright(self): RESULTS_NUM = 2 queries = [{ "ra": 102.707, "dec": -0.54089, "delta": 10 }, { "CoRot": 116 }] client = StarsProvider().getProvider(obtain_method="CorotBright", obtain_params=queries) stars = client.getStars(max_bins=100) self.failUnless(len(stars) == RESULTS_NUM) self.failIf(None in [st.lightCurve for st in stars])
def testOgle(self): queries = [{ "starid": 2, "field_num": 1, "target": "lmc" }, { "ra": 5.545575 * 15, "dec": -70.55272, "delta": 30 }] client = StarsProvider().getProvider(obtain_method="OgleII", obtain_params=queries) stars = client.getStars() print len(stars) plotStarsPicture(stars[1:]) self.failUnless(len(stars) == 2) self.failUnless(isinstance(stars[0], Star))
def skip_test_Asas(): queries = [{ "ASAS": "000030-3937.5" }, { "ra": 10.08, "dec": -39.625, "delta": 20 }, { "ra": 0.1251, "dec": -39.6250, "delta": 10 }] client = StarsProvider().getProvider("Asas", queries) stars = client.getStars() assert len(stars) > 0 assert isinstance(stars[0], Star) check_lc(stars)
def testAsas(self): queries = [{ "ASAS": "000030-3937.5" }, { "ra": 10.08, "dec": -39.625, "delta": 20 }, { "ra": 0.1251, "dec": -39.6250, "delta": 10 }] client = StarsProvider().getProvider(obtain_method="Asas", obtain_params=queries) stars = client.getStars() self.failIf(len(stars) == 0) self.failUnless(isinstance(stars[0], Star)) print " ,".join([st.coo.to_string() for st in stars])
def test_Kepler(): RESULTS_NUM = 4 queries = [{ "ra": 297.8399, "dec": 46.57427, "delta": 10, "nearest": True }, { "kic_num": 9787239 }, { "kic_jkcolor": (0.3, 0.4), "max_records": 2 }] client = StarsProvider().getProvider("Kepler", queries) stars = client.getStars() assert not np.isnan(stars[1].lightCurve.getHistogram()[1]).any() assert stars and len(stars) == RESULTS_NUM assert stars[1].name == "KIC_9787239" assert len(stars[1].lightCurve.time) == 1624
def getStarsFromRemoteDb(query, query_path): """ This method parsing the query text in order to return desired stars from remote database. Parameters ----------- query : str Query text contains db_key and query file separated by ':' Returns -------- List of Star objects Example ------- _getStarsFromRemoteDb("OgleII:query_file.txt") --> [Star objects] query_file.txt: #starid;field;target 1;1;lmc 10;1;smc """ try: db_key, query_file = query.split(":") except: QueryInputError( "Key for resolving stars source was not recognized:\n%s" % query) queries = StatusResolver(os.path.join(query_path, query_file)).getQueries() stars = [] for query in progressbar(queries, "Querying stars: "): starsProvider = StarsProvider().getProvider(obtain_method=db_key, obtain_params=query) stars += starsProvider.getStars() return stars
def testKepler(self): # NOTE: Ok RESULTS_NUM = 4 EQUAL = (1, 2) queries = [{ "ra": 297.8399, "dec": 46.57427, "delta": 10, "nearest": True }, { "kic_num": 9787239 }, { "kic_jkcolor": (0.3, 0.4), "max_records": 2 }] client = StarsProvider().getProvider(obtain_method="Kepler", obtain_params=queries) stars = client.getStars() self.failIf(np.NaN in stars[1].lightCurve.getHistogram()[1]) self.failUnless(stars and len(stars) == RESULTS_NUM)
def queryStar(self, query): status = collections.OrderedDict( (("found", False), ("lc", False), ("passed", False))) try: provider = StarsProvider().getProvider(self.obth_method, query) if hasattr(provider, "multiproc"): provider.multiproc = False stars = provider.getStars() except QueryInputError: raise except (KeyboardInterrupt, SystemExit): raise except Exception as e: warn(str(e)) warn("Couldn't download any star for query %s" % query ) stars = [] # TODO: status attribute is rewrited and just status of the last star is noted for one_star in stars: status["found"] = True contain_lc = True try: one_star.lightCurve.time except AttributeError: contain_lc = False if contain_lc: # TODO if self.save_coords and self.stars_filters: spc = self.stars_filters[ 0].getSpaceCoordinates([one_star]).values if len(spc): self._saveCoords([one_star.name] + spc[0].tolist()) # Try to apply filters to the star try: passed = self.filterStar(one_star, query) status["lc"] = True status["passed"] = passed except (KeyboardInterrupt, SystemExit): raise except IOError as err: raise InvalidFilesPath(err) except Exception as err: self.failProcedure(query, err) warn( "Something went wrong during filtering:\n\t%s" % err) else: status["lc"] = False status["passed"] = False query["name"] = one_star.name self.statusFile(query, status) if not stars: query["name"] = "" self.statusFile(query, status) return stars, status