Coverage for subcell_pipeline/visualization/scatter_plots.py: 0%

18 statements  

« prev     ^ index     » next       coverage.py v7.5.3, created at 2024-08-29 15:14 +0000

1"""Methods for scatter plot visualization.""" 

2 

3from typing import Optional 

4 

5import numpy as np 

6from simulariumio import ScatterPlotData 

7 

8from subcell_pipeline.analysis.compression_metrics.compression_metric import ( 

9 CompressionMetric, 

10) 

11 

12 

13def make_empty_scatter_plots( 

14 metrics: list[CompressionMetric], 

15 total_steps: int = -1, 

16 times: Optional[np.ndarray] = None, 

17 time_units: Optional[str] = None, 

18) -> dict[CompressionMetric, ScatterPlotData]: 

19 """ 

20 Create empty scatter plot placeholders for list of metrics. 

21 

22 Parameters 

23 ---------- 

24 metrics 

25 List of metrics. 

26 total_steps 

27 Total number of timesteps. Required if times is not given. 

28 times 

29 List of timepoints. Required if total_steps is not given. 

30 time_units 

31 Time units. Used only with times. 

32 

33 Returns 

34 ------- 

35 : 

36 Map of metric to empty scatter plot placeholder. 

37 """ 

38 

39 if total_steps < 0 and times is None: 

40 raise Exception("Either total_steps or times array is required for plots") 

41 elif times is None: 

42 # use normalized time 

43 xlabel = "T (normalized)" 

44 xtrace = (1 / float(total_steps)) * np.arange(total_steps) 

45 else: 

46 # use actual time 

47 xlabel = f"T ({time_units})" 

48 xtrace = times 

49 total_steps = times.shape[0] 

50 

51 plots = {} 

52 

53 for metric in metrics: 

54 lower_bound, upper_bound = metric.bounds() 

55 plots[metric] = ScatterPlotData( 

56 title=metric.label(), 

57 xaxis_title=xlabel, 

58 yaxis_title=metric.description(), 

59 xtrace=xtrace, 

60 ytraces={ 

61 "<<<": lower_bound * np.ones(total_steps), 

62 ">>>": upper_bound * np.ones(total_steps), 

63 }, 

64 render_mode="lines", 

65 ) 

66 

67 return plots