@@ -64,7 +64,6 @@ class AuroraProcessing(BaseProcessing):
64
64
"""
65
65
66
66
def __init__ (self , ** kwargs ):
67
- super ().__init__ (** kwargs )
68
67
self .merge_dictionary = {
69
68
1 : {"period_min" : 4 , "period_max" : 30000 },
70
69
4 : {"period_min" : 1 , "period_max" : 30000 },
@@ -93,6 +92,8 @@ def __init__(self, **kwargs):
93
92
94
93
self ._processing_dict_keys = ["config" , "kernel_dataset" ]
95
94
95
+ super ().__init__ (** kwargs )
96
+
96
97
def _get_merge_df (self ):
97
98
"""
98
99
a datafram containing the periods to use for each sample rate
@@ -110,7 +111,9 @@ def _get_merge_df(self):
110
111
}
111
112
)
112
113
113
- def create_config (self , decimation_kwargs = {}, ** kwargs ):
114
+ def create_config (
115
+ self , kernel_dataset = None , decimation_kwargs = {}, ** kwargs
116
+ ):
114
117
"""
115
118
116
119
decimation kwargs can include information about window,
@@ -119,21 +122,58 @@ def create_config(self, decimation_kwargs={}, **kwargs):
119
122
:rtype: aurora.config
120
123
121
124
"""
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 :
123
167
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 :
126
170
decimation_kwargs .update (
127
171
self .default_window_parameters ["high" ]
128
172
)
129
173
else :
130
174
decimation_kwargs .update (self .default_window_parameters ["low" ])
131
175
self ._set_decimation_level_parameters (config , ** decimation_kwargs )
132
176
return config
133
- else :
134
- raise ValueError (
135
- "Cannot make config because KernelDataset has not been set yet."
136
- )
137
177
138
178
def _set_decimation_level_parameters (self , config , ** kwargs ):
139
179
"""
@@ -152,14 +192,31 @@ def _set_decimation_level_parameters(self, config, **kwargs):
152
192
for key , value in kwargs .items ():
153
193
decimation .set_attr_from_name (key , value )
154
194
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 (
156
211
self ,
157
212
run_summary = None ,
158
213
local_station_id = None ,
159
214
remote_station_id = None ,
160
215
sample_rate = None ,
216
+ inplace = False ,
161
217
):
162
218
"""
219
+ This can be a stane alone method and return a kds, or create in place
163
220
Build KernelDataset
164
221
"""
165
222
@@ -170,7 +227,14 @@ def build_kernel_dataset(
170
227
if sample_rate is not None :
171
228
run_summary = self .run_summary .set_sample_rate (sample_rate )
172
229
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
174
238
175
239
def process_single_sample_rate (
176
240
self , sample_rate , config = None , kernel_dataset = None
@@ -184,11 +248,11 @@ def process_single_sample_rate(
184
248
"""
185
249
186
250
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
+ )
192
256
if config is None :
193
257
config = self .create_config ()
194
258
@@ -414,7 +478,7 @@ def _get_merge_tf_list(self, tf_dict):
414
478
415
479
merge_df = self ._get_merge_df ()
416
480
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 () :
418
482
if key in merge_df .sample_rate :
419
483
row = merge_df .loc [merge_df .sample_rate == key ]
420
484
period_min = row .period_min [0 ]
0 commit comments