Skip to main content

Description

ConTEST is a statistical test for assessing the consistency between observations and astrophysical models. It uses a combination of non-parametric methods and distance measures to obtain a test statistic that evaluates the closeness of the astrophysical model to the observations; hypothesis testing is then performed using bootstrap.

Table of Contents

Step-by-step setup

Follow the instructions below to install and start using ConTEST in Python.

  1. Install ConTEST:
    pip install ConsistencyTEST
    
    or git clone the repository:
    git clone https://github.com/FiorenSt/ConTEST.git
    

  1. (Optional) Install the statistical software R. R is required only if you plan to use the smoothed_contest_reg() function. This function employs local linear regression using the np package in R.

  1. (Optional) To ensure that Python can access R's libraries, run the three lines below in Python (of course, modify to match your folders). This step is only necessary if you intend to use the smoothed_contest_reg() function:

     import os
     os.environ['R_HOME'] = '~/Program Files/R/R-4.0.2'  #-> Your installed R folder
     os.environ['R_USER'] = '~/Miniconda3/envs/ConsistencyTest/lib/site-packages/'  #-> Your python environment
     os.environ['R_LIBS_USER'] = "~/Program Files/R/R-4.0.2/library/"  #-> Your R packages library
    

  1. Install Python dependencies. Note that the rpy2 package, which facilitates interaction between R and Python, is required only if you plan to use the smoothed_contest_reg() function:
    pip intall matplotlib
    pip intall numpy
    pip intall pandas
    pip intall scipy
    pip intall seaborn
    pip intall rpy2
    

  1. (Optional) If this is the first time you use ConTEST and you plan to use the smoothed_contest_reg() function, you need to install the R package used in Smoothed ConTEST. In Python, simply run:

     def install_R_functions(packnames=('np')):
         # import R's utility package
         utils = rpackages.importr('utils')
         # select a mirror for R packages
         utils.chooseCRANmirror(ind=1)  # select the first mirror in the list
         # R package install
         utils.install_packages(packnames)
     
     install_R_functions()
    
  2. Use ConTEST in Python! Follow the tutorial below for more information about the individual functions.



Dependencies:

The following combination of package versions works on most Linux and Windows computers, however other package versions may also work. If a problem with the combination of packages occurs, raise an issue, and we will help you solve it.

Python 3 (or superior)

  • Numpy 1.21.6
  • Pandas 1.4.2
  • Scipy 1.7.1
  • Matplotlib 3.3.4
  • Seaborn 0.11.2
  • Rpy2 3.5.2 (For R and Python interaction)

R 3.6.0 (or superior)

  • Np 0.60

Tutorial

ConTEST can be applied in different case scenarios depending on the nature of the model being tested.
For more details check out the paper: Stoppa et al., in preparation

There are 4 fundamental functions in ConTEST:

  • ConTEST for regression: Test the consistency of a model with respect to an observed dataset and their uncertainties
  • Smoothed ConTEST for regression (requires R and the rpy2 Python package): Test the consistency of a model with respect to an observed dataset and their uncertainties
  • ConTEST for outliers: Test if an observed sample is likely to come from a density model (or a simulated dataset)
  • ConTEST for densities: Test the consistency of a density model (or a simulated dataset) with respect to an observed dataset

Intro script

 # ensure that Python can access R
 import os
 os.environ['R_HOME'] = '~/Program Files/R/R-4.0.2'  #-> Your installed R folder
 os.environ['R_USER'] = '~/Miniconda3/envs/ConsistencyTest/lib/site-packages/'  #-> Your python environment
 os.environ['R_LIBS_USER'] = "~/Program Files/R/R-4.0.2/library/"  #-> Your R packages library
 
 # load contest functions
 from ConTEST.CONTEST import contest_reg, smoothed_contest_reg, contest_outliers, contest_dens

Regression models

Create synthetic model, observations, and uncertainties to test the functions:

# random sample 
n=100
x = np.random.rand(n)

# synthetic model 
beta1 = -0.3
beta2 = 8
m = 2
model = np.exp(beta1*x)*np.sin(beta2*x) + m

# error function (Not known in real scenarios)
err_model = model * .05

# sample observations from the model with the correct uncertainties
obs = np.zeros(N)
   for i in range(N):
  obs[i] = model[i] + stats.multivariate_normal.rvs(mean=0, cov=(err_model[i])**2,size=1)

# assign correct uncertainties to the observations
err_obs = err_model

ConTEST for regression

Test1 = contest_reg(y_obs = obs, x_obs = x, y_mod = model, y_obs_err = err_obs, K=1000,plot=True)

Smoothed ConTEST for regression (requires R and the rpy2 Python package)

Test2 = smoothed_contest_reg(y_obs = obs, x_obs = x, y_mod = model, y_obs_err = err_obs, K=1000,plot=True)   

Density models

Create synthetic model and observations:

n=100

#1D example
obs = stats.multivariate_normal.rvs(mean=5, cov= [1.5],size=n)
model = stats.multivariate_normal.rvs(mean=5, cov= [1.5],size=1000)
 
#2D example
obs_2d =  stats.multivariate_normal.rvs(mean=[5,5], cov= [[1.5,.8],[.8,2.5]],size=n)
model_2d = stats.multivariate_normal.rvs(mean=[5,5], cov= [[1.5,.8],[.8,2.5]],size=1000)

### ConTEST for outliers 

```sh
Test3 = contest_outliers(mod=model, obs=obs, K=10000, plot=True)
Test3 = contest_outliers(mod=model_2d, obs=obs_2d, K=10000, plot=True)

ConTEST for densities

Test4 = contest_dens(mod=model, obs=obs, K=10000, plot=True)   
Test4 = contest_dens(mod=model_2d, obs=obs_2d, K=10000, plot=True)

Metadata

Release files for ConsistencyTEST 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ConsistencyTEST 0.0.2
File Size Uploaded Provenance Actions
ConsistencyTEST-0.0.2.tar.gz 13.5 kB Without provenance Details for ConsistencyTEST-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ConsistencyTEST 0.0.2
File Interpreter ABI Platform Actions
ConsistencyTEST-0.0.2-py3-none-any.whl Python 3 none any Details for ConsistencyTEST-0.0.2-py3-none-any.whl

Total release size: 24.9 kB

Release files / ConsistencyTEST-0.0.2.tar.gz

Download URL ConsistencyTEST-0.0.2.tar.gz
Size 13.5 kB
Tags Source
SHA-256 checksum
How to use checksums
edf3ab646e665658f49d59e6d59791d153e797297fc67da294d20080e608df0a
BLAKE2b-256 checksum
How to use checksums
8602d4a9c8f57bc3edfe59c85e9fc848e6dcc1dfc0f7261b95852889a2da1813
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.7

Release files / ConsistencyTEST-0.0.2-py3-none-any.whl

Download URL ConsistencyTEST-0.0.2-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f5adebb02f1a37fbdec493f8c14ab641c859b0599797efeb8ed847729600fa2e
BLAKE2b-256 checksum
How to use checksums
8ebab46831a0c757270b67ca4ec4d4b6d9a0ee0c5b930e6762ef240b5ddc2a52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.7

Security for ConsistencyTEST 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page