Skip to content

Commit 6bedbac

Browse files
authored
Use circstd**2 for variance to ensure consistency across SciPy versions (#50)
* Calculate variance as stdev**2. Ensure consistency across SciPy versions * Do not import circvar as it is not needed
1 parent fa97e5f commit 6bedbac

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

MDRestraintsGenerator/datatypes.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from MDAnalysis.selections import gromacs as mda_gmx
3434
import numpy as np
3535
from scipy import stats
36-
from scipy.stats import circmean, circvar, circstd
36+
from scipy.stats import circmean, circstd
3737
from matplotlib import pyplot as plt
3838

3939

@@ -56,7 +56,8 @@ def analyze(self):
5656
if not self.periodic:
5757
self.mean = self.values.mean()
5858
self.stdev = self.values.std()
59-
self.var = self.values.var()
59+
# Same behavior as for periodic data
60+
self.var = self.stdev**2
6061
else:
6162
p_high = 180
6263
if self.atype == "angle":
@@ -65,7 +66,9 @@ def analyze(self):
6566
p_low = -180
6667
self.mean = circmean(self.values, low=p_low, high=p_high)
6768
self.stdev = circstd(self.values, low=p_low, high=p_high)
68-
self.var = circvar(self.values, low=p_low, high=p_high)
69+
# Use circstd**2 instead of circvar to
70+
# have same behavior across SciPy versions
71+
self.var = self.stdev**2
6972

7073
def mean_squared(self):
7174
"""Returns (value-mean)**2 """

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
install_requires=[
2727
'MDAnalysis>1.0.0',
2828
'numpy',
29-
'scipy<1.8',
29+
'scipy',
3030
'matplotlib',
3131
],
3232
)

0 commit comments

Comments
 (0)