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
utils/savers/_to_folder.py
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Routines for saving MRIO and Part instances to folders.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
import os
|
|
6
|
-
from mrio_toolbox.utils.savers._path_checker import check_path
|
|
7
|
-
import numpy as np
|
|
8
|
-
import yaml
|
|
9
|
-
import pandas as pd
|
|
10
|
-
|
|
11
|
-
import logging
|
|
12
|
-
|
|
13
|
-
log = logging.getLogger(__name__)
|
|
14
|
-
|
|
15
|
-
def save_mrio_to_folder(obj,
|
|
16
|
-
path,
|
|
17
|
-
name=None,
|
|
18
|
-
extension=".npy",
|
|
19
|
-
overwrite=False,
|
|
20
|
-
**kwargs):
|
|
21
|
-
"""
|
|
22
|
-
Save an MRIO instance in a folder
|
|
23
|
-
|
|
24
|
-
Parameters
|
|
25
|
-
----------
|
|
26
|
-
path : str
|
|
27
|
-
Path to the folder to save the MRIO instance into.
|
|
28
|
-
extension : str, optional
|
|
29
|
-
Extension of the files to save the MRIO instance into.
|
|
30
|
-
The default is "npy".
|
|
31
|
-
overwrite : bool, optional
|
|
32
|
-
Whether to overwrite the existing files. The default is False.
|
|
33
|
-
If False, the version name is iterated until a non-existing
|
|
34
|
-
file name is found.
|
|
35
|
-
kwargs : dict
|
|
36
|
-
Additional arguments to pass to the saver.
|
|
37
|
-
"""
|
|
38
|
-
if name is None:
|
|
39
|
-
name = os.path.basename(path)+".yaml"
|
|
40
|
-
if not os.path.isdir(path):
|
|
41
|
-
os.mkdir(path)
|
|
42
|
-
elif not overwrite:
|
|
43
|
-
os.mkdir(check_path(path))
|
|
44
|
-
log.info(f"Saving MRIO instance {name} to folder {path}")
|
|
45
|
-
kwargs.pop("write_instructions", None) #Instructions are written anyway
|
|
46
|
-
loading_instructions = dict()
|
|
47
|
-
loading_instructions.update(obj.metadata)
|
|
48
|
-
loading_instructions["path"] = path
|
|
49
|
-
parts_instructions = dict()
|
|
50
|
-
for part in obj.parts:
|
|
51
|
-
save_part_to_folder(
|
|
52
|
-
obj.parts[part],
|
|
53
|
-
path,
|
|
54
|
-
extension=extension,
|
|
55
|
-
overwrite=overwrite,
|
|
56
|
-
include_labels=False,
|
|
57
|
-
write_instructions=False,
|
|
58
|
-
**kwargs
|
|
59
|
-
)
|
|
60
|
-
#Save part metadata
|
|
61
|
-
parts_instructions[part] = dict()
|
|
62
|
-
parts_instructions[part]["dimensions"] = obj.parts[part].get_dimensions()
|
|
63
|
-
parts_instructions[part]["metadata"] = obj.parts[part].metadata
|
|
64
|
-
write_labels(path,obj.labels)
|
|
65
|
-
loading_instructions["parts"] = parts_instructions
|
|
66
|
-
loading_instructions["extension"] = extension
|
|
67
|
-
with open(os.path.join(path+".yaml"),"w") as file:
|
|
68
|
-
yaml.dump(loading_instructions,file)
|
|
69
|
-
|
|
70
|
-
def write_labels(path,labels):
|
|
71
|
-
"""
|
|
72
|
-
Save labels in a folder
|
|
73
|
-
|
|
74
|
-
Parameters
|
|
75
|
-
----------
|
|
76
|
-
path : str
|
|
77
|
-
Path to the folder to save the labels into.
|
|
78
|
-
extension : str, optional
|
|
79
|
-
Extension of the files to save the labels into.
|
|
80
|
-
The default is "txt".
|
|
81
|
-
overwrite : bool, optional
|
|
82
|
-
Whether to overwrite the existing files. The default is False.
|
|
83
|
-
If False, the version name is iterated until a non-existing
|
|
84
|
-
file name is found.
|
|
85
|
-
kwargs : dict
|
|
86
|
-
Additional arguments to pass to the saver.
|
|
87
|
-
"""
|
|
88
|
-
with open(os.path.join(path,"labels.yaml"),"w") as file:
|
|
89
|
-
yaml.dump(labels,file)
|
|
90
|
-
|
|
91
|
-
def save_part_to_folder(obj,
|
|
92
|
-
path,
|
|
93
|
-
name=None,
|
|
94
|
-
extension=".npy",
|
|
95
|
-
save_labels=True,
|
|
96
|
-
write_instructions=True,
|
|
97
|
-
overwrite=False,
|
|
98
|
-
include_labels=True,
|
|
99
|
-
**kwargs):
|
|
100
|
-
"""
|
|
101
|
-
Save a Part instance in a folder
|
|
102
|
-
|
|
103
|
-
Parameters
|
|
104
|
-
----------
|
|
105
|
-
obj : Part
|
|
106
|
-
Part instance to save
|
|
107
|
-
path : str
|
|
108
|
-
Path to the folder to save the Part instance into.
|
|
109
|
-
extension : str, optional
|
|
110
|
-
Extension of the files to save the Part instance into.
|
|
111
|
-
The default is ".npy".
|
|
112
|
-
save_labels : bool, optional
|
|
113
|
-
Whether to save the labels. The default is True.
|
|
114
|
-
save_instructions : bool, optional
|
|
115
|
-
Whether to save the instructions. The default is True.
|
|
116
|
-
overwrite : bool, optional
|
|
117
|
-
Whether to overwrite the existing files. The default is False.
|
|
118
|
-
If False, the version name is iterated until a non-existing
|
|
119
|
-
file name is found.
|
|
120
|
-
include_labels: bool, optional
|
|
121
|
-
Whether to include the labels in the file. The default is True.
|
|
122
|
-
This is only relevant for .csv and .xlsx files.
|
|
123
|
-
If False, the labels are saved in a separate file.
|
|
124
|
-
kwargs : dict
|
|
125
|
-
Additional arguments to pass to the saver.
|
|
126
|
-
"""
|
|
127
|
-
if name is None:
|
|
128
|
-
name = obj.name
|
|
129
|
-
log.info(f"Saving Part instance {name} to folder {path} with extension {extension}")
|
|
130
|
-
if not os.path.isdir(path):
|
|
131
|
-
os.mkdir(path)
|
|
132
|
-
elif not overwrite:
|
|
133
|
-
os.mkdir(check_path(path))
|
|
134
|
-
if save_labels:
|
|
135
|
-
write_labels(path,obj.labels)
|
|
136
|
-
parts_instructions = dict()
|
|
137
|
-
if write_instructions:
|
|
138
|
-
parts_instructions["dimensions"] = obj.get_dimensions()
|
|
139
|
-
parts_instructions["metadata"] = obj.metadata
|
|
140
|
-
if extension == ".npy":
|
|
141
|
-
np.save(os.path.join(path,name+extension),obj.data,**kwargs)
|
|
142
|
-
elif extension == ".csv":
|
|
143
|
-
delimiter = kwargs.pop("delimiter",",")
|
|
144
|
-
if include_labels:
|
|
145
|
-
obj.to_pandas().to_csv(os.path.join(path,name+extension),
|
|
146
|
-
**kwargs)
|
|
147
|
-
parts_instructions["index_col"] = [i for i in range(len(obj.axes[0].dims))]
|
|
148
|
-
if len(obj.axes) > 1:
|
|
149
|
-
parts_instructions["header"] = [i for i in range(len(obj.axes[1].dimensions))]
|
|
150
|
-
else:
|
|
151
|
-
np.savetxt(os.path.join(path,name+extension),obj.data,
|
|
152
|
-
delimiter=delimiter,**kwargs)
|
|
153
|
-
elif extension == ".txt":
|
|
154
|
-
delimiter = kwargs.pop("delimiter","\t")
|
|
155
|
-
np.savetxt(os.path.join(path,name+extension),obj.data,
|
|
156
|
-
delimiter=delimiter,**kwargs)
|
|
157
|
-
elif extension == ".xlsx":
|
|
158
|
-
obj.to_pandas().to_excel(os.path.join(path,name+extension),
|
|
159
|
-
**kwargs)
|
|
160
|
-
else:
|
|
161
|
-
raise NotImplementedError(f"Extension {extension} not supported")
|
|
162
|
-
if write_instructions:
|
|
163
|
-
parts_instructions["file"] = os.path.join(path,name+extension)
|
|
164
|
-
with open(os.path.join(path,name+".yaml"),"w") as file:
|
|
165
|
-
yaml.dump(parts_instructions,file)
|
utils/savers/_to_nc.py
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Routines for saving to netCDF files.
|
|
3
|
-
"""
|
|
4
|
-
import os
|
|
5
|
-
import yaml
|
|
6
|
-
import pandas as pd
|
|
7
|
-
from mrio_toolbox.utils.savers._path_checker import check_path
|
|
8
|
-
import logging
|
|
9
|
-
import xarray as xr
|
|
10
|
-
|
|
11
|
-
log = logging.getLogger(__name__)
|
|
12
|
-
|
|
13
|
-
def save_to_nc(obj,path,overwrite=False,write_instructions=False,**kwargs):
|
|
14
|
-
"""
|
|
15
|
-
Save an MRIO or Part instance in a .nc file
|
|
16
|
-
|
|
17
|
-
Parameters
|
|
18
|
-
----------
|
|
19
|
-
path : str
|
|
20
|
-
Path to the .nc file to save the MRIO instance into.
|
|
21
|
-
|
|
22
|
-
**kwargs : dict
|
|
23
|
-
Additional arguments to pass to the saver.
|
|
24
|
-
"""
|
|
25
|
-
log.info(f"Saving {obj.__class__.__name__} instance to {path}")
|
|
26
|
-
if os.path.dirname(path) == "":
|
|
27
|
-
path = os.path.join(os.getcwd(), path)
|
|
28
|
-
#Check destination path
|
|
29
|
-
if not os.path.exists(os.path.dirname(path)):
|
|
30
|
-
log.info(f"{os.path.abspath(
|
|
31
|
-
os.path.dirname(path))} does not exist. Creating directory.")
|
|
32
|
-
os.makedirs(os.path.dirname(path))
|
|
33
|
-
|
|
34
|
-
ds = obj.to_xarray()
|
|
35
|
-
|
|
36
|
-
#Remove dict attrs (not supported for serialization)
|
|
37
|
-
attrs = list(ds.attrs.keys())
|
|
38
|
-
for attr in attrs:
|
|
39
|
-
if isinstance(ds.attrs[attr],dict):
|
|
40
|
-
log.warning(f"Attribute {attr} is a dict. It will not be saved.")
|
|
41
|
-
ds.attrs.pop(attr)
|
|
42
|
-
|
|
43
|
-
if isinstance(ds, xr.Dataset):
|
|
44
|
-
for var in ds.data_vars:
|
|
45
|
-
attrs = list(ds[var].attrs.keys())
|
|
46
|
-
for attr in attrs:
|
|
47
|
-
if isinstance(ds[var].attrs[attr],dict):
|
|
48
|
-
log.warning(f"Attribute {attr} of {var} is a dict. It will not be saved.")
|
|
49
|
-
ds[var].attrs.pop(attr)
|
|
50
|
-
|
|
51
|
-
if not overwrite:
|
|
52
|
-
path = check_path(path)
|
|
53
|
-
ds.to_netcdf(path,**kwargs)
|
|
54
|
-
if write_instructions:
|
|
55
|
-
instructions = {
|
|
56
|
-
"file": path
|
|
57
|
-
}
|
|
58
|
-
base_path, ext = os.path.splitext(path)
|
|
59
|
-
with open(base_path+".yaml","w") as file:
|
|
60
|
-
yaml.dump(instructions,file)
|
|
File without changes
|
|
File without changes
|