diff --git a/psrqpy/__init__.py b/psrqpy/__init__.py index 92b81572..6814c776 100644 --- a/psrqpy/__init__.py +++ b/psrqpy/__init__.py @@ -2,7 +2,7 @@ """ A Python tool for interacting with the ATNF pulsar catalogue """ -__version__ = "0.3.6" +__version__ = "0.4.1" from .search import QueryATNF from .pulsar import Pulsar, Pulsars diff --git a/psrqpy/config.py b/psrqpy/config.py index dd210bc3..0e818c42 100644 --- a/psrqpy/config.py +++ b/psrqpy/config.py @@ -57,7 +57,7 @@ } # just return the parameter names -PSR_GENERAL_PARS = PSR_GENERAL.keys() +PSR_GENERAL_PARS = list(PSR_GENERAL.keys()) # timing solution and profile parameters PSR_TIMING = {'P0': {'ref': True, 'err': True, 'units': 's', 'format': 'f8'}, # Barycentric period of the pulsar (s) @@ -79,7 +79,7 @@ 'S2000': {'ref': True, 'err': True, 'units': 'mJy', 'format': 'f8'} # Mean flux density at 2000 MHz (mJy) } -PSR_TIMING_PARS = PSR_TIMING.keys() +PSR_TIMING_PARS = list(PSR_TIMING.keys()) # binary system parameters PSR_BINARY = {'BINARY': {'ref': True, 'err': False, 'units': None, 'format': 'S5'}, # Binary model (usually one of several recognised by the pulsar timing programs TEMPO or TEMPO2). Modified versions of standard models are often used - refer to the source paper for details of the binary model used. @@ -96,7 +96,7 @@ 'BINCOMP': {'ref': True, 'err': False, 'units': None, 'format': 'S4'} # Companion type } -PSR_BINARY_PARS = PSR_BINARY.keys() +PSR_BINARY_PARS = list(PSR_BINARY.keys()) # derived parameters PSR_DERIVED = {'R_LUM': {'ref': False, 'err': False, 'units': 'mJy kpc^2', 'format': 'f8'}, # Radio luminosity at 400 MHz (mJy kpc2) @@ -113,7 +113,7 @@ 'B_LC': {'ref': False, 'err': False, 'units': 'G', 'format': 'f8'} # Magnetic field at light cylinder (gauss) } -PSR_DERIVED_PARS = PSR_DERIVED.keys() +PSR_DERIVED_PARS = list(PSR_DERIVED.keys()) # a list of all allowed parameters for querying PSR_ALL = dict(itertools.chain(PSR_GENERAL.items(), PSR_TIMING.items(), PSR_BINARY.items(), PSR_DERIVED.items())) diff --git a/psrqpy/pulsar.py b/psrqpy/pulsar.py index 80cbf8c5..b4291db7 100644 --- a/psrqpy/pulsar.py +++ b/psrqpy/pulsar.py @@ -6,7 +6,8 @@ from __future__ import print_function, division import warnings -import six + +from six import string_types, iteritems from .config import PSR_ALL_PARS, PSR_ALL from .utils import get_version @@ -28,7 +29,7 @@ def __init__(self, psrname, version=None, **kwargs): self._version = version if not version else get_version() self._ephemeris = None - for key, value in six.iteritems(kwargs): + for key, value in iteritems(kwargs): setattr(self, key, value) def __repr__(self): @@ -51,7 +52,7 @@ def items(self): """ Return a list of the class attribute values """ - return [value for key, value in six.iteritems(self.__dict__) if key in PSR_ALL_PARS+[par+'_ERR' for par in PSR_ALL_PARS]] + return [value for key, value in iteritems(self.__dict__) if key in PSR_ALL_PARS+[par+'_ERR' for par in PSR_ALL_PARS]] @property def name(self): @@ -185,7 +186,7 @@ def set_ephemeris(self, ephem=None): if not self._ephemeris and ephem: self._ephemeris = ephem # set ephemeris if it doesn't already exist - assert isinstance(self._ephemeris, basestring), 'Ephemeris must be a string' + assert isinstance(self._ephemeris, string_types), 'Ephemeris must be a string' # get ephemeris values ephemvals = [ev.split() for ev in ephem.split('\n') if len(ev.split()) > 1] @@ -336,7 +337,7 @@ def remove_pulsar(self, psrname): psrname (str): a string with the name of a pulsar """ - assert isinstance(psrname, basestring), 'psrname is not a string' + assert isinstance(psrname, string_types), 'psrname is not a string' if psrname in self._psrs: del self._psrs[psrname] @@ -348,7 +349,7 @@ def pop(self, psrname): Args: psrname (str): a string with the name of a pulsar """ - assert isinstance(psrname, basestring), 'psrname is not a string' + assert isinstance(psrname, string_types), 'psrname is not a string' if psrname in self._psrs: return self._psrs.pop(psrname) diff --git a/psrqpy/search.py b/psrqpy/search.py index a4393f73..96d36bd8 100644 --- a/psrqpy/search.py +++ b/psrqpy/search.py @@ -9,9 +9,11 @@ import warnings from collections import OrderedDict import re -import cPickle as pickle import six +from six.moves import cPickle as pickle +from six import string_types + import numpy as np import requests from bs4 import BeautifulSoup @@ -107,12 +109,12 @@ def __init__(self, params=None, condition=None, psrtype=None, assoc=None, bincom raise Exception("No parameters in list") for p in params: - if not isinstance(p, basestring): + if not isinstance(p, string_types): raise Exception("Non-string value '{}' found in params list".format(p)) self._query_params = [p.upper() for p in params] # make sure parameter names are all upper case else: - if isinstance(params, basestring): + if isinstance(params, string_types): self._query_params = [params.upper()] # make sure parameter is all upper case else: if self._psrs and self._get_ephemeris: # if getting ephemerides then param can be None @@ -211,7 +213,7 @@ def generate_query(self, version='', params=None, condition='', sortorder='asc', query_dict['version'] = self._atnf_version if params: - if isinstance(params, basestring): + if isinstance(params, string_types): params = [params] # convert to list else: if not isinstance(params, list): @@ -236,7 +238,7 @@ def generate_query(self, version='', params=None, condition='', sortorder='asc', query_dict['sortattr'] = self._sort_attr if psrnames: - if isinstance(psrnames, basestring): + if isinstance(psrnames, string_types): self._psrs = [psrnames] # convert to list else: if not isinstance(psrnames, list): @@ -245,7 +247,7 @@ def generate_query(self, version='', params=None, condition='', sortorder='asc', qpulsars = '' # pulsar name query string if self._psrs is not None: - if isinstance(self._psrs, basestring): + if isinstance(self._psrs, string_types): self._psrs = [self._psrs] # if a string pulsar name then convert to list for psr in self._psrs: @@ -555,7 +557,7 @@ def parse_conditions(self, condition, psrtype=None, assoc=None, bincomp=None, ex if not condition: conditionparse = '' else: - if not isinstance(condition, basestring): + if not isinstance(condition, string_types): warnings.warn('Condition "{}" must be a string. No condition being set'.format(condition), UserWarning) return '' @@ -602,11 +604,11 @@ def parse_conditions(self, condition, psrtype=None, assoc=None, bincomp=None, ex raise Exception("No pulsar types in list") for p in psrtype: - if not isinstance(p, basestring): + if not isinstance(p, string_types): raise Exception("Non-string value '{}' found in pulsar type list".format(p)) self._query_psr_types = psrtype else: - if isinstance(psrtype, basestring): + if isinstance(psrtype, string_types): self._query_psr_types = [psrtype] else: raise Exception("'psrtype' must be a list or string") @@ -628,11 +630,11 @@ def parse_conditions(self, condition, psrtype=None, assoc=None, bincomp=None, ex raise Exception("No pulsar types in list") for p in assoc: - if not isinstance(p, basestring): + if not isinstance(p, string_types): raise Exception("Non-string value '{}' found in associations list".format(p)) self._query_assocs = assoc else: - if isinstance(assoc, basestring): + if isinstance(assoc, string_types): self._query_assocs = [assoc] else: raise Exception("'assoc' must be a list or string") @@ -654,11 +656,11 @@ def parse_conditions(self, condition, psrtype=None, assoc=None, bincomp=None, ex raise Exception("No pulsar types in list") for p in bincomp: - if not isinstance(p, basestring): + if not isinstance(p, string_types): raise Exception("Non-string value '{}' found in binary companions list".format(p)) self._query_bincomps = bincomp else: - if isinstance(bincomp, basestring): + if isinstance(bincomp, string_types): self._query_bincomps = [bincomp] else: raise Exception("'bincomp' must be a list or string") @@ -772,7 +774,7 @@ def ppdot(self, intrinsicpdot=False, excludeGCs=False, showtypes=[], showGCs=Fal if intrinsicpdot and 'P1_I' not in self._query_params: self._query_params.append('P1_I') - if isinstance(showtypes, basestring): + if isinstance(showtypes, string_types): nshowtypes = [showtypes] else: nshowtypes = showtypes diff --git a/psrqpy/utils.py b/psrqpy/utils.py index 158358d0..7a0e8f15 100644 --- a/psrqpy/utils.py +++ b/psrqpy/utils.py @@ -9,9 +9,10 @@ import datetime import numpy as np import requests - from bs4 import BeautifulSoup +from six import string_types + from .config import ATNF_BASE_URL, ATNF_VERSION, ADS_URL # problematic references that are hard to parse @@ -117,7 +118,7 @@ def get_references(useads=False): 'Sov. Astron. Lett.': 'SvAL', 'ATel.': 'ATel'} - if isinstance(rdf, basestring): # only run on string values + if isinstance(rdf, string_types): # only run on string values rdfs = re.sub(r'\s+', ' ', rdf) # make sure only single spaces are present for js in journalsubs: if js in rdfs: @@ -160,7 +161,7 @@ def get_references(useads=False): if '&' in sepauthors[-1] or 'and' in sepauthors[-1]: # split any authors that are seperated by an ampersand lastauthors = [a.strip() for a in re.split(r'& | and ', sepauthors.pop(-1))] sepauthors = sepauthors + lastauthors - for i in xrange(len(sepauthors)-2): + for i in range(len(sepauthors)-2): sepauthors[i] += '.' # re-add final full stops where needed sepauthors[-1] += '.' else: