def write_methods(self, overwrite=False, verbose=True): num_methods, num_cfs, num_unlinked = self.statistics(False) if num_unlinked: raise ValueError((u"Can't write unlinked methods ({} unlinked cfs)" ).format(num_unlinked)) for ds in self.data: if ds["name"] in methods: if overwrite: del methods[ds["name"]] else: raise ValueError( (u"Method {} already exists. Use " u"``overwrite=True`` to overwrite existing methods" ).format(ds["name"])) with warnings.catch_warnings(): warnings.simplefilter("ignore") method = Method(ds["name"]) method.register( description=ds["description"], filename=ds["filename"], unit=ds["unit"], ) method.write(self._reformat_cfs(ds["exchanges"])) method.process() if verbose: print(u"Wrote {} LCIA methods with {} characterization factors". format(num_methods, num_cfs))
def create_methods(self): gw = [ [("b", "bad"), 1], ] method = Method(("foo", )) method.register() method.write(gw) method.process() fake_dynamic_method = DynamicIAMethod("Dynamic foo") fake_dynamic_method.register() fake_dynamic_method.write({x[0]: x[1] for x in gw})
def to_worst_case_method(self, name, lower=None, upper=None, dynamic=True, register=True): """Create a static LCA method using the worst case for each dynamic CF function. Default time interval over which to test for maximum CF is `datetime.now()` to `datetime.now()+relativedelta(years=100)`. Args: * *name* (string): method name. * *lower* (datetime, default=datetime(2010, 1, 1): lower bound of the interval to consider. * *upper* (datetime, default=lower + relativedelta(years=100): upper bound of the interval to consider. * *dynamic* (bool, default=True): If total CF function of time of emission * *register* (bool, default=True): If to register the method """ kwargs = {'dynamic': dynamic} if lower is not None: kwargs['lower'] = lower if upper is not None: kwargs['upper'] = upper with warnings.catch_warnings(): warnings.simplefilter("ignore") worst_case_method = Method(tuple(name)) if worst_case_method.name not in methods: worst_case_method.register(dynamic_method=self.name) data = self.load() data.update(self.create_functions()) # for now just characterize all the 'Carbon dioxide, in air' to be sure they are not skipped # should think better on how to deal with this method = [[('biosphere3', 'cc6a1abb-b123-4ca6-8f16-38209df609be'), abs(get_maximum_value(value, **kwargs))] if key == ('static_forest', "C_biogenic") else [key, abs(get_maximum_value(value, **kwargs))] for key, value in data.items()] #needed for GWP function to avoid registration every time if not register: return method worst_case_method.write(method) worst_case_method.process() #GIU: guess not needed anymore right? return worst_case_method