ararpy 0.0.1a1__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/__init__.py +178 -0
- ararpy/calc/__init__.py +11 -0
- ararpy/calc/age.py +161 -0
- ararpy/calc/arr.py +490 -0
- ararpy/calc/basic.py +57 -0
- ararpy/calc/corr.py +240 -0
- ararpy/calc/err.py +117 -0
- ararpy/calc/histogram.py +166 -0
- ararpy/calc/isochron.py +194 -0
- ararpy/calc/jvalue.py +38 -0
- ararpy/calc/plot.py +68 -0
- ararpy/calc/raw_funcs.py +118 -0
- ararpy/calc/regression.py +961 -0
- ararpy/calc/spectra.py +63 -0
- ararpy/files/__init__.py +2 -0
- ararpy/files/arr_file.py +86 -0
- ararpy/files/basic.py +100 -0
- ararpy/files/calc_file.py +683 -0
- ararpy/files/export.py +1181 -0
- ararpy/files/json.py +49 -0
- ararpy/files/new_file.py +31 -0
- ararpy/files/raw.py +115 -0
- ararpy/files/raw_file.py +14 -0
- ararpy/files/xls.py +27 -0
- ararpy/smp/__init__.py +17 -0
- ararpy/smp/basic.py +371 -0
- ararpy/smp/calculation.py +94 -0
- ararpy/smp/consts.py +20 -0
- ararpy/smp/corr.py +376 -0
- ararpy/smp/initial.py +232 -0
- ararpy/smp/plots.py +636 -0
- ararpy/smp/sample.py +911 -0
- ararpy/smp/style.py +191 -0
- ararpy/smp/table.py +131 -0
- ararpy-0.0.1a1.dist-info/LICENSE +21 -0
- ararpy-0.0.1a1.dist-info/METADATA +269 -0
- ararpy-0.0.1a1.dist-info/RECORD +39 -0
- ararpy-0.0.1a1.dist-info/WHEEL +5 -0
- ararpy-0.0.1a1.dist-info/top_level.txt +1 -0
ararpy/calc/spectra.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: UTF-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
# ==========================================
|
|
5
|
+
# Copyright 2023 Yang
|
|
6
|
+
# ararpy - calc- spectra
|
|
7
|
+
# ==========================================
|
|
8
|
+
#
|
|
9
|
+
# Spectra
|
|
10
|
+
#
|
|
11
|
+
"""
|
|
12
|
+
import numpy as np
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def get_data(y: list, sy: list, x: list, f: int = 1, indices: list = None,
|
|
16
|
+
cumulative: bool = False, successive: bool = True):
|
|
17
|
+
"""
|
|
18
|
+
Get spectra data based on passed x, y, and sy.
|
|
19
|
+
|
|
20
|
+
Parameters
|
|
21
|
+
----------
|
|
22
|
+
y :
|
|
23
|
+
sy :
|
|
24
|
+
x :
|
|
25
|
+
f : error factor of sy, 1 or 2 for 1 or 2 sigma
|
|
26
|
+
indices : array-like, default None for all sequences included
|
|
27
|
+
An array of ints indicating which sequences to include.
|
|
28
|
+
cumulative : bool, default False.
|
|
29
|
+
This parameter should be True if x is already cumulative.
|
|
30
|
+
successive : If setting indices successive
|
|
31
|
+
|
|
32
|
+
Returns
|
|
33
|
+
-------
|
|
34
|
+
list of lists of float. [x, y1, y2]
|
|
35
|
+
"""
|
|
36
|
+
if np.issubdtype(type(f), np.integer) and f > 1:
|
|
37
|
+
sy = np.divide(sy, f)
|
|
38
|
+
dp = np.shape([y, sy, x])[-1]
|
|
39
|
+
if indices is None:
|
|
40
|
+
indices = list(range(dp))
|
|
41
|
+
if successive:
|
|
42
|
+
indices = list(range(min(indices), max(indices) + 1))
|
|
43
|
+
if not cumulative:
|
|
44
|
+
x = np.divide(np.cumsum(x) * 100, sum(x)).tolist()
|
|
45
|
+
k0, k1, k2 = [], [], []
|
|
46
|
+
for i in range(dp):
|
|
47
|
+
if i not in indices:
|
|
48
|
+
continue
|
|
49
|
+
else:
|
|
50
|
+
k0.append([x[i - 1], 0][i == 0])
|
|
51
|
+
k0.append(x[i])
|
|
52
|
+
k1.append(y[i] + sy[i] if i % 2 == 0 else y[i] - sy[i])
|
|
53
|
+
k1.append(y[i] + sy[i] if i % 2 == 0 else y[i] - sy[i])
|
|
54
|
+
k2.append(y[i] - sy[i] if i % 2 == 0 else y[i] + sy[i])
|
|
55
|
+
k2.append(y[i] - sy[i] if i % 2 == 0 else y[i] + sy[i])
|
|
56
|
+
# Close the spectrum
|
|
57
|
+
k0.insert(0, k0[0])
|
|
58
|
+
k0.append(k0[-1])
|
|
59
|
+
k1.insert(0, k2[0])
|
|
60
|
+
k1.append(k2[-1])
|
|
61
|
+
k2.insert(0, k1[0])
|
|
62
|
+
k2.append(k1[-1])
|
|
63
|
+
return [k0, k1, k2]
|
ararpy/files/__init__.py
ADDED
ararpy/files/arr_file.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: UTF-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
# ==========================================
|
|
5
|
+
# Copyright 2023 Yang
|
|
6
|
+
# ararpy - files - arr_file
|
|
7
|
+
# ==========================================
|
|
8
|
+
#
|
|
9
|
+
#
|
|
10
|
+
#
|
|
11
|
+
"""
|
|
12
|
+
# === External imports ===
|
|
13
|
+
import os
|
|
14
|
+
import pickle
|
|
15
|
+
|
|
16
|
+
from .. import smp
|
|
17
|
+
|
|
18
|
+
SAMPLE_MODULE = smp.Sample().__module__
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def to_sample(file_path, sample_name: str = ""):
|
|
22
|
+
"""
|
|
23
|
+
file_path: full path of input file
|
|
24
|
+
name: samplename
|
|
25
|
+
return sample instance
|
|
26
|
+
"""
|
|
27
|
+
try:
|
|
28
|
+
with open(file_path, 'rb') as f:
|
|
29
|
+
sample = renamed_load(f)
|
|
30
|
+
except (Exception, BaseException):
|
|
31
|
+
raise ValueError(f"Fail to open arr file: {file_path}")
|
|
32
|
+
# Check arr version
|
|
33
|
+
# recalculation will not be applied automatically
|
|
34
|
+
sample = check_version(sample)
|
|
35
|
+
return sample
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def save(file_path, sample: smp.Sample):
|
|
39
|
+
""" Save arr project as arr files
|
|
40
|
+
|
|
41
|
+
Parameters
|
|
42
|
+
----------
|
|
43
|
+
file_path : str, filepath
|
|
44
|
+
sample : Sample instance
|
|
45
|
+
|
|
46
|
+
Returns
|
|
47
|
+
-------
|
|
48
|
+
str, file name
|
|
49
|
+
"""
|
|
50
|
+
file_path = os.path.join(file_path, f"{sample.Info.sample.name}.arr")
|
|
51
|
+
with open(file_path, 'wb') as f:
|
|
52
|
+
f.write(pickle.dumps(sample))
|
|
53
|
+
# with open(file_path, 'w') as f:
|
|
54
|
+
# # save serialized json data to a readable text
|
|
55
|
+
# f.write(basic_funcs.getJsonDumps(sample))
|
|
56
|
+
return f"{sample.Info.sample.name}.arr"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def check_version(sample: smp.Sample):
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
Parameters
|
|
63
|
+
----------
|
|
64
|
+
sample
|
|
65
|
+
|
|
66
|
+
Returns
|
|
67
|
+
-------
|
|
68
|
+
|
|
69
|
+
"""
|
|
70
|
+
if sample.version != smp.VERSION:
|
|
71
|
+
smp.initial.re_set_smp(sample)
|
|
72
|
+
return sample
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class RenameUnpickler(pickle.Unpickler):
|
|
76
|
+
def find_class(self, module: str, name: str):
|
|
77
|
+
renamed_module = module
|
|
78
|
+
if '.sample' in module and module != SAMPLE_MODULE:
|
|
79
|
+
renamed_module = SAMPLE_MODULE
|
|
80
|
+
|
|
81
|
+
return super(RenameUnpickler, self).find_class(renamed_module, name)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def renamed_load(file_obj):
|
|
85
|
+
return RenameUnpickler(file_obj).load()
|
|
86
|
+
|
ararpy/files/basic.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: UTF-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
# ==========================================
|
|
5
|
+
# Copyright 2023 Yang
|
|
6
|
+
# ararpy - files - basic
|
|
7
|
+
# ==========================================
|
|
8
|
+
#
|
|
9
|
+
#
|
|
10
|
+
#
|
|
11
|
+
"""
|
|
12
|
+
# from programs.ararpy.files import json as myjson
|
|
13
|
+
from ..files import json as myjson
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
import pickle
|
|
17
|
+
import traceback
|
|
18
|
+
import json
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
try:
|
|
22
|
+
from webarar.settings import SETTINGS_ROOT
|
|
23
|
+
except ModuleNotFoundError:
|
|
24
|
+
SETTINGS_ROOT = ""
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def upload(file, media_dir):
|
|
28
|
+
try:
|
|
29
|
+
name, suffix = os.path.splitext(file.name)
|
|
30
|
+
if suffix not in [
|
|
31
|
+
'.xls', '.age', '.xlsx', '.arr', '.jpg', '.png', '.txt',
|
|
32
|
+
'.log', '.seq', '.json', '.ahd']:
|
|
33
|
+
raise TypeError("Wrong File")
|
|
34
|
+
web_file_path = os.path.join(media_dir, file.name)
|
|
35
|
+
with open(web_file_path, 'wb') as f:
|
|
36
|
+
for chunk in file.chunks():
|
|
37
|
+
f.write(chunk)
|
|
38
|
+
print("File path on the server: %s" % web_file_path)
|
|
39
|
+
except PermissionError:
|
|
40
|
+
raise ValueError(f'Permission denied')
|
|
41
|
+
except (Exception, BaseException) as e:
|
|
42
|
+
print(traceback.format_exc())
|
|
43
|
+
raise ValueError(f'Error in opening file: {e}')
|
|
44
|
+
else:
|
|
45
|
+
return web_file_path, name, suffix
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def read(file_path):
|
|
49
|
+
""" Read text files, default 'r', 'rb'
|
|
50
|
+
Parameters
|
|
51
|
+
----------
|
|
52
|
+
file_path
|
|
53
|
+
|
|
54
|
+
Returns
|
|
55
|
+
-------
|
|
56
|
+
|
|
57
|
+
"""
|
|
58
|
+
try:
|
|
59
|
+
with open(file_path, 'r') as f:
|
|
60
|
+
params = json.load(f)
|
|
61
|
+
except UnicodeDecodeError:
|
|
62
|
+
with open(file_path, 'rb') as f:
|
|
63
|
+
params = pickle.load(f)
|
|
64
|
+
return params
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def write(file_path, params):
|
|
68
|
+
"""
|
|
69
|
+
Parameters
|
|
70
|
+
----------
|
|
71
|
+
file_path
|
|
72
|
+
params
|
|
73
|
+
|
|
74
|
+
Returns
|
|
75
|
+
-------
|
|
76
|
+
|
|
77
|
+
"""
|
|
78
|
+
# with open(file_path, 'wb') as f:
|
|
79
|
+
# f.write(pickle.dumps(params))
|
|
80
|
+
with open(file_path, 'w') as f: # save serialized json data to a readable text
|
|
81
|
+
f.write(myjson.dumps(params))
|
|
82
|
+
return file_path
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def delete(file_path):
|
|
86
|
+
"""
|
|
87
|
+
Parameters
|
|
88
|
+
----------
|
|
89
|
+
file_path
|
|
90
|
+
|
|
91
|
+
Returns
|
|
92
|
+
-------
|
|
93
|
+
|
|
94
|
+
"""
|
|
95
|
+
try:
|
|
96
|
+
os.remove(file_path)
|
|
97
|
+
except Exception:
|
|
98
|
+
return False
|
|
99
|
+
else:
|
|
100
|
+
return True
|