MtxDrawer


NameMtxDrawer JSON
Version 0.0.32 PyPI version JSON
download
home_pagehttps://github.com/Rhythmicc/DrawMtxAsThumbnail
SummaryDraw Mtx As Thumbnail
upload_time2024-11-03 09:36:01
maintainerNone
docs_urlNone
authorRhythmLian
requires_pythonNone
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Draw Mtx As Thumbnail - 将 Mtx 画为缩略图

![help](https://cos.rhythmlian.cn/ImgBed/a9cdf3bef0655d1d6e2563c40069938b.png)

## 样例

|      ![aver](./img/ash85_aver.png)<br />平均值      |   ![real](./img/ash85_real.png)<br />不处理    |
| :-------------------------------------------------: | :--------------------------------------------: |
| ![log](./img/ash85_log.png)<br /><b>取 0 次 log</b> | ![abs](./img/ash85_abs.png)<br /><b>绝对值</b> |

## 安装

```shell
pip3 install MtxDrawer -U
```

自动安装依赖并注册一个命令`mtx-drawer`

## 子命令与参数

包含两个子命令 `draw-one` 和 `draw`,可以在终端中通过`mtx-drawer`命令查看,二者区别是`draw-one`只会处理一个文件,而`draw`会递归处理当前目录下的所有 mtx 文件。

### 参数

1. `[--force]`: 强制替换已存在的缩略图
2. `[--log-times <n: int>]`: 对缩略图的像素值取 log 的次数
3. `[--mat-size <n: int>]`: 缩略图的尺寸
4. `[--block-size <n: int>]`: 直接设置子矩阵块的大小
5. `[--tick-step <n: int>]`: 设置 x 轴和 y 轴的刻度间隔,启用后会绘制网格线,类似下图:
   ![tick-step](./img/tick-step.svg)

   ```shell
   mtx-drawer draw --block-size 1 --tick-step 4 --force -ops real
   ```

6. `<filepath>`: mtx 文件的路径 (`draw-one`子命令中必填)
7. `<-ops <aver | abs | real | log | ... >>`: 缩略图的类型,其中`<aver>`表示平均值,`<abs>`表示绝对值,`<real>`表示实际值,`<log>`表示对数值进行对数变换

## 运行例子

```shell
mtx-drawer draw-one 2.mtx --force --log-times 0 -ops aver abs log real # 一次性绘制2.mtx的四种图,log取0次,强制替换
mtx-drawer draw-one 2.mtx  -ops aver abs log real # 一次性绘制2.mtx的四种图,log取2次,不强制替换
mtx-drawer draw --force -ops aver abs log # 绘制当前目录及子目录下的全部mtx文件的三种图,强制替换
mtx-drawer draw -ops aver abs log real # 绘制当前目录及子目录下的全部mtx文件的三种图,不强制替换且log取2次
```

### 特殊说明

子矩阵划分方式:当行列不相等时,较大的属性被分为`matSize`块,较小的属性为`rate * matSize`块;其中`rate`为$ min(m,n)/max(m,n) $

### 命令行补全

基于[QuickProject.Commmander](https://github.com/Rhythmicc/QuickProject)开发的命令行 APP 可以提供 zsh 或 [fig](https://fig.io/) 的补全脚本:

```sh
mtx-drawer complete
```

## 基于 Drawer 类的自定义开发

当默认提供的四种算法无法满足需要时,可以按如下方式自行设计算法:

```python
from MtxDrawer.Drawer import Drawer

"""
您可以通过如下方式自定义算法并通过Drawer对象的call方法来调用;
自定义算法可接受的参数将在下表中说明,此外,自定义算法必须返回一个数值用于表示color_bar的显示范围(返回1则表示-1~1)
"""

@Drawer.algorithmWrapper() # 算法装饰器
def myOwnAlgorithm(mat, extern_arg): # 参数命名要符合下表的要求,mat是下表第9项,extern_arg是下表第15项
    print(extern_arg)
    return max(abs(max([max(i) for i in mat])), abs(min([min(i) for i in mat])))


drawer = Drawer('dist/2.mtx', False, set_log-times=0, force_update=True)
drawer.call('myOwnAlgorithm', extern_arg=1)

"""
---结果---

[信息] 路径模板: "dist/2_{}.svg"
1
[信息] absVal = 1
"""
```

| 序号 | 合法参数       | 说明                                               |
| :--: | -------------- | -------------------------------------------------- |
|  1   | `has_aver`     | 是否有取平均值选项 => div 是否可用                 |
|  2   | `log-times`    | 外部设定的取 log 的次数                            |
|  3   | `mat-size`     | 矩阵行列值较大的属性被分的块数                     |
|  4   | `mtx`          | 文件的 scipy.sparse.coo\*matrix 对象,未做任何更改 |
|  5   | `coo_shape`    | mtx 的尺寸                                         |
|  6   | `coo_data`     | 矩阵的非零元值                                     |
|  7   | `coo_rows`     | 矩阵的非零元素行索引映射到 mat 的行值              |
|  8   | `coo_cols`     | 矩阵的非零元素列索引映射到 mat 的列值              |
|  9   | `mat`          | 被初始化好的二维画布对象,类型为 numpy.array       |
|  10  | `div`          | 子矩阵非零元数,只有当 has_aver 为 True 时才会有效 |
|  11  | `row_size`     | mat 的行数                                         |
|  12  | `col_size`     | mat 的列数                                         |
|  13  | `row_block_sz` | 划分的子矩阵的行数                                 |
|  14  | `col_block_sz` | 划分的子矩阵的列数                                 |
|  15  | `extern_*`     | 额外的参数命名方式,需以"extern_xx=bala"的方式调用 |

### 现代 IDE 下的提示

![IDE](./img/1.png)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Rhythmicc/DrawMtxAsThumbnail",
    "name": "MtxDrawer",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "RhythmLian",
    "author_email": "RhythmLian@outlook.com",
    "download_url": "https://files.pythonhosted.org/packages/76/35/65d2d74930a3e1b356f61030472d4bdf2513ffff47bb17374e18bb3fed90/mtxdrawer-0.0.32.tar.gz",
    "platform": null,
    "description": "# Draw Mtx As Thumbnail - \u5c06 Mtx \u753b\u4e3a\u7f29\u7565\u56fe\n\n![help](https://cos.rhythmlian.cn/ImgBed/a9cdf3bef0655d1d6e2563c40069938b.png)\n\n## \u6837\u4f8b\n\n|      ![aver](./img/ash85_aver.png)<br />\u5e73\u5747\u503c      |   ![real](./img/ash85_real.png)<br />\u4e0d\u5904\u7406    |\n| :-------------------------------------------------: | :--------------------------------------------: |\n| ![log](./img/ash85_log.png)<br /><b>\u53d6 0 \u6b21 log</b> | ![abs](./img/ash85_abs.png)<br /><b>\u7edd\u5bf9\u503c</b> |\n\n## \u5b89\u88c5\n\n```shell\npip3 install MtxDrawer -U\n```\n\n\u81ea\u52a8\u5b89\u88c5\u4f9d\u8d56\u5e76\u6ce8\u518c\u4e00\u4e2a\u547d\u4ee4`mtx-drawer`\n\n## \u5b50\u547d\u4ee4\u4e0e\u53c2\u6570\n\n\u5305\u542b\u4e24\u4e2a\u5b50\u547d\u4ee4 `draw-one` \u548c `draw`\uff0c\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u901a\u8fc7`mtx-drawer`\u547d\u4ee4\u67e5\u770b\uff0c\u4e8c\u8005\u533a\u522b\u662f`draw-one`\u53ea\u4f1a\u5904\u7406\u4e00\u4e2a\u6587\u4ef6\uff0c\u800c`draw`\u4f1a\u9012\u5f52\u5904\u7406\u5f53\u524d\u76ee\u5f55\u4e0b\u7684\u6240\u6709 mtx \u6587\u4ef6\u3002\n\n### \u53c2\u6570\n\n1. `[--force]`: \u5f3a\u5236\u66ff\u6362\u5df2\u5b58\u5728\u7684\u7f29\u7565\u56fe\n2. `[--log-times <n: int>]`: \u5bf9\u7f29\u7565\u56fe\u7684\u50cf\u7d20\u503c\u53d6 log \u7684\u6b21\u6570\n3. `[--mat-size <n: int>]`: \u7f29\u7565\u56fe\u7684\u5c3a\u5bf8\n4. `[--block-size <n: int>]`: \u76f4\u63a5\u8bbe\u7f6e\u5b50\u77e9\u9635\u5757\u7684\u5927\u5c0f\n5. `[--tick-step <n: int>]`: \u8bbe\u7f6e x \u8f74\u548c y \u8f74\u7684\u523b\u5ea6\u95f4\u9694\uff0c\u542f\u7528\u540e\u4f1a\u7ed8\u5236\u7f51\u683c\u7ebf\uff0c\u7c7b\u4f3c\u4e0b\u56fe\uff1a\n   ![tick-step](./img/tick-step.svg)\n\n   ```shell\n   mtx-drawer draw --block-size 1 --tick-step 4 --force -ops real\n   ```\n\n6. `<filepath>`: mtx \u6587\u4ef6\u7684\u8def\u5f84 (`draw-one`\u5b50\u547d\u4ee4\u4e2d\u5fc5\u586b)\n7. `<-ops <aver | abs | real | log | ... >>`: \u7f29\u7565\u56fe\u7684\u7c7b\u578b\uff0c\u5176\u4e2d`<aver>`\u8868\u793a\u5e73\u5747\u503c\uff0c`<abs>`\u8868\u793a\u7edd\u5bf9\u503c\uff0c`<real>`\u8868\u793a\u5b9e\u9645\u503c\uff0c`<log>`\u8868\u793a\u5bf9\u6570\u503c\u8fdb\u884c\u5bf9\u6570\u53d8\u6362\n\n## \u8fd0\u884c\u4f8b\u5b50\n\n```shell\nmtx-drawer draw-one 2.mtx --force --log-times 0 -ops aver abs log real # \u4e00\u6b21\u6027\u7ed8\u52362.mtx\u7684\u56db\u79cd\u56fe\uff0clog\u53d60\u6b21\uff0c\u5f3a\u5236\u66ff\u6362\nmtx-drawer draw-one 2.mtx  -ops aver abs log real # \u4e00\u6b21\u6027\u7ed8\u52362.mtx\u7684\u56db\u79cd\u56fe\uff0clog\u53d62\u6b21\uff0c\u4e0d\u5f3a\u5236\u66ff\u6362\nmtx-drawer draw --force -ops aver abs log # \u7ed8\u5236\u5f53\u524d\u76ee\u5f55\u53ca\u5b50\u76ee\u5f55\u4e0b\u7684\u5168\u90e8mtx\u6587\u4ef6\u7684\u4e09\u79cd\u56fe\uff0c\u5f3a\u5236\u66ff\u6362\nmtx-drawer draw -ops aver abs log real # \u7ed8\u5236\u5f53\u524d\u76ee\u5f55\u53ca\u5b50\u76ee\u5f55\u4e0b\u7684\u5168\u90e8mtx\u6587\u4ef6\u7684\u4e09\u79cd\u56fe\uff0c\u4e0d\u5f3a\u5236\u66ff\u6362\u4e14log\u53d62\u6b21\n```\n\n### \u7279\u6b8a\u8bf4\u660e\n\n\u5b50\u77e9\u9635\u5212\u5206\u65b9\u5f0f\uff1a\u5f53\u884c\u5217\u4e0d\u76f8\u7b49\u65f6\uff0c\u8f83\u5927\u7684\u5c5e\u6027\u88ab\u5206\u4e3a`matSize`\u5757\uff0c\u8f83\u5c0f\u7684\u5c5e\u6027\u4e3a`rate * matSize`\u5757\uff1b\u5176\u4e2d`rate`\u4e3a$ min(m,n)/max(m,n) $\n\n### \u547d\u4ee4\u884c\u8865\u5168\n\n\u57fa\u4e8e[QuickProject.Commmander](https://github.com/Rhythmicc/QuickProject)\u5f00\u53d1\u7684\u547d\u4ee4\u884c APP \u53ef\u4ee5\u63d0\u4f9b zsh \u6216 [fig](https://fig.io/) \u7684\u8865\u5168\u811a\u672c\uff1a\n\n```sh\nmtx-drawer complete\n```\n\n## \u57fa\u4e8e Drawer \u7c7b\u7684\u81ea\u5b9a\u4e49\u5f00\u53d1\n\n\u5f53\u9ed8\u8ba4\u63d0\u4f9b\u7684\u56db\u79cd\u7b97\u6cd5\u65e0\u6cd5\u6ee1\u8db3\u9700\u8981\u65f6\uff0c\u53ef\u4ee5\u6309\u5982\u4e0b\u65b9\u5f0f\u81ea\u884c\u8bbe\u8ba1\u7b97\u6cd5\uff1a\n\n```python\nfrom MtxDrawer.Drawer import Drawer\n\n\"\"\"\n\u60a8\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0b\u65b9\u5f0f\u81ea\u5b9a\u4e49\u7b97\u6cd5\u5e76\u901a\u8fc7Drawer\u5bf9\u8c61\u7684call\u65b9\u6cd5\u6765\u8c03\u7528\uff1b\n\u81ea\u5b9a\u4e49\u7b97\u6cd5\u53ef\u63a5\u53d7\u7684\u53c2\u6570\u5c06\u5728\u4e0b\u8868\u4e2d\u8bf4\u660e\uff0c\u6b64\u5916\uff0c\u81ea\u5b9a\u4e49\u7b97\u6cd5\u5fc5\u987b\u8fd4\u56de\u4e00\u4e2a\u6570\u503c\u7528\u4e8e\u8868\u793acolor_bar\u7684\u663e\u793a\u8303\u56f4\uff08\u8fd4\u56de1\u5219\u8868\u793a-1~1\uff09\n\"\"\"\n\n@Drawer.algorithmWrapper() # \u7b97\u6cd5\u88c5\u9970\u5668\ndef myOwnAlgorithm(mat, extern_arg): # \u53c2\u6570\u547d\u540d\u8981\u7b26\u5408\u4e0b\u8868\u7684\u8981\u6c42\uff0cmat\u662f\u4e0b\u8868\u7b2c9\u9879\uff0cextern_arg\u662f\u4e0b\u8868\u7b2c15\u9879\n    print(extern_arg)\n    return max(abs(max([max(i) for i in mat])), abs(min([min(i) for i in mat])))\n\n\ndrawer = Drawer('dist/2.mtx', False, set_log-times=0, force_update=True)\ndrawer.call('myOwnAlgorithm', extern_arg=1)\n\n\"\"\"\n---\u7ed3\u679c---\n\n[\u4fe1\u606f] \u8def\u5f84\u6a21\u677f: \"dist/2_{}.svg\"\n1\n[\u4fe1\u606f] absVal = 1\n\"\"\"\n```\n\n| \u5e8f\u53f7 | \u5408\u6cd5\u53c2\u6570       | \u8bf4\u660e                                               |\n| :--: | -------------- | -------------------------------------------------- |\n|  1   | `has_aver`     | \u662f\u5426\u6709\u53d6\u5e73\u5747\u503c\u9009\u9879 => div \u662f\u5426\u53ef\u7528                 |\n|  2   | `log-times`    | \u5916\u90e8\u8bbe\u5b9a\u7684\u53d6 log \u7684\u6b21\u6570                            |\n|  3   | `mat-size`     | \u77e9\u9635\u884c\u5217\u503c\u8f83\u5927\u7684\u5c5e\u6027\u88ab\u5206\u7684\u5757\u6570                     |\n|  4   | `mtx`          | \u6587\u4ef6\u7684 scipy.sparse.coo\\*matrix \u5bf9\u8c61\uff0c\u672a\u505a\u4efb\u4f55\u66f4\u6539 |\n|  5   | `coo_shape`    | mtx \u7684\u5c3a\u5bf8                                         |\n|  6   | `coo_data`     | \u77e9\u9635\u7684\u975e\u96f6\u5143\u503c                                     |\n|  7   | `coo_rows`     | \u77e9\u9635\u7684\u975e\u96f6\u5143\u7d20\u884c\u7d22\u5f15\u6620\u5c04\u5230 mat \u7684\u884c\u503c              |\n|  8   | `coo_cols`     | \u77e9\u9635\u7684\u975e\u96f6\u5143\u7d20\u5217\u7d22\u5f15\u6620\u5c04\u5230 mat \u7684\u5217\u503c              |\n|  9   | `mat`          | \u88ab\u521d\u59cb\u5316\u597d\u7684\u4e8c\u7ef4\u753b\u5e03\u5bf9\u8c61\uff0c\u7c7b\u578b\u4e3a numpy.array       |\n|  10  | `div`          | \u5b50\u77e9\u9635\u975e\u96f6\u5143\u6570\uff0c\u53ea\u6709\u5f53 has_aver \u4e3a True \u65f6\u624d\u4f1a\u6709\u6548 |\n|  11  | `row_size`     | mat \u7684\u884c\u6570                                         |\n|  12  | `col_size`     | mat \u7684\u5217\u6570                                         |\n|  13  | `row_block_sz` | \u5212\u5206\u7684\u5b50\u77e9\u9635\u7684\u884c\u6570                                 |\n|  14  | `col_block_sz` | \u5212\u5206\u7684\u5b50\u77e9\u9635\u7684\u5217\u6570                                 |\n|  15  | `extern_*`     | \u989d\u5916\u7684\u53c2\u6570\u547d\u540d\u65b9\u5f0f\uff0c\u9700\u4ee5\"extern_xx=bala\"\u7684\u65b9\u5f0f\u8c03\u7528 |\n\n### \u73b0\u4ee3 IDE \u4e0b\u7684\u63d0\u793a\n\n![IDE](./img/1.png)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Draw Mtx As Thumbnail",
    "version": "0.0.32",
    "project_urls": {
        "Homepage": "https://github.com/Rhythmicc/DrawMtxAsThumbnail"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "69604d6c39f27194027a46e450d12ccea6fa5c7aced5589bae758e0a128c9d37",
                "md5": "586ea6e84a961659db7d8ffccdd10ae3",
                "sha256": "a81f3916eaa125a0d8ba077545ddbc3b205d3dae9a9b4b5056983445f321a087"
            },
            "downloads": -1,
            "filename": "MtxDrawer-0.0.32-cp311-cp311-macosx_14_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "586ea6e84a961659db7d8ffccdd10ae3",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": null,
            "size": 40209,
            "upload_time": "2024-11-03T09:35:59",
            "upload_time_iso_8601": "2024-11-03T09:35:59.512254Z",
            "url": "https://files.pythonhosted.org/packages/69/60/4d6c39f27194027a46e450d12ccea6fa5c7aced5589bae758e0a128c9d37/MtxDrawer-0.0.32-cp311-cp311-macosx_14_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "763565d2d74930a3e1b356f61030472d4bdf2513ffff47bb17374e18bb3fed90",
                "md5": "867e9bd9b2bd6a3fd908a9438a34f596",
                "sha256": "a5fa262ae57aa07964b6ef15df1dbca10c8f48f0e427b0b2c99b038a14a14804"
            },
            "downloads": -1,
            "filename": "mtxdrawer-0.0.32.tar.gz",
            "has_sig": false,
            "md5_digest": "867e9bd9b2bd6a3fd908a9438a34f596",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 80820,
            "upload_time": "2024-11-03T09:36:01",
            "upload_time_iso_8601": "2024-11-03T09:36:01.180747Z",
            "url": "https://files.pythonhosted.org/packages/76/35/65d2d74930a3e1b356f61030472d4bdf2513ffff47bb17374e18bb3fed90/mtxdrawer-0.0.32.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-03 09:36:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Rhythmicc",
    "github_project": "DrawMtxAsThumbnail",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "mtxdrawer"
}
        
Elapsed time: 0.34142s