Skip to content

Commit 78c6483

Browse files
committed
adjusting the processing flow
1 parent c18d940 commit 78c6483

File tree

3 files changed

+84
-20
lines changed

3 files changed

+84
-20
lines changed

mtpy/processing/aurora/process_aurora.py

Lines changed: 81 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ class AuroraProcessing(BaseProcessing):
6464
"""
6565

6666
def __init__(self, **kwargs):
67-
super().__init__(**kwargs)
6867
self.merge_dictionary = {
6968
1: {"period_min": 4, "period_max": 30000},
7069
4: {"period_min": 1, "period_max": 30000},
@@ -93,6 +92,8 @@ def __init__(self, **kwargs):
9392

9493
self._processing_dict_keys = ["config", "kernel_dataset"]
9594

95+
super().__init__(**kwargs)
96+
9697
def _get_merge_df(self):
9798
"""
9899
a datafram containing the periods to use for each sample rate
@@ -110,7 +111,9 @@ def _get_merge_df(self):
110111
}
111112
)
112113

113-
def create_config(self, decimation_kwargs={}, **kwargs):
114+
def create_config(
115+
self, kernel_dataset=None, decimation_kwargs={}, **kwargs
116+
):
114117
"""
115118
116119
decimation kwargs can include information about window,
@@ -119,21 +122,58 @@ def create_config(self, decimation_kwargs={}, **kwargs):
119122
:rtype: aurora.config
120123
121124
"""
122-
if self.has_kernel_dataset():
125+
if kernel_dataset is None:
126+
if self.has_kernel_dataset():
127+
cc = ConfigCreator()
128+
config = cc.create_from_kernel_dataset(self, **kwargs)
129+
if self.sample_rate > 1000:
130+
decimation_kwargs.update(
131+
self.default_window_parameters["high"]
132+
)
133+
else:
134+
decimation_kwargs.update(
135+
self.default_window_parameters["low"]
136+
)
137+
self._set_decimation_level_parameters(
138+
config, **decimation_kwargs
139+
)
140+
return config
141+
else:
142+
if (
143+
self.local_mth5_path is not None
144+
and self.local_station_id is not None
145+
):
146+
self._initialize_kernel_dataset()
147+
cc = ConfigCreator()
148+
config = cc.create_from_kernel_dataset(self, **kwargs)
149+
if self.sample_rate > 1000:
150+
decimation_kwargs.update(
151+
self.default_window_parameters["high"]
152+
)
153+
else:
154+
decimation_kwargs.update(
155+
self.default_window_parameters["low"]
156+
)
157+
self._set_decimation_level_parameters(
158+
config, **decimation_kwargs
159+
)
160+
return config
161+
162+
else:
163+
raise ValueError(
164+
"Cannot make config because KernelDataset has not been set yet."
165+
)
166+
else:
123167
cc = ConfigCreator()
124-
config = cc.create_from_kernel_dataset(self, **kwargs)
125-
if self.sample_rate > 1000:
168+
config = cc.create_from_kernel_dataset(kernel_dataset, **kwargs)
169+
if kernel_dataset.sample_rate > 1000:
126170
decimation_kwargs.update(
127171
self.default_window_parameters["high"]
128172
)
129173
else:
130174
decimation_kwargs.update(self.default_window_parameters["low"])
131175
self._set_decimation_level_parameters(config, **decimation_kwargs)
132176
return config
133-
else:
134-
raise ValueError(
135-
"Cannot make config because KernelDataset has not been set yet."
136-
)
137177

138178
def _set_decimation_level_parameters(self, config, **kwargs):
139179
"""
@@ -152,14 +192,31 @@ def _set_decimation_level_parameters(self, config, **kwargs):
152192
for key, value in kwargs.items():
153193
decimation.set_attr_from_name(key, value)
154194

155-
def build_kernel_dataset(
195+
def _initialize_kernel_dataset(self, sample_rate=None):
196+
"""
197+
make an initial kernel dataset
198+
"""
199+
200+
if not self.has_run_summary():
201+
self.run_summary = self.get_run_summary()
202+
203+
if sample_rate is not None:
204+
run_summary = self.run_summary.set_sample_rate(sample_rate)
205+
else:
206+
run_summary = self.run_summary.clone()
207+
208+
self.from_run_summary(run_summary)
209+
210+
def create_kernel_dataset(
156211
self,
157212
run_summary=None,
158213
local_station_id=None,
159214
remote_station_id=None,
160215
sample_rate=None,
216+
inplace=False,
161217
):
162218
"""
219+
This can be a stane alone method and return a kds, or create in place
163220
Build KernelDataset
164221
"""
165222

@@ -170,7 +227,14 @@ def build_kernel_dataset(
170227
if sample_rate is not None:
171228
run_summary = self.run_summary.set_sample_rate(sample_rate)
172229

173-
self.from_run_summary(run_summary, local_station_id, remote_station_id)
230+
if inplace:
231+
self.from_run_summary(run_summary)
232+
else:
233+
kernel_dataset = KernelDataset()
234+
kernel_dataset.from_run_summary(
235+
run_summary, local_station_id, remote_station_id
236+
)
237+
return kernel_dataset
174238

175239
def process_single_sample_rate(
176240
self, sample_rate, config=None, kernel_dataset=None
@@ -184,11 +248,11 @@ def process_single_sample_rate(
184248
"""
185249

186250
if kernel_dataset is None:
187-
if not self.has_run_summary():
188-
self.run_summary = self.get_run_summary()
189-
run_summary = self.run_summary.set_sample_rate(sample_rate)
190-
self.from_run_summary(run_summary)
191-
kernel_dataset = self.clone()
251+
kernel_dataset = self.create_kernel_dataset(
252+
local_station_id=self.local_station_id,
253+
remote_station_id=self.remote_station_id,
254+
sample_rate=sample_rate,
255+
)
192256
if config is None:
193257
config = self.create_config()
194258

@@ -414,7 +478,7 @@ def _get_merge_tf_list(self, tf_dict):
414478

415479
merge_df = self._get_merge_df()
416480
merge_list = []
417-
for key, pdict in self._validate_tf_processed_dict(tf_dict):
481+
for key, pdict in self._validate_tf_processed_dict(tf_dict).items():
418482
if key in merge_df.sample_rate:
419483
row = merge_df.loc[merge_df.sample_rate == key]
420484
period_min = row.period_min[0]

mtpy/processing/kernel_dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def __init__(
162162
setattr(self, key, value)
163163

164164
def __str__(self):
165-
return str(self.mini_summary.head())
165+
return str(self.mini_summary.head(-1))
166166

167167
def __repr__(self):
168168
return self.__str__()
@@ -369,7 +369,7 @@ def remote_mth5_path(self):
369369
].unique()[0]
370370
)
371371
else:
372-
return None
372+
return self._remote_mth5_path
373373

374374
@remote_mth5_path.setter
375375
def remote_mth5_path(self, value):

mtpy/processing/run_summary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init__(
8181
self._mini_summary_columns = MINI_SUMMARY_COLUMNS
8282

8383
def __str__(self):
84-
return str(self.mini_summary.head())
84+
return str(self.mini_summary.head(-1))
8585

8686
def __repr__(self):
8787
return self.__str__()

0 commit comments

Comments
 (0)