def get_mapped_method(method_id, indicators=None, methods=None): """Obtains a mapped method stored as parquet, if that file does not exist locally, it is generated""" method_id = util.check_as_class(method_id) mapped_method = util.read_method(method_id) if mapped_method is None: util.log.info('generating ' + method_id.name) method = get_method(method_id) if 'mapping' in method_id.get_metadata(): mapping_system = method_id.get_metadata()['mapping'] case_insensitive = method_id.get_metadata()['case_insensitivity'] if case_insensitive: method['Flowable'] = method['Flowable'].str.lower() mapped_method = map_flows(method, system=mapping_system, case_insensitive=case_insensitive) mapped_method = util.collapse_indicators(mapped_method) util.store_method(mapped_method, method_id) else: mapped_method = method if indicators is not None: mapped_method = mapped_method[mapped_method['Indicator'].isin(indicators)] if len(mapped_method) == 0: util.log.error('indicator not found') if methods is not None: mapped_method = mapped_method[mapped_method['Method'].isin(methods)] if len(mapped_method) == 0: util.log.error('specified method not found') return mapped_method
def main(): os.makedirs(outputpath, exist_ok=True) log.basicConfig(level=log.INFO) file = method.get_filename() data = lciafmt.get_method(method, endpoint=False) data_endpoint = lciafmt.get_method(method, endpoint=True) data = data.append(data_endpoint, ignore_index=True) # map the flows to the Fed.LCA commons flows # set preserve_unmapped=True if you want to keep unmapped # flows in the resulting data frame mapping = method.get_metadata()['mapping'] mapped_data = lciafmt.map_flows(data, system=mapping) mapped_data = collapse_indicators(mapped_data) # write the result to parquet and JSON-LD store_method(mapped_data, method) for m in mapped_data['Method'].unique(): json_pack = outputpath + m + "_json.zip" if os.path.exists(json_pack): os.remove(json_pack) data_for_json = mapped_data[mapped_data['Method'] == m] lciafmt.to_jsonld(data_for_json, json_pack)
def main(): os.makedirs(outputpath, exist_ok=True) log.basicConfig(level=log.INFO) data = lciafmt.get_method(method, endpoint=False, summary=False) data_endpoint = lciafmt.get_method(method, endpoint=True, summary=apply_summary) data = data.append(data_endpoint, ignore_index=True) # make flowables case insensitive to handle lack of consistent structure in source file data['Flowable'] = data['Flowable'].str.lower() # map the flows to the Fed.LCA commons flows # set preserve_unmapped=True if you want to keep unmapped # flows in the resulting data frame mapping = method.get_metadata()['mapping'] mapped_data = lciafmt.map_flows(data, system=mapping, case_insensitive=True) # write the result to parquet and JSON-LD store_method(mapped_data, method) for m in mapped_data['Method'].unique(): mapped_data[mapped_data['Method'] == m].to_csv( outputpath + m.replace('/', '_') + ".csv", index=False) json_pack = outputpath + m.replace('/', '_') + "_json.zip" if os.path.exists(json_pack): os.remove(json_pack) data_for_json = mapped_data[mapped_data['Method'] == m] lciafmt.to_jsonld(data_for_json, json_pack)
def main(): os.makedirs(outputpath, exist_ok=True) log.basicConfig(level=log.INFO) file = method.get_filename() data = lciafmt.get_method(method) if mod is not None: log.info("getting modified CFs") modified_cfs=lciafmt.get_modification(mod,"TRACI2.1") data = data.merge(modified_cfs,how='left',on=['Flowable','Context','Indicator']) data.loc[data['Updated CF'].notnull(),'Characterization Factor']=data['Updated CF'] data = data.drop(columns=['Updated CF','Note']) data['Method']="TRACI 2.1 ("+mod+" mod)" # map the flows to the Fed.LCA commons flows # set preserve_unmapped=True if you want to keep unmapped # flows in the resulting data frame mapping = method.get_metadata()['mapping'] mapped_data = lciafmt.map_flows(data, system=mapping) # write the result to parquet and JSON-LD store_method(mapped_data, method) if mod is not None: file=mod+"_"+file json_pack = outputpath+file+"_json.zip" if os.path.exists(json_pack): os.remove(json_pack) lciafmt.to_jsonld(mapped_data, json_pack)
def main(): log.debug('Subsets available: ' + ", ".join(map(str, fedefl.subset_list.get_subsets()))) subsets = None inventory_methods = lciafmt.get_method(method_id='FEDEFL Inventory',subset=subsets) store_method(inventory_methods, method) save_json(method, inventory_methods)
def main(): os.makedirs(outputpath, exist_ok=True) log.basicConfig(level=log.INFO) file = method.get_filename() log.info(fedefl.subset_list.get_subsets()) subsets = None inventory_methods = lciafmt.get_method(method_id='FEDEFL Inventory',subset=subsets) store_method(inventory_methods, method) json_pack = outputpath+file+"_json.zip" if os.path.exists(json_pack): os.remove(json_pack)
def main(): data = lciafmt.get_method(method) # map the flows to the Fed.LCA commons flows # set preserve_unmapped=True if you want to keep unmapped # flows in the resulting data frame mapping = method.get_metadata()['mapping'] mapped_data = lciafmt.map_flows(data, system=mapping) mapped_data = collapse_indicators(mapped_data) # write the result to parquet and JSON-LD store_method(mapped_data, method) for m in mapped_data['Method'].unique(): save_json(method, mapped_data, m)
def main(): data = lciafmt.get_method(method) if mod is not None: log.info("getting modified CFs") modified_cfs=get_modification(mod,"TRACI2.1") data = data.merge(modified_cfs,how='left',on=['Flowable','Context','Indicator']) data.loc[data['Updated CF'].notnull(),'Characterization Factor']=data['Updated CF'] data = data.drop(columns=['Updated CF','Note']) data['Method']="TRACI 2.1 ("+mod+" mod)" # map the flows to the Fed.LCA commons flows # set preserve_unmapped=True if you want to keep unmapped # flows in the resulting data frame mapping = method.get_metadata()['mapping'] mapped_data = lciafmt.map_flows(data, system=mapping) # write the result to parquet and JSON-LD store_method(mapped_data, method) save_json(method, mapped_data)
def main(): data = lciafmt.get_method(method, endpoint=True, summary=apply_summary) # make flowables case insensitive to handle lack of consistent structure in source file data['Flowable'] = data['Flowable'].str.lower() # map the flows to the Fed.LCA commons flows # set preserve_unmapped=True if you want to keep unmapped # flows in the resulting data frame mapping = method.get_metadata()['mapping'] mapped_data = lciafmt.map_flows(data, system=mapping, case_insensitive=True) mapped_data = collapse_indicators(mapped_data) # write the result to parquet and JSON-LD store_method(mapped_data, method) for m in mapped_data['Method'].unique(): save_json(method, mapped_data, m)