mrio-toolbox 1.1.1__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.

Files changed (61) hide show
  1. {mrio_toolbox-1.1.1.dist-info → mrio_toolbox-1.1.3.dist-info}/METADATA +2 -2
  2. mrio_toolbox-1.1.3.dist-info/RECORD +5 -0
  3. mrio_toolbox-1.1.3.dist-info/top_level.txt +1 -0
  4. mrio_toolbox/__init__.py +0 -21
  5. mrio_toolbox/_parts/_Axe.py +0 -539
  6. mrio_toolbox/_parts/_Part.py +0 -1698
  7. mrio_toolbox/_parts/__init__.py +0 -7
  8. mrio_toolbox/_parts/part_operations.py +0 -57
  9. mrio_toolbox/extractors/__init__.py +0 -20
  10. mrio_toolbox/extractors/downloaders.py +0 -36
  11. mrio_toolbox/extractors/emerging/__init__.py +0 -3
  12. mrio_toolbox/extractors/emerging/emerging_extractor.py +0 -117
  13. mrio_toolbox/extractors/eora/__init__.py +0 -3
  14. mrio_toolbox/extractors/eora/eora_extractor.py +0 -132
  15. mrio_toolbox/extractors/exiobase/__init__.py +0 -3
  16. mrio_toolbox/extractors/exiobase/exiobase_extractor.py +0 -270
  17. mrio_toolbox/extractors/extractors.py +0 -79
  18. mrio_toolbox/extractors/figaro/__init__.py +0 -3
  19. mrio_toolbox/extractors/figaro/figaro_downloader.py +0 -280
  20. mrio_toolbox/extractors/figaro/figaro_extractor.py +0 -187
  21. mrio_toolbox/extractors/gloria/__init__.py +0 -3
  22. mrio_toolbox/extractors/gloria/gloria_extractor.py +0 -202
  23. mrio_toolbox/extractors/gtap11/__init__.py +0 -7
  24. mrio_toolbox/extractors/gtap11/extraction/__init__.py +0 -3
  25. mrio_toolbox/extractors/gtap11/extraction/extractor.py +0 -129
  26. mrio_toolbox/extractors/gtap11/extraction/harpy_files/__init__.py +0 -6
  27. mrio_toolbox/extractors/gtap11/extraction/harpy_files/_header_sets.py +0 -279
  28. mrio_toolbox/extractors/gtap11/extraction/harpy_files/har_file.py +0 -262
  29. mrio_toolbox/extractors/gtap11/extraction/harpy_files/har_file_io.py +0 -974
  30. mrio_toolbox/extractors/gtap11/extraction/harpy_files/header_array.py +0 -300
  31. mrio_toolbox/extractors/gtap11/extraction/harpy_files/sl4.py +0 -229
  32. mrio_toolbox/extractors/gtap11/gtap_mrio/__init__.py +0 -6
  33. mrio_toolbox/extractors/gtap11/gtap_mrio/mrio_builder.py +0 -158
  34. mrio_toolbox/extractors/icio/__init__.py +0 -3
  35. mrio_toolbox/extractors/icio/icio_extractor.py +0 -121
  36. mrio_toolbox/extractors/wiod/__init__.py +0 -3
  37. mrio_toolbox/extractors/wiod/wiod_extractor.py +0 -143
  38. mrio_toolbox/mrio.py +0 -899
  39. mrio_toolbox/msm/__init__.py +0 -6
  40. mrio_toolbox/msm/multi_scale_mapping.py +0 -863
  41. mrio_toolbox/utils/__init__.py +0 -3
  42. mrio_toolbox/utils/converters/__init__.py +0 -5
  43. mrio_toolbox/utils/converters/pandas.py +0 -247
  44. mrio_toolbox/utils/converters/xarray.py +0 -130
  45. mrio_toolbox/utils/formatting/__init__.py +0 -0
  46. mrio_toolbox/utils/formatting/formatter.py +0 -528
  47. mrio_toolbox/utils/loaders/__init__.py +0 -7
  48. mrio_toolbox/utils/loaders/_loader.py +0 -312
  49. mrio_toolbox/utils/loaders/_loader_factory.py +0 -96
  50. mrio_toolbox/utils/loaders/_nc_loader.py +0 -184
  51. mrio_toolbox/utils/loaders/_np_loader.py +0 -112
  52. mrio_toolbox/utils/loaders/_pandas_loader.py +0 -128
  53. mrio_toolbox/utils/loaders/_parameter_loader.py +0 -386
  54. mrio_toolbox/utils/savers/__init__.py +0 -11
  55. mrio_toolbox/utils/savers/_path_checker.py +0 -37
  56. mrio_toolbox/utils/savers/_to_folder.py +0 -165
  57. mrio_toolbox/utils/savers/_to_nc.py +0 -60
  58. mrio_toolbox-1.1.1.dist-info/RECORD +0 -59
  59. mrio_toolbox-1.1.1.dist-info/top_level.txt +0 -1
  60. {mrio_toolbox-1.1.1.dist-info → mrio_toolbox-1.1.3.dist-info}/WHEEL +0 -0
  61. {mrio_toolbox-1.1.1.dist-info → mrio_toolbox-1.1.3.dist-info}/licenses/LICENSE +0 -0
@@ -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)
@@ -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)
@@ -1,59 +0,0 @@
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 +0,0 @@
1
- mrio_toolbox