word 不能直接导入 eps 格式的图片,所以先将 eps 图片转换成 png 格式。

这里使用 python 调用 PIL 读取 eps 图片,直接保存为 png 图片

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

# pip install pillow
# scoop install ghostscript

from PIL import Image

import os

for parent, dirnames, filenames in os.walk(os.getcwd()):
for filename in filenames:
ext = os.path.splitext(filename)[1]
if ext != '.eps':
continue

eps_image = Image.open(filename)
size = eps_image.size
print(filename, size)

eps_image.load(scale=10) # 分辨率增大到10倍
eps_image.save(filename+'.png', quality=100)
  • PIL 默认采用 Ghostscript 处理 eps 图片, 所以先确保安装了 Ghostscript。 scoop install ghostscript
  • eps 为矢量图,默认情况下其尺寸较小,导致保存成图片式分辨率较低,eps_image.load(scale=10) 将分辨率增大到10倍后保存。

下载 bili 视频

1
2
3
4
5
6
7
pip install you-get
# you-get https://www.bilibili.com/video/BV1234567890

pip install yt-dlp
# yt-dlp https://www.bilibili.com/video/BV1234567890

# yt-dlp "https://www.youtube.com/watch?v=GGGGGGGGGGGG" --proxy http://127.0.0.1:7890

视频转音频

1
2
3
4
5
6
scoop install ffmpeg
ffmpeg -i xxx.mp4
# checkout the audio video format
ffmpeg -i xxx.mp4 -acodec copy xxx.aac
ffmpeg -i xxx.mp4 -acodec copy xxx.mp3
ffmpeg -i xxx.mkv -acodec copy xxx.opus

音频转文字 📘

https://github.com/openai/whisper

  1. ** whisper **:
1
2
3
4
pip install -U openai-whisper

whisper audio.flac audio.mp3 audio.wav --model small --device cpu --language zh

  1. ** python **:
    使用 Python 运行 main.py 脚本。
1
2
3
4
5
6
import whisper

model = whisper.load_model("small", device="cpu")
result = model.transcribe(f"123.mp3")

print(result["text"]))

numpy: 线性插值、 对数插值

scipy: 样条插值 interp1d 等

https://docs.scipy.org/doc/scipy/reference/interpolate.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# %%
import numpy as np
from numpy import log, exp, interp
import matplotlib.pyplot as plt

from scipy.interpolate import interp1d as sciInter
from scipy.interpolate import Akima1DInterpolator as sciAkima
from scipy.interpolate import PchipInterpolator as sciPchip
from scipy.interpolate import CubicSpline as sciCubic

import pandas as pd
from rich.pretty import pprint

pd.set_option("display.width", 1000)
pd.set_option("display.max_rows", 500)
pd.set_option("display.max_columns", 500)

# %%
df = pd.read_csv("datas.csv")
pprint(df)
阅读全文 »

cat-catch 设置 N_m3u8DL-RE

ref https://github.com/nilaoda/N_m3u8DL-RE
ref https://github.com/xifangczy/cat-catch
ref https://github.com/corbamico/m3u8dl-invoke/

1.1 电脑安装 n-m3u8dl-re 软件

1
scoop install n-m3u8dl-re_x

1.2 Edge 浏览器安装 cat-catch 插件

设置 - N_m3u8DL-RE 的参数:

1
"${url}" --save-dir "%USERPROFILE%\Downloads\m3u8dl" --save-name "${title}_${now}" ${referer|exists:'-H "Referer:*"'} --del-after-done --no-log

1.3 添加 m3u8dl协议

  • 使用 https://github.com/xifangczy/URLProtocol 工具。
  • 下载URLProtocol和N_m3u8DL-RE 并放置在一起。
  • 打开URLProtocol工具,协议名填写 m3u8dl 点击选择目标程序按钮,选择N_m3u8DL-RE.exe 点击添加。

1.4 添加 m3u8dl协议(另一种方法)

阅读全文 »

matplotlib marker color 字符对照

ref: https://matplotlib.org/stable/api/colors_api.html
ref: https://matplotlib.org/stable/gallery/color/named_colors.html

1
2
3
4
5
6
7
8
9
10
11

import matplotlib.pyplot as plt
import matplotlib.colors as mcolors

for (k, v) in mcolors.BASE_COLORS.items():
v = "#" + "".join(format(round(val * 255), "02x") for val in v)
print(f'<font color="{v}"> {k:<10} ■ </font>')

for (k, v) in mcolors.TABLEAU_COLORS.items():
print(f'<font color="{v}"> {k:<10} ■ </font>')

mcolors.BASE_COLORS (8)

████ b
████ g
████ r
████ c
████ m
████ y
████ k
████ w

mcolors.TABLEAU_COLORS (10)

████ tab:blue
████ tab:orange
████ tab:green
████ tab:red
████ tab:purple
████ tab:brown
████ tab:pink
████ tab:gray
████ tab:olive
████ tab:cyan

阅读全文 »

文件夹禁用文件类型识别

文件夹启动时默认会识别该文件夹内的文件类型(比如图片、音乐、视频等媒体文件的信息),媒体文件过多时加载速度较慢。

可以禁用此功能。

1
2
3
4
5
6
# 管理员运行运行后重启:
reg add "HKCU\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags\AllFolders\Shell" /v "FolderType" /t REG_SZ /d "NotSpecified" /f

# 恢复默认:
# reg.exe delete "HKCU\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags\AllFolders\Shell" /f

Python f-string 备忘单

ref https://fstring.help/cheat/

ref https://cheatography.com/brianallan/cheat-sheets/python-f-strings-basics/
ref https://cheatography.com/brianallan/cheat-sheets/python-f-strings-number-formatting/

数字

num format
%d 整数
%e 科学计数
%f 浮点
% 百分数
%b 二进制
%o 八进制
%x 十六进制
%c Unicode

integer = 123
number_ = 9876.6789
percent = 0.98765

var num format f-string output
integer 123 d f’{integer:d}’ 123
integer 123 b f’{integer:b}’ 1111011
integer 123 8b f’{integer:8b}’ 1111011
integer 123 _b f’{integer:_b}’ 111_1011
integer 123 09_b f’{integer:09_b}’ 0111_1011
integer 123 o f’{integer:o}’ 173
integer 123 #o f’{integer:#o}’ 0o173
integer 123 x f’{integer:x}’ 7b
integer 123 #x f’{integer:#x}’ 0x7b
integer 123 08x f’{integer:08x}’ 0000007b
integer 123 c f’{integer:c}’ {
number_ 9876.6789 f f’{number_:f}’ 9876.678900
number_ 9876.6789 .2f f’{number_:.2f}’ 9876.68
number_ 9876.6789 09.2f f’{number_:09.2f}’ 009876.68
number_ 9876.6789 09.5f f’{number_:09.5f}’ 9876.67890
number_ 9876.6789 .2f f’{number_:.2f}’ 9876.68
percent 0.98765 % f’{percent:%}’ 98.765000%
percent 0.98765 9.5% f’{percent:9.5%}’ 98.76500%
percent 0.98765 09.4% f’{percent:09.4%}’ 098.7650%
percent 0.98765 09.5% f’{percent:09.5%}’ 98.76500%
number_ 9876.6789 .2e f’{number_:.2e}’ 9.88e+03
number_ 9876.6789 09.2e f’{number_:09.2e}’ 09.88e+03

string = “Python”

var num format f-string output
string Python 20 f’{string:20}’ Python
string Python >20 f’{string:>20}’ Python
string Python <20 f’{string:<20}’ Python
string Python ^20 f’{string:^20}’ Python
string Python >>20 f’{string:>>20}’ >>>>>>>>>>>>>>Python
string Python <<20 f’{string:<<20}’ Python<<<<<<<<<<<<<<
string Python ^^20 f’{string:^^20}’ ^^^^^^^Python^^^^^^^
string Python =^20 f’{string:=^20}’ =======Python=======
阅读全文 »

radioactivedecay 用于放射性核素衰变的简单分析计算的开源包,支持放射性核素、亚稳态和分支衰变的衰变链。

https://github.com/radioactivedecay/radioactivedecay

安装:pip install radioactivedecay

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# %%
# ============ (2) ==================
import radioactivedecay as rd
import matplotlib.pyplot as plt
# 创建一组放射性源项:Inventory
inv = rd.Inventory({'U-235': 1}, 'Ci')

inv_t1 = inv.decay(50, 'd')
print(inv_t1.activities('Bq'))

# 绘图
inv.plot(50, 'd')
inv.plot(50, 'd', order='alphabetical')

# %%
import radioactivedecay as rd
import matplotlib.pyplot as plt

from cycler import cycler

plt.rcParams["font.family"] = "monospace"
cm = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf']
ls = ['-', '--']
mk = ['+', 'x', '*', '^', 's']
me = [31, 71, 91, 113, 161]
cc = (cycler(color=cm) + cycler(linestyle=ls) * (cycler(marker=mk))) + cycler(markevery=me) * 2

DICT = {'U-235': 1e9,
'Rn-222': 1e9}

TIME = iter([10, 1])

for (hesu, huodu) in DICT.items():
t1 = next(TIME)
inv = rd.Inventory({hesu: huodu}, 'Bq')
inv_t1 = inv.decay(t1, 'd')
act_t1 = inv_t1.activities('Bq')

fig_name = f'{hesu} @ {huodu:0.2e} Bq'
fig_note = f'the Activity after {t1} days of Decay:\n'
fig_note += '\n'.join(f'- {k} {v:.2e} Bq' for (k, v) in act_t1.items())
print(fig_name, '\n' ,fig_note)

fig0 = plt.figure(figsize=(9, 9))
plt.gca().set_prop_cycle(cc)

fig, ax = inv.plot(t1, 'd', yscale='log', ymin=1e-8, order='alphabetical', fig=fig0)
plt.title(fig_name)
plt.text(0.3, 0.1, fig_note, transform=ax.transAxes)
plt.grid(True, linestyle=':', color='gray', alpha=0.5)

plt.show()
fig.savefig(f'decay_activity_{hesu}.png', dpi=300)

阅读全文 »

radioactivedecay 用于放射性核素衰变的简单分析计算的开源包,支持放射性核素、亚稳态和分支衰变的衰变链。

https://github.com/radioactivedecay/radioactivedecay

安装:pip install radioactivedecay

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#%%
import radioactivedecay as rd
import matplotlib.pyplot as plt

# 创建一个放射性核素: Nuclide
ncld = rd.Nuclide('U-235')
half = ncld.half_life('readable') # 半衰期
prog = ncld.progeny() # 衰变产物
frac = ncld.branching_fractions() # 占比
mode = ncld.decay_modes() # 衰变射线类型

print(ncld, mode, prog, frac, half, sep='\n')

# 绘制衰变链
ncld.plot()

#%%
# 列出多个核算衰变类型
NUCs = ['U-235',
'Pu-239']

for name in NUCs:
ncld = rd.Nuclide(name)
half = ncld.half_life('readable')
prog = ncld.progeny()
frac = ncld.branching_fractions()
mode = ncld.decay_modes()
print(ncld, mode, prog, frac, half, sep='\n')

fig, ax = ncld.plot()
fig.savefig(f'decay_chains_{name}.png', dpi=300)

阅读全文 »

pandas 合并数据常用的两个函数:

刚好有一个对比 RNN 和 LSTM 神经网络运行结果的场景分别用到了这两个函数:

  • 采用 concat 合并两个csv表; csv表为两次运行结果的,列名基本一致。
  • 采用 merge 合并模型运行条件类似的表, 用于对比数据
阅读全文 »

一、WSL 安装 Ubuntu22.04

  1. 启用 WSL

  2. 打开 Microsoft Store,安装 Ubuntu22.04

  3. 设置源,更新
    ref: https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

更新:sudo apt update

升级:sudo apt upgrade

  1. 安装 ZSH、oh-my-zsh

参考 zsh & oh-my-zsh 安装配置

二、安装 openmc with conda

ref: https://docs.openmc.org/en/stable/quickinstall.html

  1. 参照 Installing on Linux/Mac with Conda,安装 openmc。
1
2
3
4
5
6
7
8
9
10
11
12
# https://www.anaconda.com/docs/getting-started/miniconda/install#linux
# 安装 miniconda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash ~/Miniconda3-latest-Linux-x86_64.sh

# 安装 openmc
conda config --add channels conda-forge
conda config --set channel_priority strict

conda create --name openmc-env openmc
conda activate openmc-env

安装完成后,运行 openmc 试一下, 提示错误: 找不到材料数据卡 cross_sections.xml

  1. 下载材料数据集
1
2
3
4
git clone https://github.com/openmc-dev/data openmc-dev_data

cd openmc-dev_data
python3 convert_nndc71.py
阅读全文 »

ref: https://github.com/ScoopInstaller/Scoop/issues/4390

0. 问题: scoop 本身不支持安装包有解压密码的自动解压。

scoop 本身不支持安装包有解压密码的自动解压。因此在安装 MAS 时会卡在解压处,无法继续安装。

1. 7z 命令手册

7z 命令是支持的: 7z x FILENAME.7z -pPWD -oOUTDIR

2. 查 Scoop 源码的解压函数

找到 Scoop 源码里的 “~\scoop\apps\scoop\current\lib\decompress.ps1” 文件。
文件封装了 Expand-7zipArchive 函数命令, 但参数没有能将密码传入的方法。

3. 试 Scoop 的 pre_install

Scoop Wiki 里提到了 pre_install 等说法。

在 MAS.json 中加入:

1
"pre_install": "7z x $dir\\$fname -p1234 $('-o' + $dir)"

尝试了很多次还是不起作用,Scoop的策略是遇到压缩包先执行解压、再做后续的事情。所以这一句不会被执行,安装程序依旧卡在解压处,无法继续安装。

阅读全文 »

1. 客户端 VSCode 安装 Remote 插件

安装插件, 略

添加远程连接 aaa@192.168.1.xxx, 连接、等待, 输入密码

2. 连接时可能连不上,并出现警告

警告: The remote host may not meet VS Code Server's prerequisitesfor glibc and libstdc++

阅读全文 »

从在线日历获取事件

Outlook 查看日历链接: 设置-日历-共享日历-发布日历,可以看到如下链接:

https://outlook.live.com/owa/calendar/d82e6afe-XXXX-XXXX/cid-YYYY/calendar.ics

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from ics import Calendar
import requests

# Parse the URL
url = "https://outlook.live.com/owa/calendar/d82e6afe--XXXX-XXXX/cid-YYYY/calendar.ics"
cal = Calendar(requests.get(url).text)


#%%
# Print all the events
events = sorted(cal.events)
for event in events:
print(event.begin , event.name )

#%%
timeline = cal.timeline
for tl in timeline:
print(tl.begin , tl.name )

# %%
# 获取今天及之后的事件
from ics import Calendar
import requests
import arrow

cal = Calendar(requests.get(url).text)

today = arrow.now()
print(today)
today = arrow.now().replace(hour=0, minute=0, second=0, microsecond=0)
print(today)
today = arrow.now().span('day')[0]
print(today)

evts = cal.timeline.start_after(today)

for evt in evts:
print(evt.begin.strftime("%Y-%m-%d %a %H:%M"), evt.name )

ref: (https://github.com/ScoopInstaller/Scoop/wiki/App-Manifests)

尝试自己制作一个安装配置文件, 软件是 N_m3u8DL-RE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{
"version": "v0.2.0-beta",
"description": "Cross-Platform, modern and powerful stream downloader for MPD/M3U8/ISM",
"homepage": "https://github.com/nilaoda/N_m3u8DL-RE",
"license": "MIT",
"suggest": {
"ffmpeg": [
"ffmpeg",
"ffmpeg-nightly"
]
},
"url": "https://github.com/nilaoda/N_m3u8DL-RE/releases/download/v0.2.0-beta/N_m3u8DL-RE_Beta_win-x64_20230628.zip",
"hash": "9e3133f03e112cc57f34bf04234b7857ae7c997c214f0eb510a120739c388652",
"bin": [
"N_m3u8DL-RE_Beta_win-x64/N_m3u8DL-RE.exe",
[
"N_m3u8DL-RE.exe",
"N_m3u8DL_RE"
]
],
"checkver": {
"url": "https://api.github.com/repos/nilaoda/N_m3u8DL-RE/releases",
"regex": "releases/download/(?<tag>[vV]?[\\w-.]+)/N_m3u8DL-RE_Beta_win-x64_(?<date>[\\d.-]+).zip",
"replace": "${tag}"
},
"autoupdate": {
"url": "https://github.com/nilaoda/N_m3u8DL-RE/releases/download/$matchTag/N_m3u8DL-RE_Beta_win-x64_$matchDate.zip"
}
}

阅读全文 »