def _set_per_location_data(self, fire): self['active_areas'] = [] for i, aa in enumerate(fire.active_areas): # set location ids self['active_areas'].append({ "id": "#{} {} - {}".format(i, aa['start'], aa['end']), "start": aa['start'], "end": aa['end'], 'locations': [] }) for j, loc in enumerate(aa.locations): lat_lng = locationutils.LatLng(loc) emissions = self._get_location_emissions(loc) timeprofiled_emissions = self._get_location_timeprofiled_emissions( aa, loc, emissions) self['active_areas'][-1]['locations'].append({ "start": aa["start"], "end": aa["end"], "lat": lat_lng.latitude, "lng": lat_lng.longitude, "area": loc["area"], "id": "#{}/#{} {},{}".format( i, j, lat_lng.latitude, lat_lng.longitude), "fuelbeds": self.fuelbeds_list_to_dict( fuelbeds.summarize([self._wrap_loc_in_fire(loc)])), 'consumption_by_category': self._get_location_consumption(loc), "emissions": emissions, 'timeprofiled_emissions': timeprofiled_emissions, "plumerise": self._get_location_plumerise(loc) })
def test_one_fire(self): fires = [ Fire({ 'activity': [{ "location": { "area": 10 }, "fuelbeds": [{ "fccs_id": "1", "pct": 40 }, { "fccs_id": "2", "pct": 60 }] }] }) ] summary = fuelbeds.summarize(fires) assert summary == fires[0]['activity'][0]['fuelbeds']
def test_two_fires(self): fires = [ Fire({ 'activity': [{ "location": { "area": 10 }, "fuelbeds": [{ "fccs_id": "1", "pct": 30 }, { "fccs_id": "2", "pct": 70 }] }] }), Fire({ 'activity': [{ "location": { "area": 5 }, "fuelbeds": [{ "fccs_id": "2", "pct": 10 }, { "fccs_id": "3", "pct": 90 }] }] }) ] expected_summary = [{ "fccs_id": "1", "pct": 20 }, { "fccs_id": "2", "pct": 50 }, { "fccs_id": "3", "pct": 30 }] summary = fuelbeds.summarize(fires) assert summary == expected_summary
def test_two_fires(self): fires = [ Fire({ 'activity':[{ "active_areas":[{ "specified_points": [{ "area": 10, "lat": 45, "lng": -118, "fuelbeds":[ {"fccs_id": "1", "pct": 30}, {"fccs_id": "2", "pct": 70} ] }] }] }] }), Fire({ 'activity':[{ "active_areas":[{ "specified_points": [{ "area": 5, "lat": 44, "lng": -117, "fuelbeds":[ {"fccs_id": "2", "pct": 10}, {"fccs_id": "3", "pct": 90} ] }] }] }] }) ] expected_summary = [ {"fccs_id": "1", "pct": 20}, {"fccs_id": "2", "pct": 50}, {"fccs_id": "3", "pct": 30} ] summary = fuelbeds.summarize(fires) assert summary == expected_summary
def test_one_fire(self): fires = [ Fire({ 'activity':[{ "active_areas":[{ "specified_points": [{ "area": 10, "lat": 45, "lng": -118, "fuelbeds":[ {"fccs_id": "1", "pct": 40}, {"fccs_id": "2", "pct": 60} ] }] }] }] }) ] expected_summary = [ {"fccs_id": "1", "pct": 40}, {"fccs_id": "2", "pct": 60} ] summary = fuelbeds.summarize(fires) assert summary == expected_summary
def _set_fire_fuelbeds(self, fire): # throw away 'total_area' return value self['fuelbeds'] = self.fuelbeds_list_to_dict( fuelbeds.summarize([fire]))
def test_no_fires(self): assert fuelbeds.summarize([]) == []