예제 #1
0
    def getCatalagoFromTAP(self):

        degrees_range = self.__degrees_range
        ra_min = self.__coordinates.ra.degree - (degrees_range / 2)
        ra_max = self.__coordinates.ra.degree + (degrees_range / 2)
        dec_min = self.__coordinates.dec.degree - (degrees_range / 2)
        dec_max = self.__coordinates.dec.degree + (degrees_range / 2)
        query = self.__simple_rec_query.format(ra_min, ra_max, dec_min,
                                               dec_max)

        respond = self.getTapRequest(query=query)

        result = AstroSource(self.__coordinates)
        if len(respond) > 0:
            self.setSummary(result, respond)
            """
            image = ImageSource(result.getSummary()["id"], self.__catalog_provider)

            bands = ["grz", "gz", "g"]
            mag_band = [result.getSummary()["mag_r"], result.getSummary()["mag_z"], result.getSummary()["mag_g"]]

            for index in range(len(bands)):
                band = bands[index]
                mag = mag_band[index]
                img = self.getImage(self.__coordinates, band)
                image.addCutout(img["jpeg"], 256, band, mag)
                image.addFile(band, img["fits"])

            result.addImage(image)
            """

        return result
예제 #2
0
    def query(self, **kwargs):
        if "coordinates" in kwargs:
            self.__coordinates = kwargs["coordinates"]
        elif "ra" in kwargs and "dec" in kwargs:
            self.__coordinates = str(kwargs["ra"]) + "," + str(kwargs["dec"])
        radius = 1  # arcmin
        if "radius" in kwargs:
            radius = kwargs["radius"]

        self.__coordinates = CoordinateParser.validateCoordinates(
            self.__coordinates)
        self.__save_path = self.__save_path.format(
            str(self.__coordinates.ra.degree) + "_" +
            str(self.__coordinates.dec.degree))

        self.__arcmin_range = radius
        self.__degrees_range = CoordinateParser.getMinToDegree(radius)
        result = AstroSource(self.__coordinates)
        df = self.getCatalogFromSIAS()

        # GET catalogs from SIAS DB, the object is selected from the near source using Pythagorean theorem
        if len(df.index) > 0:
            index, loss = CoordinateParser.getNearPositionIndex(
                self.__coordinates.ra.degree, self.__coordinates.dec.degree,
                df["ra"].values, df["dec"].values)
            self.loss = loss
            self.setSummary(result, df.iloc[index])

            table = Table.from_pandas(df)
            Utils.createPath(self.__save_path)
            catalog = CatalogSource(
                "des", "Search in radius " + str(self.__arcmin_range))
            VOTableUtil.saveFromTable(table, self.__save_path + "catalog.xml")
            catalog.addFile("des", self.__save_path + "catalog.xml", "vo")

            result.addCatalog(catalog)

            #GET IMAGES From SIAS by ra dec radio in arcmin(the service recieve radii in degree)
            img = self.getImageFromSIAS()
            if img != None:
                result.addImage(img)

        return result
예제 #3
0
    def query(self, **kwargs):

        # check for data release to use
        if "coordinates" in kwargs:
            self.__coordinates = kwargs["coordinates"]
        elif "ra" in kwargs and "dec" in kwargs:
            self.__coordinates = str(kwargs["ra"]) + "," + str(kwargs["dec"])
        else:
            raise ValueError(
                "Not valid coordinates found. Used coordinates key or ra dec keys"
            )

        radius = 1  # arcmin
        if "radius" in kwargs:
            radius = kwargs["radius"]

        self.__coordinates = CoordinateParser.validateCoordinates(
            self.__coordinates)

        self.__save_path = self.__save_path.format(
            str(self.__coordinates.ra.degree) + "_" +
            str(self.__coordinates.dec.degree))

        self.__radius_degree = CoordinateParser.getMinToDegree(radius)

        all_wise = self.getData(self.__service_provider["all_wise"])
        wise = self.getData(self.__service_provider["wise"])

        result = AstroSource(self.__coordinates)
        catalog = None
        allWiseWavelenght = WaveLenghtCover.wise()

        if len(all_wise) > 0:
            Utils.createPath(self.__save_path)
            catalog = CatalogSource("allwise",
                                    "Search in radius " + str(radius))
            VOTableUtil.saveFromTable(all_wise,
                                      self.__save_path + "allwise_catalog.xml")
            catalog.addFile("allwise",
                            self.__save_path + "allwise_catalog.xml", "vo")

            index, loss = CoordinateParser.getNearPositionIndex(
                self.__coordinates.ra.degree, self.__coordinates.dec.degree,
                all_wise["RAJ2000"], all_wise["DEJ2000"])

            result.addSummaryParams("allwise_ra", all_wise["RAJ2000"][index])
            result.addSummaryParams("allwise_dec", all_wise["DEJ2000"][index])
            result.addSummaryParams("distance", loss)

            data = {
                "lambda": allWiseWavelenght["w1"],
                "ab": str(all_wise["W1mag"][index]),
                "err": str(all_wise["e_W1mag"][index])
            }

            result.addSummaryParams("allwise_w1mag", data)

            data = {
                "lambda": allWiseWavelenght["w2"],
                "ab": str(all_wise["W2mag"][index]),
                "err": str(all_wise["e_W2mag"][index])
            }
            result.addSummaryParams("allwise_w2mag", data)

            data = {
                "lambda": allWiseWavelenght["w3"],
                "ab": str(all_wise["W3mag"][index]),
                "err": str(all_wise["e_W3mag"][index])
            }

            result.addSummaryParams("allwise_w3mag", data)

            data = {
                "lambda": allWiseWavelenght["w4"],
                "ab": str(all_wise["W4mag"][index]),
                "err": str(all_wise["e_W4mag"][index])
            }

            result.addSummaryParams("allwise_w4mag", data)

            data = {
                "lambda": allWiseWavelenght["j"],
                "ab": str(all_wise["Jmag"][index]),
                "err": str(all_wise["e_Jmag"][index])
            }

            result.addSummaryParams("allwise_Jmag", data)

            data = {
                "lambda": allWiseWavelenght["h"],
                "ab": str(all_wise["Hmag"][index]),
                "err": str(all_wise["e_Hmag"][index])
            }
            result.addSummaryParams("allwise_Hmag", data)

            data = {
                "lambda": allWiseWavelenght["k"],
                "ab": str(all_wise["Kmag"][index]),
                "err": str(all_wise["e_Kmag"][index])
            }
            result.addSummaryParams("allwise_Kmag", data)

            result.addCatalog(catalog)

        if len(wise) > 0:
            index, loss = CoordinateParser.getNearPositionIndex(
                self.__coordinates.ra.degree, self.__coordinates.dec.degree,
                wise["RAJ2000"], wise["DEJ2000"])

            if catalog is None:
                Utils.createPath(self.__save_path)
                catalog = CatalogSource(
                    "wise", "Search in radius(arcmin) " + str(radius))

            VOTableUtil.saveFromTable(wise,
                                      self.__save_path + "wise_catalog.xml")
            catalog.addFile("wise", self.__save_path + "wise_catalog.xml",
                            "vo")

            result.addSummaryParams("wise_ra", wise["RAJ2000"][index])
            result.addSummaryParams("wise_dec", wise["DEJ2000"][index])
            result.addSummaryParams("wise_distance", loss)

            data = {
                "lambda": allWiseWavelenght["w1"],
                "ab": str(wise["W1mag"][index]),
                "err": str(wise["e_W1mag"][index])
            }

            result.addSummaryParams("wise_w1mag", data)

            data = {
                "lambda": allWiseWavelenght["w2"],
                "ab": str(wise["W2mag"][index]),
                "err": str(wise["e_W2mag"][index])
            }

            result.addSummaryParams("wise_w2mag", data)

            data = {
                "lambda": allWiseWavelenght["w3"],
                "ab": str(wise["W3mag"][index]),
                "err": str(wise["e_W3mag"][index])
            }

            result.addSummaryParams("wise_w3mag", data)

            data = {
                "lambda": allWiseWavelenght["w4"],
                "ab": str(wise["W4mag"][index]),
                "err": str(wise["e_W4mag"][index])
            }

            result.addSummaryParams("wise_w4mag", data)

            data = {
                "lambda": allWiseWavelenght["j"],
                "ab": str(wise["Jmag"][index]),
                "err": str(wise["e_Jmag"][index])
            }

            result.addSummaryParams("wise_Jmag", data)

            data = {
                "lambda": allWiseWavelenght["h"],
                "ab": str(wise["Hmag"][index]),
                "err": str(wise["e_Hmag"][index])
            }

            result.addSummaryParams("wise_Hmag", data)

            data = {
                "lambda": allWiseWavelenght["k"],
                "ab": str(wise["Kmag"][index]),
                "err": str(wise["e_Kmag"][index])
            }

            result.addSummaryParams("wise_Kmag", data)

            result.addCatalog(catalog)

        return result
예제 #4
0
    def query(self, **kwargs):
        if "coordinates" in kwargs:
            self.__coordinates = kwargs["coordinates"]
        elif "ra" in kwargs and "dec" in kwargs:
            self.__coordinates = str(kwargs["ra"]) + "," + str(kwargs["dec"])
        radius = 1  # arcmin
        if "radius" in kwargs:
            radius = kwargs["radius"]

        self.__coordinates = CoordinateParser.validateCoordinates(
            self.__coordinates)
        self.__save_path = self.__save_path.format(
            str(self.__coordinates.ra.degree) + "_" +
            str(self.__coordinates.dec.degree))

        degrees_range = CoordinateParser.getMinToDegree(radius)

        ra_min = self.__coordinates.ra.degree - (degrees_range / 2)
        ra_max = self.__coordinates.ra.degree + (degrees_range / 2)
        dec_min = self.__coordinates.dec.degree - (degrees_range / 2)
        dec_max = self.__coordinates.dec.degree + (degrees_range / 2)
        query = self.__simple_rec_query.format(ra_min, ra_max, dec_min,
                                               dec_max)
        respond = self.getTapRequest(query=query)
        result = AstroSource(self.__coordinates)
        if len(respond) > 0:

            Utils.createPath(self.__save_path)
            catalog = CatalogSource("decals",
                                    "Search in radius " + str(radius))
            VOTableUtil.saveFromTable(respond,
                                      self.__save_path + "catalog.xml")
            catalog.addFile("decals", self.__save_path + "catalog.xml", "vo")

            result.addCatalog(catalog)

            index, loss = CoordinateParser.getNearPositionIndex(
                self.__coordinates.ra.degree, self.__coordinates.dec.degree,
                respond["ra"], respond["dec"])
            result.addSummaryParams("ra", respond["ra"][index])
            result.addSummaryParams("dec", respond["dec"][index])
            result.addSummaryParams("distance", loss)

            decals = WaveLenghtCover.decals()

            data = {
                "lambda": decals["g"],
                "ab": str(respond["mag_g"][index]),
                "err": -99
            }
            result.addSummaryParams("mag_g", data)

            data = {
                "lambda": decals["r"],
                "ab": str(respond["mag_r"][index]),
                "err": -99
            }
            result.addSummaryParams("mag_r", data)

            data = {
                "lambda": decals["z"],
                "ab": str(respond["mag_z"][index]),
                "err": -99
            }
            result.addSummaryParams("mag_z", data)

            result.addSummaryParams("flux_g", str(respond["flux_g"][index]))
            result.addSummaryParams("flux_r", str(respond["flux_r"][index]))
            result.addSummaryParams("flux_z", str(respond["flux_z"][index]))
            result.addSummaryParams("type", str(respond["type"][index]))

            image = ImageSource(result.getSummary()["id"],
                                self.__catalog_provider)

            bands = ["grz", "gz", "g"]
            mag_band = [
                result.getSummary()["mag_r"],
                result.getSummary()["mag_z"],
                result.getSummary()["mag_g"]
            ]

            for index in range(len(bands)):
                band = bands[index]
                mag = str(mag_band[index]["ab"]) + "+/-" + str(
                    mag_band[index]["err"])

                img = self.getImage(self.__coordinates, band)
                link = img["link"]
                image.addCutout(img["jpeg"], 256, band, mag, link)
                #image.addFile(band,img["fits"])

                local_path = self.__save_path + "decals_band_" + band + ".fits"
                image.addFile(band,
                              img["fits"],
                              "fits",
                              download=True,
                              local_path=local_path,
                              uncompress=False,
                              thumbnail=False,
                              external=False)

            result.addImage(image)

        return result
예제 #5
0
    def query(self, **kwargs):
        if "coordinates" in kwargs:
            self.__coordinates = kwargs["coordinates"]
        elif "ra" in kwargs and "dec" in kwargs:
            self.__coordinates = str(kwargs["ra"]) + "," + str(kwargs["dec"])
        radius = 1  # arcmin
        if "radius" in kwargs:
            radius = kwargs["radius"]
        radius_degree = CoordinateParser.getMinToDegree(radius)
        self.__coordinates = CoordinateParser.validateCoordinates(self.__coordinates)

        self.__save_path = self.__save_path.format(
            str(self.__coordinates.ra.degree) + "_" + str(self.__coordinates.dec.degree))

        try:
            result=sha.query(self.__coordinates, size=radius_degree)
        except IndexError:
            result = []
        except ValueError:
            result=[]
        respond = AstroSource(self.__coordinates)
        if len(result)>0:
            index,loss = CoordinateParser.getNearPositionIndex(self.__coordinates.ra.degree, self.__coordinates.dec.degree,
                                                          result["ra"], result["dec"])
            row = result[index]


            Utils.createPath(self.__save_path)
            catalog = CatalogSource("spitzer", "Search in radius " + str(radius))
            VOTableUtil.saveFromTable(result, self.__save_path + "catalog.xml")
            catalog.addFile("spitzer", self.__save_path + "catalog.xml", "vo")

            respond.addCatalog(catalog)

            respond.addSummaryParams("ra", row["ra"])
            respond.addSummaryParams("dec", row["dec"])
            respond.addSummaryParams("distance", loss)
            respond.addSummaryParams("filetype",row["filetype"])
            respond.addSummaryParams("modedisplayname", row["modedisplayname"])
            respond.addSummaryParams("wavelength", row["wavelength"])
            respond.addSummaryParams("minwavelength", row["minwavelength"])
            respond.addSummaryParams("maxwavelength", row["maxwavelength"])

        return respond
예제 #6
0
    def query(self, **kwargs):
        if "coordinates" in kwargs:
            self.__coordinates = kwargs["coordinates"]
        elif "ra" in kwargs and "dec" in kwargs:
            self.__coordinates = str(kwargs["ra"]) + "," + str(kwargs["dec"])
        radius = 1  # arcmin
        if "radius" in kwargs:
            radius = kwargs["radius"]

        self.__coordinates = CoordinateParser.validateCoordinates(
            self.__coordinates)
        self.__save_path = self.__save_path.format(
            str(self.__coordinates.ra.degree) + "_" +
            str(self.__coordinates.dec.degree))

        degrees_range = CoordinateParser.getMinToDegree(radius)

        ra_min = self.__coordinates.ra.degree - (degrees_range / 2)
        ra_max = self.__coordinates.ra.degree + (degrees_range / 2)
        dec_min = self.__coordinates.dec.degree - (degrees_range / 2)
        dec_max = self.__coordinates.dec.degree + (degrees_range / 2)

        table = self.__service_provider["video"]["table"]
        query = self.__simple_rec_query.format(table, ra_min, ra_max, dec_min,
                                               dec_max)
        url = self.__service_provider["video"]["url"]
        respond = self.getTapRequest(url=url, query=query)
        program = "video"
        if len(respond) <= 0:
            table = self.__service_provider["viking"]["table"]
            query = self.__simple_rec_query.format(table, ra_min, ra_max,
                                                   dec_min, dec_max)
            url = self.__service_provider["viking"]["url"]
            respond = self.getTapRequest(url=url, query=query)
            program = "viking"

        if len(respond) <= 0:
            table = self.__service_provider["vhs"]["table"]
            query = self.__simple_rec_query.format(table, ra_min, ra_max,
                                                   dec_min, dec_max)
            url = self.__service_provider["vhs"]["url"]
            respond = self.getTapRequest(url=url, query=query)
            program = "vhs"

        result = AstroSource(self.__coordinates)
        if len(respond) > 0:
            vhs = WaveLenghtCover.vhs()
            Utils.createPath(self.__save_path)
            catalog = CatalogSource("vhs", "Search in radius " + str(radius))
            VOTableUtil.saveFromTable(respond,
                                      self.__save_path + "catalog.xml")
            catalog.addFile("vhs", self.__save_path + "catalog.xml", "vo")

            result.addCatalog(catalog)

            index, loss = CoordinateParser.getNearPositionIndex(
                self.__coordinates.ra.degree, self.__coordinates.dec.degree,
                respond["ra"], respond["dec"])

            result.addSummaryParams("ra", respond["ra"][index])
            result.addSummaryParams("dec", respond["dec"][index])
            result.addSummaryParams("distance", loss)
            mag = {
                "Y":
                str(respond["yAperMag3"][index]) + "+/-" +
                str(respond["yAperMag3Err"][index]),
                "J":
                str(respond["jAperMag3"][index]) + "+/-" +
                str(respond["jAperMag3Err"][index]),
                "H":
                str(respond["hAperMag3"][index]) + "+/-" +
                str(respond["hAperMag3Err"][index]),
                "Ks":
                str(respond["ksAperMag3"][index]) + "+/-" +
                str(respond["ksAperMag3Err"][index])
            }
            if program == "video" or program == "viking":
                result.addSummaryParams(
                    "magpetro_z", {
                        "lambda": vhs["z"],
                        "ab": str(respond["zPetroMag"][index]),
                        "err": str(respond["zPetroMagErr"][index])
                    })
                result.addSummaryParams(
                    "magAper_z", {
                        "lambda": vhs["z"],
                        "ab": str(respond["zAperMag3"][index]),
                        "err": str(respond["zAperMag3Err"][index])
                    })
                mag["Z"] = str(respond["zAperMag3"][index]) + "+/-" + str(
                    respond["zAperMag3Err"][index])

            result.addSummaryParams(
                "magpetro_y", {
                    "lambda": vhs["y"],
                    "ab": str(respond["yPetroMag"][index]),
                    "err": str(respond["yPetroMagErr"][index])
                })
            result.addSummaryParams(
                "magpetro_j", {
                    "lambda": vhs["j"],
                    "ab": str(respond["jPetroMag"][index]),
                    "err": str(respond["jPetroMagErr"][index])
                })
            result.addSummaryParams(
                "magpetro_h", {
                    "lambda": vhs["h"],
                    "ab": str(respond["hPetroMag"][index]),
                    "err": str(respond["hPetroMagErr"][index])
                })
            result.addSummaryParams(
                "magpetro_ks", {
                    "lambda": vhs["ks"],
                    "ab": str(respond["ksPetroMag"][index]),
                    "err": str(respond["ksPetroMagErr"][index])
                })

            result.addSummaryParams(
                "magAper_y", {
                    "lambda": vhs["y"],
                    "ab": str(respond["yAperMag3"][index]),
                    "err": str(respond["yAperMag3Err"][index])
                })
            result.addSummaryParams(
                "magAper_j", {
                    "lambda": vhs["j"],
                    "ab": str(respond["jAperMag3"][index]),
                    "err": str(respond["jAperMag3Err"][index])
                })
            result.addSummaryParams(
                "magAper_h", {
                    "lambda": vhs["h"],
                    "ab": str(respond["hAperMag3"][index]),
                    "err": str(respond["hAperMag3Err"][index])
                })
            result.addSummaryParams(
                "magAper_ks", {
                    "lambda": vhs["ks"],
                    "ab": str(respond["ksAperMag3"][index]),
                    "err": str(respond["ksAperMag3Err"][index])
                })

            result.addSummaryParams("type", str(respond["mergedClass"][index]))

            images = self.getImages(program)

            image = ImageSource(result.getSummary()["id"],
                                self.__catalog_provider)

            saved_path = {}

            for idx in range(len(images)):
                img = images[idx]
                band = img["band"]
                mag_val = mag[band]
                image.addCutout(img["image"], 256, band, mag_val)
                index_image = ""
                if band in saved_path:
                    saved_path[band] += 1
                    index_image = saved_path[band]
                else:
                    saved_path[band] = 0

                local_path = self.__save_path + "vhs_band_" + band + str(
                    index_image) + ".fits"
                image.addFile(band,
                              img["fits"],
                              "fits",
                              download=True,
                              local_path=local_path,
                              uncompress=True,
                              thumbnail=False,
                              external=False)

            result.addImage(image)

        return result
예제 #7
0
    def query(self, **kwargs):

        # check for data release to use
        if "coordinates" in kwargs:
            self.__coordinates = kwargs["coordinates"]
        elif "ra" in kwargs and "dec" in kwargs:
            self.__coordinates = str(kwargs["ra"]) + "," + str(kwargs["dec"])
        else:
            raise ValueError(
                "Not valid coordinates found. Used coordinates key or ra dec keys"
            )

        self.__coordinates = CoordinateParser.validateCoordinates(
            self.__coordinates)

        self.__save_path = self.__save_path.format(
            str(self.__coordinates.ra.degree) + "_" +
            str(self.__coordinates.dec.degree))

        Utils.createPath(self.__save_path)

        radius = 1  # arcmin
        if "radius" in kwargs:
            radius = kwargs["radius"]

        #check for data release to use
        if "release" in kwargs:
            self.__data_release = kwargs["release"]

        respond = SDSS.query_region(self.__coordinates,
                                    spectro=True,
                                    photoobj_fields=[
                                        'ra', 'dec', 'objid', 'run', 'type',
                                        'rerun', 'camcol', 'field', 'u', 'g',
                                        'r', 'i', 'z', 'err_u', 'err_g',
                                        'err_r', 'err_i', 'err_z'
                                    ],
                                    specobj_fields=[
                                        'z', 'zErr', 'zWarning', 'plate',
                                        'mjd', 'fiberID', 'specobjid', 'run2d',
                                        'instrument', 'targetObjID'
                                    ],
                                    data_release=self.__data_release,
                                    radius=radius * u.arcmin)

        #sp=SDSS.get_spectra(matches=respond,data_release=self.__data_release)
        #im = SDSS.get_images(matches=respond,data_release=self.__data_release)

        # print(respond)
        # for col in respond.columns:
        #     print(respond[col])

        result = AstroSource(self.__coordinates)

        sdss = WaveLenghtCover.sdss()
        index, loss = CoordinateParser.getNearPositionIndex(
            self.__coordinates.ra.degree, self.__coordinates.dec.degree,
            respond["ra"], respond["dec"])
        if respond != None:
            Utils.createPath(self.__save_path)
            VOTableUtil.saveFromTable(respond,
                                      self.__save_path + "catalog.xml")
            catalog = CatalogSource("sdss",
                                    "Search in radius(arcmin) " + str(radius))
            catalog.addFile("sdss", self.__save_path + "catalog.xml", "vo")

            result.addSummaryParams("ra", respond["ra"][index])
            result.addSummaryParams("dec", respond["dec"][index])

            result.addSummaryParams("distance", loss)

            data = {
                "lambda": sdss["u"],
                "ab": str(respond["u"][index]),
                "err": str(respond["err_u"][index])
            }
            result.addSummaryParams("mag_u", data)

            data = {
                "lambda": sdss["g"],
                "ab": str(respond["g"][index]),
                "err": str(respond["err_g"][index])
            }
            result.addSummaryParams("mag_g", data)

            data = {
                "lambda": sdss["r"],
                "ab": str(respond["r"][index]),
                "err": str(respond["err_r"][index])
            }
            result.addSummaryParams("mag_r", data)

            data = {
                "lambda": sdss["i"],
                "ab": str(respond["i"][index]),
                "err": str(respond["err_i"][index])
            }
            result.addSummaryParams("mag_i", data)

            data = {
                "lambda": sdss["z"],
                "ab": str(respond["z"][index]),
                "err": str(respond["err_z"][index])
            }
            result.addSummaryParams("mag_z", data)

            result.addSummaryParams("type", str(respond["type"][index]))
            result.addSummaryParams("z", respond["z1"][index])
            result.addSummaryParams("zErr", str(respond["zErr"][index]))
            result.addSummaryParams("zWarning",
                                    str(respond["zWarning"][index]))

            image = ImageSource(result.getSummary()["id"],
                                self.__catalog_provider)

            bands = ["u", "g", "r", "i", "z"]
            displayUrl = self.__service_provider["display"]

            imagesList = self.downloadImages(respond["rerun"][index],
                                             respond["run"][index],
                                             respond["camcol"][index],
                                             respond["field"][index], bands)

            result.addCatalog(catalog)

            for img in imagesList:
                band = str(img["band"]).replace(" ", "")
                image.addFile(name="band-" + img["band"],
                              url=img["url"],
                              download=True,
                              local_path=img["local_path"],
                              uncompress=True,
                              thumbnail=True,
                              external=False)
                image.addCutout(self.getImageCutout(respond["ra"][index],
                                                    respond["dec"][index],
                                                    query="G" +
                                                    str(band).upper()),
                                300,
                                band,
                                magnitude=str(respond[band][index]) + "+/-" +
                                str(respond["err_" + band][index]),
                                link=displayUrl.format(respond["ra"][index],
                                                       respond["dec"][index]))

            result.addImage(image)

            if respond["specobjid"][index] != None:
                spec = self.getSpecImage(respond["specobjid"][index])
                spectra = SpectraSource(result.getSummary()["id"],
                                        self.__catalog_provider)
                spectra.addCutout(spec, 700, "visible")
                result.addSpectra(spectra)
        else:
            result.addSummaryParams("error",
                                    "Any results was found in SDSS Archive")

        return result
예제 #8
0
    def query(self, **kwargs):
        if "coordinates" in kwargs:
            self.__coordinates = kwargs["coordinates"]
        elif "ra" in kwargs and "dec" in kwargs:
            self.__coordinates = str(kwargs["ra"]) + "," + str(kwargs["dec"])
        radius = 1  # arcmin
        if "radius" in kwargs:
            radius = kwargs["radius"]

        self.__coordinates = CoordinateParser.validateCoordinates(
            self.__coordinates)
        self.__save_path = self.__save_path.format(
            str(self.__coordinates.ra.degree) + "_" +
            str(self.__coordinates.dec.degree))

        width_survey = "w"
        deep_survey = "d"

        radius_degree = CoordinateParser.getMinToDegree(radius)

        query = self.__simple_rec_query.format(deep_survey,
                                               self.__coordinates.ra.degree,
                                               self.__coordinates.dec.degree,
                                               radius_degree)
        respond = self.getTapRequest(query=query)
        self.wide = False

        if len(respond) <= 0:
            query = self.__simple_rec_query.format(
                width_survey, self.__coordinates.ra.degree,
                self.__coordinates.dec.degree, radius_degree)
            respond = self.getTapRequest(query=query)
            self.wide = True

        result = AstroSource(self.__coordinates)
        if len(respond) > 0:
            Utils.createPath(self.__save_path)

            catalog = CatalogSource("cfht", "Search in radius " + str(radius))
            VOTableUtil.saveFromTable(respond,
                                      self.__save_path + "catalog.xml")
            catalog.addFile("allwise", self.__save_path + "catalog.xml", "vo")

            index, loss = CoordinateParser.getNearPositionIndex(
                self.__coordinates.ra.degree, self.__coordinates.dec.degree,
                respond["RAJ2000"], respond["DEJ2000"])

            result.addSummaryParams("ra", respond["RAJ2000"][index])
            result.addSummaryParams("dec", respond["DEJ2000"][index])

            result.addSummaryParams("distance", loss)
            result.addSummaryParams("survey", "wide" if self.wide else "deep")

            cfht = WaveLenghtCover.cfht()
            data = {
                "lambda": cfht["u"],
                "ab": str(respond["umag"][index]),
                "err": str(respond["e_umag"][index])
            }

            result.addSummaryParams("mag_u", data)

            data = {
                "lambda": cfht["g"],
                "ab": str(respond["gmag"][index]),
                "err": str(respond["e_gmag"][index])
            }
            result.addSummaryParams("mag_g", data)

            data = {
                "lambda": cfht["r"],
                "ab": str(respond["rmag"][index]),
                "err": str(respond["e_rmag"][index])
            }
            result.addSummaryParams("mag_r", data)

            data = {
                "lambda": cfht["i"],
                "ab": str(respond["imag"][index]),
                "err": str(respond["e_imag"][index])
            }
            result.addSummaryParams("mag_i", data)

            data = {
                "lambda": cfht["z"],
                "ab": str(respond["zmag"][index]),
                "err": str(respond["e_zmag"][index])
            }
            result.addSummaryParams("mag_z", data)

            result.addSummaryParams("flux_u", str(respond["uFpk"][index]))
            result.addSummaryParams("flux_g", str(respond["gFpk"][index]))
            result.addSummaryParams("flux_r", str(respond["rFpk"][index]))
            result.addSummaryParams("flux_i", str(respond["iFpk"][index]))
            result.addSummaryParams("flux_z", str(respond["zFpk"][index]))

            result.addCatalog(catalog)

            if self.wide:

                #img=self.getWideImages()
                url = self.__service_provider[
                    "width_cutout"] + "?lang=en&object=&ra={0}&dec={1}&size=256"
                url = url.format(self.__coordinates.ra.degree,
                                 self.__coordinates.dec.degree)
                images = self.delayRequest(url)
                image = ImageSource(result.getSummary()["id"],
                                    self.__catalog_provider)
                mag = {
                    "U":
                    str(respond["umag"][index]) + "+/-" +
                    str(respond["e_umag"][index]),
                    "G":
                    str(respond["gmag"][index]) + "+/-" +
                    str(respond["e_gmag"][index]),
                    "R":
                    str(respond["rmag"][index]) + "+/-" +
                    str(respond["e_rmag"][index]),
                    "I":
                    str(respond["imag"][index]) + "+/-" +
                    str(respond["e_imag"][index]),
                    "Z":
                    str(respond["zmag"][index]) + "+/-" +
                    str(respond["e_zmag"][index]),
                    "2":
                    -99
                }
                for idx in range(len(images)):
                    img = images[idx]
                    band = img["band"]
                    mag_val = mag[band]
                    image.addCutout(img["image"], 256, band, mag_val)

                    local_path = self.__save_path + "cfht_band_" + band + ".fits"
                    image.addFile(band,
                                  img["fits"],
                                  "fits",
                                  download=True,
                                  local_path=local_path,
                                  uncompress=False,
                                  thumbnail=True,
                                  external=False)

                result.addImage(image)

        return result
예제 #9
0
    def query(self, **kwargs):

        # check for data release to use
        if "coordinates" in kwargs:
            self.__coordinates = kwargs["coordinates"]
        elif "ra" in kwargs and "dec" in kwargs:
            self.__coordinates = str(kwargs["ra"]) + "," + str(kwargs["dec"])
        else:
            raise ValueError("Not valid coordinates found. Used coordinates key or ra dec keys")

        radius = 1  # arcmin
        if "radius" in kwargs:
            radius = kwargs["radius"]

        self.__coordinates = CoordinateParser.validateCoordinates(self.__coordinates)

        large_suvey="II/319/las9"
        galactic_cluster_suvey = "II/319/gcs9"
        deep_suvey = "II/319/dxs9"
        galatic_plane_survey="II/316/gps6"

        radius_degree = CoordinateParser.getMinToDegree(radius)
        program_id="ALL"

        self.__save_path = self.__save_path.format(
            str(self.__coordinates.ra.degree) + "_" + str(self.__coordinates.dec.degree))

        query = self.__simple_rec_query.format(large_suvey, self.__coordinates.ra.degree, self.__coordinates.dec.degree,
                                               radius_degree)
        respond = self.getTapRequest(query=query)

        result = AstroSource(self.__coordinates)
        if len(respond) <= 0:
            query = self.__simple_rec_query.format(galactic_cluster_suvey, self.__coordinates.ra.degree,
                                                   self.__coordinates.dec.degree, radius_degree)
            respond = self.getTapRequest(query=query)
            program_id = "GCS"

        if len(respond) <= 0:
            query = self.__simple_rec_query.format(deep_suvey, self.__coordinates.ra.degree,
                                                   self.__coordinates.dec.degree, radius_degree)
            respond = self.getTapRequest(query=query)
            program_id = "DXS"

        if len(respond) <= 0:
            query = self.__simple_rec_query.format(galatic_plane_survey, self.__coordinates.ra.degree,
                                                   self.__coordinates.dec.degree, radius_degree)
            respond = self.getTapRequest(query=query)
            program_id = "GPS"

        if len(respond)>0:


            Utils.createPath(self.__save_path)
            catalog = CatalogSource("ukidss", "Search in radius " + str(radius))
            VOTableUtil.saveFromTable(respond, self.__save_path + "catalog.xml")
            catalog.addFile("ukidss", self.__save_path + "catalog.xml", "vo")

            result.addCatalog(catalog)

            index,loss = CoordinateParser.getNearPositionIndex(self.__coordinates.ra.degree, self.__coordinates.dec.degree,
                                                          respond["RAJ2000"], respond["DEJ2000"])

            ukidss = WaveLenghtCover.ukidss()
            result.addSummaryParams("ra", respond["RAJ2000"][index])
            result.addSummaryParams("dec", respond["DEJ2000"][index])
            result.addSummaryParams("distance", loss)

            magnitudes={"Y":-99,"J":-99,"H":-99,"K":-99,"Z":-99}

            try:
                data={"lambda": ukidss["h"], "ab": str(respond["Hmag"][index]), "err": str(respond["e_Hmag"][index])}
                result.addSummaryParams("mag_h", data)
                magnitudes["H"] = data["ab"] + "+/-" + data["err"]
            except KeyError:
                print("No mag_h found")

            try:
                data = {"lambda": ukidss["j"], "ab": str(respond["Jmag"][index]), "err": str(respond["e_Jmag"][index])}
                result.addSummaryParams("mag_j", data)
                magnitudes["J"] = data["ab"] + "+/-" + data["err"]
            except KeyError:
                print("No mag_j found")

            try:
                data = {"lambda": ukidss["j"], "ab": str(respond["Jmag1"][index]), "err": str(respond["e_Jmag1"][index])}
                result.addSummaryParams("mag_j1", data)
                magnitudes["J"] = data["ab"] + "+/-" + data["err"]
            except KeyError:
                print("No mag_j1 found")

            try:
                data = {"lambda": ukidss["j"], "ab": str(respond["Jmag2"][index]),"err": str(respond["e_Jmag2"][index])}
                result.addSummaryParams("mag_j2", data)
                magnitudes["J"] = data["ab"] + "+/-" + data["err"]
            except KeyError:
                print("No mag_j2 found")

            try:
                data = {"lambda": ukidss["j"], "ab": str(respond["pJmag"][index]),"err": str(respond["e_pJmag"][index])}
                result.addSummaryParams("pmag_j", data)
                magnitudes["J"] = data["ab"] + "+/-" + data["err"]
            except KeyError:
                print("No pmag_j found")

            try:
                data = {"lambda": ukidss["k"], "ab": str(respond["pKmag"][index]),"err": str(respond["e_pKmag"][index])}
                result.addSummaryParams("pmag_k", data)
                magnitudes["K"] = data["ab"] + "+/-" + data["err"]
            except KeyError:
                print("No pmag_k found")

            try:
                data = {"lambda": ukidss["k"], "ab": str(respond["Kmag"][index]),"err": str(respond["e_Kmag"][index])}
                result.addSummaryParams("mag_k", data)
                magnitudes["K"] = data["ab"] + "+/-" + data["err"]
            except KeyError:
                print("No mag_k found")

            try:
                data = {"lambda": ukidss["k"], "ab": str(respond["Kmag1"][index]), "err": str(respond["e_Kmag1"][index])}
                result.addSummaryParams("mag_k1", data)
                magnitudes["K"] = data["ab"] + "+/-" + data["err"]
            except KeyError:
                print("No mag_k1 found")
            try:
                data = {"lambda": ukidss["k"], "ab": str(respond["Kmag2"][index]),"err": str(respond["e_Kmag2"][index])}
                result.addSummaryParams("mag_k2", data)
                magnitudes["K"] = data["ab"] + "+/-" + data["err"]
            except KeyError:
                print("No mag_k2 found")

            try:
                data = {"lambda": ukidss["y"], "ab": str(respond["Ymag"][index]),"err": str(respond["e_Ymag"][index])}
                result.addSummaryParams("mag_y", data)
                magnitudes["Y"] = data["ab"] + "+/-" + data["err"]
            except KeyError:
                print("No mag_y found")
            try:
                data = {"lambda": ukidss["z"], "ab": str(respond["Zmag"][index]), "err": str(respond["e_Zmag"][index])}
                result.addSummaryParams("mag_z", data)
                magnitudes["Z"] = data["ab"] + "+/-" + data["err"]
            except KeyError:
                print("No mag_z found")

            images = Ukidss.get_image_list(self.__coordinates,waveband='all', frame_type='stack',
                                            image_width=radius * u.arcmin,
                                            database="UKIDSSDR10PLUS",programme_id=program_id)

            display_urls = [link.replace("getFImage", "getImage")for link in images]
            image_urls = [link.replace("getFImage", "getJImage") for link in images]

            image = ImageSource(result.getSummary()["id"], self.__catalog_provider)


            for index in range(len(images)):
                img= image_urls[index]
                band = str(img[img.find("band")+5:img.find("band")+6]).replace(" ","")
                mag=magnitudes[band]
                image.addCutout(image_urls[index],300, band, magnitude=mag,link=display_urls[index])

                local_path = self.__save_path + "ukidss_band_" + band + ".fits"
                image.addFile(name="band-" + band, url=images[index], download=True,
                              local_path=local_path, uncompress=False, thumbnail=True,external=False)

                #image.addFile("band-" + band,images[index] , "fits")

            result.addImage(image)

        return result