AeroViz 0.1.3__py3-none-any.whl → 0.1.3b0__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.

Potentially problematic release.


This version of AeroViz might be problematic. Click here for more details.

Files changed (107) hide show
  1. AeroViz/__init__.py +4 -4
  2. AeroViz/dataProcess/Chemistry/__init__.py +38 -38
  3. AeroViz/dataProcess/Chemistry/_calculate.py +15 -15
  4. AeroViz/dataProcess/Chemistry/_isoropia.py +69 -68
  5. AeroViz/dataProcess/Chemistry/_mass_volume.py +158 -158
  6. AeroViz/dataProcess/Chemistry/_ocec.py +109 -109
  7. AeroViz/dataProcess/Chemistry/_partition.py +19 -18
  8. AeroViz/dataProcess/Chemistry/_teom.py +8 -11
  9. AeroViz/dataProcess/Optical/_IMPROVE.py +40 -39
  10. AeroViz/dataProcess/Optical/__init__.py +35 -35
  11. AeroViz/dataProcess/Optical/_absorption.py +35 -35
  12. AeroViz/dataProcess/Optical/_extinction.py +25 -24
  13. AeroViz/dataProcess/Optical/_mie.py +5 -6
  14. AeroViz/dataProcess/Optical/_mie_sd.py +89 -90
  15. AeroViz/dataProcess/Optical/_scattering.py +16 -16
  16. AeroViz/dataProcess/SizeDistr/__init__.py +37 -37
  17. AeroViz/dataProcess/SizeDistr/__merge.py +159 -158
  18. AeroViz/dataProcess/SizeDistr/_merge.py +155 -154
  19. AeroViz/dataProcess/SizeDistr/_merge_v1.py +162 -161
  20. AeroViz/dataProcess/SizeDistr/_merge_v2.py +153 -152
  21. AeroViz/dataProcess/SizeDistr/_merge_v3.py +326 -326
  22. AeroViz/dataProcess/SizeDistr/_merge_v4.py +272 -274
  23. AeroViz/dataProcess/SizeDistr/_size_distr.py +51 -51
  24. AeroViz/dataProcess/VOC/__init__.py +7 -7
  25. AeroViz/dataProcess/VOC/_potential_par.py +53 -55
  26. AeroViz/dataProcess/__init__.py +4 -4
  27. AeroViz/dataProcess/core/__init__.py +59 -58
  28. AeroViz/plot/__init__.py +6 -1
  29. AeroViz/plot/bar.py +126 -0
  30. AeroViz/plot/box.py +68 -0
  31. AeroViz/plot/distribution/distribution.py +421 -427
  32. AeroViz/plot/meteorology/meteorology.py +240 -292
  33. AeroViz/plot/optical/__init__.py +0 -1
  34. AeroViz/plot/optical/optical.py +230 -230
  35. AeroViz/plot/pie.py +198 -0
  36. AeroViz/plot/regression.py +210 -0
  37. AeroViz/plot/scatter.py +99 -0
  38. AeroViz/plot/templates/__init__.py +0 -3
  39. AeroViz/plot/templates/contour.py +25 -25
  40. AeroViz/plot/templates/corr_matrix.py +86 -93
  41. AeroViz/plot/templates/diurnal_pattern.py +24 -24
  42. AeroViz/plot/templates/koschmieder.py +106 -106
  43. AeroViz/plot/templates/metal_heatmap.py +34 -34
  44. AeroViz/plot/timeseries/timeseries.py +53 -60
  45. AeroViz/plot/utils/__init__.py +2 -1
  46. AeroViz/plot/utils/_color.py +57 -57
  47. AeroViz/plot/utils/_unit.py +48 -48
  48. AeroViz/plot/utils/plt_utils.py +92 -0
  49. AeroViz/plot/utils/sklearn_utils.py +49 -0
  50. AeroViz/plot/violin.py +79 -0
  51. AeroViz/process/__init__.py +15 -15
  52. AeroViz/process/core/DataProc.py +9 -9
  53. AeroViz/process/core/SizeDist.py +81 -81
  54. AeroViz/process/method/PyMieScatt_update.py +488 -488
  55. AeroViz/process/method/mie_theory.py +231 -229
  56. AeroViz/process/method/prop.py +40 -40
  57. AeroViz/process/script/AbstractDistCalc.py +103 -103
  58. AeroViz/process/script/Chemical.py +166 -166
  59. AeroViz/process/script/IMPACT.py +40 -40
  60. AeroViz/process/script/IMPROVE.py +152 -152
  61. AeroViz/process/script/Others.py +45 -45
  62. AeroViz/process/script/PSD.py +26 -26
  63. AeroViz/process/script/PSD_dry.py +69 -70
  64. AeroViz/process/script/retrieve_RI.py +50 -51
  65. AeroViz/rawDataReader/__init__.py +57 -57
  66. AeroViz/rawDataReader/core/__init__.py +328 -326
  67. AeroViz/rawDataReader/script/AE33.py +18 -18
  68. AeroViz/rawDataReader/script/AE43.py +20 -20
  69. AeroViz/rawDataReader/script/APS_3321.py +30 -30
  70. AeroViz/rawDataReader/script/Aurora.py +23 -23
  71. AeroViz/rawDataReader/script/BC1054.py +40 -40
  72. AeroViz/rawDataReader/script/EPA_vertical.py +9 -9
  73. AeroViz/rawDataReader/script/GRIMM.py +21 -21
  74. AeroViz/rawDataReader/script/IGAC_TH.py +67 -67
  75. AeroViz/rawDataReader/script/IGAC_ZM.py +59 -59
  76. AeroViz/rawDataReader/script/MA350.py +39 -39
  77. AeroViz/rawDataReader/script/NEPH.py +74 -74
  78. AeroViz/rawDataReader/script/OCEC_LCRES.py +21 -21
  79. AeroViz/rawDataReader/script/OCEC_RES.py +16 -16
  80. AeroViz/rawDataReader/script/SMPS_TH.py +25 -25
  81. AeroViz/rawDataReader/script/SMPS_aim11.py +32 -32
  82. AeroViz/rawDataReader/script/SMPS_genr.py +31 -31
  83. AeroViz/rawDataReader/script/TEOM.py +28 -28
  84. AeroViz/rawDataReader/script/Table.py +12 -12
  85. AeroViz/rawDataReader/script/VOC_TH.py +16 -16
  86. AeroViz/rawDataReader/script/VOC_ZM.py +28 -28
  87. AeroViz/rawDataReader/script/__init__.py +20 -20
  88. AeroViz/rawDataReader/utils/config.py +161 -161
  89. AeroViz/tools/database.py +65 -65
  90. AeroViz/tools/dataclassifier.py +106 -106
  91. AeroViz/tools/dataprinter.py +51 -51
  92. AeroViz/tools/datareader.py +38 -38
  93. {AeroViz-0.1.3.dist-info → AeroViz-0.1.3b0.dist-info}/METADATA +5 -4
  94. AeroViz-0.1.3b0.dist-info/RECORD +110 -0
  95. AeroViz/config/__init__.py +0 -0
  96. AeroViz/plot/improve/__init__.py +0 -1
  97. AeroViz/plot/improve/improve.py +0 -240
  98. AeroViz/plot/optical/aethalometer.py +0 -77
  99. AeroViz/plot/templates/event_evolution.py +0 -65
  100. AeroViz/plot/templates/regression.py +0 -256
  101. AeroViz/plot/templates/scatter.py +0 -130
  102. AeroViz/plot/templates/templates.py +0 -398
  103. AeroViz/plot/utils/_decorator.py +0 -74
  104. AeroViz-0.1.3.dist-info/RECORD +0 -111
  105. {AeroViz-0.1.3.dist-info → AeroViz-0.1.3b0.dist-info}/LICENSE +0 -0
  106. {AeroViz-0.1.3.dist-info → AeroViz-0.1.3b0.dist-info}/WHEEL +0 -0
  107. {AeroViz-0.1.3.dist-info → AeroViz-0.1.3b0.dist-info}/top_level.txt +0 -0
@@ -1,175 +1,175 @@
1
- from pandas import date_range, concat, DataFrame, to_numeric
1
+ from pandas import concat, DataFrame
2
2
 
3
3
 
4
4
  def _basic(df_che, df_ref, df_water, df_density, nam_lst):
5
- df_all = concat(df_che, axis=1)
6
- index = df_all.index.copy()
7
- df_all.columns = nam_lst
8
-
9
- ## parameter
10
- mol_A, mol_S, mol_N = df_all['NH4+'] / 18, df_all['SO42-'] / 96, df_all['NO3-'] / 62
11
- df_all['status'] = (mol_A) / (2 * mol_S + mol_N)
12
-
13
- convert_nam = {'AS': 'SO42-',
14
- 'AN': 'NO3-',
15
- 'OM': 'OC',
16
- 'Soil': 'Fe',
17
- 'SS': 'Na+',
18
- 'EC': 'EC',
19
- }
20
-
21
- mass_coe = {'AS': 1.375,
22
- 'AN': 1.29,
23
- 'OM': 1.8,
24
- 'Soil': 28.57,
25
- 'SS': 2.54,
26
- 'EC': 1,
27
- }
28
-
29
- vol_coe = {'AS': 1.76,
30
- 'AN': 1.73,
31
- 'OM': 1.4,
32
- 'Soil': 2.6,
33
- 'SS': 2.16,
34
- 'EC': 1.5,
35
- }
36
-
37
- RI_coe = {'550': {'ALWC': 1.333 + 0j,
38
- 'AS': 1.53 + 0j,
39
- 'AN': 1.55 + 0j,
40
- 'OM': 1.55 + 0.0163j,
41
- 'Soil': 1.56 + 0.006j,
42
- 'SS': 1.54 + 0j,
43
- 'EC': 1.80 + 0.72j,
44
- },
45
-
46
- ## m + kj -> m value is same as 550 current
47
- '450': {'ALWC': 1.333 + 0j,
48
- 'AS': 1.57 + 0j,
49
- 'AN': 1.57 + 0j,
50
- 'OM': 1.58 + 0.056,
51
- 'Soil': 1.56 + 0.009j,
52
- 'SS': 1.54 + 0j,
53
- 'EC': 1.80 + 0.79j,
54
- },
55
- }
56
-
57
- ## mass
58
- ## NH4 Enough
59
- df_mass = DataFrame()
60
- df_enough = df_all.where(df_all['status'] >= 1).dropna().copy()
61
-
62
- for _mass_nam, _coe in mass_coe.items():
63
- df_mass[_mass_nam] = df_all[convert_nam[_mass_nam]] * _coe
64
-
65
- ## NH4 Deficiency
66
- defic_idx = df_all['status'] < 1
67
-
68
- if defic_idx.any():
69
- residual = mol_A - 2 * mol_S
70
-
71
- ## residual > 0
72
- _status = residual > 0
73
- if _status.any():
74
- _cond = _status & (residual <= mol_N)
75
- df_mass.loc[_cond, 'AN'] = residual.loc[_cond] * 80
76
-
77
- _cond = _status & (residual > mol_N)
78
- df_mass.loc[_cond, 'AN'] = mol_N.loc[_cond] * 80
79
-
80
- ## residual < 0
81
- _status = residual <= 0
82
- if _status.any():
83
- df_mass.loc[_status, 'AN'] = 0
84
-
85
- _cond = _status & (mol_A <= 2 * mol_S)
86
- df_mass.loc[_cond, 'AS'] = mol_A.loc[_cond] / 2 * 132
87
-
88
- _cond = _status & (mol_A > 2 * mol_S)
89
- df_mass.loc[_cond, 'AS'] = mol_S.loc[_cond] * 132
90
-
91
- df_mass_cal = df_mass.dropna().copy()
92
- df_mass['total'] = df_mass.sum(axis=1, min_count=6)
93
-
94
- qc_ratio = df_mass['total'] / df_ref
95
- qc_cond = (qc_ratio >= 0.7) & (qc_ratio <= 1.3)
96
-
97
- ## volume
98
- df_vol = DataFrame()
99
- for _vol_nam, _coe in vol_coe.items():
100
- df_vol[_vol_nam] = df_mass_cal[_vol_nam] / _coe
101
-
102
- if df_water is not None:
103
- df_vol['ALWC'] = df_water
104
- df_vol = df_vol.dropna()
105
- df_vol['total_wet'] = df_vol.sum(axis=1, min_count=6)
106
-
107
- df_vol['total_dry'] = df_vol[vol_coe.keys()].sum(axis=1, min_count=6)
108
-
109
- ## density
110
- df_vol_cal = DataFrame()
111
- df_den_rec = df_mass['total'] / df_vol['total_dry']
112
- if df_density is not None:
113
- df_den_all = concat([df_all[['SO42-', 'NO3-', 'NH4+', 'EC']], df_density, df_mass['OM']], axis=1).dropna()
114
-
115
- df_vol_cal = (df_den_all[['SO42-', 'NO3-', 'NH4+']].sum(axis=1) / 1.75) + \
116
- df_den_all['Cl-'] / 1.52 + \
117
- df_den_all['OM'] / 1.4 + df_den_all['EC'] / 1.77
118
-
119
- df_den = df_den_all.sum(axis=1, min_count=6) / df_vol_cal
120
- # df_den = df_den_all.sum(axis=1) / df_vol_cal
121
- # df_den = df_mass['total'].loc[df_den_all.index] / df_vol_cal
122
-
123
- ## refractive index
124
- ri_dic = {}
125
- for _lambda, _coe in RI_coe.items():
126
-
127
- df_RI = DataFrame()
128
-
129
- for _ky, _df in df_vol.items():
130
- if 'total' in _ky: continue
131
- df_RI[_ky] = (_df * _coe[_ky])
132
-
133
- df_RI['RI_wet'] = None
134
- if df_water is not None:
135
- df_RI['RI_wet'] = (df_RI / df_vol['total_wet'].to_frame().values).sum(axis=1)
5
+ df_all = concat(df_che, axis=1)
6
+ index = df_all.index.copy()
7
+ df_all.columns = nam_lst
8
+
9
+ ## parameter
10
+ mol_A, mol_S, mol_N = df_all['NH4+'] / 18, df_all['SO42-'] / 96, df_all['NO3-'] / 62
11
+ df_all['status'] = (mol_A) / (2 * mol_S + mol_N)
12
+
13
+ convert_nam = {'AS': 'SO42-',
14
+ 'AN': 'NO3-',
15
+ 'OM': 'OC',
16
+ 'Soil': 'Fe',
17
+ 'SS': 'Na+',
18
+ 'EC': 'EC',
19
+ }
20
+
21
+ mass_coe = {'AS': 1.375,
22
+ 'AN': 1.29,
23
+ 'OM': 1.8,
24
+ 'Soil': 28.57,
25
+ 'SS': 2.54,
26
+ 'EC': 1,
27
+ }
28
+
29
+ vol_coe = {'AS': 1.76,
30
+ 'AN': 1.73,
31
+ 'OM': 1.4,
32
+ 'Soil': 2.6,
33
+ 'SS': 2.16,
34
+ 'EC': 1.5,
35
+ }
36
+
37
+ RI_coe = {'550': {'ALWC': 1.333 + 0j,
38
+ 'AS': 1.53 + 0j,
39
+ 'AN': 1.55 + 0j,
40
+ 'OM': 1.55 + 0.0163j,
41
+ 'Soil': 1.56 + 0.006j,
42
+ 'SS': 1.54 + 0j,
43
+ 'EC': 1.80 + 0.72j,
44
+ },
45
+
46
+ ## m + kj -> m value is same as 550 current
47
+ '450': {'ALWC': 1.333 + 0j,
48
+ 'AS': 1.57 + 0j,
49
+ 'AN': 1.57 + 0j,
50
+ 'OM': 1.58 + 0.056,
51
+ 'Soil': 1.56 + 0.009j,
52
+ 'SS': 1.54 + 0j,
53
+ 'EC': 1.80 + 0.79j,
54
+ },
55
+ }
56
+
57
+ ## mass
58
+ ## NH4 Enough
59
+ df_mass = DataFrame()
60
+ df_enough = df_all.where(df_all['status'] >= 1).dropna().copy()
61
+
62
+ for _mass_nam, _coe in mass_coe.items():
63
+ df_mass[_mass_nam] = df_all[convert_nam[_mass_nam]] * _coe
64
+
65
+ ## NH4 Deficiency
66
+ defic_idx = df_all['status'] < 1
67
+
68
+ if defic_idx.any():
69
+ residual = mol_A - 2 * mol_S
70
+
71
+ ## residual > 0
72
+ _status = residual > 0
73
+ if _status.any():
74
+ _cond = _status & (residual <= mol_N)
75
+ df_mass.loc[_cond, 'AN'] = residual.loc[_cond] * 80
76
+
77
+ _cond = _status & (residual > mol_N)
78
+ df_mass.loc[_cond, 'AN'] = mol_N.loc[_cond] * 80
79
+
80
+ ## residual < 0
81
+ _status = residual <= 0
82
+ if _status.any():
83
+ df_mass.loc[_status, 'AN'] = 0
84
+
85
+ _cond = _status & (mol_A <= 2 * mol_S)
86
+ df_mass.loc[_cond, 'AS'] = mol_A.loc[_cond] / 2 * 132
87
+
88
+ _cond = _status & (mol_A > 2 * mol_S)
89
+ df_mass.loc[_cond, 'AS'] = mol_S.loc[_cond] * 132
90
+
91
+ df_mass_cal = df_mass.dropna().copy()
92
+ df_mass['total'] = df_mass.sum(axis=1, min_count=6)
93
+
94
+ qc_ratio = df_mass['total'] / df_ref
95
+ qc_cond = (qc_ratio >= 0.7) & (qc_ratio <= 1.3)
96
+
97
+ ## volume
98
+ df_vol = DataFrame()
99
+ for _vol_nam, _coe in vol_coe.items():
100
+ df_vol[_vol_nam] = df_mass_cal[_vol_nam] / _coe
101
+
102
+ if df_water is not None:
103
+ df_vol['ALWC'] = df_water
104
+ df_vol = df_vol.dropna()
105
+ df_vol['total_wet'] = df_vol.sum(axis=1, min_count=6)
106
+
107
+ df_vol['total_dry'] = df_vol[vol_coe.keys()].sum(axis=1, min_count=6)
108
+
109
+ ## density
110
+ df_vol_cal = DataFrame()
111
+ df_den_rec = df_mass['total'] / df_vol['total_dry']
112
+ if df_density is not None:
113
+ df_den_all = concat([df_all[['SO42-', 'NO3-', 'NH4+', 'EC']], df_density, df_mass['OM']], axis=1).dropna()
114
+
115
+ df_vol_cal = (df_den_all[['SO42-', 'NO3-', 'NH4+']].sum(axis=1) / 1.75) + \
116
+ df_den_all['Cl-'] / 1.52 + \
117
+ df_den_all['OM'] / 1.4 + df_den_all['EC'] / 1.77
118
+
119
+ df_den = df_den_all.sum(axis=1, min_count=6) / df_vol_cal
120
+ # df_den = df_den_all.sum(axis=1) / df_vol_cal
121
+ # df_den = df_mass['total'].loc[df_den_all.index] / df_vol_cal
122
+
123
+ ## refractive index
124
+ ri_dic = {}
125
+ for _lambda, _coe in RI_coe.items():
126
+
127
+ df_RI = DataFrame()
128
+
129
+ for _ky, _df in df_vol.items():
130
+ if 'total' in _ky: continue
131
+ df_RI[_ky] = (_df * _coe[_ky])
132
+
133
+ df_RI['RI_wet'] = None
134
+ if df_water is not None:
135
+ df_RI['RI_wet'] = (df_RI / df_vol['total_wet'].to_frame().values).sum(axis=1)
136
136
 
137
- df_RI['RI_dry'] = (df_RI[vol_coe.keys()] / df_vol['total_dry'].to_frame().values).sum(axis=1)
137
+ df_RI['RI_dry'] = (df_RI[vol_coe.keys()] / df_vol['total_dry'].to_frame().values).sum(axis=1)
138
138
 
139
- ri_dic[f'RI_{_lambda}'] = df_RI[['RI_dry', 'RI_wet']]
139
+ ri_dic[f'RI_{_lambda}'] = df_RI[['RI_dry', 'RI_wet']]
140
140
 
141
- ## mole and equivalent
142
- df_eq = concat((mol_A, mol_S, mol_N, mol_A * 1, mol_S * 2, mol_N * 1), axis=1)
143
- df_eq.columns = ['mol_NH4', 'mol_SO4', 'mol_NO3', 'eq_NH4', 'eq_SO4', 'eq_NO3', ]
141
+ ## mole and equivalent
142
+ df_eq = concat((mol_A, mol_S, mol_N, mol_A * 1, mol_S * 2, mol_N * 1), axis=1)
143
+ df_eq.columns = ['mol_NH4', 'mol_SO4', 'mol_NO3', 'eq_NH4', 'eq_SO4', 'eq_NO3', ]
144
144
 
145
- ## out
146
- out = {'mass': df_mass,
147
- 'volume': df_vol,
148
- 'vol_cal': df_vol_cal,
149
- 'eq': df_eq,
150
- 'density_mat': df_den,
151
- 'density_rec': df_den_rec,
152
- }
153
- out.update(ri_dic)
145
+ ## out
146
+ out = {'mass': df_mass,
147
+ 'volume': df_vol,
148
+ 'vol_cal': df_vol_cal,
149
+ 'eq': df_eq,
150
+ 'density_mat': df_den,
151
+ 'density_rec': df_den_rec,
152
+ }
153
+ out.update(ri_dic)
154
154
 
155
- for _ky, _df in out.items():
156
- out[_ky] = _df.reindex(index).where(qc_cond)
155
+ for _ky, _df in out.items():
156
+ out[_ky] = _df.reindex(index).where(qc_cond)
157
157
 
158
- return out
158
+ return out
159
159
 
160
160
 
161
161
  # '''
162
162
 
163
163
 
164
164
  def mass_ratio(_df):
165
- if _df['PM25'] >= _df['total_mass']:
166
- _df['others'] = _df['PM25'] - _df['total_mass']
167
- for _val, _species in zip(_df.values, _df.index):
168
- _df[f'{_species}_ratio'] = _val / _df['PM25'].__round__(3)
165
+ if _df['PM25'] >= _df['total_mass']:
166
+ _df['others'] = _df['PM25'] - _df['total_mass']
167
+ for _val, _species in zip(_df.values, _df.index):
168
+ _df[f'{_species}_ratio'] = _val / _df['PM25'].__round__(3)
169
169
 
170
- if _df['PM25'] < _df['total_mass']:
171
- _df['others'] = 0
172
- for _val, _species in zip(_df.values, _df.index):
173
- _df[f'{_species}_ratio'] = _val / _df['PM25'].__round__(3)
170
+ if _df['PM25'] < _df['total_mass']:
171
+ _df['others'] = 0
172
+ for _val, _species in zip(_df.values, _df.index):
173
+ _df[f'{_species}_ratio'] = _val / _df['PM25'].__round__(3)
174
174
 
175
- return _df['others':].drop(labels=['PM25_ratio', 'total_mass_ratio'])
175
+ return _df['others':].drop(labels=['PM25_ratio', 'total_mass_ratio'])
@@ -1,161 +1,161 @@
1
- from AeroViz.dataProcess.core import _union_index
2
-
3
- from pandas import date_range, concat, DataFrame, to_numeric
4
- from scipy.optimize import curve_fit
5
1
  import numpy as np
2
+ from pandas import concat, DataFrame
3
+ from scipy.optimize import curve_fit
4
+
5
+ from AeroViz.dataProcess.core import _union_index
6
6
 
7
7
  __all__ = [
8
- '_basic',
9
- # '_ocec_ratio_cal',
8
+ '_basic',
9
+ # '_ocec_ratio_cal',
10
10
  ]
11
11
 
12
12
 
13
13
  def _min_Rsq(_oc, _ec, _rng):
14
- _val_mesh, _oc_mesh = np.meshgrid(_rng, _oc)
15
- _val_mesh, _ec_mesh = np.meshgrid(_rng, _ec)
14
+ _val_mesh, _oc_mesh = np.meshgrid(_rng, _oc)
15
+ _val_mesh, _ec_mesh = np.meshgrid(_rng, _ec)
16
16
 
17
- _out_table = DataFrame(_oc_mesh - _val_mesh * _ec_mesh, index=_oc.index, columns=_rng)
17
+ _out_table = DataFrame(_oc_mesh - _val_mesh * _ec_mesh, index=_oc.index, columns=_rng)
18
18
 
19
- ## calculate R2
20
- _r2_dic = {}
21
- _func = lambda _x, _sl, _inte: _sl * _x + _inte
22
- for _ocec, _out in _out_table.items():
23
- _df = DataFrame([_out.values, _ec.values]).T.dropna()
19
+ ## calculate R2
20
+ _r2_dic = {}
21
+ _func = lambda _x, _sl, _inte: _sl * _x + _inte
22
+ for _ocec, _out in _out_table.items():
23
+ _df = DataFrame([_out.values, _ec.values]).T.dropna()
24
24
 
25
- _x, _y = _df[0], _df[1]
26
- _opt, _ = curve_fit(_func, _x, _y)
25
+ _x, _y = _df[0], _df[1]
26
+ _opt, _ = curve_fit(_func, _x, _y)
27
27
 
28
- _tss = np.sum((_y - _y.mean()) ** 2.)
29
- _rss = np.sum((_y - _func(_x, *_opt)) ** 2.)
28
+ _tss = np.sum((_y - _y.mean()) ** 2.)
29
+ _rss = np.sum((_y - _func(_x, *_opt)) ** 2.)
30
30
 
31
- _r2_dic[round(_ocec, 3)] = 1. - _rss / _tss
31
+ _r2_dic[round(_ocec, 3)] = 1. - _rss / _tss
32
32
 
33
- ## get the min R2
34
- _ratio = DataFrame(_r2_dic, index=[0]).idxmin(axis=1).values[0]
33
+ ## get the min R2
34
+ _ratio = DataFrame(_r2_dic, index=[0]).idxmin(axis=1).values[0]
35
35
 
36
- return _ratio, _out_table[_ratio]
36
+ return _ratio, _out_table[_ratio]
37
37
 
38
38
 
39
39
  def _ocec_ratio_cal(_nam, _lcres_splt, _hr_lim, _range_, _wisoc_range_):
40
- ## parameter
41
- _out = DataFrame(index=_lcres_splt.index)
42
- (_, _oc), (_, _ec) = _lcres_splt.items()
43
- # _oc, _ec = _lcres_splt['Thermal_OC'], _lcres_splt['Thermal_EC']
40
+ ## parameter
41
+ _out = DataFrame(index=_lcres_splt.index)
42
+ (_, _oc), (_, _ec) = _lcres_splt.items()
43
+ # _oc, _ec = _lcres_splt['Thermal_OC'], _lcres_splt['Thermal_EC']
44
44
 
45
- ## real data OC/EC
46
- _ocec_ratio_real = (_oc / _ec).quantile(.5)
45
+ ## real data OC/EC
46
+ _ocec_ratio_real = (_oc / _ec).quantile(.5)
47
47
 
48
- _out[f'OC/EC_real_{_nam}'] = _ocec_ratio_real
49
- _out[f'POC_real_{_nam}'] = _ocec_ratio_real * _ec
50
- _out[f'SOC_real_{_nam}'] = _oc - _out[f'POC_real_{_nam}']
48
+ _out[f'OC/EC_real_{_nam}'] = _ocec_ratio_real
49
+ _out[f'POC_real_{_nam}'] = _ocec_ratio_real * _ec
50
+ _out[f'SOC_real_{_nam}'] = _oc - _out[f'POC_real_{_nam}']
51
51
 
52
- ## the least R2 method
53
- ## estimated OC/EC
54
- if (len(_lcres_splt) <= _hr_lim):
55
- print(f"\t\t{_lcres_splt.index[0].strftime('%Y-%m-%d %X')} to {_lcres_splt.index[-1].strftime('%Y-%m-%d %X')}")
56
- print('\t\tPlease Modify the Values of "hour_limit" or Input Sufficient Amount of Data !!')
52
+ ## the least R2 method
53
+ ## estimated OC/EC
54
+ if (len(_lcres_splt) <= _hr_lim):
55
+ print(f"\t\t{_lcres_splt.index[0].strftime('%Y-%m-%d %X')} to {_lcres_splt.index[-1].strftime('%Y-%m-%d %X')}")
56
+ print('\t\tPlease Modify the Values of "hour_limit" or Input Sufficient Amount of Data !!')
57
57
 
58
- _out[[f'OC/EC_{_nam}', f'POC_{_nam}', f'SOC_{_nam}', f'WISOC/OC_{_nam}', f'WSOC_{_nam}',
59
- f'WISOC_{_nam}']] = np.nan
58
+ _out[[f'OC/EC_{_nam}', f'POC_{_nam}', f'SOC_{_nam}', f'WISOC/OC_{_nam}', f'WSOC_{_nam}',
59
+ f'WISOC_{_nam}']] = np.nan
60
60
 
61
- return _out
61
+ return _out
62
62
 
63
- if (len(_lcres_splt.dropna()) == 0):
64
- _out[[f'OC/EC_{_nam}', f'POC_{_nam}', f'SOC_{_nam}', f'WISOC/OC_{_nam}', f'WSOC_{_nam}',
65
- f'WISOC_{_nam}']] = np.nan
63
+ if (len(_lcres_splt.dropna()) == 0):
64
+ _out[[f'OC/EC_{_nam}', f'POC_{_nam}', f'SOC_{_nam}', f'WISOC/OC_{_nam}', f'WSOC_{_nam}',
65
+ f'WISOC_{_nam}']] = np.nan
66
66
 
67
- return _out
67
+ return _out
68
68
 
69
- ## OC/EC
70
- _ocec_ratio = False
71
- _st, _ed, _stp = _range_
69
+ ## OC/EC
70
+ _ocec_ratio = False
71
+ _st, _ed, _stp = _range_
72
72
 
73
- for _ in range(2):
74
- if _ocec_ratio:
75
- _ocec_rng = np.arange(_ocec_ratio - _stp / 2, _ocec_ratio + _stp / 2, .01).round(3)
76
- else:
77
- _ocec_rng = np.arange(_st, _ed + _stp, _stp).round(3)
73
+ for _ in range(2):
74
+ if _ocec_ratio:
75
+ _ocec_rng = np.arange(_ocec_ratio - _stp / 2, _ocec_ratio + _stp / 2, .01).round(3)
76
+ else:
77
+ _ocec_rng = np.arange(_st, _ed + _stp, _stp).round(3)
78
78
 
79
- _ocec_ratio, _soc = _min_Rsq(_oc, _ec, _ocec_rng)
79
+ _ocec_ratio, _soc = _min_Rsq(_oc, _ec, _ocec_rng)
80
80
 
81
- ## WISOC
82
- _st, _ed, _stp = _wisoc_range_
83
- _wisoc_rng = (np.arange(_st, _ed + _stp, _stp) * _ocec_ratio).round(5)
84
- _wisoc_ratio, _wsoc = _min_Rsq(_oc, _ec, _wisoc_rng)
81
+ ## WISOC
82
+ _st, _ed, _stp = _wisoc_range_
83
+ _wisoc_rng = (np.arange(_st, _ed + _stp, _stp) * _ocec_ratio).round(5)
84
+ _wisoc_ratio, _wsoc = _min_Rsq(_oc, _ec, _wisoc_rng)
85
85
 
86
- ## out
87
- _out[f'OC/EC_{_nam}'] = _ocec_ratio
88
- _out[f'SOC_{_nam}'] = _soc
89
- _out[f'POC_{_nam}'] = _oc - _out[f'SOC_{_nam}']
90
- _out[f'WISOC/OC_{_nam}'] = _wisoc_ratio
91
- _out[f'WSOC_{_nam}'] = _wsoc
92
- _out[f'WISOC_{_nam}'] = _oc - _out[f'WSOC_{_nam}']
86
+ ## out
87
+ _out[f'OC/EC_{_nam}'] = _ocec_ratio
88
+ _out[f'SOC_{_nam}'] = _soc
89
+ _out[f'POC_{_nam}'] = _oc - _out[f'SOC_{_nam}']
90
+ _out[f'WISOC/OC_{_nam}'] = _wisoc_ratio
91
+ _out[f'WSOC_{_nam}'] = _wsoc
92
+ _out[f'WISOC_{_nam}'] = _oc - _out[f'WSOC_{_nam}']
93
93
 
94
- return _out[[f'OC/EC_{_nam}', f'POC_{_nam}', f'SOC_{_nam}', f'WISOC/OC_{_nam}', f'WSOC_{_nam}', f'WISOC_{_nam}',
95
- f'OC/EC_real_{_nam}', f'POC_real_{_nam}', f'SOC_real_{_nam}']]
94
+ return _out[[f'OC/EC_{_nam}', f'POC_{_nam}', f'SOC_{_nam}', f'WISOC/OC_{_nam}', f'WSOC_{_nam}', f'WISOC_{_nam}',
95
+ f'OC/EC_real_{_nam}', f'POC_real_{_nam}', f'SOC_real_{_nam}']]
96
96
 
97
97
 
98
98
  def _basic(_lcres, _res, _mass, _ocec_ratio, _ocec_ratio_month, _hr_lim, _range, _wisoc_range):
99
- _lcres, _res, _mass = _union_index(_lcres, _res, _mass)
99
+ _lcres, _res, _mass = _union_index(_lcres, _res, _mass)
100
100
 
101
- _out = {}
101
+ _out = {}
102
102
 
103
- ## OC1, OC2, OC3, OC4, PC
104
- _df_bsc = _res / _lcres['Sample_Volume'].to_frame().values.copy()
103
+ ## OC1, OC2, OC3, OC4, PC
104
+ _df_bsc = _res / _lcres['Sample_Volume'].to_frame().values.copy()
105
105
 
106
- ## SOC, POC, OC/EC
107
- if _ocec_ratio is not None:
108
- try:
109
- iter(_ocec_ratio)
110
- except TypeError:
111
- raise TypeError('"ocec_ratio" Only Accept a Single Value !!')
106
+ ## SOC, POC, OC/EC
107
+ if _ocec_ratio is not None:
108
+ try:
109
+ iter(_ocec_ratio)
110
+ except TypeError:
111
+ raise TypeError('"ocec_ratio" Only Accept a Single Value !!')
112
112
 
113
- _prcs_df = DataFrame(index=_df_bsc.index)
114
- _prcs_df['OC/EC'] = _ocec_ratio
115
- _prcs_df['POC'] = _ocec_ratio * _lcres['Thermal_EC']
116
- _prcs_df['SOC'] = _lcres['Thermal_OC'] - _prcs_df['POC']
113
+ _prcs_df = DataFrame(index=_df_bsc.index)
114
+ _prcs_df['OC/EC'] = _ocec_ratio
115
+ _prcs_df['POC'] = _ocec_ratio * _lcres['Thermal_EC']
116
+ _prcs_df['SOC'] = _lcres['Thermal_OC'] - _prcs_df['POC']
117
117
 
118
- else:
119
- _df_lst = []
120
- for _, _df in _lcres.resample(f'{_ocec_ratio_month}MS', closed='left'):
121
- _thm_cal = _ocec_ratio_cal('thm', _df[['Thermal_OC', 'Thermal_EC']], _hr_lim, _range, _wisoc_range)
122
- _opt_cal = _ocec_ratio_cal('opt', _df[['Optical_OC', 'Optical_EC']], _hr_lim, _range, _wisoc_range)
123
- _df_lst.append(concat([_thm_cal, _opt_cal], axis=1))
118
+ else:
119
+ _df_lst = []
120
+ for _, _df in _lcres.resample(f'{_ocec_ratio_month}MS', closed='left'):
121
+ _thm_cal = _ocec_ratio_cal('thm', _df[['Thermal_OC', 'Thermal_EC']], _hr_lim, _range, _wisoc_range)
122
+ _opt_cal = _ocec_ratio_cal('opt', _df[['Optical_OC', 'Optical_EC']], _hr_lim, _range, _wisoc_range)
123
+ _df_lst.append(concat([_thm_cal, _opt_cal], axis=1))
124
124
 
125
- _prcs_df = concat(_df_lst)
125
+ _prcs_df = concat(_df_lst)
126
126
 
127
- _df_bsc = concat((_df_bsc.copy(), _prcs_df), axis=1)
127
+ _df_bsc = concat((_df_bsc.copy(), _prcs_df), axis=1)
128
128
 
129
- ## ratio
130
- _df_ratio = DataFrame(index=_df_bsc.index)
129
+ ## ratio
130
+ _df_ratio = DataFrame(index=_df_bsc.index)
131
131
 
132
- for _ky, _val in _df_bsc.items():
133
- if 'OC/EC' in _ky: continue
134
- _df_ratio[f'{_ky}/Thermal_OC'] = _val / _lcres['Thermal_OC']
135
- _df_ratio[f'{_ky}/Optical_OC'] = _val / _lcres['Optical_OC']
132
+ for _ky, _val in _df_bsc.items():
133
+ if 'OC/EC' in _ky: continue
134
+ _df_ratio[f'{_ky}/Thermal_OC'] = _val / _lcres['Thermal_OC']
135
+ _df_ratio[f'{_ky}/Optical_OC'] = _val / _lcres['Optical_OC']
136
136
 
137
- if _mass is not None:
138
- for _ky, _val in _df_bsc.items():
139
- _df_ratio[f'{_ky}/PM'] = _val / _mass
137
+ if _mass is not None:
138
+ for _ky, _val in _df_bsc.items():
139
+ _df_ratio[f'{_ky}/PM'] = _val / _mass
140
140
 
141
- _df_ratio[f'Thermal_OC/PM'] = _lcres['Thermal_OC'] / _mass
142
- _df_ratio[f'Thermal_EC/PM'] = _lcres['Thermal_EC'] / _mass
141
+ _df_ratio[f'Thermal_OC/PM'] = _lcres['Thermal_OC'] / _mass
142
+ _df_ratio[f'Thermal_EC/PM'] = _lcres['Thermal_EC'] / _mass
143
143
 
144
- _df_ratio[f'Optical_OC/PM'] = _lcres['Optical_OC'] / _mass
145
- _df_ratio[f'Optical_EC/PM'] = _lcres['Optical_EC'] / _mass
144
+ _df_ratio[f'Optical_OC/PM'] = _lcres['Optical_OC'] / _mass
145
+ _df_ratio[f'Optical_EC/PM'] = _lcres['Optical_EC'] / _mass
146
146
 
147
- ## ratio status
148
- _df_bsc = concat((_lcres, _df_bsc.copy()), axis=1)
147
+ ## ratio status
148
+ _df_bsc = concat((_lcres, _df_bsc.copy()), axis=1)
149
149
 
150
- for _ky, _df in _df_ratio.items():
151
- _df_bsc[f'{_ky}_status'] = 'Normal'
152
- _df_bsc[f'{_ky}_status'] = _df_bsc[f'{_ky}_status'].mask(_df > 1, 'Warning')
150
+ for _ky, _df in _df_ratio.items():
151
+ _df_bsc[f'{_ky}_status'] = 'Normal'
152
+ _df_bsc[f'{_ky}_status'] = _df_bsc[f'{_ky}_status'].mask(_df > 1, 'Warning')
153
153
 
154
- ## out
155
- _out['ratio'] = _df_ratio
156
- _out['basic'] = _df_bsc
154
+ ## out
155
+ _out['ratio'] = _df_ratio
156
+ _out['basic'] = _df_bsc
157
157
 
158
- return _out
158
+ return _out
159
159
 
160
160
 
161
161
  '''