Beispiel #1
0
def run(fires_manager):
    """Runs plumerise module

    Args:
     - fires_manager -- bluesky.models.fires.FiresManager object
    """
    fires_manager.processed(__name__, __version__)
    if not fires_manager.met:
        raise ValueError(NO_MET_ERROR_MSG)

    arl_profiler = arlprofiler.ArlProfiler(fires_manager.met.get('files'),
                                           time_step=Config().get(
                                               'localmet', 'time_step'))
    logging.debug("Extracting localmet data for %d fires",
                  len(fires_manager.fires))
    for fire in fires_manager.fires:
        with fires_manager.fire_failure_handler(fire):
            # Make sure fire has at least some locations, but
            # iterate first through activice areas and then through
            # locations in order to get utc_offset and time windows
            if not fire.locations:
                raise ValueError(NO_ACTIVITY_ERROR_MSG)

            for aa in fire.active_areas:
                utc_offset = parse_utc_offset(aa.get('utc_offset'))
                tw = parse_datetimes(aa, 'start', 'end')
                for loc in aa.locations:
                    latlng = LatLng(loc)
                    # parse_utc_offset makes sure utc offset is defined and valid
                    loc['localmet'] = arl_profiler.profile(
                        latlng.latitude, latlng.longitude, tw['start'],
                        tw['end'], utc_offset)
Beispiel #2
0
def run(fires_manager):
    """Runs plumerise module

    Args:
     - fires_manager -- bluesky.models.fires.FiresManager object
    """
    logging.info("Running localmet module")
    fires_manager.processed(__name__, __version__)
    if not fires_manager.met:
        raise ValueError("Specify met files to use in localmet")

    arl_profiler = ArlProfiler(fires_manager.met.get('files'),
                               time_step=Config.get('localmet', 'time_step'))
    logging.debug("Extracting localmet data for %d fires",
                  len(fires_manager.fires))
    for fire in fires_manager.fires:
        with fires_manager.fire_failure_handler(fire):
            if not fire.get('activity'):
                raise ValueError("Missing activity data required for localmet")
            for a in fire['activity']:
                latlng = LatLng(a.get('location'))
                # parse_utc_offset makes sure utc offset is defined and valid
                utc_offset = parse_utc_offset(
                    a.get('location', {}).get('utc_offset'))
                tw = parse_datetimes(a, 'start', 'end')
                a['localmet'] = arl_profiler.profile(latlng.latitude,
                                                     latlng.longitude,
                                                     tw['start'], tw['end'],
                                                     utc_offset)
Beispiel #3
0
def _validate_input(fires_manager):
    ecoregion_lookup = None  # instantiate only if necessary
    for fire in fires_manager.fires:
        with fires_manager.fire_failure_handler(fire):
            active_areas = fire.active_areas
            if not active_areas:
                raise ValueError(VALIDATION_ERROR_MSGS['NO_ACTIVITY'])

            for aa in active_areas:
                locations = aa.locations
                if not locations:
                    raise ValueError(VALIDATION_ERROR_MSGS["NO_LOCATIONS"])

                for loc in locations:
                    if not loc.get('fuelbeds'):
                        raise ValueError(VALIDATION_ERROR_MSGS["NO_FUELBEDS"])

                    # only 'area' is required from location
                    if not loc.get('area'):
                        raise ValueError(
                            VALIDATION_ERROR_MSGS["AREA_UNDEFINED"])

                    if not loc.get('ecoregion'):
                        # import EcoregionLookup here so that, if fires do have
                        # ecoregion defined, consumption can be run without mapscript
                        # and other dependencies installed
                        try:
                            latlng = LatLng(loc)
                            if not ecoregion_lookup:
                                from bluesky.ecoregion.lookup import EcoregionLookup
                                implemenation = Config().get(
                                    'consumption',
                                    'ecoregion_lookup_implemenation')
                                ecoregion_lookup = EcoregionLookup(
                                    implemenation)
                            loc['ecoregion'] = ecoregion_lookup.lookup(
                                latlng.latitude, latlng.longitude)
                            if not loc['ecoregion']:
                                logging.warning(
                                    "Failed to look up ecoregion for "
                                    "{}, {}".format(latlng.latitude,
                                                    latlng.longitude))
                                _use_default_ecoregion(fires_manager, loc)

                        except exceptions.MissingDependencyError as e:
                            _use_default_ecoregion(fires_manager, loc, e)

                    for fb in loc['fuelbeds']:
                        if not fb.get('fccs_id') or not fb.get('pct'):
                            raise ValueError(
                                "Each fuelbed must define 'fccs_id' and 'pct'")
Beispiel #4
0
        def _filter(fire, active_area):
            if not isinstance(active_area, dict):
                self._fail_fire(fire, self.MISSING_FIRE_LOCATION_INFO_MSG)
            try:
                latlng = LatLng(active_area)
                lat = latlng.latitude
                lng = latlng.longitude
            except ValueError as e:
                self._fail_fire(fire, self.MISSING_FIRE_LOCATION_INFO_MSG)
            if not lat or not lng:
                self._fail_fire(fire, self.MISSING_FIRE_LOCATION_INFO_MSG)

            return (lat < b['sw']['lat'] or lat > b['ne']['lat']
                    or lng < b['sw']['lng'] or lng > b['ne']['lng'])
Beispiel #5
0
        def _filter(fire, g):
            if not isinstance(g.get('location'), dict):
                self._fail_fire(fire, self.MISSING_FIRE_LAT_LNG_MSG)
            try:
                latlng = LatLng(g['location'])
                lat = latlng.latitude
                lng = latlng.longitude
            except ValueError as e:
                self._fail_fire(fire, self.MISSING_FIRE_LAT_LNG_MSG)
            if not lat or not lng:
                self._fail_fire(fire, self.MISSING_FIRE_LAT_LNG_MSG)

            return (lat < b['sw']['lat'] or lat > b['ne']['lat']
                    or lng < b['sw']['lng'] or lng > b['ne']['lng'])
Beispiel #6
0
def _validate_input(fires_manager):
    ecoregion_lookup = None  # instantiate only if necessary
    for fire in fires_manager.fires:
        with fires_manager.fire_failure_handler(fire):
            if not fire.get('activity'):
                raise ValueError(
                    "Missing activity data required for computing consumption")
            for a in fire.activity:
                for k in ('fuelbeds', 'location'):
                    if not a.get(k):
                        raise ValueError("Missing activity '{}' data required "
                                         "for computing consumption".format(k))
                # only 'area' is required from location
                if not a['location'].get('area'):
                    raise ValueError("Fire activity location data must "
                                     "define area for computing consumption")
                if not a['location'].get('ecoregion'):
                    # import EcoregionLookup here so that, if fires do have
                    # ecoregion defined, consumption can be run without mapscript
                    # and other dependencies installed
                    try:
                        latlng = LatLng(a['location'])
                        if not ecoregion_lookup:
                            from bluesky.ecoregion.lookup import EcoregionLookup
                            implemenation = Config.get(
                                'consumption',
                                'ecoregion_lookup_implemenation')
                            ecoregion_lookup = EcoregionLookup(implemenation)
                        a['location']['ecoregion'] = ecoregion_lookup.lookup(
                            latlng.latitude, latlng.longitude)
                        if not a['location']['ecoregion']:
                            logging.warning("Failed to look up ecoregion for "
                                            "{}, {}".format(
                                                latlng.latitude,
                                                latlng.longitude))
                            _use_default_ecoregion(fires_manager, a)

                    except exceptions.MissingDependencyError as e:
                        _use_default_ecoregion(fires_manager, a, e)

                for fb in a['fuelbeds']:
                    if not fb.get('fccs_id') or not fb.get('pct'):
                        raise ValueError(
                            "Each fuelbed must define 'fccs_id' and 'pct'")
Beispiel #7
0
def run(fires_manager):
    """Runs plumerise module

    Args:
     - fires_manager -- bluesky.models.fires.FiresManager object
    """
    fires_manager.processed(__name__, __version__)
    if not fires_manager.met:
        raise ValueError(NO_MET_ERROR_MSG)

    start_utc = None
    end_utc = None

    # keep array of references to locations passed into arlprofiler,
    # to update with local met data after bulk profiler is called
    locations = []
    # actual array of locations to pass into arlprofiler
    profiler_locations = []
    for fire in fires_manager.fires:
        with fires_manager.fire_failure_handler(fire):
            # Make sure fire has at least some locations, but
            # iterate first through activice areas and then through
            # locations in order to get utc_offset and time windows
            if not fire.locations:
                raise ValueError(NO_ACTIVITY_ERROR_MSG)

            for aa in fire.active_areas:
                # parse_utc_offset makes sure utc offset is defined and valid
                utc_offset = parse_utc_offset(aa.get('utc_offset'))
                tw = parse_datetimes(aa, 'start', 'end')

                # subtract utc_offset, since we want to get back to utc
                loc_start_utc = tw['start'] - datetime.timedelta(
                    hours=utc_offset)
                start_utc = min(start_utc,
                                loc_start_utc) if start_utc else loc_start_utc

                loc_end_utc = tw['end'] - datetime.timedelta(hours=utc_offset)
                end_utc = min(end_utc, loc_end_utc) if end_utc else loc_end_utc

                for loc in aa.locations:
                    latlng = LatLng(loc)
                    p_loc = {
                        'latitude': latlng.latitude,
                        'longitude': latlng.longitude
                    }

                    locations.append(loc)
                    profiler_locations.append(p_loc)

    if len(locations) != len(profiler_locations):
        raise RuntimeError(FAILED_TO_COMPILE_INPUT_ERROR_MSG)

    if not start_utc or not end_utc:
        raise RuntimeError(NO_START_OR_END_ERROR_MSG)

    arl_profiler = arlprofiler.ArlProfiler(fires_manager.met.get('files'),
                                           time_step=Config().get(
                                               'localmet', 'time_step'))
    logging.debug("Extracting localmet data for %d locations",
                  len(profiler_locations))

    localmet = arl_profiler.profile(start_utc, end_utc, profiler_locations)

    if len(localmet) != len(locations):
        raise RuntimeError(PROFILER_RUN_ERROR_MSG)

    for i in range(len(localmet)):
        locations[i]['localmet'] = localmet[i]