ararpy 0.1.13__py3-none-any.whl → 0.1.15__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/calc/corr.py CHANGED
@@ -59,14 +59,14 @@ def mdf(rm: float, srm: float, m1: float, m2: float, ra: float = 298.56,
59
59
  sdelta_m = err.add(sm2, sm1)
60
60
  ratio_m = m2 / m1
61
61
  sratio_m = err.div((m2, sm2), (m1, sm1))
62
- isAapkop = True
63
- if isAapkop:
62
+ useRyu = False
63
+ if not useRyu:
64
64
  # line
65
- k1 = (ra / rm + delta_m - 1) / delta_m # A.A.P.Koppers
65
+ k1 = (ra / rm + delta_m - 1) / delta_m
66
66
  k2 = err.div(((ra / rm + delta_m - 1), err.div((ra, sra), (rm, srm))), (delta_m, sdelta_m))
67
67
  # exp
68
68
  try:
69
- k3 = (np.log(ra / rm) / np.log(ratio_m)) * (1 / m1) + 1 # A.A.P.Koppers
69
+ k3 = (np.log(ra / rm) / np.log(ratio_m)) * (1 / m1) + 1
70
70
  v1 = err.log((ra / rm, err.div((ra, sra), (rm, srm))))
71
71
  v2 = err.log((ratio_m, sratio_m))
72
72
  v3 = err.div((np.log(ra / rm), v1), (np.log(ratio_m), v2))
@@ -75,7 +75,7 @@ def mdf(rm: float, srm: float, m1: float, m2: float, ra: float = 298.56,
75
75
  k3, k4 = "Null", "Null"
76
76
  # pow
77
77
  try:
78
- k5 = pow((ra / rm), (1 / delta_m)) # A.A.P.Koppers
78
+ k5 = pow((ra / rm), (1 / delta_m)) # Renne2009, B.D. Turrin2010
79
79
  k6 = err.pow((ra / rm, err.div((ra, sra), (rm, srm))),
80
80
  (1 / delta_m, err.div((1, 0), (delta_m, sdelta_m))))
81
81
  except Exception:
@@ -107,14 +107,14 @@ def discr(a0: list, e0: list, mdf: list, smdf: list, m: list, m40: list,
107
107
  for i in range(min([len(arg) for arg in [a0, e0, mdf, smdf]])):
108
108
  delta_mass = abs(m40[i] - m[i])
109
109
  ratio_mass = abs(m40[i] / m[i]) if m[i] != 0 else 1
110
- if method.lower()[0] == 'l':
110
+ if method.lower().startswith("l"):
111
111
  k0 = 1 / (delta_mass * mdf[i] - delta_mass + 1) if (delta_mass * mdf[i] - delta_mass + 1) != 0 else 0
112
112
  k1 = err.div((1, 0), (delta_mass * mdf[i] - delta_mass + 1, smdf[i] * delta_mass))
113
- elif method.lower()[0] == 'e':
113
+ elif method.lower().startswith("e"):
114
114
  k0 = 1 / (ratio_mass ** (mdf[i] * m40[i] - m[i]))
115
115
  k1 = err.div((1, 0), (ratio_mass ** (mdf[i] * m40[i] - m[i]), err.pow((ratio_mass, 0), (
116
116
  mdf[i] * m40[i] - m[i], err.mul((mdf[i], smdf[i]), (m40[i], 0))))))
117
- elif method.lower()[0] == 'p':
117
+ elif method.lower().startswith("p"):
118
118
  k0 = 1 / (mdf[i] ** delta_mass)
119
119
  k1 = err.div((1, 0), (mdf[i] ** delta_mass, err.pow((mdf[i], smdf[i]), (delta_mass, 0))))
120
120
  else:
ararpy/calc/plot.py CHANGED
@@ -13,9 +13,9 @@ import traceback
13
13
 
14
14
  import decimal
15
15
  from math import exp, log, cos, acos, ceil, sqrt, atan, sin, gamma
16
- from typing import List, Any
17
- from scipy.optimize import fsolve
18
- from scipy.stats import distributions
16
+ # from typing import List, Any
17
+ # from scipy.optimize import fsolve
18
+ # from scipy.stats import distributions
19
19
  import numpy as np
20
20
 
21
21
  math_e = 2.718281828459045
ararpy/calc/raw_funcs.py CHANGED
@@ -46,6 +46,8 @@ def get_raw_data_regression_results(points_data, unselected: list = None):
46
46
  # line_data = transpose([lines_x, res[7](lines_x)])
47
47
  line_results = res[0:4]
48
48
  reg_coeffs = res[5]
49
+ if any(np.isnan(line_results)):
50
+ raise ValueError
49
51
  # if np.isin(np.inf, line_data) or np.isin(np.nan, line_data):
50
52
  # raise ZeroDivisionError(f"Infinite value or nan value.")
51
53
  if abs(res[0] - min(y)) > 5 * (max(y) - min(y)):
ararpy/calc/regression.py CHANGED
@@ -966,11 +966,6 @@ def exponential(a0: list, a1: list):
966
966
  se_intercept = sec / errfz * errfx
967
967
  rse_intercept = se_intercept / intercept * 100
968
968
 
969
- if abs(intercept) > 10 * max(a0):
970
- raise ValueError
971
- if intercept < 0:
972
- raise ValueError
973
-
974
969
  return intercept, se_intercept, rse_intercept, r2, 'mswd', [a, b, c], 'se', \
975
970
  lambda x: [_exp_func(i, a, b, c) for i in x], m_ssresid
976
971
 
ararpy/calc/spectra.py CHANGED
@@ -13,7 +13,7 @@ import numpy as np
13
13
 
14
14
 
15
15
  def get_data(y: list, sy: list, x: list, f: int = 1, indices: list = None,
16
- cumulative: bool = False, successive: bool = True):
16
+ cumulative: bool = False, successive: bool = True, sigma: int = 1):
17
17
  """
18
18
  Get spectra data based on passed x, y, and sy.
19
19
 
@@ -28,6 +28,7 @@ def get_data(y: list, sy: list, x: list, f: int = 1, indices: list = None,
28
28
  cumulative : bool, default False.
29
29
  This parameter should be True if x is already cumulative.
30
30
  successive : If setting indices successive
31
+ sigma:
31
32
 
32
33
  Returns
33
34
  -------
@@ -35,6 +36,7 @@ def get_data(y: list, sy: list, x: list, f: int = 1, indices: list = None,
35
36
  """
36
37
  if np.issubdtype(type(f), np.integer) and f > 1:
37
38
  sy = np.divide(sy, f)
39
+ sy = np.array(sy) * sigma
38
40
  dp = np.shape([y, sy, x])[-1]
39
41
  if indices is None:
40
42
  indices = list(range(dp))
ararpy/files/calc_file.py CHANGED
@@ -109,6 +109,8 @@ def open_252(data: pd.DataFrame, logs01: pd.DataFrame, logs02: pd.DataFrame):
109
109
  -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, # 100-109
110
110
  -999, -999, -999, -999, -1, # 110-114
111
111
  -999, -999, -999, -999, -999, -999, -999, -999, # 115-122
112
+ -999, -999, -999, -999, -999, -999, -999, -999, # 123-130
113
+ -999, -999, -999, -999, -999, # 131-135
112
114
  ]
113
115
 
114
116
  # double transpose to remove keys
@@ -283,6 +285,10 @@ def open_240(data: pd.DataFrame, logs01: pd.DataFrame, logs02: pd.DataFrame):
283
285
  -999, -999, -999, -999, -1,
284
286
  # 115-122
285
287
  -999, -999, -999, -999, -999, -999, -999, -999,
288
+ # 123-130
289
+ -999, -999, -999, -999, -999, -999, -999, -999,
290
+ # 131-135
291
+ -999, -999, -999, -999, -999,
286
292
  ]
287
293
 
288
294
  # double transpose to remove keys
@@ -503,15 +509,17 @@ def open_full_xls(file_path: str, sample_name: str = ''):
503
509
  -1, -1, # 56-57
504
510
  -1, -1, # 58-59
505
511
  -1, -1, -1, -1, -1, -1, -1, -1, -1, # 60-68
506
- 10, 11, 12, 13, #
507
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, #
508
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, #
509
- -1, -1, -1, -1, #
510
- -1, -1, -1, -1, #
511
- -1, -1, -1, -1, -1, #
512
- -1, -1, -1, -1, #
513
- -1, -1, -1, -1, #
514
- -1, #
512
+ 10, 11, 12, 13, # 69-72
513
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, # 73-84
514
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, # 85-94
515
+ -1, -1, -1, -1, # 95-98
516
+ -1, -1, -1, -1, # 99-102
517
+ -1, -1, -1, -1, # 103-106
518
+ -1, -1, -1, -1, # 107-110
519
+ -1, -1, -1, -1, # 111-114
520
+ -1, -1, -1, -1, -1, -1, -1, -1, # 115-122
521
+ -1, -1, -1, -1, -1, -1, -1, -1, # 123-130
522
+ -1, -1, -1, -1, -1, # 131-135
515
523
  ])
516
524
 
517
525
  month_convert = {'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06',
ararpy/smp/corr.py CHANGED
@@ -49,8 +49,16 @@ def corr_blank(sample: Sample):
49
49
  blank_corrected = np.zeros([10, len(sample.SequenceName)])
50
50
  try:
51
51
  for i in range(5):
52
+ b, sb = copy.deepcopy(sample.BlankIntercept[i * 2: i * 2 + 2])
53
+ f, sf = np.array(sample.TotalParam[126 + i * 2:128 + i * 2])
54
+ sf = f * sf / 100
55
+ _ = calc.corr.gain(*sample.BlankIntercept[i * 2:2 + i * 2], f, sf)
56
+ for index in range(len(sample.BlankIntercept[i * 2])):
57
+ if sample.TotalParam[111][index]: # use same parameters to correct blank intercepts
58
+ b[index] = _[0][index]
59
+ sb[index] = _[1][index]
52
60
  blank_corrected[i * 2:2 + i * 2] = calc.corr.blank(
53
- *sample.CorrectedValues[i * 2:2 + i * 2], *sample.BlankIntercept[i * 2:2 + i * 2])
61
+ *sample.CorrectedValues[i * 2:2 + i * 2], b, sb)
54
62
  except Exception as e:
55
63
  print(traceback.format_exc())
56
64
  raise ValueError('Blank correction error')
@@ -743,6 +743,8 @@ class DiffArrmultiFunc(DiffSample):
743
743
  for j in range(0, na, 2):
744
744
  a1[j + 1] = a1[j + 1] / sum
745
745
 
746
+ # 生成体积浓度分数随机值,归一到总和为1
747
+
746
748
  # Definition of sizes (start with random order numbers greater to smaller)
747
749
  sum = 0.0
748
750
  for j in range(0, na - 2, 2):
@@ -753,11 +755,15 @@ class DiffArrmultiFunc(DiffSample):
753
755
  for j in range(0, na - 2, 2):
754
756
  a1[j] = a1[j] / sum * xro
755
757
 
758
+ # 从后到前随机生成尺寸,归一化到最大值为xro
759
+
756
760
  sum = a1[na - 1] + a1[na - 3]
757
761
  for j in range(2, na - 3, 2):
758
762
  a1[j] = a1[j] - np.log10(sum)
759
763
  sum = sum + a1[na - (j + 1) - 2]
760
764
 
765
+ # 调整尺寸的值,为什么?
766
+
761
767
  ro = 10.0 ** a1[0]
762
768
 
763
769
  for j in range(2, na - 3, 2):
@@ -3716,7 +3722,7 @@ class SmpTemperatureCalibration:
3716
3722
  if line == "":
3717
3723
  break
3718
3724
  k = line.split(";")
3719
- time = dt.strptime(k[0], "%Y-%m-%dT%H:%M:%S%z").timestamp()
3725
+ time = dt.strptime(k[0], "%Y-%m-%dT%H:%M:%S%z").timestamp() # UTC datetime
3720
3726
  cumulative_time = 0
3721
3727
  if int(k[1]) != last_sp:
3722
3728
  last_sp = int(k[1])
@@ -3731,11 +3737,12 @@ class SmpTemperatureCalibration:
3731
3737
  except KeyError:
3732
3738
  inside_temp = [0, 0]
3733
3739
 
3734
- libano_log.append([time, int(k[1]), int(k[2]), cumulative_time, inside_temp[0], inside_temp[1]])
3740
+ # timestamp, cumulative_time of the current temperature, SP, AP, Inside, Inside error
3741
+ libano_log.append([time, cumulative_time, int(k[1]), int(k[2]), (inside_temp[0] + inside_temp[1]) / 2,
3742
+ abs(inside_temp[0] - inside_temp[1]) / 2, 9999])
3735
3743
  n += 1
3736
3744
 
3737
3745
  libano_file.close()
3738
- libano_log = np.array(libano_log).transpose()
3739
3746
 
3740
3747
  # # set time starts with zero
3741
3748
  # log_time = [i - log_time[0] for i in log_time]
@@ -3749,10 +3756,13 @@ class SmpTemperatureCalibration:
3749
3756
  helix_log = [[], [], [], [], [], [], [], [], [], [], [], []]
3750
3757
  nstep = 0
3751
3758
 
3759
+ time_difference = 147 # helix time - libano time 时间差
3760
+
3752
3761
  keys = {
3753
3762
  "start_buildup": "GenWorkflow-BuildUp.cs: line 1: Clock reset",
3754
3763
  "set_temp": "GenWorkflow-Sampling.cs: Target temperature: key = Intensity, value = ",
3755
3764
  "end_sampling": "GenWorkflow-Prepare.cs: line 1: CLOSE for VUcleaningline/VINL2",
3765
+ # "start_sampling": "GenWorkflow-Prepare.cs: line 15: CLOSE for VUcleaningline/VGP5", # Y01样品之后发现VPL1漏气,多加了一步关闭VPL1因此,在那之后是line 15
3756
3766
  "start_sampling": "GenWorkflow-Prepare.cs: line 14: CLOSE for VUcleaningline/VGP5",
3757
3767
  "end_sequence": "GenWorkflow-PostAcquisition.cs: line 7: Starting Acquisition",
3758
3768
  "get_setpoint": "GenWorkflow-Sampling.cs: Target temperature: key = Intensity, value = ",
@@ -3781,7 +3791,9 @@ class SmpTemperatureCalibration:
3781
3791
  dt_utc = dt_str[:26] + dt_str[27:] # dt_utc will be like 2024-10-23T19:58:59.666214+02:00
3782
3792
  dt_utc = dt.fromisoformat(str(dt_utc)).timestamp()
3783
3793
 
3784
- if not (self.start_time <= dt_utc <= self.end_time):
3794
+ dt_utc = dt_utc - time_difference
3795
+
3796
+ if not (self.start_time <= int(dt_utc) <= self.end_time):
3785
3797
  continue
3786
3798
  if message1.startswith(keys["start_buildup"]):
3787
3799
  ### start buildup
@@ -3795,6 +3807,16 @@ class SmpTemperatureCalibration:
3795
3807
  # 关闭vinlet2,60秒进质谱,之后开vinlet2,90秒抽气
3796
3808
  gas_collection_end = dt_utc
3797
3809
  helix_log[1].append(dt_utc)
3810
+ try:
3811
+ gas_collection_start = gas_collection_start
3812
+ except NameError:
3813
+ gas_collection_start = buildup_start
3814
+ # 添加阶段标记
3815
+ for each_row in libano_log:
3816
+ # 时间在集气过程中
3817
+ if gas_collection_start <= each_row[0] <= gas_collection_end:
3818
+ each_row[6] = nstep
3819
+
3798
3820
  if message1.startswith(keys["start_sampling"]):
3799
3821
  # Close VGP5, start peak centering and measurement, IMPORTANT: start to sampling
3800
3822
  gas_collection_start = dt_utc
@@ -3815,6 +3837,8 @@ class SmpTemperatureCalibration:
3815
3837
  for i in helix_log:
3816
3838
  print(len(i))
3817
3839
  print(i)
3840
+
3841
+ libano_log = np.array(libano_log).transpose()
3818
3842
  helix_log = np.array(helix_log)
3819
3843
 
3820
3844
 
@@ -3843,12 +3867,12 @@ class SmpTemperatureCalibration:
3843
3867
  yellow_data_index.append(_index)
3844
3868
 
3845
3869
  med = int((_index[0] + _index[-1]) / 2)
3846
- helix_log[4, i] = (libano_log[4, _index][0] + libano_log[5, _index][0]) / 2
3847
- helix_log[5, i] = abs(libano_log[4, _index][0] - libano_log[5, _index][0]) / 2
3848
- helix_log[6, i] = (libano_log[4, _index][-1] + libano_log[5, _index][-1]) / 2
3849
- helix_log[7, i] = abs(libano_log[4, _index][-1] - libano_log[5, _index][-1]) / 2
3850
- helix_log[8, i] = (libano_log[4, med] + libano_log[5, med]) / 2
3851
- helix_log[9, i] = abs(libano_log[4, med] - libano_log[5, med]) / 2
3870
+ helix_log[4, i] = libano_log[4, _index][0]
3871
+ helix_log[5, i] = libano_log[5, _index][0]
3872
+ helix_log[6, i] = libano_log[4, _index][-1]
3873
+ helix_log[7, i] = libano_log[5, _index][-1]
3874
+ helix_log[8, i] = libano_log[4, med]
3875
+ helix_log[9, i] = libano_log[5, med]
3852
3876
  helix_log[11, i] = gas_in_end - gas_in_start
3853
3877
 
3854
3878
  line = f"{i + 1}\t{helix_log[10, i]}\t{helix_log[11, i]}\t" + '\t'.join(
@@ -3871,11 +3895,9 @@ class SmpTemperatureCalibration:
3871
3895
  ax.plot(libano_log[0], libano_log[1], c='green')
3872
3896
  ax.plot(libano_log[0], libano_log[2], c='blue')
3873
3897
  ax.plot(libano_log[0], libano_log[4], c='red')
3874
- ax.plot(libano_log[0], libano_log[5], c='red')
3875
3898
  for i in range(nstep):
3876
3899
  _index = yellow_data_index[i]
3877
3900
  ax.plot(libano_log[0, _index], libano_log[4, _index], c='yellow')
3878
- ax.plot(libano_log[0, _index], libano_log[5, _index], c='yellow')
3879
3901
 
3880
3902
  fig.tight_layout()
3881
3903
  plt.show()