<commit_before># pulsar.py

# Class containing pulsar data from timing package [tempo2/PINT].

from __future__ import absolute_import, division, print_function, unicode_literals

import json
import logging
import os

import astropy.units as u
import numpy as np
from ephem import Ecliptic, Equatorial

import enterprise
from enterprise.signals import utils

try:
    import cPickle as pickle
except:
    import pickle

try:
    import libstempo as t2
except ImportError:
    print("Ooh, no libstempo?")
    t2 = None

try:
    import pint
    import pint.toa as toa
    import pint.models.model_builder as mb
    from pint.models import TimingModel
    from pint.residuals import Residuals as resids
except ImportError:
    print("Cannot import PINT? Meh...")
    pint = None


if pint is None and t2 is None:
    err_msg = "Must have either PINT or libstempo timing package installed"
    raise ImportError(err_msg)

logging.basicConfig(format="%(levelname)s: %(name)s: %(message)s", level=logging.INFO)
logger = logging.getLogger(__name__)


def get_maxobs(timfile):
    """Utility function to return number of lines in tim file.

    :param timfile:
        Full path to tim-file. For tim-files that use INCLUDEs this
        should be the base tim file.

    :returns: Number of lines in tim-file
    """

    maxobs = 0
    with open(timfile) as tfile:
        flines = tfile.readlines()
        lines = [ln for ln in flines if not ln.startswith("C")]
        if any(map(lambda x: "INCLUDE" in x, lines)):
            for line in filter(lambda x: "INCLUDE" in x, lines):
                maxobs += get_maxobs(line.split()[-1])
        else:
            maxobs = sum(1 for line in lines if line.rstrip("\n"))
    return maxobs


class BasePulsar(object):
    """Abstract Base Class for Pulsar objects."""

    def _get_pdist(self):
        dfile = enterprise.__path__[0] + "/datafiles/pulsar_distances.json"
        with open(dfile, "r") as fl:
            pdict = json.load(fl)

        if self.name[0] not in ["J", "B"]:
            if "J" + self.name in pdict:
                pdist = tuple(pdict.get("J" + self.name))
            elif "B" + self.name in pdict:
                pdist = tuple(pdict.get("B" + self.name))
        else:
            pdist = tuple(pdict.get(self.name, (1.0, 0.2)))

        if pdist == (1.0, 0.2):
            msg = "WARNING: Could not find pulsar distance for "
            msg += "PSR {0}.".format(self.name)
            msg += " Setting value to 1 with 20% uncertainty."
            logger.warning(msg)
        return pdist<commit_msg>minor change to how pulsar distance is set<commit_after># pulsar.py

# Class containing pulsar data from timing package [tempo2/PINT].

from __future__ import absolute_import, division, print_function, unicode_literals

import json
import logging
import os

import astropy.units as u
import numpy as np
from ephem import Ecliptic, Equatorial

import enterprise
from enterprise.signals import utils

try:
    import cPickle as pickle
except:
    import pickle

try:
    import libstempo as t2
except ImportError:
    print("Ooh, no libstempo?")
    t2 = None

try:
    import pint
    import pint.toa as toa
    import pint.models.model_builder as mb
    from pint.models import TimingModel
    from pint.residuals import Residuals as resids
except ImportError:
    print("Cannot import PINT? Meh...")
    pint = None


if pint is None and t2 is None:
    err_msg = "Must have either PINT or libstempo timing package installed"
    raise ImportError(err_msg)

logging.basicConfig(format="%(levelname)s: %(name)s: %(message)s", level=logging.INFO)
logger = logging.getLogger(__name__)


def get_maxobs(timfile):
    """Utility function to return number of lines in tim file.

    :param timfile:
        Full path to tim-file. For tim-files that use INCLUDEs this
        should be the base tim file.

    :returns: Number of lines in tim-file
    """

    maxobs = 0
    with open(timfile) as tfile:
        flines = tfile.readlines()
        lines = [ln for ln in flines if not ln.startswith("C")]
        if any(map(lambda x: "INCLUDE" in x, lines)):
            for line in filter(lambda x: "INCLUDE" in x, lines):
                maxobs += get_maxobs(line.split()[-1])
        else:
            maxobs = sum(1 for line in lines if line.rstrip("\n"))
    return maxobs


class BasePulsar(object):
    """Abstract Base Class for Pulsar objects."""

    def _get_pdist(self):
        dfile = enterprise.__path__[0] + "/datafiles/pulsar_distances.json"
        with open(dfile, "r") as fl:
            pdict = json.load(fl)

        if self.name[0] not in ["J", "B"]:
            if "J" + self.name in pdict:
                pdist = tuple(pdict.get("J" + self.name, (1.0, 0.2)))
            else:
                pdist = tuple(pdict.get("B" + self.name, (1.0, 0.2)))
        else:
            pdist = tuple(pdict.get(self.name, (1.0, 0.2)))

        if pdist == (1.0, 0.2):
            msg = "WARNING: Could not find pulsar distance for "
            msg += "PSR {0}.".format(self.name)
            msg += " Setting value to 1 with 20% uncertainty."
            logger.warning(msg)
        return pdist
{'fraction_non_alphanumeric': 0.10359489756474681, 'fraction_numerical': 0.009663703131039814, 'mean_word_length': 2.5348360655737703, 'pattern_counts': {'":': 0, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6302913', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1624, 'n_words': 550}