Giter Club home page Giter Club logo

ipython-physics's Introduction

ipython-physics

This is an extension for IPython 0.11+ that at the moment mainly enables easy input of physical quantities (i.e. numbers with units). The implementation is adapted from Konrad Hinsen's "Scientific.Physics.PhysicalQuantities" module.

If the "uncertainties" module (http://github.com/newville/uncertainties/) is installed, you can also enter values with standard errors wherever you can enter quantities, see the examples below.

You can have a look at a short notebook tutorial put together by Hans Fangohr at http://www.southampton.ac.uk/~fangohr/blog/physical-quantities-numerical-value-with-units-in-python.html.

Quick installation advice:

Place physics.py in any directory on PYTHONPATH, or add its directory to sys.path in your IPython ipython_config.py file. Then you can load it either in the config file or on the command line as described here: http://ipython.org/ipython-doc/dev/config/extensions/index.html

Quick usage examples:

  In:  1 m // cm                        # convert between units
  Out: 100 cm                           # (syntax inspired by Mathematica)

  In:  (1 m)/(1 s)                      # sugar for inline quantity input
  Out: 1 m/s                            # in arbitrary expressions

  In:  Quantity('1 m')/Quantity('1 s')  # this is the desugared form
  Out: 1 m/s

  In:  // furlong/fortnight             # convert units in last result
  Out: 6012.8848 furlong/fortnight

  In:  alpha = 90 deg                   # more sugar for assignment: no
                                        # parentheses needed

  In:  sin(alpha)                       # angle units work with NumPy
  Out: 1.0                              # trigonometric functions

  In:  m = 80 +/- 5 kg                  # calculating with uncertainties
  In:  v = 130 +/- 10 m/s               # (needs the "uncertainties" module)
  In:  0.5 * m * v**2 // kJ
  Out: 676 +/- 112.25445 kJ

  In:  %tbl sqrt(?x**2 + ?y**2) // cm   # quickly tabulate a formula:
  x = 1 m                               # provide some values
  y = 2 m
  Out: 223.6068 cm                      # and get the result
  x = 3 m                               # ... this continues as long as you
  y = 4 m                               # enter new values
  Out: 500 cm

  In:  c0                               # important physical constants
  Out: 2.9979246e+08 m/s
  In:  setprec(4)                       # set the display precision
  In:  c0
  Out: 2.998e+08 m/s

The predefined constants are:

  pi
  e
  c0    -- vacuum speed of light
  mu0   -- magnetic constant
  eps0  -- electric constant
  Grav  -- Newton's constant
  hpl   -- Planck's constant
  hbar  -- Planck's constant / 2pi
  e0    -- elementary charge
  me    -- electron mass
  mp    -- proton mass
  mn    -- neutron mass
  NA    -- Avogadro's number
  kb    -- Boltzmann constant
  g0    -- Standard earth gravity
  R     -- Universal gas constant
  alpha -- fine structure constant
  Ry    -- Rydberg constant
  mu_n  -- Magnetic moment of the neutron
  gamma -- Gyromagnetic ratio of the neutron
  h0    -- dimensionless Hubble parameter

Please let me know if anything is missing.

ipython-physics's People

Contributors

birkenfeld avatar carreau avatar hansihe avatar smutch avatar takluyver avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

ipython-physics's Issues

What about license?

I have written two tools to read in and process binary Nanoindenter- and AFM-data. To prevent user errors due to wrong units, I'm considering to implement physical values as values with unit. When looking for solutions, I stumbbled over this project. But I'm not sure, under what conditions I can use this package? Or maybe even just use a moddified physics.py (I don't need ipyton support) in my projects? My projects both use MIT-license.

cannot load extension in ipython 5.8 (python 3.7.3)

Hello,

I have been using your wonderful extension for many years, with and ipython 2.3 (python 2.7.3 )

Now I have switched to ipython 5.8 (python 3.7.3) and I get following error when trying to load the extension:

[TerminalIPythonApp] WARNING | Error in loading extension: physics
Check your config files in ~/.ipython/profile_default
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/IPython/core/shellapp.py", line 248, in init_extensions
    self.shell.extension_manager.load_extension(ext)
  File "/usr/lib/python3/dist-packages/IPython/core/extensions.py", line 83, in load_extension
    __import__(module_str)
  File "~/.ipython/extensions/physics.py", line 21
    def valuetype((v, u)):
                  ^
SyntaxError: invalid syntax

I see the extension has not been updated for many years, so i suspect it is nt compatible with current version.

Could you please consider updating it?

Missing unit for physical constants

It seems the argument Q(1, 'NA') returns

physics.UnitError: Invalid or unknown unit in 'NA'

I have added the line _addUnit('NA', '6.02214129e23*1/mol', 'Avogadro number') and cleared the error. Likely some other constants need to be added too.

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.