How to use the astroquery.utils.commons.suppress_vo_warnings function in astroquery

To help you get started, we’ve selected a few astroquery examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github astropy / astroquery / astroquery / vizier / core.py View on Github external
def parse_vizier_votable(data, verbose=False, invalid='warn',
                         get_catalog_names=False):
    """
    Given a votable as string, parse it into dict or tables
    """
    if not verbose:
        commons.suppress_vo_warnings()

    tf = BytesIO(data)

    if invalid == 'mask':
        vo_tree = votable.parse(tf, pedantic=False, invalid='mask')
    elif invalid == 'warn':
        try:
            vo_tree = votable.parse(tf, pedantic=False, invalid='exception')
        except Exception as ex:
            warnings.warn("VOTABLE parsing raised exception: {0}".format(ex))
            vo_tree = votable.parse(tf, pedantic=False, invalid='mask')
    elif invalid == 'exception':
        vo_tree = votable.parse(tf, pedantic=False, invalid='exception')
    else:
        raise ValueError("Invalid keyword for 'invalid'. "
                         "Must be exception, mask, or warn")
github astropy / astroquery / astroquery / ned / core.py View on Github external
Parameters
        ----------
        response : `requests.Response`
            The HTTP response object
        verbose : bool, optional
            Defaults to false. When true it will display warnings whenever
            the VOtable returned from the service doesn't conform to the
            standard.

        Returns
        -------
        table : `astropy.table.Table`

        """
        if not verbose:
            commons.suppress_vo_warnings()
        try:
            tf = six.BytesIO(response.content)
            first_table = votable.parse(tf, pedantic=False).get_first_table()
            table = first_table.to_table(use_names_over_ids=True)
            return table
        except Exception as ex:
            (is_valid, err_msg) = _check_ned_valid(response.content)
            if not is_valid:
                if err_msg:
                    raise RemoteServiceError(
                        "The remote service returned the following error "
                        "message.\nERROR: {err_msg}".format(err_msg=err_msg))
                else:
                    raise RemoteServiceError(
                        "The remote service returned an error, but with no "
                        "message.")
github astropy / astroquery / astroquery / cds / core.py View on Github external
Parameters
        ----------
        response : `~requests.Response`
            The HTTP response returned by the MOCServer.
        verbose : bool, optional
            False by default.

        Returns
        -------
        result : `astropy.table.Table` or `mocpy.MOC`
            By default an astropy table of the data-sets matching the query. If ``return_moc`` is set to True, it gives
            a MOC object corresponding to the union of the MOCs from all the matched data-sets.
        """
        if not verbose:
            commons.suppress_vo_warnings()

        result = response.json()

        if not self.return_moc:
            """
            The user will get `astropy.table.Table` object whose columns refer to the returned data-set meta-datas.
            """
            # cast the data-sets meta-datas values to their correct Python type.
            typed_result = []
            for d in result:
                typed_d = {k: self._cast_to_float(v) for k, v in d.items()}
                typed_result.append(typed_d)

            # looping over all the record's keys to find all the existing keys
            column_names_l = []
            for d in typed_result:
github astropy / astroquery / astroquery / nrao / core.py View on Github external
def _parse_votable_result(self, response, verbose=False):
        if not verbose:
            commons.suppress_vo_warnings()

        new_content = response.text

        # these are pretty bad hacks, but also needed...
        days_re = re.compile(r'unit="days"  datatype="double"')
        new_content = days_re.sub(r'unit="days"  datatype="char" '
                                  'arraysize="*"', new_content)
        degrees_re = re.compile(r'unit="degrees"  datatype="double"')
        new_content = degrees_re.sub(r'unit="degrees"  datatype="char" '
                                     'arraysize="*"', new_content)
        telconfig_re = re.compile(r'datatype="char"  name="Telescope:config"')
        new_content = telconfig_re.sub(r'datatype="unicodeChar" '
                                       'name="Telescope:config" '
                                       ' arraysize="*" ', new_content)

        datatype_mapping = {'integer': 'long'}
github astropy / astroquery / astroquery / oac / core.py View on Github external
def _parse_result(self, response, verbose=False):
        if not verbose:
            commons.suppress_vo_warnings()

        try:
            if response.status_code != 200:
                raise AttributeError

            if 'message' in response.text:
                raise KeyError

            raw_output = response.text
            output_response = self._format_output(raw_output)

        except AttributeError:
            print("ERROR: The web service returned error code: %s" %
                  response.status_code)
            return
github astropy / astroquery / astroquery / heasarc / core.py View on Github external
def _parse_result(self, response, verbose=False):
        # if verbose is False then suppress any VOTable related warnings
        if not verbose:
            commons.suppress_vo_warnings()

        if "BATCH_RETRIEVAL_MSG ERROR:" in response.text:
            raise InvalidQueryError("One or more inputs is not recognized by HEASARC. "
                             "Check that the object name is in GRB, SIMBAD+Sesame, or "
                             "NED format and that the mission name is as listed in "
                             "query_mission_list().")
        elif "Software error:" in response.text:
            raise InvalidQueryError("Unspecified error from HEASARC database. "
                                    "\nCheck error message: \n{!s}".format(response.text))

        try:
            data = BytesIO(response.content)
            table = Table.read(data, hdu=1)
            return table
        except ValueError:
            return self._fallback(response.content)