ararpy 0.1.199__py3-none-any.whl → 0.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ararpy/Example - Check arr.py +52 -0
- ararpy/Example - Granite Cooling History.py +411 -0
- ararpy/Example - Plot temperature calibration.py +291 -0
- ararpy/Example - Show MDD results.py +561 -0
- ararpy/Example - Show all Kfs age spectra.py +344 -0
- ararpy/Example - Show random walk results.py +363 -0
- ararpy/Example - Tc calculation.py +437 -0
- ararpy/__init__.py +3 -4
- ararpy/calc/age.py +34 -36
- ararpy/calc/arr.py +0 -20
- ararpy/calc/basic.py +26 -3
- ararpy/calc/corr.py +131 -85
- ararpy/calc/plot.py +1 -2
- ararpy/calc/raw_funcs.py +41 -2
- ararpy/calc/regression.py +224 -132
- ararpy/files/arr_file.py +2 -1
- ararpy/files/basic.py +0 -22
- ararpy/files/calc_file.py +107 -84
- ararpy/files/raw_file.py +242 -229
- ararpy/smp/basic.py +133 -34
- ararpy/smp/calculation.py +6 -6
- ararpy/smp/corr.py +339 -153
- ararpy/smp/diffusion_funcs.py +345 -36
- ararpy/smp/export.py +247 -129
- ararpy/smp/info.py +2 -2
- ararpy/smp/initial.py +93 -45
- ararpy/smp/json.py +2 -2
- ararpy/smp/plots.py +144 -164
- ararpy/smp/raw.py +11 -15
- ararpy/smp/sample.py +222 -181
- ararpy/smp/style.py +26 -7
- ararpy/smp/table.py +42 -33
- ararpy/thermo/atomic_level_random_walk.py +56 -48
- ararpy/thermo/basic.py +2 -2
- {ararpy-0.1.199.dist-info → ararpy-0.2.1.dist-info}/METADATA +1 -1
- ararpy-0.2.1.dist-info/RECORD +73 -0
- {ararpy-0.1.199.dist-info → ararpy-0.2.1.dist-info}/WHEEL +1 -1
- ararpy-0.1.199.dist-info/RECORD +0 -66
- {ararpy-0.1.199.dist-info → ararpy-0.2.1.dist-info}/licenses/LICENSE +0 -0
- {ararpy-0.1.199.dist-info → ararpy-0.2.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
# Copyright (C) 2025 Yang. - All Rights Reserved
|
|
2
|
+
|
|
3
|
+
#!/usr/bin/env python
|
|
4
|
+
# -*- coding: UTF-8 -*-
|
|
5
|
+
"""
|
|
6
|
+
# ==========================================
|
|
7
|
+
# Copyright 2025 Yang
|
|
8
|
+
# ararpy - Example - Plot temperature calibration
|
|
9
|
+
# ==========================================
|
|
10
|
+
#
|
|
11
|
+
#
|
|
12
|
+
#
|
|
13
|
+
"""
|
|
14
|
+
import datetime
|
|
15
|
+
import os
|
|
16
|
+
import re
|
|
17
|
+
import pytz
|
|
18
|
+
|
|
19
|
+
import numpy as np
|
|
20
|
+
import ararpy as ap
|
|
21
|
+
import pdf_maker as pm
|
|
22
|
+
import matplotlib
|
|
23
|
+
from matplotlib import cm
|
|
24
|
+
from matplotlib.collections import PathCollection
|
|
25
|
+
|
|
26
|
+
matplotlib.use('TkAgg')
|
|
27
|
+
matplotlib.rc('font',family='Arial', size=10)
|
|
28
|
+
import matplotlib.pyplot as plt
|
|
29
|
+
import matplotlib.dates as mdates
|
|
30
|
+
from matplotlib.patches import Rectangle
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def transform(ax: plt.Axes):
|
|
34
|
+
xlabels = [i.get_text().replace('−', '-') for i in ax.get_xticklabels()]
|
|
35
|
+
ylabels = [i.get_text().replace('−', '-') for i in ax.get_yticklabels()]
|
|
36
|
+
linestyles = {'-': 'solid', '--': 'dashed', '-.': 'dashdot', ':': 'dotted'}
|
|
37
|
+
|
|
38
|
+
series = []
|
|
39
|
+
for i, line in enumerate(ax.lines):
|
|
40
|
+
xy_data = line.get_xydata() # [[x1, y1], [x2, y2], ...]
|
|
41
|
+
line_style = linestyles.get(line.get_linestyle(), 'solid')
|
|
42
|
+
series.append({
|
|
43
|
+
'type': 'series.line', 'id': f'line-{i}', 'name': f'line-{i}',
|
|
44
|
+
'color': line.get_color(), 'line_width': 1, 'line_style': line_style,
|
|
45
|
+
'data': xy_data, 'line_caps': 'none'
|
|
46
|
+
})
|
|
47
|
+
if bool(line._marker):
|
|
48
|
+
series.append({
|
|
49
|
+
'type': 'series.scatter', 'id': f'line-marker-{i}', 'name': f'line-marker-{i}',
|
|
50
|
+
'stroke_color': line.get_markeredgecolor(), 'fill_color': line.get_markerfacecolor(),
|
|
51
|
+
'data': xy_data, 'size': 2,
|
|
52
|
+
# 'symbol': line._marker.markers.get(line.get_marker(), 'square'),
|
|
53
|
+
'symbol': 'rec'
|
|
54
|
+
})
|
|
55
|
+
for i, collection in enumerate(ax.collections):
|
|
56
|
+
series.append({
|
|
57
|
+
'type': 'series.scatter', 'id': f'scatter-{i}', 'name': f'{collection.get_label()}',
|
|
58
|
+
'stroke_color': collection.get_edgecolor()[0][:3], 'fill_color': collection.get_edgecolor()[0][:3],
|
|
59
|
+
'data': collection.get_offsets(), 'size': 2,
|
|
60
|
+
'symbol': 'rec'
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
for i, text in enumerate(ax.texts):
|
|
64
|
+
xy_data = text.get_position() # [[x1, y1], [x2, y2], ...]
|
|
65
|
+
series.append({
|
|
66
|
+
'type': 'series.text', 'id': f'text-{i}', 'name': f'text-{i}',
|
|
67
|
+
'color': text.get_color(), 'data': [xy_data], 'text': text.get_text().replace('\n', '<r>'),
|
|
68
|
+
'size': 8
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
for child in ax._children:
|
|
72
|
+
if isinstance(child, Rectangle):
|
|
73
|
+
ld = [*child.get_xy(), child.get_width(), child.get_height()]
|
|
74
|
+
series.append({
|
|
75
|
+
'type': 'series.rect', 'id': f'rect-{child.get_gid()}', 'name': f'rect-{child.get_gid()}',
|
|
76
|
+
'color': child.get_edgecolor()[:3], 'fill_color': child.get_facecolor()[:3], 'fill': True,
|
|
77
|
+
'data': [ld], 'label': child.get_label(), 'clip': True
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
series.append({
|
|
81
|
+
'type': 'series.text', 'id': f'title', 'name': f'title',
|
|
82
|
+
'color': 'black', 'data': [[sum(ax.get_xlim()) / 2, ax.get_ylim()[1]]],
|
|
83
|
+
'h_align': "middle", 'v_align': "top",
|
|
84
|
+
'text': ax.get_title(), 'size': 8
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
if ax.legend_ is not None:
|
|
88
|
+
for handle, text in zip(ax.legend_.legend_handles, ax.legend_.texts):
|
|
89
|
+
series.append({
|
|
90
|
+
'type': 'series.text', 'id': f'legend', 'name': f'legend',
|
|
91
|
+
'color': text.get_color(), 'data': [[ax.get_xlim()[0], ax.get_ylim()[0]]],
|
|
92
|
+
'h_align': "left", 'v_align': "bottom",
|
|
93
|
+
'text': text.get_text(), 'size': 8
|
|
94
|
+
})
|
|
95
|
+
if isinstance(handle, plt.Line2D):
|
|
96
|
+
series.append({
|
|
97
|
+
'type': 'series.line', 'id': f'legend-line', 'name': f'legend-line-{text.get_text()}',
|
|
98
|
+
'color': handle.get_color(), 'data':[[ax.get_xlim()[0], ax.get_ylim()[0]], [ax.get_xlim()[1], ax.get_ylim()[1]]],
|
|
99
|
+
'line_width': 1, 'line_style': linestyles.get(handle.get_linestyle(), 'solid')
|
|
100
|
+
})
|
|
101
|
+
if isinstance(handle, PathCollection):
|
|
102
|
+
stroke_c = handle.get_edgecolor()[0][:3]
|
|
103
|
+
stroke_c = f"#{int(stroke_c[0]*255):02x}{int(stroke_c[1]*255):02x}{int(stroke_c[2]*255):02x}"
|
|
104
|
+
fill_c = handle.get_facecolor()[0][:3]
|
|
105
|
+
fill_c = f"#{int(fill_c[0]*255):02x}{int(fill_c[1]*255):02x}{int(fill_c[2]*255):02x}"
|
|
106
|
+
series.append({
|
|
107
|
+
'type': 'series.scatter', 'id': f'legend-scatter', 'name': f'legend-scatter-{text.get_text()}',
|
|
108
|
+
'stroke_color': stroke_c, 'fill_color': fill_c,
|
|
109
|
+
'data': [[sum(ax.get_xlim()) / 2, sum(ax.get_ylim()) / 2]],
|
|
110
|
+
'size': 2, 'symbol': 'rec'
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
data = {
|
|
114
|
+
'xAxis': [{
|
|
115
|
+
'extent': ax.get_xlim(), 'interval': xlabels, 'title': ax.get_xlabel(),
|
|
116
|
+
'nameLocation': 'middle', 'show_frame': True, 'label_size': 8, 'title_size': 8,
|
|
117
|
+
}],
|
|
118
|
+
'yAxis': [{
|
|
119
|
+
'extent': ax.get_ylim(), 'interval': ylabels, 'title': ax.get_ylabel(),
|
|
120
|
+
'nameLocation': 'middle', 'show_frame': True, 'label_size': 8, 'title_size': 8,
|
|
121
|
+
}],
|
|
122
|
+
'series': series
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
# print(data)
|
|
126
|
+
return data
|
|
127
|
+
|
|
128
|
+
def read_libano(file_path):
|
|
129
|
+
res = []
|
|
130
|
+
|
|
131
|
+
if os.path.isdir(file_path):
|
|
132
|
+
for root, dirs, files in os.walk(file_path):
|
|
133
|
+
for file in files:
|
|
134
|
+
if "libano" in file:
|
|
135
|
+
file_path = os.path.join(file_path, file)
|
|
136
|
+
break
|
|
137
|
+
print(f"{file_path = }")
|
|
138
|
+
if os.path.exists(file_path):
|
|
139
|
+
for line in open(file_path, "r"):
|
|
140
|
+
temp = re.findall(r"Z;\d+;\d+", line)
|
|
141
|
+
setpoint, reading = re.findall(r"\d+", temp[0])
|
|
142
|
+
dt_object = datetime.datetime.strptime(
|
|
143
|
+
re.findall(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z", line)[0],
|
|
144
|
+
"%Y-%m-%dT%H:%M:%SZ")
|
|
145
|
+
|
|
146
|
+
timezone = pytz.utc
|
|
147
|
+
dt_object = timezone.localize(dt_object)
|
|
148
|
+
|
|
149
|
+
res.append([dt_object, int(setpoint), int(reading)])
|
|
150
|
+
# res[int(dt_object.timestamp())] = {
|
|
151
|
+
# "set": int(setpoint), "read": int(reading)
|
|
152
|
+
# }
|
|
153
|
+
|
|
154
|
+
return res
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def read_test_log(file_path):
|
|
158
|
+
# res = {}
|
|
159
|
+
res = []
|
|
160
|
+
|
|
161
|
+
if os.path.isdir(file_path):
|
|
162
|
+
for root, dirs, files in os.walk(file_path):
|
|
163
|
+
for file in files:
|
|
164
|
+
if "Test" in file:
|
|
165
|
+
file_path = os.path.join(file_path, file)
|
|
166
|
+
break
|
|
167
|
+
|
|
168
|
+
print(f"{file_path = }")
|
|
169
|
+
if os.path.exists(file_path):
|
|
170
|
+
for line in open(file_path, "r"):
|
|
171
|
+
if len(line) <= 20:
|
|
172
|
+
continue
|
|
173
|
+
split = line.split(";")
|
|
174
|
+
time_str = split[0]
|
|
175
|
+
temp_str = split[1]
|
|
176
|
+
|
|
177
|
+
dt_object = datetime.datetime.strptime(
|
|
178
|
+
re.findall(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z", time_str)[0],
|
|
179
|
+
"%Y-%m-%dT%H:%M:%SZ")
|
|
180
|
+
|
|
181
|
+
timezone = pytz.utc
|
|
182
|
+
dt_object = timezone.localize(dt_object)
|
|
183
|
+
|
|
184
|
+
# res[int(dt_object.timestamp())] = {
|
|
185
|
+
# "read": int(temp_str)
|
|
186
|
+
# }
|
|
187
|
+
res.append([dt_object, int(temp_str)])
|
|
188
|
+
|
|
189
|
+
return res
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
loc = r"C:\Users\Young\OneDrive\Documents\Libano Data\2024-03-13"
|
|
193
|
+
|
|
194
|
+
s = r"202403131203-libano.log"
|
|
195
|
+
|
|
196
|
+
filepath = os.path.join(loc, s)
|
|
197
|
+
|
|
198
|
+
outside = read_libano(loc)
|
|
199
|
+
inside = read_test_log(loc)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
fig, axs = plt.subplots(1, 1, figsize=(6, 4))
|
|
203
|
+
|
|
204
|
+
# axs.set_xlim(0, 20, auto=True)
|
|
205
|
+
# axs.set_ylim(0, 10, auto=True)
|
|
206
|
+
# axs.set_title(f'Temperature check', loc='center', y=1)
|
|
207
|
+
# axs.set_ylabel(f'Time (ms)')
|
|
208
|
+
# axs.set_xlabel(f'Temperature (°C)')
|
|
209
|
+
|
|
210
|
+
i = 0
|
|
211
|
+
v = cm.get_cmap('viridis')
|
|
212
|
+
colors = [v(i) for i in np.random.random(22)]
|
|
213
|
+
|
|
214
|
+
x1, y1_set, y1_read = ap.calc.arr.transpose(outside)
|
|
215
|
+
x2, y2_read = ap.calc.arr.transpose(inside)
|
|
216
|
+
|
|
217
|
+
print(x1)
|
|
218
|
+
print(y1_set)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
axs.plot(x1, y1_set, label="Setpoints", c="green")
|
|
222
|
+
axs.plot(x1, y1_read, label="Outside readings", c="blue")
|
|
223
|
+
axs.plot(x2, y2_read, label="Inside readings", c="red")
|
|
224
|
+
|
|
225
|
+
# 设置x轴格式
|
|
226
|
+
axs.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M:%S'))
|
|
227
|
+
axs.xaxis.set_major_locator(mdates.SecondLocator(interval=7200)) # 每分钟一个主刻度
|
|
228
|
+
axs.xaxis.set_minor_locator(mdates.SecondLocator(interval=3600)) # 每10秒一个次刻度
|
|
229
|
+
axs.set_xlim(
|
|
230
|
+
datetime.datetime.strptime("2024-03-13T15:40:00Z", "%Y-%m-%dT%H:%M:%SZ"),
|
|
231
|
+
datetime.datetime.strptime("2024-03-13T16:20:00Z", "%Y-%m-%dT%H:%M:%SZ")
|
|
232
|
+
)
|
|
233
|
+
axs.set_ylim(650, 800)
|
|
234
|
+
|
|
235
|
+
# axs.legend(loc='best')
|
|
236
|
+
fig.tight_layout()
|
|
237
|
+
plt.show()
|
|
238
|
+
|
|
239
|
+
#
|
|
240
|
+
#
|
|
241
|
+
# filename = f"39argon release excess ar - 2 - matplotlib"
|
|
242
|
+
#
|
|
243
|
+
# params_list = {
|
|
244
|
+
# "page_size": 'a4', "ppi": 72, "width": 14, "height": 8,
|
|
245
|
+
# "pt_width": 0.8, "pt_height": 0.8, "pt_left": 0.16, "pt_bottom": 0.18,
|
|
246
|
+
# "offset_top": 0, "offset_right": 0, "offset_bottom": 20, "offset_left": 30,
|
|
247
|
+
# "plot_together": False, "show_frame": False,
|
|
248
|
+
# 'xlabel_offset': 8, 'ylabel_offset': 2
|
|
249
|
+
# }
|
|
250
|
+
#
|
|
251
|
+
# plot_data = {
|
|
252
|
+
# "data": [
|
|
253
|
+
# transform(axs),
|
|
254
|
+
# ],
|
|
255
|
+
# "file_name": filename,
|
|
256
|
+
# "plot_names": [f"plotname"],
|
|
257
|
+
# }
|
|
258
|
+
#
|
|
259
|
+
# filepath = os.path.join(r"C:\Users\Young\Downloads", f"ceshi.pdf")
|
|
260
|
+
# cvs = [[ap.smp.export.get_cv_from_dict(plot, **params_list) for plot in plot_data['data']]]
|
|
261
|
+
# for i in range(len(cvs[0])):
|
|
262
|
+
# pt = cvs[0][i]._plot_areas[0]
|
|
263
|
+
# for index, legned in enumerate(list(filter(lambda cp: cp.name() == 'legend', pt._components))):
|
|
264
|
+
# legned._size = 7
|
|
265
|
+
# legned._z_index = 250
|
|
266
|
+
# legned._h_align = "left"
|
|
267
|
+
# legned._v_align = "center"
|
|
268
|
+
# if i == 0: # age spectra
|
|
269
|
+
# legned._x = 175
|
|
270
|
+
# legned._y = 40 + index * 10
|
|
271
|
+
# elif i == 1: # cooling history
|
|
272
|
+
# legned._x = 65
|
|
273
|
+
# legned._y = 135 - index * 10
|
|
274
|
+
# elif i == 2: # arrhenius
|
|
275
|
+
# legned._x = 75
|
|
276
|
+
# legned._y = 40 + index * 10
|
|
277
|
+
# else:
|
|
278
|
+
# legned._x = 65
|
|
279
|
+
# legned._y = 40 + index * 10
|
|
280
|
+
# for comp in pt._components:
|
|
281
|
+
# if legned._text in comp.name() and "legend" in comp.name():
|
|
282
|
+
# comp._z_index = 250
|
|
283
|
+
# if isinstance(comp, pm.Scatter):
|
|
284
|
+
# comp._x = legned._x - 10
|
|
285
|
+
# comp._y = legned._y
|
|
286
|
+
# if isinstance(comp, pm.Line):
|
|
287
|
+
# comp._start = [legned._x - 16, legned._y]
|
|
288
|
+
# comp._end = [legned._x - 4, legned._y]
|
|
289
|
+
#
|
|
290
|
+
#
|
|
291
|
+
# filepath = ap.smp.export.export_chart_to_pdf(cvs, filename, filepath)
|