mrio-toolbox 1.1.2__py3-none-any.whl → 1.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mrio-toolbox might be problematic. Click here for more details.
- {mrio_toolbox-1.1.2.dist-info → mrio_toolbox-1.1.3.dist-info}/METADATA +1 -1
- mrio_toolbox-1.1.3.dist-info/RECORD +5 -0
- mrio_toolbox-1.1.3.dist-info/top_level.txt +1 -0
- __init__.py +0 -21
- _parts/_Axe.py +0 -539
- _parts/_Part.py +0 -1739
- _parts/__init__.py +0 -7
- _parts/part_operations.py +0 -57
- extractors/__init__.py +0 -20
- extractors/downloaders.py +0 -36
- extractors/emerging/__init__.py +0 -3
- extractors/emerging/emerging_extractor.py +0 -117
- extractors/eora/__init__.py +0 -3
- extractors/eora/eora_extractor.py +0 -132
- extractors/exiobase/__init__.py +0 -3
- extractors/exiobase/exiobase_extractor.py +0 -270
- extractors/extractors.py +0 -81
- extractors/figaro/__init__.py +0 -3
- extractors/figaro/figaro_downloader.py +0 -280
- extractors/figaro/figaro_extractor.py +0 -187
- extractors/gloria/__init__.py +0 -3
- extractors/gloria/gloria_extractor.py +0 -202
- extractors/gtap11/__init__.py +0 -7
- extractors/gtap11/extraction/__init__.py +0 -3
- extractors/gtap11/extraction/extractor.py +0 -129
- extractors/gtap11/extraction/harpy_files/__init__.py +0 -6
- extractors/gtap11/extraction/harpy_files/_header_sets.py +0 -279
- extractors/gtap11/extraction/harpy_files/har_file.py +0 -262
- extractors/gtap11/extraction/harpy_files/har_file_io.py +0 -974
- extractors/gtap11/extraction/harpy_files/header_array.py +0 -300
- extractors/gtap11/extraction/harpy_files/sl4.py +0 -229
- extractors/gtap11/gtap_mrio/__init__.py +0 -6
- extractors/gtap11/gtap_mrio/mrio_builder.py +0 -158
- extractors/icio/__init__.py +0 -3
- extractors/icio/icio_extractor.py +0 -121
- extractors/wiod/__init__.py +0 -3
- extractors/wiod/wiod_extractor.py +0 -143
- mrio.py +0 -899
- mrio_toolbox-1.1.2.dist-info/RECORD +0 -59
- mrio_toolbox-1.1.2.dist-info/top_level.txt +0 -6
- msm/__init__.py +0 -6
- msm/multi_scale_mapping.py +0 -863
- utils/__init__.py +0 -3
- utils/converters/__init__.py +0 -5
- utils/converters/pandas.py +0 -244
- utils/converters/xarray.py +0 -132
- utils/formatting/__init__.py +0 -0
- utils/formatting/formatter.py +0 -527
- utils/loaders/__init__.py +0 -7
- utils/loaders/_loader.py +0 -312
- utils/loaders/_loader_factory.py +0 -96
- utils/loaders/_nc_loader.py +0 -184
- utils/loaders/_np_loader.py +0 -112
- utils/loaders/_pandas_loader.py +0 -128
- utils/loaders/_parameter_loader.py +0 -386
- utils/savers/__init__.py +0 -11
- utils/savers/_path_checker.py +0 -37
- utils/savers/_to_folder.py +0 -165
- utils/savers/_to_nc.py +0 -60
- {mrio_toolbox-1.1.2.dist-info → mrio_toolbox-1.1.3.dist-info}/WHEEL +0 -0
- {mrio_toolbox-1.1.2.dist-info → mrio_toolbox-1.1.3.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
.. autoclass: HarFileObj
|
|
3
|
-
:members:
|
|
4
|
-
|
|
5
|
-
Created on Mar 12 09:53:27 2018
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from .har_file_io import HarFileIO, HarFileInfoObj
|
|
9
|
-
from .header_array import HeaderArrayObj
|
|
10
|
-
from collections import OrderedDict
|
|
11
|
-
from typing import TypeVar, List, Union
|
|
12
|
-
from os import path
|
|
13
|
-
import warnings
|
|
14
|
-
TypeHarFileObj = TypeVar('TypeHarFileObj', bound='HarFileObj')
|
|
15
|
-
|
|
16
|
-
class HarFileObj(object):
|
|
17
|
-
"""
|
|
18
|
-
HAR file object - essentially a memory representation of a HAR file.
|
|
19
|
-
|
|
20
|
-
``HarFileObj`` stores a `list` of ``harpy.HeaderArrayObj`` in ``self``.
|
|
21
|
-
Each ``harpy.HeaderArrayObj`` corresponds to a header-array.
|
|
22
|
-
If ``HarFileObj`` is provided with ``filename``, then the header-arrays in that file will be loaded - i.e., each ``harpy.HeaderArrayObj`` in ``self`` will correspond to a header-array in that file.
|
|
23
|
-
|
|
24
|
-
Access to the ``HarFileObj`` is provided in a dict-like style: `__getitem__`, `__setitem__`, `__delitem__`, and `__contains__` are implemented. Each can take list arguments and returns results as a list.
|
|
25
|
-
Note that all methods are case insensitive with respect to header names.
|
|
26
|
-
|
|
27
|
-
Example: given file ex.har with Headers HD1 and HD2::
|
|
28
|
-
|
|
29
|
-
>>> from harpy import HarFileObj
|
|
30
|
-
>>> thisHar = HarFileObj("ex.har")
|
|
31
|
-
>>> headersOnFile = thisHar.getHeaderArrayNames() # ["HD1","HD2"]
|
|
32
|
-
>>> hd1Head = thisHar["HD1"] # obtain the HeaderArrayObj for HD1
|
|
33
|
-
>>> del thisHar["HD1"] # remove HD1 from HarFile
|
|
34
|
-
>>> print("HD1" in thisHar)
|
|
35
|
-
False
|
|
36
|
-
>>> thisHar.writeToDisk() # overwrites ex.har, now only contains HD2
|
|
37
|
-
|
|
38
|
-
Attributes
|
|
39
|
-
----------
|
|
40
|
-
head_arrs : OrderedDict
|
|
41
|
-
Returned/provided as a `list` of ``HeaderArrayObj`` defining all ``HeaderArrayObj`` associated with a file.
|
|
42
|
-
|
|
43
|
-
_hfi : HarFileInfoObj
|
|
44
|
-
Basic info of the HAR file content. This is used in conjunction with `head_arrs` to permit on-the-fly reading of ``HeaderArrayObj`` and thus reduce the memory footprint.
|
|
45
|
-
"""
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def __init__(self, filename: str=None):
|
|
49
|
-
self._head_arrs = OrderedDict()
|
|
50
|
-
self.filename=filename
|
|
51
|
-
if isinstance(filename, str):
|
|
52
|
-
if path.isfile(filename):
|
|
53
|
-
self._hfi = HarFileIO.readHarFileInfo(filename)
|
|
54
|
-
else:
|
|
55
|
-
self._hfi = HarFileInfoObj(file=filename)
|
|
56
|
-
|
|
57
|
-
def __getitem__(self, item : 'Union[str, List[str]]' ):
|
|
58
|
-
if isinstance(item,str):
|
|
59
|
-
return self._getHeaderArrayObj(item)
|
|
60
|
-
elif isinstance(item,list):
|
|
61
|
-
if not all([isinstance(myitem,str) for myitem in item]):
|
|
62
|
-
raise TypeError("All items in item must be of type 'str'")
|
|
63
|
-
return self._getHeaderArrayObjs(item)
|
|
64
|
-
else:
|
|
65
|
-
raise TypeError("item must be string or list of strings")
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def __setitem__(self, key: 'Union[str, List[str]]', value: 'Union[HeaderArrayObj, List[HeaderArrayObj]]'):
|
|
69
|
-
if isinstance(key, str) and isinstance(value,HeaderArrayObj):
|
|
70
|
-
self._addHeaderArrayObj(key, value)
|
|
71
|
-
elif isinstance(key, list) and isinstance(value,list):
|
|
72
|
-
if not all([isinstance(mykey,str) for mykey in key]):
|
|
73
|
-
raise TypeError("All items in key must be of type 'str'")
|
|
74
|
-
if not all([isinstance(myval,HeaderArrayObj) for myval in value]):
|
|
75
|
-
raise TypeError("All items in value must be of type 'HeaderArrayObj'")
|
|
76
|
-
self._addHeaderArrayObjs(key, value)
|
|
77
|
-
else:
|
|
78
|
-
raise TypeError("Only combination str-HeaderArrayObj or list(str)-list(HeaderArrayObj) permitted in __getitem__'")
|
|
79
|
-
|
|
80
|
-
return None
|
|
81
|
-
|
|
82
|
-
def __delitem__(self, key):
|
|
83
|
-
if isinstance(key,str):
|
|
84
|
-
if key.strip().upper() in self._head_arrs:
|
|
85
|
-
del self._head_arrs[key.strip().upper()]
|
|
86
|
-
elif isinstance(key,list):
|
|
87
|
-
for mykey in key:
|
|
88
|
-
if mykey in self._head_arrs:
|
|
89
|
-
del self[mykey]
|
|
90
|
-
else:
|
|
91
|
-
raise TypeError("key must be string or list of strings")
|
|
92
|
-
|
|
93
|
-
return None
|
|
94
|
-
|
|
95
|
-
def __contains__(self, key):
|
|
96
|
-
if isinstance(key,str):
|
|
97
|
-
return key.strip().upper() in self._head_arrs
|
|
98
|
-
return False
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
def getHeaderArrayNames(self):
|
|
104
|
-
"""
|
|
105
|
-
:return: Returns the name of all ``harpy.HeaderArrayObj()`` stored with ``self``.
|
|
106
|
-
"""
|
|
107
|
-
|
|
108
|
-
if not self._hfi.is_valid(fatal=False):
|
|
109
|
-
warnings.warn("Har file "+self._hfi.filename+" has changed since last access, rereading information")
|
|
110
|
-
self._hfi=HarFileObj(self._hfi.file)._hfi
|
|
111
|
-
self._head_arrs=OrderedDict()
|
|
112
|
-
|
|
113
|
-
return self._hfi.getHeaderArrayNames()
|
|
114
|
-
|
|
115
|
-
def getRealHeaderArrayNames(self):
|
|
116
|
-
"""
|
|
117
|
-
:return: Returns only the names of arrays of type 2D or 7D - i.e. multi-dimensional header arrays of floating point numbers.
|
|
118
|
-
"""
|
|
119
|
-
|
|
120
|
-
if not self._hfi.is_valid():
|
|
121
|
-
warnings.warn("Har file "+self._hfi.filename+" has changed since last access, rereading information")
|
|
122
|
-
self._hfi = HarFileObj(self._hfi.file)._hfi
|
|
123
|
-
self._head_arrs = OrderedDict()
|
|
124
|
-
return [key for key,val in self._hfi.items() if val.data_type in ["RE","RL","2R"]]
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
def _getHeaderArrayObj(self, ha_name: str):
|
|
128
|
-
"""
|
|
129
|
-
Retrieve a single ``harpy.HeaderArrayObj``.
|
|
130
|
-
|
|
131
|
-
:param ha_name: The ``"name"`` of the ``harpy.HeaderArrayObj``.
|
|
132
|
-
:return: A ``harpy.HeaderArrayObj``.
|
|
133
|
-
"""
|
|
134
|
-
|
|
135
|
-
if not self._hfi.is_valid(fatal=False):
|
|
136
|
-
warnings.warn("Har file "+self._hfi.filename+" has changed since last access, rereading information")
|
|
137
|
-
self._hfi = HarFileObj(self._hfi.file)._hfi
|
|
138
|
-
self._head_arrs = OrderedDict()
|
|
139
|
-
|
|
140
|
-
if not isinstance(ha_name, str):
|
|
141
|
-
raise TypeError("'ha_name' must be a string.")
|
|
142
|
-
|
|
143
|
-
upname=ha_name.strip().upper()
|
|
144
|
-
if not upname in self._hfi:
|
|
145
|
-
raise KeyError("HeaderArrayObj '%s' does not exist in HarFileObj." % ha_name)
|
|
146
|
-
if not upname in self._head_arrs:
|
|
147
|
-
hnames, haos= HarFileIO.readHeaderArraysFromFile(self._hfi, ha_names=upname)
|
|
148
|
-
self._head_arrs[upname]=haos[0]
|
|
149
|
-
|
|
150
|
-
return self._head_arrs[upname]
|
|
151
|
-
|
|
152
|
-
def _getHeaderArrayObjs(self, ha_names=None):
|
|
153
|
-
"""
|
|
154
|
-
Retrieve a `list` of `harpy.HeaderArrayObj`.
|
|
155
|
-
|
|
156
|
-
:param 'Union[None,str,List[str]]' ha_names: The name or `list` of names of ``harpy.HeaderArrayObj``. If `None` is provided (the default) then all ``harpy.HeaderArrayObj`` are returned.
|
|
157
|
-
:return: `list` of ``harpy.HeaderArrayObj``.
|
|
158
|
-
"""
|
|
159
|
-
|
|
160
|
-
if isinstance(ha_names, str):
|
|
161
|
-
ha_names = [ha_names]
|
|
162
|
-
elif ha_names is None:
|
|
163
|
-
ha_names = self.getHeaderArrayNames()
|
|
164
|
-
|
|
165
|
-
ha_objs = []
|
|
166
|
-
for ha_name in ha_names:
|
|
167
|
-
ha_objs.append(self._getHeaderArrayObj(ha_name))
|
|
168
|
-
return ha_objs
|
|
169
|
-
|
|
170
|
-
def _readHeaderArrayObjs(self, ha_names = None):
|
|
171
|
-
"""
|
|
172
|
-
Reads the header array objects with names ``ha_names`` from ``filename``. If `None` (the default), read all header array objects. `harpy.HeaderArrayObj` are stored in ``self`` and can be retrieved with the ``self.getHeaderArrayObjs()`` method.
|
|
173
|
-
|
|
174
|
-
:param 'Union[None,str,List[str]]' ha_names:
|
|
175
|
-
"""
|
|
176
|
-
hnames, haos = HarFileIO.readHeaderArraysFromFile(self._hfi, ha_names=ha_names)
|
|
177
|
-
self._head_arrs=OrderedDict(zip(hnames, haos))
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
def writeToDisk(self, filename: str=None, ha_names=None):
|
|
181
|
-
"""
|
|
182
|
-
:param str filename: Writes `harpy.HeaderArrayObj` with ``ha_names`` to ``filename``. If ``ha_names`` is None, write all the `harpy.HeaderArrayObj` stored in ``self``.
|
|
183
|
-
:param 'Union[None,str,List[str]]' ha_names: The names of the header arrays to write to ``filename``.
|
|
184
|
-
"""
|
|
185
|
-
if filename is None and self.filename is None:
|
|
186
|
-
raise ValueError("No filename specified in write or upon creation, use writeToDisk(filename=YOURFILENAME)")
|
|
187
|
-
if filename is None:
|
|
188
|
-
filename=self.filename
|
|
189
|
-
if ha_names is None:
|
|
190
|
-
ha_names = self.getHeaderArrayNames()
|
|
191
|
-
elif isinstance(ha_names, str):
|
|
192
|
-
ha_names = [ha_names]
|
|
193
|
-
|
|
194
|
-
ha_to_write = self._getHeaderArrayObjs(ha_names)
|
|
195
|
-
|
|
196
|
-
HarFileIO.writeHeaders(filename, ha_names, ha_to_write)
|
|
197
|
-
self._hfi.updateMtime()
|
|
198
|
-
|
|
199
|
-
def _removeHeaderArrayObjs(self, ha_names):
|
|
200
|
-
"""
|
|
201
|
-
TODO: its more of a pop, not a remove, maybe rename
|
|
202
|
-
:param 'Union[str,List[str]]' ha_names: Remove one or more `harpy.HeaderArrayObj` from ``self``.
|
|
203
|
-
"""
|
|
204
|
-
|
|
205
|
-
if isinstance(ha_names, str):
|
|
206
|
-
ha_names = [ha_names]
|
|
207
|
-
|
|
208
|
-
outlist=self._getHeaderArrayObjs(ha_names)
|
|
209
|
-
|
|
210
|
-
for ha_name in ha_names:
|
|
211
|
-
if ha_name.strip().upper() in self._hfi:
|
|
212
|
-
del self._hfi._ha_infos[ha_name.strip().upper()]
|
|
213
|
-
if ha_name.strip().upper() in self._head_arrs:
|
|
214
|
-
del self._head_arrs[ha_name.strip().upper()]
|
|
215
|
-
return outlist
|
|
216
|
-
|
|
217
|
-
def _addHeaderArrayObjs(self, hnames, ha_objs) -> None:
|
|
218
|
-
"""
|
|
219
|
-
:param 'Union[HeaderArrayObj,List[HeaderArrayObj]]' ha_objs: Add one or more `harpy.HeaderArrayObj` to ``self``.
|
|
220
|
-
"""
|
|
221
|
-
|
|
222
|
-
if isinstance(ha_objs, HeaderArrayObj):
|
|
223
|
-
ha_objs = [ha_objs]
|
|
224
|
-
if isinstance(hnames, str):
|
|
225
|
-
hnames = [hnames]
|
|
226
|
-
|
|
227
|
-
for hname, ha_obj in zip(hnames,ha_objs):
|
|
228
|
-
if ha_obj.is_valid():
|
|
229
|
-
self._addHeaderArrayObj(hname, ha_obj)
|
|
230
|
-
|
|
231
|
-
return None
|
|
232
|
-
|
|
233
|
-
def _addHeaderArrayObj(self, hname : str, ha_obj: HeaderArrayObj):
|
|
234
|
-
"""
|
|
235
|
-
:param ha_obj: A `harpy.HeaderArrayObj` object.
|
|
236
|
-
"""
|
|
237
|
-
|
|
238
|
-
if len(hname.strip()) > 4:
|
|
239
|
-
raise HarFileObj.InvalidHeaderArrayName("Name of Header too long")
|
|
240
|
-
|
|
241
|
-
self._hfi.addHAInfo(hname.strip().upper(),0,0)
|
|
242
|
-
self._head_arrs[hname.strip().upper()]= ha_obj
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
@staticmethod
|
|
246
|
-
def _loadFromDisk(filename: str, ha_names: list = None) -> TypeHarFileObj:
|
|
247
|
-
"""Loads a HAR file into memory, returning a HarFileObj.
|
|
248
|
-
|
|
249
|
-
:param filename: The name of the file to load.
|
|
250
|
-
:param ha_names: If provided, only reads headers with the names matching the strings contained in this list. By default, all header arrays are read.
|
|
251
|
-
:return "HarFileObj": Returns ``HarFileObj`` with
|
|
252
|
-
"""
|
|
253
|
-
|
|
254
|
-
hfo = HarFileObj(filename=filename)
|
|
255
|
-
hfo._readHeaderArrayObjs(ha_names=ha_names)
|
|
256
|
-
|
|
257
|
-
return hfo
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
class InvalidHeaderArrayName(ValueError):
|
|
261
|
-
"""Raised if header array name is not exactly four (alphanumeric) characters long."""
|
|
262
|
-
pass
|