Skip to main content

This package provides engineering-related classes and functions

Project description

PyPI version License Python versions supported Format

https://travis-ci.org/pmacosta/peng.svg?branch=master Windows continuous integration Continuous integration coverage Documentation status

Description

This package provides engineering-related classes and functions, including:

  • A waveform class that is a first-class object. For example:

    >>> import copy, numpy, peng
    >>> obj_a=peng.Waveform(
    ...     indep_vector=numpy.array([1, 2, 3]),
    ...     dep_vector=numpy.array([10, 20, 30]),
    ...     dep_name='obj_a'
    ... )
    >>> obj_b = obj_a*2
    >>> print(obj_b)
    Waveform: obj_a*2
    Independent variable: [ 1, 2, 3 ]
    Dependent variable: [ 20, 40, 60 ]
    Independent variable scale: LINEAR
    Dependent variable scale: LINEAR
    Independent variable units: (None)
    Dependent variable units: (None)
    Interpolating function: CONTINUOUS
    >>> obj_c = copy.copy(obj_b)
    >>> obj_a == obj_b
    False
    >>> obj_b == obj_c
    True

    Numerous functions are provided (trigonometric, calculus, transforms, etc.) and creating new functions that operate on waveforms is simple since all of their relevant information can be accessed through properties

  • Handling numbers represented in engineering notation, obtaining their constituent components and converting to and from regular floats. For example:

    >>> import peng
    >>> x = peng.peng(1346, 2, True)
    >>> x
    '   1.35k'
    >>> peng.peng_float(x)
    1350.0
    >>> peng.peng_int(x)
    1
    >>> peng.peng_frac(x)
    35
    >>> str(peng.peng_mant(x))
    '1.35'
    >>> peng.peng_power(x)
    EngPower(suffix='k', exp=1000.0)
    >>> peng.peng_suffix(x)
    'k'
  • Pretty printing Numpy vectors. For example:

    >>> from __future__ import print_function
    >>> import peng
    >>> header = 'Vector: '
    >>> data = [1e-3, 20e-6, 30e+6, 4e-12, 5.25e3, -6e-9, 70, 8, 9]
    >>> print(
    ...     header+peng.pprint_vector(
    ...         data,
    ...         width=30,
    ...         eng=True,
    ...         frac_length=1,
    ...         limit=True,
    ...         indent=len(header)
    ...     )
    ... )
    Vector: [    1.0m,   20.0u,   30.0M,
                         ...
                70.0 ,    8.0 ,    9.0  ]
  • Formatting numbers represented in scientific notation with a greater degree of control and options than standard Python string formatting. For example:

    >>> import peng
    >>> peng.to_scientific_string(
    ...     number=99.999,
    ...     frac_length=1,
    ...     exp_length=2,
    ...     sign_always=True
    ... )
    '+1.0E+02'

Interpreter

The package has been developed and tested with Python 2.6, 2.7, 3.3, 3.4 and 3.5 under Linux (Debian, Ubuntu), Apple OS X and Microsoft Windows

Installing

$ pip install peng

Documentation

Available at Read the Docs

Contributing

  1. Abide by the adopted code of conduct

  2. Fork the repository from GitHub and then clone personal copy [1]:

    $ git clone \
          https://github.com/[github-user-name]/peng.git
    Cloning into 'peng'...
    ...
    $ cd peng
    $ export PENG_DIR=${PWD}
  3. Install the project’s Git hooks and build the documentation. The pre-commit hook does some minor consistency checks, namely trailing whitespace and PEP8 compliance via Pylint. Assuming the directory to which the repository was cloned is in the $PENG_DIR shell environment variable:

    $ ${PENG_DIR}/sbin/complete-cloning.sh
    Installing Git hooks
    Building peng package documentation
    ...
  4. Ensure that the Python interpreter can find the package modules (update the $PYTHONPATH environment variable, or use sys.paths(), etc.)

    $ export PYTHONPATH=${PYTHONPATH}:${PENG_DIR}
  5. Install the dependencies (if needed, done automatically by pip):

    • Astroid (Python 2.6: older than 1.4, Python 2.7 or newer: 1.3.8 or newer)

    • Cog (2.4 or newer)

    • Coverage (3.7.1 or newer)

    • Decorator (3.4.2 or newer)

    • Docutils (Python 2.6: 0.12 or newer and older than 0.13, Python 2.7: 0.12 or newer, Python 3.3: 0.12 or newer and older than 0.13, Python 3.4: 0.12 or newer, Python 3.5: 0.12 or newer, Python 3.6: 0.12 or newer)

    • Funcsigs (Python 2.x only, 0.4 or newer)

    • Inline Syntax Highlight Sphinx Extension (0.2 or newer)

    • Mock (Python 2.x only, 1.0.1 or newer)

    • Nose (Python 2.6: 1.0.0 or newer)

    • Numpy (Python 2.6: 1.8.2 or newer and older than 1.12, Python 2.7: 1.8.2 or newer, Python 3.3: 1.8.2 or newer and older than 1.12, Python 3.4: 1.8.2 or newer, Python 3.5: 1.8.2 or newer, Python 3.6: 1.8.2 or newer)

    • Pexdoc (1.0.9 or newer)

    • Pmisc (1.2.2 or newer)

    • Py.test (2.7.0 or newer)

    • PyParsing (2.0.7 or newer)

    • Pylint (Python 2.6: 1.3 or newer and older than 1.4, Python 2.7 or newer: 1.3.1 or newer)

    • Pytest-coverage (1.8.0 or newer except 2.3.0)

    • Pytest-xdist (optional, 1.8.0 or newer)

    • ReadTheDocs Sphinx theme (0.1.9 or newer)

    • Scipy (Python 2.6: 0.13.3 or newer and older than 0.18, Python 2.7: 0.13.3 or newer, Python 3.3: 0.13.3 or newer and older than 0.18, Python 3.4: 0.13.3 or newer, Python 3.5: 0.13.3 or newer, Python 3.6: 0.13.3 or newer)

    • Six (1.4.0 or newer)

    • Sphinx (Python 2.6: 1.2.3 or newer and 1.4.9 or older, Python 2.7: 1.5 or newer, Python 3.3: 1.2.3 or newer and 1.4.9 or older, Python 3.4: 1.5 or newer, Python 3.5: 1.5 or newer, Python 3.6: 1.5 or newer)

    • Tox (1.9.0 or newer)

    • Virtualenv (13.1.2 or newer)

  6. Implement a new feature or fix a bug

  7. Write a unit test which shows that the contributed code works as expected. Run the package tests to ensure that the bug fix or new feature does not have adverse side effects. If possible achieve 100% code and branch coverage of the contribution. Thorough package validation can be done via Tox and Py.test:

    $ tox
    GLOB sdist-make: .../peng/setup.py
    py26-pkg inst-nodeps: .../peng/.tox/dist/peng-...zip

    Setuptools can also be used (Tox is configured as its virtual environment manager) [2]:

    $ python setup.py tests
    running tests
    running egg_info
    writing requirements to peng.egg-info/requires.txt
    writing peng.egg-info/PKG-INFO
    ...

    Tox (or Setuptools via Tox) runs with the following default environments: py26-pkg, py27-pkg, py33-pkg, py34-pkg and py35-pkg [3]. These use the Python 2.6, 2.7, 3.3, 3.4 and 3.5 interpreters, respectively, to test all code in the documentation (both in Sphinx *.rst source files and in docstrings), run all unit tests, measure test coverage and re-build the exceptions documentation. To pass arguments to Py.test (the test runner) use a double dash (--) after all the Tox arguments, for example:

    $ tox -e py27-pkg -- -n 4
    GLOB sdist-make: .../peng/setup.py
    py27-pkg inst-nodeps: .../peng/.tox/dist/peng-...zip
    ...

    Or use the -a Setuptools optional argument followed by a quoted string with the arguments for Py.test. For example:

    $ python setup.py tests -a "-e py27-pkg -- -n 4"
    running tests
    ...

    There are other convenience environments defined for Tox [4]:

    • py26-repl, py27-repl, py33-repl, py34-repl and py35-repl run the Python 2.6, 2.7, 3.3, 3.4 or 3.5 REPL, respectively, in the appropriate virtual environment. The peng package is pip-installed by Tox when the environments are created. Arguments to the interpreter can be passed in the command line after a double dash (--)

    • py26-test, py27-test, py33-test, py34-test and py35-test run py.test using the Python 2.6, 2.7, 3.3, 3.4 or Python 3.5 interpreter, respectively, in the appropriate virtual environment. Arguments to py.test can be passed in the command line after a double dash (--) , for example:

      $ tox -e py34-test -- -x test_eng.py
      GLOB sdist-make: [...]/peng/setup.py
      py34-test inst-nodeps: [...]/peng/.tox/dist/peng-[...].zip
      py34-test runtests: PYTHONHASHSEED='680528711'
      py34-test runtests: commands[0] | [...]py.test -x test_eng.py
      ==================== test session starts ====================
      platform linux -- Python 3.4.2 -- py-1.4.30 -- [...]
      ...
    • py26-cov, py27-cov, py33-cov, py34-cov and py35-cov test code and branch coverage using the Python 2.6, 2.7, 3.3, 3.4 or 3.5 interpreter, respectively, in the appropriate virtual environment. Arguments to py.test can be passed in the command line after a double dash (--). The report can be found in ${PENG_DIR}/.tox/py[PV]/usr/share/peng/tests/htmlcov/index.html where [PV] stands for 26, 27, 33, 34 or 35 depending on the interpreter used

  8. Verify that continuous integration tests pass. The package has continuous integration configured for Linux (via Travis) and for Microsoft Windows (via Appveyor). Aggregation/cloud code coverage is configured via Codecov. It is assumed that the Codecov repository upload token in the Travis build is stored in the ${CODECOV_TOKEN} environment variable (securely defined in the Travis repository settings page). Travis build artifacts can be transferred to Dropbox using the Dropbox Uploader script (included for convenience in the ${PENG_DIR}/sbin directory). For an automatic transfer that does not require manual entering of authentication credentials place the APPKEY, APPSECRET, ACCESS_LEVEL, OAUTH_ACCESS_TOKEN and OAUTH_ACCESS_TOKEN_SECRET values required by Dropbox Uploader in the in the ${DBU_APPKEY}, ${DBU_APPSECRET}, ${DBU_ACCESS_LEVEL}, ${DBU_OAUTH_ACCESS_TOKEN} and ${DBU_OAUTH_ACCESS_TOKEN_SECRET} environment variables, respectively (also securely defined in Travis repository settings page)

  9. Document the new feature or bug fix (if needed). The script ${PENG_DIR}/sbin/build_docs.py re-builds the whole package documentation (re-generates images, cogs source files, etc.):

    $ ${PUTIL_DIR}/sbin/build_docs.py -h
    usage: build_docs.py [-h] [-d DIRECTORY] [-r]
                         [-n NUM_CPUS] [-t]
    
    Build peng package documentation
    
    optional arguments:
      -h, --help            show this help message and exit
      -d DIRECTORY, --directory DIRECTORY
                            specify source file directory
                            (default ../peng)
      -r, --rebuild         rebuild exceptions documentation.
                            If no module name is given all
                            modules with auto-generated
                            exceptions documentation are
                            rebuilt
      -n NUM_CPUS, --num-cpus NUM_CPUS
                            number of CPUs to use (default: 1)
      -t, --test            diff original and rebuilt file(s)
                            (exit code 0 indicates file(s) are
                            identical, exit code 1 indicates
                            file(s) are different)

    Output of shell commands can be automatically included in reStructuredText source files with the help of Cog and the docs.support.term_echo module.

    Similarly Python files can be included in docstrings with the help of Cog and the docs.support.incfile module

Footnotes

License

The MIT License (MIT)

Copyright (c) 2013-2017 Pablo Acosta-Serafini

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. .. CHANGELOG.rst .. Copyright (c) 2013-2017 Pablo Acosta-Serafini .. See LICENSE for details

Changelog

  • 1.0.6 [2016-02-11]: Package build enhancements and fixes

  • 1.0.5 [2016-02-09]: Python 3.6 support

  • 1.0.4 [2016-09-19]: Fixed Touchstone read function for “MA” and “DB” formats where the angles were incorrectly treated as being in radians

  • 1.0.3 [2016-07-29]: Fixed resolution loss when writing Touchstone files

  • 1.0.2 [2016-07-25]:

    • Frequency vector is now always in Hertz regardless of unit used in Touchstone file

    • Minor documentation bug fixes

  • 1.0.1 [2016-06-11]: Minor documentation build bug fix

  • 1.0.0 [2016-05-12]: Final release of 1.0.0 branch

  • 1.0.0rc1 [2016-05-11]: Initial commit, forked a subset from putil PyPI package

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

peng-1.0.6.tar.gz (133.4 kB view details)

Uploaded Source

Built Distributions

peng-1.0.6-py36-none-any.whl (50.4 kB view details)

Uploaded Python 3.6

peng-1.0.6-py35-none-any.whl (50.4 kB view details)

Uploaded Python 3.5

peng-1.0.6-py34-none-any.whl (50.4 kB view details)

Uploaded Python 3.4

peng-1.0.6-py33-none-any.whl (50.4 kB view details)

Uploaded Python 3.3

peng-1.0.6-py27-none-any.whl (50.4 kB view details)

Uploaded Python 2.7

peng-1.0.6-py26-none-any.whl (50.4 kB view details)

Uploaded Python 2.6

File details

Details for the file peng-1.0.6.tar.gz.

File metadata

  • Download URL: peng-1.0.6.tar.gz
  • Upload date:
  • Size: 133.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for peng-1.0.6.tar.gz
Algorithm Hash digest
SHA256 ad4f8ff8b2853beed30bcb33b5ce0e90e7ee535f853b47b785306af6c726fa6e
MD5 4bf0960929a2bc63fa1d733aba76725e
BLAKE2b-256 e5f5dd160a3835d555094ca1cd410032c901618426c776baceaff30111ce0997

See more details on using hashes here.

File details

Details for the file peng-1.0.6-py36-none-any.whl.

File metadata

File hashes

Hashes for peng-1.0.6-py36-none-any.whl
Algorithm Hash digest
SHA256 0fb858299a3ee238f53b1e9aa1f45397c1a339f7412a2e392127548ca93f56ee
MD5 dfcab8f17d02100bd719e894e954b2bf
BLAKE2b-256 287c8ec80d9683359b70aa1667a85910bac9f7a9a22ca1746c6369b0f2911ec1

See more details on using hashes here.

File details

Details for the file peng-1.0.6-py35-none-any.whl.

File metadata

File hashes

Hashes for peng-1.0.6-py35-none-any.whl
Algorithm Hash digest
SHA256 3b2bde2e28b51ff0dd620c9c8e0a940ae00017cd6f7774fd1440cffbaa136d3e
MD5 17835ecf5d316a27975729155be1dc54
BLAKE2b-256 9b24b58609e1033a78f3a85a3a1bce962f2127eb406a4cba2e2a198a53d31c7c

See more details on using hashes here.

File details

Details for the file peng-1.0.6-py34-none-any.whl.

File metadata

File hashes

Hashes for peng-1.0.6-py34-none-any.whl
Algorithm Hash digest
SHA256 7c5443eac3e803686fdc1b66c2cd73ebf908652922ec7ff41fe669bbb03b2a26
MD5 5d43e948f5f6aa6a6915cb5ffcd99729
BLAKE2b-256 c013d0a54c974a2c40cc5cc62ffa166d4f5aa8ae6a2f81a6e3b5be47d59ecab2

See more details on using hashes here.

File details

Details for the file peng-1.0.6-py33-none-any.whl.

File metadata

File hashes

Hashes for peng-1.0.6-py33-none-any.whl
Algorithm Hash digest
SHA256 8d4739f391c404ea9ceceeaaf916af77ac214d9b39029c686de5727cd83c05b3
MD5 b6866342c2a83271db4e640e57df4952
BLAKE2b-256 1bacac1bb06668bcbb3c70fae72a9b97769e908fa866d36bea1d1211d539822e

See more details on using hashes here.

File details

Details for the file peng-1.0.6-py27-none-any.whl.

File metadata

File hashes

Hashes for peng-1.0.6-py27-none-any.whl
Algorithm Hash digest
SHA256 ee48d3376bee9e1fbe42df7c16167a27df96469a7c5541f441c3f36a5f70710e
MD5 5a30c0020ddb8712cf6b90c1a7bc4f7e
BLAKE2b-256 ae77860d21c8cad9b0cd1e87548db31103c3e026bccb4b896fb7775efee226ce

See more details on using hashes here.

File details

Details for the file peng-1.0.6-py26-none-any.whl.

File metadata

File hashes

Hashes for peng-1.0.6-py26-none-any.whl
Algorithm Hash digest
SHA256 173ef2271dcecfe366bc040649b281a1ccd4021af16552960de654bbc7097efa
MD5 d676143ad98bf5af4919ce0adba0dd3c
BLAKE2b-256 29617ef7cf6db69db44d2b4de52c35b913ffaabbbbcfae9863d047c2a78ceb9b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page