Esempio n. 1
0
 def test_met_info(self, reset_config):
     met_info = {
         "grid": {
             "spacing": 6.0,
             "boundary": {
                 "ne": {
                     "lat": 45.25,
                     "lng": -106.5
                 },
                 "sw": {
                     "lat": 27.75,
                     "lng": -131.5
                 }
             }
         }
     }
     expected = {
         'center_latitude': 36.5,
         'center_longitude': -119.0,
         'height_latitude': 17.5,
         'spacing_latitude': 0.06705008458605,
         'spacing_longitude': 0.06705008458605,
         'width_longitude': 25.0
     }
     assert expected == hysplit_utils.get_grid_params(met_info=met_info)
Esempio n. 2
0
    def _set_dispersion_output_info(self):
        disp_output_info = (self._fires_manager.dispersion
            and self._fires_manager.dispersion.get('output')) or {}

        self._hysplit_output_directory = (disp_output_info.get('directory')
            or disp_config('output_dir'))
        if not self._hysplit_output_directory:
            raise ValueError("hysplit output directory must be defined")
        if not os.path.isdir(self._hysplit_output_directory):
            raise RuntimeError("hysplit output directory {} is not valid".format(
                self._hysplit_output_directory))

        self._hysplit_output_file = (disp_output_info.get('grid_filename')
            or disp_hysplit_config('output_file_name'))
        if not self._hysplit_output_file:
            raise ValueError("hysplit output file must be defined")
        self._hysplit_output_file = os.path.join(self._hysplit_output_directory, self._hysplit_output_file)
        if not os.path.isfile(self._hysplit_output_file):
            raise RuntimeError("hysplit output file {} does not exist".format(
                self._hysplit_output_file))

        self._grid_params = (disp_output_info.get("grid_parameters")
            or (hysplit_utils.get_grid_params(allow_undefined=True))
            or {}) # allow them to be undefined

        self._start_time = (disp_output_info.get("start_time")
            or disp_config("start"))
        self._num_hours = (disp_output_info.get("num_hours")
            or disp_config('num_hours'))
Esempio n. 3
0
 def test_user_defined_grid(self, reset_config):
     Config.set(True, "dispersion", "hysplit", "USER_DEFINED_GRID")
     Config.set(36.5, "dispersion", "hysplit", "CENTER_LATITUDE")
     Config.set(-119.0, "dispersion", "hysplit", "CENTER_LONGITUDE")
     Config.set(25.0, "dispersion", "hysplit", "WIDTH_LONGITUDE")
     Config.set(17.5, "dispersion", "hysplit", "HEIGHT_LATITUDE")
     Config.set(0.05, "dispersion", "hysplit", "SPACING_LONGITUDE")
     Config.set(0.05, "dispersion", "hysplit", "SPACING_LATITUDE")
     expected = {
         'center_latitude': 36.5,
         'center_longitude': -119.0,
         'height_latitude': 17.5,
         'spacing_latitude': 0.05,
         'spacing_longitude': 0.05,
         'width_longitude': 25.0
     }
     assert expected == hysplit_utils.get_grid_params()
Esempio n. 4
0
 def test_grid(self, reset_config):
     Config().set( {
         "spacing": 6.0,
         "boundary": {
             "ne": {
                 "lat": 45.25,
                 "lng": -106.5
             },
             "sw": {
                 "lat": 27.75,
                 "lng": -131.5
             }
         }
     }, "dispersion", "hysplit" , "grid")
     expected = {
         'center_latitude': 36.5,
         'center_longitude': -119.0,
         'height_latitude': 17.5,
         'spacing_latitude': 0.06705008458605,
         'spacing_longitude': 0.06705008458605,
         'width_longitude': 25.0
     }
     assert expected == hysplit_utils.get_grid_params()
Esempio n. 5
0
 def test_fail(self, reset_config):
     with raises(BlueSkyConfigurationError) as e_info:
         hysplit_utils.get_grid_params()
     assert e_info.value.args[0] == 'Specify hysplit dispersion grid'
Esempio n. 6
0
 def test_allow_undefined(self, reset_config):
     expected = {}
     assert expected == hysplit_utils.get_grid_params(allow_undefined=True)
Esempio n. 7
0
    def test_compute_grid(self, reset_config):
        fires_one = [{'latitude': 40.0, 'longitude': -118.5}]
        fires_two = [{
            'latitude': 40.0,
            'longitude': -118.5
        }, {
            'latitude': 45.0,
            'longitude': -117.5
        }]

        ## Missing spacing

        Config.set(True, "dispersion", "hysplit", "compute_grid")
        with raises(BlueSkyConfigurationError) as e_info:
            hysplit_utils.get_grid_params(fires=fires_one)
        assert e_info.value.args[0] == (
            "Config settings 'spacing_latitude' "
            "and 'spacing_longitude' required to compute hysplit grid")

        Config.reset()
        Config.set(True, "dispersion", "hysplit", "compute_grid")
        Config.set(0.05, 'dispersion', 'hysplit', 'spacing_longitude')
        with raises(BlueSkyConfigurationError) as e_info:
            hysplit_utils.get_grid_params(fires=fires_one)
        assert e_info.value.args[0] == (
            "Config settings 'spacing_latitude' "
            "and 'spacing_longitude' required to compute hysplit grid")

        Config.reset()
        Config.set(True, "dispersion", "hysplit", "compute_grid")
        Config.set(0.05, 'dispersion', 'hysplit', 'spacing_latitude')
        with raises(BlueSkyConfigurationError) as e_info:
            hysplit_utils.get_grid_params(fires=fires_one)
        assert e_info.value.args[0] == (
            "Config settings 'spacing_latitude' "
            "and 'spacing_longitude' required to compute hysplit grid")

        ## no fires or two many fires

        Config.reset()
        Config.set(True, "dispersion", "hysplit", "compute_grid")
        Config.set(0.05, 'dispersion', 'hysplit', 'spacing_latitude')
        Config.set(0.05, 'dispersion', 'hysplit', 'spacing_longitude')

        with raises(ValueError) as e_info:
            hysplit_utils.get_grid_params()
        assert e_info.value.args[
            0] == 'Option to compute grid only supported for runs with one fire'

        with raises(ValueError) as e_info:
            hysplit_utils.get_grid_params(fires=fires_two)
        assert e_info.value.args[
            0] == 'Option to compute grid only supported for runs with one fire'

        expected = {
            'center_latitude': 40.0,
            'center_longitude': -118.5,
            'height_latitude': 18.01801801801802,
            'spacing_latitude': 0.05,
            'spacing_longitude': 0.05,
            'width_longitude': 23.453239118438354
        }
        assert expected == hysplit_utils.get_grid_params(fires=fires_one)

        # custom grid length (default is 2000)
        Config.set(1000, 'dispersion', 'hysplit', 'grid_length')
        expected = {
            'center_latitude': 40.0,
            'center_longitude': -118.5,
            'height_latitude': 9.00900900900901,
            'spacing_latitude': 0.05,
            'spacing_longitude': 0.05,
            'width_longitude': 11.726619559219177
        }
        assert expected == hysplit_utils.get_grid_params(fires=fires_one)