def test_basic_mean_predictor_bad_value(self): """ Test that the plugin returns a numpy float64 value and that the value matches the BAD_VALUE, when the appropriate condition is found. The ensemble mean is the predictor. """ initial_guess = [1e65, 1e65, 1e65, 1e65] initial_guess = np.array(initial_guess, dtype=np.float32) cube = set_up_wind_speed_cube() forecast_predictor = cube.collapsed("realization", iris.analysis.MEAN) forecast_variance = cube.collapsed("realization", iris.analysis.VARIANCE) truth = cube.collapsed("realization", iris.analysis.MAX) forecast_predictor_data = (forecast_predictor.data.flatten().astype( np.float32)) forecast_variance_data = (forecast_variance.data.flatten().astype( np.float32)) truth_data = truth.data.flatten().astype(np.float32) sqrt_pi = np.sqrt(np.pi).astype(np.float32) predictor_of_mean_flag = "mean" plugin = Plugin() result = plugin.truncated_normal_crps_minimiser( initial_guess, forecast_predictor_data, truth_data, forecast_variance_data, sqrt_pi, predictor_of_mean_flag) self.assertIsInstance(result, np.float64) self.assertAlmostEqual(result, plugin.BAD_VALUE)
def test_basic_members_predictor(self): """ Test that the plugin returns a numpy array. The ensemble members are the predictor. """ initial_guess = [5, 1, 0, 1, 1, 1] initial_guess = np.array(initial_guess, dtype=np.float32) cube = set_up_wind_speed_cube() forecast_predictor = cube.copy() forecast_variance = cube.collapsed("realization", iris.analysis.VARIANCE) truth = cube.collapsed("realization", iris.analysis.MAX) forecast_predictor_data = ( convert_cube_data_to_2d(forecast_predictor).astype(np.float32)) forecast_variance_data = (forecast_variance.data.flatten().astype( np.float32)) truth_data = truth.data.flatten().astype(np.float32) sqrt_pi = np.sqrt(np.pi).astype(np.float32) predictor_of_mean_flag = "members" plugin = Plugin() result = plugin.truncated_normal_crps_minimiser( initial_guess, forecast_predictor_data, truth_data, forecast_variance_data, sqrt_pi, predictor_of_mean_flag) self.assertIsInstance(result, np.float64) self.assertAlmostEqual(result, 533.487612959)
def setUp(self): """Set up multiple cubes for testing.""" self.current_temperature_forecast_cube = ( add_forecast_reference_time_and_forecast_period( set_up_temperature_cube())) self.historic_temperature_forecast_cube = (_create_historic_forecasts( self.current_temperature_forecast_cube)) self.temperature_truth_cube = (_create_truth( self.current_temperature_forecast_cube)) self.current_wind_speed_forecast_cube = ( add_forecast_reference_time_and_forecast_period( set_up_wind_speed_cube())) self.historic_wind_speed_forecast_cube = (_create_historic_forecasts( self.current_wind_speed_forecast_cube)) self.wind_speed_truth_cube = (_create_truth( self.current_wind_speed_forecast_cube))
def setUp(self): """Create cubes to input.""" self.temperature_cube = set_up_temperature_cube() self.wind_speed_cube = set_up_wind_speed_cube() # create cube with metadata and values suitable for pressure. pressure_data = (np.tile(np.linspace(100000, 110000, 9), 3).reshape(3, 1, 3, 3)) pressure_data[0] -= 2 pressure_data[1] += 2 pressure_data[2] += 4 self.pressure_cube = set_up_cube(pressure_data, "air_pressure", "Pa") # create cube with metadata and values suitable for relative humidity. relative_humidity_data = (np.tile(np.linspace(0, 0.6, 9), 3).reshape(3, 1, 3, 3)) relative_humidity_data[0] += 0 relative_humidity_data[1] += 0.2 relative_humidity_data[2] += 0.4 self.relative_humidity_cube = set_up_cube(relative_humidity_data, "relative_humidity", "1")
def setUp(self): """Set up temperature and wind speed cubes for testing.""" # Note: test_temperature_realizations_data_check produces ~0.5K # different results when the temperature forecast cube is float32 # below. A bug? self.current_temperature_forecast_cube = ( add_forecast_reference_time_and_forecast_period( set_up_temperature_cube())) self.historic_temperature_forecast_cube = (_create_historic_forecasts( self.current_temperature_forecast_cube)) self.temperature_truth_cube = (_create_truth( self.current_temperature_forecast_cube)) self.current_wind_speed_forecast_cube = ( add_forecast_reference_time_and_forecast_period( set_up_wind_speed_cube())) self.historic_wind_speed_forecast_cube = (_create_historic_forecasts( self.current_wind_speed_forecast_cube)) self.wind_speed_truth_cube = (_create_truth( self.current_wind_speed_forecast_cube))
def setUp(self): """Creates cubes to input""" self.temperature_cube = set_up_temperature_cube()[0, :, 0] self.wind_speed_cube = set_up_wind_speed_cube()[0, :, 0]