Esempio n. 1
0
def run(fires_manager):
    """Runs the fire data through consumption calculations, using the consume
    package for the underlying computations.

    Args:
     - fires_manager -- bluesky.models.fires.FiresManager object
    """
    # TODO: don't hard code consume_version; either update consume to define
    # it's version in consume.__version__, or execute pip:
    #   $ pip3 freeze |grep consume
    #  or
    #   $ pip3 show apps-consume4|grep "^Version:"
    fires_manager.processed(__name__,
                            __version__,
                            consume_version=CONSUME_VERSION_STR)

    # TODO: get msg_level and burn_type from fires_manager's config
    msg_level = 2  # 1 => fewest messages; 3 => most messages

    all_fuel_loadings = Config().get('consumption', 'fuel_loadings')
    fuel_loadings_manager = FuelLoadingsManager(
        all_fuel_loadings=all_fuel_loadings)

    _validate_input(fires_manager)

    # TODO: can I safely instantiate one FuelConsumption object and
    # use it across all fires, or at lesat accross all fuelbeds within
    # a single fire?
    for fire in fires_manager.fires:
        with fires_manager.fire_failure_handler(fire):
            _run_fire(fire, fuel_loadings_manager, msg_level)

    datautils.summarize_all_levels(fires_manager, 'consumption')
    datautils.summarize_all_levels(fires_manager, 'heat')
Esempio n. 2
0
def run(fires_manager):
    """Loads fire data from one or more sources

    Args:
     - fires_manager -- bluesky.models.fires.FiresManager object
    """
    successfully_loaded_sources = []
    sources = Config().get('load', 'sources')
    if not sources:
        raise BlueSkyConfigurationError("No sources specified for load module")
    try:
        for source in sources:
            # TODO: use something like with fires_manager.fire_failure_handler(fire)
            #   to optionally skip invalid sources (sources that are insufficiently
            #   configured, don't have corresponding loader class, etc.) and source
            #   that fail to load
            try:
                loaded_fires = _load_source(source)
                fires_manager.add_fires(loaded_fires)
                # TODO: add fires to fires_manager
                if source.get("name").lower() == "bsf" and source.get("load_consumption"):
                    datautils.summarize_all_levels(fires_manager, 'consumption')
                successfully_loaded_sources.append(source)
            except:
                # Let skip_failed_sources be defined at top level
                # or under 'load' in the config
                if not (Config().get('skip_failed_sources')
                        or Config().get('load', 'skip_failed_sources', allow_missing=True)):
                    raise
    finally:
        fires_manager.processed(__name__, __version__,
            successfully_loaded_sources=successfully_loaded_sources)
Esempio n. 3
0
def run(fires_manager):
    """Runs emissions module

    Args:
     - fires_manager -- bluesky.models.fires.FiresManager object

    Config options:
     - emissions > model -- emissions model to use
     - emissions > species -- whitelist of species to compute emissions for
     - emissions > include_emissions_details -- whether or not to include
        emissions per fuel category per phase, as opposed to just per phase
     - emissions > fuel_loadings --
     - consumption > fuel_loadings -- considered if fuel loadings aren't
        specified in the emissions config
    """
    model = Config().get('emissions', 'model')

    include_emissions_details = Config().get('emissions',
                                             'include_emissions_details')
    fires_manager.processed(__name__,
                            __version__,
                            model=model,
                            emitcalc_version=emitcalc_version,
                            eflookup_version=eflookup_version,
                            consume_version=CONSUME_VERSION_STR)

    try:
        klass_name = ''.join([e.capitalize() for e in model.split('-')])
        klass = getattr(sys.modules[__name__], klass_name)
        e = klass(fires_manager.fire_failure_handler)
    except AttributeError:
        msg = "Invalid emissions model: '{}'.".format(model)
        if model == 'urbanski':
            msg += " The urbanski model has be replaced by prichard-oneill"
        raise BlueSkyConfigurationError(msg)

    e.run(fires_manager.fires)

    # fix keys
    for fire in fires_manager.fires:
        with fires_manager.fire_failure_handler(fire):
            for aa in fire.active_areas:
                for loc in aa.locations:
                    for fb in loc['fuelbeds']:
                        _fix_keys(fb['emissions'])
                        if include_emissions_details:
                            _fix_keys(fb['emissions_details'])

    datautils.summarize_all_levels(fires_manager, 'emissions')
    if include_emissions_details:
        datautils.summarize_over_all_fires(fires_manager, 'emissions_details')
Esempio n. 4
0
 def test_no_active_areas(self):
     fm = MockFiresManager([{"id": "SF11C14225236095807750"}])
     datautils.summarize_all_levels(fm, 'emissions')
     assert fm.fires == [{
         "id": "SF11C14225236095807750",
         'fuel_type': 'natural',
         'type': 'wildfire',
         "emissions": {
             'summary': {
                 'total': 0.0
             }
         }
     }]
     assert fm.summary == {"emissions": {'summary': {'total': 0.0}}}
Esempio n. 5
0
 def test_no_locations(self):
     fm = MockFiresManager([{
         "id":
         "SF11C14225236095807750",
         "activity": [{
             "active_areas": [{
                 "start": "2014-05-25T17:00:00",
                 "end": "2014-05-26T17:00:00",
             }]
         }]
     }])
     with raises(ValueError) as e_info:
         datautils.summarize_all_levels(fm, 'emissions')
     assert e_info.value.args[
         0] == activity.ActiveArea.MISSING_LOCATION_INFO_MSG
Esempio n. 6
0
def run(fires_manager):
    """Runs plumerise module

    Args:
     - fires_manager -- bluesky.models.fires.FiresManager object
    """
    compute_func = ComputeFunction(fires_manager)

    with osutils.create_working_dir(
            working_dir=compute_func.config.get('working_dir')) as working_dir:
        for fire in fires_manager.fires:
            with fires_manager.fire_failure_handler(fire):
                compute_func(fire, working_dir=working_dir)

    # Make sure to distribute the heat if it was loaded here.
    if compute_func.config.get("load_heat"):
        datautils.summarize_all_levels(fires_manager, 'heat')
Esempio n. 7
0
 def test_no_fuelbeds(self):
     fm = MockFiresManager([{
         "id":
         "SF11C14225236095807750",
         "activity": [{
             "active_areas": [{
                 "start":
                 "2014-05-25T17:00:00",
                 "end":
                 "2014-05-26T17:00:00",
                 'specified_points': [{
                     'area': 34,
                     'lat': 45.0,
                     'lng': -120.0
                 }]
             }]
         }]
     }])
     datautils.summarize_all_levels(fm, 'emissions')
     assert fm.fires == [{
         "id":
         "SF11C14225236095807750",
         'fuel_type':
         'natural',
         'type':
         'wildfire',
         "activity": [{
             "active_areas": [{
                 "start":
                 "2014-05-25T17:00:00",
                 "end":
                 "2014-05-26T17:00:00",
                 'specified_points': [{
                     'area': 34,
                     'lat': 45.0,
                     'lng': -120.0,
                     "emissions": {
                         'summary': {
                             'total': 0.0
                         }
                     }
                 }],
                 "emissions": {
                     'summary': {
                         'total': 0.0
                     }
                 }
             }],
             "emissions": {
                 'summary': {
                     'total': 0.0
                 }
             }
         }],
         "emissions": {
             'summary': {
                 'total': 0.0
             }
         }
     }]
     assert fm.summary == {"emissions": {'summary': {'total': 0.0}}}
Esempio n. 8
0
 def test_two_fires_two_ac_two_aa_two_locations_two_fuelbed(self):
     fm = MockFiresManager([
         {
             "id":
             "SF11C14225236095807750",
             "activity": [{
                 "active_areas": [{
                     "start":
                     "2014-05-25T17:00:00",
                     "end":
                     "2014-05-26T17:00:00",
                     'specified_points': [{
                         'area':
                         34,
                         'lat':
                         45.0,
                         'lng':
                         -120.0,
                         "fuelbeds": [{
                             "emissions": {
                                 "flaming": {
                                     "PM2.5": [10]
                                 },
                                 "smoldering": {
                                     "PM2.5": [7]
                                 },
                                 "total": {
                                     "PM2.5": [22]
                                 },  # incorrect, but should be ignored
                             }
                         }]
                     }]
                 }]
             }]
         },
         {
             "id":
             "sfkjfsdlksdflkjdf",
             "activity": [{
                 "active_areas": [{
                     "start":
                     "2014-05-25T17:00:00",
                     "end":
                     "2014-05-26T17:00:00",
                     'specified_points': [{
                         'area':
                         34,
                         'lat':
                         45.0,
                         'lng':
                         -120.0,
                         "fuelbeds": [{
                             "emissions": {
                                 "flaming": {
                                     "PM2.5": [42]
                                 },
                                 "residual": {
                                     "PM2.5": [1],
                                     "CO": [123]
                                 },
                                 "total": {
                                     "PM2.5": [22]
                                 },  # incorrect, but should be ignored
                             }
                         }]
                     }]
                 }]
             }]
         }
     ])
     datautils.summarize_all_levels(fm, 'emissions')
     expected_fires = [
         {
             "id":
             "SF11C14225236095807750",
             'fuel_type':
             'natural',
             'type':
             'wildfire',
             "activity": [{
                 "active_areas": [{
                     "start":
                     "2014-05-25T17:00:00",
                     "end":
                     "2014-05-26T17:00:00",
                     'specified_points': [{
                         'area':
                         34,
                         'lat':
                         45.0,
                         'lng':
                         -120.0,
                         "fuelbeds": [{
                             "emissions": {
                                 "flaming": {
                                     "PM2.5": [10]
                                 },
                                 "smoldering": {
                                     "PM2.5": [7]
                                 },
                                 "total": {
                                     "PM2.5":
                                     [22
                                      ]  # incorrect, but should be ignored
                                 },
                             }
                         }],
                         "emissions": {
                             'summary': {
                                 'PM2.5': 17.0,
                                 'total': 17.0
                             }
                         }
                     }],
                     "emissions": {
                         'summary': {
                             'PM2.5': 17.0,
                             'total': 17.0
                         }
                     }
                 }],
                 "emissions": {
                     'summary': {
                         'PM2.5': 17.0,
                         'total': 17.0
                     }
                 }
             }],
             "emissions": {
                 'summary': {
                     'PM2.5': 17.0,
                     'total': 17.0
                 }
             }
         },
         {
             "id":
             "sfkjfsdlksdflkjdf",
             'fuel_type':
             'natural',
             'type':
             'wildfire',
             "activity": [{
                 "active_areas": [{
                     "start":
                     "2014-05-25T17:00:00",
                     "end":
                     "2014-05-26T17:00:00",
                     'specified_points': [{
                         'area':
                         34,
                         'lat':
                         45.0,
                         'lng':
                         -120.0,
                         "fuelbeds": [{
                             "emissions": {
                                 "flaming": {
                                     "PM2.5": [42]
                                 },
                                 "residual": {
                                     "PM2.5": [1],
                                     "CO": [123]
                                 },
                                 "total": {
                                     "PM2.5":
                                     [22
                                      ]  # incorrect, but should be ignored
                                 },
                             }
                         }],
                         "emissions": {
                             'summary': {
                                 'PM2.5': 43.0,
                                 'CO': 123.0,
                                 'total': 166.0
                             }
                         }
                     }],
                     "emissions": {
                         'summary': {
                             'PM2.5': 43.0,
                             'CO': 123.0,
                             'total': 166.0
                         }
                     }
                 }],
                 "emissions": {
                     'summary': {
                         'PM2.5': 43.0,
                         'CO': 123.0,
                         'total': 166.0
                     }
                 }
             }],
             "emissions": {
                 'summary': {
                     'PM2.5': 43.0,
                     'CO': 123.0,
                     'total': 166.0
                 }
             }
         }
     ]
     assert fm.fires == expected_fires
     expected_summary = {
         "emissions": {
             "flaming": {
                 "PM2.5": [52.0]
             },
             "residual": {
                 "PM2.5": [1.0],
                 "CO": [123.0]
             },
             "smoldering": {
                 "PM2.5": [7.0]
             },
             'summary': {
                 'PM2.5': 60.0,
                 "CO": 123.0,
                 'total': 183.0
             }
         }
     }
     assert fm.summary == expected_summary
Esempio n. 9
0
 def test_no_fires(self):
     fm = MockFiresManager([])
     datautils.summarize_all_levels(fm, 'emissions')
     assert fm.fires == []
     assert fm.summary == {"emissions": {'summary': {'total': 0.0}}}
Esempio n. 10
0
 def test_one_fire_one_fuelbed_with_emissions(self):
     fm = MockFiresManager([{
         "id":
         "SF11C14225236095807750",
         "activity": [{
             "active_areas": [{
                 "start":
                 "2014-05-25T17:00:00",
                 "end":
                 "2014-05-26T17:00:00",
                 'specified_points': [{
                     'area':
                     34,
                     'lat':
                     45.0,
                     'lng':
                     -120.0,
                     "fuelbeds": [{
                         "emissions": {
                             "flaming": {
                                 "PM2.5": [10]
                             },
                             "smoldering": {
                                 "PM2.5": [7]
                             },
                             "total": {
                                 "PM2.5": [22]
                             }  # incorrect, but should be ignored
                         }
                     }]
                 }]
             }]
         }]
     }])
     datautils.summarize_all_levels(fm, 'emissions')
     expected_fires = [{
         "id":
         "SF11C14225236095807750",
         'fuel_type':
         'natural',
         'type':
         'wildfire',
         "activity": [{
             "active_areas": [{
                 "start":
                 "2014-05-25T17:00:00",
                 "end":
                 "2014-05-26T17:00:00",
                 'specified_points': [{
                     'area':
                     34,
                     'lat':
                     45.0,
                     'lng':
                     -120.0,
                     "fuelbeds": [{
                         "emissions": {
                             "flaming": {
                                 "PM2.5": [10]
                             },
                             "smoldering": {
                                 "PM2.5": [7]
                             },
                             "total": {
                                 "PM2.5": [22]
                             }  # incorrect, but should be ignored
                         }
                     }],
                     "emissions": {
                         'summary': {
                             'PM2.5': 17.0,
                             'total': 17.0
                         }
                     }
                 }],
                 "emissions": {
                     'summary': {
                         'PM2.5': 17.0,
                         'total': 17.0
                     }
                 }
             }],
             "emissions": {
                 'summary': {
                     'PM2.5': 17.0,
                     'total': 17.0
                 }
             }
         }],
         "emissions": {
             'summary': {
                 'PM2.5': 17.0,
                 'total': 17.0
             }
         }
     }]
     assert fm.fires == expected_fires
     assert fm.summary == {
         "emissions": {
             "flaming": {
                 "PM2.5": [10]
             },
             "smoldering": {
                 "PM2.5": [7]
             },
             'summary': {
                 'PM2.5': 17.0,
                 'total': 17.0
             }
         }
     }