Coverage for tests/test_sample_data.py: 100%

1"""

2 Contains unit tests for scores.sample_data

3"""

4

5 import xarray as xr

6

7 import scores.sample_data as sd

8

9

10 def test_simple_forecast():

11 """

12 Very basic test that the functions return comparable things

13 """

14 fcst = sd.simple_forecast()

15 obs = sd.simple_observations()

16

17 assert len(fcst) == len(obs)

18

19

20 def test_continuous_data():

21 """tests sample_data.continuous_forecast and sample_data.continuous_observations"""

22 obs_small = sd.continuous_observations(large_size=False)

23 forecast_small = sd.continuous_forecast(large_size=False)

24 forecast_small_lead_days = sd.continuous_forecast(large_size=False, lead_days=True)

25

26 assert obs_small.shape == forecast_small.shape

27 assert forecast_small_lead_days.size == 2 * forecast_small.size

28 assert forecast_small_lead_days.dims == ("lead_time", "lat", "lon", "time")

29 assert forecast_small.dims == ("lat", "lon", "time")

30 assert isinstance(forecast_small, xr.DataArray)

31 assert isinstance(obs_small, xr.DataArray)

32

33

34 def test_cdf_data():

35 """tests sample_data.cdf_forecast and sample_data.obs_for_cdf_forecast"""

36 obs = sd.cdf_observations()

37 fcst = sd.cdf_forecast()

38 fcst_lead_days = sd.cdf_forecast(lead_days=True)

39

40 assert 2 * fcst.size == fcst_lead_days.size

41 assert 100 * obs.size == fcst.size

42 assert len(obs.dims) == 3

43 assert len(fcst.dims) == 4

44 assert len(fcst_lead_days.dims) == 5

45 assert isinstance(obs, xr.DataArray)

46 assert isinstance(fcst, xr.DataArray)

47 assert isinstance(fcst_lead_days, xr.DataArray)