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
@@ -14,387 +14,389 @@ __all__ = ['AbstractReader']
14
14
 
15
15
 
16
16
  class AbstractReader(ABC):
17
- nam = 'AbstractReader'
17
+ nam = 'AbstractReader'
18
18
 
19
- # initial config
20
- # input : file path, reset switch
19
+ # initial config
20
+ # input : file path, reset switch
21
21
 
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'
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
- 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")
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
- # class parameter
32
- # self.index = lambda _freq: date_range(_sta, _fin, freq=_freq)
33
- self.path = Path(_path)
34
- self.meta = meta[self.nam]
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
- if update_meta is not None:
37
- self.meta.update(update_meta)
36
+ if update_meta is not None:
37
+ self.meta.update(update_meta)
38
38
 
39
- self.reset = reset
40
- self.rate = rate
41
- self.qc = QC
42
- self.csv = csv_raw
43
- self.apnd = append_data & reset
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
- self.pkl_nam = f'_read_{self.nam.lower()}.pkl'
46
- self.csv_nam = f'_read_{self.nam.lower()}.csv'
45
+ self.pkl_nam = f'_read_{self.nam.lower()}.pkl'
46
+ self.csv_nam = f'_read_{self.nam.lower()}.csv'
47
47
 
48
- self.pkl_nam_raw = f'_read_{self.nam.lower()}_raw.pkl'
49
- self.csv_nam_raw = f'_read_{self.nam.lower()}_raw.csv'
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
- self.csv_out = f'output_{self.nam.lower()}.csv'
51
+ self.csv_out = f'output_{self.nam.lower()}.csv'
52
52
 
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')}")
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
- # 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):
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
- self._oth_set = kwarg
65
+ self._oth_set = kwarg
66
66
 
67
- if start and end and end <= start:
68
- raise ValueError(
69
- f'\nPlease check out input time : \n\tstart : {start.strftime("%Y-%m-%d %X")}\n\tend : {end.strftime("%Y-%m-%d %X")}')
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
- fout = self._run(start, end)
73
+ fout = self._run(start, end)
72
74
 
73
- if fout is not None:
74
- if mean_freq is not None:
75
- fout = fout.resample(mean_freq).mean()
75
+ if fout is not None:
76
+ if mean_freq is not None:
77
+ fout = fout.resample(mean_freq).mean()
76
78
 
77
- if csv_out:
78
- fout.to_csv(self.path / self.csv_out)
79
+ if csv_out:
80
+ fout.to_csv(self.path / self.csv_out)
79
81
 
80
- return fout
82
+ return fout
81
83
 
82
- # dependency injection function
83
- @abstractmethod
84
- def _raw_reader(self, _file):
85
- # customize each instrument
86
- pass
84
+ # dependency injection function
85
+ @abstractmethod
86
+ def _raw_reader(self, _file):
87
+ # customize each instrument
88
+ pass
87
89
 
88
- @abstractmethod
89
- def _QC(self, df: DataFrame):
90
- # customize each instrument
91
- return df
90
+ @abstractmethod
91
+ def _QC(self, df: DataFrame):
92
+ # customize each instrument
93
+ return df
92
94
 
93
- # set each to true datetime(18:30:01 -> 18:30:00) and rindex data
94
- def _raw_process(self, _df):
95
- # get time from df and set time to whole time to create time index
96
- _st, _ed = _df.index.sort_values()[[0, -1]]
97
- _tm_index = date_range(_st.strftime('%Y%m%d %H00'),
98
- (_ed + dtmdt(hours=1)).strftime('%Y%m%d %H00'),
99
- freq=self.meta['freq'])
100
- _tm_index.name = 'time'
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
- return _df.apply(to_numeric, errors='coerce').resample(self.meta['freq']).mean().reindex(_tm_index)
104
+ return _df.apply(to_numeric, errors='coerce').resample(self.meta['freq']).mean().reindex(_tm_index)
103
105
 
104
- # acquisition rate and yield rate
105
- def _rate_calculate(self, _fout_raw, _fout_qc, _st_raw, _ed_raw):
106
+ # acquisition rate and yield rate
107
+ def _rate_calculate(self, _fout_raw, _fout_qc, _st_raw, _ed_raw):
106
108
 
107
- if self.meta['deter_key'] is not None:
108
- _start, _end = _fout_qc.index[[0, -1]]
109
+ if self.meta['deter_key'] is not None:
110
+ _start, _end = _fout_qc.index[[0, -1]]
109
111
 
110
- _drop_how = 'any'
111
- _the_size = len(_fout_raw.resample('1h').mean().index)
112
+ _drop_how = 'any'
113
+ _the_size = len(_fout_raw.resample('1h').mean().index)
112
114
 
113
- _f_pth = (self.path / f'{self.nam}.log')
114
- _f = _f_pth.open('r+' if _f_pth.exists() else 'w+')
115
+ _f_pth = (self.path / f'{self.nam}.log')
116
+ _f = _f_pth.open('r+' if _f_pth.exists() else 'w+')
115
117
 
116
- _cont = _f.read()
117
- _f.seek(0)
118
+ _cont = _f.read()
119
+ _f.seek(0)
118
120
 
119
- _f.write(f"\n{dtm.now().strftime('%Y/%m/%d %X')}\n")
120
- _f.write(f"{'-' * 60}\n")
121
- _f.write(f"rawdata time : \n\t{_st_raw.strftime('%Y-%m-%d %X')} ~ {_ed_raw.strftime('%Y-%m-%d %X')}\n")
122
- _f.write(f"output time : \n\t{_start.strftime('%Y-%m-%d %X')} ~ {_end.strftime('%Y-%m-%d %X')}\n")
123
- _f.write(f"{'-' * 60}\n")
124
- print(f"\n\t\tfrom {_start.strftime('%Y-%m-%d %X')} to {_end.strftime('%Y-%m-%d %X')}\n")
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
- for _nam, _key in self.meta['deter_key'].items():
128
+ for _nam, _key in self.meta['deter_key'].items():
127
129
 
128
- if _key == ['all']:
129
- _key, _drop_how = _fout_qc.keys(), 'all'
130
+ if _key == ['all']:
131
+ _key, _drop_how = _fout_qc.keys(), 'all'
130
132
 
131
- _real_size = len(_fout_raw[_key].resample('1h').mean().copy().dropna(how=_drop_how).index)
132
- _QC_size = len(_fout_qc[_key].resample('1h').mean().copy().dropna(how=_drop_how).index)
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
- try:
135
- _acq_rate = round((_real_size / _the_size) * 100, 1)
136
- _yid_rate = round((_QC_size / _real_size) * 100, 1)
137
- except ZeroDivisionError:
138
- _acq_rate, _yid_rate = 0, 0
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
- _f.write(f'{_nam} : \n')
141
- _f.write(f"\tacquisition rate : {_acq_rate}%\n")
142
- _f.write(f'\tyield rate : {_yid_rate}%\n')
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
- print(f'\t\t{_nam} : ')
145
- print(f'\t\t\tacquisition rate : \033[91m{_acq_rate}%\033[0m')
146
- print(f'\t\t\tyield rate : \033[91m{_yid_rate}%\033[0m')
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
- _f.write(f"{'=' * 40}\n")
149
- _f.write(_cont)
150
+ _f.write(f"{'=' * 40}\n")
151
+ _f.write(_cont)
150
152
 
151
- _f.close()
153
+ _f.close()
152
154
 
153
- # process time index
154
- @staticmethod
155
- def _tmidx_process(_start, _end, _df):
156
- _st, _ed = _df.index.sort_values()[[0, -1]]
157
- _start, _end = to_datetime(_start) or _st, to_datetime(_end) or _ed
158
- _idx = date_range(_start, _end, freq=_df.index.freq.copy())
159
- _idx.name = 'time'
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
- return _df.reindex(_idx), _st, _ed
163
+ return _df.reindex(_idx), _st, _ed
162
164
 
163
- # append new data to exist pkl
164
- @staticmethod
165
- def _apnd_prcs(_df_done, _df_apnd):
165
+ # append new data to exist pkl
166
+ @staticmethod
167
+ def _apnd_prcs(_df_done, _df_apnd):
166
168
 
167
- if _df_apnd is not None:
168
- _df = concat([_df_apnd.dropna(how='all').copy(), _df_done.dropna(how='all').copy()])
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
- _idx = date_range(*_df.index.sort_values()[[0, -1]], freq=_df_done.index.freq.copy())
171
- _idx.name = 'time'
172
+ _idx = date_range(*_df.index.sort_values()[[0, -1]], freq=_df_done.index.freq.copy())
173
+ _idx.name = 'time'
172
174
 
173
- return _df.loc[~_df.index.duplicated()].copy().reindex(_idx)
175
+ return _df.loc[~_df.index.duplicated()].copy().reindex(_idx)
174
176
 
175
- return _df_done
177
+ return _df_done
176
178
 
177
- # remove outlier
178
- def _outlier_prcs(self, _df):
179
+ # remove outlier
180
+ def _outlier_prcs(self, _df):
179
181
 
180
- if (self.path / 'outlier.json') not in self.path.glob('*.json'):
181
- return _df
182
+ if (self.path / 'outlier.json') not in self.path.glob('*.json'):
183
+ return _df
182
184
 
183
- with (self.path / 'outlier.json').open('r', encoding='utf-8', errors='ignore') as f:
184
- self.outlier = jsn.load(f)
185
+ with (self.path / 'outlier.json').open('r', encoding='utf-8', errors='ignore') as f:
186
+ self.outlier = jsn.load(f)
185
187
 
186
- for _st, _ed in self.outlier.values():
187
- _df.loc[_st:_ed] = np.nan
188
+ for _st, _ed in self.outlier.values():
189
+ _df.loc[_st:_ed] = np.nan
188
190
 
189
- return _df
191
+ return _df
190
192
 
191
- # save pickle file
192
- def _save_dt(self, _save_raw, _save_qc):
193
- # dump pickle file
194
- _check = True
195
- while _check:
196
- try:
197
- with (self.path / self.pkl_nam).open('wb') as f:
198
- pkl.dump(_save_qc, f, protocol=pkl.HIGHEST_PROTOCOL)
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
- # dump csv file
201
- if self.csv:
202
- _save_qc.to_csv(self.path / self.csv_nam)
202
+ # dump csv file
203
+ if self.csv:
204
+ _save_qc.to_csv(self.path / self.csv_nam)
203
205
 
204
- # output raw data if qc file
205
- if self.meta['deter_key'] is not None:
206
- with (self.path / self.pkl_nam_raw).open('wb') as f:
207
- pkl.dump(_save_raw, f, protocol=pkl.HIGHEST_PROTOCOL)
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
- if self.csv:
210
- _save_raw.to_csv(self.path / self.csv_nam_raw)
211
+ if self.csv:
212
+ _save_raw.to_csv(self.path / self.csv_nam_raw)
211
213
 
212
- _check = False
214
+ _check = False
213
215
 
214
- except PermissionError as _err:
215
- print('\n', _err)
216
- input('\t\t\33[41m Please Close The File And Press "Enter" \33[0m\n')
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
- # read pickle file
219
- def _read_pkl(self, ):
220
- with (self.path / self.pkl_nam).open('rb') as f:
221
- _fout_qc = pkl.load(f)
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
- if (self.path / self.pkl_nam_raw).exists():
224
- with (self.path / self.pkl_nam_raw).open('rb') as f:
225
- _fout_raw = pkl.load(f)
226
- else:
227
- _fout_raw = _fout_qc
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
- return _fout_raw, _fout_qc
231
+ return _fout_raw, _fout_qc
230
232
 
231
- # read raw data
232
- def _read_raw(self, ):
233
- pattern = self.meta['pattern']
234
- patterns = {pattern, pattern.lower(), pattern.upper()}
235
- _df_con, _f_list = None, list(chain.from_iterable(self.path.glob(p) for p in patterns))
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
- for file in _f_list:
238
- if file.name in [self.csv_out, self.csv_nam, self.csv_nam_raw, f'{self.nam}.log']:
239
- continue
240
-
241
- print(f"\r\t\treading {file.name}", end='')
242
-
243
- _df = self._raw_reader(file)
244
-
245
- # concat the concated list
246
- if _df is not None:
247
- _df_con = concat([_df_con, _df]) if _df_con is not None else _df
248
-
249
- if _df_con is None:
250
- print(f"\t\t\033[31mNo File in '{self.path}' Could Read, Please Check Out the Current Path\033[0m")
251
- return None, None
252
-
253
- # QC
254
- _fout_raw = self._raw_process(_df_con)
255
- _fout_qc = self._QC(_fout_raw)
256
-
257
- return _fout_raw, _fout_qc
258
-
259
- # main flow
260
- def _run(self, _start, _end):
261
-
262
- _f_raw_done, _f_qc_done = None, None
263
-
264
- # read pickle if pickle file exists and 'reset=False' or process raw data or append new data
265
- _pkl_exist = self.path / self.pkl_nam in list(self.path.glob('*.pkl'))
266
- if _pkl_exist & ((~self.reset) | self.apnd):
267
- print(f"\n\t{dtm.now().strftime('%m/%d %X')} : Reading \033[96mPICKLE\033[0m file of {self.nam}")
268
-
269
- _f_raw_done, _f_qc_done = self._read_pkl()
270
-
271
- if not self.apnd:
272
- _f_raw_done, _start_raw, _end_raw = self._tmidx_process(_start, _end, _f_raw_done)
273
- _f_qc_done, _start_raw, _end_raw = self._tmidx_process(_start, _end, _f_qc_done)
274
-
275
- _f_qc_done = self._outlier_prcs(_f_qc_done)
276
-
277
- if self.rate:
278
- self._rate_calculate(_f_raw_done, _f_qc_done, _start_raw, _end_raw)
279
-
280
- return _f_qc_done if self.qc else _f_raw_done
281
-
282
- # read raw data
283
- print(f"\n\t{dtm.now().strftime('%m/%d %X')} : Reading \033[96mRAW DATA\033[0m of {self.nam} and process it")
284
-
285
- _f_raw, _f_qc = self._read_raw()
286
- if _f_raw is None:
287
- return None
288
-
289
- # append new data and pickle data
290
- if self.apnd & _pkl_exist:
291
- _f_raw = self._apnd_prcs(_f_raw_done, _f_raw)
292
- _f_qc = self._apnd_prcs(_f_qc_done, _f_qc)
293
-
294
- _f_qc = self._outlier_prcs(_f_qc)
295
-
296
- # save
297
- self._save_dt(_f_raw, _f_qc)
298
-
299
- # process time index
300
- # if (_start is not None)|(_end is not None):
301
- _f_raw, _start_raw, _end_raw = self._tmidx_process(_start, _end, _f_raw)
302
- _f_qc, _start_raw, _end_raw = self._tmidx_process(_start, _end, _f_qc)
303
-
304
- self._rate_calculate(_f_raw, _f_qc, _start_raw, _end_raw)
305
-
306
- return _f_qc if self.qc else _f_raw
307
-
308
- # -------------------------------------------------------------------------------------
309
- # old flow
310
- # def __run(self, _start, _end):
311
- #
312
- # ## read pickle if pickle file exists and 'reset=False' or process raw data
313
- # if (self.path / self.pkl_nam in list(self.path.glob('*.pkl'))) & (~self.reset):
314
- # print(f"\n\t{dtm.now().strftime('%m/%d %X')} : Reading \033[96mPICKLE\033[0m file of {self.nam}")
315
- #
316
- # with (self.path / self.pkl_nam).open('rb') as f:
317
- # _fout_qc = pkl.load(f)
318
- #
319
- # _exist = (self.path / self.pkl_nam_raw).exists()
320
- # if _exist:
321
- # with (self.path / self.pkl_nam_raw).open('rb') as f:
322
- # _fout_raw = pkl.load(f)
323
- # else:
324
- # _fout_raw = _fout_qc
325
- #
326
- # _start, _end = to_datetime(_start) or _fout_qc.index[0], to_datetime(_end) or _fout_qc.index[-1]
327
- # _idx = date_range(_start, _end, freq=_fout_qc.index.freq.copy())
328
- # _idx.name = 'time'
329
- #
330
- # _fout_raw, _fout_qc = _fout_raw.reindex(_idx), _fout_qc.reindex(_idx)
331
- # if (self.rate) & (_exist):
332
- # self._rate_calculate(_fout_raw, _fout_qc)
333
- #
334
- # return _fout_qc if self.qc else _fout_raw
335
- # else:
336
- # print(
337
- # f"\n\t{dtm.now().strftime('%m/%d %X')} : Reading \033[96mRAW DATA\033[0m of {self.nam} and process it")
338
- #
339
- # ##=================================================================================================================
340
- # ## read raw data
341
- # _df_con, _f_list = None, list(self.path.glob(self.meta['pattern']))
342
- #
343
- # if len(_f_list) == 0:
344
- # print(f"\t\t\033[31mNo File in '{self.path}' Could Read, Please Check Out the Current Path\033[0m")
345
- # return None
346
- #
347
- # for file in _f_list:
348
- # if file.name in [self.csv_out, self.csv_nam, self.csv_nam_raw, f'{self.nam}.log']: continue
349
- #
350
- # print(f"\r\t\treading {file.name}", end='')
351
- #
352
- # _df = self._raw_reader(file)
353
- #
354
- # ## concat the concated list
355
- # if _df is not None:
356
- # _df_con = concat([_df_con, _df]) if _df_con is not None else _df
357
- # print()
358
- #
359
- # ## QC
360
- # _save_raw = self._raw_process(_df_con)
361
- # _save_qc = self._QC(_save_raw)
362
- #
363
- # _start, _end = to_datetime(_start) or _save_raw.index[0], to_datetime(_end) or _save_raw.index[-1]
364
- # _idx = date_range(_start, _end, freq=_save_raw.index.freq.copy())
365
- # _idx.name = 'time'
366
- #
367
- # _fout_raw, _fout_qc = _save_raw.reindex(_idx).copy(), _save_qc.reindex(_idx).copy()
368
- #
369
- # self._rate_calculate(_fout_raw, _fout_qc)
370
- #
371
- # ##=================================================================================================================
372
- # ## dump pickle file
373
- # _check = True
374
- # while _check:
375
- #
376
- # try:
377
- # with (self.path / self.pkl_nam).open('wb') as f:
378
- # pkl.dump(_save_qc, f, protocol=pkl.HIGHEST_PROTOCOL)
379
- #
380
- # ## dump csv file
381
- # if self.csv:
382
- # _save_qc.to_csv(self.path / self.csv_nam)
383
- #
384
- # ## output raw data if qc file
385
- # if self.meta['deter_key'] is not None:
386
- # with (self.path / self.pkl_nam_raw).open('wb') as f:
387
- # pkl.dump(_save_raw, f, protocol=pkl.HIGHEST_PROTOCOL)
388
- #
389
- # if self.csv:
390
- # _save_raw.to_csv(self.path / self.csv_nam_raw)
391
- #
392
- # return _fout_qc if self.qc else _fout_raw
393
- #
394
- # _check = False
395
- #
396
- # except PermissionError as _err:
397
- # print('\n', _err)
398
- # input('\t\t\33[41m Please Close The File And Press "Enter" \33[0m\n')
399
- #
400
- # return _fout_qc
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