diff --git a/.gitignore b/.gitignore index 41c1214a..e8dfdac0 100644 --- a/.gitignore +++ b/.gitignore @@ -89,4 +89,4 @@ site/ out # Sphinx -_static +#_static diff --git a/README.md b/README.md index 8d4f6fd0..c02082cd 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,21 @@ # stat_tool -_________________ +--- [![Docs](https://readthedocs.org/projects/stat_tool/badge/?version=latest)](https://stat_tool.readthedocs.io/) [![Build Status](https://github.com/openalea/stat_tool/actions/workflows/conda-package-build.yml/badge.svg?branch=main)](https://github.com/openalea/stat_tool/actions/workflows/conda-package-build.yml?query=branch%3Amaster) [![License](https://img.shields.io/badge/License--CeCILL-C-blue)](https://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html) [![Anaconda-Server Badge](https://anaconda.org/openalea3/stat_tool/badges/version.svg)](https://anaconda.org/openalea3/stat_tool) -_________________ +--- [Read Latest Documentation](https://stat_tool.readthedocs.io/) - [Browse GitHub Code Repository](https://github.com/openalea/stat_tool/) -_________________ +--- **stat_tool** Basic Statistical tools used by different Structure Analysis libraries. -### Contributors +## Contributors Thanks to all that ontribute making this package what it is ! @@ -23,20 +23,19 @@ Thanks to all that ontribute making this package what it is ! -### Note for developers - * Compile and install with +## Note for developers - pip install -e . +- Compile and install with + + pip install -e . after activation of the conda environment depicted in the online documentation. - * Comilation options for developers such are WITH_TEST, WITH_EFENCE are defined in pyproject.toml. They can be used with + * Compilation options for developers such as WITH_TEST, WITH_EFENCE are defined in pyproject.toml. They can be used with - pip install --no-build-isolation --config-settings=cmake.define.WITH_TEST=TRUE -e . - pip install --no-build-isolation --config-settings=cmake.build-type="Debug" -e . + pip install --no-build-isolation --config-settings=cmake.define.WITH_TEST=TRUE -e . + pip install --no-build-isolation --config-settings=cmake.build-type="Debug" -e . and also combined: pip install --no-build-isolation --config-settings=cmake.define.WITH_TEST=TRUE --config-settings=cmake.define.WITH_EFENCE=TRUE --config-settings=cmake.build-type="Debug" -e . - - diff --git a/doc/Doxyfile b/doc/Doxyfile index 7a1ee5d4..30d94c84 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -1779,7 +1779,7 @@ MAN_LINKS = NO # captures the structure of the code including all documentation. # The default value is: NO. -GENERATE_XML = NO +GENERATE_XML = YES # The XML_OUTPUT tag is used to specify where the XML pages will be put. If a # relative path is entered the value of OUTPUT_DIRECTORY will be put in front of diff --git a/doc/_static/openalea_web.svg b/doc/_static/openalea_web.svg new file mode 100644 index 00000000..1e3527c9 --- /dev/null +++ b/doc/_static/openalea_web.svg @@ -0,0 +1,108 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + OpenAlea + + + diff --git a/doc/api.md b/doc/api.md deleted file mode 100644 index e1a4b56f..00000000 --- a/doc/api.md +++ /dev/null @@ -1,8 +0,0 @@ -# API reference - -```{toctree} -:maxdepth: 2 -:hidden: - - -``` diff --git a/doc/api.rst b/doc/api.rst new file mode 100644 index 00000000..a65b84ff --- /dev/null +++ b/doc/api.rst @@ -0,0 +1,27 @@ +C++ Documentation +################# + +.. toctree + :maxdepth: 2 + + + .. doxygenclass:: stat_tool:: + :project: stat_tool + :members: + + .. autodoxygenindex:: + :project: stat_tool + + .. doxygennamespace:: stat_tool::Clusters + + .. doxygennamespace:: stat_tool + +.. contents:: + :local: + :depth: 2 + +.. doxygenindex:: + + + + diff --git a/doc/api/classes.rst b/doc/api/classes.rst new file mode 100644 index 00000000..e65c9cd3 --- /dev/null +++ b/doc/api/classes.rst @@ -0,0 +1,77 @@ +Classes +------- + +.. doxygenclass:: stat_tool::CategoricalProcess + :members: +.. doxygenclass:: stat_tool::Chain + :members: +.. doxygenclass:: stat_tool::ChainData + :members: +.. doxygenclass:: stat_tool::ChainReestimation + :members: +.. doxygenclass:: stat_tool::Clusters + :members: +.. doxygenclass:: stat_tool::Compound + :members: +.. doxygenclass:: stat_tool::CompoundData + :members: +.. doxygenclass:: ContinousParametric + :members: +.. doxygenclass:: ContinousParametricProcess + :members: +.. doxygenclass:: stat_tool::Convolution + :members: +.. doxygenclass:: stat_tool::ConvolutionData + :members: +.. doxygenclass:: stat_tool::Curves + :members: +.. doxygenclass:: stat_tool::Dendrogram + :members: +.. doxygenclass:: stat_tool::DiscreteDistributionData + :members: +.. doxygenclass:: stat_tool::DiscreteMixture + :members: +.. doxygenclass:: stat_tool::DiscreteMixtureData + :members: +.. doxygenclass:: stat_tool::DiscreteParametric + :members: +.. doxygenclass:: stat_tool::DiscreteParametricModel + :members: +.. doxygenclass:: stat_tool::DiscreteParametricProcess + :members: +.. doxygenclass:: stat_tool::DistanceMatrix + :members: +.. doxygenclass:: stat_tool::Distribution + :members: +.. doxygenclass:: stat_tool::Forward + :members: +.. doxygenclass:: stat_tool::FrequencyDistribution + :members: +.. doxygenclass:: stat_tool::Histogram + :members: +.. doxygenclass:: stat_tool::MultiPlot + :members: +.. doxygenclass:: stat_tool::MultivariateMixture + :members: +.. doxygenclass:: stat_tool::MultivariateMixtureData + :members: +.. doxygenclass:: stat_tool::Reestimation + :members: +.. doxygenclass:: stat_tool::Regression + :members: +.. doxygenclass:: stat_tool::RegressionKernel + :members: +.. doxygenclass:: stat_tool::SinglePlot + :members: +.. doxygenclass:: stat_tool::StatError + :members: +.. doxygenclass:: stat_tool::StatInterface + :members: +.. doxygenclass:: stat_tool::TemplateMultiPlotSet + :members: +.. doxygenclass:: stat_tool::Test + :members: +.. doxygenclass:: stat_tool::VectorDistance + :members: +.. doxygenclass:: stat_tool::Vectors + :members: diff --git a/doc/api/constants.rst b/doc/api/constants.rst new file mode 100644 index 00000000..348e5e20 --- /dev/null +++ b/doc/api/constants.rst @@ -0,0 +1,149 @@ +Constants +--------- + +.. doxygenvariable:: COMPOUND_THRESHOLD +.. doxygenvariable:: COMPOUND_INIT_PROBABILITY +.. doxygenvariable:: COMPOUND_LIKELIHOOD_DIFF +.. doxygenvariable:: COMPOUND_NB_ITER +.. doxygenvariable:: COMPOUND_DIFFERENCE_WEIGHT +.. doxygenvariable:: COMPOUND_ENTROPY_WEIGHT +.. doxygenvariable:: COMPOUND_COEFF +.. doxygenvariable:: bilateral_tail +.. doxygenvariable:: posterior_threshold +.. doxygenvariable:: CONVOLUTION_NB_DISTRIBUTION +.. doxygenvariable:: CONVOLUTION_THRESHOLD +.. doxygenvariable:: CONVOLUTION_INIT_PROBABILITY +.. doxygenvariable:: CONVOLUTION_LIKELIHOOD_DIFF +.. doxygenvariable:: CONVOLUTION_NB_ITER +.. doxygenvariable:: CONVOLUTION_DIFFERENCE_WEIGHT +.. doxygenvariable:: CONVOLUTION_ENTROPY_WEIGHT +.. doxygenvariable:: CONVOLUTION_COEFF +.. doxygenvariable:: MAX_FREQUENCY +.. doxygenvariable:: MAX_RANGE +.. doxygenvariable:: PLOT_NB_CURVE +.. doxygenvariable:: PLOT_MIN_FREQUENCY +.. doxygenvariable:: DISCRETE_MIXTURE_NB_COMPONENT +.. doxygenvariable:: NEGATIVE_BINOMIAL_PARAMETER +.. doxygenvariable:: MIN_WEIGHT_STEP +.. doxygenvariable:: MAX_WEIGHT_STEP +.. doxygenvariable:: DISCRETE_MIXTURE_COEFF +.. doxygenvariable:: DISCRETE_MIXTURE_LIKELIHOOD_DIFF +.. doxygenvariable:: DISCRETE_MIXTURE_NB_ITER +.. doxygenvariable:: ASCII_NB_INDIVIDUAL +.. doxygenvariable:: PLOT_YMARGIN +.. doxygenvariable:: DISTANCE_ROUNDNESS +.. doxygenvariable:: GLOBAL_NB_ITER +.. doxygenvariable:: PARTITIONING_NB_ITER_1 +.. doxygenvariable:: PARTITIONING_NB_ITER_2 +.. doxygenvariable:: NB_STATE +.. doxygenvariable:: ORDER +.. doxygenvariable:: MIN_PROBABILITY +.. doxygenvariable:: THRESHOLDING_FACTOR +.. doxygenvariable:: NB_PARAMETER +.. doxygenvariable:: NB_OUTPUT_PROCESS +.. doxygenvariable:: NB_OUTPUT +.. doxygenvariable:: OBSERVATION_THRESHOLD +.. doxygenvariable:: ACCESSIBILITY_THRESHOLD +.. doxygenvariable:: ACCESSIBILITY_LENGTH +.. doxygenvariable:: NOISE_PROBABILITY +.. doxygenvariable:: MEAN_SHIFT_COEFF +.. doxygenvariable:: MIN_NB_ELEMENT +.. doxygenvariable:: OBSERVATION_COEFF +.. doxygenvariable:: GAMMA_MAX_NB_DECIMAL +.. doxygenvariable:: INVERSE_GAUSSIAN_MAX_NB_DECIMAL +.. doxygenvariable:: GAUSSIAN_MAX_NB_DECIMAL +.. doxygenvariable:: DEGREE_DECIMAL_SCALE +.. doxygenvariable:: RADIAN_DECIMAL_SCALE +.. doxygenvariable:: MVMIXTURE_LIKELIHOOD_DIFF +.. doxygenvariable:: MIXTURE_COEFF +.. doxygenvariable:: CUMUL_THRESHOLD +.. doxygenvariable:: BISECTION_RATIO_THRESHOLD +.. doxygenvariable:: BISECTION_NB_ITER +.. doxygenvariable:: REGRESSION_NB_VECTOR +.. doxygenvariable:: NEIGHBORHOOD +.. doxygenvariable:: ERROR_LENGTH +.. doxygenvariable:: I_DEFAULT +.. doxygenvariable:: D_DEFAULT +.. doxygenvariable:: D_INF +.. doxygenvariable:: DOUBLE_ERROR +.. doxygenvariable:: NB_CRITICAL_PROBABILITY +.. doxygenvariable:: ref_critical_probability +.. doxygenvariable:: NB_VALUE +.. doxygenvariable:: SAMPLE_NB_VALUE +.. doxygenvariable:: MAX_INF_BOUND +.. doxygenvariable:: MAX_DIFF_BOUND +.. doxygenvariable:: MAX_MEAN +.. doxygenvariable:: MAX_SEQUENCE_LENGTH +.. doxygenvariable:: B_PROBABILITY +.. doxygenvariable:: B_THRESHOLD +.. doxygenvariable:: P_THRESHOLD +.. doxygenvariable:: NB_THRESHOLD +.. doxygenvariable:: SAMPLE_NB_VALUE_COEFF +.. doxygenvariable:: INF_BOUND_MARGIN +.. doxygenvariable:: SUP_BOUND_MARGIN +.. doxygenvariable:: POISSON_RATIO +.. doxygenvariable:: POISSON_RANGE +.. doxygenvariable:: NB_VALUE_COEFF +.. doxygenvariable:: MIN_RANGE +.. doxygenvariable:: MAX_SURFACE +.. doxygenvariable:: DIST_NB_ELEMENT +.. doxygenvariable:: NB_COMPLETE_INTERVAL +.. doxygenvariable:: RENEWAL_LIKELIHOOD_DIFF +.. doxygenvariable:: RENEWAL_NB_ITER +.. doxygenvariable:: RENEWAL_DIFFERENCE_WEIGHT +.. doxygenvariable:: RENEWAL_ENTROPY_WEIGHT +.. doxygenvariable:: MAX_VALUE_COEFF +.. doxygenvariable:: CONTINUOUS_POSITIVE_INF_BOUND +.. doxygenvariable:: GAMMA_TAIL +.. doxygenvariable:: GAMMA_NB_STEP +.. doxygenvariable:: GAMMA_NB_SUB_STEP +.. doxygenvariable:: GAMMA_INVERSE_SAMPLE_SIZE_FACTOR +.. doxygenvariable:: GAMMA_MIN_SHAPE_PARAMETER +.. doxygenvariable:: GAMMA_DEFAULT_SCALE_PARAMETER +.. doxygenvariable:: GAMMA_ZERO_FREQUENCY_THRESHOLD +.. doxygenvariable:: GAMMA_SHAPE_PARAMETER_THRESHOLD +.. doxygenvariable:: GAMMA_FREQUENCY_THRESHOLD +.. doxygenvariable:: GAMMA_ITERATION_FACTOR +.. doxygenvariable:: GAMMA_MAX_NB_ITERATION +.. doxygenvariable:: INVERSE_GAUSSIAN_TAIL +.. doxygenvariable:: INVERSE_GAUSSIAN_NB_STEP +.. doxygenvariable:: INVERSE_GAUSSIAN_NB_SUB_STEP +.. doxygenvariable:: GAUSSIAN_TAIL +.. doxygenvariable:: GAUSSIAN_NB_STEP +.. doxygenvariable:: GAUSSIAN_NB_SUB_STEP +.. doxygenvariable:: GAUSSIAN_MIN_VARIATION_COEFF +.. doxygenvariable:: VON_MISES_NB_STEP +.. doxygenvariable:: VON_MISES_NB_SUB_STEP +.. doxygenvariable:: CHI2_FREQUENCY +.. doxygenvariable:: MARGINAL_DISTRIBUTION_MAX_VALUE +.. doxygenvariable:: HISTOGRAM_FREQUENCY +.. doxygenvariable:: SKEWNESS_ROUNDNESS +.. doxygenvariable:: NB_ERROR +.. doxygenvariable:: LINE_NB_CHARACTER +.. doxygenvariable:: ASCII_NB_VALUE +.. doxygenvariable:: ASCII_SPACE +.. doxygenvariable:: ASCII_ROUNDNESS +.. doxygenvariable:: SPREADSHEET_ROUNDNESS +.. doxygenvariable:: DISPLAY_NB_INDIVIDUAL +.. doxygenvariable:: PLOT_NB_DISTRIBUTION +.. doxygenvariable:: PLOT_NB_HISTOGRAM +.. doxygenvariable:: PLOT_ROUNDNESS +.. doxygenvariable:: PLOT_SHIFT +.. doxygenvariable:: PLOT_MAX_SHIFT +.. doxygenvariable:: TIC_THRESHOLD +.. doxygenvariable:: PLOT_MASS_THRESHOLD +.. doxygenvariable:: YSCALE +.. doxygenvariable:: PLOT_RANGE_RATIO +.. doxygenvariable:: CRITICAL_PROBABILITY_FACTOR +.. doxygenvariable:: VECTOR_NB_VARIABLE +.. doxygenvariable:: DISTANCE_NB_VECTOR +.. doxygenvariable:: SUP_NORM_DISTANCE_NB_VECTOR +.. doxygenvariable:: CONTINGENCY_NB_VALUE +.. doxygenvariable:: DISPLAY_CONTINGENCY_NB_VALUE +.. doxygenvariable:: VARIANCE_ANALYSIS_NB_VALUE +.. doxygenvariable:: DISPLAY_CONDITIONAL_NB_VALUE +.. doxygenvariable:: PLOT_NB_VALUE +.. doxygenvariable:: NB_CATEGORY +.. doxygenvariable:: MIN_NB_ASSIGNMENT +.. doxygenvariable:: MAX_NB_ASSIGNMENT +.. doxygenvariable:: NB_ASSIGNMENT_PARAMETER diff --git a/doc/api/enums.rst b/doc/api/enums.rst new file mode 100644 index 00000000..9bbe0baf --- /dev/null +++ b/doc/api/enums.rst @@ -0,0 +1,48 @@ +Enums +----- + +.. doxygenenum:: curve_transformation +.. doxygenenum:: matrix_transform +.. doxygenenum:: hierarchical_strategy +.. doxygenenum:: linkage +.. doxygenenum:: cluster_scale +.. doxygenenum:: isolation_scale +.. doxygenenum:: state_type +.. doxygenenum:: model_type +.. doxygenenum:: observation_process +.. doxygenenum:: count_pattern +.. doxygenenum:: latent_structure_algorithm +.. doxygenenum:: process_distribution +.. doxygenenum:: penalty_type +.. doxygenenum:: side_effect +.. doxygenenum:: parametric_function +.. doxygenenum:: stat_tool_keyword +.. doxygenenum:: stat_tool_label +.. doxygenenum:: stat_tool_parsing +.. doxygenenum:: stat_tool_error +.. doxygenenum:: output_format +.. doxygenenum:: test_distribution +.. doxygenenum:: frequency_distribution_transformation +.. doxygenenum:: rounding +.. doxygenenum:: discrete_parametric +.. doxygenenum:: distribution_transformation +.. doxygenenum:: distribution_computation +.. doxygenenum:: continuous_parametric +.. doxygenenum:: angle_unit +.. doxygenenum:: compound_distribution +.. doxygenenum:: variable_type +.. doxygenenum:: log_base +.. doxygenenum:: process_type +.. doxygenenum:: estimation_criterion +.. doxygenenum:: duration_distribution_mean_estimator +.. doxygenenum:: censoring_estimator +.. doxygenenum:: model_selection_criterion +.. doxygenenum:: error_type +.. doxygenenum:: variable_nature +.. doxygenenum:: vector_transformation +.. doxygenenum:: threshold_direction +.. doxygenenum:: correlation_type +.. doxygenenum:: metric +.. doxygenenum:: tying_rule +.. doxygenenum:: moving_average_method + diff --git a/doc/api/functions.rst b/doc/api/functions.rst new file mode 100644 index 00000000..a84f0de5 --- /dev/null +++ b/doc/api/functions.rst @@ -0,0 +1,33 @@ +Functions +========= + +.. doxygenfunction:: cumul_computation(int nb_value, const double *pmass, double *pcumul) +.. doxygenfunction:: cumul_distance_computation(int dim, double *distance) +.. doxygenfunction:: pattern_sort(int nb_pattern, double *distance, int nb_sorted_pattern) +.. doxygenfunction:: von_mises_concentration_computation +.. doxygenfunction:: q_q_plot_computation(double min_value, double step, int nb_step, double *theoretical_cdf, int nb_value, double **empirical_cdf) +.. doxygenfunction:: q_q_plot_computation(int nb_value, double **cdf) const +.. doxygenfunction:: q_q_plot_print(const char *path, int nb_value, double **qqplot) +.. doxygenfunction:: q_q_plotable_write(SinglePlot &plot, int nb_value, double **qqplot) +.. doxygenfunction:: cumul_matching_plot_print +.. doxygenfunction:: set_seed +.. doxygenfunction:: column_width(double min_value, double max_value) +.. doxygenfunction:: column_width(int min_value, int max_value) +.. doxygenfunction:: column_width(int nb_value, const double *value, double scale) +.. doxygenfunction:: column_width(int value) +.. doxygenfunction:: plot_print(const char *path) +.. doxygenfunction:: plot_print(const char *path) const +.. doxygenfunction:: plot_print(const char *path, const FrequencyDistribution *histo = NULL) const +.. doxygenfunction:: plot_print(const char *path, const Histogram *histo1 = NULL, const FrequencyDistribution *histo2 = NULL) +.. doxygenfunction:: plot_print(const char *path, double *concentration, double scale) const +.. doxygenfunction:: plot_print(const char *path, double *cumul, double *concentration, double shift = 0.) const +.. doxygenfunction:: plot_print(const char *path, double *standard_residual = NULL) const +.. doxygenfunction:: plot_print(const char *path, int ilength = I_DEFAULT, const Curves *curves_0 = NULL, const Curves *curves_1 = NULL) const +.. doxygenfunction:: plot_print(const char *path, int nb_dist, const Distribution **dist, double *scale, int *dist_nb_value, int nb_histo, const FrequencyDistribution **histo) +.. doxygenfunction:: plot_print(const char *path, int nb_dist, const Distribution **dist, double *scale, int *dist_nb_value, int nb_histo, const FrequencyDistribution **histo) +.. doxygenfunction:: plot_print(const char *path, int nb_histo = 0, const FrequencyDistribution **histo = NULL) const +.. doxygenfunction:: plot_print(const char *prefix, const char *title, int process, FrequencyDistribution **empirical_observation = NULL, FrequencyDistribution *marginal_distribution = NULL, model_type model = HIDDEN_MARKOV) const +.. doxygenfunction:: plot_print(const char *prefix, const char *title, int process, FrequencyDistribution **empirical_observation = NULL, FrequencyDistribution *marginal_distribution = NULL, model_type model = HIDDEN_MARKOV) const +.. doxygenfunction:: plot_print(const char *prefix, const char *title, int process, Histogram **observation_histogram = NULL, FrequencyDistribution **observation_distribution = NULL, Histogram *marginal_histogram = NULL, FrequencyDistribution *marginal_distribution = NULL, int nb_value = I_DEFAULT, double **empirical_cdf = NULL, model_type model = HIDDEN_MARKOV) const +.. doxygenfunction:: log_computation(int nb_value, const double *pmass, double *plog) +.. doxygenfunction:: cumul_method diff --git a/doc/api/index.rst b/doc/api/index.rst new file mode 100644 index 00000000..722766b7 --- /dev/null +++ b/doc/api/index.rst @@ -0,0 +1,24 @@ +API Reference +============= + +.. toctree:: + :maxdepth: 4 + + ../user/list.rst + python + + +.. toctree:: + :maxdepth: 4 + :hidden: + :caption: C++ API: + + classes + enums + constants + + + + .. functions + .. doxygenindex:: + diff --git a/doc/api/python.rst b/doc/api/python.rst new file mode 100644 index 00000000..8fc697fb --- /dev/null +++ b/doc/api/python.rst @@ -0,0 +1,7 @@ +Python API +---------- + +.. toctree:: + :maxdepth: 2 + + ../user/autosum.rst diff --git a/doc/conf.py b/doc/conf.py index 67f5d0d6..30e06695 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -3,13 +3,13 @@ import sys from importlib.metadata import metadata -pkg_name='stat_tool' -meta = metadata('openalea.' + pkg_name) +pkg_name = "stat_tool" +meta = metadata("openalea." + pkg_name) release = meta.get("version") # for example take major/minor -version = ".".join(release.split('.')[:3]) -author = meta['Author'].split(',')[0] + "et al." -desc = meta['Summary'] +version = ".".join(release.split(".")[:3]) +author = meta["Author"].split(",")[0] + "et al." +desc = meta["Summary"] # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the @@ -35,11 +35,13 @@ "sphinx_favicon", # support for favicon "nbsphinx", # for integrating jupyter notebooks "myst_parser", # for parsing .md files + "matplotlib.sphinxext.plot_directive", + "breathe", ] nbsphinx_thumbnails = { - 'examples/Segmentation': '_static/segmentation_thumb.png', + "examples/Segmentation": "_static/segmentation_thumb.png", } nbsphinx_allow_errors = True @@ -53,6 +55,10 @@ ".rst": "restructuredtext", ".md": "markdown", } + +breathe_projects = {"stat_tool": "xml"} +breathe_default_project = "stat_tool" + # The master toctree document. master_doc = "index" # General information about the project. @@ -155,3 +161,6 @@ ] # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = {"python": ("https://docs.python.org/", None)} + +breathe_projects = {'stat_tool': 'xml'} +breathe_default_project = 'stat_tool' diff --git a/doc/examples/example1.ipynb b/doc/examples/example1.ipynb deleted file mode 100644 index 65552dee..00000000 --- a/doc/examples/example1.ipynb +++ /dev/null @@ -1,33 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "2c12aee5", - "metadata": {}, - "source": [ - "# Basic usage of stat_tool" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.13.9" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/doc/examples/example2.ipynb b/doc/examples/example2.ipynb deleted file mode 100644 index 99f4f63f..00000000 --- a/doc/examples/example2.ipynb +++ /dev/null @@ -1,39 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "d6f2043d", - "metadata": {}, - "source": [ - "# Advanced usage of stat_tool" - ] - }, - { - "cell_type": "markdown", - "id": "ee85c79f", - "metadata": {}, - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.13.9" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/doc/extra.md b/doc/extra.md index ea0a4bac..91e6c8a7 100644 --- a/doc/extra.md +++ b/doc/extra.md @@ -1,8 +1,7 @@ # Additional resources for stat_tool ```{include} ../CONTRIBUTING.md - :start-after: - :end-before + ``` ```{include} ../AUTHORS.md diff --git a/doc/index.md b/doc/index.md index 803e0d39..03270afc 100644 --- a/doc/index.md +++ b/doc/index.md @@ -8,11 +8,12 @@ Home Install -Getting started +User guide Usage -API Reference +API Reference More ``` ```{include} ../README.md + ``` diff --git a/doc/usage.md b/doc/usage.md index 2f934ea1..8c97d444 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -1,6 +1,6 @@ # Usage + ```{nbgallery} -examples/example1.ipynb -examples/example2.ipynb -``` +examples/clustering.ipynb + diff --git a/doc/user/index.rst b/doc/user/index.rst index 8b614201..2e5f1741 100644 --- a/doc/user/index.rst +++ b/doc/user/index.rst @@ -36,13 +36,3 @@ tutorials and examples aml2py.rst troubleshooting.rst - -VisuAlea dataflow -=================== - -.. toctree:: - :maxdepth: 1 - - - visualea_oak_demo.rst - visualea_beech1.rst diff --git a/doc/user/tutorial.rst b/doc/user/tutorial.rst index 9c5bcfd3..4a9141e2 100644 --- a/doc/user/tutorial.rst +++ b/doc/user/tutorial.rst @@ -47,7 +47,7 @@ be sufficient to allow you to declare and manipulate other objects such as .. just to prevent annoying warnings -.. htmlonly:: +.. only:: html .. toctree:: :hidden: diff --git a/doc/user/visualea_beech1.rst b/doc/user/visualea_beech1.rst deleted file mode 100644 index 55c44fbe..00000000 --- a/doc/user/visualea_beech1.rst +++ /dev/null @@ -1,19 +0,0 @@ -Beech demo -=========== -.. sectionauthor:: Thomas Cokelaer - -.. dataflow:: Demo.ChangePoint_stat_tool beech1 - :width: 50% - - test - - - -.. plot:: - :width: 40% - - from openalea.core.alea import * - pm = PackageManager() - run_and_display(('Demo.ChangePoint_stat_tool', 'beech1'),{},pm=pm) - - diff --git a/doc/user/visualea_oak_demo.rst b/doc/user/visualea_oak_demo.rst deleted file mode 100644 index 404abdbf..00000000 --- a/doc/user/visualea_oak_demo.rst +++ /dev/null @@ -1,20 +0,0 @@ -OAK demo -========= - -.. sectionauthor:: Thomas Cokelaer - - -.. dataflow:: Demo.ChangePoint_stat_tool oak_demo - :width: 50% - - test - - -.. plot:: - :width: 40% - - from openalea.core.alea import * - pm = PackageManager() - run_and_display(('Demo.ChangePoint_stat_tool', 'oak_demo'),{},pm=pm) - - diff --git a/pyproject.toml b/pyproject.toml index b2a7853d..54752332 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -82,6 +82,8 @@ doc = [ "sphinx-copybutton", "ipython_genutils", "nbsphinx", + "breathe", + "doxygen" ] # section specific to conda-only distributed package (not used by pip yet) diff --git a/src/openalea/stat_tool/output.py b/src/openalea/stat_tool/output.py index 769da88a..b50e10a0 100644 --- a/src/openalea/stat_tool/output.py +++ b/src/openalea/stat_tool/output.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding: utf-8 -*- +# -*- coding: utf-8 -*- """Output functions .. topic:: output.py summary @@ -15,45 +15,49 @@ :Revision: $Id$ """ + __version__ = "$Id$" -import os import glob +import os import sys + from . import ( - plot, error, + plot, ) # Output functions from ._stat_tool import ( - FORWARD_DYNAMIC_PROGRAMMING, - FORWARD_BACKWARD_SAMPLING, GENERALIZED_VITERBI, FORWARD_BACKWARD_SAMPLING, + FORWARD_DYNAMIC_PROGRAMMING, + GENERALIZED_VITERBI, ) try: from openalea.sequence_analysis.enums_seq import ( - NB_STATE_SEQUENCE, NB_SEGMENTATION, -) + NB_STATE_SEQUENCE, + ) except: NB_SEGMENTATION = 10 NB_STATE_SEQUENCE = 10 + def add_doc(function): """a simple decorator to replace f's docstring by a new one The new one is the docstring of the function's name capitalized. E.g: if function's name is display, then - display.__doc__ = Display.__doc__ + >>> display.__doc__ = Display.__doc__ """ name = function.__name__ function.__doc__ = eval(name.capitalize()).__doc__ return function + def Display(obj, *args, **kargs): """ASCII output of an object of the STAT module @@ -134,30 +138,29 @@ def Display(obj, *args, **kargs): return obj.display(*args, **kargs) - def Plot(obj, *args, **kargs): """ Graphical output of an object of the STAT module using the GNUPLOT software. In the case of Markovian models or sequences, the graphical outputs are grouped as follows: - * "SelfTransition": add outgoing server thunderbirdself-transition probability as a function of the + - "SelfTransition": add outgoing server thunderbirdself-transition probability as a function of the index parameter (non-homogeneous Markov chain), - * "Observation": observation distributions attached to each state of the + - "Observation": observation distributions attached to each state of the underlying (semi-)Markov chain (lumped processes or hidden Markovian processes), - * "Intensity": (empirical) probabilities of states/outputs as a function + - "Intensity": (empirical) probabilities of states/outputs as a function of the index parameter, - * "FirstOccurrence": (frequency) distributions of the time-up to the first + - "FirstOccurrence": (frequency) distributions of the time-up to the first occurrence of a state/output (or first-passage time in a state/output distributions), - * "Recurrence" (frequency) distributions of the recurrence time in a + - "Recurrence" (frequency) distributions of the recurrence time in a state/output, - * "Sojourn": (frequency) distributions of the sojourn time in a + - "Sojourn": (frequency) distributions of the sojourn time in a state/output (or state/output occupancy distributions). For the frequency distributions extracted from sequences, the sojourn times in the last visited states which are considered as censored are isolated. - * "Counting": counting (frequency) distributions (either distributions of + - "Counting": counting (frequency) distributions (either distributions of the number of runs (or clumps) of a state/output per sequence or distributions of the number of occurrences of a state/output per sequence). @@ -170,38 +173,40 @@ def Plot(obj, *args, **kargs): a function of the index parameter t computed from the parameters of a hidden Markovian model for the sequence (ViewPoint="StateProfile"). - :Parameters: - * obj1 (`_Distribution`, `_Mixture`, `_Convolution`, `_Compound`, + Parameters + ---------- + obj1: (`_Distribution`, `_Mixture`, `_Convolution`, `_Compound`, `_DiscreteDistributionData`, `_DiscreteMixtureData`, `_ConvolutionData`, `_CompoundData`,`_Renewal`, `_TimeEvents`, `_RenewalData`, `_Sequences`, `_DistanceMatrix`, ` _TopParameters`, `_Tops`), - * vec1 (`_Vectors`): values, - * vecn (`_Vectors`): vectors, - * variable (int): variable index, - * obj2: (`_Markov`, `_SemiMarkov`, `_HiddenMarkov`, `_HiddenSemiMarkov`, + vec1: (`_Vectors`) values, + vecn: (`_Vectors`) vectors, + variable: (int) variable index, + obj2: (`_Markov`, `_SemiMarkov`, `_HiddenMarkov`, `_HiddenSemiMarkov`, `_DiscreteSequences`, `_MarkovData`, `_SemiMarkovData`): Markovian model for discrete univariate sequences or discrete univariate sequences, - * obj3: (`_Markov`, `_SemiMarkov`, `_HiddenMarkov`, `_HiddenSemiMarkov`, + obj3: (`_Markov`, `_SemiMarkov`, `_HiddenMarkov`, `_HiddenSemiMarkov`, `_DiscreteSequences`, `_MarkovData`, `_SemiMarkovData`): Markovian model for discrete multivariate sequences or discrete multivariate sequences, - * type (string): type of graphical outputs in the case of Markovian models + type (string): type of graphical outputs in the case of Markovian models or sequences: "SelfTransition", "Observation", "Intensity", "FirstOccurrence", "Recurrence", "Sojourn" or "Counting", - * dist1, dist2, ... (`_Distribution`, `_Mixture`, `_Convolution`, `_Compound`), - * histo1, histo2, ... (`_DiscreteDistributionData`, `_DiscreteMixtureData`, `_ConvolutionData`, + dist1, dist2, ...: (`_Distribution`, `_Mixture`, `_Convolution`, `_Compound`), + histo1, histo2, ...: (`_DiscreteDistributionData`, `_DiscreteMixtureData`, `_ConvolutionData`, `_CompoundData`), - * seq (`_Sequences`, `_DiscreteSequences`, `_MarkovData`, `_SemiMarkovData`, + seq: (`_Sequences`, `_DiscreteSequences`, `_MarkovData`, `_SemiMarkovData`, `_Tops`), - * dist (`_Distribution`, `_Mixture`, `_Convolution`, `_Compound`), - * histo (`_DiscreteDistributionData`, `_DiscreteMixtureData`, `_ConvolutionData`, + dist: (`_Distribution`, `_Mixture`, `_Convolution`, `_Compound`), + histo: (`_DiscreteDistributionData`, `_DiscreteMixtureData`, `_ConvolutionData`, `_CompoundData`), - * hmc (_HiddenMarkov), - * hsmc (_HiddenSemiMarkov), - * identifier (int): identifier of a sequence. + hmc: (_HiddenMarkov), + hsmc: (_HiddenSemiMarkov), + identifier: (int) identifier of a sequence. - :Keywords: + Keywords + -------- - * ViewPoint (string): point of view on the object ("Data" or "Survival" + ViewPoint: (string) point of view on the object ("Data" or "Survival" or "StateProfile"). This optional argument can be set at : * "Data" only if the first mandatory argument is of type sequences, discrete_sequences, markov_data, semi-markov_data or tops, @@ -210,8 +215,10 @@ def Plot(obj, *args, **kargs): convolution_data or compound_data * "StateProfile" only if the first mandatory argument is of type hidden_markov or hidden_semi-markov. - * Title (string): graphic title (the default: no title). - * nbcol (int): number of columns in the output figure + Title: (string) + graphic title (the default: no title). + nbcol: (int) + number of columns in the output figure * Show: * legend_size: 10 * legend_nbcol: 2 @@ -219,10 +226,12 @@ def Plot(obj, *args, **kargs): * legend: True/False - :Returns: + Returns + ------- Nothing. - :Examples: + Examples + -------- .. doctest:: :options: +SKIP @@ -243,14 +252,15 @@ def Plot(obj, *args, **kargs): >>> Plot(histo, ViewPoint="Survival", Title="Survival rates") >>> Plot(hsmc, identifier, ViewPoint="StateProfile", Title="Smoothed probabilities") - .. seealso:: - :func:`~openalea.stat_tool.output.Display`, - :func:`~openalea.stat_tool.output.Save`. + See Also + -------- + :func:`~openalea.stat_tool.output.Display`, + :func:`~openalea.stat_tool.output.Save`. """ - return obj.plot(*args, **kargs) + def Save(obj, *args, **kargs): """ Saving of an object of the STAT module in a file. @@ -274,21 +284,24 @@ def Save(obj, *args, **kargs): .. note:: The persistence mechanism is implemented by the Save function. - :Parameters: + Parameters + ---------- - * obj: object of the STAT module (except objects of type vector_distance), - * file_name (string), - * histo (_FrequencyDistribution, _DiscreteMixtureData, _ConvolutionData, _CompoundData), - * vec (_Vectors), - * timev (_TimeEvents, _RenewalData), - * seq (_Sequences, _DiscreteSequences, _MarkovData, _SemiMarkovData, _Tops). - * dist (_Distribution, _Mixture, _Convolution, _Compound), - * hmc (_HiddenMarkov), - * hsmc (_HiddenSemiMarkov). + obj: object of the STAT module (except objects of type vector_distance), + file_name : (string), + histo : (_FrequencyDistribution, _DiscreteMixtureData, _ConvolutionData, _CompoundData), + vec : (_Vectors), + timev : (_TimeEvents, _RenewalData), + seq : (_Sequences, _DiscreteSequences, _MarkovData, _SemiMarkovData, _Tops). + dist : (_Distribution, _Mixture, _Convolution, _Compound), + hmc : (_HiddenMarkov), + hsmc : (_HiddenSemiMarkov). - :Keywords: + Keywords + -------- - * ViewPoint (string): point of view on the object ("Data" or "Survival" or "StateProfile"). + ViewPoint : (string) + point of view on the object ("Data" or "Survival" or "StateProfile"). This optional argument can be set at : * "Data" only if the first argument is of type `_Sequences`, `_DiscreteSequences`, `_MarkovData`, `_SemiMarkovData` or `_Tops`, @@ -297,29 +310,35 @@ def Save(obj, *args, **kargs): `_ConvolutionData` or `_CompoundData` * "StateProfile" only if the first argument is of type `_HiddenMarkov or `_HiddenSemiMarkov`. - * Detail (int): level of detail: 1 (default value) or 2. + Detail : (int) + level of detail: 1 (default value) or 2. This optional argument can only be used if the optional argument ViewPoint is not set, or if the optional argument ViewPoint is set at "Data" and if the first mandatory argument is of type `_Vectors`, `_Sequences`, `_DiscreteSequences`, `_MarkovData`, `_SemiMarkovData` or `_Tops`. - * Format (string): file format: "ASCII" (default format), "Binary" or "SpreadSheet". + Format : (string) + file format: "ASCII" (default format), "Binary" or "SpreadSheet". These file formats cannot be specified if the optional argument ViewPoint is set at "Data". The optional argument Format can only be set at "Binary" if the optional argument ViewPoint is not set. - * Format (string): format of sequences (only relevant for multivariate sequences): + Format : (string) + format of sequences (only relevant for multivariate sequences): "Column" (default value) or "Line". This optional argument can only be used if the optional argument ViewPoint is set at "Data", and hence, if the first argument is of type `_Sequences`, `_DiscreteSequences`, `_MarkovData`, `_SemiMarkovData` or `_Tops`. If the first argument is of type `_Vectors`, use Format="Data" to actually save the data rather than their summary. - * Sequence (int): identifier of a sequence. This optional argument can only be used + Sequence : (int) + identifier of a sequence. This optional argument can only be used if the optional argument ViewPoint is set at "StateProfile", and hence, if the first mandatory argument is of type `_HiddenMarkov` or `_HiddenSemiMarkov`. - :Returns: + Returns + ------- No object returned. - :Examples: + Examples + -------- .. doctest:: :options: +SKIP @@ -335,11 +354,13 @@ def Save(obj, *args, **kargs): >>> Save(hmc, ViewPoint="StateProfile", Sequence=1, Format="SpreadSheet") >>> Save(hsmc, ViewPoint="StateProfile", Sequence=1, Format="SpreadSheet") - .. seealso:: - :func:`~openalea.stat_tool.output.Display`, - :func:`~openalea.stat_tool.output.Plot`. + See Also + -------- + :func:`~openalea.stat_tool.output.Display`, + :func:`~openalea.stat_tool.output.Plot`. - .. todo:: + Todo + ---- In the statInterface, Format is used for ViewPoint=="Data" need to be clarified """ @@ -347,20 +368,13 @@ def Save(obj, *args, **kargs): return obj.save(*args, **kargs) - class StatInterface: - """ Abstract base class for stat_tool objects """ - - - + """Abstract base class for stat_tool objects""" def old_plot(self, *args, **kargs): - """ Old AML style plot """ - #todo: to be replace by correct enumerate but depends on sequence_analysis - output_type = { - "ChangePoint" : 0, - "Segment" : 1 - } + """Old AML style plot""" + # todo: to be replace by correct enumerate but depends on sequence_analysis + output_type = {"ChangePoint": 0, "Segment": 1} title = kargs.get("Title", "") ViewPoint = kargs.get("ViewPoint", "") suffix = kargs.get("Suffix", "") @@ -372,69 +386,70 @@ def old_plot(self, *args, **kargs): stateprofile = bool(ViewPoint.lower() == "stateprofile") segmentprofile = bool(ViewPoint.lower() == "segmentprofile") - import tempfile + prefix = tempfile.mktemp() - if(data): + if data: try: self.plot_data_write(prefix, title) except AttributeError: - raise AttributeError("%s has not 'data' viewpoint" - % (str(type(self)))) - elif(survival): + raise AttributeError("%s has not 'data' viewpoint" % (str(type(self)))) + elif survival: try: self.survival_plot_write(prefix, title) except AttributeError: - raise AttributeError("%s has not 'survival' viewpoint" - % (str(type(self)))) + raise AttributeError( + "%s has not 'survival' viewpoint" % (str(type(self))) + ) - elif(stateprofile): + elif stateprofile: try: self.state_profile_plot_write(prefix, title, *params) except AttributeError: - raise AttributeError("%s has not 'state_profile' viewpoint" - % (str(type(self)))) - elif (segmentprofile): + raise AttributeError( + "%s has not 'state_profile' viewpoint" % (str(type(self))) + ) + elif segmentprofile: try: - - error.CheckType([args[0],args[1]], - [int,int]) - if len(args)==2: + error.CheckType([args[0], args[1]], [int, int]) + if len(args) == 2: error.CheckType([args[2]], [[list, str]]) models = [] for model in args[2]: try: from openalea.sequence_analysis.enums_seq import model_type + models.append(model_type[args[2]]) except: pass else: - models = [3] #Gaussian todo: check this is correct + models = [3] # Gaussian todo: check this is correct output = output_type[output] - self.segment_profile_write(prefix, args[0], args[1], models, - output, title) + self.segment_profile_write( + prefix, args[0], args[1], models, output, title + ) except AttributeError: - raise AttributeError("%s has not 'segment_profile' viewpoint" - % (str(type(self)))) - elif(args): + raise AttributeError( + "%s has not 'segment_profile' viewpoint" % (str(type(self))) + ) + elif args: self.plot_write(prefix, title, list(args)) else: self.plot_write(prefix, title) - plot_file = prefix + suffix + ".plot" f = open(plot_file, "a") f.write("pause -1") f.close() - if("win32" in sys.platform): + if "win32" in sys.platform: # replace file separators f = open(plot_file, "r") ct = f.read() f.close() - ctrp = ct.replace('\\', '\\\\') - ctrp = ctrp.replace(',\\\\', ',\\') + ctrp = ct.replace("\\", "\\\\") + ctrp = ctrp.replace(",\\\\", ",\\") f = open(plot_file, "w") f.write(ctrp) f.close() @@ -442,21 +457,22 @@ def old_plot(self, *args, **kargs): try: import Gnuplot + command = Gnuplot.GnuplotOpts.gnuplot_command except ImportError: - if("win32" in sys.platform): + if "win32" in sys.platform: command = "pgnuplot.exe" else: command = "gnuplot" - if(not plot.DISABLE_PLOT): - os.system("%s %s"%(command, plot_file)) + if not plot.DISABLE_PLOT: + os.system("%s %s" % (command, plot_file)) # for f in glob.glob(prefix+"*"): # os.remove(f) def plot_print(self, *args, **kargs): - """ Old AML style print into .ps file """ + """Old AML style print into .ps file""" title = kargs.get("Title", "") ViewPoint = kargs.get("ViewPoint", "") @@ -467,30 +483,32 @@ def plot_print(self, *args, **kargs): stateprofile = bool(ViewPoint.lower() == "stateprofile") import tempfile + prefix = tempfile.mktemp() - if(survival): + if survival: try: self.survival_plot_write(prefix, title) except AttributeError: - raise AttributeError("%s has not 'survival' viewpoint" - % (str(type(self)))) + raise AttributeError( + "%s has not 'survival' viewpoint" % (str(type(self))) + ) - elif(stateprofile): + elif stateprofile: try: self.state_profile_plot_write(prefix, title, *params) except AttributeError: - raise AttributeError("%s has not 'state_profile' viewpoint" - % (str(type(self)))) - + raise AttributeError( + "%s has not 'state_profile' viewpoint" % (str(type(self))) + ) - elif(args): + elif args: self.plot_write(prefix, title, list(args)) else: self.plot_write(prefix, title) plot_file = prefix + suffix + ".print" - print(("Graph printed into file:", prefix + suffix + ".ps")) + print(("Graph printed into file:", prefix + suffix + ".ps")) f = open(plot_file, "r") f.readline() contents = f.read() @@ -502,13 +520,13 @@ def plot_print(self, *args, **kargs): f = open(plot_file, "a") f.write("pause -1") f.close() - if("win32" in sys.platform): + if "win32" in sys.platform: # replace file separators f = open(plot_file, "r") ct = f.read() f.close() - ctrp = ct.replace('\\', '\\\\') - ctrp = ctrp.replace(',\\\\', ',\\') + ctrp = ct.replace("\\", "\\\\") + ctrp = ctrp.replace(",\\\\", ",\\") f = open(plot_file, "w") f.write(ctrp) f.close() @@ -516,39 +534,41 @@ def plot_print(self, *args, **kargs): try: import Gnuplot + command = Gnuplot.GnuplotOpts.gnuplot_command except ImportError: - if("win32" in sys.platform): + if "win32" in sys.platform: command = "pgnuplot.exe" else: command = "gnuplot" - if(not plot.DISABLE_PLOT): - os.system("%s %s"%(command, plot_file)) + if not plot.DISABLE_PLOT: + os.system("%s %s" % (command, plot_file)) - for f in glob.glob(prefix+"*"): + for f in glob.glob(prefix + "*"): if f != prefix + suffix + ".ps": os.remove(f) + @add_doc def plot(self, *args, **kargs): - Title = kargs.get("Title", "") params = kargs.get("Params", ()) groups = kargs.get("Groups", ()) - possible_modes = {'Blocking':False, 'NonBlocking':True} - Mode = error.ParseKargs(kargs, 'Mode', 'Blocking', possible=possible_modes) + possible_modes = {"Blocking": False, "NonBlocking": True} + Mode = error.ParseKargs(kargs, "Mode", "Blocking", possible=possible_modes) - viewpoint_map = {'v':'v', - "Data":"d", - "Survival":'s', - "SegmentProfile":'q', - "StateProfile":'p'} + viewpoint_map = { + "v": "v", + "Data": "d", + "Survival": "s", + "SegmentProfile": "q", + "StateProfile": "p", + } ViewPoint = error.ParseKargs(kargs, "ViewPoint", "v", possible=viewpoint_map) - - #todo: check the compatibilities between options + # todo: check the compatibilities between options """ if ((output_option) && ((view_point != 'q') || ((args[0].tag() != AMObjType::SEQUENCES) && (args[0].tag() @@ -632,12 +652,12 @@ def plot(self, *args, **kargs): except: from openalea.stat_tool.enums import output_display - if kargs.get('Output'): + if kargs.get("Output"): try: Output = None - Output = error.ParseKargs(kargs, "Output", 'Segment', output_display) + Output = error.ParseKargs(kargs, "Output", "Segment", output_display) except: - print('warning could not import output_display from sequence_analysis') + print("warning could not import output_display from sequence_analysis") else: try: from openalea.sequence_analysis.enums_seq import output_display @@ -646,67 +666,103 @@ def plot(self, *args, **kargs): Output = None if Output is None: - if ViewPoint == 'q': - Output = output_display['Segment'] - elif ViewPoint == 'p': - Output = output_display['State'] - elif (ViewPoint == 'q' and Output not in [output_display['ChangePoint'], output_display['Segment']]) \ - or (ViewPoint == 'p' and Output not in [output_display['State'], output_display['InState'], output_display['OutState']]): + if ViewPoint == "q": + Output = output_display["Segment"] + elif ViewPoint == "p": + Output = output_display["State"] + elif ( + ViewPoint == "q" + and Output not in [output_display["ChangePoint"], output_display["Segment"]] + ) or ( + ViewPoint == "p" + and Output + not in [ + output_display["State"], + output_display["InState"], + output_display["OutState"], + ] + ): raise ValueError(" INCOMPATIBLE_OPTIONS between ViewPoint and Output") plotable = None - #calling the plot functions from here + # calling the plot functions from here explicit_error = False try: - if ViewPoint=='s': - from openalea.stat_tool.enums import histogram_types - from openalea.stat_tool.enums import model_distribution_types - #todo is *params needed or not? + if ViewPoint == "s": + from openalea.stat_tool.enums import ( + histogram_types, + model_distribution_types, + ) + + # todo is *params needed or not? if type(self) in model_distribution_types: - #equivalent to dist->suvival_plot_write(error, Plot_prefix, title) + # equivalent to dist->suvival_plot_write(error, Plot_prefix, title) plotable = self.survival_get_plotable(*params) elif type(self) in histogram_types: - #equivalent to histo->survival_plot_write(error , Plot_prefix , title) + # equivalent to histo->survival_plot_write(error , Plot_prefix , title) plotable = self.survival_get_plotable(*params) else: explicit_error = True - local_error = ValueError("""(%s) has no survival point. Use another + local_error = ValueError( + """(%s) has no survival point. Use another Viewpoint or use a first argument in DISTRIBUTION or MIXTURE or CONVOLUTION or COMPOUND or FREQUENCY_DISTRIBUTION or MIXTURE_DATA or CONVOLUTION_DATA or COMPOUND_DATA""" - % str(type(self))) + % str(type(self)) + ) - elif ViewPoint=='p': - #print 'viewpoint = state-profile' - Plot_prefix='' + elif ViewPoint == "p": + # print 'viewpoint = state-profile' + Plot_prefix = "" plotable = None - from openalea.sequence_analysis._sequence_analysis import \ - _HiddenVariableOrderMarkov, _HiddenSemiMarkov + from openalea.sequence_analysis._sequence_analysis import ( + _HiddenSemiMarkov, + _HiddenVariableOrderMarkov, + ) + if type(self) == _HiddenVariableOrderMarkov: plotable = self.state_profile_plotable_write(args[0]) elif type(self) == _HiddenSemiMarkov: - if len(args)==0: + if len(args) == 0: explicit_error = True - local_error = SyntaxError("expect an identifier (Plot(hsmc25, 1, ViewPoint='StateProfile')") - elif len(args)==1: + local_error = SyntaxError( + "expect an identifier (Plot(hsmc25, 1, ViewPoint='StateProfile')" + ) + elif len(args) == 1: identifier = args[0] else: - #print 'iiiiiiiiiiiiiii' + # print 'iiiiiiiiiiiiiii' explicit_error = True - local_error = SyntaxError("expect only one identifier Plot(hsmc25, 1, ViewPoint='StateProfile'") + local_error = SyntaxError( + "expect only one identifier Plot(hsmc25, 1, ViewPoint='StateProfile'" + ) plotable = self.state_profile_plotable_write(identifier, Output) else: - #todo 3 args required - from openalea.sequence_analysis._sequence_analysis import _MarkovianSequences, _VariableOrderMarkovData, _SemiMarkovData, _NonhomogeneousMarkovData - assert type(self) in [_MarkovianSequences, _VariableOrderMarkovData, - _SemiMarkovData, _NonhomogeneousMarkovData] - if type(args[1])==_HiddenVariableOrderMarkov: - plotable = args[1].state_profile_plotable_write2(self , args[0]); - elif type(args[1])==_HiddenSemiMarkov: - plotable = args[1].state_profile_plotable_write2(self , args[0], Output) + # todo 3 args required + from openalea.sequence_analysis._sequence_analysis import ( + _MarkovianSequences, + _NonhomogeneousMarkovData, + _SemiMarkovData, + _VariableOrderMarkovData, + ) + + assert type(self) in [ + _MarkovianSequences, + _VariableOrderMarkovData, + _SemiMarkovData, + _NonhomogeneousMarkovData, + ] + if type(args[1]) == _HiddenVariableOrderMarkov: + plotable = args[1].state_profile_plotable_write2(self, args[0]) + elif type(args[1]) == _HiddenSemiMarkov: + plotable = args[1].state_profile_plotable_write2( + self, args[0], Output + ) else: explicit_error = True - local_error = TypeError("expect HiddenVariableOrderMarkov or HiddenSemiMarkov") + local_error = TypeError( + "expect HiddenVariableOrderMarkov or HiddenSemiMarkov" + ) if plotable == None: try: @@ -714,62 +770,96 @@ def plot(self, *args, **kargs): except: pass - elif ViewPoint=='q': - from openalea.sequence_analysis._sequence_analysis import _Sequences, _MarkovianSequences, _VariableOrderMarkovData, _SemiMarkovData - if type(self) not in [_Sequences, _MarkovianSequences, _VariableOrderMarkovData, _SemiMarkovData]: + elif ViewPoint == "q": + from openalea.sequence_analysis._sequence_analysis import ( + _MarkovianSequences, + _SemiMarkovData, + _Sequences, + _VariableOrderMarkovData, + ) + + if type(self) not in [ + _Sequences, + _MarkovianSequences, + _VariableOrderMarkovData, + _SemiMarkovData, + ]: explicit_error = True - local_error = TypeError('object must be in SEQUENCES or MARKOVIAN_SEQUENCES or VARIABLE_ORDER_MARKOV_DATA or SEMI-MARKOV_DATA') + local_error = TypeError( + "object must be in SEQUENCES or MARKOVIAN_SEQUENCES or VARIABLE_ORDER_MARKOV_DATA or SEMI-MARKOV_DATA" + ) try: self.nb_variable except: explicit_error = True - local_error = ValueError("object has no nb_variable. check that it is a sequence") + local_error = ValueError( + "object has no nb_variable. check that it is a sequence" + ) nb_variable = self.nb_variable - assert len(args)>=2 + assert len(args) >= 2 error.CheckType([args[0], args[1]], [[int], [int]]) - #construct model_type + # construct model_type from openalea.sequence_analysis.enums_seq import model_type + types = [] for i in range(0, nb_variable): - error.CheckType([args[i+2]], [str]) + error.CheckType([args[i + 2]], [str]) if i == 0: - types.append(model_type[args[i+2]]) - #Multinomial or Poisson or Ordinal or Gaussian or + types.append(model_type[args[i + 2]]) + # Multinomial or Poisson or Ordinal or Gaussian or # Mean or Variance or MeanVariance - if args[i+2] in ["Mean", "MeanVariance"]: + if args[i + 2] in ["Mean", "MeanVariance"]: for j in range(1, nb_variable): types.append(types[i]) break else: # Multinomial or Poisson or Ordinal or Gaussian # or Variance - types.append(model_type[args[i+2]]) - #seq->segment_profile_plot_write( + types.append(model_type[args[i + 2]]) + # seq->segment_profile_plot_write( # error , Plot_prefix , args[1].val.i , # args[2].val.i , model_type , output , title); - plotable = self.segment_profile_plotable_write(args[0], args[1], - types, Output) - - #data viewPoint - elif ViewPoint == 'd': - from openalea.sequence_analysis._sequence_analysis import _SemiMarkovData, _MarkovianSequences, _Sequences, _NonHomogeneousMarkovData#, _Tops - if type(self) in [_SemiMarkovData, _MarkovianSequences, _Sequences, - _NonHomogeneousMarkovData, - #_Tops - ]: - #status = seq->plot_data_write(error , Plot_prefix , title); + plotable = self.segment_profile_plotable_write( + args[0], args[1], types, Output + ) + + # data viewPoint + elif ViewPoint == "d": + from openalea.sequence_analysis._sequence_analysis import ( + _MarkovianSequences, + _NonHomogeneousMarkovData, + _SemiMarkovData, + _Sequences, + ) # , _Tops + + if type(self) in [ + _SemiMarkovData, + _MarkovianSequences, + _Sequences, + _NonHomogeneousMarkovData, + # _Tops + ]: + # status = seq->plot_data_write(error , Plot_prefix , title); plotable = self.get_plotable_data(*params) - elif ViewPoint == 'v': + elif ViewPoint == "v": # plot_write(error , Plot_prefix , title); if args: - #sequence case: - #todo: make it looser: observation, intensity INTENSITY? - choices = ["SelfTransition", "Observation", "Intensity", - "FirstOccurrence", "Recurrence", "Sojourn", "Counting", - "NbRun", "NbOccurrence"] + # sequence case: + # todo: make it looser: observation, intensity INTENSITY? + choices = [ + "SelfTransition", + "Observation", + "Intensity", + "FirstOccurrence", + "Recurrence", + "Sojourn", + "Counting", + "NbRun", + "NbOccurrence", + ] if args[0] in choices: multiplotset = self.get_plotable() viewpoints = [x for x in multiplotset.viewpoint()] @@ -778,47 +868,65 @@ def plot(self, *args, **kargs): from openalea.sequence_analysis import enums_seq except: explicit_error = True - errlocal_erroror = ImportError("sequence analysis not installed !!") + errlocal_erroror = ImportError( + "sequence analysis not installed !!" + ) - if len(args)==1: + if len(args) == 1: variable = 0 - elif len(args)==2: + elif len(args) == 2: variable = args[1] try: for index, xx in enumerate(viewpoints): - if xx==enums_seq.markovian_sequence_type[args[0]]: - if multiplotset.variable[index]==variable: + if xx == enums_seq.markovian_sequence_type[args[0]]: + if multiplotset.variable[index] == variable: plotable.append(multiplotset[index]) except AttributeError: explicit_error = True - local_error = ImportError("sequence analysis not installed !!") - if ((enums_seq.markovian_sequence_type[args[0]] in viewpoints) and (len(plotable) == 0)): + local_error = ImportError( + "sequence analysis not installed !!" + ) + if ( + enums_seq.markovian_sequence_type[args[0]] in viewpoints + ) and (len(plotable) == 0): explicit_error = True - msg = "ViewPoint " + str(args[0]) + " not found for variable " + str(variable) + "." - local_error = ValueError(msg) + msg = ( + "ViewPoint " + + str(args[0]) + + " not found for variable " + + str(variable) + + "." + ) + local_error = ValueError(msg) elif len(args) == 1 and type(args[0]) == str: explicit_error = True - local_error = SyntaxError("first argument must be in %s and second arg (int) may be provided." % choices) - elif len(args)==1 and type(args[0])==int: + local_error = SyntaxError( + "first argument must be in %s and second arg (int) may be provided." + % choices + ) + elif len(args) == 1 and type(args[0]) == int: from openalea.stat_tool._stat_tool import _Vectors - if type(self)==_Vectors: - #Plot(vector, 1) + + if type(self) == _Vectors: + # Plot(vector, 1) multiplotset = self.get_plotable() viewpoints = [x for x in multiplotset.viewpoint] plotable = [] try: - from openalea.sequence_analysis import enums + pass except: explicit_error = True - local_error = ImportError("sequence analysis not installed !!") + local_error = ImportError( + "sequence analysis not installed !!" + ) plotable = [multiplotset[args[0]]] else: - #Plot(hist1, hist2, hist3) + # Plot(hist1, hist2, hist3) plotable = self.get_plotable_list() - elif len(args)==1: - #e.g., list of histograms + elif len(args) == 1: + # e.g., list of histograms plotable = self.get_plotable_list(list(args), *params) - elif (type(args[0]) == str) and not(args[0] in choices): + elif (type(args[0]) == str) and args[0] not in choices: explicit_error = True local_error = ValueError("Bad viewpoint: " + args[0]) else: @@ -828,6 +936,7 @@ def plot(self, *args, **kargs): plotter = plot.get_plotter() except: import warnings + warnings.warn("Cannot use new plotter. Use old style plot.") plotable = None if explicit_error: @@ -836,33 +945,31 @@ def plot(self, *args, **kargs): if plot.DISABLE_PLOT: return - if(plotable is not None): + if plotable is not None: plotter.plot(plotable, Title, groups, *args, **kargs) else: self.old_plot(*args, **kargs) - @add_doc def display(self, *args, **kargs): - format_map = { - 'c':'c', - 'l':'l', - 'Column': 'c', - 'Line': 'l'} - viewpoint_map = {'v':'v', - "Data":"d", - "Survival":'s', - "SegmentProfile":'q', - "StateProfile":'p'} + format_map = {"c": "c", "l": "l", "Column": "c", "Line": "l"} + viewpoint_map = { + "v": "v", + "Data": "d", + "Survival": "s", + "SegmentProfile": "q", + "StateProfile": "p", + } segmentations_map = { - "DynamicProgramming": FORWARD_DYNAMIC_PROGRAMMING, - "ForwardBackwardSampling": FORWARD_BACKWARD_SAMPLING - } + "DynamicProgramming": FORWARD_DYNAMIC_PROGRAMMING, + "ForwardBackwardSampling": FORWARD_BACKWARD_SAMPLING, + } - state_seq_map = { "GeneralizedViterbi": GENERALIZED_VITERBI, - "ForwardBackwardSampling": FORWARD_BACKWARD_SAMPLING - } + state_seq_map = { + "GeneralizedViterbi": GENERALIZED_VITERBI, + "ForwardBackwardSampling": FORWARD_BACKWARD_SAMPLING, + } # Detail level Detail = error.ParseKargs(kargs, "Detail", 1, [1, 2]) @@ -872,27 +979,24 @@ def display(self, *args, **kargs): exhaustive = False Format = error.ParseKargs(kargs, "Format", "c", format_map) ViewPoint = error.ParseKargs(kargs, "ViewPoint", "v", viewpoint_map) - NbStateSequence = error.ParseKargs(kargs, "NbStateSequence", - NB_STATE_SEQUENCE) + NbStateSequence = error.ParseKargs(kargs, "NbStateSequence", NB_STATE_SEQUENCE) error.CheckType([NbStateSequence], [[int, float]]) - NbSegmentation = error.ParseKargs(kargs, "NbSegmentation", - NB_SEGMENTATION) + NbSegmentation = error.ParseKargs(kargs, "NbSegmentation", NB_SEGMENTATION) error.CheckType([NbSegmentation], [[int, float]]) - - StateSequence = error.ParseKargs(kargs, "StateSequence", - "GeneralizedViterbi", state_seq_map) - Segmentation = error.ParseKargs(kargs, "Segmentation", - "DynamicProgramming", - segmentations_map) - #todo it seems that by default, segmentation = FORWARD_DYNAMIC_PROGRAMMING , - + StateSequence = error.ParseKargs( + kargs, "StateSequence", "GeneralizedViterbi", state_seq_map + ) + Segmentation = error.ParseKargs( + kargs, "Segmentation", "DynamicProgramming", segmentations_map + ) + # todo it seems that by default, segmentation = FORWARD_DYNAMIC_PROGRAMMING , # !! in AML, Output is not set y default, i.e. equivalent to None # the ParseKargs does not accept None sinc we provide the list of # possible keys in output_display (which do not contain None) - #, so we first need to check the presence of Output in the kargs + # , so we first need to check the presence of Output in the kargs # then, to give a default value!=None. But be aware that tis default # value is a dummy variable that is not used. try: @@ -900,12 +1004,12 @@ def display(self, *args, **kargs): except: from openalea.stat_tool.enums import output_display - if kargs.get('Output'): + if kargs.get("Output"): try: Output = None - Output = error.ParseKargs(kargs, "Output", 'Segment', output_display) + Output = error.ParseKargs(kargs, "Output", "Segment", output_display) except: - print('warning could not import output_display from sequence_analysis') + print("warning could not import output_display from sequence_analysis") else: try: from openalea.sequence_analysis.enums_seq import output_display @@ -914,22 +1018,29 @@ def display(self, *args, **kargs): Output = None if Output is None: - if ViewPoint == 'q': - Output = output_display['Segment'] - elif ViewPoint == 'p': - Output = output_display['State'] - elif (ViewPoint == 'q' and Output not in [output_display['ChangePoint'], output_display['Segment']]) \ - or (ViewPoint == 'p' and Output not in [output_display['State'], output_display['InState'], output_display['OutState']]): + if ViewPoint == "q": + Output = output_display["Segment"] + elif ViewPoint == "p": + Output = output_display["State"] + elif ( + ViewPoint == "q" + and Output not in [output_display["ChangePoint"], output_display["Segment"]] + ) or ( + ViewPoint == "p" + and Output + not in [ + output_display["State"], + output_display["InState"], + output_display["OutState"], + ] + ): raise ValueError(" INCOMPATIBLE_OPTIONS between ViewPoint and Output") + # check arguments compatibilities - - - #check arguments compatibilities - - if Detail == 2 and ViewPoint not in ['v', 'd']: + if Detail == 2 and ViewPoint not in ["v", "d"]: raise ValueError("incompatible options") - if Format == 'l' and ViewPoint != 'd': + if Format == "l" and ViewPoint != "d": raise ValueError("incompatible options") """if segmentations_option or nb_segmentation_option) and \ (view_point!='q' or args[0] not in @@ -966,113 +1077,133 @@ def display(self, *args, **kargs): } """ - - # ---------------- ViewPoint # 1-Survival - if ViewPoint == 's': - from openalea.stat_tool.enums import histogram_types - from openalea.stat_tool.enums import model_distribution_types + if ViewPoint == "s": + from openalea.stat_tool.enums import ( + histogram_types, + model_distribution_types, + ) if type(self) in model_distribution_types: output = self.survival_ascii_write() elif type(self) in histogram_types: output = self.survival_ascii_write() else: - raise ValueError("""(%s) has no survival point. Use another + raise ValueError( + """(%s) has no survival point. Use another Viewpoint or use a first argument in DISTRIBUTION or MIXTURE or CONVOLUTION or COMPOUND or FREQUENCY_DISTRIBUTION or MIXTURE_DATA or CONVOLUTION_DATA or COMPOUND_DATA""" - % str(type(self))) + % str(type(self)) + ) # Data elif ViewPoint == "d": try: - #todo checkType + # todo checkType # Markovian_Sequences, VOMData, SMData, # or Nonhomogenous_Markov_data output = self.ascii_data_write(exhaustive, Format) - except Exception as e: - #for vectors only - #todo checkType + except Exception: + # for vectors only + # todo checkType try: output = self.ascii_data_write(exhaustive) except AttributeError: - raise AttributeError(""" - %s has not 'data' viewpoint""" % (str(type(self)))) + raise AttributeError( + """ + %s has not 'data' viewpoint""" + % (str(type(self))) + ) # StatProfile - elif ViewPoint == 'p': + elif ViewPoint == "p": try: - from openalea.sequence_analysis._sequence_analysis import \ - _HiddenVariableOrderMarkov, _HiddenSemiMarkov, \ - _MarkovianSequences, VariableOrderMarkovData, \ - _SemiMarkovData, _NonhomogenousMarkovData + from openalea.sequence_analysis._sequence_analysis import ( + VariableOrderMarkovData, + _HiddenSemiMarkov, + _HiddenVariableOrderMarkov, + _MarkovianSequences, + _NonhomogenousMarkovData, + _SemiMarkovData, + ) except: raise ImportError("openalea.sequence_analysis not found") - assert len(args)>=1 + assert len(args) >= 1 error.CheckType(args[0], [int]) if type(self) == _HiddenVariableOrderMarkov: - assert len(args)==1 - self.state_profile_ascii_write(args[0], StateSequence, - NbStateSequence) + assert len(args) == 1 + self.state_profile_ascii_write(args[0], StateSequence, NbStateSequence) elif type(self) == _HiddenSemiMarkov: - assert len(args)==1 - self._HiddenSemiMarkov.state_profile_ascii_write(args[0], - output , StateSequence , NbStateSequence) - elif type(self) in [_MarkovianSequences, VariableOrderMarkovData, - _SemiMarkovData, _NonhomogenousMarkovData]: - assert len(args)==2 + assert len(args) == 1 + self._HiddenSemiMarkov.state_profile_ascii_write( + args[0], output, StateSequence, NbStateSequence + ) + elif type(self) in [ + _MarkovianSequences, + VariableOrderMarkovData, + _SemiMarkovData, + _NonhomogenousMarkovData, + ]: + assert len(args) == 2 if type(args[1]) == _HiddenVariableOrderMarkov: - args[1].state_profile_write(self , args[0], 'a', - StateSequence , NbStateSequence) + args[1].state_profile_write( + self, args[0], "a", StateSequence, NbStateSequence + ) elif type(args[1]) == _HiddenSemiMarkov: - args[1].state_profile_write(self , args[0] , output , - 'a' , StateSequence , NbStateSequence) + args[1].state_profile_write( + self, args[0], output, "a", StateSequence, NbStateSequence + ) else: raise ValueError( - """Display with state profile requires 3 arugments and + """Display with state profile requires 3 arugments and second one must be HIDDEN_VARIABLE_ORDER_MARKOV or - HIDDEN_SEMI_MARKOV""") + HIDDEN_SEMI_MARKOV""" + ) else: raise ValueError("Wrong arguments combinaison. Check them") - #segment profile - elif ViewPoint == 'q': + # segment profile + elif ViewPoint == "q": try: self.nb_variable except: - raise ValueError("object has no nb_variable. check that it is a sequence") + raise ValueError( + "object has no nb_variable. check that it is a sequence" + ) nb_variable = self.nb_variable - assert len(args)>=2 - error.CheckType([args[0], args[1]], [[int],[int]]) - #construct model_type + assert len(args) >= 2 + error.CheckType([args[0], args[1]], [[int], [int]]) + # construct model_type try: from openalea.sequence_analysis.enums_seq import model_type except: pass types = [] for i in range(0, nb_variable): - error.CheckType([args[i+2]], [str]) - if i==0: - types.append(model_type[args[i+2]]) - #Multinomial or Poisson or Ordinal or Gaussian or + error.CheckType([args[i + 2]], [str]) + if i == 0: + types.append(model_type[args[i + 2]]) + # Multinomial or Poisson or Ordinal or Gaussian or # Mean or Variance or MeanVariance - if args[i+2] in ["Mean","MeanVariance"]: + if args[i + 2] in ["Mean", "MeanVariance"]: for j in range(1, nb_variable): - types.append(types[i]) + types.append(types[i]) break else: # Multinomial or Poisson or Ordinal or Gaussian # or Variance - types.append(model_type[args[i+2]]) - output = self.segment_profile_write(args[0], args[1], types, Output, - 'a', Segmentation, NbSegmentation) - elif ViewPoint == 'v': + types.append(model_type[args[i + 2]]) + output = self.segment_profile_write( + args[0], args[1], types, Output, "a", Segmentation, NbSegmentation + ) + elif ViewPoint == "v": from openalea.stat_tool.enums import all_stat_tool_types + try: from openalea.sequence_analysis.enums_seq import all_sequences_types except ImportError: @@ -1091,22 +1222,20 @@ def display(self, *args, **kargs): return output @add_doc - def save(self, filename, Detail=2, ViewPoint="", Format="ASCII" ): - + def save(self, filename, Detail=2, ViewPoint="", Format="ASCII"): # Detail level - if(Detail>1): + if Detail > 1: exhaustive = True else: exhaustive = False - if(Format.lower() == "spreadsheet"): + if Format.lower() == "spreadsheet": self.spreadsheet_write(filename) - #f = open(filename, 'w') - #f.write(outstr) - #f.close() + # f = open(filename, 'w') + # f.write(outstr) + # f.close() - elif(Format.lower() == "data"): + elif Format.lower() == "data": self.file_ascii_data_write(filename, exhaustive) else: self.file_ascii_write(filename, exhaustive) -