Coverage for C: \ Users \ peaco \ OneDrive \ Documents \ GitHub \ mth5 \ mth5 \ groups \ filter_groups \ coefficient_filter_group.py: 89%
35 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-10 00:01 -0800
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-10 00:01 -0800
1# -*- coding: utf-8 -*-
2"""
3Created on Wed Jun 9 08:58:15 2021
5:copyright:
6 Jared Peacock (jpeacock@usgs.gov)
8:license: MIT
10"""
12# =============================================================================
13# Imports
14# =============================================================================
15from mt_metadata.timeseries.filters import CoefficientFilter
17from mth5.groups.base import BaseGroup
20# =============================================================================
21# COEFFCIENT Group
22# =============================================================================
25class CoefficientGroup(BaseGroup):
26 """
27 Container for Coefficient type filters
28 """
30 def __init__(self, group, **kwargs):
31 super().__init__(group, **kwargs)
33 @property
34 def filter_dict(self):
35 """
37 Dictionary of available coefficient filters
39 :return: DESCRIPTION
40 :rtype: TYPE
41 """
42 f_dict = {}
43 for key in self.hdf5_group.keys():
44 coefficient_group = self.hdf5_group[key]
45 f_dict[key] = {
46 "type": coefficient_group.attrs["type"],
47 "hdf5_ref": coefficient_group.ref,
48 }
50 return f_dict
52 def add_filter(self, name, coefficient_metadata):
53 """
54 Add a coefficient Filter
56 :param name: DESCRIPTION
57 :type name: TYPE
58 :param coefficient_metadata: DESCRIPTION
59 :type coefficient_metadata: TYPE
60 :return: DESCRIPTION
61 :rtype: TYPE
63 """
64 # create a group for the filter by the name
65 coefficient_filter_group = self.hdf5_group.create_group(name)
67 # fill in the metadata
68 coefficient_filter_group.attrs.update(coefficient_metadata)
70 return coefficient_filter_group
72 def remove_filter(self):
73 pass
75 def get_filter(self, name):
76 """
77 Get a filter from the name
79 :param name: name of the filter
80 :type name: string
82 :return: HDF5 group of the ZPK filter
83 """
84 return self.hdf5_group[name]
86 def from_object(self, coefficient_object):
87 """
88 make a filter from a :class:`mt_metadata.timeseries.filters.CoefficientFilter`
90 :param zpk_object: MT metadata Coefficient Filter
91 :type zpk_object: :class:`mt_metadata.timeseries.filters.CoefficientFilter`
93 """
95 if not isinstance(coefficient_object, CoefficientFilter):
96 msg = f"Filter must be a CoefficientFilter not {type(coefficient_object)}"
97 self.logger.error(msg)
98 raise TypeError(msg)
100 input_dict = coefficient_object.to_dict(single=True, required=False)
101 for k, v in input_dict.items():
102 if v is None:
103 input_dict[k] = str(v)
104 coefficient_group = self.add_filter(coefficient_object.name, input_dict)
105 return coefficient_group
107 def to_object(self, name):
108 """
109 make a :class:`mt_metadata.timeseries.filters.CoefficientFilter` object
111 :return: DESCRIPTION
112 :rtype: TYPE
114 """
116 coefficient_group = self.get_filter(name)
118 coefficient_obj = CoefficientFilter(**coefficient_group.attrs)
120 return coefficient_obj