Skip to content

faq 84705299

Billy Charlton edited this page Sep 5, 2018 · 2 revisions

Emissions Events, how to read it using an event handler?

by Rolando Armas on 2016-09-19 10:55:36


Hi, Guys.

I need to get the total warm and cold emissions from the emission events file.

I have created my own event handler object, however, when I try to read it, matsim apparently does not recognize the emission events. I have looked the emission contribution examples however I am a little confusing. My main method is:

public static void main (String[] args) throws Exception{
          
         String emissionEventsFile="./output/ITERS/it.10/10.emission.events.offline.xml.gz";
         EventsManager eventsManager = EventsUtils.createEventsManager();
       
         EmissAggregHandler emisAggh = new EmissAggregHandler();
         eventsManager.addHandler(emisAggh);
     
         // Connect a file reader to the EventsManager and read in the event file.
         MatsimEventsReader reader = new MatsimEventsReader(eventsManager);
        
         reader.readFile(emissionEventsFile);

         log.info("Events file read!");

         // Print the counts from the TripCounter
         log.info("Warm Emission Totals:"+ emisAggh.printWarmEmissions());      
     }

The emission event handler object looks like:

public class EmissAggregHandler implements WarmEmissionEventHandler{

     //total emission 
     private Map<WarmPollutant, Double> warmEtotal = new HashMap<WarmPollutant, Double>();
     private Map<ColdPollutant, Double> coldEtotal = new HashMap<ColdPollutant, Double>();
    
     private final static Logger log = Logger.getLogger(EmissAggregHandler.class);
    
     public EmissAggregHandler(){
         log.info("EmissAggregHandle instance");
     }
    
     @Override
     public void reset(int iteration) {
         warmEtotal.clear();
         coldEtotal.clear();
        
     }

     @Override
     public void handleEvent(WarmEmissionEvent event) {
         double updatew=0.0; 
         log.info("Reading warm events");   
         for (WarmPollutant key:event.getWarmEmissions().keySet()){            
             updatew= warmEtotal.get(key).doubleValue()+event.getWarmEmissions().get(key);
             warmEtotal.put(key, updatew);
         }


     public String printWarmEmissions(){
         return warmEtotal.toString();
     }
 }

When I run in debug mode, it does not go inside of the methods, and the output does not show the results.

2016-09-19 19:49:47,702  INFO EmissAggregHandler:32 EmissAggregHandle instance
 2016-09-19 19:49:47,704  INFO EventsManagerImpl:144 adding Event-Handler: org.moblab.test.EmissAggregHandler
 2016-09-19 19:49:47,704  INFO EventsManagerImpl:148   org.matsim.contrib.emissions.events.WarmEmissionEventHandler
 2016-09-19 19:49:47,704  INFO EventsManagerImpl:207     > org.matsim.contrib.emissions.events.WarmEmissionEvent
 2016-09-19 19:49:47,704  INFO EventsManagerImpl:148   org.matsim.contrib.emissions.events.ColdEmissionEventHandler
 2016-09-19 19:49:47,705  INFO EventsManagerImpl:207     > org.matsim.contrib.emissions.events.ColdEmissionEvent
 2016-09-19 19:49:47,705  INFO EventsManagerImpl:156 
 2016-09-19 19:49:47,710  INFO MatsimEventsReader$XmlEventsReader:114 using events_v1-reader.
 2016-09-19 19:49:47,710  INFO MatsimXmlParser:144 starting to parse xml from file ./output/ITERS/it.10/10.emission.events.offline.xml.gz ...
 2016-09-19 19:49:47,719  INFO EventsManagerImpl:134  event # 1
 2016-09-19 19:49:47,720  INFO EventsManagerImpl:134  event # 2
 2016-09-19 19:49:47,720  INFO EventsManagerImpl:134  event # 4
 2016-09-19 19:49:47,721  INFO EventsManagerImpl:134  event # 8
 2016-09-19 19:49:47,723  INFO EventsManagerImpl:134  event # 16
 2016-09-19 19:49:47,725  INFO EventsManagerImpl:134  event # 32
 2016-09-19 19:49:47,728  INFO EventsManagerImpl:134  event # 64
 2016-09-19 19:49:47,733  INFO EventsManagerImpl:134  event # 128
 2016-09-19 19:49:47,740  INFO EventsManagerImpl:134  event # 256
 2016-09-19 19:49:47,754  INFO EventsManagerImpl:134  event # 512
 2016-09-19 19:49:47,775  INFO EventsManagerImpl:134  event # 1024
 2016-09-19 19:49:47,797  INFO EventsManagerImpl:134  event # 2048
 2016-09-19 19:49:47,819  INFO EventsManagerImpl:134  event # 4096
 2016-09-19 19:49:47,854  INFO EventsManagerImpl:134  event # 8192
 2016-09-19 19:49:47,918  INFO EventsManagerImpl:134  event # 16384
 2016-09-19 19:49:48,007  INFO EventsManagerImpl:134  event # 32768
 2016-09-19 19:49:48,158  INFO EventsManagerImpl:134  event # 65536
 2016-09-19 19:49:48,437  INFO EventsManagerImpl:134  event # 131072
 2016-09-19 19:49:48,528  INFO EmissTotal:43 Events file read!
 2016-09-19 19:49:48,529  INFO EmissTotal:46 Warm Emission Totals:{}

What is wrong? Could you help me please?

Thanks!


Comments: 1


Re: Emissions Events, how to read it using an event handler?

by Marcel Rieser on 2016-09-19 15:26:59

The emissions contrib provides its own events reader for that cause:  org.matsim.contrib.emissions.events.EmissionEventsReader.

Try to use this class instead of MatsimEventsReader to parse your events file.

Clone this wiki locally