title: Importation of method EF 3.0 - trouble with results
body: <p>I wrote a script to import the characterization factors of the LCIA method EF 3.0 (adapated) on Brightway. I think it works fine as I see the right characterization factors on the Activity Browser (ex for the Climate Change method : <a href="https://i.stack.imgur.com/R6zy7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R6zy7.png" alt="enter image description here" /></a><a href="https://i.stack.imgur.com/o9W4W.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o9W4W.png" alt="enter image description here" /></a> but when I run calculations with the method, the results are not the same as on Simapro (where I got the CSV Import File from) :<a href="https://i.stack.imgur.com/SCQez.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SCQez.png" alt="enter image description here" /></a> <a href="https://i.stack.imgur.com/5U1o9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5U1o9.png" alt="enter image description here" /></a>And for instance the result is 0 for the Climate Change method. Do you know what can be the issue ?
  It seems that the units are different but it is the same for the other methods that are available on Brightway.</p>
  <p>Besides, I saw on another question that there would be a method implemented to import the EF 3.0 method, is it available yet ?
  Thank you very much for your help.</p>
  <p>Code of the importation script :</p>
  <pre><code>import brightway2 as bw
  import csv
  import uuid
  from bw2data import mapping
  from bw2data.utils import recursive_str_to_unicode
  
  
  
  class import_method_EF:
  '''Class for importing the EF method from Simapro export CSV file to Brightway. '''
  
  
  def __init__(
          self,
          project_name,
          name_file,
          ):
  
      self.project_name = project_name
      self.name_file = name_file
      self.db_biosphere = bw.Database('biosphere3')
      
      
           
      #Definition of the dictionnary for the correspondance between the Simapro and the ecoinvent categories
      self.dict_categories = {'high. pop.' : 'urban air close to ground',
                         'low. pop.' : 'low population density, long-term',
                         'river' : 'surface water',
                         'in water' : 'in water',
                         '(unspecified)' : '',
                         'ocean' : 'ocean',
                         'indoor' : 'indoor',
                         'stratosphere + troposphere' : 'lower stratosphere + upper troposphere',
                         'low. pop., long-term' : 'low population density, long-term',
                         'groundwater, long-term' : 'ground-, long-term',
                         'agricultural' : 'agricultural',
                         'industrial' : 'industrial',
                         }
      
      
      #Definition of the dictionnary of the ecoinvent units abreviations 
      self.dict_units = {'kg' : 'kilogram',
                          'kWh' : 'kilowatt hour',
                          'MJ' : 'megajoule',
                          'p':'p',
                          'unit':'unit',
                          'km':'kilometer',
                          'my' : 'meter-year',
                          'tkm' : 'ton kilometer',
                          'm3' : 'cubic meter',
                          'm2' :'square meter',
                          'kBq' : 'kilo Becquerel',
                          'm2a' : 'm2a', #à modifier
                          }
      
      
  def importation(self) :
      
      &quot;&quot;&quot;
      Makes the importation from the Simapro CSV file to Brightway.
      
      &quot;&quot;&quot;
      
      
      #Set the current project
      bw.projects.set_current(self.project_name)
      
      self.data = self.open_CSV(self.name_file, [])
      
      list_methods = []
      new_flows = []
      
      for i in range(len(self.data)) :
          
          #print(self.data[i])
          if self.data[i] == ['Name'] :
              name_method = self.data[i+1][0]
          
          if self.data[i] == ['Impact category'] :
              list_flows = []
              
              j = 4
              
              while len(self.data[i+j])&gt;1 :
                  
                  biosphere_code = self.get_biosphere_code(self.data[i+j][2],self.data[i+j][1],self.data[i+j][0].lower())    
                  
                  
                  if biosphere_code == 0 :
                      
                      if self.find_if_already_new_flow(i+j, new_flows)[0] :
                          code = self.find_if_already_new_flow(i+j, new_flows)[1]
                          list_flows.append((('biosphere3', code),float(self.data[i+j][4].replace(',','.'))))
                      
                      else :
                          
                          code = str(uuid.uuid4())
                          while (self.db_biosphere.name, code) in mapping:
                              code = str(uuid.uuid4())
                              
                          new_flows.append({'amount' : float(self.data[i+j][4].replace(',','.')),
                                'CAS number' : self.data[i+j][3],
                                'categories' : (self.data[i+j][0].lower(), self.dict_categories[self.data[i+j][1]]),
                                'name' : self.data[i+j][2],
                                'unit' : self.dict_units[self.data[i+j][5]],
                                'type' : 'biosphere',
                                'code' : code})
                          list_flows.append((('biosphere3', code),float(self.data[i+j][4].replace(',','.'))))
                          
                    
                  else :
                      list_flows.append((('biosphere3', biosphere_code),float(self.data[i+j][4].replace(',','.'))))
              
                  j+=1
                  
              list_methods.append({'name' : self.data[i+1][0],
                                   'unit' : self.data[i+1][1],
                                   'flows' : list_flows})
       
          
      new_flows = recursive_str_to_unicode(dict([self._format_flow(flow) for flow in new_flows]))
          
      if new_flows :
          print('new flows :',len(new_flows))
          self.new_flows = new_flows
          biosphere = bw.Database(self.db_biosphere.name)
          biosphere_data = biosphere.load()
          biosphere_data.update(new_flows)
          biosphere.write(biosphere_data)
          print('biosphere_data :',len(biosphere_data))
          
  
      for i in range(len(list_methods)) :
          method = bw.Method((name_method,list_methods[i]['name']))
          method.register(**{'unit':list_methods[i]['unit'],
                          'description':''})
          method.write(list_methods[i]['flows'])
          print(method.metadata)
          method.load()
      
      
      
  def open_CSV(self, CSV_file_name, list_rows):
      
      '''
      Opens a CSV file and gets a list of the rows.
      
      : param : CSV_file_name = str, name of the CSV file (must be in the working directory)
      : param : list_rows = list, list to get the rows
      
      : return : list_rows = list, list of the rows
      
      '''
      
      #Open the CSV file and read it
      with open(CSV_file_name, 'rt') as csvfile:
          data = csv.reader(csvfile, delimiter = ';')
          
          #Write every row in the list 
          for row in data:
              list_rows.append(row)
      
      return list_rows
  
  
  
  
  
  def get_biosphere_code(self, simapro_name, simapro_cat, type_biosphere):
      
      &quot;&quot;&quot;
      Gets the Brightway code of a biosphere process given in a Simapro format.
      
      : param : simapro_name = str, name of the biosphere process in a Simapro format.
      : param : simapro_cat = str, category of the biosphere process (ex : high. pop., river, etc)
      : param : type_biosphere = str, type of the biosphere process (ex : Emissions to water, etc)
      
      : return :  0 if the process is not found in biosphere, the code otherwise
      
      &quot;&quot;&quot;
  
      
      
      if 'GLO' in simapro_name or 'RER' in simapro_name :
          simapro_name = simapro_name[:-5]
      if '/m3' in simapro_name :
          simapro_name = simapro_name[:-3]
      
      #Search in the biosphere database, depending on the category
      if simapro_cat == '' :
          act_biosphere = self.db_biosphere.search(simapro_name, filter={'categories' : (type_biosphere,)})
      else :
          act_biosphere = self.db_biosphere.search(simapro_name, filter={'categories' : (type_biosphere, self.dict_categories[simapro_cat])})
      
      #Pourquoi j'ai fait ça ? ...
      for act in act_biosphere :
          if simapro_cat == '' :
              if act['categories'] == (type_biosphere, ):
                  return act['code']
          else :
              if act['categories'] == (type_biosphere, self.dict_categories[simapro_cat]):
                  return act['code']
      return 0
  
  
          
          
  def _format_flow(self, cf):
      # TODO
      return (self.db_biosphere.name, cf['code']), {
          'exchanges': [],
          'categories': cf['categories'],
          'name': cf['name'],
          'type': (&quot;resource&quot; if cf[&quot;categories&quot;][0] == &quot;resource&quot;
                   else &quot;emission&quot;),
          'unit': cf['unit'],
      }
  
  
  
  def find_if_already_new_flow(self, n, new_flows) :
      
      &quot;&quot;&quot;
      &quot;&quot;&quot;
      
      for k in range(len(new_flows)) :
          if new_flows[k]['name'] == self.data[n][2] :
              return True, new_flows[k]['code'] 
          
      return False, 0
  </code></pre>
  <p><a href="https://i.stack.imgur.com/kZ9hk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kZ9hk.jpg" alt="enter image description here" /></a></p>
  <p><strong>Edit</strong> : I made a modification in the get_biosphere_code method and it works better (it was not finding some biosphere flows) but I still have important differences between the results I get on Brightway and the results I get on Simapro. My investigations led me to the following observations :</p>
  <ul>
  <li>there are some differences in ecoinvent activities and especially in the lists of biosphere flows (should be a sink of differences in result), some are missing in Brightway and also in the ecoSpold data that was used for the importation compared to the data in Simapro</li>
  <li>it seems that the LCA calculation doesn't work the same way as regards the subcategories : for example, the biosphere flow Carbon dioxide, fossil (air,) is in the list of caracterization factors for the Climate Change method and when looking at the inventory in the Simapro LCA results, it appears that all the Carbon dioxide, fossil flows to air participate in the Climate Change impact, no matter what their subcategory is. But Brightway does not work this way and only takes into account the flows that are exactly the same, so it leads to important differences in the results.</li>
  </ul>