Coverage for C: \ Users \ peaco \ OneDrive \ Documents \ GitHub \ mth5 \ mth5 \ groups \ experiment.py: 88%
17 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 Dec 23 16:59:45 2020
5:copyright:
6 Jared Peacock (jpeacock@usgs.gov)
8:license:
9 MIT
11"""
13# =============================================================================
14# Imports
15# =============================================================================
16from mth5.groups import BaseGroup, MasterSurveyGroup
19# =============================================================================
20# Experiment Group
21# =============================================================================
24class ExperimentGroup(BaseGroup):
25 """
26 Utility class to hold general information about the experiment and
27 accompanying metadata for an MT experiment.
29 To access the hdf5 group directly use `ExperimentGroup.hdf5_group`.
31 >>> experiment = ExperimentGroup(hdf5_group)
32 >>> experiment.hdf5_group.ref
33 <HDF5 Group Reference>
35 .. note:: All attributes should be input into the metadata object, that
36 way all input will be validated against the metadata standards.
37 If you change attributes in metadata object, you should run the
38 `ExperimentGroup.write_metadata()` method. This is a temporary
39 solution, working on an automatic updater if metadata is changed.
41 >>> experiment.metadata.existing_attribute = 'update_existing_attribute'
42 >>> experiment.write_metadata()
44 If you want to add a new attribute this should be done using the
45 `metadata.add_base_attribute` method.
47 >>> experiment.metadata.add_base_attribute('new_attribute',
48 >>> ... 'new_attribute_value',
49 >>> ... {'type':str,
50 >>> ... 'required':True,
51 >>> ... 'style':'free form',
52 >>> ... 'description': 'new attribute desc.',
53 >>> ... 'units':None,
54 >>> ... 'options':[],
55 >>> ... 'alias':[],
56 >>> ... 'example':'new attribute
58 .. tip:: If you want ot add stations, reports, etc to the experiment this
59 should be done from the MTH5 object. This is to avoid
60 duplication, at least for now.
62 To look at what the structure of ``/Experiment`` looks like:
64 >>> experiment
65 /Experiment:
66 ====================
67 |- Group: Surveys
68 -----------------
69 |- Group: Reports
70 -----------------
71 |- Group: Standards
72 -------------------
73 |- Group: Stations
74 ------------------
76 """
78 def __init__(self, group, **kwargs):
79 super().__init__(group, **kwargs)
81 @BaseGroup.metadata.getter
82 def metadata(self):
83 """Overwrite get metadata to include station information"""
85 # need the try statement for when the file is initiated there is no
86 # /Station group yet
87 try:
88 self._metadata.surveys = []
89 for key in self.surveys_group.groups_list:
90 key_group = self.surveys_group.get_survey(key)
91 self._metadata.surveys.append(key_group.metadata)
93 except KeyError:
94 pass
96 return self._metadata
98 @property
99 def surveys_group(self):
100 return MasterSurveyGroup(self.hdf5_group["Surveys"])