Giter VIP home page Giter VIP logo

physicalquantities's People

Contributors

juhasch avatar juhaschrb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

physicalquantities's Issues

Comparisons

Comparisons like <, >, and == are not implemented.

Python 3 support

Does not work with Python3 and Partly Python2

  • 1/s displayed as s/1 because of wrong division function ?

How to define a new unity.

Hello,
Your work is very useful to me. Thank you.

After reading the docs I continue to don't understand how to define more units.

Please help me to define new physical quantities.
For instance 1 L (0.001 m^3):

  • if I change more_units.py with
    ...
    #Volume units
    add_composite_unit('L', '0.001*m**3','Litre')
    ...
    when in python and I call it with
    from PhysicalQuantities import more_units

it gives an error:
36 add_composite_unit('L', '0.001*m**3','Litre')
NameError: name 'Litre' is not defined

I understand it, but where to define Litre?

  • if I instead change imperial.py, with:
    ...
    #Volume units
    add_composite_unit('L', 0.001, 'm**3', verbosename='Litre',
    url='https://en.wikipedia.org/wiki/Litre')
    ...
    Works well until the next update. However, it doesn't seem to be the right way.

thank you very much in advance
Filipe

Tab completion: show .unit and .value

Now:

In [55]: a = 1m

In [56]: a.
a.Gm        a.any_to    a.convert   a.km        a.pm        a.to
a.Mm        a.autoscale a.copy      a.m         a.sin       a.um
a.Tm        a.base      a.cos       a.mm        a.sqrt
a.am        a.cm        a.fm        a.nm        a.tan

Conversion between incompatible units should raise UnitError, not AttributeError

When trying to convert between incompatible units one would expect UnitError to be raised, instead e.g. PhysicalQuantity(1, 'm').to('kg') raises AttributeError("PhysicalUnit instance has no attribute 'unit'"). This is caused by line 453 in Unit.py, introduced by b1f54a1.

>>> PhysicalQuantity(1, 'm').to('kg')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/PhysicalQuantities/Quantity.py", line 565, in to
    value = convertvalue(self.value, self.unit, unit)
  File "/usr/lib/python2.7/site-packages/PhysicalQuantities/Unit.py", line 58, in convertvalue
    (factor, offset) = src_unit.conversion_tuple_to(target_unit)
  File "/usr/lib/python2.7/site-packages/PhysicalQuantities/Unit.py", line 453, in conversion_tuple_to
    raise UnitError('Incompatible unit for conversion %s' % other.unit)
AttributeError: PhysicalUnit instance has no attribute 'unit'

@juhasch, how about just going back to raise UnitError('Incompatible units') as in e10ab54?

After update of all installed python packages (April 14) %load_ext PhysicalQuantities.ipython give an error

!uname -a
Darwin Mac132 18.7.0 Darwin Kernel Version 18.7.0: Mon Feb 10 21:08:45 PST 2020; root:xnu-4903.278.28~1/RELEASE_X86_64 x86_64
pip_freeze.txt

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-726c0454b5bc> in <module>
----> 1 get_ipython().run_line_magic('load_ext', 'PhysicalQuantities.ipython')
      2 import PhysicalQuantities.constants as q
      3 import PhysicalQuantities.imperial
      4 from IPython.display import display, Math, Latex
      5 from sympy import *

/Applications/SageMath/local/lib/python3.7/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
   2315                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2316             with self.builtin_trap:
-> 2317                 result = fn(*args, **kwargs)
   2318             return result
   2319 

<decorator-gen-64> in load_ext(self, module_str)

/Applications/SageMath/local/lib/python3.7/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    185     # but it's overkill for just that one bit of state.
    186     def magic_deco(arg):
--> 187         call = lambda f, *a, **k: f(*a, **k)
    188 
    189         if callable(arg):

/Applications/SageMath/local/lib/python3.7/site-packages/IPython/core/magics/extension.py in load_ext(self, module_str)
     31         if not module_str:
     32             raise UsageError('Missing module name.')
---> 33         res = self.shell.extension_manager.load_extension(module_str)
     34 
     35         if res == 'already loaded':

/Applications/SageMath/local/lib/python3.7/site-packages/IPython/core/extensions.py in load_extension(self, module_str)
     85                               dir=compress_user(self.ipython_extension_dir)))
     86             mod = sys.modules[module_str]
---> 87             if self._call_load_ipython_extension(mod):
     88                 self.loaded.add(module_str)
     89             else:

/Applications/SageMath/local/lib/python3.7/site-packages/IPython/core/extensions.py in _call_load_ipython_extension(self, mod)
    132     def _call_load_ipython_extension(self, mod):
    133         if hasattr(mod, 'load_ipython_extension'):
--> 134             mod.load_ipython_extension(self.shell)
    135             return True
    136 

/Applications/SageMath/local/lib/python3.7/site-packages/PhysicalQuantities/ipython.py in load_ipython_extension(ip)
     62     global __transformer, within_comment
     63     within_comment = False
---> 64     ip.input_transformer_manager.logical_line_transforms.insert(0, __transformer)
     65     ip.user_ns['pq'] = PhysicalQuantities.q
     66 

AttributeError: 'TransformerManager' object has no attribute 'logical_line_transforms'

units with powers

a = pq.Q(1, 's**3*m**2')
leads to:
TypeError: unsupported operand type(s) for +: 'dict' and 'dict'

.to() function incorrect

a.to('1/m)' -> m/1 is displayed, although Unit should be the same

a = 1 / 1 m
b = a.to('1/m')
print a,b
print a.unit.names, b.unit.names
> 1.0 1/m 1.0 m/1
> {'m': -1} {'1': -1, 'm': 1}

Comparison not acting as expected

I don't think comparison is working.

For example, if I run the following code:

def test_comparison():
    a = pq.Q(1e-3, 'm')
    b = pq.Q(1, 'mm')
    return(a == b)
test_comparison()

I get

     False

I am using pq.version 0.2 in iPython 2.2.0.

I can get what I want by doing:

 return(a.base.value == b.base.value)

Autoscale fails on negative numbers

With PhysicalQuantities-0.9.1 in IPython, I get:

>>> (-0.00032C).autoscale
/home/foo/.local/lib/python3.6/site-packages/PhysicalQuantities/quantity.py:580: RuntimeWarning: invalid value encountered in log10
  n = np.log10(b.value)
-0.00032 C

pip install fails with DistributionNotFound

The package appears to be hosted on PyPi here:

https://pypi.python.org/pypi/physicalquantities/0.6.

However, attempting to install with pip fails:

pip install --user PhysicalQuantities

Full log:

------------------------------------------------------------
/usr/bin/pip run on Wed Jan 27 22:18:28 2016
Downloading/unpacking PhysicalQuantities
  Getting page https://pypi.python.org/simple/PhysicalQuantities/
  URLs to search for versions for PhysicalQuantities:
  * https://pypi.python.org/simple/PhysicalQuantities/
  Analyzing links from page https://pypi.python.org/simple/physicalquantities/
  Could not find any downloads that satisfy the requirement PhysicalQuantities
Cleaning up...
No distributions at all found for PhysicalQuantities
Exception information:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 290, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1178, in prepare_files
    url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 277, in find_requirement
    raise DistributionNotFound('No distributions at all found for %s' % req)
DistributionNotFound: No distributions at all found for PhysicalQuantities

Conversion from string

Thanks for the cool library!
It would be nice to have a function that can parse a PhysicalQuantity from a string.

For usage outside ipython, it would be nice if this was available under a short name, such as the already existing q().

A quick mock-up which just splits at whitespace:

from PhysicalQuantities import PhysicalQuantity, _Quantity, q
_Quantity.__call__ = lambda s, x: PhysicalQuantity(float(x.split()[0]), x.split()[1])
print(q("1 m") / q("1 s"))  # gives 1.0 m/s

It would also be useful for parsing string data loaded from files or input by user.

Doesn't work on Python 3.9.1

Hi! I am using Python 3.9.1 with Spyder 4.2.1 and command %load_ext PhysicalQuantities.ipython in Spyder console gives the following problem
spyder_problem
What should/can I do to solve it? (other tryings with different commands gave me no positive result)
Thanks!

TypeError in ^3

xQ = np.array([1, 3, 0]) * 1 m
xq = np.array([3, 2, 0]) * 1 m
ra=np.linalg.norm(xQ-xq)
ra**3

TypeError: unsupported operand type(s) for *: 'int' and 'dict'

Bohr unit still using pi as a unit

The line below throws out an error because it's trying to use pi as a unit, and it is not using np.pi as you've changed others to.

 addunit('Bohr', '4*pi*eps0*hbar**2/me/e0**2', 'Bohr radius')

Error:

 NameError: name 'pi' is not defined

Also, it looks like hartree is the the same.

sqrt does not work

sqrt(1 m**2) returns TypeError: unorderable types: PhysicalQuantity() < int()

what if a is array?

print("{:.3f}".format(a)) dosnt work and
I've set %precision 3 and np.set_printoptions(precision=3) but result is still wo rounding
precision problem

dB() outdated

use dBQuantity(10*np.log10(3),'dB',islog=True) instead of dBUnit(10*np.log10(x),'dB',islog=True)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.