Statistics Documentation

class Statistics[source]

Statistics relating to the data in each plugin are calculated automatically by the statistics class. The maximum, minimum, mean and standard deviation are calculated per slice, and are combined at the end of the plugin to give volume-wide statistics of max, min, mean, mean_std_dev and median_std_dev. Additionally, residuals are calculated between the data slices pre and post processing. These are used to calculated the RMSD (root mean square deviation) between the data before and after processing, and this is normalised by dividing by the mean to produce the NRMSD. This is a measure of how much a plugin is changing the data.

Every plugin object contains a statistics object called stats_obj. This object contains the per-slice stats for that plugin, as well as the volume-wide stats for that plugin, and every plugin that came before it.


Accessing statistics in Savu

The volume-wide stats for a plugin can be accessed in Savu either with the plugin number, or the name of the plugin, using the following methods:

Statistics.get_stats(p_num=None, stat=None, instance=- 1)[source]

Returns stats associated with a certain plugin, given the plugin number (its place in the process list).

Parameters
  • p_num – Plugin number of the plugin whose associated stats are being fetched. If p_num <= 0, it is relative to the plugin number of the current plugin being run. E.g current plugin number = 5, p_num = -2 –> will return stats of the third plugin. By default will gather stats for the current plugin.

  • stat – Specify the stat parameter you want to fetch, i.e ‘max’, ‘mean’, ‘median_std_dev’. If left blank will return the whole dictionary of stats: {‘max’: , ‘min’: , ‘mean’: , ‘mean_std_dev’: , ‘median_std_dev’: , ‘NRMSD’: }

  • instance – In cases where there are multiple set of stats associated with a plugin due to iterative loops or multi-parameters, specify which set you want to retrieve, i.e 3 to retrieve the stats associated with the third run of a plugin. Pass ‘all’ to get a list of all sets. By default will retrieve the most recent set.

Statistics.get_stats_from_name(plugin_name, n=None, stat=None, instance=- 1)[source]

Returns stats associated with a certain plugin.

Parameters
  • plugin_name – name of the plugin whose associated stats are being fetched.

  • n – In a case where there are multiple instances of plugin_name in the process list, specify the nth instance. Not specifying will select the first (or only) instance.

  • stat – Specify the stat parameter you want to fetch, i.e ‘max’, ‘mean’, ‘median_std_dev’. If left blank will return the whole dictionary of stats: {‘max’: , ‘min’: , ‘mean’: , ‘mean_std_dev’: , ‘median_std_dev’: , ‘NRMSD’: }

  • instance – In cases where there are multiple set of stats associated with a plugin due to iterative loops or multi-parameters, specify which set you want to retrieve, i.e 3 to retrieve the stats associated with the third run of a plugin. Pass ‘all’ to get a list of all sets. By default will retrieve the most recent set.

Volume-wide stats are also added to the metadata of the output dataset for each plugin. If you have a dataset object, for example by using the plugin.get_datasets() method, stats can be accessed using the following method:

Statistics.get_stats_from_dataset(dataset, stat=None, instance=- 1)[source]

Returns stats associated with a dataset.

Parameters
  • dataset – The dataset whose associated stats are being fetched.

  • stat – Specify the stat parameter you want to fetch, i.e ‘max’, ‘mean’, ‘median_std_dev’. If left blank will return the whole dictionary of stats: {‘max’: , ‘min’: , ‘mean’: , ‘mean_std_dev’: , ‘median_std_dev’: , ‘NRMSD’: }

  • instance – In cases where there are multiple set of stats associated with a dataset due to iterative loops or multi-parameters, specify which set you want to retrieve, i.e 3 to retrieve the stats associated with the third run of a plugin. Pass ‘all’ to get a list of all sets. By default will retrieve the most recent set.

Here are examples of how to use these methods:

../../_images/get_stats.png
../../_images/get_stats_from_name.png
../../_images/get_stats_from_dataset.png

Note that stats aren’t currently gathered in loaders, meaning that if a plugin occurs right after a loader in a plugin chain it will not be able to access stats and errors may occur if this is attempted. If this is needed, add NoProcessPlugin right after the loader with an appropriate pattern. This will calculate stats for the input data without doing any processing.

class NoProcessPlugin[source]

Accessing statistics outside of Savu

After a Savu run has completed, the statistics for that run are contained in the stats folder in the output directory. In that folder you’ll find a table containing the stats for every plugin, as well as graphs showing how each statistical measure changes from plugin to plugin, in projection and reconstruction space.

max min mean mean_std_dev median_std_dev NRMSD
Projection 2: DarkFlatFieldCorrection 0.754647 0.000000 0.605264 0.169827 0.169827 30627.281575
3: DezingerSinogram 0.743160 0.051666 0.605285 0.114450 0.159685 0.008255
4: MedianFilter 0.729688 0.055079 0.605291 0.113849 0.159878 0.008986
Reconstruction 5: AstraReconCpu 0.123803 -0.145944 0.002769 0.004747 0.004719 NaN
6: MedianFilter2 0.112739 -0.092735 0.002767 0.004632 0.004687 0.005097
7: MedianFilter3 0.111458 -0.068332 0.002763 0.004593 0.004681 0.001670
8: MedianFilter4 0.109190 -0.060353 0.002761 0.004562 0.004675 0.001084

../../_images/projection_stats.png
../../_images/reconstruction_stats.png

All these figures are generated by looking at a hdf5 file called stats.h5, which is populated over the course of the run, and can be found in the same folder as the figures. It can be viewed in DAWN, or could provide the statistics data for scripts doing further processing.

Since statistics are also attached to the output datasets of plugins, they can also be viewed in DAWN by opening the output nexus file and looking at the meta header table.

Stats in iterative loops

Stats are calculated for every iteration of an iterative loop. You can use the instance parameter of the get methods above to specify which iteration you want the stats for.

../../_images/get_stats_from_dataset_iterative.png

In the table found in /stats, the stats values for every iteration will be displayed one after each other for each plugin in the loop. In the graphs, the minimum and maximum value for each stat will be displayed as an error bar for each plugin in the loop.

max min mean mean_std_dev median_std_dev NRMSD
Projection 2: DarkFlatFieldCorrection 0.754647 0 0.605264 0.169827 0.169827 30627.3
3: DezingerSinogram 0.74316 0.051666 0.605285 0.11445 0.159685 0.00825511
4: MedianFilter 0.729688 0.0550785 0.605291 0.113849 0.159878 0.00898604
Reconstruction 5: AstraReconCpu 0.123803 -0.145944 0.00276923 0.00474743 0.00471922 None
6: MedianFilter2 (loop0) [0.11273914575576782, 0.1091899424791336, 0.10694712400436401, 0.10543075203895569] [-0.09273546934127808, -0.060353074222803116, -0.04863771051168442, -0.03930406644940376] [0.0027667053509503603, 0.0027608955278992653, 0.002756689675152302, 0.0027529550716280937] [0.004632266238331795, 0.00456209247931838, 0.004512254614382982, 0.0044701192528009415] [0.00468667084351182, 0.00467502698302269, 0.004673760384321213, 0.004672942217439413] [0.005097260774460717, 0.0010840471163607837, 0.0008157274204517187, 0.0007261793343611832]
7: MedianFilter3 (loop0) [0.11145839095115662, 0.10745032876729965, 0.10627936571836472, 0.10477979481220245] [-0.06833195686340332, -0.05121315270662308, -0.041387010365724564, -0.03770136460661888] [0.0027633714489638805, 0.002758702728897333, 0.0027547532226890326, 0.0027512619271874428] [0.004592671524733305, 0.004535829648375511, 0.004490320570766926, 0.004451526328921318] [0.0046811639331281185, 0.004674311261624098, 0.004673303570598364, 0.004672533832490444] [0.0016701188189876801, 0.000940213365650342, 0.0007964634904066289, 0.0006711845244251432]
8: MedianFilter4 0.105431 -0.0393041 0.00275296 0.00447012 0.00467294 0.000726179

../../_images/reconstruction_stats_iterate.png

Setting statistics

Volume-wide stats are automatically calculated and set directly after the post_process() method in each plugin. Attempting to access the stats of the current plugin before this point, for example from its out dataset, will result in an error. If stats are needed before this point, call the method set_volume_stats() first to populate the relevant dictionaries and datasets. This should happen after all data processing has occurred.

Statistics.set_volume_stats()[source]

Calculates volume-wide statistics from slice stats, and updates class-wide arrays with these values. Links volume stats with the output dataset and writes slice stats to file.

Turning statistics off

To stop statistics being calculated on a run of Savu, use the –stats option and pass off to it.

../../_images/stats_flag.png

Some plugins don’t have statistics calculated for them, such as plugins which exclusively produce metadata instead of processed data. To turn stats off for a single plugin you can set self.stats_obj.calc_stats to False in the Setup() method of that plugin.

Attempting to access stats for plugins where stats is turned off will result in errors.

Examples

The statistics class is used by the following plugins in Savu:

class DezingerSinogram[source]
process_frames(data)[source]

This method is called after the plugin has been created by the pipeline framework and forms the main processing step

Parameters

data (list(np.array)) – A list of numpy arrays for each input dataset.

class DownsampleFilter[source]
get_min_and_max()[source]
class ImageSaver(name='ImageSaver')[source]
_get_min_and_max()[source]

The MinAndMax plugin is deprecated and should not be used to gather min and max values.