Skip to content

Commit

Permalink
Merging master into new_python_api
Browse files Browse the repository at this point in the history
  • Loading branch information
jbdurand committed Jul 18, 2024
2 parents c615b79 + fffa324 commit 2e9d075
Show file tree
Hide file tree
Showing 21 changed files with 81 additions and 61 deletions.
2 changes: 1 addition & 1 deletion stat_tool/src/openalea/stat_tool/mixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def Mixture(*args):
# Extract weights ands distributions
weights = []
dists = []
for i in range(nb_param / 2):
for i in range(nb_param // 2):
weights.append(args[i * 2])
error.CheckType([args[i * 2 + 1]], [types], arg_id=[i * 2 + 1])
error.CheckType([args[i * 2]], [float], arg_id=[i * 2])
Expand Down
11 changes: 7 additions & 4 deletions stat_tool/test/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
from openalea.stat_tool.vectors import Vectors, VectorDistance
from openalea.stat_tool.comparison import Compare
from openalea.stat_tool.data_transform import SelectVariable
from openalea.stat_tool.cluster import Transcode, Clustering, \
ToDistanceMatrix, Cluster
from openalea.stat_tool.cluster import (Transcode, Clustering,
ToDistanceMatrix, Cluster)

from tools import runTestClass
from openalea.stat_tool import get_shared_data
from tools import runTestClass, robust_path
import openalea.stat_tool as st
#from openalea.stat_tool import get_shared_data, get_shared_data_path

get_shared_data = robust_path


class Test:
Expand Down
3 changes: 2 additions & 1 deletion stat_tool/test/test_cluster_and_distance_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
from openalea.stat_tool import ExtractHistogram
from openalea.stat_tool import Display

from openalea.stat_tool import get_shared_data
#from openalea.stat_tool import get_shared_data
from tools import robust_path as get_shared_data

def test():
vec10 = Vectors(get_shared_data('chene_sessile.vec'))
Expand Down
5 changes: 3 additions & 2 deletions stat_tool/test/test_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
from openalea.stat_tool.data_transform import SelectVariable
from openalea.stat_tool.comparison import Compare, ComparisonTest

from tools import runTestClass
from tools import runTestClass, robust_path as get_shared_data

#from openalea.stat_tool import get_shared_data

from openalea.stat_tool import get_shared_data
class TestHisto():
"""a simple unittest class"""

Expand Down
11 changes: 6 additions & 5 deletions stat_tool/test/test_compound_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
"""
__version__ = "$Id$"

import os

from openalea.stat_tool import Compound, Histogram, Distribution

from openalea.stat_tool import Simulate, ExtractHistogram, ToHistogram
from openalea.stat_tool import Estimate, ExtractData, ExtractDistribution
from openalea.stat_tool import Plot, Shift
from openalea.stat_tool import shared_data_path
import os
from openalea.stat_tool import (
Simulate, ExtractHistogram, ToHistogram,
Estimate, ExtractData, ExtractDistribution,
Plot, Shift
)

# read data file
def test():
Expand Down
2 changes: 1 addition & 1 deletion stat_tool/test/test_convolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_extract_data(self):
eprime = Estimate(s, "CONVOLUTION", Binomial(0, 10, 0.5))

# todo: find robust assert ?
print eprime.get_mean
print(eprime.get_mean)

def test_truncate(self):
s = self.data
Expand Down
14 changes: 8 additions & 6 deletions stat_tool/test/test_data_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@

from openalea.stat_tool.vectors import Vectors
from openalea.stat_tool.histogram import Histogram
from openalea.stat_tool.distribution import Distribution, Uniform, Binomial, \
from openalea.stat_tool.distribution import (
Distribution, Uniform, Binomial,
NegativeBinomial
)
from openalea.stat_tool.mixture import Mixture
from openalea.stat_tool.convolution import Convolution
from openalea.stat_tool.simulate import Simulate
from openalea.stat_tool.compound import Compound
from openalea.stat_tool.output import Plot
from openalea.stat_tool.data_transform import Shift, Merge, Fit, ValueSelect, \
SelectVariable, SelectIndividual, MergeVariable, ExtractDistribution, \
from openalea.stat_tool.data_transform import (
Shift, Merge, Fit, ValueSelect,
SelectVariable, SelectIndividual, MergeVariable, ExtractDistribution,
ExtractHistogram, ExtractData, SelectStep
)

from tools import runTestClass

from openalea.stat_tool import get_shared_data
from tools import runTestClass, robust_path as get_shared_data

class data():
"""Create some common data sets for the classes
Expand Down
3 changes: 1 addition & 2 deletions stat_tool/test/test_distance_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
from openalea.stat_tool.cluster import Clustering, ToDistanceMatrix

from tools import interface
from tools import runTestClass
from openalea.stat_tool import get_shared_data
from tools import runTestClass, robust_path as get_shared_data

class Test(interface):

Expand Down
3 changes: 0 additions & 3 deletions stat_tool/test/test_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
__version__ = "$Id$"


from openalea.stat_tool import _stat_tool
from openalea.stat_tool.distribution import Distribution, Uniform, Binomial
from openalea.stat_tool.distribution import NegativeBinomial, Poisson
from openalea.stat_tool.distribution import Multinomial
from openalea.stat_tool.distribution import ToHistogram, ToDistribution
from openalea.stat_tool.histogram import Histogram
from openalea.stat_tool import Estimate



from openalea.stat_tool._stat_tool import _DiscreteParametricModel

from tools import interface
Expand Down
6 changes: 3 additions & 3 deletions stat_tool/test/test_distribution_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@


from openalea.stat_tool.plot import DISABLE_PLOT

DISABLE_PLOT = False

from openalea.stat_tool.data_transform import ExtractDistribution
from openalea.stat_tool.histogram import Histogram
Expand All @@ -49,7 +49,7 @@
from openalea.stat_tool.simulate import Simulate
from openalea.stat_tool.cluster import Cluster

from openalea.stat_tool import get_shared_data
from tools import robust_path as get_shared_data

plot.DISABLE_PLOT = DISABLE_PLOT

Expand Down Expand Up @@ -92,7 +92,7 @@ def test():
Plot(mixt2)
Plot(ExtractDistribution(mixt2, "Mixture"))

print type(ExtractDistribution(mixt2, "Component", 1))
print(type(ExtractDistribution(mixt2, "Component", 1)))


Plot(ExtractDistribution(mixt2, "Component", 1),
Expand Down
2 changes: 1 addition & 1 deletion stat_tool/test/test_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,4 @@ def test_class_error():
fe._error()
fe = FormatError(error="test")
fe._error()
print fe
print(fe)
4 changes: 1 addition & 3 deletions stat_tool/test/test_estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@

from openalea.stat_tool.estimate import Estimate, likelihood_penalty_type

from tools import runTestClass
from tools import runTestClass, robust_path as get_shared_data


from openalea.stat_tool import get_shared_data

class Test():

def __init__(self):
Expand Down
5 changes: 2 additions & 3 deletions stat_tool/test/test_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
from openalea.stat_tool.distribution import Distribution

from tools import interface
from tools import runTestClass
from tools import runTestClass, robust_path as get_shared_data

from openalea.stat_tool import get_shared_data

class Test(interface):
"""a simple unittest class
Expand Down Expand Up @@ -122,7 +121,7 @@ def test_extract_vec():
vs = stat_tool.Vectors("data/cvectors.vec")
h = vs.extract(4)
assert h
print h
print(h)


if __name__ == "__main__":
Expand Down
3 changes: 1 addition & 2 deletions stat_tool/test/test_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from openalea.stat_tool.comparison import Compare

from tools import interface
from tools import runTestClass
from openalea.stat_tool import get_shared_data
from tools import runTestClass, robust_path as get_shared_data

class Test(interface):
"""a simple unittest class for distance matrix"""
Expand Down
4 changes: 1 addition & 3 deletions stat_tool/test/test_mixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
from openalea.stat_tool.estimate import Estimate

from tools import interface
from tools import runTestClass

from openalea.stat_tool import get_shared_data
from tools import runTestClass, robust_path as get_shared_data

class Test(interface):
"""a simple unittest class"""
Expand Down
12 changes: 6 additions & 6 deletions stat_tool/test/test_multivariate_mixture_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test1():
d23 = Poisson(0, 0.2)

m = _MultivariateMixture([0.1, 0.2, 0.7], [[d11, d21], [d12, d22], [d13, d23]])
print m
print(m)

#m2 = _MultivariateMixture("mixture_mv1.mixt")
#print m2
Expand All @@ -34,22 +34,22 @@ def test1():
#m = _MultivariateMixture("mixture_mv_nonparam.mixt")
# print m

print "Simulation de melanges multivaries : "
print("Simulation de melanges multivaries : ")
v = m.simulate(5000)
print v
print(v)

Plot(m, variable=1, Title="Simulated mixture")

print "Estimation de melanges multivaries ", \
print("Estimation de melanges multivaries ")
# "d'apres un modele initial : "
m_estim_model = v.mixture_estimation(m, 100, [True, True])

extracted_mixture = m_estim_model.extract_mixture(1)
extracted_mixture.old_plot(variable=1, Title="Marginal distribution")
Plot(m_estim_model, variable = 1, Title="Estimated mixture")

print "Estimation de melanges multivaries ", \
"d'apres un nombre de composantes : "
print("Estimation de melanges multivaries ",
"d'apres un nombre de composantes : ")

m_estim_nbcomp = v.mixture_estimation(2, 100, [True, True])

Expand Down
3 changes: 1 addition & 2 deletions stat_tool/test/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
from openalea.stat_tool.output import Plot, Display
from openalea.stat_tool.plot import DISABLE_PLOT

from tools import runTestClass
from tools import runTestClass, robust_path as get_shared_data

from openalea.stat_tool import get_shared_data

class Test:
"""a simple unittest class"""
Expand Down
1 change: 1 addition & 0 deletions stat_tool/test/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from openalea.stat_tool import _stat_tool
from openalea.stat_tool.plot import get_plotter, gnuplot
from openalea.stat_tool.plot import DISABLE_PLOT
DISABLE_PLOT = True

from tools import runTestClass

Expand Down
3 changes: 1 addition & 2 deletions stat_tool/test/test_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
from openalea.stat_tool.enums import variance_type

from tools import interface
from tools import runTestClass
from tools import runTestClass, robust_path as get_shared_data

from openalea.stat_tool import get_shared_data

class Test(interface):
"""a simple unittest class
Expand Down
26 changes: 16 additions & 10 deletions stat_tool/test/test_vectors_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@
"""
__version__ = "$Id$"

from openalea.stat_tool.vectors import Vectors, \
VarianceAnalysis, ContingencyTable
from openalea.stat_tool.vectors import (
Vectors,
VarianceAnalysis,
ContingencyTable
)
from openalea.stat_tool.data_transform import ValueSelect
from openalea.stat_tool.regression import Regression
from openalea.stat_tool.data_transform import ExtractHistogram, \
SelectVariable, ExtractDistribution
from openalea.stat_tool.data_transform import (
ExtractHistogram,
SelectVariable,
ExtractDistribution
)
from openalea.stat_tool.comparison import Compare
from openalea.stat_tool.estimate import Estimate
from openalea.stat_tool.output import Display, Plot
Expand Down Expand Up @@ -72,22 +78,22 @@ def test():
Plot(ExtractHistogram(vec11, 5), ExtractHistogram(vec12, 5),
ExtractHistogram(vec13, 5))

mixt20 = Estimate(ExtractHistogram(vec10, 2), \
"MIXTURE", "NB", "NB", "NB", "NB", \
mixt20 = Estimate(ExtractHistogram(vec10, 2),
"MIXTURE", "NB", "NB", "NB", "NB",
NbComponent="Estimated")
Display(mixt20)

Plot(mixt20)
Plot(ExtractDistribution(mixt20, "Mixture"))

_mixt21 = Estimate(ExtractHistogram(vec10, 5), \
"MIXTURE", "NB", "NB", "NB", "NB", \
_mixt21 = Estimate(ExtractHistogram(vec10, 5),
"MIXTURE", "NB", "NB", "NB", "NB",
NbComponent="Estimated")

vec9596 = ValueSelect(vec10, 1, 1995, 1996)

Plot(ExtractHistogram(ValueSelect(vec9596, 4, 1), 6), \
ExtractHistogram(ValueSelect(vec9596, 4, 2), 6), \
Plot(ExtractHistogram(ValueSelect(vec9596, 4, 1), 6),
ExtractHistogram(ValueSelect(vec9596, 4, 2), 6),
ExtractHistogram(ValueSelect(vec9596, 4, 3, 4), 6))

# linear regression
Expand Down
19 changes: 18 additions & 1 deletion stat_tool/test/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
"""
__version__ = "$Id$"

import os


from openalea.stat_tool import Simulate
from openalea.stat_tool.plot import DISABLE_PLOT
import os
from openalea.stat_tool.output import Display, Save
DISABLE_PLOT=True

from pathlib import Path
from openalea.stat_tool import get_shared_data, get_shared_data_path
import openalea.stat_tool as st

def runTestClass(myclass):
functions = [x for x in dir(myclass) if x.startswith('test')]
Expand Down Expand Up @@ -205,3 +210,15 @@ def test_extract(self):
def test_extract_data(self):
raise NotImplementedError()


def robust_path(filename):
p = get_shared_data_path(st)
if p is not None:
# module in develop mode?
return get_shared_data(filename)

p = Path(st.__path__[0])
if 'src' in str(p):
root_pkg = p/'../../..'
data = get_shared_data_path(root_pkg)
return os.path.join(data,filename)

0 comments on commit 2e9d075

Please sign in to comment.