import yt.utilities.units as ytu

import base

class BenchYTUnits(base.BenchModule):
    facts = {
        'LOC': "N/A",
        'First Release': "N/A",
        "Most recent release": "N/A",
        "Implementation": "Subclass",
        "URL": "http://yt-project.org",
        "PyPI": "yt",
    }

    @property
    def name(self):
        return yta.__name__

    @property
    def make_syntax(self):
        return "constructor"

    def make(self, ndarray, units):
         return yta.YTArray(ndarray, input_units=units)

if __name__ == '__main__':
    import warnings
    warnings.simplefilter('ignore')
    np.seterr(all='ignore')
    base.bench(BenchYTUnits)
    facts = {
        'LOC': 270,
        'First release': '2012-07',
        'Most recent release': '2013-06',
        'Implementation': 'Unique!',
        'URL': 'https://github.com/sbyrnes321/numericalunits',
        'PyPI': 'numericalunits',
    }

    def __init__(self, np_obj):
        numericalunits.reset_units()
        base.BenchModule.__init__(self, np_obj)

    @property
    def name(self):
        return numericalunits.__name__

    @property
    def make_syntax(self):
        return "multiply"

    def make(self, ndarray, units):
        return ndarray * getattr(numericalunits, units)


if __name__ == '__main__':
    import warnings
    warnings.simplefilter('ignore')
    np.seterr(all='ignore')
    base.bench(BenchNumericalunits)
class BenchAstropy(base.BenchModule):
    facts = {
        'LOC': 3448,
        'First release': '2013-01',
        'Most recent release': '2013-05',
        'Implementation': 'Container',
        'URL': 'https://astropy.readthedocs.org/en/latest/units/index.html',
        'PyPI': 'astropy',
    }

    @property
    def name(self):
        return astropy.units.__name__

    @property
    def make_syntax(self):
        return "multiply"

    def make(self, ndarray, units):
        try:
            return getattr(astropy.units, units) * ndarray
        except:
            return getattr(astropy.units.imperial, units) * ndarray

if __name__ == '__main__':
    import warnings
    warnings.simplefilter('ignore')
    np.seterr(all='ignore')
    base.bench(BenchAstropy)
        "LOC": 2914,
        "First release": "2012-07",
        "Most recent release": "2014-02",
        "Implementation": "Container",
        "URL": "https://pint.readthedocs.org/en/latest/",
        "PyPI": "pint",
    }

    def __init__(self, np_obj):
        self.unitreg = pint.UnitRegistry()
        base.BenchModule.__init__(self, np_obj)

    @property
    def name(self):
        return pint.__name__

    @property
    def make_syntax(self):
        return "multiply"

    def make(self, ndarray, units):
        return ndarray * getattr(self.unitreg, units)


if __name__ == "__main__":
    import warnings

    warnings.simplefilter("ignore")
    np.seterr(all="ignore")
    base.bench(BenchPint)
Example #5
0

class BenchPhysicalQuantities(base.BenchModule):
    facts = {
        'LOC': 486,
        'First release': '2005-12',
        'Most recent release': '2012-10',
        'Implementation': 'Container',
        'URL': 'https://bitbucket.org/khinsen/scientificpython',
        'PyPI': False,
        'hg': 'https://bitbucket.org/khinsen/scientificpython',
    }

    @property
    def name(self):
        return "SP.PhysicalQuantities"

    @property
    def make_syntax(self):
        return "constructor"

    def make(self, ndarray, units):
        return pq.PhysicalQuantity(ndarray, units)


if __name__ == '__main__':
    import warnings
    warnings.simplefilter('ignore')
    np.seterr(all='ignore')
    base.bench(BenchPhysicalQuantities)

class BenchScimath(base.BenchModule):
    facts = {
        'LOC': 4488,
        'First release': '2009-03',
        'Most recent release': '2013-03',
        'Implementation': 'Subclass',
        'URL': 'http://docs.enthought.com/scimath/',
        'PyPI': "scimath",
    }

    @property
    def name(self):
        return "scimath"

    @property
    def make_syntax(self):
        return "constructor"

    def make(self, ndarray, units):
        d = scimath.unit_parser.parse_unit(units)
        return scimath.UnitArray(ndarray, units=d)


if __name__ == '__main__':
    import warnings
    warnings.simplefilter('ignore')
    np.seterr(all='ignore')
    base.bench(BenchScimath)

class BenchUnum(base.BenchModule):
    facts = {
        'LOC': 778,
        'First release': '2000',
        'Most recent release': '2010-06',
        'Implementation': 'Container',
        'URL': 'http://home.scarlet.be/be052320/Unum.html',
        'PyPI': 'unum',
    }

    @property
    def name(self):
        return unum.__name__

    @property
    def make_syntax(self):
        return "multiply"

    def make(self, ndarray, units):
        # NB! units must be on the left!
        return getattr(unum.units, units) * ndarray


if __name__ == '__main__':
    import warnings
    warnings.simplefilter('ignore')
    np.seterr(all='ignore')
    base.bench(BenchUnum)
import base


class BenchMagnitude(base.BenchModule):
    facts = {
        'LOC': 483,
        'First release': '2010-05',
        'Most recent release': '2010-05',
        'Implementation': 'Container',
        'URL': 'http://juanreyero.com/open/magnitude/index.html',
        'PyPI': 'magnitude',
    }

    @property
    def name(self):
        return magnitude.__name__

    @property
    def make_syntax(self):
        return "constructor"

    def make(self, ndarray, units):
        return magnitude.mg(ndarray, units)


if __name__ == '__main__':
    import warnings
    warnings.simplefilter('ignore')
    np.seterr(all='ignore')
    base.bench(BenchMagnitude)
Example #9
0
import base


class BenchDimensions(base.BenchModule):
    facts = {
        'LOC': 403,
        'First release': '2010-07',
        'Most recent release': '2010-07',
        'Implementation': 'Container',
        'URL': 'http://code.activestate.com/recipes/577333-numerical-type-with-units-dimensionspy/',
        'PyPI': False,
    }

    @property
    def name(self):
        return "dimensions.py"

    @property
    def make_syntax(self):
        return "constructor"

    def make(self, ndarray, units):
        return dimensions.Q(ndarray, units)


if __name__ == '__main__':
    import warnings
    warnings.simplefilter('ignore')
    np.seterr(all='ignore')
    base.bench(BenchDimensions)
        "LOC": 270,
        "First release": "2012-07",
        "Most recent release": "2013-06",
        "Implementation": "Unique!",
        "URL": "https://github.com/sbyrnes321/numericalunits",
        "PyPI": "numericalunits",
    }

    def __init__(self, np_obj):
        numericalunits.reset_units()
        base.BenchModule.__init__(self, np_obj)

    @property
    def name(self):
        return numericalunits.__name__

    @property
    def make_syntax(self):
        return "multiply"

    def make(self, ndarray, units):
        return ndarray * getattr(numericalunits, units)


if __name__ == "__main__":
    import warnings

    warnings.simplefilter("ignore")
    np.seterr(all="ignore")
    base.bench(BenchNumericalunits)
Example #11
0

class BenchIpythonPhysics(base.BenchModule):
    facts = {
        'LOC': 640,
        'First release': '2011-10',
        'Most recent release': '2013-03',
        'Implementation': 'Container',
        'URL': 'https://bitbucket.org/birkenfeld/ipython-physics',
        'PyPI': False,
        'hg': 'https://bitbucket.org/birkenfeld/ipython-physics',
    }

    @property
    def name(self):
        return "ipython-physics"

    @property
    def make_syntax(self):
        return "constructor"

    def make(self, ndarray, units):
        return physics.Q(ndarray, units)


if __name__ == '__main__':
    import warnings
    warnings.simplefilter('ignore')
    np.seterr(all='ignore')
    base.bench(BenchIpythonPhysics)
Example #12
0
    facts = {
        'LOC': 2914,
        'First release': '2012-07',
        'Most recent release': '2014-02',
        'Implementation': 'Container',
        'URL': 'https://pint.readthedocs.org/en/latest/',
        'PyPI': 'pint',
    }

    def __init__(self, np_obj):
        self.unitreg = pint.UnitRegistry()
        base.BenchModule.__init__(self, np_obj)

    @property
    def name(self):
        return pint.__name__

    @property
    def make_syntax(self):
        return "multiply"

    def make(self, ndarray, units):
        return ndarray * getattr(self.unitreg, units)


if __name__ == '__main__':
    import warnings
    warnings.simplefilter('ignore')
    np.seterr(all='ignore')
    base.bench(BenchPint)
        'LOC': 1900,
        'First release': '2008-08',
        'Most recent release': '2008-08',
        'Implementation': 'Container',
        'URL': 'http://www.inference.phy.cam.ac.uk/db410/',
        'PyPI': False,
    }

    def __init__(self, np_obj):
        dimpy.m = dimpy.meter
        dimpy.s = dimpy.second
        base.BenchModule.__init__(self, np_obj)

    @property
    def name(self):
        return "dimpy"

    @property
    def make_syntax(self):
        return "multiply"

    def make(self, ndarray, units):
        return getattr(dimpy, units) * ndarray


if __name__ == '__main__':
    import warnings
    warnings.simplefilter('ignore')
    np.seterr(all='ignore')
    base.bench(BenchDimpy)
        "First release": "2008-08",
        "Most recent release": "2008-08",
        "Implementation": "Container",
        "URL": "http://www.inference.phy.cam.ac.uk/db410/",
        "PyPI": False,
    }

    def __init__(self, np_obj):
        dimpy.m = dimpy.meter
        dimpy.s = dimpy.second
        base.BenchModule.__init__(self, np_obj)

    @property
    def name(self):
        return "dimpy"

    @property
    def make_syntax(self):
        return "multiply"

    def make(self, ndarray, units):
        return getattr(dimpy, units) * ndarray


if __name__ == "__main__":
    import warnings

    warnings.simplefilter("ignore")
    np.seterr(all="ignore")
    base.bench(BenchDimpy)
import base


class BenchQuantities(base.BenchModule):
    facts = {
        'LOC': 7030,
        'First release': '2009-10',
        'Most recent release': '2011-09',
        'Implementation': 'Subclass',
        'URL': 'http://pythonhosted.org/quantities/',
        'PyPI': 'quantities',
    }

    @property
    def name(self):
        return pq.__name__

    @property
    def make_syntax(self):
        return "multiply"

    def make(self, ndarray, units):
        return ndarray * getattr(pq, units)


if __name__ == '__main__':
    import warnings
    warnings.simplefilter('ignore')
    np.seterr(all='ignore')
    base.bench(BenchQuantities)
Example #16
0
        'First release': '2008-05',
        'Most recent release': '2008-05',
        'Implementation': 'Subclass',
        'URL': 'http://sourceforge.net/p/piquant/code/HEAD/tree/trunk/',
        'PyPI': 'piquant',
    }

    def __init__(self, np_obj):
        piquant.m = piquant.meter
        piquant.mile = piquant.m
        piquant.s = piquant.second
        base.BenchModule.__init__(self, np_obj)

    @property
    def name(self):
        return piquant.__name__

    @property
    def make_syntax(self):
        return "multiply"

    def make(self, ndarray, units):
        return ndarray * getattr(piquant, units)


if __name__ == '__main__':
    import warnings
    warnings.simplefilter('ignore')
    np.seterr(all='ignore')
    base.bench(BenchPiquant)
class BenchAstropy(base.BenchModule):
    facts = {
        'LOC': 3448,
        'First release': '2013-01',
        'Most recent release': '2013-05',
        'Implementation': 'Container',
        'URL': 'https://astropy.readthedocs.org/en/latest/units/index.html',
        'PyPI': 'astropy',
    }

    @property
    def name(self):
        return astropy.units.__name__

    @property
    def make_syntax(self):
        return "multiply"

    def make(self, ndarray, units):
        try:
            return getattr(astropy.units, units) * ndarray
        except:
            return getattr(astropy.units.imperial, units) * ndarray


if __name__ == '__main__':
    import warnings
    warnings.simplefilter('ignore')
    np.seterr(all='ignore')
    base.bench(BenchAstropy)