def run(burn_type, csv_input, do_metric, msg_level, outfile, fuel_loadings=None, col_cfg=None, no_sera=False): # validate alternate loadings file if provide. Throws exception on invalid if fuel_loadings: validate_fuel_loadings(fuel_loadings) # obtain a FuelConsumption object consumer = consume.FuelConsumption(fccs_file=fuel_loadings, msg_level=msg_level) \ if fuel_loadings else consume.FuelConsumption(msg_level=msg_level) # run the calculator and either pickle results for later output # or output as specified consumer.burn_type = burn_type if consumer.load_scenario(csv_input, display=False): emissions = consume.Emissions(consumer) if no_sera: emissions.no_sera = True else: emissions.no_sera = False results = emissions.results() write_results(results, outfile, do_metric, col_cfg_file=col_cfg) if not pickle_output(col_cfg): print("\nSuccess!!! Results are in \"{}\"".format(outfile))
def _run_on_fuelbed(self, fb, season, location, burn_type): if 'consumption' not in fb: raise ValueError( "Missing consumption data required for computing emissions") if 'heat' not in fb: raise ValueError( "Missing heat data required for computing emissions") if 'pct' not in fb: raise ValueError( "Missing fuelbed 'ptc' required for computing emissions") if 'ecoregion' not in location: raise ValueError( "Missing ecoregion required for computing emissions") fuel_loadings_csv_filename = self.fuel_loadings_manager.generate_custom_csv( fb['fccs_id']) # unlike with consume consumption results, emissions results reflect # how you set area and output_units area = (fb['pct'] / 100.0) * location['area'] fc = FuelConsumptionForEmissions(fb["consumption"], fb['heat'], area, burn_type, fb['fccs_id'], season, location, fccs_file=fuel_loadings_csv_filename) e_fuel_loadings = self.fuel_loadings_manager.get_fuel_loadings( fb['fccs_id'], fc.FCCS) fb['emissions_fuel_loadings'] = e_fuel_loadings e = consume.Emissions(fuel_consumption_object=fc) e.output_units = 'tons' # Consume emissions prints out lines like # Converting units: tons_ac -> tons # which we want to capture and ifnore with capture_stdout() as stdout_buffer: r = e.results()['emissions'] fb['emissions'] = {f: {} for f in CONSUME_FIELDS} # r's key hierarchy is species > phase; we want phase > species for k in r: upper_k = 'PM2.5' if k == 'pm25' else k.upper() if k != 'stratum' and (not self.species or upper_k in self.species): for p in r[k]: fb['emissions'][p][upper_k] = r[k][p] if self.include_emissions_details: # Note: consume gives details per fuel category, not per # subcategory; to match what FEPS and Prichard/O'Neill calculators # produce, put all per-category details under'summary' # The details are under key 'stratum'. the key hierarchy is: # 'stratum' > species > fuel category > phase # we want phase > species: # 'summary' > fuel category > phase > species fb['emissions_details'] = { "summary": {} } for k in r.get('stratum', {}): upper_k = 'PM2.5' if k == 'pm25' else k.upper() if not self.species or upper_k in self.species: for c in r['stratum'][k]: fb['emissions_details']['summary'][c] = fb['emissions_details']['summary'].get(c, {}) for p in r['stratum'][k][c]: fb['emissions_details']['summary'][c][p] = fb['emissions_details']['summary'][c].get(p, {}) fb['emissions_details']['summary'][c][p][upper_k] = r['stratum'][k][c][p]