<commit_before># coding: utf-8

from __future__ import division, print_function

__author__ = "adrn <<EMAIL>>"

# Standard library
from collections import OrderedDict

# Third-party
import numpy as np
from astropy.constants import G
import astropy.units as u
from astropy.utils import isiterable

# Project
from ..integrate import *
from ..util import inherit_docs, ImmutableDict, atleast_2d
from ..units import UnitSystem
from ..dynamics import CartesianOrbit, CartesianPhaseSpacePosition

__all__ = ["PotentialBase", "CompositePotential"]

class PotentialBase(object):
    """
    A baseclass for defining gravitational potentials.

    Subclasses must define a function that evaluates the value of the
    potential at a given position and time. For integration, the
    subclasses should also define a gradient function. Optionally, they
    may also define functions to compute the density and hessian.
    """
    def __init__(self, parameters, units=None):
        # make sure the units specified are a UnitSystem instance
        if units is not None and not isinstance(units, UnitSystem):
            units = UnitSystem(*units)
        self.units = units

        # in case the user specified an ordered dict
        self.parameters = OrderedDict()
        for k,v in parameters.items():
            if hasattr(v, 'unit'):
                self.parameters[k] = v.decompose(self.units)
            else:
                self.parameters[k] = v*u.one

        self.G = G.decompose(self.units).value

    def _value(self):
        raise NotImplementedError()

    def value(self, q, t=0.):
        """
        Compute the value of the potential at the given position(s).
<commit_msg>if no units, use dimensionless unit system<commit_after># coding: utf-8

from __future__ import division, print_function

__author__ = "adrn <<EMAIL>>"

# Standard library
from collections import OrderedDict

# Third-party
import numpy as np
from astropy.constants import G
import astropy.units as u
from astropy.utils import isiterable

# Project
from ..integrate import *
from ..util import inherit_docs, ImmutableDict, atleast_2d
from ..units import UnitSystem, DimensionlessUnitSystem
from ..dynamics import CartesianOrbit, CartesianPhaseSpacePosition

__all__ = ["PotentialBase", "CompositePotential"]

class PotentialBase(object):
    """
    A baseclass for defining gravitational potentials.

    Subclasses must define a function that evaluates the value of the
    potential at a given position and time. For integration, the
    subclasses should also define a gradient function. Optionally, they
    may also define functions to compute the density and hessian.
    """
    def __init__(self, parameters, units=None):
        # make sure the units specified are a UnitSystem instance
        if units is not None and not isinstance(units, UnitSystem):
            units = UnitSystem(*units)

        elif units is None:
            units = DimensionlessUnitSystem()

        self.units = units

        # in case the user specified an ordered dict
        self.parameters = OrderedDict()
        for k,v in parameters.items():
            if hasattr(v, 'unit'):
                self.parameters[k] = v.decompose(self.units)
            else:
                self.parameters[k] = v*u.one

        try:
            self.G = G.decompose(self.units).value
        except u.UnitConversionError:
            self.G = 1. # TODO: this is BAD and could lead to user confusion

    def _value(self):
        raise NotImplementedError()

    def value(self, q, t=0.):
        """
        Compute the value of the potential at the given position(s).

{'fraction_non_alphanumeric': 0.0748074807480748, 'fraction_numerical': 0.0019251925192519251, 'mean_word_length': 2.914962325080732, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3356828', 'n_tokens_mistral': 990, 'n_tokens_neox': 957, 'n_words': 372}