mrio-toolbox 1.0.0__py3-none-any.whl → 1.1.1__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/__init__.py +18 -2
- mrio_toolbox/_parts/_Axe.py +95 -37
- mrio_toolbox/_parts/_Part.py +264 -70
- mrio_toolbox/_parts/__init__.py +4 -0
- mrio_toolbox/_parts/part_operations.py +24 -17
- mrio_toolbox/extractors/__init__.py +20 -0
- mrio_toolbox/extractors/downloaders.py +36 -0
- mrio_toolbox/extractors/emerging/__init__.py +3 -0
- mrio_toolbox/extractors/emerging/emerging_extractor.py +117 -0
- mrio_toolbox/extractors/eora/__init__.py +3 -0
- mrio_toolbox/extractors/eora/eora_extractor.py +132 -0
- mrio_toolbox/extractors/exiobase/__init__.py +3 -0
- mrio_toolbox/extractors/exiobase/exiobase_extractor.py +270 -0
- mrio_toolbox/extractors/extractors.py +79 -0
- mrio_toolbox/extractors/figaro/__init__.py +3 -0
- mrio_toolbox/extractors/figaro/figaro_downloader.py +280 -0
- mrio_toolbox/extractors/figaro/figaro_extractor.py +187 -0
- mrio_toolbox/extractors/gloria/__init__.py +3 -0
- mrio_toolbox/extractors/gloria/gloria_extractor.py +202 -0
- mrio_toolbox/extractors/gtap11/__init__.py +7 -0
- mrio_toolbox/extractors/gtap11/extraction/__init__.py +3 -0
- mrio_toolbox/extractors/gtap11/extraction/extractor.py +129 -0
- mrio_toolbox/extractors/gtap11/extraction/harpy_files/__init__.py +6 -0
- mrio_toolbox/extractors/gtap11/extraction/harpy_files/_header_sets.py +279 -0
- mrio_toolbox/extractors/gtap11/extraction/harpy_files/har_file.py +262 -0
- mrio_toolbox/extractors/gtap11/extraction/harpy_files/har_file_io.py +974 -0
- mrio_toolbox/extractors/gtap11/extraction/harpy_files/header_array.py +300 -0
- mrio_toolbox/extractors/gtap11/extraction/harpy_files/sl4.py +229 -0
- mrio_toolbox/extractors/gtap11/gtap_mrio/__init__.py +6 -0
- mrio_toolbox/extractors/gtap11/gtap_mrio/mrio_builder.py +158 -0
- mrio_toolbox/extractors/icio/__init__.py +3 -0
- mrio_toolbox/extractors/icio/icio_extractor.py +121 -0
- mrio_toolbox/extractors/wiod/__init__.py +3 -0
- mrio_toolbox/extractors/wiod/wiod_extractor.py +143 -0
- mrio_toolbox/mrio.py +254 -94
- mrio_toolbox/msm/__init__.py +6 -0
- mrio_toolbox/msm/multi_scale_mapping.py +863 -0
- mrio_toolbox/utils/__init__.py +3 -0
- mrio_toolbox/utils/converters/__init__.py +3 -0
- mrio_toolbox/utils/converters/pandas.py +8 -6
- mrio_toolbox/utils/converters/xarray.py +2 -13
- mrio_toolbox/utils/formatting/__init__.py +0 -0
- mrio_toolbox/utils/formatting/formatter.py +528 -0
- mrio_toolbox/utils/loaders/__init__.py +4 -0
- mrio_toolbox/utils/loaders/_loader.py +60 -4
- mrio_toolbox/utils/loaders/_loader_factory.py +22 -1
- mrio_toolbox/utils/loaders/_nc_loader.py +37 -1
- mrio_toolbox/utils/loaders/_pandas_loader.py +29 -3
- mrio_toolbox/utils/loaders/_parameter_loader.py +61 -16
- mrio_toolbox/utils/savers/__init__.py +3 -0
- mrio_toolbox/utils/savers/_path_checker.py +25 -7
- mrio_toolbox/utils/savers/_to_folder.py +6 -1
- mrio_toolbox/utils/savers/_to_nc.py +26 -18
- {mrio_toolbox-1.0.0.dist-info → mrio_toolbox-1.1.1.dist-info}/METADATA +10 -6
- mrio_toolbox-1.1.1.dist-info/RECORD +59 -0
- {mrio_toolbox-1.0.0.dist-info → mrio_toolbox-1.1.1.dist-info}/WHEEL +1 -1
- mrio_toolbox-1.0.0.dist-info/RECORD +0 -26
- {mrio_toolbox-1.0.0.dist-info → mrio_toolbox-1.1.1.dist-info/licenses}/LICENSE +0 -0
- {mrio_toolbox-1.0.0.dist-info → mrio_toolbox-1.1.1.dist-info}/top_level.txt +0 -0
|
@@ -13,16 +13,64 @@ log = logging.Logger(__name__)
|
|
|
13
13
|
|
|
14
14
|
class Loader:
|
|
15
15
|
"""
|
|
16
|
-
Parent class for the
|
|
16
|
+
Parent class for loaders in the MRIO toolbox.
|
|
17
|
+
|
|
18
|
+
The `Loader` class provides a base implementation for loading MRIO data.
|
|
19
|
+
It includes methods for extracting metadata, updating settings, and managing
|
|
20
|
+
groupings and labels. Specific loaders can inherit from this class to implement
|
|
21
|
+
format-specific loading functionality.
|
|
22
|
+
|
|
23
|
+
Instance variables
|
|
24
|
+
------------------
|
|
25
|
+
metadata : dict
|
|
26
|
+
Metadata associated with the loader.
|
|
27
|
+
labels : dict
|
|
28
|
+
Labels for the axes of the MRIO data.
|
|
29
|
+
groupings : dict
|
|
30
|
+
Groupings for the labels, defining higher-level aggregations.
|
|
31
|
+
file : str or None
|
|
32
|
+
Path to the file being loaded.
|
|
33
|
+
loader_kwargs : dict
|
|
34
|
+
Additional parameters for the loader.
|
|
35
|
+
|
|
36
|
+
Methods
|
|
37
|
+
-------
|
|
38
|
+
extract_basic_info(**kwargs):
|
|
39
|
+
Extract basic information such as path, labels, and groupings.
|
|
40
|
+
update_settings(**settings):
|
|
41
|
+
Update the loader settings with new parameters.
|
|
42
|
+
load_mrio():
|
|
43
|
+
Create an MRIO container based on the current parameters.
|
|
44
|
+
load_part(**kwargs):
|
|
45
|
+
Load an MRIO Part based on new or existing parameters.
|
|
46
|
+
set_groupings(groupings):
|
|
47
|
+
Update the groupings attribute of the loader.
|
|
48
|
+
update_attributes(**kwargs):
|
|
49
|
+
Update the current attributes of the loader.
|
|
50
|
+
load_groupings(file, dimension=None, path=None):
|
|
51
|
+
Load groupings from a file.
|
|
52
|
+
set_labels(labels):
|
|
53
|
+
Update the labels attribute of the loader.
|
|
54
|
+
available_parts(**kwargs):
|
|
55
|
+
Return the available parts in the MRIO data.
|
|
56
|
+
check_instructions(**kwargs):
|
|
57
|
+
Interpret the file argument for loading a part and check for instruction consistency.
|
|
58
|
+
|
|
59
|
+
Notes
|
|
60
|
+
-----
|
|
61
|
+
This class is intended to be used as a base class for specific loaders.
|
|
62
|
+
It provides general functionality for managing metadata, labels, and groupings,
|
|
63
|
+
but does not implement actual data loading.
|
|
17
64
|
"""
|
|
18
65
|
def __init__(
|
|
19
66
|
self
|
|
20
67
|
):
|
|
21
68
|
"""
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
They hold metadata and methods to load MRIO data.
|
|
69
|
+
Initialize a Loader object.
|
|
25
70
|
|
|
71
|
+
Notes
|
|
72
|
+
-----
|
|
73
|
+
Loaders are created with format-specific parameters. They hold metadata and methods to load MRIO data.
|
|
26
74
|
A loader is created using the base class if no specific loader is required,
|
|
27
75
|
i.e., if the data is directly loaded from dict, pandas or xarray.
|
|
28
76
|
In that case, the loader will fail when used,
|
|
@@ -78,6 +126,7 @@ class Loader:
|
|
|
78
126
|
self.metadata = dict()
|
|
79
127
|
self.labels = dict()
|
|
80
128
|
self.groupings = dict()
|
|
129
|
+
self.file = None
|
|
81
130
|
pass
|
|
82
131
|
|
|
83
132
|
def load_part(
|
|
@@ -222,6 +271,13 @@ class Loader:
|
|
|
222
271
|
"""
|
|
223
272
|
self.labels = labels
|
|
224
273
|
|
|
274
|
+
def available_parts(self,**kwargs):
|
|
275
|
+
"""
|
|
276
|
+
Return the available parts in the MRIO data
|
|
277
|
+
"""
|
|
278
|
+
if self.file is None:
|
|
279
|
+
raise FileNotFoundError("No file was provided.")
|
|
280
|
+
|
|
225
281
|
def check_instructions(self,**kwargs):
|
|
226
282
|
"""
|
|
227
283
|
Interpret the file argument for loading a part.
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Initialize the appropriate loader based on the provided parameters.
|
|
3
|
+
"""
|
|
1
4
|
import os
|
|
2
5
|
import yaml
|
|
3
6
|
from mrio_toolbox.utils.loaders._nc_loader import NetCDF_Loader
|
|
@@ -22,6 +25,8 @@ def make_loader(**kwargs):
|
|
|
22
25
|
All non-netCDF files are loaded using the Parameter_Loader.
|
|
23
26
|
"""
|
|
24
27
|
file = kwargs.get("file",None)
|
|
28
|
+
if file is not None:
|
|
29
|
+
file = os.path.abspath(file) # Avoid issue with UNIX/windows path
|
|
25
30
|
extension = kwargs.get("extension",None)
|
|
26
31
|
|
|
27
32
|
if extension is None:
|
|
@@ -72,4 +77,20 @@ def load_from_yaml(**kwargs):
|
|
|
72
77
|
#Override parameters with kwargs
|
|
73
78
|
log.debug(f"Override file parameter {kwarg} with explicit parameter {kwargs[kwarg]}")
|
|
74
79
|
parameters[kwarg] = kwargs[kwarg]
|
|
75
|
-
|
|
80
|
+
|
|
81
|
+
# Error handling
|
|
82
|
+
if "path" not in parameters.keys():
|
|
83
|
+
if "file" not in parameters.keys():
|
|
84
|
+
log.info("No path provided, using current working directory instead")
|
|
85
|
+
parameters["path"] = os.getcwd()
|
|
86
|
+
elif not os.path.isdir(parameters["path"]):
|
|
87
|
+
log.error("Provided path is not a directory")
|
|
88
|
+
raise ValueError("Provided path is not a directory")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
return make_loader(instructions=instructions,**parameters)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Provides the NetCDF_Loader class for loading MRIO data from netCDF files.
|
|
3
|
+
"""
|
|
1
4
|
from mrio_toolbox.utils.loaders._loader import Loader
|
|
2
5
|
from mrio_toolbox.utils import converters
|
|
3
6
|
import xarray as xr
|
|
@@ -10,13 +13,46 @@ log = logging.getLogger(__name__)
|
|
|
10
13
|
class NetCDF_Loader(Loader):
|
|
11
14
|
"""
|
|
12
15
|
Class for loading MRIO data from a netCDF file.
|
|
16
|
+
|
|
17
|
+
The `NetCDF_Loader` class extends the base `Loader` class to provide
|
|
18
|
+
functionality for loading MRIO data stored in netCDF format. It uses the
|
|
19
|
+
xarray library to load the data and extract metadata, labels, and groupings.
|
|
20
|
+
|
|
21
|
+
Instance variables
|
|
22
|
+
------------------
|
|
23
|
+
data : xarray.Dataset
|
|
24
|
+
The loaded netCDF data stored as an xarray Dataset.
|
|
25
|
+
_available_parts : list
|
|
26
|
+
List of available parts in the MRIO data.
|
|
27
|
+
metadata : dict
|
|
28
|
+
Metadata extracted from the netCDF file.
|
|
29
|
+
labels : dict
|
|
30
|
+
Labels for the axes of the MRIO data.
|
|
31
|
+
groupings : dict
|
|
32
|
+
Groupings for the labels, defining higher-level aggregations.
|
|
33
|
+
file : str or None
|
|
34
|
+
Path to the netCDF file being loaded.
|
|
35
|
+
loader_kwargs : dict
|
|
36
|
+
Additional parameters passed to the xarray loader.
|
|
37
|
+
|
|
38
|
+
Methods
|
|
39
|
+
-------
|
|
40
|
+
load_mrio(file=None, **kwargs):
|
|
41
|
+
Load a netCDF file into memory and extract metadata.
|
|
42
|
+
load_part(file=None, **kwargs):
|
|
43
|
+
Load a specific part of the MRIO table.
|
|
44
|
+
get_file(file=None, **kwargs):
|
|
45
|
+
Get the file to load, updating the current file if necessary.
|
|
46
|
+
available_parts(**kwargs):
|
|
47
|
+
Return a list of available parts in the MRIO table.
|
|
13
48
|
"""
|
|
49
|
+
|
|
14
50
|
def __init__(
|
|
15
51
|
self,
|
|
16
52
|
**kwargs
|
|
17
53
|
):
|
|
18
54
|
"""
|
|
19
|
-
|
|
55
|
+
Initialize a NetCDF_Loader object.
|
|
20
56
|
|
|
21
57
|
Parameters
|
|
22
58
|
----------
|
|
@@ -11,15 +11,41 @@ log = logging.getLogger(__name__)
|
|
|
11
11
|
class Pandas_Loader(Parameter_Loader):
|
|
12
12
|
"""
|
|
13
13
|
Class for loading MRIO data through Pandas.
|
|
14
|
+
|
|
15
|
+
The `Pandas_Loader` class extends the `Parameter_Loader` class to provide
|
|
16
|
+
functionality for loading MRIO data from `.xlsx` and `.csv` files. It uses
|
|
17
|
+
the Pandas library to read the data and extract metadata, labels, and parts.
|
|
18
|
+
|
|
19
|
+
Instance variables
|
|
20
|
+
------------------
|
|
21
|
+
groupings : dict
|
|
22
|
+
Groupings for the labels, defining higher-level aggregations.
|
|
23
|
+
labels : dict
|
|
24
|
+
Explicit dictionary of labels for the MRIO data.
|
|
25
|
+
dimensions : list of int
|
|
26
|
+
List of label names.
|
|
27
|
+
path : str
|
|
28
|
+
Path to the data file.
|
|
29
|
+
labels_path : str
|
|
30
|
+
Path to the labels file.
|
|
31
|
+
parts : dict
|
|
32
|
+
Parts to load, with specific settings.
|
|
33
|
+
loader_kwargs : dict
|
|
34
|
+
Parameters passed to the underlying Pandas loader (e.g., `read_excel`, `read_csv`).
|
|
35
|
+
|
|
36
|
+
Methods
|
|
37
|
+
-------
|
|
38
|
+
load_part(**kwargs):
|
|
39
|
+
Load a specific Part from explicit parameters.
|
|
40
|
+
|
|
14
41
|
"""
|
|
42
|
+
|
|
15
43
|
def __init__(
|
|
16
44
|
self,
|
|
17
45
|
**kwargs
|
|
18
46
|
):
|
|
19
47
|
"""
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
Used for loading data from .xlsx and .csv files.
|
|
48
|
+
Initialize a Pandas_Loader object.
|
|
23
49
|
|
|
24
50
|
Parameters
|
|
25
51
|
----------
|
|
@@ -14,41 +14,86 @@ log = logging.getLogger(__name__)
|
|
|
14
14
|
class Parameter_Loader(Loader):
|
|
15
15
|
"""
|
|
16
16
|
Class for loading MRIO data from explicit parameters.
|
|
17
|
+
|
|
18
|
+
The `Parameter_Loader` class extends the `Loader` class to provide
|
|
19
|
+
functionality for loading MRIO data from explicit parameters, such as
|
|
20
|
+
`.npy`, `.csv`, or `.txt` files. It supports metadata extraction, label
|
|
21
|
+
formatting, and grouping management.
|
|
22
|
+
|
|
23
|
+
Instance variables
|
|
24
|
+
------------------
|
|
25
|
+
metadata : dict
|
|
26
|
+
Metadata associated with the MRIO data.
|
|
27
|
+
labels : dict
|
|
28
|
+
Explicit dictionary of labels for the MRIO data.
|
|
29
|
+
groupings : dict
|
|
30
|
+
Groupings for the labels, defining higher-level aggregations.
|
|
31
|
+
path : str
|
|
32
|
+
Path to the data file or directory.
|
|
33
|
+
labels_path : str
|
|
34
|
+
Path to the labels file or directory.
|
|
35
|
+
part_settings : dict
|
|
36
|
+
Settings for loading specific parts of the MRIO data.
|
|
37
|
+
extension : str or None
|
|
38
|
+
File extension for the data files (e.g., `.npy`, `.csv`).
|
|
39
|
+
|
|
40
|
+
Methods
|
|
41
|
+
-------
|
|
42
|
+
available_parts(extension=None):
|
|
43
|
+
List the available parts in the current path.
|
|
44
|
+
extract_path(update=False, **kwargs):
|
|
45
|
+
Extract the path from the provided parameters.
|
|
46
|
+
format_labels(labels):
|
|
47
|
+
Process and format the label information.
|
|
48
|
+
load_mrio(**kwargs):
|
|
49
|
+
Load MRIO data from explicit parameters.
|
|
50
|
+
get_file(**kwargs):
|
|
51
|
+
Get the file to load based on the provided parameters.
|
|
52
|
+
load_part(**kwargs):
|
|
53
|
+
Load a specific Part from explicit parameters.
|
|
54
|
+
_get_labels(l):
|
|
55
|
+
Find the labels fitting an axis with a given shape.
|
|
56
|
+
|
|
57
|
+
Notes
|
|
58
|
+
-----
|
|
59
|
+
This class is designed for loading MRIO data in non-netCDF formats.
|
|
60
|
+
It provides flexible handling of paths, labels, and groupings, making it
|
|
61
|
+
suitable for a variety of file formats and data structures.
|
|
17
62
|
"""
|
|
18
63
|
def __init__(
|
|
19
64
|
self,
|
|
20
65
|
**kwargs
|
|
21
66
|
):
|
|
22
67
|
"""
|
|
23
|
-
|
|
68
|
+
Initialize a Parameter_Loader object.
|
|
24
69
|
|
|
25
70
|
Parameters
|
|
26
71
|
----------
|
|
27
72
|
loader_kwargs : dict, optional
|
|
28
73
|
Parameters passed to the underlying loader.
|
|
29
|
-
-
|
|
30
|
-
-
|
|
74
|
+
- `.npy`: numpy.load
|
|
75
|
+
- `.csv`, `.txt`: numpy.loadtxt
|
|
31
76
|
groupings : dict, optional
|
|
32
|
-
|
|
77
|
+
Groupings for the labels, defining higher-level aggregations.
|
|
33
78
|
labels : dict, optional
|
|
34
|
-
Explicit dictionary of labels.
|
|
79
|
+
Explicit dictionary of labels for the MRIO data.
|
|
35
80
|
dimensions : list of int, optional
|
|
36
81
|
List of label names.
|
|
37
82
|
path : str, optional
|
|
38
|
-
Path to the data
|
|
39
|
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
-
|
|
44
|
-
- table/year/version
|
|
83
|
+
Path to the data file or directory. Recognized paths include:
|
|
84
|
+
- `path`
|
|
85
|
+
- `mrio_path`
|
|
86
|
+
- `file`
|
|
87
|
+
- `data_path`
|
|
88
|
+
- `table/year/version`
|
|
45
89
|
labels_path : str, optional
|
|
46
|
-
Path to the labels
|
|
90
|
+
Path to the labels file or directory.
|
|
47
91
|
parts : dict, optional
|
|
48
|
-
|
|
92
|
+
Settings for loading specific parts of the MRIO data.
|
|
93
|
+
extension : str, optional
|
|
94
|
+
File extension for the data files (e.g., `.npy`, `.csv`).
|
|
49
95
|
**kwargs : dict
|
|
50
|
-
|
|
51
|
-
MRIO metadata are passed to associated parts.
|
|
96
|
+
Additional metadata for the MRIO data.
|
|
52
97
|
|
|
53
98
|
"""
|
|
54
99
|
self.extract_basic_info(**kwargs)
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Routines for checking and extending file paths to avoid overwriting existing files.
|
|
3
|
+
"""
|
|
1
4
|
import os
|
|
5
|
+
import re
|
|
2
6
|
|
|
3
7
|
def check_path(path):
|
|
4
8
|
"""
|
|
@@ -9,11 +13,25 @@ def check_path(path):
|
|
|
9
13
|
path : str
|
|
10
14
|
Path currently selected
|
|
11
15
|
"""
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
|
|
17
|
+
i = 1
|
|
18
|
+
while os.path.isfile(path):
|
|
19
|
+
base_path, ext = os.path.splitext(path)
|
|
20
|
+
|
|
21
|
+
# Remove existing _number suffix if present
|
|
22
|
+
base_path = re.sub(r'_\d+$', repl, base_path)
|
|
23
|
+
|
|
24
|
+
path = f"{base_path}_{i}{ext}"
|
|
25
|
+
i += 1
|
|
26
|
+
|
|
19
27
|
return path
|
|
28
|
+
|
|
29
|
+
def repl(match):
|
|
30
|
+
'''
|
|
31
|
+
Condition for replacing the _number suffix
|
|
32
|
+
|
|
33
|
+
If the suffix as 2 or 4 digits, we keep it and add version number after
|
|
34
|
+
2 digits can be used to identify MRIO tables, 4 digits for years
|
|
35
|
+
'''
|
|
36
|
+
s = match.group()
|
|
37
|
+
return s if len(s) == 3 or len(s) == 5 else ""
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Routines for saving MRIO and Part instances to folders.
|
|
3
|
+
"""
|
|
4
|
+
|
|
1
5
|
import os
|
|
2
6
|
from mrio_toolbox.utils.savers._path_checker import check_path
|
|
3
7
|
import numpy as np
|
|
@@ -37,7 +41,8 @@ def save_mrio_to_folder(obj,
|
|
|
37
41
|
os.mkdir(path)
|
|
38
42
|
elif not overwrite:
|
|
39
43
|
os.mkdir(check_path(path))
|
|
40
|
-
log.info(f"Saving MRIO instance {name} to folder {path}")
|
|
44
|
+
log.info(f"Saving MRIO instance {name} to folder {path}")
|
|
45
|
+
kwargs.pop("write_instructions", None) #Instructions are written anyway
|
|
41
46
|
loading_instructions = dict()
|
|
42
47
|
loading_instructions.update(obj.metadata)
|
|
43
48
|
loading_instructions["path"] = path
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Routines for saving to netCDF files.
|
|
3
|
+
"""
|
|
1
4
|
import os
|
|
2
5
|
import yaml
|
|
3
6
|
import pandas as pd
|
|
4
7
|
from mrio_toolbox.utils.savers._path_checker import check_path
|
|
5
8
|
import logging
|
|
9
|
+
import xarray as xr
|
|
6
10
|
|
|
7
11
|
log = logging.getLogger(__name__)
|
|
8
12
|
|
|
9
13
|
def save_to_nc(obj,path,overwrite=False,write_instructions=False,**kwargs):
|
|
10
14
|
"""
|
|
11
|
-
Save an MRIO or
|
|
15
|
+
Save an MRIO or Part instance in a .nc file
|
|
12
16
|
|
|
13
17
|
Parameters
|
|
14
18
|
----------
|
|
@@ -19,12 +23,15 @@ def save_to_nc(obj,path,overwrite=False,write_instructions=False,**kwargs):
|
|
|
19
23
|
Additional arguments to pass to the saver.
|
|
20
24
|
"""
|
|
21
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
|
+
|
|
22
34
|
ds = obj.to_xarray()
|
|
23
|
-
for index in ds.indexes:
|
|
24
|
-
if isinstance(ds.indexes[index],pd.MultiIndex):
|
|
25
|
-
import cf_xarray as cfxr
|
|
26
|
-
#Compress MultiIndex data as it is not supported by xarray
|
|
27
|
-
ds = cfxr.encode_multi_index_as_compress(ds,index)
|
|
28
35
|
|
|
29
36
|
#Remove dict attrs (not supported for serialization)
|
|
30
37
|
attrs = list(ds.attrs.keys())
|
|
@@ -32,21 +39,22 @@ def save_to_nc(obj,path,overwrite=False,write_instructions=False,**kwargs):
|
|
|
32
39
|
if isinstance(ds.attrs[attr],dict):
|
|
33
40
|
log.warning(f"Attribute {attr} is a dict. It will not be saved.")
|
|
34
41
|
ds.attrs.pop(attr)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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)
|
|
42
50
|
|
|
43
51
|
if not overwrite:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
ds.to_netcdf(path+".nc",**kwargs)
|
|
52
|
+
path = check_path(path)
|
|
53
|
+
ds.to_netcdf(path,**kwargs)
|
|
47
54
|
if write_instructions:
|
|
48
55
|
instructions = {
|
|
49
|
-
"file": path
|
|
56
|
+
"file": path
|
|
50
57
|
}
|
|
51
|
-
|
|
58
|
+
base_path, ext = os.path.splitext(path)
|
|
59
|
+
with open(base_path+".yaml","w") as file:
|
|
52
60
|
yaml.dump(instructions,file)
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: mrio_toolbox
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.1.1
|
|
4
4
|
Summary: Basic manipulation of Multi-Regional Input-Output tables.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
Author-email: Timothe Beaufils <timothe.beaufils@pik-potsdam.de>, Florian Wirth <florian.wirth@pik-potsdam.de>
|
|
6
|
+
License-Expression: GPL-3.0-or-later
|
|
7
|
+
Project-URL: Homepage, https://codeberg.org/tbeaufils/mrio_toolbox
|
|
8
|
+
Project-URL: Documentation, https://tbeaufils.codeberg.page/
|
|
8
9
|
Keywords: MRIO,Input-Output,Economics,Industrial Ecology,netcdf,International Trade
|
|
9
10
|
Classifier: Programming Language :: Python :: 3
|
|
10
|
-
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
|
|
11
11
|
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Requires-Python: >=3.6
|
|
12
15
|
Description-Content-Type: text/markdown
|
|
13
16
|
License-File: LICENSE
|
|
14
17
|
Requires-Dist: netcdf4
|
|
@@ -16,6 +19,7 @@ Requires-Dist: xarray
|
|
|
16
19
|
Requires-Dist: numpy
|
|
17
20
|
Requires-Dist: pandas
|
|
18
21
|
Requires-Dist: openpyxl
|
|
22
|
+
Dynamic: license-file
|
|
19
23
|
|
|
20
24
|
# README mrio_toolbox
|
|
21
25
|
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
mrio_toolbox/__init__.py,sha256=oFgfSYusvbP0OwzcEE3ItG-3OS2nGCu5Dh3ANPu99sM,907
|
|
2
|
+
mrio_toolbox/mrio.py,sha256=ll1I-dKKncxo-GhnWhRmlLUezUxMr1dIUuKZbC7Kb3w,34936
|
|
3
|
+
mrio_toolbox/_parts/_Axe.py,sha256=LhH1Vx085B6Jv-jDTT_ROP2-9GyyDVUD-L62jUhREMw,19888
|
|
4
|
+
mrio_toolbox/_parts/_Part.py,sha256=iWCQdFitv4SmufTLFX4lbHqL1rKmwGklueVGbLsP7Bk,60899
|
|
5
|
+
mrio_toolbox/_parts/__init__.py,sha256=dls6ESbnqzUiSpGRg9EkVN0XfUgDdpzRDb9Tvf9Znlk,127
|
|
6
|
+
mrio_toolbox/_parts/part_operations.py,sha256=PpGnSpo2evMtXIHCMBHTaA7sXv6kZv8qaBpHzgetnq4,1622
|
|
7
|
+
mrio_toolbox/extractors/__init__.py,sha256=uwp-VEHkkvKncdc15V9Hs0J6ABMFw6oLfnMeYh0NQGs,500
|
|
8
|
+
mrio_toolbox/extractors/downloaders.py,sha256=_IdNkCzhizZZ5rvPpvM-TvQ2eny9PuGl7Q-mZPT0SKk,1361
|
|
9
|
+
mrio_toolbox/extractors/extractors.py,sha256=SqMptIFADlQehp8x0fv8PFYGNpID3c3sADX2eEvTx58,3431
|
|
10
|
+
mrio_toolbox/extractors/emerging/__init__.py,sha256=5L_OdZVy499lInfn1qNysR5gkQCsYtxHQ76nQgT6Wlk,53
|
|
11
|
+
mrio_toolbox/extractors/emerging/emerging_extractor.py,sha256=8twv8bIN3LCvsjYwRzHks4YUrJSYlIP70Mi1I3WXYeg,3699
|
|
12
|
+
mrio_toolbox/extractors/eora/__init__.py,sha256=hNEV1fd5VGu0euVyAVPc5FX3eDrK0P8sf0pCBJo05RY,50
|
|
13
|
+
mrio_toolbox/extractors/eora/eora_extractor.py,sha256=-cFX0FhxYixu4COlhAc4Cia98UpwlRGMQRm2iKt8VQ4,4129
|
|
14
|
+
mrio_toolbox/extractors/exiobase/__init__.py,sha256=Yy3X5PH5SEPvQhX71Oae8QL8nKvfTuaQVwVwUgXpf1g,55
|
|
15
|
+
mrio_toolbox/extractors/exiobase/exiobase_extractor.py,sha256=Zb9iiuW3VCxjKpHAofs5bPIYMGZ0DQwR44RW3fmaLOs,13455
|
|
16
|
+
mrio_toolbox/extractors/figaro/__init__.py,sha256=dKuW3WsJ_UcilFPDXczvfGnYgvCFuSc6p3mbYTEsHN4,78
|
|
17
|
+
mrio_toolbox/extractors/figaro/figaro_downloader.py,sha256=q5NbNRYPDVnOuXpbD7q1blo-5rKBNEssAjijU263Mqw,13221
|
|
18
|
+
mrio_toolbox/extractors/figaro/figaro_extractor.py,sha256=_MZtQU5g9taxFfux4b4cq3ZTtT_dda3otXNDrAUkgHo,7792
|
|
19
|
+
mrio_toolbox/extractors/gloria/__init__.py,sha256=IQ_B4KYmKL1013YaFDnFl8JNez7nkF4Hv4oyT6shxyk,51
|
|
20
|
+
mrio_toolbox/extractors/gloria/gloria_extractor.py,sha256=cr_nqy_rAZINhELQDhDooqa9D-3JGSS9LN1f0VkDQq0,6898
|
|
21
|
+
mrio_toolbox/extractors/gtap11/__init__.py,sha256=Zk5yS2MyEzOdMvphFKifnqINQeAiPC3H4h-jIEWkYoM,247
|
|
22
|
+
mrio_toolbox/extractors/gtap11/extraction/__init__.py,sha256=LbLoTaFAlXmgCATnjRdNUIwgpUTzphGJLxT53i72ur0,54
|
|
23
|
+
mrio_toolbox/extractors/gtap11/extraction/extractor.py,sha256=v5DWVhfYkU7VjFfFJ94KON2ump5ceeX92WiDteJrSOM,4225
|
|
24
|
+
mrio_toolbox/extractors/gtap11/extraction/harpy_files/__init__.py,sha256=brrMawTkLnuXroM6ms0WKersbnooKbyAFCqqUq2Cysg,245
|
|
25
|
+
mrio_toolbox/extractors/gtap11/extraction/harpy_files/_header_sets.py,sha256=Ij4Qu_WDydFQnyWI_eabFFBBODKvqt0iQ-qw0A089b0,10612
|
|
26
|
+
mrio_toolbox/extractors/gtap11/extraction/harpy_files/har_file.py,sha256=RZJGqucx1XBFcJNuekgCnpKw1wERur70WNMv8wPasDU,10765
|
|
27
|
+
mrio_toolbox/extractors/gtap11/extraction/harpy_files/har_file_io.py,sha256=bqKT5PjxktJNOOaJkVPrmZpnm2W0dZGX3pRWcuI3UYU,36889
|
|
28
|
+
mrio_toolbox/extractors/gtap11/extraction/harpy_files/header_array.py,sha256=wcSjSyJUxMo0u5tlQ3YvxZkHz3l11JIZhhFvq0HBTeU,10934
|
|
29
|
+
mrio_toolbox/extractors/gtap11/extraction/harpy_files/sl4.py,sha256=16rtQHNIs8IiNL8iCXDYjGHbB6Ay8pKV0yjpMJLCIQo,10888
|
|
30
|
+
mrio_toolbox/extractors/gtap11/gtap_mrio/__init__.py,sha256=ybiLYcBuR1_EOZoPuxAre0HGRO9YiHzyGpr7B8BAc5w,134
|
|
31
|
+
mrio_toolbox/extractors/gtap11/gtap_mrio/mrio_builder.py,sha256=CnmbiGFcYsmkKJCzf0_ZdZ8nX2-prstxggtrCw9PNxU,5825
|
|
32
|
+
mrio_toolbox/extractors/icio/__init__.py,sha256=emSLWDbQp4bsRY458fKITMHORbLjoRvrdxgek2WtK5o,50
|
|
33
|
+
mrio_toolbox/extractors/icio/icio_extractor.py,sha256=t4nQlSLsMAtEJRcA1GHG67f-0TKd2LfUEO1vR2-SAV4,5013
|
|
34
|
+
mrio_toolbox/extractors/wiod/__init__.py,sha256=JSJcx-3jMqhO7E0kcO7lpmbDqTv0wPfsDOw9R9PTPYA,50
|
|
35
|
+
mrio_toolbox/extractors/wiod/wiod_extractor.py,sha256=FRTZ40BrRD6mK_ru2i6eFGSAFPFQ8s7S_Pir1gZyipo,4162
|
|
36
|
+
mrio_toolbox/msm/__init__.py,sha256=YaLmvU6Vlxk-bSGv-HgWR-7rKa2mqTuDOwmBQdhkHi0,192
|
|
37
|
+
mrio_toolbox/msm/multi_scale_mapping.py,sha256=Rshz9Q4DOFpaf17lYFMdLxkRayZGzkt73UkhXZ5kSjw,34510
|
|
38
|
+
mrio_toolbox/utils/__init__.py,sha256=BdiUAsKXUfe-vEJSsyNOTwt1RWVCXQ_B1kAZ-EwPEmQ,108
|
|
39
|
+
mrio_toolbox/utils/converters/__init__.py,sha256=HDYyq9Hu7ooi3nrS4yfrOzCcwZ--VkGhHlXEESLN5-A,163
|
|
40
|
+
mrio_toolbox/utils/converters/pandas.py,sha256=aY3B-Rk-zBDL18-HnA6rpmItECJsrrT0c42f0CHLI-A,7665
|
|
41
|
+
mrio_toolbox/utils/converters/xarray.py,sha256=VqXH6KMLnp8pXHm3TYO1-w2hDv9_Ads5puW-PwctRMQ,3721
|
|
42
|
+
mrio_toolbox/utils/formatting/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
43
|
+
mrio_toolbox/utils/formatting/formatter.py,sha256=yK2t8-MzEH1P9TMqZRj5ud26f1tZMqEkKpm8XgTblso,20870
|
|
44
|
+
mrio_toolbox/utils/loaders/__init__.py,sha256=I0_rQReuL4Os4G0ZOhajUtMQB6fdTkjV2Bf1UDbSpL0,203
|
|
45
|
+
mrio_toolbox/utils/loaders/_loader.py,sha256=tzV_yCkbPkfcsRgeUA0oyss_flU17HJ_lC4IC7duxj0,11210
|
|
46
|
+
mrio_toolbox/utils/loaders/_loader_factory.py,sha256=L3L06IkaBcRekcFr-_iRabAOpuLqSSCF24EG-ge5l-w,3300
|
|
47
|
+
mrio_toolbox/utils/loaders/_nc_loader.py,sha256=duqnnOV4-9tXY0TE6gk9fWR_gFrYGzp_dYB6uZ4PFmY,5263
|
|
48
|
+
mrio_toolbox/utils/loaders/_np_loader.py,sha256=qrOXoiAkpWjuEJtAf3iJvk1qRP6DNFtK3m-whJjp09o,3784
|
|
49
|
+
mrio_toolbox/utils/loaders/_pandas_loader.py,sha256=TO9OdGjaZYZheICZbWAx7-W6GE8VxK1ftMEyP3PG7n8,4065
|
|
50
|
+
mrio_toolbox/utils/loaders/_parameter_loader.py,sha256=M8ZNKuuLY6cZF6pdlpM5fdFhK9NKrJ-DY9N_2mbCH6Y,13157
|
|
51
|
+
mrio_toolbox/utils/savers/__init__.py,sha256=uiaTRDuqTYNsTAYME3NQgFzAqFjdg74S2nBvGR0ieZ4,313
|
|
52
|
+
mrio_toolbox/utils/savers/_path_checker.py,sha256=f_oTP2xBybtNqK1wmHSv_9ZlXU7M89YopPBdFYeqvzk,916
|
|
53
|
+
mrio_toolbox/utils/savers/_to_folder.py,sha256=jGQNmiofx47tCnwAa_s20Tmbn-XrCmv22SV7cYyGMbI,6155
|
|
54
|
+
mrio_toolbox/utils/savers/_to_nc.py,sha256=I8AKwsB_0w_uwCI5pdD3HGf-ur96yAurJKzPyM8sv4w,1931
|
|
55
|
+
mrio_toolbox-1.1.1.dist-info/licenses/LICENSE,sha256=q7yPlSQr4UbocyAmi56sBygg841JSclXoeXH8eOG7xQ,35819
|
|
56
|
+
mrio_toolbox-1.1.1.dist-info/METADATA,sha256=C6R8thAWD5oJTMF4H834cGx2nYPQ_oZ1avQIYI2C9_E,1193
|
|
57
|
+
mrio_toolbox-1.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
58
|
+
mrio_toolbox-1.1.1.dist-info/top_level.txt,sha256=Q2vYXHwBrGslGjwHwr_dnCyVOfx1gXwxd2G739rNwZg,13
|
|
59
|
+
mrio_toolbox-1.1.1.dist-info/RECORD,,
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
mrio_toolbox/__init__.py,sha256=FshX9q9yXmtnBjyqg1UJa67vJfIItynqMj0w-LYNQ5I,142
|
|
2
|
-
mrio_toolbox/mrio.py,sha256=VWXFZ_cE-36ohcVbC_9uClwf1YOtxRO7btvsP2MWFPo,27165
|
|
3
|
-
mrio_toolbox/_parts/_Axe.py,sha256=1QgIhQAGB7BsoImx3TtT72UBfR1eNvGbeE5S39kG7So,17776
|
|
4
|
-
mrio_toolbox/_parts/_Part.py,sha256=9gsvTjRmbMOjk-KW-b4_EdD510i8PEr4td1qsAYP1Gc,52924
|
|
5
|
-
mrio_toolbox/_parts/__init__.py,sha256=avCyX-GGW5X9z5nyJ71lf02bvODfDQ29P6-B0yY67HA,67
|
|
6
|
-
mrio_toolbox/_parts/part_operations.py,sha256=NDW-chkkdfDdX4NxrQUD2NIbEB03iQnyCikY8qLPZBU,1564
|
|
7
|
-
mrio_toolbox/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
-
mrio_toolbox/utils/converters/__init__.py,sha256=OC7szDkNwDyqXhCNsqG2p2bUiWCeedaKLUmt68BDIUs,42
|
|
9
|
-
mrio_toolbox/utils/converters/pandas.py,sha256=dJDEJpukvcRana39JSpxgd9F94kJGSewgvB5kVR6K_A,7612
|
|
10
|
-
mrio_toolbox/utils/converters/xarray.py,sha256=_tjpUM7ViT5hGWlLB_CHvugfQY_4KLhmkmbJA6mMnaw,4143
|
|
11
|
-
mrio_toolbox/utils/loaders/__init__.py,sha256=UGKPYdZUgofltQhWDHBSRe62RCPj_xC5nrknkQIfZFk,95
|
|
12
|
-
mrio_toolbox/utils/loaders/_loader.py,sha256=q3ROBSNOd1mPz_NM36Jxt8KkNhuYnPmB4sipwLE3eCQ,9001
|
|
13
|
-
mrio_toolbox/utils/loaders/_loader_factory.py,sha256=77TFy7epp5gj9uWcDYLL-JrKBzu3to7t3bawpXbVqYQ,2687
|
|
14
|
-
mrio_toolbox/utils/loaders/_nc_loader.py,sha256=jNYovf4hb9w_00uW7iyzaWqtcBKgB82Jr1XU22R_hU4,3920
|
|
15
|
-
mrio_toolbox/utils/loaders/_np_loader.py,sha256=qrOXoiAkpWjuEJtAf3iJvk1qRP6DNFtK3m-whJjp09o,3784
|
|
16
|
-
mrio_toolbox/utils/loaders/_pandas_loader.py,sha256=kBZ3cmhXmp4W441C0IGFBFhMxNTwiMHKB3WSkNkCRzc,3194
|
|
17
|
-
mrio_toolbox/utils/loaders/_parameter_loader.py,sha256=VJGSNmLgahfoZSLfGPeVOxUBYJG5MNN2wbLmW4b-PQs,11259
|
|
18
|
-
mrio_toolbox/utils/savers/__init__.py,sha256=iQCLNjgPkjYAomeJGHYL5M2395nOFI7JcWKYKmCnz7E,238
|
|
19
|
-
mrio_toolbox/utils/savers/_path_checker.py,sha256=UTewg5tvSJw1NFd2EG9OlHP87wXVAPSnhX1DTCxa9oc,416
|
|
20
|
-
mrio_toolbox/utils/savers/_to_folder.py,sha256=0H9hSwLultwJtp5TBSsyHwdx_hJCvgEQUZFuLPeZO2s,6010
|
|
21
|
-
mrio_toolbox/utils/savers/_to_nc.py,sha256=0meSTbMvWdrMyrwUJ1iF5rmM1NmNwGuxYwn5YLuOTj8,1757
|
|
22
|
-
mrio_toolbox-1.0.0.dist-info/LICENSE,sha256=q7yPlSQr4UbocyAmi56sBygg841JSclXoeXH8eOG7xQ,35819
|
|
23
|
-
mrio_toolbox-1.0.0.dist-info/METADATA,sha256=XcwCkHymQYqm9abBcO9FyG3BO7-leVsGxVWOSHZNLok,976
|
|
24
|
-
mrio_toolbox-1.0.0.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
|
|
25
|
-
mrio_toolbox-1.0.0.dist-info/top_level.txt,sha256=Q2vYXHwBrGslGjwHwr_dnCyVOfx1gXwxd2G739rNwZg,13
|
|
26
|
-
mrio_toolbox-1.0.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|