8
8
# =============================================================================
9
9
# Imports
10
10
# =============================================================================
11
- from pathlib import Path
12
11
13
12
from mtpy .processing .run_summary import RunSummary
14
13
from mtpy .processing .kernel_dataset import KernelDataset
15
14
16
15
# =============================================================================
17
16
18
17
19
- class BaseProcessing :
18
+ class BaseProcessing ( KernelDataset ) :
20
19
"""
21
20
Base processing class contains path to various files
22
21
"""
23
22
24
23
def __init__ (self , ** kwargs ):
25
- self .local_station_id = None
26
- self .remote_station_id = None
27
- self .local_mth5_path = None
28
- self .remote_mth5_path = None
29
- self .config = None
30
- self .run_summary = RunSummary ()
31
- self .kernel_dataset = KernelDataset ()
32
-
33
- for key , value in kwargs .items ():
34
- setattr (self , key , value )
35
-
36
- @property
37
- def local_station_id (self ):
38
- return self ._local_station_id
39
-
40
- @local_station_id .setter
41
- def local_station_id (self , value ):
42
- if value is None :
43
- self ._local_station_id = None
44
- else :
45
- try :
46
- self ._local_station_id = str (value )
47
- except ValueError :
48
- raise ValueError (
49
- f"Bad type { type (value )} . "
50
- "Cannot convert local_station_id value to string."
51
- )
52
-
53
- @property
54
- def local_mth5_path (self ):
55
- return self ._local_mth5_path
56
-
57
- @local_mth5_path .setter
58
- def local_mth5_path (self , value ):
59
- self ._local_mth5_path = self .set_path (value )
60
-
61
- def has_local_mth5 (self ):
62
- """test if local mth5 exists"""
63
- if self .local_mth5_path is None :
64
- return False
65
- else :
66
- return self .local_mth5_path .exists ()
67
-
68
- @property
69
- def remote_station_id (self ):
70
- return self ._remote_station_id
71
-
72
- @remote_station_id .setter
73
- def remote_station_id (self , value ):
74
- if value is None :
75
- self ._remote_station_id = None
76
- else :
77
- try :
78
- self ._remote_station_id = str (value )
79
- except ValueError :
80
- raise ValueError (
81
- f"Bad type { type (value )} . "
82
- "Cannot convert remote_station_id value to string."
83
- )
84
-
85
- @property
86
- def remote_mth5_path (self ):
87
- return self ._remote_mth5_path
24
+ super ().__init__ (** kwargs )
88
25
89
- @remote_mth5_path .setter
90
- def remote_mth5_path (self , value ):
91
- self ._remote_mth5_path = self .set_path (value )
92
-
93
- def has_remote_mth5 (self ):
94
- """test if remote mth5 exists"""
95
- if self .remote_mth5_path is None :
96
- return False
97
- else :
98
- return self .remote_mth5_path .exists ()
26
+ self .config = None
99
27
100
28
@property
101
29
def mth5_list (self ):
102
30
"""
103
- list of mth5's as [local, remote]
104
31
105
- :return: DESCRIPTION
106
- :rtype: TYPE
32
+ :return: list of mth5 to get run summary from
33
+ :rtype: list
107
34
108
35
"""
109
36
mth5_list = []
110
37
if self .has_local_mth5 ():
111
38
mth5_list .append (self .local_mth5_path )
112
- if self .has_remote_mth5 ():
113
- if self .local_mth5_path != self .remote_mth5_path :
114
- mth5_list .append (self .remote_mth5_path )
115
- else :
116
- raise IOError ("Local MTH5 path must be set with a valid file path." )
117
- return mth5_list
118
-
119
- @classmethod
120
- def set_path (self , value ):
121
- return_path = None
122
- if value is not None :
123
- if isinstance (value , (str , Path )):
124
- return_path = Path (value )
125
- if not return_path .exists ():
126
- raise IOError (f"Cannot find file: { return_path } " )
127
- else :
128
- raise ValueError (f"Cannot convert type{ type (value )} to Path" )
39
+ if self .has_remote_mth5 ():
40
+ mth5_list .append (self .remote_mth5_path )
129
41
130
- return return_path
42
+ if len (mth5_list ) == 0 :
43
+ raise ValueError ("No MTH5 file paths set. Return list is empty." )
44
+ return mth5_list
131
45
132
- def get_run_summary (self , inplace : bool = True ):
46
+ def get_run_summary (self ):
133
47
"""
134
48
Get the RunSummary object
135
49
@@ -142,47 +56,9 @@ def get_run_summary(self, inplace: bool = True):
142
56
143
57
"""
144
58
145
- if inplace :
146
- self .run_summary .from_mth5s (self .mth5_list )
147
- else :
148
- run_summary = RunSummary ()
149
- run_summary .from_mth5s (self .mth5_list )
150
- return run_summary
151
-
152
- def has_run_summary (self ):
153
- """
154
- test if has run summary
155
-
156
- :return: DESCRIPTION
157
- :rtype: TYPE
158
-
159
- """
160
- if self .run_summary .df is not None :
161
- return True
162
- return False
163
-
164
- def get_kernel_dataset (self , inplace : bool = True ):
165
- """
166
-
167
- :param inplace: DESCRIPTION, defaults to True
168
- :type inplace: bool, optional
169
- :return: DESCRIPTION
170
- :rtype: TYPE
171
-
172
- """
173
- if not self .has_run_summary ():
174
- self .get_run_summary ()
175
- if inplace :
176
-
177
- self .kernel_dataset .from_run_summary (
178
- self .run_summary , self .local_station_id , self .remote_station_id
179
- )
180
- else :
181
- kds = KernelDataset ()
182
- kds .from_run_summary (
183
- self .run_summary , self .local_station_id , self .remote_station_id
184
- )
185
- return kds
59
+ run_summary = RunSummary ()
60
+ run_summary .from_mth5s (self .mth5_list )
61
+ return run_summary
186
62
187
63
def has_kernel_dataset (self ):
188
64
"""
0 commit comments