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)
def reset_config(): Config.reset() return Config