<commit_before># Licensed under a 3-clause BSD style license - see LICENSE.rst
from __future__ import print_function

import re
import os
import warnings
import functools
import keyring

import numpy as np
import astropy.units as u
import astropy.io.votable as votable
from astropy import coordinates
import six
from astropy.table import Table
from astropy import log
from bs4 import BeautifulSoup

from ..query import QueryWithLogin
from ..utils import commons, async_to_sync, prepend_docstr_nosections
from ..exceptions import TableParseError, LoginError

from . import conf

__all__ = ["Nrao", "NraoClass"]


def _validate_params(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        telescope = kwargs.get('telescope', 'all')
        telescope_config = kwargs.get('telescope_config', 'all')
        obs_band = kwargs.get('obs_band', 'all')
        sub_array = kwargs.get('sub_array', 'all')
        if not isinstance(telescope, (list, tuple)):
            telescope = [telescope]
        for tel in telescope:
            if tel not in Nrao.telescope_code:
                raise ValueError("'telescope must be one of {!s}"
                                 .format(Nrao.telescope_code.keys()))
        if not isinstance(telescope_config, (list, tuple)):
            telescope_config = [telescope_config]
        for tconf in telescope_config:
            if tconf.upper() not in Nrao.telescope_config:
                raise ValueError("'telescope_config' must be one of {!s}"
                                 .format(Nrao.telescope_config))
        if isinstance(obs_band, (list, tuple)):
            for ob in obs_band:
                if ob not in Nrao.obs_bands:
                    raise ValueError("'obs_band' must be one of {!s}"
                                     .format(Nrao.obs_bands))
        elif obs_band not in Nrao.obs_bands:
            raise ValueError("'obs_band' must be one of {!s}"
                             .format(Nrao.obs_bands))
        if sub_array not in Nrao.subarrays and sub_array != 'all':
            raise ValueError("'sub_array' must be one of {!s}"
                             .format(Nrao.subarrays))
        return func(*args, **kwargs)
    return wrapper


@async_to_sync
class NraoClass(QueryWithLogin):

    DATA_URL = conf.server
    TIMEOUT = conf.timeout
    USERNAME = conf.username

    # dicts and lists for data archive queries
    telescope_code = {
        "all": "ALL",
        "jansky_vla": "EVLA",
        "historical_vla": "VLA",
        "vlba": "VLBA",
        "gbt": "GBT",
    }

    telescope_config = ['ALL', 'A', 'AB', 'BnA', 'B', 'BC', 'CnB', 'C',
                        'CD', 'DnC', 'D', 'DA']

    obs_bands = ['ALL', 'all', '4', 'P', 'L', 'S', 'C', 'X', 'U', 'K', 'Ka', 'Q', 'W']

    subarrays = ['ALL', 1, 2, 3, 4, 5]

    @_validate_params
    def _args_to_payload(self, **kwargs):
        """
        Queries the NRAO data archive and fetches table of observation
        summaries.

        Parameters
        ----------
        coordinates : str or `astropy.coordinates` object
            The target around which to search. It may be specified as a
            string in which case it is resolved using online services or as
            the appropriate `astropy.coordinates` object. ICRS coordinates
            may also be entered as a string.
        radius : str or `~astropy.units.Quantity` object, optional
            The string must be parsable by `astropy.coordinates.Angle`. The
            appropriate `~astropy.units.Quantity` object may also be
            used. Defaults to 1 arcminute.
        equinox : str, optional
            One of 'J2000' or 'B1950'. Defaults to 'J2000'.
        telescope : str, optional<commit_msg>fix telescope config checking: really only want to compare uppercase versions<commit_after># Licensed under a 3-clause BSD style license - see LICENSE.rst
from __future__ import print_function

import re
import os
import warnings
import functools
import keyring

import numpy as np
import astropy.units as u
import astropy.io.votable as votable
from astropy import coordinates
import six
from astropy.table import Table
from astropy import log
from bs4 import BeautifulSoup

from ..query import QueryWithLogin
from ..utils import commons, async_to_sync, prepend_docstr_nosections
from ..exceptions import TableParseError, LoginError

from . import conf

__all__ = ["Nrao", "NraoClass"]


def _validate_params(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        telescope = kwargs.get('telescope', 'all')
        telescope_config = kwargs.get('telescope_config', 'all')
        obs_band = kwargs.get('obs_band', 'all')
        sub_array = kwargs.get('sub_array', 'all')
        if not isinstance(telescope, (list, tuple)):
            telescope = [telescope]
        for tel in telescope:
            if tel not in Nrao.telescope_code:
                raise ValueError("'telescope must be one of {!s}"
                                 .format(Nrao.telescope_code.keys()))
        if not isinstance(telescope_config, (list, tuple)):
            telescope_config = [telescope_config]
        for tconf in telescope_config:
            if tconf.upper() not in Nrao.telescope_config:
                raise ValueError("'telescope_config' must be one of {!s}"
                                 .format(Nrao.telescope_config))
        if isinstance(obs_band, (list, tuple)):
            for ob in obs_band:
                if ob not in Nrao.obs_bands:
                    raise ValueError("'obs_band' must be one of {!s}"
                                     .format(Nrao.obs_bands))
        elif obs_band not in Nrao.obs_bands:
            raise ValueError("'obs_band' must be one of {!s}"
                             .format(Nrao.obs_bands))
        if sub_array not in Nrao.subarrays and sub_array != 'all':
            raise ValueError("'sub_array' must be one of {!s}"
                             .format(Nrao.subarrays))
        return func(*args, **kwargs)
    return wrapper


@async_to_sync
class NraoClass(QueryWithLogin):

    DATA_URL = conf.server
    TIMEOUT = conf.timeout
    USERNAME = conf.username

    # dicts and lists for data archive queries
    telescope_code = {
        "all": "ALL",
        "jansky_vla": "EVLA",
        "historical_vla": "VLA",
        "vlba": "VLBA",
        "gbt": "GBT",
    }

    telescope_config = ['ALL', 'A', 'AB', 'BnA', 'B', 'BC', 'CnB', 'C',
                        'CD', 'DnC', 'D', 'DA']
    # we only ever use uppercase versions
    telescope_config = [x.upper() for x in telescope_config]

    obs_bands = ['ALL', 'all', '4', 'P', 'L', 'S', 'C', 'X', 'U', 'K', 'Ka', 'Q', 'W']

    subarrays = ['ALL', 1, 2, 3, 4, 5]

    @_validate_params
    def _args_to_payload(self, **kwargs):
        """
        Queries the NRAO data archive and fetches table of observation
        summaries.

        Parameters
        ----------
        coordinates : str or `astropy.coordinates` object
            The target around which to search. It may be specified as a
            string in which case it is resolved using online services or as
            the appropriate `astropy.coordinates` object. ICRS coordinates
            may also be entered as a string.
        radius : str or `~astropy.units.Quantity` object, optional
            The string must be parsable by `astropy.coordinates.Angle`. The
            appropriate `~astropy.units.Quantity` object may also be
            used. Defaults to 1 arcminute.
        equinox : str, optional
            One of 'J2000' or 'B1950'. Defaults to 'J2000'.
        telescope : str, optional
{'fraction_non_alphanumeric': 0.10412034009156311, 'fraction_numerical': 0.005493786788750818, 'mean_word_length': 2.253617021276596, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4787269', 'n_tokens_mistral': 2332, 'n_tokens_neox': 2276, 'n_words': 729}