Python - jupyter

若不存在文件夹则创建对应文件夹

1
2
3
4
5
import os
path = waveletG
err = 0.1
if not os.path.exists('./{}/wavenumber{}'.format(path[0:-1],err)):
os.makedirs('./{}/wavenumber{}'.format(path,err))

循环内定义文件名称

1
filename ='{}/{}'.format(path,file)

按列读取文件数据

1
2
3
4
5
6
7
8
X0,X1= [],[]
with open(filename, 'r',) as f:
next(f) #跳过第一行
lines = f.readlines()
for line in lines:
value = [float(s) for s in line.split()]
X0.append(value[0]) # 第一列
X1.append(value[1]) # 第二列

输出到txt文件的列间距控制

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
filename = 'N=3-R_10={:3.2f}mm-R_20={:3.2f}mm-{:4.1f}MPa.txt'.format(R_10*1e3,R_20*1e3,pin0/1e6)

#标题
with open(filename, 'w') as f:#创建空白文档
Tittle = 'T(ms)','R_1(mm)','U_1(m/s)','DU_1(m/s^2)'
print("{:<10}{:<10}{:<10}{:<16}".format(*Tittle), file=f)#居左
f.close()
#数据
with open(filename, 'a') as f:#写入
if i % 1000 == 0:
print("{:<9.3f}".format(t*1e3),
"{:<9.3f}".format(R_1*1e3),
"{:<9.3f}".format(U_1),
"{:<15.3f}".format(DU_1),
file=f)
f.close()

注意到标题为str,写入位数要比数据多一位。

保存多列数据为txt文档

1
np.savetxt('array.txt', np.column_stack((a,b)), fmt='%f')

图片加时间戳水印

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
55
56
from PIL import Image, ImageDraw, ImageFont
import os

# ========== 配置区域 ==========
input_folder = "./imagess" # 原始图像文件夹
output_folder = "./output" # 输出图像文件夹
os.makedirs(output_folder, exist_ok=True)

# 水印字体设置(如果不需要中文,可以使用 ImageFont.load_default())
font = ImageFont.truetype("simhei.ttf", 32)
font_size = 24 # 字体大小占图像宽度的比例(例如 0.05 表示宽度的5%)
text_margin_bottom = 20 # 水印距离底边的像素距离
text_color = (255, 255, 255) # 白色

# 水印内容生成函数:根据实际需求修改
def get_watermark_text(image_path):
"""
根据图像文件路径生成水印文本。
这里示例:假设文件名形如 "myphoto059.jpg",提取数字并加上 " us"。
如果无法提取,返回空字符串或默认文本。
"""
filename = os.path.basename(image_path)
# 假设文件名中只有一段数字,我们提取第一个数字
import re
numbers = re.findall(r'\d+', filename)
if numbers:
# 取第一个数字,拼接 " us"
return f"{((int(numbers[0])-59)*4):03d} us"
else:
# 若未找到数字,返回默认文本,您也可以返回 None 跳过该图
return "unknown us"

# ========== 批量处理 ==========
for filename in os.listdir("images"):
# 只处理图片格式文件(png, jpg, jpeg)
if filename.lower().endswith((".png", ".jpg", ".jpeg")):
# 打开图片并转换为RGBA模式(支持透明度)
# img = Image.open(f"images/{filename}").convert("RGBA")
img = Image.open(f"images/{filename}")
draw = ImageDraw.Draw(img) # 创建绘图对象
watermark_text = get_watermark_text(f"images/{filename}")
# 计算水印文字的边界框尺寸
bbox = draw.textbbox((0, 0),watermark_text , font=font)
text_width = bbox[2] - bbox[0] # 文字宽度
text_height = bbox[3] - bbox[1] # 文字高度
# 计算水印位置
#position = (img.width - text_width - 10, img.height - text_height - 10)# 右下角,留10像素边距
position = (img.width/2-text_width/2,img.height - text_height - 10)
# 添加水印文字(白色,220透明度)
#draw.rectangle([position[0] - 5, position[1], position[0] + text_width + 5, position[1] + text_height + 5],fill=(0, 0, 0, 128))
#draw.text(position, watermark_text, font=font, fill=(255, 255, 255,220))
draw.text(position, watermark_text, font=font, fill="white")
# 转换为RGB模式并保存到output目录
img.save(f"output/{filename}")
# img.convert("RGB").save(f"output/{filename}")
print("水印添加完成!") # 完成提示

Latex

latexdiff

  1. 准备文件:

旧文件:old.tex old.bib

新文件:new.tex new.bib

  1. 编译文档
1
2
3
4
5
pdflatex -output-directory=build -interaction=nonstopmode old.tex
pdflatex -output-directory=build -interaction=nonstopmode new.tex

biber --output-directory=build --input-directory=build old.bcf
biber --output-directory=build --input-directory=build new.bcf

3.

1
latexdiff --append-textcmd="field,name" ./build/old.bbl ./build/new.bbl > ./build/diff.bbl

latexdiff处理参考文献的差异。

上面我试了一下,出不来。

只能用笨办法一个一个标记了,但是也有稍微能加速的。

不想写了,有需要的联系我吧。


latexdiff apssamp-V0.tex apssamp.tex > diff1.tex

latexdiff Manuscript-old.tex Manuscript-new.tex > diff.tex

Bash

批量删除OpenFOAMprocessor*内的时间步

1
for i in {0..127}; do for val in $(seq 0 0.01 2.11); do rm -rf "processor$i/${val}e-06"; done; echo "processor$i done"; done

OpenFOAM

画网格是重中之重

  • 完整矩形网格
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2212 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object blockMeshDict;
}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

//
scale 0.001;

// 立方体参数
xMin -1;
xMax 1;
yMin -1;
yMax 1;
zMin -1;
zMax 1;

//
nx 100;
ny 100;
nz 100;

vertices
(
// 底面 (zMin)
($xMin $yMin $zMin) // 0
($xMax $yMin $zMin) // 1
($xMax $yMax $zMin) // 2
($xMin $yMax $zMin) // 3

// 顶面 (zMax)
($xMin $yMin $zMax) // 4
($xMax $yMin $zMax) // 5
($xMax $yMax $zMax) // 6
($xMin $yMax $zMax) // 7
);

blocks
(
hex (0 1 2 3 4 5 6 7) ($nx $ny $nz) simpleGrading (1 1 1)
);

edges
(
);

boundary
(
// x 方向
left
{
type patch;
faces
(
(0 4 7 3) // x = xMin
);
}

right
{
type patch;
faces
(
(1 2 6 5) // x = xMax
);
}

// y 方向
front
{
type patch;
faces
(
(0 1 5 4) // y = yMin
);
}

back
{
type patch;
faces
(
(3 7 6 2) // y = yMax
);
}

// z 方向
bottom
{
type patch;
faces
(
(0 3 2 1) // z = zMin
);
}

top
{
type patch;
faces
(
(4 5 6 7) // z = zMax
);
}
);

mergePatchPairs
(
);

// ************************************************************************* //
  • 八分之一网格
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2212 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object blockMeshDict;
}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

scale 0.001;

min 0;
delta 2; //
num 200; //

vertices
(
($min $min $min)
(#eval "($min+$delta)" $min $min)
(#eval "($min+$delta)" #eval "($min+$delta)" $min)
($min #eval "($min+$delta)" $min)
($min $min #eval "($min+$delta)")
(#eval "($min+$delta)" $min #eval "($min+$delta)")
(#eval "($min+$delta)" #eval "($min+$delta)" #eval "($min+$delta)")
($min #eval "($min+$delta)" #eval "($min+$delta)")
);

blocks
(
hex (0 1 2 3 4 5 6 7) ($num $num $num) simpleGrading (1 1 1)
);

edges
(
);

boundary
(

upSide
{
type patch;
faces
(
(4 5 6 7) //上黄
);
}

downSide
{
type symmetry;
faces
(
(0 3 2 1) //下白
);
}

frontSide
{
type symmetry;
faces
(
(1 5 4 0) //前蓝
);
}

BackSide
{
type patch;
faces
(
(3 7 6 2) //后绿
);
}

leftSide
{
type symmetry;
faces
(
(0 4 7 3) //左橙
);
}

rightSide
{
type patch;
faces
(
(2 6 5 1) //右红

);
}
);

mergePatchPairs
(
);


// ************************************************************************* //

Linux

linux挂载命令:

1
sudo mount -t drvfs F: /mnt/f