Skip to content

Commit

Permalink
Define __version__; save metadata in final output
Browse files Browse the repository at this point in the history
* Version number:
	ecospold2matrix/version.py handles version number for setup.py
	Now accessible:
		*  to instance object
		*  from ecospol2matrix.__version__

* Save key parameters and filepaths in metadata variable _inside_ final output
	We used to log everything, but that is not enough: the files
	would get handled/passed along separately, making it difficult
	to associate a file output with its history.

 Sur la branche dev
 Modifications qui seront validées :
	modifié :         ecospold2matrix/__init__.py
	modifié :         ecospold2matrix/ecospold2matrix.py
	nouveau fichier : ecospold2matrix/version.py
	modifié :         setup.py
  • Loading branch information
majeau-bettez committed Aug 14, 2017
1 parent ca2593a commit ff09a41
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions ecospold2matrix/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .version import __version__
from ecospold2matrix.ecospold2matrix import Ecospold2Matrix

34 changes: 30 additions & 4 deletions ecospold2matrix/ecospold2matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"""

import os
import glob
import io
Expand Down Expand Up @@ -1840,6 +1841,19 @@ def save_system(self, file_formats=None):
# TODO: include characterisation factors in all formats and also
# non-normalized


def generate_metadata(self):
metadata = dict(wasteflows_are_positive=self.positive_waste,
system_directory=self.sys_dir,
output_directory=self.out_dir,
characterisation_file=self.characterisation_file,
project_name=self.project_name,
data_version=self.version_name,
time=logging.time.strftime("%c"),
ecospold2matrix_version=__version__
)
return metadata

def pickling(filename, adict, what_it_is, mat):
""" subfunction that handles creation of binary files """

Expand Down Expand Up @@ -1873,7 +1887,8 @@ def pickle_symm_norm(PRO=None, STR=None, IMP=None, A=None, F=None,
'C': C,
'PRO_header': PRO_header,
'STR_header': STR_header,
'IMP_header': IMP_header
'IMP_header': IMP_header,
'metadata': metadata,
}
else:
adict = {'PRO_gen': PRO,
Expand All @@ -1884,7 +1899,8 @@ def pickle_symm_norm(PRO=None, STR=None, IMP=None, A=None, F=None,
'C': C,
'PRO_header': PRO_header,
'STR_header': STR_header,
'IMP_header': IMP_header
'IMP_header': IMP_header,
'metadata': metadata,
}
self.log.info("about to write to file")
pickling(file_pr + '_symmNorm', adict,
Expand All @@ -1897,7 +1913,9 @@ def pickle_symm_scaled(PRO, STR, Z, G_pro, mat=False):
adict = {'PRO': PRO,
'STR': STR,
'Z': Z,
'G_pro': G_pro}
'G_pro': G_pro,
'metadata': metadata,
}
pickling(file_pr + '_symmScale', adict,
'Final, symmetric, scaled-up flow matrices', mat)

Expand All @@ -1910,11 +1928,14 @@ def pickle_sut(prod, act, STR, U, V, V_prodVol, G_act, mat=False):
'U': U,
'V': V,
'V_prodVol': V_prodVol,
'G_act': G_act}
'G_act': G_act,
'metadata': metadata,
}

pickling(file_pr + '_SUT', adict, 'Final SUT matrices', mat)

self.log.info("Starting to export to file")
metadata = generate_metadata()
# save as full Dataframes
format_name = 'Pandas'
if file_formats is None or format_name in file_formats:
Expand Down Expand Up @@ -2023,6 +2044,11 @@ def pickle_sut(prod, act, STR, U, V, V_prodVol, G_act, mat=False):
csv_dir = os.path.join(self.out_dir, 'csv')
if not os.path.exists(csv_dir):
os.makedirs(csv_dir)
# write metadata
with open(os.path.join(csv_dir, 'metadata.csv'), 'w+') as f:
w = csv.writer(f)
w.writerows(metadata.items())
# write the actual data
self.PRO.to_csv(os.path.join(csv_dir, 'PRO.csv'))
self.STR.to_csv(os.path.join(csv_dir, 'STR.csv'))
if self.C is not None:
Expand Down
1 change: 1 addition & 0 deletions ecospold2matrix/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '0.2.0dev'
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from setuptools import setup

exec(open('ecospold2matrix/version.py').read())

setup(
name='ecospold2matrix',
packages=['ecospold2matrix', ],
version='0.1.0',
version=__version__,
author='Guillaume Majeau-Bettez',
author_email="guillaume.majeau-bettez@ntnu.no",
description="Class for recasting Ecospold2 LCA dataset into Leontief matrix representations or Supply and Use Tables",
Expand Down

0 comments on commit ff09a41

Please sign in to comment.