@@ -17,14 +17,29 @@ def test_subset():
1717 '2023-12-24T00:57:07.814960674' , '2023-12-24T00:57:07.826344209' ]).astype (np .datetime64 ).astype (float ))
1818 assert np .sum (selection ) == 10
1919
20- def test_color_by_time_datetime ():
20+ def test_color_by_time_datetime_nolimit ():
21+ some_datetimes = np .array ([dt (2021 , 4 , 9 , 1 , 51 , 0 ), dt (2021 , 4 , 9 , 1 , 52 , 0 ), dt (2021 , 4 , 9 , 1 , 53 , 0 ), dt (2021 , 4 , 9 , 1 , 54 , 0 ), dt (2021 , 4 , 9 , 1 , 59 , 0 )])
22+ vmin , vmax , colors = color_by_time (some_datetimes )
23+ assert vmin == 0
24+ assert vmax == 480
25+ assert np .allclose (colors , np .array ([0 , 60 , 120 , 180 , 480 ]))
26+
27+
28+ def test_color_by_time_datetime_limit ():
2129 some_datetimes = np .array ([dt (2021 , 4 , 9 , 1 , 51 , 0 ), dt (2021 , 4 , 9 , 1 , 52 , 0 ), dt (2021 , 4 , 9 , 1 , 53 , 0 ), dt (2021 , 4 , 9 , 1 , 54 , 0 ), dt (2021 , 4 , 9 , 1 , 59 , 0 )])
2230 limits = [dt (2021 , 4 , 9 , 1 , 50 , 0 ), dt (2021 , 4 , 9 , 2 , 0 , 0 )]
2331 vmin , vmax , colors = color_by_time (some_datetimes , limits )
2432 assert vmin == 0
25- assert vmax == 540
26- assert np .allclose (colors , np .array ([0 , 60 , 120 , 180 , 480 ]))
33+ assert vmax == 600
34+ assert np .allclose (colors , np .array ([60 , 120 , 180 , 240 , 540 ]))
2735
36+ def test_color_by_time_xarray ():
37+ dataset = xr .open_dataset ('tests/truth/lma_netcdf/lma.nc' )
38+ vmin , vmax , colors = color_by_time (dataset .event_time )
39+ assert vmin == 0
40+ assert np .isclose (vmax , 57.943683385849 )
41+ assert np .isclose (np .mean (colors ), 30.483982899376258 )
42+ assert np .isclose (np .std (colors ), 17.25687093241869 )
2843
2944def test_setup_hist ():
3045 lma = xr .open_dataset ('tests/truth/lma_netcdf/lma.nc' )
0 commit comments