Skip to main content

Spice 原始解析器

项目描述

斯皮奇

一个用于解析和绘制香料原始数据文件的小型 Python 包。

https://img.shields.io/pypi/v/spyci.svg https://img.shields.io/travis/gmagno/spyci.svg 文件状态
  • 免费软件:麻省理工学院许可证

  • 文档:https ://spyci.readthedocs.io 。

入门

这些说明将为您提供包的副本并在本地计算机上运行。

注意:目前只支持 ascii raw spice 格式!

安装

来自 PyPI

$ pip install spyci  # it is recommended to this in a virtual environment

来自 github 仓库

$ pip install git+https://github.com/gmagno/spyci.git

或者

$ git clone git@github.com:gmagno/spyci.git
$ cd spyci/
$ python setup.py install

用法

从 python 运行:

>>> from spyci import spyci
>>> data = spyci.load_raw("/path/to/rawspice.raw")  # see 'Data structure' section below

或者只使用 CLI:

$ spyci -r /path/to/rawspice.raw vin vout

有关更多详细信息,请使用:

$ spyci -h
usage: spyci [-h] [-v] [-r RAW_FILE] [-l] [-f] [-o OUT_IMAGE] ...

Spyci (spyci v0.6.1) -- parses ngspice raw data files and
plots the specified variables.
For full documentation check the repo: https://github.com/gmagno/spyci

positional arguments:
  VARS                  List of variables to plot

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         shows spyci version
  -r RAW_FILE, --raw-file RAW_FILE
                        path to raw file to be parsed
  -l, --list-variables  lists variables that can be plotted
  -f, --out-formats     lists supported output image formats
  -o OUT_IMAGE, --out-image OUT_IMAGE
                        path to output image file, use -f, to list supported
                        formats

                                                 /##
                                                |__/
          /#######  /######  /##   /##  /####### /##
         /##_____/ /##__  ##| ##  | ## /##_____/| ##
        |  ###### | ##  \ ##| ##  | ##| ##      | ##
         \____  ##| ##  | ##| ##  | ##| ##      | ##
         /#######/| #######/|  #######|  #######| ##
        |_______/ | ##____/  \____  ## \_______/|__/
                  | ##       /##  | ##
                  | ##      |  ######/
                  |__/       \______/

return:
    The return value of spyci is 0 if the raw file is successfully
    parsed and plotted.

examples:
    # Run without arguments will attempt to load rawspice.raw from cwd
    # and plot all variables
    $ spyci

    # List variables that can be plotted
    $ spyci -l
    Variables:

    idx  name        type
    -----  ----------  -------
        1  i(l1)       current
        2  n1          voltage
        3  vi          voltage
        4  vo          voltage
        5  i(vsource)  current

    # Load 'some/location/sim.raw' and plot variables 'i(l1)' and 'vo'
    $ spyci -r some/location/sim.raw "i(l1)" vo

    # Indices can be used insted of variable names, this is equivalent
    # to the previous example
    $ spyci -r some/location/sim.raw 1 4

    # Save your plot to the file system
    $ spyci -o myplot.png 1 4

    # Different image formats are supported, just use the correct
    # extension, {.png, .svg, .pdf, ...}. For a list of supported
    # formats run with -f flag
    $ spyci -f
    Supported output image file formats:

    ext    format
    -----  -------------------------
    raw    Raw RGBA bitmap
    rgba   Raw RGBA bitmap
    pgf    PGF code for LaTeX
    svgz   Scalable Vector Graphics
    svg    Scalable Vector Graphics
    ps     Postscript
    png    Portable Network Graphics
    eps    Encapsulated Postscript
    pdf    Portable Document Format

copyright:
    Copyright © 2020 Gonçalo Magno <goncalo@gmagno.dev>
    This software is licensed under the MIT License.

数据结构

load_raw()正确解析的原始香料文件返回具有以下结构的字典:

{
    "title": <str>,
    "date:": <str>,
    "plotname:": <str>,
    "flags:": <str>,
    "no_vars:": <str>,
    "no_points:": <str>,
    "vars": [
        { "idx": <int>, "name": <str>, "type": <str> },
        { "idx": <int>, "name": <str>, "type": <str> }
        ...
        { "idx": <int>, "name": <str>, "type": <str> }
    ]
    "values": {
        "var1": <numpy.ndarray>,
        "var2": <numpy.ndarray>,
        ...
        "varN": <numpy.ndarray>
    }
}

其中 values values是一个带有实际数据的 numpy 结构化数组。

例子

以下示例使用 ngspice 运行 spice 模拟,因此请确保已安装它。在 ubuntu 上,这将是:

$ sudo apt install ngspice

带运算放大器 LM741 的反相放大器

检查目录examples/amplifier/以获取有关电路和模拟文件的详细信息。

示意图:

放大器

运行模拟:

$ cd examples/amplifier
$ ngspice -r rawspice.raw -o output.log main.cir
$ spyci vout vin

这将触发 ngspice 生成 output.log 和 rawspice.raw 文件,并绘制电压vinvout

放大器

带有运算放大器 LM741 的二阶低通滤波器

检查目录examples/lp_filter/以获取有关 cirtcuit 和模拟文件的详细信息。

示意图:

lp_filter

运行模拟:

$ cd examples/lp_filter
$ ngspice -r rawspice.raw -o output.log main.cir
$ spyci vout vin

这将触发 ngspice 生成 output.log 和 rawspice.raw 文件,并以 dB 为单位绘制增益vout / vin

lp_filter

执照

该项目在 MIT 许可下获得许可 - 请参阅LICENSE文件了解详细信息

历史

0.6.2 (2020-06-02)

  • 修复项目。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

spyci-1.0.2.tar.gz (16.5 kB 查看哈希

已上传 source

内置分布

spyci-1.0.2-py2.py3-none-any.whl (9.0 kB 查看哈希

已上传 py2 py3