Skip to content

Commit 6318876

Browse files
committed
adding example notebook
1 parent e96d2b2 commit 6318876

File tree

2 files changed

+386
-57
lines changed

2 files changed

+386
-57
lines changed

docs/source/notebooks/aurora_processing.ipynb

Lines changed: 311 additions & 0 deletions
Large diffs are not rendered by default.

mtpy/processing/aurora/process_aurora.py

Lines changed: 75 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,19 @@ def create_kernel_dataset(
200200
def process_single_sample_rate(
201201
self, sample_rate, config=None, kernel_dataset=None
202202
):
203-
"""Process data.
204-
:return: DESCRIPTION.
205-
:rtype: TYPE
203+
"""
204+
Process a single sample rate
205+
206+
:param sample_rate: sample rate of time series data
207+
:type sample_rate: float
208+
:param config: configuration file, defaults to None
209+
:type config: aurora.config, optional
210+
:param kernel_dataset: Kerenel dataset to define what data to process,
211+
defaults to None
212+
:type kernel_dataset: mtpy.processing.KernelDataset, optional
213+
:return: transfer function
214+
:rtype: mtpy.MT
215+
206216
"""
207217

208218
if kernel_dataset is None:
@@ -235,35 +245,52 @@ def process(
235245
merge=True,
236246
save_to_mth5=True,
237247
):
238-
"""If you provide just the sample rates, then at each sample rate a
248+
"""
249+
Need to either provide a list of sample rates to process or
250+
a processing dictionary.
251+
252+
If you provide just the sample rates, then at each sample rate a
239253
KernelDataset will be created as well as a subsequent config object
240254
which are then used to process the data.
241255
242256
If processing_dict is set then the processing will loop through the
243257
dictionary and use the provided config and kernel datasets.
244258
245-
process all runs for all sample rates and the combine the transfer
246-
function according to merge_dict.
259+
The processing dict has the following form
247260
248-
Need to figure out a way to adjust the config per sample rate. Maybe
249-
A dictionary of configs keyed by sample rate.
261+
.. code_block:: python
250262
251-
processing_dict = {sample_rate: {
252-
"config": config object,
253-
"kernel_dataset": KernelDataset object,
254-
}
255-
:param processing_dict:
256-
Defaults to None.
257-
:param sample_rates:
258-
Defaults to None.
259-
:param config: Dictionary of configuration keyed by sample rates.
260-
:type config: dictionary
261-
:param merge: DESCRIPTION, defaults to True.
262-
:type merge: TYPE, optional
263-
:param save_to_mth5: DESCRIPTION, defaults to True.
263+
processing_dict = {sample_rate: {
264+
"config": config object,
265+
"kernel_dataset": KernelDataset object,
266+
}
267+
268+
If merge is True then all runs for all sample rates are combined into
269+
a single function according to merge_dict.
270+
271+
If `save_to_mth5` is True then the transfer functions are saved to
272+
the local MTH5.
273+
274+
275+
:param sample_rates: list of sample rates to process, defaults to None
276+
:type sample_rates: float or list, optional
277+
:param processing_dict: processing dictionary as described above,
278+
defaults to None
279+
:type processing_dict: dict, optional
280+
:param merge: [ True | False ] True merges all sample rates into a
281+
single transfer function according to the merge_dict, defaults to True
282+
:type merge: bool, optional
283+
:param save_to_mth5: [ True | False ] save transfer functions to the
284+
local MTH5, defaults to True
264285
:type save_to_mth5: TYPE, optional
265-
:return: DESCRIPTION.
266-
:rtype: TYPE
286+
:raises ValueError: If neither sample rates nor processing dict are
287+
provided
288+
:raises TypeError: If the provided processing dictionary is not
289+
the correct format
290+
:return: dictionary of each sample rate processed in the form of
291+
{sample_rate: {'processed': bool, 'tf': MT}}
292+
:rtype: dict
293+
267294
"""
268295

269296
if sample_rates is None and processing_dict is None:
@@ -328,26 +355,15 @@ def process(
328355
return processed
329356

330357
def _validate_config(self, config):
331-
"""Validate config.
332-
:param config: DESCRIPTION.
333-
:type config: TYPE
334-
:return: DESCRIPTION.
335-
:rtype: TYPE
336-
"""
358+
"""Validate config."""
337359
if not isinstance(config, Processing):
338360
raise TypeError(
339361
"Config must be a aurora.config.metadata.Processing object. "
340362
f"Got type {type(config)}"
341363
)
342364

343365
def _validate_kernel_dataset(self, kernel_dataset):
344-
"""Validate kernel dataset.
345-
:param kernel_dataset:
346-
:param config: DESCRIPTION.
347-
:type config: TYPE
348-
:return: DESCRIPTION.
349-
:rtype: TYPE
350-
"""
366+
"""Validate kernel dataset."""
351367
if not isinstance(kernel_dataset, KernelDataset):
352368
raise TypeError(
353369
"Config must be a mtpy.processing.KernelDataset object. "
@@ -356,10 +372,9 @@ def _validate_kernel_dataset(self, kernel_dataset):
356372

357373
def _validate_processing_dict(self, processing_dict):
358374
"""Validate the processing dict to make sure it is in the correct format.
359-
:param processing_dict: DESCRIPTION.
360-
:type processing_dict: TYPE
361-
:return: DESCRIPTION.
362-
:rtype: TYPE
375+
376+
:param processing_dict: processing dictionary
377+
:type processing_dict: dict
363378
"""
364379
error_msg = "Format is {sample_rate: {'config': config object, "
365380
"'kernel_dataset': KernelDataset object}"
@@ -388,10 +403,11 @@ def _validate_tf_processed_dict(self, tf_dict):
388403
"""Pick out processed transfer functions from a given processed dict,
389404
which may have some sample rates that did not process for whatever
390405
reason.
391-
:param tf_dict: DESCRIPTION.
392-
:type tf_dict: TYPE
393-
:return: DESCRIPTION.
394-
:rtype: TYPE
406+
407+
:param tf_dict: dictionary of processed transfer functions.
408+
:type tf_dict: dict
409+
:return: dicionary of trasnfer functions for which processed=True
410+
:rtype: dict
395411
"""
396412

397413
new_dict = {}
@@ -405,10 +421,9 @@ def _validate_tf_processed_dict(self, tf_dict):
405421

406422
def _add_tf_to_local_mth5(self, tf_dict):
407423
"""Add transfer function to MTH5.
408-
:param tf_dict: DESCRIPTION.
409-
:type tf_dict: TYPE
410-
:return: DESCRIPTION.
411-
:rtype: TYPE
424+
425+
:param tf_dict: dictionary of transfer functions
426+
:type tf_dict: dict
412427
"""
413428

414429
with MTH5() as m:
@@ -418,10 +433,12 @@ def _add_tf_to_local_mth5(self, tf_dict):
418433

419434
def _get_merge_tf_list(self, tf_dict):
420435
"""Merge transfer functions according to merge dict.
421-
:param tf_dict: DESCRIPTION.
422-
:type tf_dict: TYPE
423-
:return: DESCRIPTION.
424-
:rtype: TYPE
436+
437+
:param tf_dict: dictionary of transfer functions.
438+
:type tf_dict: dict
439+
:return: list of transfer functions with appropriate min/max period
440+
to merge
441+
:rtype: list
425442
"""
426443

427444
merge_df = self._get_merge_df()
@@ -446,11 +463,12 @@ def _get_merge_tf_list(self, tf_dict):
446463
return merge_list
447464

448465
def merge_transfer_functions(self, tf_dict):
449-
"""Merge transfer functions.
450-
:param tf_dict: DESCRIPTION.
451-
:type tf_dict: TYPE
452-
:return: DESCRIPTION.
453-
:rtype: TYPE
466+
"""Merge transfer functions according to AuroraProcessing.merge_dict
467+
468+
:param tf_dict: dictionary of transfer functions
469+
:type tf_dict: dict
470+
:return: merged transfer function.
471+
:rtype: mtpy.MT
454472
"""
455473

456474
merge_list = self._get_merge_tf_list(tf_dict)

0 commit comments

Comments
 (0)