nf6x-eetools


Namenf6x-eetools JSON
Version 1.0.1 PyPI version JSON
download
home_page
SummaryNF6X's misc. electrical engineering related tools.
upload_time2024-02-26 05:52:48
maintainer
docs_urlNone
author
requires_python>3.8
license
keywords drill ee fractional iec 60063:2015 resistor
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # nf6x_eetools: NF6X's misc. electrical engineering related tools.

This Python package is a collection of miscellaneous tools I've created for my general electrical engineering related tasks. I use them in scripts and in interactive ipython shells.

## EngFormatter

EngFormatter extends the standard string.Formatter class to support new Format Specification Mini Language types which are handy for component values, electrical measurements, etc.:

type | description
-----|-------------------------------------------------------------------------
i    | "engineering" format with specified digits of precision and SI unit prefix
I    | "engineering" format with specified digits of presions and SI word prefix

These two variants both format numbers with coefficients in the range of \[1...1000), an SI prefix, and a specified total number of significant digits. Rounding is performed with the decimal.Decimal() class, using decimal.ROUND_HALF_UP. This handles significant digits in much the same way that HP scientific calculators do.

The top level package creates variable `eformat` as a shortcut to the format() method of an EngFormatter instance. It also provides the `eng()` function as a shortcut for interactive use.

For example:

```
>>> import nf6x_eetools as ee
>>> print(ee.eformat('R{:d} = {:3i}Ω', 123, 12345))
R123 = 12.3 kΩ
>>> print(ee.eformat('V1 = {:+2I}volt', 0.012345))
V1 = +12 millivolt
>>> ee.eng(12345)
'12.3 k'
>>> ee.eng(12345, 2, 'V')
'12 kV'
```


## E3, E6, E12, E24, E48, E96, E192(value, unit='Ω')

These classes find the nearest IEC 60063:2015 standard component value to a specified ideal value. See [E series of preferred numbers](https://en.wikipedia.org/wiki/E_series_of_preferred_numbers) for reference.

When cast to a str, the approximated value will be formatted with EngFormatter
using an appropriate number of significant digits for the series and appending
SI units. 

For example, to print the standard 1% tolerance resistor value closest to 50 ohms, along with its tolerance and nominal error from the ideal value:

```
>>> import nf6x_eetools as ee
>>> r = ee.E96(50)
>>> print(f'{str(r)} ±{r.tolerance():%} ({r.error():+.2%} error)')
49.9 Ω ±1% (-0.20% error)
```

## ratio(v1, v2, maxsteps=1)

Find a pair of standard component values approximating a ratio.

I typically use this for tasks such as finding standard resistor values to use in a resistor divider setting the output voltage of a regulator.

Given two values v1 and v2, ratio() finds two nearby standard component values which most closely match the ratio of the ideal values. If the passed values are derived from Eseries, then the chosen value will be in the same series, within +/- maxsteps of the nearest standard value. If either passed value is not derived from Eseries, then E96 (±1%) values will be used.

maxsteps must be an integer >= 1.

Returns tuple of (w1, w2, error) where w1 and w2 are the new approximate values, and error is defined as:

                    (w1.approx() / w2.approx())
    error = 1.0  -  ---------------------------
                     (v1.exact() / v2.exact())

```
>>> import nf6x_eetools as ee
>>> r1_ideal = 1.23456E3
>>> r2_ideal = 6.54321E5
>>> (R1, R2, error) = ee.ratio(ee.E96(r1_ideal), ee.E96(r2_ideal))
>>> print(f'R1 = {str(R1)}')
R1 = 1.21 kΩ
>>> print(f'R2 = {str(R2)}')
R2 = 634 kΩ
>>> print(f'error = {error:+.2%}')
error = -1.15%
```


## divider(v_in, v_out, r_total=E96(10000), maxsteps=1)

Design a resistor divider using standard values.

For the passed input voltage v_in and output voltage v_out, divider() designs a resistor divider using standard component values to produce v_out from v_in. The top and bottom resistors will add up to approximately r_total, and will be in the same series as r_total. If r_total is not an Eseries subclass, then E96 (±1%) values will be used. maxsteps determines how many standard value steps the top and bottom resistors may deviate from their initial approximations. Increasing maxsteps tends to reduce the v_out error and increase the deviation from r_total.

Returns a tuple of (r_top, r_bot, error), with error defined by:

error = (v_out_actual - v_out)/v_out


## frac(value, denominator=64, rounding=0, correction=True)

Find nearest fractional dimension to provided value.

Returns a string representation of a fractional dimension approximating the provided value.

Argument     | Description \[default\]
-------------|------------------------------------------
value        | Numeric value to be approximated
denominator  | Fractional denominator prior to reduction \[64\]
rounding     | Round normally if 0; round up if positive; round down if negative \[0\]
correction   | Include correction for original value \[True\]


## drill(diameter, margin=0, showdiam=True, table=drill_table)

Return string representing nearest American drill size. See [Drill bit sizes](https://en.wikipedia.org/wiki/Drill_bit_sizes) for reference.

For a given diameter, return a string representing the nearest American twist drill size.

Argument     | Description \[default\]
-------------|------------------------------------------
diameter     | Hole diameter to be approximated
margin       | If 0, return nearest size; if > 0, return equal or larger size; if < 0, return equal or smaller size \[0\]
showdiam     | If True, include actual diameter in returned string \[True\]
table        | Drill table to use \[drill_table\]

Four drill tables are currently defined:

Table                  | Description
-----------------------|----------------------------------
fractional_drill_table | Fractional inch drill sizes
number_drill_table     | Number gauge drill sizes
letter_drill_table     | Letter gauge drill sizes
drill_table            | Combined table of all drill sizes


For example:

```
>>> import nf6x_eetools as ee
>>> ee.drill(0.256)
'F (0.257 in)'
>>> ee.drill(0.256, 1)
'F (0.257 in)'
>>> ee.drill(0.256, -1)
'1/4in (0.25 in)'
```

## Building and Installing from Source

After cloning the source code repository, build with the python `build` package, and then install the generated wheel file with `pip`. For example:

```
python3 -m build
python3 -m pip install dist/nf6x_eetools-1.0-py3-none-any.whl
```

(change the version number in the .whl path to point to the generated wheel file)

## Running Tests on the Source Code

To run lint on the code, install pylint and run it from the top directory:

```
pylint ./src ./tests
```

To run regression tests, install pytest and pytest-cov, and run pytest from the top directory:

```
pytest
```



            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "nf6x-eetools",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">3.8",
    "maintainer_email": "",
    "keywords": "drill,EE,fractional,IEC 60063:2015,resistor",
    "author": "",
    "author_email": "\"Mark J. Blair\" <nf6x@nf6x.net>",
    "download_url": "https://files.pythonhosted.org/packages/2b/4f/3135c3551cc27a8b45255ebc45b5508238776851cfad7121367f2a8057e9/nf6x_eetools-1.0.1.tar.gz",
    "platform": null,
    "description": "# nf6x_eetools: NF6X's misc. electrical engineering related tools.\n\nThis Python package is a collection of miscellaneous tools I've created for my general electrical engineering related tasks. I use them in scripts and in interactive ipython shells.\n\n## EngFormatter\n\nEngFormatter extends the standard string.Formatter class to support new Format Specification Mini Language types which are handy for component values, electrical measurements, etc.:\n\ntype | description\n-----|-------------------------------------------------------------------------\ni    | \"engineering\" format with specified digits of precision and SI unit prefix\nI    | \"engineering\" format with specified digits of presions and SI word prefix\n\nThese two variants both format numbers with coefficients in the range of \\[1...1000), an SI prefix, and a specified total number of significant digits. Rounding is performed with the decimal.Decimal() class, using decimal.ROUND_HALF_UP. This handles significant digits in much the same way that HP scientific calculators do.\n\nThe top level package creates variable `eformat` as a shortcut to the format() method of an EngFormatter instance. It also provides the `eng()` function as a shortcut for interactive use.\n\nFor example:\n\n```\n>>> import nf6x_eetools as ee\n>>> print(ee.eformat('R{:d} = {:3i}\u03a9', 123, 12345))\nR123 = 12.3 k\u03a9\n>>> print(ee.eformat('V1 = {:+2I}volt', 0.012345))\nV1 = +12 millivolt\n>>> ee.eng(12345)\n'12.3 k'\n>>> ee.eng(12345, 2, 'V')\n'12 kV'\n```\n\n\n## E3, E6, E12, E24, E48, E96, E192(value, unit='\u03a9')\n\nThese classes find the nearest IEC 60063:2015 standard component value to a specified ideal value. See [E series of preferred numbers](https://en.wikipedia.org/wiki/E_series_of_preferred_numbers) for reference.\n\nWhen cast to a str, the approximated value will be formatted with EngFormatter\nusing an appropriate number of significant digits for the series and appending\nSI units. \n\nFor example, to print the standard 1% tolerance resistor value closest to 50 ohms, along with its tolerance and nominal error from the ideal value:\n\n```\n>>> import nf6x_eetools as ee\n>>> r = ee.E96(50)\n>>> print(f'{str(r)} \u00b1{r.tolerance():%} ({r.error():+.2%} error)')\n49.9 \u03a9 \u00b11% (-0.20% error)\n```\n\n## ratio(v1, v2, maxsteps=1)\n\nFind a pair of standard component values approximating a ratio.\n\nI typically use this for tasks such as finding standard resistor values to use in a resistor divider setting the output voltage of a regulator.\n\nGiven two values v1 and v2, ratio() finds two nearby standard component values which most closely match the ratio of the ideal values. If the passed values are derived from Eseries, then the chosen value will be in the same series, within +/- maxsteps of the nearest standard value. If either passed value is not derived from Eseries, then E96 (\u00b11%) values will be used.\n\nmaxsteps must be an integer >= 1.\n\nReturns tuple of (w1, w2, error) where w1 and w2 are the new approximate values, and error is defined as:\n\n                    (w1.approx() / w2.approx())\n    error = 1.0  -  ---------------------------\n                     (v1.exact() / v2.exact())\n\n```\n>>> import nf6x_eetools as ee\n>>> r1_ideal = 1.23456E3\n>>> r2_ideal = 6.54321E5\n>>> (R1, R2, error) = ee.ratio(ee.E96(r1_ideal), ee.E96(r2_ideal))\n>>> print(f'R1 = {str(R1)}')\nR1 = 1.21 k\u03a9\n>>> print(f'R2 = {str(R2)}')\nR2 = 634 k\u03a9\n>>> print(f'error = {error:+.2%}')\nerror = -1.15%\n```\n\n\n## divider(v_in, v_out, r_total=E96(10000), maxsteps=1)\n\nDesign a resistor divider using standard values.\n\nFor the passed input voltage v_in and output voltage v_out, divider() designs a resistor divider using standard component values to produce v_out from v_in. The top and bottom resistors will add up to approximately r_total, and will be in the same series as r_total. If r_total is not an Eseries subclass, then E96 (\u00b11%) values will be used. maxsteps determines how many standard value steps the top and bottom resistors may deviate from their initial approximations. Increasing maxsteps tends to reduce the v_out error and increase the deviation from r_total.\n\nReturns a tuple of (r_top, r_bot, error), with error defined by:\n\nerror = (v_out_actual - v_out)/v_out\n\n\n## frac(value, denominator=64, rounding=0, correction=True)\n\nFind nearest fractional dimension to provided value.\n\nReturns a string representation of a fractional dimension approximating the provided value.\n\nArgument     | Description \\[default\\]\n-------------|------------------------------------------\nvalue        | Numeric value to be approximated\ndenominator  | Fractional denominator prior to reduction \\[64\\]\nrounding     | Round normally if 0; round up if positive; round down if negative \\[0\\]\ncorrection   | Include correction for original value \\[True\\]\n\n\n## drill(diameter, margin=0, showdiam=True, table=drill_table)\n\nReturn string representing nearest American drill size. See [Drill bit sizes](https://en.wikipedia.org/wiki/Drill_bit_sizes) for reference.\n\nFor a given diameter, return a string representing the nearest American twist drill size.\n\nArgument     | Description \\[default\\]\n-------------|------------------------------------------\ndiameter     | Hole diameter to be approximated\nmargin       | If 0, return nearest size; if > 0, return equal or larger size; if < 0, return equal or smaller size \\[0\\]\nshowdiam     | If True, include actual diameter in returned string \\[True\\]\ntable        | Drill table to use \\[drill_table\\]\n\nFour drill tables are currently defined:\n\nTable                  | Description\n-----------------------|----------------------------------\nfractional_drill_table | Fractional inch drill sizes\nnumber_drill_table     | Number gauge drill sizes\nletter_drill_table     | Letter gauge drill sizes\ndrill_table            | Combined table of all drill sizes\n\n\nFor example:\n\n```\n>>> import nf6x_eetools as ee\n>>> ee.drill(0.256)\n'F (0.257 in)'\n>>> ee.drill(0.256, 1)\n'F (0.257 in)'\n>>> ee.drill(0.256, -1)\n'1/4in (0.25 in)'\n```\n\n## Building and Installing from Source\n\nAfter cloning the source code repository, build with the python `build` package, and then install the generated wheel file with `pip`. For example:\n\n```\npython3 -m build\npython3 -m pip install dist/nf6x_eetools-1.0-py3-none-any.whl\n```\n\n(change the version number in the .whl path to point to the generated wheel file)\n\n## Running Tests on the Source Code\n\nTo run lint on the code, install pylint and run it from the top directory:\n\n```\npylint ./src ./tests\n```\n\nTo run regression tests, install pytest and pytest-cov, and run pytest from the top directory:\n\n```\npytest\n```\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "NF6X's misc. electrical engineering related tools.",
    "version": "1.0.1",
    "project_urls": {
        "Source": "https://gitlab.com/NF6X_Development/nf6x_eetools"
    },
    "split_keywords": [
        "drill",
        "ee",
        "fractional",
        "iec 60063:2015",
        "resistor"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5b2684417a66ba468fa8f37414b2e24bf7ee7410a4cb8ab8f8c2d64ec9f77fbe",
                "md5": "9cf05090bcbc78a7fae6e5e44c1f5dfa",
                "sha256": "df88e7f11337a55202bea30320b0344aeb249048203bd86e06abb777103f3b81"
            },
            "downloads": -1,
            "filename": "nf6x_eetools-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9cf05090bcbc78a7fae6e5e44c1f5dfa",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">3.8",
            "size": 27866,
            "upload_time": "2024-02-26T05:52:46",
            "upload_time_iso_8601": "2024-02-26T05:52:46.831288Z",
            "url": "https://files.pythonhosted.org/packages/5b/26/84417a66ba468fa8f37414b2e24bf7ee7410a4cb8ab8f8c2d64ec9f77fbe/nf6x_eetools-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2b4f3135c3551cc27a8b45255ebc45b5508238776851cfad7121367f2a8057e9",
                "md5": "679a67189c2b193cb2469f4c7e6bbd43",
                "sha256": "c1a2823dad7f97660b0ac2f806e9729b1b245260d4c7b3a84524f7fadc053fd1"
            },
            "downloads": -1,
            "filename": "nf6x_eetools-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "679a67189c2b193cb2469f4c7e6bbd43",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">3.8",
            "size": 25854,
            "upload_time": "2024-02-26T05:52:48",
            "upload_time_iso_8601": "2024-02-26T05:52:48.154355Z",
            "url": "https://files.pythonhosted.org/packages/2b/4f/3135c3551cc27a8b45255ebc45b5508238776851cfad7121367f2a8057e9/nf6x_eetools-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-26 05:52:48",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "NF6X_Development",
    "gitlab_project": "nf6x_eetools",
    "lcname": "nf6x-eetools"
}
        
Elapsed time: 0.22658s