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.
- AeroViz/__init__.py +4 -4
- AeroViz/dataProcess/Chemistry/__init__.py +38 -38
- AeroViz/dataProcess/Chemistry/_calculate.py +15 -15
- AeroViz/dataProcess/Chemistry/_isoropia.py +69 -68
- AeroViz/dataProcess/Chemistry/_mass_volume.py +158 -158
- AeroViz/dataProcess/Chemistry/_ocec.py +109 -109
- AeroViz/dataProcess/Chemistry/_partition.py +19 -18
- AeroViz/dataProcess/Chemistry/_teom.py +8 -11
- AeroViz/dataProcess/Optical/_IMPROVE.py +40 -39
- AeroViz/dataProcess/Optical/__init__.py +35 -35
- AeroViz/dataProcess/Optical/_absorption.py +35 -35
- AeroViz/dataProcess/Optical/_extinction.py +25 -24
- AeroViz/dataProcess/Optical/_mie.py +5 -6
- AeroViz/dataProcess/Optical/_mie_sd.py +89 -90
- AeroViz/dataProcess/Optical/_scattering.py +16 -16
- AeroViz/dataProcess/SizeDistr/__init__.py +37 -37
- AeroViz/dataProcess/SizeDistr/__merge.py +159 -158
- AeroViz/dataProcess/SizeDistr/_merge.py +155 -154
- AeroViz/dataProcess/SizeDistr/_merge_v1.py +162 -161
- AeroViz/dataProcess/SizeDistr/_merge_v2.py +153 -152
- AeroViz/dataProcess/SizeDistr/_merge_v3.py +326 -326
- AeroViz/dataProcess/SizeDistr/_merge_v4.py +272 -274
- AeroViz/dataProcess/SizeDistr/_size_distr.py +51 -51
- AeroViz/dataProcess/VOC/__init__.py +7 -7
- AeroViz/dataProcess/VOC/_potential_par.py +53 -55
- AeroViz/dataProcess/__init__.py +4 -4
- AeroViz/dataProcess/core/__init__.py +59 -58
- AeroViz/plot/__init__.py +6 -1
- AeroViz/plot/bar.py +126 -0
- AeroViz/plot/box.py +68 -0
- AeroViz/plot/distribution/distribution.py +421 -427
- AeroViz/plot/meteorology/meteorology.py +240 -292
- AeroViz/plot/optical/__init__.py +0 -1
- AeroViz/plot/optical/optical.py +230 -230
- AeroViz/plot/pie.py +198 -0
- AeroViz/plot/regression.py +210 -0
- AeroViz/plot/scatter.py +99 -0
- AeroViz/plot/templates/__init__.py +0 -3
- AeroViz/plot/templates/contour.py +25 -25
- AeroViz/plot/templates/corr_matrix.py +86 -93
- AeroViz/plot/templates/diurnal_pattern.py +24 -24
- AeroViz/plot/templates/koschmieder.py +106 -106
- AeroViz/plot/templates/metal_heatmap.py +34 -34
- AeroViz/plot/timeseries/timeseries.py +53 -60
- AeroViz/plot/utils/__init__.py +2 -1
- AeroViz/plot/utils/_color.py +57 -57
- AeroViz/plot/utils/_unit.py +48 -48
- AeroViz/plot/utils/plt_utils.py +92 -0
- AeroViz/plot/utils/sklearn_utils.py +49 -0
- AeroViz/plot/violin.py +79 -0
- AeroViz/process/__init__.py +15 -15
- AeroViz/process/core/DataProc.py +9 -9
- AeroViz/process/core/SizeDist.py +81 -81
- AeroViz/process/method/PyMieScatt_update.py +488 -488
- AeroViz/process/method/mie_theory.py +231 -229
- AeroViz/process/method/prop.py +40 -40
- AeroViz/process/script/AbstractDistCalc.py +103 -103
- AeroViz/process/script/Chemical.py +166 -166
- AeroViz/process/script/IMPACT.py +40 -40
- AeroViz/process/script/IMPROVE.py +152 -152
- AeroViz/process/script/Others.py +45 -45
- AeroViz/process/script/PSD.py +26 -26
- AeroViz/process/script/PSD_dry.py +69 -70
- AeroViz/process/script/retrieve_RI.py +50 -51
- AeroViz/rawDataReader/__init__.py +57 -57
- AeroViz/rawDataReader/core/__init__.py +328 -326
- AeroViz/rawDataReader/script/AE33.py +18 -18
- AeroViz/rawDataReader/script/AE43.py +20 -20
- AeroViz/rawDataReader/script/APS_3321.py +30 -30
- AeroViz/rawDataReader/script/Aurora.py +23 -23
- AeroViz/rawDataReader/script/BC1054.py +40 -40
- AeroViz/rawDataReader/script/EPA_vertical.py +9 -9
- AeroViz/rawDataReader/script/GRIMM.py +21 -21
- AeroViz/rawDataReader/script/IGAC_TH.py +67 -67
- AeroViz/rawDataReader/script/IGAC_ZM.py +59 -59
- AeroViz/rawDataReader/script/MA350.py +39 -39
- AeroViz/rawDataReader/script/NEPH.py +74 -74
- AeroViz/rawDataReader/script/OCEC_LCRES.py +21 -21
- AeroViz/rawDataReader/script/OCEC_RES.py +16 -16
- AeroViz/rawDataReader/script/SMPS_TH.py +25 -25
- AeroViz/rawDataReader/script/SMPS_aim11.py +32 -32
- AeroViz/rawDataReader/script/SMPS_genr.py +31 -31
- AeroViz/rawDataReader/script/TEOM.py +28 -28
- AeroViz/rawDataReader/script/Table.py +12 -12
- AeroViz/rawDataReader/script/VOC_TH.py +16 -16
- AeroViz/rawDataReader/script/VOC_ZM.py +28 -28
- AeroViz/rawDataReader/script/__init__.py +20 -20
- AeroViz/rawDataReader/utils/config.py +161 -161
- AeroViz/tools/database.py +65 -65
- AeroViz/tools/dataclassifier.py +106 -106
- AeroViz/tools/dataprinter.py +51 -51
- AeroViz/tools/datareader.py +38 -38
- {AeroViz-0.1.3.dist-info → AeroViz-0.1.3b0.dist-info}/METADATA +5 -4
- AeroViz-0.1.3b0.dist-info/RECORD +110 -0
- AeroViz/config/__init__.py +0 -0
- AeroViz/plot/improve/__init__.py +0 -1
- AeroViz/plot/improve/improve.py +0 -240
- AeroViz/plot/optical/aethalometer.py +0 -77
- AeroViz/plot/templates/event_evolution.py +0 -65
- AeroViz/plot/templates/regression.py +0 -256
- AeroViz/plot/templates/scatter.py +0 -130
- AeroViz/plot/templates/templates.py +0 -398
- AeroViz/plot/utils/_decorator.py +0 -74
- AeroViz-0.1.3.dist-info/RECORD +0 -111
- {AeroViz-0.1.3.dist-info → AeroViz-0.1.3b0.dist-info}/LICENSE +0 -0
- {AeroViz-0.1.3.dist-info → AeroViz-0.1.3b0.dist-info}/WHEEL +0 -0
- {AeroViz-0.1.3.dist-info → AeroViz-0.1.3b0.dist-info}/top_level.txt +0 -0
|
@@ -14,387 +14,389 @@ __all__ = ['AbstractReader']
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class AbstractReader(ABC):
|
|
17
|
-
|
|
17
|
+
nam = 'AbstractReader'
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
# initial config
|
|
20
|
+
# input : file path, reset switch
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
# list the file in the path and read pickle file if it exists, else read raw data and dump the pickle file the
|
|
23
|
+
# pickle file will be generated after read raw data first time, if you want to re-read the rawdata, please set
|
|
24
|
+
# 'reset=True'
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
def __init__(self, _path, QC=True, csv_raw=True, reset=False, rate=False, append_data=False, update_meta=None):
|
|
27
|
+
# logging.info(f'\n{self.nam}')
|
|
28
|
+
# print('='*65)
|
|
29
|
+
# logger.info(f"Reading file and process data")
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
# class parameter
|
|
32
|
+
# self.index = lambda _freq: date_range(_sta, _fin, freq=_freq)
|
|
33
|
+
self.path = Path(_path)
|
|
34
|
+
self.meta = meta[self.nam]
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
if update_meta is not None:
|
|
37
|
+
self.meta.update(update_meta)
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
self.reset = reset
|
|
40
|
+
self.rate = rate
|
|
41
|
+
self.qc = QC
|
|
42
|
+
self.csv = csv_raw
|
|
43
|
+
self.apnd = append_data & reset
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
self.pkl_nam = f'_read_{self.nam.lower()}.pkl'
|
|
46
|
+
self.csv_nam = f'_read_{self.nam.lower()}.csv'
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
self.pkl_nam_raw = f'_read_{self.nam.lower()}_raw.pkl'
|
|
49
|
+
self.csv_nam_raw = f'_read_{self.nam.lower()}_raw.csv'
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
self.csv_out = f'output_{self.nam.lower()}.csv'
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
# print(f" from {_sta.strftime('%Y-%m-%d %X')} to {_fin.strftime('%Y-%m-%d %X')}")
|
|
54
|
+
# print('='*65)
|
|
55
|
+
# print(f"{dtm.now().strftime('%m/%d %X')}")
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
# get data
|
|
58
|
+
def __call__(self,
|
|
59
|
+
start: dtm | None = None,
|
|
60
|
+
end: dtm | None = None,
|
|
61
|
+
mean_freq='1h',
|
|
62
|
+
csv_out=True,
|
|
63
|
+
**kwarg):
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
self._oth_set = kwarg
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
if start and end and end <= start:
|
|
68
|
+
raise ValueError(
|
|
69
|
+
f'\nPlease check out input time : '
|
|
70
|
+
f'\n\tstart : {start.strftime("%Y-%m-%d %X")}'
|
|
71
|
+
f'\n\tend : {end.strftime("%Y-%m-%d %X")}')
|
|
70
72
|
|
|
71
|
-
|
|
73
|
+
fout = self._run(start, end)
|
|
72
74
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
if fout is not None:
|
|
76
|
+
if mean_freq is not None:
|
|
77
|
+
fout = fout.resample(mean_freq).mean()
|
|
76
78
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
if csv_out:
|
|
80
|
+
fout.to_csv(self.path / self.csv_out)
|
|
79
81
|
|
|
80
|
-
|
|
82
|
+
return fout
|
|
81
83
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
# dependency injection function
|
|
85
|
+
@abstractmethod
|
|
86
|
+
def _raw_reader(self, _file):
|
|
87
|
+
# customize each instrument
|
|
88
|
+
pass
|
|
87
89
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
@abstractmethod
|
|
91
|
+
def _QC(self, df: DataFrame):
|
|
92
|
+
# customize each instrument
|
|
93
|
+
return df
|
|
92
94
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
95
|
+
# set each to true datetime(18:30:01 -> 18:30:00) and rindex data
|
|
96
|
+
def _raw_process(self, _df):
|
|
97
|
+
# get time from df and set time to whole time to create time index
|
|
98
|
+
_st, _ed = _df.index.sort_values()[[0, -1]]
|
|
99
|
+
_tm_index = date_range(_st.strftime('%Y%m%d %H00'),
|
|
100
|
+
(_ed + dtmdt(hours=1)).strftime('%Y%m%d %H00'),
|
|
101
|
+
freq=self.meta['freq'])
|
|
102
|
+
_tm_index.name = 'time'
|
|
101
103
|
|
|
102
|
-
|
|
104
|
+
return _df.apply(to_numeric, errors='coerce').resample(self.meta['freq']).mean().reindex(_tm_index)
|
|
103
105
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
# acquisition rate and yield rate
|
|
107
|
+
def _rate_calculate(self, _fout_raw, _fout_qc, _st_raw, _ed_raw):
|
|
106
108
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
if self.meta['deter_key'] is not None:
|
|
110
|
+
_start, _end = _fout_qc.index[[0, -1]]
|
|
109
111
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
+
_drop_how = 'any'
|
|
113
|
+
_the_size = len(_fout_raw.resample('1h').mean().index)
|
|
112
114
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
+
_f_pth = (self.path / f'{self.nam}.log')
|
|
116
|
+
_f = _f_pth.open('r+' if _f_pth.exists() else 'w+')
|
|
115
117
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
+
_cont = _f.read()
|
|
119
|
+
_f.seek(0)
|
|
118
120
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
_f.write(f"\n{dtm.now().strftime('%Y/%m/%d %X')}\n")
|
|
122
|
+
_f.write(f"{'-' * 60}\n")
|
|
123
|
+
_f.write(f"rawdata time : \n\t{_st_raw.strftime('%Y-%m-%d %X')} ~ {_ed_raw.strftime('%Y-%m-%d %X')}\n")
|
|
124
|
+
_f.write(f"output time : \n\t{_start.strftime('%Y-%m-%d %X')} ~ {_end.strftime('%Y-%m-%d %X')}\n")
|
|
125
|
+
_f.write(f"{'-' * 60}\n")
|
|
126
|
+
print(f"\n\t\tfrom {_start.strftime('%Y-%m-%d %X')} to {_end.strftime('%Y-%m-%d %X')}\n")
|
|
125
127
|
|
|
126
|
-
|
|
128
|
+
for _nam, _key in self.meta['deter_key'].items():
|
|
127
129
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
+
if _key == ['all']:
|
|
131
|
+
_key, _drop_how = _fout_qc.keys(), 'all'
|
|
130
132
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
+
_real_size = len(_fout_raw[_key].resample('1h').mean().copy().dropna(how=_drop_how).index)
|
|
134
|
+
_QC_size = len(_fout_qc[_key].resample('1h').mean().copy().dropna(how=_drop_how).index)
|
|
133
135
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
try:
|
|
137
|
+
_acq_rate = round((_real_size / _the_size) * 100, 1)
|
|
138
|
+
_yid_rate = round((_QC_size / _real_size) * 100, 1)
|
|
139
|
+
except ZeroDivisionError:
|
|
140
|
+
_acq_rate, _yid_rate = 0, 0
|
|
139
141
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
142
|
+
_f.write(f'{_nam} : \n')
|
|
143
|
+
_f.write(f"\tacquisition rate : {_acq_rate}%\n")
|
|
144
|
+
_f.write(f'\tyield rate : {_yid_rate}%\n')
|
|
143
145
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
146
|
+
print(f'\t\t{_nam} : ')
|
|
147
|
+
print(f'\t\t\tacquisition rate : \033[91m{_acq_rate}%\033[0m')
|
|
148
|
+
print(f'\t\t\tyield rate : \033[91m{_yid_rate}%\033[0m')
|
|
147
149
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
+
_f.write(f"{'=' * 40}\n")
|
|
151
|
+
_f.write(_cont)
|
|
150
152
|
|
|
151
|
-
|
|
153
|
+
_f.close()
|
|
152
154
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
155
|
+
# process time index
|
|
156
|
+
@staticmethod
|
|
157
|
+
def _tmidx_process(_start, _end, _df):
|
|
158
|
+
_st, _ed = _df.index.sort_values()[[0, -1]]
|
|
159
|
+
_start, _end = to_datetime(_start) or _st, to_datetime(_end) or _ed
|
|
160
|
+
_idx = date_range(_start, _end, freq=_df.index.freq.copy())
|
|
161
|
+
_idx.name = 'time'
|
|
160
162
|
|
|
161
|
-
|
|
163
|
+
return _df.reindex(_idx), _st, _ed
|
|
162
164
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
165
|
+
# append new data to exist pkl
|
|
166
|
+
@staticmethod
|
|
167
|
+
def _apnd_prcs(_df_done, _df_apnd):
|
|
166
168
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
+
if _df_apnd is not None:
|
|
170
|
+
_df = concat([_df_apnd.dropna(how='all').copy(), _df_done.dropna(how='all').copy()])
|
|
169
171
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
+
_idx = date_range(*_df.index.sort_values()[[0, -1]], freq=_df_done.index.freq.copy())
|
|
173
|
+
_idx.name = 'time'
|
|
172
174
|
|
|
173
|
-
|
|
175
|
+
return _df.loc[~_df.index.duplicated()].copy().reindex(_idx)
|
|
174
176
|
|
|
175
|
-
|
|
177
|
+
return _df_done
|
|
176
178
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
+
# remove outlier
|
|
180
|
+
def _outlier_prcs(self, _df):
|
|
179
181
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
+
if (self.path / 'outlier.json') not in self.path.glob('*.json'):
|
|
183
|
+
return _df
|
|
182
184
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
+
with (self.path / 'outlier.json').open('r', encoding='utf-8', errors='ignore') as f:
|
|
186
|
+
self.outlier = jsn.load(f)
|
|
185
187
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
+
for _st, _ed in self.outlier.values():
|
|
189
|
+
_df.loc[_st:_ed] = np.nan
|
|
188
190
|
|
|
189
|
-
|
|
191
|
+
return _df
|
|
190
192
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
193
|
+
# save pickle file
|
|
194
|
+
def _save_dt(self, _save_raw, _save_qc):
|
|
195
|
+
# dump pickle file
|
|
196
|
+
_check = True
|
|
197
|
+
while _check:
|
|
198
|
+
try:
|
|
199
|
+
with (self.path / self.pkl_nam).open('wb') as f:
|
|
200
|
+
pkl.dump(_save_qc, f, protocol=pkl.HIGHEST_PROTOCOL)
|
|
199
201
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
202
|
+
# dump csv file
|
|
203
|
+
if self.csv:
|
|
204
|
+
_save_qc.to_csv(self.path / self.csv_nam)
|
|
203
205
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
206
|
+
# output raw data if qc file
|
|
207
|
+
if self.meta['deter_key'] is not None:
|
|
208
|
+
with (self.path / self.pkl_nam_raw).open('wb') as f:
|
|
209
|
+
pkl.dump(_save_raw, f, protocol=pkl.HIGHEST_PROTOCOL)
|
|
208
210
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
+
if self.csv:
|
|
212
|
+
_save_raw.to_csv(self.path / self.csv_nam_raw)
|
|
211
213
|
|
|
212
|
-
|
|
214
|
+
_check = False
|
|
213
215
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
216
|
+
except PermissionError as _err:
|
|
217
|
+
print('\n', _err)
|
|
218
|
+
input('\t\t\33[41m Please Close The File And Press "Enter" \33[0m\n')
|
|
217
219
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
# read pickle file
|
|
221
|
+
def _read_pkl(self, ):
|
|
222
|
+
with (self.path / self.pkl_nam).open('rb') as f:
|
|
223
|
+
_fout_qc = pkl.load(f)
|
|
222
224
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
225
|
+
if (self.path / self.pkl_nam_raw).exists():
|
|
226
|
+
with (self.path / self.pkl_nam_raw).open('rb') as f:
|
|
227
|
+
_fout_raw = pkl.load(f)
|
|
228
|
+
else:
|
|
229
|
+
_fout_raw = _fout_qc
|
|
228
230
|
|
|
229
|
-
|
|
231
|
+
return _fout_raw, _fout_qc
|
|
230
232
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
233
|
+
# read raw data
|
|
234
|
+
def _read_raw(self, ):
|
|
235
|
+
pattern = self.meta['pattern']
|
|
236
|
+
patterns = {pattern, pattern.lower(), pattern.upper()}
|
|
237
|
+
_df_con, _f_list = None, list(chain.from_iterable(self.path.glob(p) for p in patterns))
|
|
236
238
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
239
|
+
for file in _f_list:
|
|
240
|
+
if file.name in [self.csv_out, self.csv_nam, self.csv_nam_raw, f'{self.nam}.log']:
|
|
241
|
+
continue
|
|
242
|
+
|
|
243
|
+
print(f"\r\t\treading {file.name}", end='')
|
|
244
|
+
|
|
245
|
+
_df = self._raw_reader(file)
|
|
246
|
+
|
|
247
|
+
# concat the concated list
|
|
248
|
+
if _df is not None:
|
|
249
|
+
_df_con = concat([_df_con, _df]) if _df_con is not None else _df
|
|
250
|
+
|
|
251
|
+
if _df_con is None:
|
|
252
|
+
print(f"\t\t\033[31mNo File in '{self.path}' Could Read, Please Check Out the Current Path\033[0m")
|
|
253
|
+
return None, None
|
|
254
|
+
|
|
255
|
+
# QC
|
|
256
|
+
_fout_raw = self._raw_process(_df_con)
|
|
257
|
+
_fout_qc = self._QC(_fout_raw)
|
|
258
|
+
|
|
259
|
+
return _fout_raw, _fout_qc
|
|
260
|
+
|
|
261
|
+
# main flow
|
|
262
|
+
def _run(self, _start, _end):
|
|
263
|
+
|
|
264
|
+
_f_raw_done, _f_qc_done = None, None
|
|
265
|
+
|
|
266
|
+
# read pickle if pickle file exists and 'reset=False' or process raw data or append new data
|
|
267
|
+
_pkl_exist = self.path / self.pkl_nam in list(self.path.glob('*.pkl'))
|
|
268
|
+
if _pkl_exist & ((~self.reset) | self.apnd):
|
|
269
|
+
print(f"\n\t{dtm.now().strftime('%m/%d %X')} : Reading \033[96mPICKLE\033[0m file of {self.nam}")
|
|
270
|
+
|
|
271
|
+
_f_raw_done, _f_qc_done = self._read_pkl()
|
|
272
|
+
|
|
273
|
+
if not self.apnd:
|
|
274
|
+
_f_raw_done, _start_raw, _end_raw = self._tmidx_process(_start, _end, _f_raw_done)
|
|
275
|
+
_f_qc_done, _start_raw, _end_raw = self._tmidx_process(_start, _end, _f_qc_done)
|
|
276
|
+
|
|
277
|
+
_f_qc_done = self._outlier_prcs(_f_qc_done)
|
|
278
|
+
|
|
279
|
+
if self.rate:
|
|
280
|
+
self._rate_calculate(_f_raw_done, _f_qc_done, _start_raw, _end_raw)
|
|
281
|
+
|
|
282
|
+
return _f_qc_done if self.qc else _f_raw_done
|
|
283
|
+
|
|
284
|
+
# read raw data
|
|
285
|
+
print(f"\n\t{dtm.now().strftime('%m/%d %X')} : Reading \033[96mRAW DATA\033[0m of {self.nam} and process it")
|
|
286
|
+
|
|
287
|
+
_f_raw, _f_qc = self._read_raw()
|
|
288
|
+
if _f_raw is None:
|
|
289
|
+
return None
|
|
290
|
+
|
|
291
|
+
# append new data and pickle data
|
|
292
|
+
if self.apnd & _pkl_exist:
|
|
293
|
+
_f_raw = self._apnd_prcs(_f_raw_done, _f_raw)
|
|
294
|
+
_f_qc = self._apnd_prcs(_f_qc_done, _f_qc)
|
|
295
|
+
|
|
296
|
+
_f_qc = self._outlier_prcs(_f_qc)
|
|
297
|
+
|
|
298
|
+
# save
|
|
299
|
+
self._save_dt(_f_raw, _f_qc)
|
|
300
|
+
|
|
301
|
+
# process time index
|
|
302
|
+
# if (_start is not None)|(_end is not None):
|
|
303
|
+
_f_raw, _start_raw, _end_raw = self._tmidx_process(_start, _end, _f_raw)
|
|
304
|
+
_f_qc, _start_raw, _end_raw = self._tmidx_process(_start, _end, _f_qc)
|
|
305
|
+
|
|
306
|
+
self._rate_calculate(_f_raw, _f_qc, _start_raw, _end_raw)
|
|
307
|
+
|
|
308
|
+
return _f_qc if self.qc else _f_raw
|
|
309
|
+
|
|
310
|
+
# -------------------------------------------------------------------------------------
|
|
311
|
+
# old flow
|
|
312
|
+
# def __run(self, _start, _end):
|
|
313
|
+
#
|
|
314
|
+
# ## read pickle if pickle file exists and 'reset=False' or process raw data
|
|
315
|
+
# if (self.path / self.pkl_nam in list(self.path.glob('*.pkl'))) & (~self.reset):
|
|
316
|
+
# print(f"\n\t{dtm.now().strftime('%m/%d %X')} : Reading \033[96mPICKLE\033[0m file of {self.nam}")
|
|
317
|
+
#
|
|
318
|
+
# with (self.path / self.pkl_nam).open('rb') as f:
|
|
319
|
+
# _fout_qc = pkl.load(f)
|
|
320
|
+
#
|
|
321
|
+
# _exist = (self.path / self.pkl_nam_raw).exists()
|
|
322
|
+
# if _exist:
|
|
323
|
+
# with (self.path / self.pkl_nam_raw).open('rb') as f:
|
|
324
|
+
# _fout_raw = pkl.load(f)
|
|
325
|
+
# else:
|
|
326
|
+
# _fout_raw = _fout_qc
|
|
327
|
+
#
|
|
328
|
+
# _start, _end = to_datetime(_start) or _fout_qc.index[0], to_datetime(_end) or _fout_qc.index[-1]
|
|
329
|
+
# _idx = date_range(_start, _end, freq=_fout_qc.index.freq.copy())
|
|
330
|
+
# _idx.name = 'time'
|
|
331
|
+
#
|
|
332
|
+
# _fout_raw, _fout_qc = _fout_raw.reindex(_idx), _fout_qc.reindex(_idx)
|
|
333
|
+
# if (self.rate) & (_exist):
|
|
334
|
+
# self._rate_calculate(_fout_raw, _fout_qc)
|
|
335
|
+
#
|
|
336
|
+
# return _fout_qc if self.qc else _fout_raw
|
|
337
|
+
# else:
|
|
338
|
+
# print(
|
|
339
|
+
# f"\n\t{dtm.now().strftime('%m/%d %X')} : Reading \033[96mRAW DATA\033[0m of {self.nam} and process it")
|
|
340
|
+
#
|
|
341
|
+
# ##=================================================================================================================
|
|
342
|
+
# ## read raw data
|
|
343
|
+
# _df_con, _f_list = None, list(self.path.glob(self.meta['pattern']))
|
|
344
|
+
#
|
|
345
|
+
# if len(_f_list) == 0:
|
|
346
|
+
# print(f"\t\t\033[31mNo File in '{self.path}' Could Read, Please Check Out the Current Path\033[0m")
|
|
347
|
+
# return None
|
|
348
|
+
#
|
|
349
|
+
# for file in _f_list:
|
|
350
|
+
# if file.name in [self.csv_out, self.csv_nam, self.csv_nam_raw, f'{self.nam}.log']: continue
|
|
351
|
+
#
|
|
352
|
+
# print(f"\r\t\treading {file.name}", end='')
|
|
353
|
+
#
|
|
354
|
+
# _df = self._raw_reader(file)
|
|
355
|
+
#
|
|
356
|
+
# ## concat the concated list
|
|
357
|
+
# if _df is not None:
|
|
358
|
+
# _df_con = concat([_df_con, _df]) if _df_con is not None else _df
|
|
359
|
+
# print()
|
|
360
|
+
#
|
|
361
|
+
# ## QC
|
|
362
|
+
# _save_raw = self._raw_process(_df_con)
|
|
363
|
+
# _save_qc = self._QC(_save_raw)
|
|
364
|
+
#
|
|
365
|
+
# _start, _end = to_datetime(_start) or _save_raw.index[0], to_datetime(_end) or _save_raw.index[-1]
|
|
366
|
+
# _idx = date_range(_start, _end, freq=_save_raw.index.freq.copy())
|
|
367
|
+
# _idx.name = 'time'
|
|
368
|
+
#
|
|
369
|
+
# _fout_raw, _fout_qc = _save_raw.reindex(_idx).copy(), _save_qc.reindex(_idx).copy()
|
|
370
|
+
#
|
|
371
|
+
# self._rate_calculate(_fout_raw, _fout_qc)
|
|
372
|
+
#
|
|
373
|
+
# ##=================================================================================================================
|
|
374
|
+
# ## dump pickle file
|
|
375
|
+
# _check = True
|
|
376
|
+
# while _check:
|
|
377
|
+
#
|
|
378
|
+
# try:
|
|
379
|
+
# with (self.path / self.pkl_nam).open('wb') as f:
|
|
380
|
+
# pkl.dump(_save_qc, f, protocol=pkl.HIGHEST_PROTOCOL)
|
|
381
|
+
#
|
|
382
|
+
# ## dump csv file
|
|
383
|
+
# if self.csv:
|
|
384
|
+
# _save_qc.to_csv(self.path / self.csv_nam)
|
|
385
|
+
#
|
|
386
|
+
# ## output raw data if qc file
|
|
387
|
+
# if self.meta['deter_key'] is not None:
|
|
388
|
+
# with (self.path / self.pkl_nam_raw).open('wb') as f:
|
|
389
|
+
# pkl.dump(_save_raw, f, protocol=pkl.HIGHEST_PROTOCOL)
|
|
390
|
+
#
|
|
391
|
+
# if self.csv:
|
|
392
|
+
# _save_raw.to_csv(self.path / self.csv_nam_raw)
|
|
393
|
+
#
|
|
394
|
+
# return _fout_qc if self.qc else _fout_raw
|
|
395
|
+
#
|
|
396
|
+
# _check = False
|
|
397
|
+
#
|
|
398
|
+
# except PermissionError as _err:
|
|
399
|
+
# print('\n', _err)
|
|
400
|
+
# input('\t\t\33[41m Please Close The File And Press "Enter" \33[0m\n')
|
|
401
|
+
#
|
|
402
|
+
# return _fout_qc
|