echidna.test package

Submodules

echidna.test.physics_tests module

Physics tests are like unittests but for testing physics results.

Example

To run all physics tests:

$ python physics_tests.py
echidna.test.physics_tests.test_function_float(function, expected, tolerance=0.001, **kwargs)[source]

Tests a function that returns a physics result (float)

Parameters:
  • function (function) – An instance of the function/method. e.g. caculator.get_n_atoms - notice no parentheses.
  • expected (float) – Expected physics result of function.
  • tolerance (float, optional) – Tolerance in agreement of results. Evaluated as tolerance*expected, i.e. a tolerance of 0.001 ensures agreement to within 0.1% of expected value.
Returns:

(bool, string): Tuple containing the result of the check True/ False for Pass/Fail and a message.

echidna.test.test_minimise module

Tests minimise module.

Tests the GridSearch.fin_minimum(), method - an alternative to calling numpy.argmin() and numpy.nanmin(), which are used by default.

The main part of this test is verifying the GridSearch class, particularly the meth:`GridSearch.minimise method.

class echidna.test.test_minimise.TestGridSearch(methodName='runTest')[source]

Bases: unittest.case.TestCase

Tests for the class echidna.limit.minimise.GridSearch.

_funct(*args)[source]

Callable to pass to minimiser.

Fits A**2 + B**2 to C**2.

Returns:numpy.ndarray: Test statistic values float: Penalty term - in this case always zero.
setUp()[source]

Set up attributes for tests.

Variables:
  • _A (spectra.Spectra) – Test spectrum A - to use in test
  • _B (spectra.Spectra) – Test spectrum B - to use in test
  • _C (spectra.Spectra) – Test spectrum C - to use in test
  • _test_statistic (test_statistic.BakerCousinsChi) – Test statistic to use in test
  • _default_grid_search (GridSearch) – GridSearch using default method (numpy) for minimisation.
  • _grid_search (GridSearch) – GridSearch using GridSearch.find_minimum(), to find minimum.
test_find_minimum()[source]

Test the GridSearch.find_minimum() method.

Tests:
  • That GridSearch.find_minimum() correctly locates the minimum.
  • That GridSearch.find_minimum() exhibits the correct behaviour when there are two minima.
test_minimise()[source]

Test the GridSearch.minimise() method.

Floats A, B and C (rates) and fits A^2 + B^2 to C^2, using a a test_statistic.BakerCousinsChi test statistic.

The fitted rates should form the pythagorean triple: 5^2 + 12^2 = 13^2.

echidna.test.test_scale module

class echidna.test.test_scale.TestScale(methodName='runTest')[source]

Bases: unittest.case.TestCase

fit_gaussian_energy(spectrum)[source]

Fits a gausian to the energy of a spectrum.

Parameters:spectra (spectra.Spectra) – Spectrum to be fitted
Returns:mean (float), sigma (float) and integral (float) of the spectrum.
Return type:tuple
gaussian(x, *p)[source]

A gaussian used for fitting.

Parameters:x (float) – Position the gaussian is calculated at.
Returns:Value of gaussian at x for given parameters
Return type:float
test_scale()[source]

Tests the variable scaling method.

Creates a Gaussian spectra with mean energy 2.5 MeV and sigma 0.2 MeV. Radial values of the spectra have a uniform distribution. The “energy_mc” of the spectra is then scaled by a factor by 1.1. The scaled spectra is fitted with a Gaussian and the extracted mean and sigma are checked against expected values within 1 %. Integral of scaled spectrum is checked against original number of entries.

echidna.test.test_shift module

class echidna.test.test_shift.TestShift(methodName='runTest')[source]

Bases: unittest.case.TestCase

fit_gaussian_energy(spectrum)[source]

Fits a gausian to the energy of a spectrum.

Parameters:spectrum (spectra.Spectra) – Spectrum to be fitted
Returns:mean (float), sigma (float) and integral (float) of the spectrum.
Return type:tuple
gaussian(x, *p)[source]

A gaussian used for fitting.

Parameters:x (float) – Position the gaussian is calculated at.
Returns:Value of gaussian at x for given parameters
Return type:float
test_shift()[source]

Tests the variable shifting method.

Creates a Gaussian spectra with mean energy 2.5 MeV and sigma 0.2 MeV. Radial values of the spectra have a uniform distribution. The “energy_mc” of the spectra is then shifted by 0.111 MeV. The shifted spectra is fitted with a Gaussian and the extracted mean and sigma are checked against expected values within 1 %. Integral of shifted spectrum is checked against original number of entries. This is then repeated for a shift of 0.2 MeV to test the shift_by_bin method.

echidna.test.test_smear module

class echidna.test.test_smear.TestSmear(methodName='runTest')[source]

Bases: unittest.case.TestCase

fit_gaussian_energy(spectrum)[source]

Fits a gausian to the energy of a spectrum.

Parameters:spectrum (spectra.Spectra) – Spectrum to be smeared
Returns:mean (float), sigma (float) and integral (float) of the spectrum.
Return type:tuple
fit_gaussian_radius(spectrum)[source]

Fits a gausian to the radius of a spectrum.

Parameters:spectrum (spectra.Spectra) – Spectrum to be smeared
Returns:mean (float), sigma (float) and integral (float)
Return type:tuple
fit_poisson_energy(spectrum)[source]

Fits a gausian to the energy of a spectrum.

Parameters:spectrum (spectra.Spectra) – Spectrum to be smeared
Returns:mean (float), sigma (float) and integral (float) of the spectrum.
Return type:tuple
gaussian(x, *p)[source]

A gaussian used for fitting.

Parameters:x (float) – Position the gaussian is calculated at.
Returns:Value of gaussian at x for given parameters (float)
Return type:float
poisson(x, *p)[source]

A poisson used for fitting.

Parameters:x (float) – Position the gaussian is calculated at.
Returns:Value of poisson at x for given parameters (float)
Return type:float
test_random_energy_res_gauss()[source]

Tests the random gaussian smearing method for energy resolution.

Creates a delta function and fits the mean and sigma after smearing. Mean and sigma are checked against set values within 1 %. Integral of smeared spectrum is checked against original number of entries.

test_random_energy_res_poiss()[source]

Tests the random gaussian smearing method for energy resolution.

Creates a delta function and fits the mean after smearing. Mean is checked against set values within 1 %. Integral of smeared spectrum is checked against original number of entries.

test_random_radius()[source]

Tests the random gaussian smearing method for radius.

Creates a delta function and fits the mean and sigma after smearing. Mean and sigma are checked against set values within 1 %. Integral of smeared spectrum is checked against original number of entries.

test_weight_energy_ly_gauss()[source]

Tests the weighted gaussian smearing method for energy by light yield.

Creates a delta function and fits the mean and sigma after smearing. Mean and sigma are checked against set values within 1 %. Integral of smeared spectrum is checked against original number of entries.

test_weight_energy_ly_poiss()[source]

Tests the weighted poisson smearing method for energy by light yield.

Creates a delta function and fits the mean after smearing. Mean is checked against set values within 1 %. Integral of smeared spectrum is checked against original number of entries.

test_weight_energy_res_gauss()[source]

Tests the weighted gaussian smearing method for energy resolution.

Creates a delta function and fits the mean and sigma after smearing. Mean and sigma are checked against set values within 1 %. Integral of smeared spectrum is checked against original number of entries.

test_weight_energy_res_poiss()[source]

Tests the weighted poisson smearing method for energy resolution.

Creates a delta function and fits the mean after smearing. Mean is checked against set values within 1 %. Integral of smeared spectrum is checked against original number of entries.

test_weight_radius()[source]

Tests the weighted gaussian smearing method for radius.

Creates a delta function and fits the mean and sigma after smearing. Mean and sigma are checked against set values within 1 %. Integral of smeared spectrum is checked against original number of entries.

echidna.test.test_spectra module

class echidna.test.test_spectra.TestSpectra(methodName='runTest')[source]

Bases: unittest.case.TestCase

test_fill()[source]

Test the fill method.

Basically tests bin positioning makes sense.

test_project()[source]

Test the projection method of the spectra.

This creates projected spectra alongside the actual spectra.

test_rebin()[source]

Tests that the spectra are being rebinned correctly.

test_scale()[source]

Test the scale method of the spectra.

This creates a spectra and then scales it.

test_slicing()[source]

Test the slicing shirnks the spectra in the correct way.

echidna.test.test_store module

class echidna.test.test_store.TestStore(methodName='runTest')[source]

Bases: unittest.case.TestCase

test_serialisation()[source]

Test saving and then reloading a test spectra.

echidna.test.test_test_statistic module

class echidna.test.test_test_statistic.TestTestStatistic(methodName='runTest')[source]

Bases: unittest.case.TestCase

Tests for the echidna.limit.test_statistic.TestStatistic class and it’s derived classes.

setUp()[source]
test_abstract_base_class()[source]

Tests the base class

test_log_likelihood()[source]

Test the echidna.limit.test_statistic.BakerCousinLL class that calculates the log likelihood ratio.

test_neyman()[source]

Test the Neyman chi-squared class

test_pearson()[source]

Test the Pearson chi-squared class

test_poisson_likelihood_chi()[source]

Test the echidna.limit.test_statistic.BakerCousinChi class that calculates the poisson likelihood chi-squared.

Module contents