├── snakebacon ├── tests │ ├── __init__.py │ ├── test_chronrecord.py │ ├── test_utils.py │ ├── MSB2K.csv │ ├── test_datedproxyrecord.py │ ├── test_mcmcbackend_bacon.py │ ├── test_mcmc.py │ ├── test_bacon_utils.py │ ├── test_baconwrap.py │ └── test_agedepth.py ├── mcmcbackends │ ├── bacon │ │ ├── bacon.pxd │ │ ├── Curves │ │ │ ├── __init__.py │ │ │ ├── postbomb_SH3.14C │ │ │ ├── postbomb_NH3.14C │ │ │ ├── postbomb_NH2.14C │ │ │ ├── postbomb_NH1.14C │ │ │ └── postbomb_SH1-2.14C │ │ ├── __init__.py │ │ ├── calibcurves.py │ │ ├── ranfun.h │ │ ├── vector.cpp │ │ ├── input.h │ │ ├── Matrix.cpp │ │ ├── ranfun.cpp │ │ ├── bacon.cpp │ │ ├── utils.py │ │ ├── kernel.cpp │ │ ├── input.cpp │ │ ├── Matrix.h │ │ ├── baconwrap.pyx │ │ └── bacon.h │ └── __init__.py ├── __init__.py ├── utils.py ├── mcmc.py ├── records.py └── agedepth.py ├── setup.cfg ├── requirements.txt ├── .readthedocs.yml ├── MANIFEST.in ├── docs ├── examples.rst ├── io.rst ├── plots.rst ├── installing.rst ├── environment.yml ├── internals.rst ├── api-invisible.rst ├── faq.rst ├── Makefile ├── make.bat ├── index.rst ├── api.rst ├── whats_new.rst └── conf.py ├── ci ├── requirements-py35.yml └── requirements-py36.yml ├── README.rst ├── .travis.yml ├── .gitignore ├── setup.py └── environment.yml /snakebacon/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [build_ext] 2 | inplace=1 3 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | numpy>=1.1 2 | Cython>=0.22 3 | pandas>=0.19 4 | matplotlib>=2.0 5 | -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/bacon/bacon.pxd: -------------------------------------------------------------------------------- 1 | cdef extern from "bacon.cpp": 2 | int notmain(int argc, char *argv[]) 3 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | conda: 2 | file: docs/environment.yml 3 | python: 4 | version: 3 5 | setup_py_install: true 6 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | recursive-include doc * 3 | prune doc/_build 4 | prune doc/generated 5 | recursive-include snakebacon *.pyx *.px[di] *.h *.c *.cpp -------------------------------------------------------------------------------- /docs/examples.rst: -------------------------------------------------------------------------------- 1 | Examples 2 | ======== 3 | 4 | .. warning:: 5 | 6 | The project is under heavy development. Code and documentation are not complete. 7 | 8 | 9 | .. toctree:: 10 | :maxdepth: 2 11 | -------------------------------------------------------------------------------- /docs/io.rst: -------------------------------------------------------------------------------- 1 | .. _io: 2 | 3 | Reading and writing files 4 | ========================= 5 | 6 | .. warning:: 7 | 8 | The project is under heavy development. Code and documentation are not complete. 9 | 10 | 11 | -------------------------------------------------------------------------------- /docs/plots.rst: -------------------------------------------------------------------------------- 1 | .. _plotting: 2 | 3 | Plotting 4 | ======== 5 | 6 | .. warning:: 7 | 8 | The project is under heavy development. Code and documentation is not complete. 9 | 10 | 11 | Introduction 12 | ------------ 13 | 14 | -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/bacon/Curves/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | This is a big hack to keep track of where the Curves directory is for the bacon 3 | C/C++ scripts. 4 | """ 5 | 6 | from os import path as _path 7 | 8 | here = _path.abspath(_path.dirname(__file__)) 9 | -------------------------------------------------------------------------------- /docs/installing.rst: -------------------------------------------------------------------------------- 1 | .. _installing: 2 | 3 | Installation 4 | ============ 5 | 6 | .. warning:: 7 | 8 | The project is under heavy development. Code and documentation are not complete. 9 | 10 | 11 | Required dependencies 12 | --------------------- 13 | -------------------------------------------------------------------------------- /docs/environment.yml: -------------------------------------------------------------------------------- 1 | name: snakebacon-docs 2 | dependencies: 3 | - python=3.5 4 | - cython 5 | - gsl 6 | - openblas 7 | - setuptools 8 | - docutils 9 | - matplotlib 10 | - numpy 11 | - numpydoc 12 | - ipython 13 | - pandas 14 | - scipy 15 | -------------------------------------------------------------------------------- /ci/requirements-py35.yml: -------------------------------------------------------------------------------- 1 | name: test_env 2 | channels: 3 | - defaults 4 | - conda-forge 5 | dependencies: 6 | - python=3.5 7 | - cython 8 | - gsl 9 | - openblas 10 | - setuptools 11 | - docutils 12 | - matplotlib 13 | - numpy 14 | - pandas 15 | - scipy 16 | -------------------------------------------------------------------------------- /ci/requirements-py36.yml: -------------------------------------------------------------------------------- 1 | name: test_env 2 | channels: 3 | - defaults 4 | - conda-forge 5 | dependencies: 6 | - python=3.6 7 | - cython 8 | - gsl 9 | - openblas 10 | - setuptools 11 | - docutils 12 | - matplotlib 13 | - numpy 14 | - pandas 15 | - scipy 16 | -------------------------------------------------------------------------------- /docs/internals.rst: -------------------------------------------------------------------------------- 1 | .. _internals: 2 | 3 | snakebacon Internals 4 | ==================== 5 | 6 | .. warning:: 7 | 8 | The project is under heavy development. Code and documentation are not complete. 9 | 10 | 11 | .. currentmodule:: xarray 12 | 13 | snakebacon builds on and wraps around the C/C++ in the Bacon from ... -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/bacon/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Cython wrapper for the C/C++ from Bacon age-modelling software (http://chrono.qub.ac.uk/blaauw/bacon.html) written by 3 | Maarten Blaauw (maarten.blaauw@qub.ac.uk) and Andres Christen (jac@cimat.mx). 4 | """ 5 | 6 | from .baconwrap import run_baconmcmc 7 | from .calibcurves import fetch_calibcurve 8 | from .utils import calibrate_dates -------------------------------------------------------------------------------- /docs/api-invisible.rst: -------------------------------------------------------------------------------- 1 | .. Generate API reference pages, but don't display these in tables. 2 | .. This extra page is a work around for sphinx not having any support for 3 | .. hiding an autosummary table. Props to xarray for help with this. 4 | 5 | .. currentmodule:: snakebacon 6 | 7 | .. autosummary:: 8 | :toctree: generated/ 9 | 10 | 11 | CalibCurve 12 | DatedProxyRecord 13 | ChronRecord 14 | ProxyRecord 15 | 16 | read_14c 17 | read_chron 18 | read_proxy 19 | 20 | -------------------------------------------------------------------------------- /docs/faq.rst: -------------------------------------------------------------------------------- 1 | Frequently Asked Questions 2 | ========================== 3 | 4 | .. warning:: 5 | 6 | The project is under heavy development. Code and documentation are not complete. 7 | 8 | Where did the name "snakebacon" come from? 9 | ------------------------------------------ 10 | 11 | The heart of the code is based on the C/C++ from the original Bacon, which is based on an interface in R. I was looking 12 | to write something similar in Python, thus "snakebacon" was born. I've kept the name because it makes me smile. -------------------------------------------------------------------------------- /snakebacon/tests/test_chronrecord.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | import numpy as np 4 | 5 | from snakebacon.records import ChronRecord 6 | 7 | 8 | class TestChronRecordMethods(unittest.TestCase): 9 | 10 | @unittest.skip('Test not written. Need methods to test equality.') 11 | def test__repr__(self): 12 | testcore = ChronRecord(age=np.array([20, 50]), error=None, depth=np.array([1.5, 3]), labid=None) 13 | self.assertTrue(testcore == eval(repr(testcore))) 14 | 15 | 16 | if __name__ == '__main__': 17 | unittest.main() 18 | -------------------------------------------------------------------------------- /snakebacon/tests/test_utils.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | import numpy as np 4 | 5 | from snakebacon import suggest_accumulation_rate 6 | from snakebacon.records import ChronRecord 7 | 8 | 9 | class TestUtils(unittest.TestCase): 10 | 11 | def test_suggest_accumulation_rate(self): 12 | goal = 20 13 | testcore = ChronRecord(age=np.array([20, 50]), error=None, depth=np.array([1.5, 3]), labid=None) 14 | test_victim = suggest_accumulation_rate(testcore) 15 | self.assertEqual(test_victim, goal) 16 | 17 | 18 | if __name__ == '__main__': 19 | unittest.main() 20 | -------------------------------------------------------------------------------- /snakebacon/__init__.py: -------------------------------------------------------------------------------- 1 | from .agedepth import AgeDepthModel 2 | from .records import CalibCurve, ChronRecord, ProxyRecord, DatedProxyRecord 3 | from .records import read_14c, read_chron, read_proxy 4 | from .utils import suggest_accumulation_rate 5 | 6 | try: 7 | from .version import version as __version__ 8 | except ImportError: 9 | raise ImportError('snakebacon not properly installed. If you are running from the source directory, please instead ' 10 | 'create a new virtual environment (using conda or virtualenv) and then install it in-place by ' 11 | 'running: pip install -e .') 12 | -------------------------------------------------------------------------------- /snakebacon/utils.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import scipy.stats as stats 3 | 4 | 5 | def suggest_accumulation_rate(chron): 6 | """From core age-depth data, suggest mean accumulation rate (cm/y) 7 | """ 8 | # Follow's Bacon's method @ Bacon.R ln 30 - 44 9 | # Suggested round vals. 10 | sugg = np.tile([1, 2, 5], (4, 1)) * np.reshape(np.repeat([0.1, 1.0, 10, 100], 3), (4, 3)) 11 | # Get ballpark accumulation rates, uncalibrated dates. 12 | ballpacc = stats.linregress(x=chron.depth, y=chron.age * 1.1).slope 13 | ballpacc = np.abs(sugg - ballpacc) 14 | sugg = sugg.flat[ballpacc.argmin()] # Suggest rounded acc.rate with lowest abs diff. 15 | return sugg 16 | 17 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SPHINXPROJ = snakebacon 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | .PHONY: clean 18 | clean: 19 | rm -rf $(BUILDDIR)/* 20 | rm -rf generated/* 21 | rm -rf auto_gallery/ 22 | 23 | # Catch-all target: route all unknown targets to Sphinx using the new 24 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 25 | %: Makefile 26 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | set SPHINXPROJ=snakebacon 13 | 14 | if "%1" == "" goto help 15 | 16 | %SPHINXBUILD% >NUL 2>NUL 17 | if errorlevel 9009 ( 18 | echo. 19 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 20 | echo.installed, then set the SPHINXBUILD environment variable to point 21 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 22 | echo.may add the Sphinx directory to PATH. 23 | echo. 24 | echo.If you don't have Sphinx installed, grab it from 25 | echo.http://sphinx-doc.org/ 26 | exit /b 1 27 | ) 28 | 29 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 30 | goto end 31 | 32 | :help 33 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 34 | 35 | :end 36 | popd 37 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | 2 | 3 | | 4 | 5 | Sediment core age modeling in Python 6 | ==================================== 7 | 8 | .. warning:: 9 | 10 | The project is under heavy development. Code and documentation are not complete. 11 | 12 | 13 | 14 | **snakebacon** is an open source Python package that blah blah 15 | 16 | Our goal is to blah blah blah Bacon_. 17 | 18 | .. _bacon: http://www.chrono.qub.ac.uk/blaauw/bacon.html 19 | 20 | Documentation 21 | ------------- 22 | 23 | .. toctree:: 24 | :maxdepth: 1 25 | 26 | whats_new 27 | faq 28 | examples 29 | installing 30 | io 31 | plots 32 | api 33 | internals 34 | 35 | See also 36 | -------- 37 | 38 | - Look at this list of all the cool things we publish. 39 | 40 | Get in touch 41 | ------------ 42 | 43 | - Report bugs or view the source code `on GitHub`_. 44 | 45 | .. _on GitHub: http://github.com/brews/snakebacon 46 | 47 | License 48 | ------- 49 | snakebacon is available under the open source `GPLv3`__. 50 | 51 | __ http://www.gnu.org/licenses/ 52 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | snakebacon 2 | ========== 3 | 4 | .. image:: https://travis-ci.org/brews/snakebacon.svg?branch=master 5 | :target: https://travis-ci.org/brews/snakebacon 6 | 7 | 8 | The project is currently unmaintained and probably no longer appropriate for production systems. It may eat your hamster. Beware. *Hic sunt dracones.* 9 | 10 | ``snakebacon`` is a Python wrapper around the "Bacon" Bayesian age-depth modelling software `(Blaauw & Christen 2011)`_. 11 | 12 | .. _(Blaauw & Christen 2011): http://dx.doi.org/10.1214%2F11-BA618 13 | 14 | 15 | Acknowledgements and support 16 | ---------------------------- 17 | 18 | C/C++ code in this repository is modified from the original "Bacon" software, available under the GPL-3.0 /GPL-2.0 License. An updated version of "Bacon" is available in R package ``rbacon``, available on CRAN (https://cran.r-project.org/web/packages/rbacon). 19 | 20 | We recommend the ``rbacon`` package if you require similar age-modeling software, as ``rbacon`` is regularly updated and maintained. 21 | 22 | Code in this repository is available under the GPL-3.0 License. 23 | -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/bacon/calibcurves.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | import numpy as np 4 | 5 | from .Curves import here as curvespath 6 | from snakebacon.records import read_14c, CalibCurve 7 | 8 | 9 | available_curves = dict() 10 | 11 | 12 | def fetch_calibcurve(curvename): 13 | """Get CalibCurve from name string""" 14 | f = available_curves[curvename] 15 | return f() 16 | 17 | 18 | def registercurve(curvename): 19 | """Decorator to register functions returning CalibCurves""" 20 | def decor(func): 21 | available_curves[curvename] = func 22 | return func 23 | return decor 24 | 25 | 26 | @registercurve('IntCal13') 27 | def fetch_intcal13(): 28 | return read_14c(os.path.join(curvespath, 'intcal13.14C')) 29 | 30 | 31 | @registercurve('Marine13') 32 | def fetch_marine13(): 33 | return read_14c(os.path.join(curvespath, 'marine13.14C')) 34 | 35 | 36 | @registercurve('SHCal13') 37 | def fetch_shcal13(): 38 | return read_14c(os.path.join(curvespath, 'shcal13.14C')) 39 | 40 | 41 | @registercurve('ConstCal') 42 | def fetch_constcal(): 43 | return CalibCurve(calbp=np.arange(-100, 50000 + 1), 44 | c14age=np.arange(-100, 50000 + 1), 45 | error=np.zeros(50000 + 101)) 46 | -------------------------------------------------------------------------------- /snakebacon/tests/MSB2K.csv: -------------------------------------------------------------------------------- 1 | labID, age, error, depth 2 | GrA-19478, 4128, 65, 1.5 3 | GrA-19143, 4106, 60, 4.5 4 | GrA-19144, 4046, 59, 8.5 5 | GrA-19146, 4184, 58, 12.5 6 | GrA-19147, 4076, 62, 14.5 7 | GrA-19148, 4107, 61, 14.5 8 | GrA-19141, 4097, 58, 14.5 9 | GrA-18675, 4177, 53, 17.5 10 | GrA-19151, 4220, 59, 20.5 11 | GrA-19476, 4281, 64, 21.5 12 | GrA-19475, 4374, 64, 21.5 13 | GrA-19152, 4493, 62, 22.5 14 | GrA-18323, 4452, 52, 28.5 15 | GrA-19474, 4616, 64, 31.5 16 | GrA-19473, 4662, 64, 32.5 17 | GrA-19509, 4743, 67, 33.5 18 | GrA-19480, 4638, 67, 34.5 19 | GrA-19483, 4810, 67, 37.5 20 | GrA-18674, 4757, 82, 38.5 21 | GrA-19153, 4839, 59, 41.5 22 | GrA-19484, 4913, 65, 43.5 23 | GrA-19154, 4880, 57, 46.5 24 | GrA-19485, 4989, 70, 47.5 25 | GrA-19486, 5070, 66, 48.5 26 | GrA-19488, 4993, 67, 49.5 27 | GrA-17626, 5115, 79, 50.5 28 | GrA-18682, 5026, 51, 52.5 29 | GrA-19489, 5242, 64, 53.5 30 | GrA-18679, 5159, 50, 54.5 31 | GrA-19490, 5130, 66, 55.5 32 | GrA-19492, 5238, 65, 58.5 33 | GrA-17501, 5293, 38, 59.5 34 | GrA-18320, 5293, 54, 64.5 35 | GrA-18678, 5368, 51, 70.5 36 | GrA-19494, 5498, 69, 71.5 37 | GrA-18319, 5588, 55, 73.5 38 | GrA-18318, 5514, 57, 75.5 39 | GrA-18688, 5535, 52, 77.5 40 | GrA-17627, 5644, 77, 79.5 41 | GrA-17508, 5885, 45, 99.5 42 | -------------------------------------------------------------------------------- /docs/api.rst: -------------------------------------------------------------------------------- 1 | .. currentmodule:: snakebacon 2 | 3 | ############# 4 | API reference 5 | ############# 6 | 7 | This page is an auto-generated summary of snakebacon's API. 8 | 9 | AgeDepthModel 10 | ============= 11 | 12 | Creating an AgeDepthModel 13 | ------------------------- 14 | 15 | .. autosummary:: 16 | :toctree: generated/ 17 | 18 | AgeDepthModel 19 | 20 | Attributes 21 | ---------- 22 | 23 | CalibCurve 24 | ========== 25 | 26 | Creating a CalibCurve 27 | --------------------- 28 | 29 | .. autosummary:: 30 | :toctree: generated/ 31 | 32 | CalibCurve 33 | read_14c 34 | 35 | 36 | Attributes 37 | ---------- 38 | 39 | DatedProxyRecord 40 | ================ 41 | 42 | Creating a DatedProxyRecord 43 | --------------------------- 44 | 45 | .. autosummary:: 46 | :toctree: generated/ 47 | 48 | DatedProxyRecord 49 | AgeDepthModel.date 50 | 51 | 52 | Attributes 53 | ---------- 54 | 55 | ChronRecord 56 | =========== 57 | 58 | Creating a ChronRecord 59 | ---------------------- 60 | 61 | .. autosummary:: 62 | :toctree: generated/ 63 | 64 | ChronRecord 65 | read_chron 66 | 67 | 68 | Attributes 69 | ---------- 70 | 71 | ProxyRecord 72 | =========== 73 | 74 | Creating a ProxyRecord 75 | ---------------------- 76 | 77 | .. autosummary:: 78 | :toctree: generated/ 79 | 80 | ProxyRecord 81 | read_proxy 82 | 83 | 84 | Attributes 85 | ---------- 86 | -------------------------------------------------------------------------------- /snakebacon/tests/test_datedproxyrecord.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | import numpy as np 4 | import pandas as pd 5 | from pandas.util.testing import assert_frame_equal 6 | 7 | from snakebacon import DatedProxyRecord 8 | 9 | 10 | class TestDatedProxyRecord(unittest.TestCase): 11 | def setUp(self): 12 | self.testdummy_median = DatedProxyRecord(pd.DataFrame({'depth': [1, 2], 'a': [2, 3]}), age=[10, 11]) 13 | self.testdummy_ensemble = DatedProxyRecord(pd.DataFrame({'depth': [1, 2], 'a': [2, 3]}), 14 | age=[[10, 10, 10], [11, 11, 11]]) 15 | 16 | def test_n_members(self): 17 | goal_median = 1 18 | goal_ensemble = 3 19 | self.assertEqual(goal_median, self.testdummy_median.n_members()) 20 | self.assertEqual(goal_ensemble, self.testdummy_ensemble.n_members()) 21 | 22 | def test_to_pandas(self): 23 | goal_median = pd.DataFrame({'a': [2, 3], 'age': [10, 11], 'depth': [1, 2]}) 24 | goal_ensemble = pd.DataFrame({'a': [2, 3] * 3, 'depth': [1, 2] * 3, 25 | 'mciter': np.repeat(np.arange(3), 2), 26 | 'age': [10, 11] * 3, }) 27 | assert_frame_equal(goal_median.sort_index(axis=1), self.testdummy_median.to_pandas().sort_index(axis=1)) 28 | assert_frame_equal(goal_ensemble.sort_index(axis=1), self.testdummy_ensemble.to_pandas().sort_index(axis=1)) 29 | 30 | 31 | if __name__ == '__main__': 32 | unittest.main() 33 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | 3 | compiler: 4 | - clang 5 | 6 | notifications: 7 | email: false 8 | 9 | matrix: 10 | fast_finish: true 11 | include: 12 | - python: 3.5 13 | env: 14 | - CONDA_ENV=py35 15 | - JOB_OS=Linux 16 | - python: 3.6 17 | env: 18 | - CONDA_ENV=py36 19 | - JOB_OS=Linux 20 | - os: osx 21 | language: generic 22 | # python: 3.5 23 | env: 24 | - CONDA_ENV=py35 25 | - JOB_OS=MacOSX 26 | 27 | before_install: 28 | - if [[ "$JOB_OS" == "MacOSX" ]]; then 29 | brew update; 30 | brew upgrade python; 31 | fi 32 | - if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then 33 | wget https://repo.continuum.io/miniconda/Miniconda2-latest-$JOB_OS-x86_64.sh -O miniconda.sh; 34 | else 35 | wget https://repo.continuum.io/miniconda/Miniconda3-latest-$JOB_OS-x86_64.sh -O miniconda.sh; 36 | fi 37 | - bash miniconda.sh -b -p $HOME/miniconda 38 | - export PATH="$HOME/miniconda/bin:$PATH" 39 | - export CC="clang" 40 | - hash -r 41 | - conda config --set always_yes yes --set changeps1 no 42 | - conda update -q conda 43 | # Useful for debugging any issues with conda 44 | - conda info -a 45 | 46 | install: 47 | - conda env create -q -f ci/requirements-$CONDA_ENV.yml 48 | - source activate test_env 49 | - python setup.py build_ext --inplace --include-dirs="$HOME/miniconda/envs/test_env/include" 50 | - python setup.py install --user 51 | 52 | script: 53 | # - python setup.py bdist_wheel 54 | - python -m unittest 55 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | 91 | # PyCharm, Jupyter, and Vim 92 | .idea 93 | *.swp 94 | .DS_Store 95 | .ipynb_checkpoints 96 | 97 | # Documentation 98 | doc/_build 99 | doc/generated 100 | snakebacon/version.py 101 | -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/bacon/ranfun.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #ifndef RANFUN_H 13 | #define RANFUN_H 14 | 15 | 16 | #define min(x, y) ((x) < (y) ? (x) : (y)) 17 | #define max(x, y) ((x) > (y) ? (x) : (y)) 18 | 19 | inline double sqr(double x) { return (x * x); } 20 | 21 | //interface for gsl_compare 22 | // x==y, 0, xy, 1. 23 | int fcmp(double x, double y, double epsilon = 0.00000000001); 24 | 25 | /*Interface with gsl*/ 26 | 27 | /*Available random number generators from gsl 28 | gsl_rng_taus 29 | 30 | see http://sourceware.cygnus.com/gsl/ref/gsl-ref_5.html*/ 31 | 32 | #define GENERATOR gsl_rng_taus 33 | 34 | /*to use inline functions in gsl (in c++)*/ 35 | /*define DHAVE_INLINE at compile time*/ 36 | #ifdef DHAVE_INLINE 37 | #define INLINE inline 38 | #endif 39 | 40 | #ifndef DHAVE_INLINE 41 | #define INLINE /*nothing*/ 42 | #endif 43 | 44 | 45 | void Seed(unsigned long int s); 46 | 47 | unsigned long int GetSeed(); 48 | 49 | double Un01(); /*Un01() */ 50 | 51 | double Unab(double a, double b); /*U(a,b]*/ 52 | 53 | unsigned int Un0n(int n); /*Uniform integer in { 0, 1, ..., n-1 }*/ 54 | 55 | int Sign(); /*random -1 or 1*/ 56 | 57 | double NorSim(double m, double sigma); /*Normal*/ 58 | 59 | double ExpSim(double mu); /*p(x) dx = {1 \over \mu} \exp(-x/\mu) dx*/ 60 | 61 | double GammaSim(double a, double b); /*Gamma: p(x) dx = K x^{a-1} e^{-x/b} dx*/ 62 | double GammaDens(double x, double a, double b); /*density for beta, as above */ 63 | 64 | double BetaSim(double a, double b); /*Beta: p(x) dx = K x^{a-1} (1-x)^{b-1} dx */ 65 | double BetaDens(double x, double a, double b); /*density for beta, as above */ 66 | 67 | unsigned int BiSim(double p, int n); /*Binomial: p^k (1-p)^{n-k} */ 68 | 69 | /*Log of Special function Gamma*/ 70 | 71 | double LogGamma(double x); 72 | 73 | #endif 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/bacon/vector.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * vector.c 3 | * 4 | * 5 | * Created by jac on 29/04/2009. 6 | * 7 | */ 8 | 9 | #include "twalk.h" 10 | 11 | 12 | //--------------------------------------------------------------------------- 13 | // Creates a vector 14 | double *vector(int ncols) { 15 | double *cabeza; 16 | cabeza = (double *) malloc(ncols * sizeof(double)); 17 | 18 | return cabeza; 19 | } 20 | 21 | 22 | //--------------------------------------------------------------------------- 23 | // Destroys a vector 24 | void free_vector(double *cabeza) { /*free((void *) cabeza);*/ } 25 | //--------------------------------------------------------------------------- 26 | 27 | 28 | void fver_vector(FILE *fptr, double *u, int m) { 29 | fprintf(fptr, "\n"); 30 | for (int i = 0; i < m; i++) 31 | fprintf(fptr, "\t%13.6g", u[i]); 32 | } 33 | 34 | /*Returns 1 if v = u, component to component*/ 35 | int vector_cmp(double *v, double *u, int n) { 36 | int i = 0; 37 | while ((fcmp(v[i], u[i]) == 0) && (i < n)) 38 | i++; 39 | 40 | if (i == n) 41 | return 1; 42 | else 43 | return 0; 44 | } 45 | 46 | //copia vector v1 en v2 47 | void cp_vector(double *v1, double *v2, int n) { 48 | for (int k = 0; k < n; k++) 49 | v2[k] = v1[k]; 50 | 51 | } 52 | 53 | //--------------------------------------------------------------------------- 54 | void resta_vector(double *v1, double *v2, int n, double *res) { 55 | for (int k = 0; k < n; k++) { 56 | res[k] = v1[k] - v2[k]; 57 | } 58 | } 59 | 60 | /*encuentra el maximo ai en valor abs de una vector y devuelve su indice*/ 61 | void indice_max_vector(double *v, int n, int &indice, int *phi) { 62 | 63 | indice = 0; 64 | 65 | for (int i = 0; i < n; i++) /// A < B 66 | indice = ((fcmp(phi[indice] * fabs(v[indice]), phi[i] * fabs(v[i])) == -1) ? i : indice); 67 | // return indice; 68 | 69 | } 70 | 71 | 72 | int sum(int *v, int n) { 73 | int summ = 0; 74 | for (int i = 0; i < n; i++) 75 | summ += v[i]; 76 | 77 | return summ; 78 | } 79 | -------------------------------------------------------------------------------- /snakebacon/mcmc.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | import numpy as np 4 | 5 | import snakebacon.mcmcbackends 6 | from snakebacon.records import ChronRecord 7 | 8 | 9 | log = logging.getLogger(__name__) 10 | 11 | 12 | class McmcSetup: 13 | def __init__(self, coredates, mcmcbackend=snakebacon.mcmcbackends.Bacon, **kwargs): 14 | self.coredates = ChronRecord(coredates) 15 | self.mcmc_kws = kwargs 16 | self.mcmcbackend = mcmcbackend 17 | 18 | def prior_dates(self): 19 | """Get the prior distribution of radiocarbon dates""" 20 | return self.mcmcbackend.prior_dates(self.coredates, **self.mcmc_kws) 21 | 22 | def prior_sediment_rate(self): 23 | """Get the prior distribution of sediment rates""" 24 | return self.mcmcbackend.prior_sediment_rate(self.coredates, **self.mcmc_kws) 25 | 26 | def prior_sediment_memory(self): 27 | """Get the prior distribution of sediment memory""" 28 | return self.mcmcbackend.prior_sediment_memory(self.coredates, **self.mcmc_kws) 29 | 30 | def validate(self): 31 | """Validate configs for mcmc run""" 32 | # TODO(brews): Write mcmc config validation 33 | pass 34 | 35 | def run(self): 36 | self.validate() 37 | return McmcResults(self) 38 | 39 | 40 | class McmcResults: 41 | def __init__(self, setup): 42 | mcmcout = setup.mcmcbackend.runmcmc(core_labid=setup.coredates.labid, 43 | core_age=setup.coredates.age, 44 | core_error=setup.coredates.error, 45 | core_depth=setup.coredates.depth, 46 | **setup.mcmc_kws) 47 | self.depth_segments = np.linspace(setup.mcmc_kws['depth_min'], setup.mcmc_kws['depth_max'], 48 | setup.mcmc_kws['k']) 49 | self.headage = mcmcout['theta'] 50 | self.sediment_rate = mcmcout['x'] 51 | self.sediment_memory = mcmcout['w'] 52 | self.objective = mcmcout['objective'] 53 | 54 | def burnin(self, n): 55 | """Remove the earliest n ensemble members from the MCMC output""" 56 | self.sediment_rate = self.sediment_rate[:, n:] 57 | self.headage = self.headage[n:] 58 | self.sediment_memory = self.sediment_memory[n:] 59 | self.objective = self.objective[n:] 60 | 61 | def n_members(self): 62 | """Get number of MCMC ensemble members in results""" 63 | return len(self.objective) 64 | 65 | def plot(self): 66 | # TODO(brews): Write function to plot raw Mcmc results. 67 | pass 68 | -------------------------------------------------------------------------------- /snakebacon/tests/test_mcmcbackend_bacon.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import os 3 | 4 | import numpy as np 5 | 6 | from snakebacon.mcmcbackends import Bacon 7 | from snakebacon import read_chron 8 | 9 | 10 | here = os.path.abspath(os.path.dirname(__file__)) 11 | 12 | 13 | class TestBaconMethods(unittest.TestCase): 14 | 15 | def setUp(self): 16 | self.mcmc_kws = dict(depth_min=1.5, depth_max=99.5, cc=[1], 17 | cc1='IntCal13', cc2='Marine13', cc3='SHCal13', cc4='ConstCal', 18 | d_r=[0], d_std=[0], t_a=[3], t_b=[4], k=20, 19 | minyr=-1000, maxyr=1e6, th01=4147, th02=4145, 20 | acc_mean=20, acc_shape=1.5, mem_strength=4, mem_mean=0.7) 21 | 22 | def test_prior_dates(self): 23 | pgoal_age_mean = 6726.8 24 | pgoal_age_std = 192.94564322687978 25 | 26 | pgoal_density_mean = 0.011642671907680679 27 | pgoal_density_std = 0.010893804880746285 28 | 29 | dgoal = np.array([77.5, 79.5, 99.5]) 30 | dgoal_n = 40 31 | pgoal_n = dgoal_n 32 | 33 | chron = read_chron(os.path.join(here, 'MSB2K.csv')) 34 | d_target, p_target = Bacon.prior_dates(chron, **self.mcmc_kws) 35 | np.testing.assert_allclose(d_target[-3:], dgoal) 36 | np.testing.assert_equal(len(d_target), dgoal_n) 37 | 38 | np.testing.assert_allclose(np.mean(p_target[-1][:, 0]), pgoal_age_mean, atol=7) 39 | np.testing.assert_allclose(np.std(p_target[-1][:, 0]), pgoal_age_std, atol=2) 40 | np.testing.assert_equal(len(p_target), pgoal_n) 41 | 42 | np.testing.assert_allclose(np.mean(p_target[-1][:, 1]), pgoal_density_mean, atol=1e-2) 43 | np.testing.assert_allclose(np.std(p_target[-1][:, 1]), pgoal_density_std, atol=1e-2) 44 | 45 | def test_prior_sediment_rate(self): 46 | np.random.seed(123) 47 | 48 | goal_mean = 0.008194080517375957 49 | goal_std = 0.01172658825323754 50 | goal_n = 100 51 | 52 | victim, x = Bacon.prior_sediment_rate(**self.mcmc_kws) 53 | 54 | np.testing.assert_equal(len(victim), goal_n) 55 | np.testing.assert_allclose(victim.mean(), goal_mean, atol=1e-3) 56 | np.testing.assert_allclose(victim.std(), goal_std, atol=1e-3) 57 | 58 | def test_prior_sediment_memory(self): 59 | np.random.seed(123) 60 | 61 | goal_mean = 0.98457848264590286 62 | goal_std = 0.71613816177236256 63 | goal_n = 100 64 | 65 | victim, x = Bacon.prior_sediment_memory(**self.mcmc_kws) 66 | 67 | np.testing.assert_equal(len(victim), goal_n) 68 | np.testing.assert_allclose(victim.mean(), goal_mean, atol=1e-3) 69 | np.testing.assert_allclose(victim.std(), goal_std, atol=1e-3) 70 | 71 | 72 | if __name__ == '__main__': 73 | unittest.main() 74 | -------------------------------------------------------------------------------- /snakebacon/tests/test_mcmc.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from copy import deepcopy 3 | from os import path 4 | 5 | import numpy as np 6 | 7 | from snakebacon import read_chron 8 | from snakebacon.mcmc import McmcResults, McmcSetup 9 | 10 | 11 | here = path.abspath(path.dirname(__file__)) 12 | 13 | 14 | mcmc_kws = dict(depth_min=1.5, depth_max=99.5, cc=[1], 15 | cc1='IntCal13', cc2='Marine13', cc3='SHCal13', cc4='ConstCal', 16 | d_r=[0], d_std=[0], t_a=[3], t_b=[4], k=20, 17 | minyr=-1000, maxyr=1e6, th01=4147, th02=4145, 18 | acc_mean=20, acc_shape=1.5, mem_strength=4, mem_mean=0.7) 19 | fullrun_setup = McmcSetup(read_chron(path.join(here, 'MSB2K.csv')), **mcmc_kws) 20 | fullrun_victim = McmcResults(fullrun_setup) 21 | 22 | 23 | class TestMcmcResults(unittest.TestCase): 24 | def setUp(self): 25 | self.testdummy = deepcopy(fullrun_victim) 26 | 27 | def test_init(self): 28 | niter_goal = 3432 29 | nsegs_goal = 20 30 | objective_mean_goal = 218.26212744522144 31 | theta_mean_goal = 4549.6406701631704 32 | w_mean_goal = 0.06277018029195805 33 | x0_mean_goal = 14.487713009032634 34 | xneg1_mean_goal = 15.65397709810606 35 | # Fuzzy to deal with vars across platforms. 36 | np.testing.assert_allclose(len(self.testdummy.headage), niter_goal, atol=50) 37 | np.testing.assert_allclose(len(self.testdummy.sediment_memory), niter_goal, atol=50) 38 | np.testing.assert_allclose(len(self.testdummy.sediment_rate[0]), niter_goal, atol=50) 39 | np.testing.assert_allclose(len(self.testdummy.sediment_rate[-1]), niter_goal, atol=50) 40 | self.assertEqual(nsegs_goal, len(self.testdummy.sediment_rate)) 41 | np.testing.assert_allclose(self.testdummy.objective.mean(), objective_mean_goal, atol=1e-1) 42 | np.testing.assert_allclose(self.testdummy.headage.mean(), theta_mean_goal, atol=15) 43 | np.testing.assert_allclose(self.testdummy.sediment_memory.mean(), w_mean_goal, atol=1e-2) 44 | np.testing.assert_allclose(self.testdummy.sediment_rate[0].mean(), x0_mean_goal, atol=2) 45 | np.testing.assert_allclose(self.testdummy.sediment_rate[-1].mean(), xneg1_mean_goal, atol=2) 46 | 47 | def test_n_members(self): 48 | n_goal = 3432 49 | n = self.testdummy.n_members() 50 | # Fuzzy to deal with vars across platforms. 51 | np.testing.assert_allclose(n, n_goal, atol=50) 52 | 53 | def test_burnin(self): 54 | n_goal = 3432 - 200 55 | self.testdummy.burnin(n=200) 56 | # Fuzzy to deal with vars across platforms. 57 | np.testing.assert_allclose(len(self.testdummy.headage), n_goal, atol=50) 58 | np.testing.assert_allclose(len(self.testdummy.sediment_memory), n_goal, atol=50) 59 | np.testing.assert_allclose(len(self.testdummy.sediment_rate[0]), n_goal, atol=50) 60 | 61 | 62 | if __name__ == '__main__': 63 | unittest.main() 64 | -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/bacon/input.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | //This class implements the input system for all parameters 7 | //It reads the configuration file and hold all input needed for 8 | //the Bacon clasess. 9 | 10 | 11 | #ifndef INPUT_H 12 | #define INPUT_H 13 | 14 | 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "cal.h" 22 | #include "bacon.h" 23 | #include "ranfun.h" 24 | 25 | //Maximum number of parameters in a lines in the input program 26 | #define MAXNUMOFPARS 20 27 | 28 | //Maximum number of hiatuses 29 | #define MAXNUMOFHIATUS 10 30 | 31 | class Input { 32 | 33 | private: 34 | 35 | Cal **curves; //array with the determinations 36 | 37 | int numofcurves; //current number of c. curves 38 | int maxnumofcurves; //Maximum number of c. curves 39 | 40 | char *buff; //Buffer to hold the parameter line 41 | 42 | int maxnumofpars; 43 | int numofpars; 44 | char **pars; //Pointers to each parameter 45 | 46 | double *rpars; //array of double to read parameters 47 | 48 | int GetPars(); 49 | 50 | int K; //Number of sections 51 | 52 | int H; //Number of hiatuses 53 | double **hiatus_pars; //location for the hiatuses and prior parameters 54 | 55 | double th0; //Initial values for theta0 56 | double thp0; 57 | 58 | Dets *dets; //these are the determinations 59 | 60 | BaconFix *bacon; 61 | 62 | twalk *BaconTwalk; 63 | 64 | 65 | public: 66 | 67 | Input(char *datafile, int maxnumofcurves, int maxm); 68 | 69 | //Run the twalk simulation, put the output in outputfnam 70 | void RunTwalk(char *outputfnam, int it, int save_every, char *mode= (char *) "w+", int silent=0) { 71 | 72 | /*In this case, only the accepted iterations are needed, 73 | include the DEFS = -DSAVEACCONLY line in the makefile*/ 74 | 75 | BaconTwalk->simulation( it, outputfnam, mode, save_every, bacon->Getx0(), bacon->Getxp0(), silent=silent); 76 | 77 | } 78 | 79 | const char *GetLabNum(int j) { return dets->labnm(j); } 80 | int GetNumDets(void) { return dets->Size(); } 81 | 82 | double GetDetY( int j) { return dets->y(j); } 83 | double GetDetSd( int j) { return dets->sd(j); } 84 | double GetDetTh( int j) { return bacon->G(dets->d(j)); } 85 | 86 | double SetDetY( int j, double y) { return dets->SetY( j, y); } 87 | double SetDetSd( int j, double sd) { return dets->SetSd( j, sd); } 88 | 89 | //Returns the dimension, total number of parameters 90 | int Dim() { return bacon->get_dim(); } 91 | 92 | //Print number of warnings 93 | void PrintNumWarnings() { return bacon->PrintNumWarnings(); } 94 | 95 | 96 | double Getc0() { return bacon->Getc0(); } 97 | double GetcK() { return bacon->GetcK(); } 98 | int GetK() { return K; } 99 | 100 | /*void PrintCal( FILE *F, double c0, double cK, double by, const double *x) { 101 | 102 | bacon->SetThetas(x); 103 | for (double d=c0; d<=cK; d += by) 104 | fprintf( F, "%6.1f ", bacon->G( d, x)); 105 | fprintf( F, "\n"); 106 | 107 | }*/ 108 | 109 | }; 110 | 111 | 112 | 113 | #endif 114 | 115 | 116 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from Cython.Build import cythonize 4 | from setuptools import setup, find_packages 5 | from setuptools.extension import Extension 6 | 7 | MAJOR = 0 8 | MINOR = 0 9 | MICRO = 6 10 | VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO) 11 | FULLVERSION = VERSION 12 | 13 | 14 | def readme(): 15 | with open('README.rst') as f: 16 | return f.read() 17 | 18 | 19 | def write_version_py(filename=None): 20 | cnt = """\ 21 | version = '%s' 22 | short_version = '%s' 23 | """ 24 | if not filename: 25 | filename = os.path.join( 26 | os.path.dirname(__file__), 'snakebacon', 'version.py') 27 | 28 | a = open(filename, 'w') 29 | try: 30 | a.write(cnt % (FULLVERSION, VERSION)) 31 | finally: 32 | a.close() 33 | 34 | write_version_py() 35 | 36 | bacon = Extension("snakebacon.mcmcbackends.bacon.baconwrap", 37 | sources=["snakebacon/mcmcbackends/bacon/baconwrap.pyx", 38 | "snakebacon/mcmcbackends/bacon/input.cpp", 39 | "snakebacon/mcmcbackends/bacon/Matrix.cpp", 40 | "snakebacon/mcmcbackends/bacon/ranfun.cpp", 41 | "snakebacon/mcmcbackends/bacon/vector.cpp", 42 | "snakebacon/mcmcbackends/bacon/kernel.cpp"], 43 | language="c++", 44 | libraries=["gsl", "openblas"], 45 | # Below for clang, need -fopenmp if using gcc 46 | extra_compile_args=["-xc++", "-lstdc++", "-shared-libgcc", "-O2"], 47 | ) 48 | 49 | setup_kwargs = dict(name='snakebacon', 50 | version=FULLVERSION, 51 | description='snakebacon', 52 | long_description=readme(), 53 | url='https://github.com/brews/snakebacon', 54 | author='S. Brewster Malevich', 55 | author_email='malevich@email.arizona.edu', 56 | license='GPLv3', 57 | classifiers=[ 58 | 'Development Status :: 3 - Alpha', 59 | 60 | 'Operating System :: POSIX', 61 | 62 | 'Intended Audience :: Developers', 63 | 'Intended Audience :: Science/Research', 64 | 65 | 'Topic :: Scientific/Engineering', 66 | 'Topic :: Software Development', 67 | 68 | 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', 69 | 70 | 'Programming Language :: Python :: 3'], 71 | keywords='marine radiocarbon c14', 72 | install_requires=['numpy', 'Cython', 'pandas', 'matplotlib', 'scipy'], 73 | packages=find_packages(), 74 | package_data={'snakebacon': ['tests/*.csv', 'mcmcbackends/bacon/Curves/*.14C']}, 75 | ) 76 | 77 | # Deal with bad linking bug with conda in readthedocs builds. 78 | if os.environ.get('READTHEDOCS') != 'True': 79 | setup_kwargs['ext_modules'] = cythonize([bacon]) 80 | 81 | setup(**setup_kwargs) 82 | -------------------------------------------------------------------------------- /environment.yml: -------------------------------------------------------------------------------- 1 | name: snakebacon 2 | channels: 3 | - conda-forge 4 | - defaults 5 | dependencies: 6 | - alabaster=0.7.10=py36_0 7 | - args=0.1.0=py36_0 8 | - asn1crypto=0.22.0=py36_0 9 | - babel=2.3.4=py36_0 10 | - blas=1.1=openblas 11 | - ca-certificates=2017.4.17=0 12 | - certifi=2017.4.17=py36_0 13 | - cffi=1.10.0=py36_0 14 | - chardet=3.0.2=py36_1 15 | - clint=0.5.1=py36_0 16 | - cryptography=1.9=py36_0 17 | - cycler=0.10.0=py36_0 18 | - cython=0.25.2=py36_1 19 | - dbus=1.10.10=3 20 | - decorator=4.0.11=py36_0 21 | - docutils=0.13.1=py36_0 22 | - expat=2.2.1=0 23 | - flake8=3.3.0=py36_0 24 | - fontconfig=2.12.1=4 25 | - freetype=2.7=1 26 | - gettext=0.19.7=1 27 | - glib=2.51.4=0 28 | - gmp=6.1.2=0 29 | - gsl=2.2.1=blas_openblas_2 30 | - icu=58.1=1 31 | - idna=2.5=py36_0 32 | - imagesize=0.7.1=py36_0 33 | - ipython=6.1.0=py36_0 34 | - ipython_genutils=0.2.0=py36_0 35 | - jedi=0.10.0=py36_0 36 | - jinja2=2.9.5=py36_0 37 | - joblib=0.11=py36_0 38 | - jpeg=9b=0 39 | - libffi=3.2.1=3 40 | - libgpuarray=0.6.8=0 41 | - libiconv=1.14=4 42 | - libpng=1.6.28=0 43 | - libxcb=1.12=1 44 | - libxml2=2.9.4=4 45 | - mako=1.0.6=py36_0 46 | - markupsafe=1.0=py36_0 47 | - matplotlib=2.0.2=np113py36_0 48 | - mccabe=0.6.1=py36_0 49 | - mpc=1.0.3=4 50 | - mpfr=3.1.5=0 51 | - ncurses=5.9=10 52 | - nose=1.3.7=py36_2 53 | - numpy=1.13.1=py36_blas_openblas_200 54 | - numpydoc=0.7.0=py36_0 55 | - openblas=0.2.19=2 56 | - openssl=1.0.2l=0 57 | - packaging=16.8=py36_0 58 | - pandas=0.20.2=np113py36_1 59 | - patsy=0.4.1=py36_0 60 | - pcre=8.39=0 61 | - pexpect=4.2.1=py36_0 62 | - pickleshare=0.7.3=py36_0 63 | - pip=9.0.1=py36_0 64 | - pkginfo=1.2.1=py36_0 65 | - prompt_toolkit=1.0.14=py36_0 66 | - ptyprocess=0.5.2=py36_0 67 | - py=1.4.34=py36_0 68 | - pycodestyle=2.3.1=py36_0 69 | - pycparser=2.18=py36_0 70 | - pyflakes=1.5.0=py36_0 71 | - pygments=2.2.0=py36_0 72 | - pygpu=0.6.8=np113py36_0 73 | - pyopenssl=16.2.0=py36_0 74 | - pyparsing=2.2.0=py36_0 75 | - pysocks=1.6.7=py36_0 76 | - pytest=3.1.3=py36_0 77 | - python=3.6.1=3 78 | - python-dateutil=2.6.0=py36_0 79 | - pytz=2017.2=py36_0 80 | - readline=6.2=0 81 | - requests=2.18.1=py36_0 82 | - requests-toolbelt=0.8.0=py36_0 83 | - scipy=0.19.1=np113py36_blas_openblas_200 84 | - setuptools=33.1.1=py36_0 85 | - simplegeneric=0.8.1=py36_0 86 | - sip=4.18=py36_1 87 | - six=1.10.0=py36_1 88 | - snowballstemmer=1.2.1=py36_0 89 | - sphinx=1.6.3=py36_0 90 | - sphinx_rtd_theme=0.2.4=py36_0 91 | - sphinxcontrib-websupport=1.0.1=py36_0 92 | - sqlite=3.13.0=1 93 | - theano=0.9.0=py36_1 94 | - tk=8.5.19=1 95 | - tornado=4.5.1=py36_0 96 | - tqdm=4.14.0=py36_0 97 | - traitlets=4.3.2=py36_0 98 | - twine=1.8.1=py36_1 99 | - typing=3.6.1=py36_0 100 | - urllib3=1.21.1=py36_1 101 | - wcwidth=0.1.7=py36_0 102 | - wheel=0.29.0=py36_0 103 | - xorg-libxau=1.0.8=3 104 | - xorg-libxdmcp=1.1.2=3 105 | - xz=5.2.2=0 106 | - zlib=1.2.11=0 107 | - cloog=0.18.0=0 108 | - gcc=4.8.5=7 109 | - isl=0.12.2=0 110 | - libgcc=5.2.0=0 111 | - libgfortran=3.0.0=1 112 | - pip: 113 | - ipython-genutils==0.2.0 114 | - prompt-toolkit==1.0.14 115 | - sphinx-rtd-theme==0.2.4 116 | prefix: /home/sbm/miniconda3/envs/snakebacon 117 | 118 | -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/bacon/Matrix.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Matrix.c 3 | * 4 | * 5 | * Created by jac on 17/04/2007. 6 | * Copyright 2007 __MyCompanyName__. All rights reserved. 7 | * 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | #include "Matrix.h" 14 | 15 | 16 | /*Auxiliary functions*/ 17 | //C = A^trA B^trB 18 | int MatMul(Matrix &C, int trA, Matrix &A, int trB, Matrix &B) { 19 | 20 | CBLAS_TRANSPOSE_t TransA = ((trA == 0) ? CblasNoTrans : CblasTrans); 21 | CBLAS_TRANSPOSE_t TransB = ((trB == 0) ? CblasNoTrans : CblasTrans); 22 | 23 | return gsl_blas_dgemm(TransA, TransB, 1.0, A.Ma(), B.Ma(), 0.0, C.Ma()); 24 | } 25 | 26 | 27 | int MatMul(Matrix &C, Matrix &A, Matrix &B) { 28 | 29 | return gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, A.Ma(), B.Ma(), 0.0, C.Ma()); 30 | } 31 | 32 | 33 | /*Cuad. Form C = b^T A b*/ 34 | double CuadForm(Matrix &A, Matrix &b) { 35 | 36 | //Make the auxiliar (vector) matrix 37 | Matrix Aux(A.nRow()); 38 | Matrix res(1); 39 | 40 | gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, A.Ma(), b.Ma(), 0.0, Aux.Ma()); 41 | gsl_blas_dgemm(CblasTrans, CblasNoTrans, 1.0, b.Ma(), Aux.Ma(), 0.0, res.Ma()); 42 | 43 | return res(0); 44 | } 45 | 46 | 47 | int MatMulSym(Matrix &C, Matrix &A, Matrix &B) { 48 | 49 | return gsl_blas_dsymm(CblasLeft, CblasUpper, 1.0, A.Ma(), B.Ma(), 0.0, C.Ma()); 50 | } 51 | 52 | //inverse of real (symmetric) positive defined matrix 53 | //as a by-product we may obtain the square root of the determinant of A 54 | int InvRPD(Matrix &R, Matrix &A, double *LogDetSqrt, Matrix *ExternChol) { 55 | 56 | assert(A.nRow() == A.nCol()); 57 | assert(R.nRow() == R.nCol()); 58 | assert(A.nRow() == R.nCol()); 59 | 60 | Matrix *Chol; 61 | //Make the auxiliar matrix equal to A 62 | if (ExternChol == NULL) 63 | Chol = new Matrix(A.nRow(), A.nCol()); 64 | else 65 | Chol = ExternChol; 66 | 67 | R.Iden(); //Make R the identity 68 | 69 | Chol->copy(A); 70 | 71 | //Chol->print("A=\n"); 72 | 73 | gsl_error_handler_t *hand = gsl_set_error_handler_off(); 74 | int res = gsl_linalg_cholesky_decomp(Chol->Ma()); 75 | gsl_set_error_handler(hand); 76 | 77 | if (res == GSL_EDOM) { 78 | //printf("Matrix::InvRPD: Warning: Non positive definite matrix.\n"); //exit(0); 79 | 80 | return 0; 81 | } 82 | 83 | assert(res != GSL_EDOM); //Check that everything went well 84 | 85 | 86 | //solve for the cannonical vectors to obtain the inverse in R 87 | for (int i = 0; i < R.nRow(); i++) { 88 | //R.print("R=\n"); 89 | gsl_linalg_cholesky_svx(Chol->Ma(), R.AsColVec(i)); 90 | } 91 | 92 | if (LogDetSqrt != NULL) { 93 | *LogDetSqrt = 0.0; 94 | for (int i = 0; i < Chol->nRow(); i++) { 95 | *LogDetSqrt += log(Chol->ele(i, i)); //multiply the diagonal elements 96 | } 97 | } 98 | 99 | if (ExternChol == NULL) 100 | delete Chol; 101 | 102 | return 1; 103 | } 104 | 105 | 106 | //I have seen problems with this when dest and src are rows or cls of the same matrix 107 | int VecCopy(gsl_vector *dest, const gsl_vector *src) { 108 | 109 | assert(dest->size == src->size); 110 | 111 | return gsl_vector_memcpy(dest, src); 112 | } 113 | 114 | -------------------------------------------------------------------------------- /docs/whats_new.rst: -------------------------------------------------------------------------------- 1 | .. currentmodule:: snakebacon 2 | 3 | What's New 4 | ========== 5 | 6 | .. _whats-new.0.0.7: 7 | 8 | v0.0.7 9 | ------ 10 | 11 | Minor patch. 12 | 13 | Enhancements 14 | ~~~~~~~~~~~~ 15 | - 16 | 17 | Bug fixes 18 | ~~~~~~~~~ 19 | - 20 | 21 | .. _whats-new.0.0.6: 22 | 23 | v0.0.6 24 | ------ 25 | 26 | Patch for a minor but annoying bug. 27 | 28 | Bug fixes 29 | ~~~~~~~~~ 30 | - Fix minor bug where certain min and max depths could cause an IndexError (`Issue #20 `_). 31 | 32 | 33 | .. _whats-new.0.0.5: 34 | 35 | v0.0.5 36 | ------ 37 | 38 | Minor patch mostly fixing compile issues and documentation. 39 | 40 | Bug fixes 41 | ~~~~~~~~~ 42 | - Documentation spelling errors. 43 | - Fixed bad compiling C++ module (`Issue #19 `_). 44 | 45 | 46 | .. _whats-new.0.0.4: 47 | 48 | v0.0.4 49 | ------ 50 | 51 | A patch with minor refactoring and bug fixes. 52 | 53 | Bug fixes 54 | ~~~~~~~~~ 55 | - All *_kwargs arguments are now *_kws (`Issue #12 `_). 56 | 57 | - Fixed some Constant Calibration curve prior dates looking bloated (`Issue #14 `_). 58 | 59 | - Fixed bug from default `t_a` and `t_b` values in `calibrate_dates()` (`Issue #13 `_) 60 | 61 | - Fixed bad label in prior accumulation memory plots. The 'thick' had been 'K'. This has been corrected. 62 | 63 | - Fix AttributeError in AgeDepthModel.plot_prior_dates() (`Issue #9 `_). 64 | 65 | 66 | .. _whats-new.0.0.3: 67 | 68 | v0.0.3 69 | ------ 70 | 71 | A quick patch to fix a show-stopping bug. 72 | 73 | Bug fixes 74 | ~~~~~~~~~ 75 | - Fixes missing curves for bacon MCMC fitting (`Issue #7 `_). 76 | 77 | 78 | .. _whats-new.0.0.2: 79 | 80 | v0.0.2 81 | ------ 82 | 83 | Enhancements 84 | ~~~~~~~~~~~~ 85 | - DateRecord class has been renamed ChronRecord to avoid confusion with DatedProxyRecord (`Issue #3 `_). The read_chron() is also now read_chron(). 86 | 87 | - AgeDepthModels now can plot prior distributions. 88 | 89 | - Can now query AgeDepthModels to get prior distribution for chronology dates, sediment rates, and sediment rate memory (`Issue #5 `_). 90 | 91 | - Now can use snakebacon.mcmcbackends.bacon.fetch_calibcurve() and the @registercurve() decorator to define and fetch calibration curves by name (`Issue #6 `_). 92 | 93 | - McmcSetup and McmcResults now throw bacon its tasks through mcmcbackends.Bacon. This should make snakebacon more bacon-agnostic. Have a look at McmcSetup's mcmcbackend arg. 94 | 95 | - suggest_accumulation_rate() is no longer a method, but a humble function. 96 | 97 | Bug fixes 98 | ~~~~~~~~~ 99 | - Fixed common AssertionError in AgeDepthModel.agedepth caused by float precision bug (`Issue #4 `_). 100 | 101 | - Fixed problem with ProxyRecords and DatedProxyRecords not making copies of Pandas DataFrame attributes. (`Issue #2 `_). 102 | 103 | 104 | .. _whats-new.0.0.1: 105 | 106 | v0.0.1 107 | ------ 108 | 109 | This is the initial, alpha release of snakebacon. 110 | -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/__init__.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import scipy.stats as stats 3 | 4 | from .bacon import run_baconmcmc, fetch_calibcurve, calibrate_dates 5 | 6 | 7 | class Bacon: 8 | def runmcmc(*args, **kwargs): 9 | return run_baconmcmc(*args, **kwargs) 10 | 11 | def prior_dates(*args, **kwargs): 12 | """Get the prior distribution of calibrated radiocarbon dates""" 13 | try: 14 | chron = args[0] 15 | except IndexError: 16 | chron = kwargs['coredates'] 17 | 18 | d_r = np.array(kwargs['d_r']) 19 | d_std = np.array(kwargs['d_std']) 20 | t_a = np.array(kwargs['t_a']) 21 | t_b = np.array(kwargs['t_b']) 22 | 23 | try: 24 | normal_distr = kwargs['normal_distr'] 25 | except KeyError: 26 | normal_distr = None 27 | 28 | cc_int = kwargs['cc'] 29 | 30 | ccdict = {0: 'ConstCal', 1: 'IntCal3', 2: 'Marine13', 31 | 3: 'SHCal13', 4: 'ConstCal'} 32 | # There is a better way to do this. 33 | if 'cc1' in kwargs: 34 | ccdict[1] = str(kwargs['cc1']) 35 | if 'cc2' in kwargs: 36 | ccdict[2] = str(kwargs['cc2']) 37 | if 'cc3' in kwargs: 38 | ccdict[3] = str(kwargs['cc3']) 39 | if 'cc4' in kwargs: 40 | ccdict[4] = str(kwargs['cc4']) 41 | 42 | cc = [] 43 | for i in cc_int: 44 | i = int(i) 45 | cc.append(fetch_calibcurve(ccdict[i])) 46 | 47 | d, p = calibrate_dates(chron, calib_curve=cc, d_r=d_r, d_std=d_std, 48 | t_a=t_a, t_b=t_b, normal_distr=normal_distr) 49 | return d, p 50 | 51 | 52 | def prior_sediment_rate(*args, **kwargs): 53 | """Get the prior density of sediment rates 54 | 55 | Returns 56 | ------- 57 | y : ndarray 58 | Array giving the density. 59 | x : ndarray 60 | Array of sediment accumulation values (yr/cm) over which the density was evaluated. 61 | """ 62 | # PlotAccPrior @ Bacon.R ln 113 -> ln 1097-1115 63 | # alpha = acc_shape, beta = acc_shape / acc_mean 64 | # TODO(brews): Check that these stats are correctly translated to scipy.stats distribs. 65 | acc_mean = kwargs['acc_mean'] 66 | acc_shape = kwargs['acc_shape'] 67 | x = np.linspace(0, 6 * np.max(acc_mean), 100) 68 | y = stats.gamma.pdf(x, a=acc_shape, 69 | scale=1 / (acc_shape/acc_mean)) 70 | return y, x 71 | 72 | 73 | def prior_sediment_memory(*args, **kwargs): 74 | """Get the prior density of sediment memory 75 | 76 | Returns 77 | ------- 78 | y : ndarray 79 | Array giving the density. 80 | x : ndarray 81 | Array of Memory (ratio) values over which the density was evaluated. 82 | """ 83 | # "plot the prior for the memory (= accumulation rate varibility between neighbouring depths)" 84 | # PlotMemPrior @ Bacon.R ln 114 -> ln 1119 - 1141 85 | # w_a = mem_strength * mem_mean, w_b = mem_strength * (1 - mem_mean) 86 | # TODO(brews): Check that these stats are correctly translated to scipy.stats distribs. 87 | mem_shape = kwargs['mem_strength'] # aka. `mem_shape` 88 | mem_mean = kwargs['mem_mean'] 89 | x = np.linspace(0, 1, 100) 90 | y = stats.beta.pdf(x, a=mem_shape * mem_mean, 91 | b=mem_shape * (1 - mem_mean)) 92 | return y, x 93 | 94 | -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/bacon/ranfun.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************************** 2 | * Pseudo-random numbers routines (extracted from GSL ) 3 | * 4 | * cpptwalk-beta-1.0 5 | * July 2006 6 | * 7 | ********************************************************************************************/ 8 | 9 | 10 | #include 11 | #include "ranfun.h" 12 | 13 | /* interface for gsl_compare */ 14 | int fcmp(double x, double y, double epsilon) { 15 | 16 | return gsl_fcmp(x, y, epsilon); 17 | } 18 | 19 | 20 | static gsl_rng *r; /*static reference to the generator*/ 21 | static unsigned long int sd = 0; /*static reference to the seed*/ 22 | 23 | 24 | void Seed(unsigned long int s) { 25 | /*This chooses the generator to be used ("taus") 26 | This is a maximally equidistributed combined Tausworthe generator by L'Ecuyer. The sequence is, 27 | 28 | x_n = (s1_n ^^ s2_n ^^ s3_n) 29 | 30 | where, 31 | 32 | s1_{n+1} = (((s1_n&4294967294)<<12)^^(((s1_n<<13)^^s1_n)>>19)) 33 | s2_{n+1} = (((s2_n&4294967288)<< 4)^^(((s2_n<< 2)^^s2_n)>>25)) 34 | s3_{n+1} = (((s3_n&4294967280)<<17)^^(((s3_n<< 3)^^s3_n)>>11)) 35 | 36 | computed modulo 2^32. In the formulas above ^^ denotes "exclusive-or". 37 | Note that the algorithm relies on the properties of 32-bit unsigned integers and has 38 | been implemented using a bitmask of 0xFFFFFFFF to make it work on 64 bit machines. 39 | 40 | The period of this generator is 2^88 (about 10^26). It uses 3 words of state per generator. 41 | For more information see, 42 | P. L'Ecuyer, "Maximally Equidistributed Combined Tausworthe Generators", 43 | Mathematics of Computation, 65, 213 (1996), 203--213.*/ 44 | 45 | /*Allocates space for a generator and sets the seed*/ 46 | 47 | 48 | r = gsl_rng_alloc(GENERATOR); 49 | 50 | if (s == 0) /*to use a seed taken from the calendar*/ 51 | sd = (unsigned long int) time(NULL); 52 | else 53 | sd = s; 54 | 55 | gsl_rng_set(r, sd); 56 | } 57 | 58 | unsigned long int GetSeed() { 59 | return sd; 60 | } 61 | 62 | 63 | double Un01() /*Un01() */ 64 | { 65 | return gsl_rng_uniform(r); 66 | } 67 | 68 | 69 | INLINE double Unab(double a, double b) /*U(a,b)*/ 70 | { 71 | return a + (b - a) * gsl_rng_uniform(r); /*gsl_rng_flat( r, a, b);*/ 72 | } 73 | 74 | INLINE unsigned int Un0n(int n) /*Uniform integer [0,n-1]*/ 75 | { 76 | return gsl_rng_uniform_int(r, n); 77 | } 78 | 79 | INLINE int Sign() /*random -1 or 1*/ 80 | { 81 | return ((gsl_rng_uniform(r) < 0.5) ? -1 : 1); 82 | } 83 | 84 | 85 | INLINE double NorSim(double m, double sigma) /*Normal*/ 86 | { 87 | return (m + gsl_ran_gaussian(r, sigma)); 88 | } 89 | 90 | INLINE double ExpSim(double mu) { 91 | return (gsl_ran_exponential(r, mu)); 92 | } 93 | 94 | INLINE double GammaSim(double a, double b) /*Gamma: K x^{a-1} e^{-x/b}*/ 95 | { 96 | return gsl_ran_gamma(r, a, b); 97 | } 98 | 99 | INLINE double GammaDens(double x, double a, double b) /*Gamma: K x^{a-1} e^{-x/b}*/ 100 | { 101 | return gsl_ran_gamma_pdf(x, a, b); 102 | } 103 | 104 | 105 | INLINE double BetaSim(double a, double b) { /*Beta: p(x) dx = K x^{a-1} (1-x)^{b-1} dx */ 106 | return gsl_ran_beta(r, a, b); 107 | } 108 | 109 | INLINE double BetaDens(double x, double a, double b) { /*density for beta, as above */ 110 | return gsl_ran_beta_pdf(x, a, b); 111 | } 112 | 113 | 114 | unsigned int BiSim(double p, int n) { 115 | return gsl_ran_binomial(r, p, n); 116 | } 117 | 118 | double LogGamma(double x) /*Logarithm of Gamma special function*/ 119 | { 120 | return gsl_sf_lngamma(x); 121 | 122 | } 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /snakebacon/tests/test_bacon_utils.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import os 3 | 4 | import numpy as np 5 | 6 | from snakebacon.mcmcbackends.bacon import fetch_calibcurve 7 | from snakebacon.mcmcbackends.bacon.utils import d_cal, calibrate_dates 8 | from snakebacon import read_chron 9 | import snakebacon.records as curve 10 | 11 | 12 | here = os.path.abspath(os.path.dirname(__file__)) 13 | 14 | 15 | class TestBaconUtilsDcal(unittest.TestCase): 16 | def setUp(self): 17 | np.random.seed(123) 18 | self.minitestcurve = curve.CalibCurve(calbp=np.arange(1, 4), 19 | c14age=np.arange(3, 0, -1), 20 | error=np.arange(21, 24), 21 | delta14c=None, sigma=None) 22 | self.smalltestcurve = curve.CalibCurve(calbp=np.arange(1, 7), 23 | c14age=np.arange(6, 0, -1), 24 | error=np.arange(21, 27), 25 | delta14c=None, sigma=None) 26 | 27 | def test_d_cal_normal(self): 28 | goalmini = np.array([[2.959184, 0.01904568], [3.000000, 0.01900584]]) 29 | goalsmall = np.array([[4, 0.1624059], [5, 0.1553523], [6, 0.1487062]]) 30 | test_minivictim = d_cal(self.minitestcurve, rcmean=5, w2=2, 31 | normal_distr=True) 32 | test_smallvictim = d_cal(self.smalltestcurve, rcmean=5, w2=2, 33 | normal_distr=True) 34 | np.testing.assert_allclose(test_minivictim[-2:], goalmini, atol=1e-7) 35 | np.testing.assert_allclose(test_smallvictim[-3:], goalsmall, atol=1e-7) 36 | 37 | def test_d_cal_notnormal(self): 38 | goalmini = np.array([[2.959184, 0.01990764], [3.000000, 0.01990352]]) 39 | goalsmall = np.array([[4, 0.1667562], [5, 0.1662155], [6, 0.1655462]]) 40 | test_minivictim = d_cal(self.minitestcurve, rcmean=5, w2=2, 41 | cutoff=0.1, normal_distr=False) 42 | test_smallvictim = d_cal(self.smalltestcurve, rcmean=5, w2=2, 43 | cutoff=0.1, normal_distr=False) 44 | np.testing.assert_allclose(test_minivictim[-2:], goalmini, atol=1e-7) 45 | np.testing.assert_allclose(test_smallvictim[-3:], goalsmall, atol=1e-7) 46 | 47 | 48 | 49 | class TestBaconUtils(unittest.TestCase): 50 | 51 | def test_calibrate_dates(self): 52 | pgoal_age_mean = 6726.8 53 | pgoal_age_std = 192.94564322687978 54 | 55 | pgoal_density_mean = 0.011642671907680679 56 | pgoal_density_std = 0.010893804880746285 57 | 58 | dgoal = np.array([77.5, 79.5, 99.5]) 59 | dgoal_n = 40 60 | pgoal_n = dgoal_n 61 | 62 | chron = read_chron(os.path.join(here, 'MSB2K.csv')) 63 | 64 | d_r = [0] 65 | d_std = [0] 66 | t_a = [3] 67 | t_b = [4] 68 | 69 | cc = [fetch_calibcurve('IntCal13')] 70 | 71 | d_target, p_target = calibrate_dates(chron, calib_curve=cc, 72 | d_r=d_r, d_std=d_std, 73 | t_a=t_a, t_b=t_b) 74 | np.testing.assert_allclose(d_target[-3:], dgoal) 75 | np.testing.assert_equal(len(d_target), dgoal_n) 76 | 77 | np.testing.assert_allclose(np.mean(p_target[-1][:, 0]), 78 | pgoal_age_mean, atol=7) 79 | np.testing.assert_allclose(np.std(p_target[-1][:, 0]), 80 | pgoal_age_std, atol=2) 81 | np.testing.assert_equal(len(p_target), pgoal_n) 82 | 83 | 84 | np.testing.assert_allclose(np.mean(p_target[-1][:, 1]), 85 | pgoal_density_mean, atol=1e-2) 86 | np.testing.assert_allclose(np.std(p_target[-1][:, 1]), 87 | pgoal_density_std, atol=1e-2) 88 | 89 | 90 | if __name__ == '__main__': 91 | unittest.main() 92 | -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/bacon/bacon.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | BACON: 5 | 6 | Implements the semiparametric autoregressive model for 7 | radiocarbon chronologies, using the twalk. See paper for mathematical details and 8 | the files: 9 | 10 | - bacon.h: This is the implementation, with the model definitions etc. 11 | 12 | - cal.h: Reads and manages calibration curves and determinations 13 | 14 | - input.h, input.c: reads the input files and stores all data 15 | 16 | - ranfun.h, twalk.h, Matrix.h: for some gsl interfaces for random number generation, the C++ twalk implementation and a simple Matrix class. 17 | 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | // #include "vector.c" // brews: I added this. Needed cp_vector(double*, double*, int). 26 | // #include "ranfun.c" // brews: I added this. Needed fcmp(double, double, double). 27 | // #include "Matrix.c" 28 | // #include "kernel.c" 29 | // #include "input.c" 30 | 31 | 32 | #include "bacon.h" 33 | #include "input.h" 34 | 35 | #define MAXNUMOFCURVES 100 36 | #define MAXNUMOFDETS 1000 37 | 38 | #define BUFFSIZE 4000 39 | 40 | 41 | //the "every" thinning subsampling parameter is EVERY_MULT*All.Dim() 42 | #define EVERY_MULT 5 43 | //The burn in is BURN_IN_MULT*All.Dim() 44 | #define BURN_IN_MULT 200 45 | 46 | //Every how many iterations we expect and acceptance: inverse of the acceptance rate 47 | #define ACCEP_EV 20 48 | 49 | 50 | int notmain(int argc, char *argv[]) {// Command line: bacon inputfile outputfile 51 | 52 | /* 53 | 54 | - Falta hacer Mov, no funciona por el momento: May 2009. 55 | 56 | - Hacer hist, command line para un solo rango de profundidades: 57 | hist 10 10.5 1 MSB2K.out 58 | d1 d2 bin size 59 | 60 | - 61 | */ 62 | 63 | if (argc < 4) { 64 | printf("Usage: bacon inputfile outputfile ssize\n"); 65 | 66 | exit(0); 67 | } 68 | 69 | char ax[BUFFSIZE]; 70 | 71 | //Program file 72 | //sprintf( ax, "Cores/%s/%s.bacon", argv[1], argv[2]); 73 | sprintf(ax, "%s", argv[1]); 74 | //Read everything from the program file 75 | Input All(ax, MAXNUMOFCURVES, MAXNUMOFDETS); 76 | 77 | 78 | 79 | //File to save the twalk output 80 | sprintf(ax, "%s", argv[2]); 81 | 82 | int ssize; 83 | sscanf(argv[3], " %d", &ssize); 84 | 85 | //ssize is the final sample size needed 86 | //ssize = it/(ACCEP_EV * All.Dim() * EVERY_MULT) - BURN_IN_MULT 87 | //Then we let 88 | 89 | int it = ACCEP_EV * All.Dim() * EVERY_MULT * (ssize + BURN_IN_MULT); 90 | 91 | int every = -1 * EVERY_MULT * All.Dim(); // only accepted iterations 92 | 93 | //Run the twalk 94 | All.RunTwalk(ax, it, every); 95 | 96 | 97 | All.PrintNumWarnings(); 98 | 99 | /* 100 | char ax2[BUFFSIZE]; 101 | //File to save the thinned twalk output 102 | sprintf( ax2, "%s", argv[2]); 103 | 104 | 105 | FILE *F, *G; 106 | if ((F = fopen( ax, "r")) == NULL) { 107 | printf("Could not open %s for reading.\n", ax); 108 | 109 | exit(0); 110 | } 111 | if ((G = fopen( ax2, "w+")) == NULL) { 112 | printf("Could not open %s for writing.\n", ax2); 113 | 114 | exit(0); 115 | } 116 | 117 | 118 | char ln[CHARBUFFER]; 119 | int burnin= BURN_IN_MULT*All.Dim(), j=0; 120 | every = 1; 121 | //subsample the twalk output: 122 | printf("\nSubsampling %s, burnin= %d, every= %d and store results in %s ...\n", ax, burnin, every, ax2); 123 | while (!feof(F)) { 124 | fgets( ln, CHARBUFFER, F); 125 | if (j == burnin) break; 126 | j++; 127 | } 128 | 129 | j=0; 130 | int ss=0; 131 | while (!feof(F)) { 132 | 133 | fgets( ln, CHARBUFFER, F); 134 | if ((j % every) == 0) { 135 | 136 | fputs( ln, G); 137 | ss++; 138 | } 139 | j++; 140 | } 141 | printf("out.all size= %d\n", j); 142 | 143 | fclose(F); 144 | fclose(G); 145 | 146 | printf("Removing %s\n", ax); 147 | remove(ax); 148 | 149 | printf("Final sample size %d\n", ss); 150 | */ 151 | 152 | printf("bacon: suggested burn in= %d\n", All.Dim() * EVERY_MULT * BURN_IN_MULT); 153 | printf(FAREWELL); 154 | 155 | 156 | return All.Dim() * EVERY_MULT * BURN_IN_MULT; 157 | 158 | 159 | } 160 | 161 | -------------------------------------------------------------------------------- /snakebacon/tests/test_baconwrap.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from os import path 3 | 4 | import numpy as np 5 | 6 | import snakebacon as snek 7 | from snakebacon.mcmcbackends.bacon import baconwrap 8 | 9 | here = path.abspath(path.dirname(__file__)) 10 | 11 | 12 | class TestBaconwrap(unittest.TestCase): 13 | def test__baconin_str(self): 14 | # Not very clever test, but okay first pass. 15 | victim = baconwrap._baconin_str(core_labid=np.array(['a', 'b', 'c']), core_age=np.array([1, 2, 3]), 16 | core_error=np.array([1, 2, 1]), core_depth=np.array([2, 3, 4]), depth_min=1.5, 17 | depth_max=99.5, cc=[1], cc1='IntCal13', cc2='Marine13', cc3='SHCal13', 18 | cc4='ConstCal', d_r=[0], d_std=[0], t_a=[3], t_b=[4], k=20, 19 | minyr=-1000, maxyr=1e6, th01=4147, th02=4145, acc_mean=20, acc_shape=1.5, 20 | mem_strength=4, mem_mean=0.7) 21 | goal = ['## Ran on Tue 09 May 2017 02:57:05 PM \n\n', 22 | 'Cal 0 : ConstCal;\n', 23 | 'Cal 1 : IntCal13, 0;\n', 24 | 'Cal 2 : Marine13;\n', 25 | 'Cal 3 : SHCal13, 0;\n', 26 | '\n## id. yr std depth d.R d.STD t.a t.b cc\n', 27 | 'Det 0 : NA , 1, 10000.0, 1.5, 0, 0, 3, 4, 0;\n', 28 | 'Det 1 : a , 1, 1.0, 2.0, 0, 0, 3, 4, 1;\n', 29 | 'Det 2 : b , 2, 2.0, 3.0, 0, 0, 3, 4, 1;\n', 30 | 'Det 3 : c , 3, 1.0, 4.0, 0, 0, 3, 4, 1;\n', 31 | 'Det 4 : NA , 3, 1000000.0, 99.5, 0, 0, 3, 4, 0;\n', 32 | '\n##\t\t K MinYr MaxYr th0 th0p w.a w.b alpha beta dmin dmax\n', 33 | 'Bacon 0: FixT, 20, -1000, 1000000.0, 4147, 4145, 2.8, 1.2000000000000002, 1.5, 0.075, 1.5, 99.5;\n'] 34 | self.assertCountEqual(victim[1:], goal[1:]) # Skip first line because datetime won't match. 35 | 36 | def test_run_baconmcmc(self): 37 | testcore_path = path.join(here, 'MSB2K.csv') 38 | c = snek.read_chron(testcore_path) 39 | fullrun_victim = baconwrap.run_baconmcmc(core_labid=c.labid, core_age=c.age, core_error=c.error, 40 | core_depth=c.depth, depth_min=1.5, depth_max=99.5, cc=[1], 41 | cc1='IntCal13', cc2='Marine13', cc3='SHCal13', cc4='ConstCal', 42 | d_r=[0], d_std=[0], t_a=[3], t_b=[4], k=20, 43 | minyr=-1000, maxyr=1e6, th01=4147, th02=4145, 44 | acc_mean=20, acc_shape=1.5, mem_strength=4, mem_mean=0.7) 45 | 46 | niter_goal = 3432 47 | nsegs_goal = 20 48 | objective_mean_goal = 218.26212744522144 49 | theta_mean_goal = 4549.6406701631704 50 | w_mean_goal = 0.06277018029195805 51 | x0_mean_goal = 14.487713009032634 52 | xneg1_mean_goal = 15.65397709810606 53 | # Fuzzy to deal with vars across platforms. 54 | np.testing.assert_allclose(len(fullrun_victim['objective']), niter_goal, atol=50) 55 | np.testing.assert_allclose(len(fullrun_victim['w']), niter_goal, atol=50) 56 | np.testing.assert_allclose(len(fullrun_victim['x'][0]), niter_goal, atol=50) 57 | np.testing.assert_allclose(len(fullrun_victim['x'][-1]), niter_goal, atol=50) 58 | self.assertEqual(nsegs_goal, len(fullrun_victim['x'])) 59 | np.testing.assert_allclose(fullrun_victim['objective'].mean(), objective_mean_goal, atol=1e-1) 60 | np.testing.assert_allclose(fullrun_victim['theta'].mean(), theta_mean_goal, atol=15) 61 | np.testing.assert_allclose(fullrun_victim['w'].mean(), w_mean_goal, atol=1e-2) 62 | np.testing.assert_allclose(fullrun_victim['x'][0].mean(), x0_mean_goal, atol=2) 63 | np.testing.assert_allclose(fullrun_victim['x'][-1].mean(), xneg1_mean_goal, atol=2) 64 | 65 | 66 | # class TestRead14c(unittest.TestCase): 67 | # 68 | # @unittest.skip('Test not written') 69 | # def test_read_14c(self): 70 | # self.assertEqual(True, False) 71 | 72 | 73 | if __name__ == '__main__': 74 | unittest.main() 75 | -------------------------------------------------------------------------------- /snakebacon/tests/test_agedepth.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from copy import deepcopy 3 | from os import path 4 | 5 | import numpy as np 6 | import pandas as pd 7 | 8 | from snakebacon import read_chron, ProxyRecord 9 | from snakebacon.agedepth import AgeDepthModel 10 | 11 | 12 | here = path.abspath(path.dirname(__file__)) 13 | 14 | mcmc_kws = dict(depth_min=1.5, depth_max=99.5, cc=[1], 15 | cc1='IntCal13', cc2='Marine13', cc3='SHCal13', cc4='ConstCal', 16 | d_r=[0], d_std=[0], t_a=[3], t_b=[4], k=20, 17 | minyr=-1000, maxyr=1e6, th01=4147, th02=4145, 18 | acc_mean=20, acc_shape=1.5, mem_strength=4, mem_mean=0.7) 19 | fullrun_agemodel = AgeDepthModel(read_chron(path.join(here, 'MSB2K.csv')), 20 | mcmc_kws=mcmc_kws) 21 | 22 | 23 | class TestAgeDepth(unittest.TestCase): 24 | def setUp(self): 25 | np.random.seed(123) 26 | self.testdummy = deepcopy(fullrun_agemodel) 27 | 28 | def test_init(self): 29 | goal_thick = 4.9 30 | goal_depthrange = (1.5, 99.5) 31 | goal_agemedian_edges = (4552.5750000000007, 6714.1464476499987) 32 | goal_agemedian_025 = (4430.3599999999997, 6582.4278499575012) 33 | goal_agemedian_975 = (4680.6210000000001, 6868.9317877499998) 34 | goal_ageensemble_shape = (99, 3232) 35 | 36 | self.assertTrue(self.testdummy.mcmcfit is not None) 37 | self.assertEqual(goal_thick, self.testdummy.thick) 38 | self.assertTupleEqual(goal_depthrange, (min(self.testdummy.depth), max(self.testdummy.depth))) 39 | 40 | np.testing.assert_allclose(self.testdummy.age_median()[0], goal_agemedian_edges[0], atol=25) 41 | np.testing.assert_allclose(self.testdummy.age_median()[-1], goal_agemedian_edges[-1], atol=25) 42 | 43 | np.testing.assert_allclose(self.testdummy.age_percentile(2.5)[0], goal_agemedian_025[0], atol=25) 44 | np.testing.assert_allclose(self.testdummy.age_percentile(2.5)[-1], goal_agemedian_025[-1], atol=25) 45 | 46 | np.testing.assert_allclose(self.testdummy.age_percentile(97.5)[0], goal_agemedian_975[0], atol=25) 47 | np.testing.assert_allclose(self.testdummy.age_percentile(97.5)[-1], goal_agemedian_975[-1], atol=25) 48 | 49 | self.assertEqual(goal_ageensemble_shape[0], len(self.testdummy.age_ensemble)) 50 | np.testing.assert_allclose(len(self.testdummy.age_ensemble[0]), goal_ageensemble_shape[1], atol=50) 51 | 52 | def test_date(self): 53 | np.random.seed(123) 54 | goal_median_idx0 = 4552.5750000000007 55 | goal_median_nmember = 3 56 | goal_ens_2_idx0 = 4503.01 57 | goal_ens_2_nmember = 2 58 | goal_ens_20_nmember = 20 59 | testproxy = ProxyRecord(pd.DataFrame({'depth': np.arange(1.5, 4.5), 'a': np.arange(20, 23)})) 60 | victim_median = self.testdummy.date(testproxy, how='median') 61 | victim_ens_2 = self.testdummy.date(testproxy, how='ensemble', n=2) 62 | victim_ens_20 = self.testdummy.date(testproxy, how='ensemble', n=20) 63 | 64 | np.testing.assert_allclose(victim_median.age[0], goal_median_idx0, atol=15) 65 | self.assertEqual(goal_median_nmember, len(victim_median.age)) 66 | 67 | np.testing.assert_allclose(victim_ens_2.age[0][0], goal_ens_2_idx0, atol=75) 68 | self.assertEqual(goal_ens_2_nmember, len(victim_ens_2.age[0])) 69 | 70 | self.assertEqual(goal_ens_20_nmember, len(victim_ens_20.age[0])) 71 | 72 | def test_agedepth(self): 73 | goal_len = 3232 74 | goal_mean = 4567.1221008870671 75 | goal_var = 3982.7408290300741 76 | victim = self.testdummy.agedepth(2.5) 77 | # Fuzzy to deal with vars across platforms. 78 | np.testing.assert_allclose(len(victim), goal_len, atol=50) 79 | np.testing.assert_allclose(victim.mean(), goal_mean, atol=10) 80 | np.testing.assert_allclose(victim.var(), goal_var, atol=550) 81 | 82 | def test_prior_sediment_memory(self): 83 | goal_mean = 0.98457848264590286 84 | goal_std = 0.71613816177236256 85 | goal_n = 100 86 | 87 | victim, x = self.testdummy.prior_sediment_memory() 88 | 89 | np.testing.assert_equal(len(victim), goal_n) 90 | np.testing.assert_allclose(victim.mean(), goal_mean, atol=1e-3) 91 | np.testing.assert_allclose(victim.std(), goal_std, atol=1e-3) 92 | 93 | 94 | def test_prior_sediment_rate(self): 95 | goal_mean = 0.008194080517375957 96 | goal_std = 0.01172658825323754 97 | goal_n = 100 98 | 99 | victim, x = self.testdummy.prior_sediment_rate() 100 | 101 | np.testing.assert_equal(len(victim), goal_n) 102 | np.testing.assert_allclose(victim.mean(), goal_mean, atol=1e-3) 103 | np.testing.assert_allclose(victim.std(), goal_std, atol=1e-3) 104 | 105 | 106 | if __name__ == '__main__': 107 | unittest.main() 108 | -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/bacon/utils.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import scipy.stats as stats 3 | 4 | 5 | def d_cal(calibcurve, rcmean, w2, cutoff=0.0001, normal_distr=False, t_a=3, t_b=4): 6 | """Get calendar date probabilities 7 | 8 | Parameters 9 | ---------- 10 | calibcurve : CalibCurve 11 | Calibration curve. 12 | rcmean : scalar 13 | Reservoir-adjusted age. 14 | w2 : scalar 15 | r'$w^2_j(\theta)$' from pg 461 & 463 of Blaauw and Christen 2011. 16 | cutoff : scalar, optional 17 | Unknown. 18 | normal_distr : Bool, optional 19 | Use normal distribution for date errors. If False, then use Student's t-distribution. 20 | t_a : scalar, optional 21 | Student's t-distribution parameter, a. t_b - 1 must equal t_b. 22 | t_b : scalar, optional 23 | Student's t-distribution parameter, b. t_b - 1 must equal t_b. 24 | 25 | 26 | #Line 943 of Bacon.R 27 | #cc : calib_curve (3-col format) 28 | #rcmean : det['age'][i] - d_R 29 | #w2 : dat['error'][i]^2 + d_STD**2 30 | """ 31 | assert t_b - 1 == t_a 32 | if normal_distr: 33 | # TODO(brews): Test this. Line 946 of Bacon.R. 34 | std = np.sqrt(calibcurve.error ** 2 + w2) 35 | dens = stats.norm(loc=rcmean, scale=std).pdf(calibcurve.c14age) 36 | else: 37 | # TODO(brews): Test this. Line 947 of Bacon.R. 38 | dens = (t_b + ((rcmean - calibcurve.c14age) ** 2) / (2 * (calibcurve.error ** 2 + w2))) ** (-1 * (t_a + 0.5)) 39 | cal = np.array([calibcurve.calbp.copy(), dens]).T 40 | cal[:, 1] = cal[:, 1] / cal[:, 1].sum() 41 | # "ensure that also very precise dates get a range of probabilities" 42 | cutoff_mask = cal[:, 1] > cutoff 43 | if cutoff_mask.sum() > 5: 44 | out = cal[cutoff_mask, :] 45 | else: 46 | calx = np.linspace(cal[:, 0].min(), cal[:, 0].max(), num=50) 47 | caly = np.interp(calx, cal[:, 0], cal[:, 1]) 48 | out = np.array([calx, caly / caly.sum()]).T 49 | return out 50 | 51 | 52 | def calibrate_dates(chron, calib_curve, d_r, d_std, cutoff=0.0001, normal_distr=False, t_a=[3], t_b=[4]): 53 | """Get density of calendar dates for chron date segment in core 54 | 55 | Parameters 56 | ---------- 57 | chron : DatedProxy-like 58 | calib_curve : CalibCurve or list of CalibCurves 59 | d_r : scalar or ndarray 60 | Carbon reservoir offset. 61 | d_std : scalar or ndarray 62 | Carbon reservoir offset error standard deviation. 63 | cutoff : scalar, optional 64 | Unknown. 65 | normal_distr : Bool, optional 66 | Use normal distribution for date errors. If False, then use Student's t-distribution. 67 | t_a : scalar or ndarray, optional 68 | Student's t-distribution parameter, a. t_a - 1 must equal t_b. 69 | t_b : scalar or ndarray, optional 70 | Student's t-distribution parameter, b. t_a - 1 must equal t_b. 71 | 72 | Returns 73 | ------- 74 | depth : ndarray 75 | Depth of dated sediment sample. 76 | probs : list of 2d arrays 77 | Density of calendar age for each dated sediment sample. For each 78 | sediment sample, the 2d array has two columns, the first is the 79 | calendar age. The second column is the density for that calendar age. 80 | 81 | """ 82 | # Python version of .bacon.calib() on line 908 in Bacon.R 83 | 84 | # .bacon.calib - line 908 85 | 86 | # rcmean = 4128; w2 = 4225; t_a=3; t_b=4 87 | # test = d_cal(cc = calib_curve.rename(columns = {0:'a', 1:'b', 2:'c'}), rcmean = 4128, w2 = 4225, t_a=t_a, 88 | # t_b=t_b, cutoff=cutoff, normal = normal) 89 | 90 | # Line 959 of Bacon.R 91 | # calib = list(dets.iloc[:, 3]) 92 | # Now Bacon goes and checks the ncol in the dets See line #960 in Bacon.R 93 | 94 | # Line #973 95 | # TODO(brews): Check that `normal_dist` is used and documented correctly in docstring above. 96 | # TODO(brews): Check whether we call returned values densities, freqs or what options we should have. 97 | n = len(chron.depth) 98 | calib_curve = np.array(calib_curve) 99 | t_a = np.array(t_a) 100 | t_b = np.array(t_b) 101 | assert t_b - 1 == t_a 102 | d_r = np.array(d_r) 103 | d_std = np.array(d_std) 104 | if len(t_a) == 1: 105 | t_a = np.repeat(t_a, n) 106 | if len(t_b) == 1: 107 | t_b = np.repeat(t_b, n) 108 | if len(d_r) == 1: 109 | d_r = np.repeat(d_r, n) 110 | if len(d_std) == 1: 111 | d_std = np.repeat(d_std, n) 112 | if len(calib_curve) == 1: 113 | calib_curve = np.repeat(calib_curve, n) 114 | 115 | calib_probs = [] 116 | rcmean = chron.age - d_r 117 | w2 = chron.error ** 2 + d_std ** 2 118 | for i in range(n): 119 | age_realizations = d_cal(calib_curve[i], rcmean=rcmean[i], w2=w2[i], 120 | t_a=t_a[i], t_b=t_b[i], 121 | cutoff=cutoff, normal_distr=normal_distr) 122 | calib_probs.append(age_realizations) 123 | return np.array(chron.depth), calib_probs 124 | -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/bacon/kernel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * kernel.c 3 | * 4 | * 5 | * Created by jac on 29/04/2009. 6 | * 7 | */ 8 | 9 | #include "twalk.h" 10 | 11 | 12 | /*OK <--- f_a(beta), a is a parameter */ 13 | double kernel::fbeta(double beta, double a) { 14 | double b = 0; 15 | 16 | if (0 <= beta && beta < 1.0) 17 | b = pow(beta, a); 18 | 19 | if (beta > 1) 20 | b = pow(1.0 / beta, a); 21 | 22 | return ((a - 1.0) * (a + 1.0) / (2.0 * a) * b); 23 | } 24 | 25 | /* OK <--- -log f_a(beta). It is assumed that beta > 0*/ 26 | double Ufbeta(double beta, double a) { 27 | double b = 0; 28 | if (beta < 1) 29 | b = -a * log(beta); 30 | if (beta >= 1) 31 | b = a * log(beta); 32 | 33 | return (-log(a - 1.0) - log(a + 1.0) + log(2.0 * a) + b); 34 | } 35 | 36 | /* OK */ 37 | double kernel::Fbeta(double beta, double a) { 38 | double b1 = 0.0; 39 | double b2 = 0.0; 40 | if (0 <= beta && beta <= 1) 41 | b1 = (a - 1.0) / (2.0 * a) * pow(beta, a + 1.0); 42 | 43 | if (beta > 1) { 44 | b1 = (a - 1.0) / (2.0 * a); 45 | b2 = (a + 1.0) / (2.0 * a) * (1 - pow(1.0 / beta, a - 1.0)); 46 | } 47 | 48 | return b1 + b2; 49 | } 50 | 51 | double Simfbeta(double a) { 52 | 53 | if (Un01() < (a - 1.0) / (2.0 * a)) 54 | return (exp(1.0 / (a + 1.0) * log(Un01()))); 55 | else 56 | return (exp(1.0 / (1.0 - a) * log(Un01()))); 57 | 58 | } 59 | 60 | 61 | //----------------------------------- K 0 -------------------------------------- 62 | double *kernel0::Simh(double *x, double *xp, int n, double beta, int *phi) { 63 | 64 | return x; 65 | } 66 | 67 | double kernel0::GU(double *h, double *x, double *xp, int n) const { 68 | if (vector_cmp(h, x, n)) 69 | return 1.0; 70 | else 71 | return 0.0; 72 | } 73 | 74 | 75 | //----------------------------------- K1 traverse---------------------------- 76 | double *kernel1::Simh(double *x, double *xp, int n, double beta, int *phi) { 77 | 78 | //double *h = vector(n); 79 | 80 | for (int i = 0; i < n; i++) 81 | if (phi[i] == 1) 82 | h[i] = xp[i] + beta * (xp[i] - x[i]); 83 | else 84 | h[i] = x[i]; 85 | 86 | return h; 87 | } 88 | 89 | double kernel1::GU(double *h, double *x, double *xp, int n) const { 90 | 91 | return -2; 92 | } 93 | 94 | 95 | //----------------------------------- K 2 -------------------------------------- 96 | //This is parameter aw in the paper 97 | double Phi2Sim(double aw) { 98 | 99 | double u = Un01(); 100 | return ((aw / (1.0 + aw)) * (-1.0 + 2.0 * u + aw * u * u)); 101 | } 102 | 103 | double *kernel2::Simh(double *x, double *xp, int n, double beta, int *phi) { 104 | 105 | //double *h = vector(n); 106 | 107 | for (int i = 0; i < n; i++) { 108 | h[i] = x[i] + phi[i] * (x[i] - xp[i]) * Phi2Sim(PARAMETER_aw); 109 | } 110 | 111 | return h; 112 | } 113 | 114 | double kernel2::GU(double *h, double *x, double *xp, int n) const { 115 | return 1.0; 116 | } 117 | 118 | 119 | //----------------------------------- K 3 -------------------------------------- 120 | double *kernel3::Simh(double *x, double *xp, int n, double beta, int *phi) { 121 | 122 | //double *h = vector(n); 123 | 124 | //double *rest = vector(n); 125 | 126 | int i; 127 | 128 | resta_vector(xp, x, n, rest); 129 | indice_max_vector(rest, n, i, phi); 130 | 131 | sigma = fabs(rest[i]) / 3.0; 132 | 133 | for (int j = 0; j < n; j++) 134 | h[j] = x[j] + phi[j] * sigma * NorSim(0, 1.0); 135 | 136 | //free_vector(rest); 137 | return h; 138 | } 139 | 140 | double kernel3::GU(double *h, double *x, double *xp, int n) const { 141 | 142 | if (!vector_cmp(x, xp, 2)) { 143 | 144 | int i; 145 | 146 | 147 | double intProd = 0.0; 148 | 149 | for (int j = 0; j < n; j++) 150 | intProd += (h[j] - xp[j]) * (h[j] - xp[j]); 151 | 152 | //it is assumed that Simh is just called and we have the correct sigma 153 | return ((n / 2) * log(2.0 * M_PI) + n * log(sigma) + 0.5 * (1 / (sigma * sigma)) * intProd); 154 | } else return -1; 155 | } 156 | 157 | 158 | //----------------------------------- K 4 -------------------------------------- 159 | double *kernel4::Simh(double *x, double *xp, int n, double beta, int *phi) { 160 | 161 | //double *rest = vector(n); 162 | //double *h = vector(n); 163 | int i; 164 | 165 | resta_vector(xp, x, n, rest); 166 | indice_max_vector(rest, n, i, phi); 167 | 168 | sigma = fabs(rest[i]); 169 | 170 | for (int j = 0; j < n; j++) 171 | if (phi[j] == 1) 172 | h[j] = xp[j] + sigma * NorSim(0, 1.0); 173 | else 174 | h[j] = x[j]; 175 | 176 | //free_vector(rest); 177 | return h; 178 | } 179 | 180 | double kernel4::GU(double *h, double *x, double *xp, int n) const { 181 | 182 | int i; 183 | 184 | 185 | double intProd = 0.0; 186 | 187 | for (int j = 0; j < n; j++) 188 | intProd += (h[j] - xp[j]) * (h[j] - xp[j]); 189 | 190 | //it is assumed that Simh is just called and we have the correct sigma 191 | return ((n / 2) * log(2.0 * M_PI) + n * log(sigma) + 0.5 * (1 / (sigma * sigma)) * intProd); 192 | } 193 | -------------------------------------------------------------------------------- /snakebacon/records.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | import matplotlib.pylab as plt 4 | import numpy as np 5 | import pandas as pd 6 | import scipy.stats as stats 7 | from matplotlib.collections import PatchCollection 8 | from matplotlib.patches import Polygon 9 | 10 | 11 | log = logging.getLogger(__name__) 12 | 13 | 14 | def read_14c(fl): 15 | """Create CalibCurve instance from Bacon curve file 16 | """ 17 | indata = pd.read_csv(fl, index_col=None, skiprows=11, header=None, 18 | names=['calbp', 'c14age', 'error', 'delta14c', 'sigma']) 19 | outcurve = CalibCurve(calbp=indata['calbp'], 20 | c14age=indata['c14age'], 21 | error=indata['error'], 22 | delta14c=indata['delta14c'], 23 | sigma=indata['sigma']) 24 | return outcurve 25 | 26 | 27 | def read_chron(fl): 28 | """Create ChronRecord instance from Bacon file 29 | """ 30 | indata = pd.read_csv(fl, sep=r'\s*\,\s*', index_col=None, engine='python') 31 | outcore = ChronRecord(age=indata['age'], 32 | error=indata['error'], 33 | depth=indata['depth'], 34 | labid=indata['labID']) 35 | return outcore 36 | 37 | 38 | def read_proxy(fl): 39 | """Read a file to create a proxy record instance 40 | """ 41 | outcore = ProxyRecord(data=pd.read_csv(fl, sep=r'\s*\,\s*', index_col=None, engine='python')) 42 | return outcore 43 | 44 | 45 | class ProxyRecord: 46 | def __init__(self, data): 47 | """Create a proxy record instance 48 | 49 | Parameters 50 | ---------- 51 | data : DataFrame 52 | Pandas dataframe containing columns with proxy sample measurements. Must also have 'depth' column. 53 | """ 54 | assert 'depth' in data.columns.values 55 | assert 'age' not in data.columns.values 56 | self.data = pd.DataFrame(data).copy() 57 | 58 | def __repr__(self): 59 | return '%s(data=%r)' % (type(self).__name__, self.data) 60 | 61 | 62 | class DatedProxyRecord(ProxyRecord): 63 | def __init__(self, data, age): 64 | """Create a dated proxy record instance 65 | 66 | Parameters 67 | ---------- 68 | data : DataFrame 69 | Pandas dataframe containing columns with proxy sample measurements. Must also have 'depth' column. 70 | age : iterable 71 | Iterable containing calendar year, or a list of years (cal yr BP) for corresponding to each sample depth in 72 | data.depth. 73 | """ 74 | super().__init__(data) 75 | assert len(data.depth) == len(age) 76 | self.age = np.array(age) 77 | 78 | def __repr__(self): 79 | return '%s(data=%r, age=%r)' % (type(self).__name__, self.data, self.age) 80 | 81 | def n_members(self): 82 | """Get number of MCMC ensemble members in calendar age estimates""" 83 | try: 84 | n = len(self.age[0]) 85 | except TypeError: 86 | n = 1 87 | return n 88 | 89 | def to_pandas(self): 90 | """Convert record to pandas.DataFrame""" 91 | agedepthdf = pd.DataFrame(self.age, index=self.data.depth) 92 | agedepthdf.columns = list(range(self.n_members())) 93 | out = (agedepthdf.join(self.data.set_index('depth')) 94 | .reset_index() 95 | .melt(id_vars=self.data.columns.values, var_name='mciter', value_name='age')) 96 | out['mciter'] = pd.to_numeric(out.loc[:, 'mciter']) 97 | if self.n_members() == 1: 98 | out = out.drop('mciter', axis=1) 99 | return out 100 | 101 | 102 | class ChronRecord: 103 | def __init__(self, obj=None, **kwargs): 104 | """Create a sediment core date instance 105 | 106 | Parameters 107 | ---------- 108 | obj : obj, optional 109 | Object with iterable attributes 'labid', 'age', 'error', and 'depth'. Assumes that depth is in increasing order 110 | order. Cannot use **kwargs if passing obj. 111 | **kwargs : optional 112 | Must include objects with iterables for 'labid', 'age', 'error', and 'depth'. Assumes depth is in in 113 | increasing order. Only parsed if obj is None. 114 | 115 | Returns 116 | ------- 117 | A ChronRecord instance. 118 | """ 119 | if obj is not None: 120 | self.labid = np.array(obj.labid) 121 | self.age = np.array(obj.age) 122 | self.error = np.array(obj.error) # Note this is called "std" in output .bacon file. 123 | self.depth = np.array(obj.depth) 124 | else: 125 | self.labid = np.array(kwargs['labid']) 126 | self.age = np.array(kwargs['age']) 127 | self.error = np.array(kwargs['error']) 128 | self.depth = np.array(kwargs['depth']) 129 | 130 | def __repr__(self): 131 | # return '%s(%r)' % (type(self).__name__, self) 132 | return '%s(age=%r, error=%r, depth=%r, labid=%r)' % (type(self).__name__, self.age, self.error, self.depth, self.labid) 133 | 134 | 135 | class CalibCurve: 136 | """A calibration curve 137 | """ 138 | 139 | def __init__(self, calbp, c14age, error, delta14c=None, sigma=None): 140 | """Create a calibration curve instance 141 | 142 | Parameters 143 | ---------- 144 | calbp : ndarray 145 | c14age : ndarray 146 | error : ndarray 147 | delta14c : ndarray 148 | sigma : ndarray 149 | 150 | """ 151 | self.calbp = np.array(calbp) 152 | self.c14age = np.array(c14age) 153 | self.error = np.array(error) 154 | if delta14c is None: 155 | delta14c = np.zeros(calbp.shape) 156 | self.delta14c = np.array(delta14c) # d_R 157 | if sigma is None: 158 | sigma = np.zeros(calbp.shape) 159 | self.sigma = np.array(sigma) # d_R variance? 160 | 161 | def __repr__(self): 162 | return '%s(calbp=%r, c14age=%r, error=%r, delta14c=%r, sigma=%r)' % (type(self).__name__, self.calbp, self.c14age, self.error, self.delta14c, self.sigma) 163 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # 4 | # snakebacon documentation build configuration file, created by 5 | # sphinx-quickstart on Thu Jun 8 08:56:05 2017. 6 | # 7 | # This file is execfile()d with the current directory set to its 8 | # containing dir. 9 | # 10 | # Note that not all possible configuration values are present in this 11 | # autogenerated file. 12 | # 13 | # All configuration values have a default; values that are commented out 14 | # serve to show the default. 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | # 20 | import os 21 | import sys 22 | 23 | sys.path.insert(0, os.path.abspath('..')) 24 | 25 | 26 | # -- General configuration ------------------------------------------------ 27 | 28 | # If your documentation needs a minimal Sphinx version, state it here. 29 | # 30 | # needs_sphinx = '1.0' 31 | 32 | # Add any Sphinx extension module names here, as strings. They can be 33 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 34 | # ones. 35 | extensions = ['sphinx.ext.autodoc', 36 | 'sphinx.ext.autosummary', 37 | 'sphinx.ext.intersphinx', 38 | 'sphinx.ext.extlinks', 39 | 'sphinx.ext.mathjax', 40 | 'sphinx.ext.autodoc', 41 | 'numpydoc', 42 | ] 43 | 44 | extlinks = {'issue': ('https://github.com/brews/snakebacon/issues/%s', 'GH'), 45 | 'pull': ('https://github.com/brews/snakebacon/pull/%s', 'PR'), 46 | } 47 | 48 | autosummary_generate = True 49 | 50 | numpydoc_class_members_toctree = True 51 | numpydoc_show_class_members = False 52 | 53 | 54 | # Add any paths that contain templates here, relative to this directory. 55 | templates_path = ['_templates'] 56 | 57 | # The suffix(es) of source filenames. 58 | # You can specify multiple suffix as a list of string: 59 | # 60 | # source_suffix = ['.rst', '.md'] 61 | source_suffix = '.rst' 62 | 63 | # The master toctree document. 64 | master_doc = 'index' 65 | 66 | # General information about the project. 67 | project = 'snakebacon' 68 | copyright = '2017, S. Brewster Malevich' 69 | author = 'S. Brewster Malevich' 70 | 71 | # The version info for the project you're documenting, acts as replacement for 72 | # |version| and |release|, also used in various other places throughout the 73 | # built documents. 74 | # 75 | # The short X.Y version. 76 | version = '0.0.1' 77 | # The full version, including alpha/beta/rc tags. 78 | release = '0.0.1' 79 | 80 | # The language for content autogenerated by Sphinx. Refer to documentation 81 | # for a list of supported languages. 82 | # 83 | # This is also used if you do content translation via gettext catalogs. 84 | # Usually you set "language" from the command line for these cases. 85 | language = None 86 | 87 | # List of patterns, relative to source directory, that match files and 88 | # directories to ignore when looking for source files. 89 | # This patterns also effect to html_static_path and html_extra_path 90 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] 91 | 92 | # The name of the Pygments (syntax highlighting) style to use. 93 | pygments_style = 'sphinx' 94 | 95 | # If true, `todo` and `todoList` produce output, else they produce nothing. 96 | todo_include_todos = False 97 | 98 | # -- Options for HTML output ---------------------------------------------- 99 | 100 | # The theme to use for HTML and HTML Help pages. See the documentation for 101 | # a list of builtin themes. 102 | 103 | on_rtd = os.environ.get('READTHEDOCS', None) == 'True' 104 | 105 | if not on_rtd: # only import and set the theme if we're building docs locally 106 | import sphinx_rtd_theme 107 | html_theme = 'sphinx_rtd_theme' 108 | html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] 109 | 110 | # html_theme = 'alabaster' 111 | 112 | # Theme options are theme-specific and customize the look and feel of a theme 113 | # further. For a list of options available for each theme, see the 114 | # documentation. 115 | # 116 | # html_theme_options = {} 117 | 118 | # Add any paths that contain custom static files (such as style sheets) here, 119 | # relative to this directory. They are copied after the builtin static files, 120 | # so a file named "default.css" will overwrite the builtin "default.css". 121 | html_static_path = ['_static'] 122 | 123 | # -- Options for HTMLHelp output ------------------------------------------ 124 | 125 | # Output file base name for HTML help builder. 126 | htmlhelp_basename = 'snakebacondoc' 127 | 128 | # -- Options for LaTeX output --------------------------------------------- 129 | 130 | latex_elements = { 131 | # The paper size ('letterpaper' or 'a4paper'). 132 | # 133 | # 'papersize': 'letterpaper', 134 | 135 | # The font size ('10pt', '11pt' or '12pt'). 136 | # 137 | # 'pointsize': '10pt', 138 | 139 | # Additional stuff for the LaTeX preamble. 140 | # 141 | # 'preamble': '', 142 | 143 | # Latex figure (float) alignment 144 | # 145 | # 'figure_align': 'htbp', 146 | } 147 | 148 | # Grouping the document tree into LaTeX files. List of tuples 149 | # (source start file, target name, title, 150 | # author, documentclass [howto, manual, or own class]). 151 | latex_documents = [ 152 | (master_doc, 'snakebacon.tex', 'snakebacon Documentation', 153 | 'S. Brewster Malevich', 'manual'), 154 | ] 155 | 156 | # -- Options for manual page output --------------------------------------- 157 | 158 | # One entry per manual page. List of tuples 159 | # (source start file, name, description, authors, manual section). 160 | man_pages = [ 161 | (master_doc, 'snakebacon', 'snakebacon Documentation', 162 | [author], 1) 163 | ] 164 | 165 | # -- Options for Texinfo output ------------------------------------------- 166 | 167 | # Grouping the document tree into Texinfo files. List of tuples 168 | # (source start file, target name, title, author, 169 | # dir menu entry, description, category) 170 | texinfo_documents = [ 171 | (master_doc, 'snakebacon', 'snakebacon Documentation', 172 | author, 'snakebacon', 'One line description of project.', 173 | 'Miscellaneous'), 174 | ] 175 | 176 | # Example configuration for intersphinx: refer to the Python standard library. 177 | intersphinx_mapping = { 178 | 'python': ('https://docs.python.org/3.5/', None), 179 | 'pandas': ('http://pandas.pydata.org/pandas-docs/stable/', None), 180 | 'numpy': ('http://docs.scipy.org/doc/numpy/', None), 181 | } 182 | -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/bacon/input.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "input.h" 7 | 8 | #define BUFFSZ 1024 9 | 10 | //Set to point at the beginning of each parameter in buff 11 | //Substitute commas or semicolon with \0 12 | int Input::GetPars() { 13 | 14 | int len = strlen(buff); 15 | numofpars = 0; 16 | pars[numofpars] = buff; //First par 17 | 18 | for (int i = 0; i < len; i++) { 19 | 20 | if (buff[i] == ',') { //Middle par 21 | buff[i] = '\0'; 22 | sscanf(pars[numofpars], " %lf", rpars + numofpars); //Try to read par. as double 23 | 24 | numofpars++; 25 | pars[numofpars] = buff + i + 1; //Next par 26 | 27 | continue; 28 | } 29 | 30 | if (buff[i] == ';') { //end 31 | buff[i] = '\0'; 32 | sscanf(pars[numofpars], " %lf", rpars + numofpars); //Try to read par. as double 33 | 34 | numofpars++; 35 | return numofpars; 36 | } 37 | } 38 | } 39 | 40 | 41 | Input::Input(char *datafile, int emaxnumofcurves, int maxm) { 42 | 43 | 44 | //Open the array to hold all c. curves 45 | maxnumofcurves = emaxnumofcurves; 46 | curves = new Cal *[maxnumofcurves]; 47 | numofcurves = 0; 48 | 49 | //Open the object to hold all determinations 50 | dets = new Dets(maxm); 51 | Det *tmpdet; 52 | 53 | //Open the array of pointers to point at each parameter 54 | maxnumofpars = MAXNUMOFPARS; 55 | pars = new char *[maxnumofpars]; 56 | numofpars = 0; 57 | rpars = new double[maxnumofpars]; 58 | 59 | 60 | //Open a double array of doubles to hold the hiatuses locations, if any, 61 | //0=h's 1=alpha's 2=betas's 3=ha's and 4=hb's for each hiatus section 62 | hiatus_pars = new double *[5]; //pointers to rows 63 | for (int i = 0; i < 5; i++) 64 | hiatus_pars[i] = new double[MAXNUMOFHIATUS]; //open each row 65 | H = 0; //set to zero hiatuses at the begining 66 | 67 | 68 | FILE *F; 69 | 70 | if ((F = fopen(datafile, "r")) == NULL) { 71 | printf("Could not open %s for reading\n", datafile); 72 | 73 | exit(-1); 74 | } 75 | 76 | printf("Reading %s\n", datafile); 77 | char line[BUFFSZ]; 78 | char key[10]; 79 | int i = 0, nm, j; 80 | 81 | 82 | do { 83 | if (fgets(line, BUFFSZ, F)); 84 | i++; 85 | 86 | //Remove leading blank spaces 87 | j = 0; 88 | while (line[j] == ' ') 89 | j++; 90 | 91 | 92 | if ((line[j] == '#') || (line[j] == '\n')) //Comment or blank line, ignore line 93 | continue; 94 | 95 | //This is the syntax, key number : parameters 96 | if (sscanf(line, " %s %d :", key, &nm) < 2) { 97 | printf("%s:%d Syntax error\n\n", datafile, i); 98 | 99 | break; 100 | } 101 | 102 | buff = strstr(line, ":") + 1; 103 | GetPars(); 104 | 105 | /**** Debug *** 106 | printf("%d: KEY: %s, n= %d, %d pars:", i, key, nm, numofpars);//Debug 107 | for (int i=0; iAddDet(tmpdet); 158 | 159 | continue; 160 | } 161 | 162 | 163 | if (strcmp(key, "Hiatus") == 0) { 164 | hiatus_pars[0][H] = rpars[0]; //Hiatus position 165 | 166 | hiatus_pars[1][H] = rpars[1]; //alpha 167 | hiatus_pars[2][H] = rpars[2]; //beta 168 | 169 | hiatus_pars[3][H] = rpars[3]; //ha 170 | hiatus_pars[4][H] = rpars[4]; //hb 171 | 172 | printf("Hiatus at: %f\n", hiatus_pars[0][H]); 173 | 174 | H++; 175 | 176 | //If H==0 then hiatus_pars willl be ignored in the constructors BaconFix and BaconMov 177 | continue; 178 | } 179 | 180 | if (strcmp(key, "Bacon") == 0) { 181 | //Include the parameters for the last (first) section, or for the whole core if H == 0 182 | hiatus_pars[0][H] = -10.0; //Hiatus position, in this case, this one will be ignored 183 | 184 | hiatus_pars[1][H] = rpars[7 + 1]; //alpha 185 | hiatus_pars[2][H] = rpars[7 + 2]; //beta 186 | 187 | hiatus_pars[3][H] = 0.0; //ha, in this case, this one will be ignored 188 | hiatus_pars[4][H] = 0.0; //hb, in this case, this one will be ignored 189 | 190 | unsigned long int seed; 191 | if (numofpars == 11) 192 | seed = 0; //automatic seed set with time() 193 | else 194 | seed = (unsigned long int) rpars[11]; 195 | 196 | 197 | //Open the Bacon object 198 | sscanf(pars[0], " %s", line); //type of object 199 | 200 | if (strcmp(line, "FixNor") == 0) 201 | //dets K H hiatus_pars a b 202 | bacon = new BaconFix(dets, (int) rpars[1], H, hiatus_pars, rpars[6], rpars[7], 203 | rpars[2], rpars[3], rpars[4], rpars[5], rpars[10], rpars[11], 0, seed); 204 | //MinYr MaxYr th0 thp0 c0 cm useNor 205 | 206 | if (strcmp(line, "FixT") == 0) 207 | //dets K H hiatus_pars a b 208 | bacon = new BaconFix(dets, (int) rpars[1], H, hiatus_pars, rpars[6], rpars[7], 209 | rpars[2], rpars[3], rpars[4], rpars[5], rpars[10], rpars[11], 1, seed); 210 | //MinYr MaxYr th0 thp0 c0 cm useT 211 | 212 | 213 | 214 | //Then open the twalk object 215 | BaconTwalk = new twalk(*bacon, bacon->Getx0(), bacon->Getxp0(), bacon->get_dim()); 216 | 217 | break; //this should be the last key in the program 218 | } 219 | 220 | printf("Unknown key: %s\n", key); 221 | 222 | } while (!feof(F)); 223 | 224 | bacon->ShowDescrip(); 225 | 226 | printf("\n"); 227 | } 228 | 229 | 230 | 231 | 232 | -------------------------------------------------------------------------------- /snakebacon/agedepth.py: -------------------------------------------------------------------------------- 1 | import logging as logging 2 | 3 | import scipy 4 | import matplotlib.pylab as plt 5 | from matplotlib.collections import PatchCollection 6 | from matplotlib.patches import Polygon 7 | import numpy as np 8 | 9 | from .mcmc import McmcSetup 10 | from .records import DatedProxyRecord 11 | 12 | 13 | log = logging.getLogger(__name__) 14 | 15 | 16 | class AgeDepthModel: 17 | def __init__(self, coredates, *, mcmc_kws, hold=False, burnin=200): 18 | self.burnin = int(burnin) 19 | self.mcmcsetup = McmcSetup(coredates, **mcmc_kws) 20 | self._mcmcfit = None 21 | self._thick = None 22 | self._depth = None 23 | self._age_ensemble = None 24 | if not hold: 25 | self.fit() 26 | 27 | @property 28 | def mcmcfit(self): 29 | if self._mcmcfit is not None: 30 | return self._mcmcfit 31 | else: 32 | raise NeedFitError('AgeDepthModel instance needs to be fit() first') 33 | 34 | @property 35 | def thick(self): 36 | if self._thick is not None: 37 | return self._thick 38 | else: 39 | raise NeedFitError('AgeDepthModel instance needs to be fit() first') 40 | 41 | @property 42 | def depth(self): 43 | if self._depth is not None: 44 | return self._depth 45 | else: 46 | raise NeedFitError('AgeDepthModel instance needs to be fit() first') 47 | 48 | @property 49 | def age_ensemble(self): 50 | if self._age_ensemble is not None: 51 | return self._age_ensemble 52 | else: 53 | raise NeedFitError('AgeDepthModel instance needs to be fit() first') 54 | 55 | def __repr__(self): 56 | return '%s(coredates=%r, mcmc_kws=%r, burnin=%r)' % (type(self).__name__, self.mcmcsetup.coredates, self.mcmcsetup.mcmc_kws, self.burnin) 57 | 58 | def age_median(self): 59 | return np.median(self.age_ensemble, axis=1) 60 | 61 | def age_percentile(self, p): 62 | return np.percentile(self.age_ensemble, q=p, axis=1) 63 | 64 | def fit(self): 65 | """Fit MCMC AgeDepthModel""" 66 | self._mcmcfit = self.mcmcsetup.run() 67 | self._mcmcfit.burnin(self.burnin) 68 | dmin = min(self._mcmcfit.depth_segments) 69 | dmax = max(self._mcmcfit.depth_segments) 70 | self._thick = (dmax - dmin) / len(self.mcmcfit.depth_segments) 71 | self._depth = np.arange(dmin, dmax + 0.001) 72 | self._age_ensemble = np.array([self.agedepth(d=dx) for dx in self.depth]) 73 | 74 | def date(self, proxy, how='median', n=500): 75 | """Date a proxy record 76 | 77 | Parameters 78 | ---------- 79 | proxy : ProxyRecord 80 | how : str 81 | How to perform the dating. 'median' returns the average of the MCMC ensemble. 'ensemble' returns a 'n' 82 | randomly selected members of the MCMC ensemble. Default is 'median'. 83 | n : int 84 | If 'how' is 'ensemble', the function will randomly select 'n' MCMC ensemble members, with replacement. 85 | 86 | Returns 87 | ------- 88 | DatedProxyRecord 89 | """ 90 | assert how in ['median', 'ensemble'] 91 | ens_members = self.mcmcfit.n_members() 92 | if how == 'ensemble': 93 | select_idx = np.random.choice(range(ens_members), size=n, replace=True) 94 | out = [] 95 | for d in proxy.data.depth.values: 96 | age = self.agedepth(d) 97 | if how == 'median': 98 | age = np.median(age) 99 | elif how == 'ensemble': 100 | age = age[select_idx] 101 | out.append(age) 102 | return DatedProxyRecord(proxy.data.copy(), out) 103 | 104 | def plot(self, agebins=50, p=(2.5, 97.5), ax=None): 105 | """Age-depth plot""" 106 | if ax is None: 107 | ax = plt.gca() 108 | ax.hist2d(np.repeat(self.depth, self.age_ensemble.shape[1]), self.age_ensemble.flatten(), 109 | (len(self.depth), agebins), cmin=1) 110 | ax.step(self.depth, self.age_median(), where='mid', color='red') 111 | ax.step(self.depth, self.age_percentile(p[0]), where='mid', color='red', linestyle=':') 112 | ax.step(self.depth, self.age_percentile(p[1]), where='mid', color='red', linestyle=':') 113 | ax.set_ylabel('Age (cal yr BP)') 114 | ax.set_xlabel('Depth (cm)') 115 | ax.grid(True) 116 | return ax 117 | 118 | def agedepth(self, d): 119 | """Get calendar age for a depth 120 | 121 | Parameters 122 | ---------- 123 | d : float 124 | Sediment depth (in cm). 125 | 126 | Returns 127 | ------- 128 | Numeric giving true age at given depth. 129 | """ 130 | # TODO(brews): Function cannot handle hiatus 131 | # See lines 77 - 100 of hist2.cpp 132 | x = self.mcmcfit.sediment_rate 133 | theta0 = self.mcmcfit.headage # Age abscissa (in yrs). If array, dimension should be iterations or realizations of the sediment 134 | deltac = self.thick 135 | c0 = min(self.depth) # Uniform depth segment abscissa (in cm). 136 | assert d > c0 or np.isclose(c0, d, atol = 1e-4) 137 | out = theta0.astype(float) 138 | i = int(np.floor((d - c0) / deltac)) 139 | for j in range(i): 140 | out += x[j] * deltac 141 | ci = c0 + i * deltac 142 | assert ci < d or np.isclose(ci, d, atol = 1e-4) 143 | try: 144 | next_x = x[i] 145 | except IndexError: 146 | # Extrapolating 147 | next_x = x[i - 1] 148 | out += next_x * (d - ci) 149 | return out 150 | 151 | def prior_dates(self): 152 | return self.mcmcsetup.prior_dates() 153 | 154 | def plot_prior_dates(self, dwidth=30, ax=None): 155 | """Plot prior chronology dates in age-depth plot""" 156 | if ax is None: 157 | ax = plt.gca() 158 | depth, probs = self.prior_dates() 159 | pat = [] 160 | for i, d in enumerate(depth): 161 | p = probs[i] 162 | z = np.array([p[:, 0], dwidth * p[:, 1] / np.sum(p[:, 1])]) # Normalize 163 | z = z[:, z[0].argsort(kind='mergesort')] # np.interp requires `xp` arg to be sorted 164 | zy = np.linspace(np.min(z[0]), np.max(z[0]), num=200) 165 | zp = np.interp(x=zy, xp=z[0], fp=z[1]) 166 | pol = np.vstack([np.concatenate([d + zp, d - zp[::-1]]), 167 | np.concatenate([zy, zy[::-1]])]) 168 | pat.append(Polygon(pol.T)) 169 | p = PatchCollection(pat) 170 | p.set_label('Prior dates') 171 | ax.add_collection(p) 172 | ax.autoscale_view() 173 | ax.set_ylabel('Age (cal yr BP)') 174 | ax.set_xlabel('Depth (cm)') 175 | ax.grid(True) 176 | return ax 177 | 178 | def prior_sediment_rate(self): 179 | return self.mcmcsetup.prior_sediment_rate() 180 | 181 | def plot_sediment_rate(self, ax=None): 182 | """Plot sediment accumulation rate prior and posterior distributions""" 183 | if ax is None: 184 | ax = plt.gca() 185 | 186 | y_prior, x_prior = self.prior_sediment_rate() 187 | ax.plot(x_prior, y_prior, label='Prior') 188 | 189 | y_posterior = self.mcmcfit.sediment_rate 190 | density = scipy.stats.gaussian_kde(y_posterior.flat) 191 | density.covariance_factor = lambda: 0.25 192 | density._compute_covariance() 193 | ax.plot(x_prior, density(x_prior), label='Posterior') 194 | 195 | acc_shape = self.mcmcsetup.mcmc_kws['acc_shape'] 196 | acc_mean = self.mcmcsetup.mcmc_kws['acc_mean'] 197 | annotstr_template = 'acc_shape: {0}\nacc_mean: {1}' 198 | annotstr = annotstr_template.format(acc_shape, acc_mean) 199 | ax.annotate(annotstr, xy=(0.9, 0.9), xycoords='axes fraction', 200 | horizontalalignment='right', verticalalignment='top') 201 | 202 | ax.set_ylabel('Density') 203 | ax.set_xlabel('Acc. rate (yr/cm)') 204 | ax.grid(True) 205 | return ax 206 | 207 | def prior_sediment_memory(self): 208 | return self.mcmcsetup.prior_sediment_memory() 209 | 210 | def plot_sediment_memory(self, ax=None): 211 | """Plot sediment memory prior and posterior distributions""" 212 | if ax is None: 213 | ax = plt.gca() 214 | 215 | y_prior, x_prior = self.prior_sediment_memory() 216 | ax.plot(x_prior, y_prior, label='Prior') 217 | 218 | y_posterior = self.mcmcfit.sediment_memory 219 | density = scipy.stats.gaussian_kde(y_posterior ** (1/self.thick)) 220 | density.covariance_factor = lambda: 0.25 221 | density._compute_covariance() 222 | ax.plot(x_prior, density(x_prior), label='Posterior') 223 | 224 | mem_mean = self.mcmcsetup.mcmc_kws['mem_mean'] 225 | mem_strength = self.mcmcsetup.mcmc_kws['mem_strength'] 226 | annotstr_template = 'mem_strength: {0}\nmem_mean: {1}\nthick: {2} cm' 227 | annotstr = annotstr_template.format(mem_strength, mem_mean, self.thick) 228 | ax.annotate(annotstr, xy=(0.9, 0.9), xycoords='axes fraction', 229 | horizontalalignment='right', verticalalignment='top') 230 | 231 | ax.set_ylabel('Density') 232 | ax.set_xlabel('Memory (ratio)') 233 | ax.grid(True) 234 | return ax 235 | 236 | 237 | class NeedFitError(Exception): 238 | pass 239 | -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/bacon/Curves/postbomb_SH3.14C: -------------------------------------------------------------------------------- 1 | 0 220 28 2 | -1 221 27 3 | -2 222 40 4 | -3 211 26 5 | -4 158 25 6 | -5 161 26 7 | -6 98 32 8 | -7 -264 27 9 | -8 -591 27 10 | -9 -1132 28 11 | -10 -1399 28 12 | -11 -1547 28 13 | -12 -1614 25 14 | -13 -2492 24 15 | -14 -3756 32 16 | -15 -4120 22 17 | -16 -3959 25 18 | -17 -3891 26 19 | -18 -3709 21 20 | -19 -3644 25 21 | -20 -3417 30 22 | -21 -3388 24 23 | -22 -3296 28 24 | -23.04 -3061 34 25 | -23.12 -3021 36 26 | -23.2 -2980 30 27 | -23.28 -2981 57 28 | -23.37 -2953 40 29 | -23.45 -2912 20 30 | -23.53 -2933 41 31 | -23.62 -2948 86 32 | -23.7 -2868 71 33 | -23.79 -2856 54 34 | -23.87 -2856 84 35 | -23.95 -2861 128 36 | -24.04 -2809 59 37 | -24.12 -2809 112 38 | -24.2 -2803 26 39 | -24.28 -2787 44 40 | -24.37 -2745 85 41 | -24.45 -2665 145 42 | -24.53 -2703 33 43 | -24.62 -2702 115 44 | -24.7 -2731 23 45 | -24.79 -2788 76 46 | -24.87 -2734 14 47 | -24.95 -2702 32 48 | -25.04 -2716 35 49 | -25.12 -2669 72 50 | -25.2 -2698 30 51 | -25.28 -2686 41 52 | -25.37 -2641 30 53 | -25.45 -2674 53 54 | -25.53 -2575 36 55 | -25.62 -2569 85 56 | -25.7 -2520 42 57 | -25.79 -2596 88 58 | -25.87 -2524 21 59 | -25.95 -2541 53 60 | -26.04 -2555 25 61 | -26.12 -2541 32 62 | -26.2 -2532 68 63 | -26.28 -2468 65 64 | -26.37 -2473 35 65 | -26.45 -2469 35 66 | -26.53 -2462 48 67 | -26.62 -2400 14 68 | -26.7 -2395 30 69 | -26.79 -2355 52 70 | -26.87 -2392 54 71 | -26.95 -2356 41 72 | -27.04 -2319 80 73 | -27.12 -2376 42 74 | -27.2 -2364 19 75 | -27.28 -2407 20 76 | -27.37 -2349 22 77 | -27.45 -2313 63 78 | -27.53 -2314 35 79 | -27.62 -2284 18 80 | -27.7 -2257 49 81 | -27.79 -2310 40 82 | -27.87 -2319 47 83 | -27.95 -2337 56 84 | -28.04 -2279 66 85 | -28.12 -2340 75 86 | -28.2 -2276 25 87 | -28.28 -2256 40 88 | -28.37 -2203 35 89 | -28.45 -2205 20 90 | -28.53 -2294 36 91 | -28.62 -2208 47 92 | -28.7 -2238 64 93 | -28.79 -2273 40 94 | -28.87 -2203 77 95 | -29.04 -2200 18 96 | -29.12 -2136 43 97 | -29.2 -2166 37 98 | -29.28 -2156 20 99 | -29.37 -2122 25 100 | -29.45 -2086 19 101 | -29.53 -2149 56 102 | -29.62 -2037 24 103 | -29.7 -2122 50 104 | -29.79 -2051 55 105 | -29.87 -2151 21 106 | -29.95 -2006 50 107 | -30.04 -2069 43 108 | -30.12 -2041 43 109 | -30.2 -2062 21 110 | -30.28 -2000 19 111 | -30.37 -2011 18 112 | -30.45 -1924 38 113 | -30.53 -1999 61 114 | -30.62 -1973 20 115 | -30.7 -1996 18 116 | -30.79 -2015 28 117 | -30.87 -2005 81 118 | -30.95 -1969 78 119 | -31.04 -1933 22 120 | -31.12 -1930 84 121 | -31.2 -1935 38 122 | -31.28 -1940 41 123 | -31.37 -1868 38 124 | -31.45 -1883 58 125 | -31.53 -1855 38 126 | -31.62 -1884 21 127 | -31.7 -1878 25 128 | -31.79 -1867 18 129 | -31.87 -1881 61 130 | -31.95 -1867 34 131 | -32.04 -1875 38 132 | -32.12 -1778 45 133 | -32.2 -2027 44 134 | -32.28 -1779 45 135 | -32.37 -1771 58 136 | -32.45 -1787 74 137 | -32.53 -1798 46 138 | -32.62 -1740 45 139 | -32.7 -1779 33 140 | -32.79 -1773 32 141 | -32.87 -1747 45 142 | -32.95 -1733 20 143 | -33.04 -1725 21 144 | -33.12 -1678 24 145 | -33.2 -1721 21 146 | -33.28 -1793 38 147 | -33.37 -1696 39 148 | -33.45 -1713 43 149 | -33.53 -1610 39 150 | -33.62 -1709 45 151 | -33.7 -1702 39 152 | -33.79 -1654 37 153 | -33.87 -1709 45 154 | -33.95 -1604 39 155 | -34.04 -1639 77 156 | -34.12 -1684 31 157 | -34.2 -1683 58 158 | -34.28 -1584 33 159 | -34.37 -1593 22 160 | -34.45 -1591 39 161 | -34.53 -1584 20 162 | -34.62 -1707 95 163 | -34.7 -1564 34 164 | -34.79 -1542 16 165 | -34.87 -1559 46 166 | -34.95 -1614 12 167 | -35.04 -1578 46 168 | -35.12 -1559 44 169 | -35.2 -1572 47 170 | -35.28 -1522 15 171 | -35.37 -1523 34 172 | -35.45 -1432 40 173 | -35.53 -1507 62 174 | -35.62 -1511 56 175 | -35.7 -1518 42 176 | -35.79 -1497 31 177 | -35.87 -1539 28 178 | -35.95 -1529 27 179 | -36.04 -1499 25 180 | -36.12 -1483 39 181 | -36.2 -1487 25 182 | -36.28 -1467 31 183 | -36.37 -1440 38 184 | -36.45 -1477 22 185 | -36.53 -1445 28 186 | -36.62 -1434 17 187 | -36.7 -1479 17 188 | -36.79 -1479 24 189 | -36.87 -1423 18 190 | -36.95 -1442 27 191 | -37.04 -1421 15 192 | -37.12 -1407 15 193 | -37.2 -1387 19 194 | -37.28 -1379 14 195 | -37.37 -1347 31 196 | -37.45 -1250 118 197 | -37.53 -1339 14 198 | -37.62 -1336 33 199 | -37.7 -1359 16 200 | -37.79 -1366 14 201 | -37.87 -1399 20 202 | -37.95 -1385 12 203 | -38.12 -1441 20 204 | -38.2 -1342 14 205 | -38.28 -1343 16 206 | -38.37 -1243 34 207 | -38.45 -1230 41 208 | -38.53 -1206 145 209 | -38.62 -1302 23 210 | -38.7 -1303 27 211 | -38.79 -1307 53 212 | -38.87 -1341 30 213 | -38.95 -1304 22 214 | -39.04 -1298 91 215 | -39.12 -1296 23 216 | -39.2 -1216 41 217 | -39.28 -1286 41 218 | -39.37 -1245 21 219 | -39.45 -1241 32 220 | -39.53 -1192 49 221 | -39.62 -1273 68 222 | -39.7 -1198 22 223 | -39.79 -1201 31 224 | -39.87 -1243 28 225 | -39.95 -1268 31 226 | -40.04 -1195 21 227 | -40.12 -1230 81 228 | -40.2 -1220 44 229 | -40.28 -1221 39 230 | -40.37 -1113 42 231 | -40.45 -1148 85 232 | -40.53 -1185 74 233 | -40.62 -1149 87 234 | -40.7 -1209 100 235 | -40.79 -1186 23 236 | -40.87 -1157 75 237 | -40.95 -1203 53 238 | -41.04 -1159 71 239 | -41.12 -1149 83 240 | -41.2 -1193 109 241 | -41.28 -1111 37 242 | -41.37 -1114 82 243 | -41.45 -1149 98 244 | -41.53 -1154 119 245 | -41.62 -1168 81 246 | -41.7 -1212 16 247 | -41.79 -1222 70 248 | -41.87 -1110 58 249 | -41.95 -1169 22 250 | -42.04 -1107 64 251 | -42.12 -1196 35 252 | -42.2 -1100 35 253 | -42.28 -1236 69 254 | -42.37 -1232 107 255 | -42.45 -1087 42 256 | -42.53 -1139 142 257 | -42.62 -1108 37 258 | -42.7 -1080 42 259 | -42.79 -1132 17 260 | -42.87 -1158 42 261 | -42.95 -1118 52 262 | -43.04 -1136 22 263 | -43.12 -1069 92 264 | -43.2 -1069 22 265 | -43.28 -1014 68 266 | -43.37 -1040 45 267 | -43.45 -975 48 268 | -43.53 -1003 18 269 | -43.62 -1033 63 270 | -43.7 -1036 33 271 | -43.79 -996 42 272 | -43.87 -1109 42 273 | -43.95 -999 28 274 | -44.04 -977 13 275 | -44.12 -971 50 276 | -44.2 -970 32 277 | -44.28 -1008 17 278 | -44.37 -976 16 279 | -44.45 -957 60 280 | -44.53 -955 21 281 | -44.62 -939 12 282 | -44.7 -955 20 283 | -44.79 -955 25 284 | -44.87 -964 33 285 | -44.95 -980 32 286 | -45.04 -970 33 287 | -45.12 -955 19 288 | -45.2 -936 16 289 | -45.28 -941 12 290 | -45.37 -930 25 291 | -45.45 -916 49 292 | -45.53 -913 13 293 | -45.62 -910 13 294 | -45.7 -920 16 295 | -45.79 -902 13 296 | -45.87 -896 14 297 | -45.95 -922 46 298 | -46.04 -920 26 299 | -46.12 -920 16 300 | -46.2 -911 10 301 | -46.28 -923 11 302 | -46.37 -900 15 303 | -46.45 -895 14 304 | -46.53 -890 11 305 | -46.62 -887 17 306 | -46.7 -871 42 307 | -46.79 -900 31 308 | -46.87 -872 19 309 | -46.95 -853 12 310 | -47.04 -845 48 311 | -47.12 -857 19 312 | -47.2 -854 24 313 | -47.28 -855 22 314 | -47.37 -891 17 315 | -47.45 -863 22 316 | -47.53 -885 22 317 | -47.62 -814 29 318 | -47.7 -863 32 319 | -47.79 -840 12 320 | -47.87 -856 16 321 | -47.95 -873 17 322 | -48.04 -852 19 323 | -48.12 -841 14 324 | -48.2 -819 22 325 | -48.28 -842 22 326 | -48.37 -798 15 327 | -48.45 -827 22 328 | -48.53 -807 21 329 | -48.62 -825 22 330 | -48.7 -813 16 331 | -48.79 -793 13 332 | -48.87 -784 9 333 | -48.95 -791 10 334 | -49.04 -760 10 335 | -49.12 -791 11 336 | -49.2 -793 9 337 | -49.28 -761 12 338 | -49.37 -779 20 339 | -49.45 -798 46 340 | -49.53 -786 8 341 | -49.62 -752 34 342 | -49.7 -749 16 343 | -49.79 -742 31 344 | -49.87 -763 9 345 | -49.95 -840 59 346 | -50.04 -763 8 347 | -50.12 -766 10 348 | -50.2 -764 23 349 | -50.28 -739 15 350 | -50.37 -723 50 351 | -50.45 -702 44 352 | -50.53 -709 15 353 | -50.62 -699 13 354 | -50.7 -739 20 355 | -50.79 -735 23 356 | -50.87 -734 35 357 | -50.95 -721 34 358 | -51.04 -744 24 359 | -51.12 -725 14 360 | -51.2 -697 25 361 | -51.28 -722 21 362 | -51.37 -723 9 363 | -51.45 -697 13 364 | -51.53 -727 12 365 | -51.62 -683 13 366 | -51.7 -689 29 367 | -51.79 -678 25 368 | -51.87 -687 23 369 | -51.95 -692 21 370 | -52.04 -671 25 371 | -52.12 -668 26 372 | -52.2 -692 10 373 | -52.28 -699 29 374 | -52.37 -697 15 375 | -52.45 -652 11 376 | -52.53 -666 11 377 | -52.62 -661 19 378 | -52.7 -644 24 379 | -52.79 -653 10 380 | -52.87 -665 10 381 | -52.95 -659 26 382 | -53.04 -700 13 383 | -53.12 -653 27 384 | -53.2 -652 35 385 | -53.28 -655 27 386 | -53.37 -666 44 387 | -53.45 -617 31 388 | -53.53 -646 36 389 | -53.62 -632 16 390 | -53.7 -602 37 391 | -53.79 -609 25 392 | -53.87 -619 32 393 | -53.95 -634 9 394 | -54.04 -593 43 395 | -54.12 -615 14 396 | -54.2 -610 8 397 | -54.28 -612 31 398 | -54.37 -601 7 399 | -54.45 -589 31 400 | -54.53 -579 29 401 | -54.62 -582 29 402 | -54.7 -579 28 403 | -54.79 -562 49 404 | -54.87 -581 31 405 | -54.95 -564 24 406 | -55.04 -582 8 407 | -55.12 -571 16 408 | -55.2 -568 18 409 | -55.28 -579 57 410 | -55.37 -566 34 411 | -55.45 -547 25 412 | -55.53 -551 24 413 | -55.62 -558 21 414 | -55.7 -552 25 415 | -55.79 -562 8 416 | -55.87 -544 24 417 | -55.95 -535 27 418 | -56.04 -547 13 419 | -56.12 -559 20 420 | -56.2 -544 6 421 | -56.28 -535 7 422 | -56.37 -510 26 423 | -56.45 -525 13 424 | -56.53 -525 26 425 | -56.62 -521 11 426 | -56.7 -519 11 427 | -56.79 -525 6 428 | -56.87 -522 27 429 | -56.95 -512 29 430 | -57.04 -503 29 431 | -57.12 -474 28 432 | -57.2 -494 35 433 | -57.28 -530 20 434 | -57.37 -505 21 435 | -57.45 -510 35 436 | -57.53 -482 16 437 | -57.62 -494 18 438 | -57.7 -495 20 439 | -57.79 -504 27 440 | -57.87 -491 25 441 | -57.95 -487 31 442 | -58.04 -480 8 443 | -58.12 -494 10 444 | -58.2 -495 8 445 | -58.28 -467 20 446 | -58.37 -476 15 447 | -58.45 -455 9 448 | -58.53 -458 11 449 | -58.62 -473 8 450 | -58.7 -467 16 451 | -58.79 -443 16 452 | -58.87 -467 14 453 | -58.95 -464 11 454 | -59.04 -461 11 455 | -59.12 -456 14 456 | -59.2 -465 10 457 | -59.28 -449 13 458 | -59.37 -446 12 459 | -59.45 -466 9 460 | -59.53 -454 12 461 | -59.7 -446 13 462 | -59.79 -468 13 463 | -59.87 -464 8 464 | -59.95 -464 9 465 | -60.28 -449 9 466 | -60.37 -449 9 467 | -60.45 -431 10 468 | -60.53 -455 17 469 | -60.7 -448 9 470 | -60.79 -433 12 471 | -60.87 -451 9 472 | -61.04 -413 9 473 | -61.12 -400 9 474 | -61.2 -383 9 475 | -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/bacon/Curves/postbomb_NH3.14C: -------------------------------------------------------------------------------- 1 | -0.5 220 19 2 | -1.5 208 20 3 | -2.5 200 40 4 | -3.5 188 29 5 | -4.5 214 32 6 | -5.5 -4 188 7 | -6.5 -140 35 8 | -7.5 -281 43 9 | -8.5 -974 38 10 | -9.5 -1637 47 11 | -10.5 -1507 33 12 | -11.5 -1651 41 13 | -12.5 -2074 41 14 | -13.37 -3336 348 15 | -13.45 -3305 53 16 | -13.53 -3724 100 17 | -13.62 -4141 138 18 | -13.7 -3923 54 19 | -13.79 -4140 53 20 | -13.87 -4168 62 21 | -13.95 -4016 87 22 | -14.12 -4192 38 23 | -14.2 -4140 95 24 | -14.28 -4081 106 25 | -14.37 -4208 137 26 | -14.45 -4367 135 27 | -14.62 -4240 52 28 | -14.7 -4349 61 29 | -14.87 -4391 56 30 | -14.95 -4367 28 31 | -15.04 -4433 51 32 | -15.12 -4335 51 33 | -15.2 -4259 47 34 | -15.28 -4245 57 35 | -15.37 -4302 56 36 | -15.45 -4335 56 37 | -15.53 -4382 60 38 | -15.62 -4405 56 39 | -15.7 -4307 56 40 | -15.79 -4321 56 41 | -15.87 -4387 65 42 | -15.95 -4359 56 43 | -16.04 -4232 80 44 | -16.12 -3777 60 45 | -16.28 -4093 58 46 | -16.37 -4025 58 47 | -16.62 -4208 90 48 | -16.7 -4098 53 49 | -16.79 -4104 48 50 | -16.87 -4045 58 51 | -16.95 -3902 54 52 | -17.04 -3906 54 53 | -17.2 -3921 59 54 | -17.28 -3919 59 55 | -17.87 -3732 60 56 | -18.2 -3547 57 57 | -18.28 -3547 57 58 | -18.37 -3717 60 59 | -18.53 -3417 73 60 | -18.7 -3599 82 61 | -18.79 -3651 66 62 | -19.37 -3532 93 63 | -19.53 -3507 103 64 | -20.5 -3317 39 65 | -21.5 -3416 38 66 | -22.5 -3053 51 67 | -23.04 -2924 90 68 | -23.12 -2950 39 69 | -23.2 -2919 81 70 | -23.28 -2918 74 71 | -23.37 -2851 145 72 | -23.45 -2994 45 73 | -23.53 -2895 117 74 | -23.62 -3014 151 75 | -23.7 -2990 131 76 | -23.79 -2941 19 77 | -23.87 -2945 31 78 | -23.95 -2725 27 79 | -24.04 -2852 62 80 | -24.12 -2784 79 81 | -24.2 -2830 51 82 | -24.28 -2816 51 83 | -24.37 -2832 39 84 | -24.45 -2850 39 85 | -24.53 -2813 51 86 | -24.62 -2875 50 87 | -24.7 -2732 108 88 | -24.79 -2775 84 89 | -24.87 -2706 149 90 | -24.95 -2570 120 91 | -25.04 -2580 125 92 | -25.12 -2590 118 93 | -25.2 -2519 96 94 | -25.28 -2593 87 95 | -25.37 -2597 109 96 | -25.45 -2692 46 97 | -25.53 -2745 68 98 | -25.62 -2624 86 99 | -25.7 -2687 63 100 | -25.79 -2682 80 101 | -25.87 -2549 27 102 | -25.95 -2570 28 103 | -26.04 -2492 38 104 | -26.12 -2488 37 105 | -26.2 -2377 138 106 | -26.28 -2387 43 107 | -26.37 -2401 15 108 | -26.45 -2445 75 109 | -26.53 -2479 30 110 | -26.62 -2415 50 111 | -26.7 -2430 31 112 | -26.79 -2346 60 113 | -26.87 -2416 26 114 | -26.95 -2314 92 115 | -27.04 -2329 53 116 | -27.12 -2313 61 117 | -27.2 -2342 37 118 | -27.28 -2320 26 119 | -27.37 -2328 48 120 | -27.45 -2346 53 121 | -27.53 -2377 66 122 | -27.62 -2338 26 123 | -27.7 -2334 55 124 | -27.79 -2309 43 125 | -27.87 -2278 46 126 | -27.95 -2209 15 127 | -28.04 -2230 49 128 | -28.12 -2267 36 129 | -28.2 -2263 30 130 | -28.28 -2273 18 131 | -28.37 -2271 29 132 | -28.45 -2334 29 133 | -28.53 -2295 61 134 | -28.62 -2275 108 135 | -28.7 -2238 85 136 | -28.79 -2222 78 137 | -28.87 -2238 56 138 | -28.95 -2221 29 139 | -29.04 -2163 16 140 | -29.12 -2130 37 141 | -29.2 -2104 46 142 | -29.28 -2103 55 143 | -29.37 -2092 72 144 | -29.45 -2074 54 145 | -29.53 -2055 66 146 | -29.62 -2131 27 147 | -29.7 -2070 60 148 | -29.79 -2062 45 149 | -29.87 -2049 51 150 | -29.95 -1959 65 151 | -30.04 -1952 35 152 | -30.12 -1926 61 153 | -30.2 -1872 79 154 | -30.28 -1916 62 155 | -30.37 -1911 58 156 | -30.45 -1950 42 157 | -30.53 -1990 32 158 | -30.62 -1938 29 159 | -30.7 -1943 78 160 | -30.79 -1918 65 161 | -30.87 -1872 35 162 | -30.95 -1843 48 163 | -31.04 -1827 52 164 | -31.12 -1897 52 165 | -31.2 -1813 33 166 | -31.28 -1810 31 167 | -31.37 -1843 49 168 | -31.45 -1905 47 169 | -31.53 -1881 68 170 | -31.62 -1855 52 171 | -31.7 -1850 43 172 | -31.79 -1913 25 173 | -31.87 -1785 26 174 | -31.95 -1854 81 175 | -32.04 -1802 12 176 | -32.12 -1775 17 177 | -32.2 -1749 39 178 | -32.28 -1749 52 179 | -32.37 -1776 42 180 | -32.45 -1755 42 181 | -32.53 -1735 59 182 | -32.62 -1764 30 183 | -32.7 -1749 17 184 | -32.79 -1749 41 185 | -32.87 -1709 51 186 | -32.95 -1705 32 187 | -33.04 -1671 63 188 | -33.12 -1660 20 189 | -33.2 -1707 19 190 | -33.28 -1673 34 191 | -33.37 -1657 47 192 | -33.45 -1714 39 193 | -33.53 -1702 39 194 | -33.62 -1707 34 195 | -33.7 -1693 28 196 | -33.79 -1669 36 197 | -33.87 -1607 39 198 | -33.95 -1604 60 199 | -34.04 -1640 80 200 | -34.12 -1578 86 201 | -34.2 -1542 47 202 | -34.28 -1556 26 203 | -34.37 -1564 42 204 | -34.45 -1593 9 205 | -34.53 -1576 43 206 | -34.62 -1578 41 207 | -34.7 -1591 32 208 | -34.79 -1581 11 209 | -34.87 -1553 40 210 | -34.95 -1607 140 211 | -35.04 -1496 70 212 | -35.12 -1479 59 213 | -35.2 -1518 66 214 | -35.28 -1503 33 215 | -35.37 -1512 32 216 | -35.45 -1533 19 217 | -35.53 -1552 38 218 | -35.62 -1549 19 219 | -35.7 -1542 42 220 | -35.79 -1458 41 221 | -35.87 -1406 95 222 | -35.95 -1453 56 223 | -36.04 -1472 40 224 | -36.12 -1463 71 225 | -36.2 -1451 39 226 | -36.28 -1402 86 227 | -36.37 -1425 42 228 | -36.45 -1418 39 229 | -36.53 -1432 23 230 | -36.62 -1446 17 231 | -36.7 -1441 43 232 | -36.79 -1434 28 233 | -36.87 -1410 23 234 | -36.95 -1373 24 235 | -37.04 -1384 24 236 | -37.12 -1380 74 237 | -37.2 -1330 51 238 | -37.28 -1360 59 239 | -37.37 -1389 38 240 | -37.45 -1390 32 241 | -37.53 -1408 25 242 | -37.62 -1409 22 243 | -37.7 -1404 18 244 | -37.79 -1359 18 245 | -37.87 -1345 31 246 | -37.95 -1328 64 247 | -38.04 -1349 12 248 | -38.12 -1300 16 249 | -38.2 -1322 14 250 | -38.28 -1282 18 251 | -38.37 -1292 31 252 | -38.45 -1315 17 253 | -38.53 -1323 39 254 | -38.62 -1334 39 255 | -38.7 -1299 32 256 | -38.79 -1309 26 257 | -38.87 -1239 34 258 | -38.95 -1269 29 259 | -39.04 -1294 10 260 | -39.12 -1276 25 261 | -39.2 -1250 12 262 | -39.28 -1225 23 263 | -39.37 -1253 28 264 | -39.45 -1254 14 265 | -39.53 -1233 54 266 | -39.62 -1258 29 267 | -39.7 -1246 12 268 | -39.79 -1242 34 269 | -39.87 -1217 34 270 | -39.95 -1196 43 271 | -40.04 -1207 25 272 | -40.12 -1196 23 273 | -40.2 -1175 17 274 | -40.28 -1149 17 275 | -40.37 -1144 25 276 | -40.45 -1183 24 277 | -40.53 -1180 36 278 | -40.62 -1156 35 279 | -40.7 -1180 28 280 | -40.79 -1183 28 281 | -40.87 -1137 62 282 | -40.95 -1102 41 283 | -41.04 -1101 14 284 | -41.12 -1093 26 285 | -41.2 -1076 37 286 | -41.28 -1086 25 287 | -41.37 -1086 25 288 | -41.45 -1112 31 289 | -41.53 -1102 23 290 | -41.62 -1118 35 291 | -41.7 -1130 36 292 | -41.79 -1071 27 293 | -41.87 -1081 20 294 | -41.95 -1092 36 295 | -42.04 -1063 27 296 | -42.12 -1025 39 297 | -42.2 -1048 56 298 | -42.28 -1054 34 299 | -42.37 -1056 36 300 | -42.45 -1065 19 301 | -42.53 -1057 12 302 | -42.62 -1069 23 303 | -42.7 -1066 16 304 | -42.79 -1050 18 305 | -42.87 -1055 15 306 | -42.95 -1027 25 307 | -43.04 -1027 25 308 | -43.12 -1012 28 309 | -43.2 -992 36 310 | -43.28 -988 9 311 | -43.37 -1015 22 312 | -43.45 -1004 9 313 | -43.53 -994 38 314 | -43.62 -987 9 315 | -43.7 -996 11 316 | -43.79 -988 13 317 | -43.87 -960 56 318 | -43.95 -961 35 319 | -44.04 -957 35 320 | -44.12 -921 12 321 | -44.2 -955 9 322 | -44.28 -921 26 323 | -44.37 -945 27 324 | -44.45 -955 37 325 | -44.53 -963 30 326 | -44.62 -941 11 327 | -44.7 -961 14 328 | -44.79 -938 34 329 | -44.87 -953 14 330 | -44.95 -926 34 331 | -45.04 -938 21 332 | -45.12 -918 9 333 | -45.2 -915 14 334 | -45.28 -893 29 335 | -45.37 -915 9 336 | -45.45 -900 7 337 | -45.53 -916 13 338 | -45.62 -899 39 339 | -45.7 -910 57 340 | -45.79 -904 39 341 | -45.87 -890 24 342 | -45.95 -887 35 343 | -46.04 -867 22 344 | -46.12 -843 40 345 | -46.2 -851 42 346 | -46.28 -834 12 347 | -46.37 -849 28 348 | -46.45 -860 25 349 | -46.53 -866 14 350 | -46.62 -849 25 351 | -46.7 -850 9 352 | -46.79 -854 17 353 | -46.87 -856 11 354 | -46.95 -836 10 355 | -47.04 -819 9 356 | -47.12 -825 21 357 | -47.2 -850 13 358 | -47.28 -798 31 359 | -47.37 -830 10 360 | -47.45 -819 14 361 | -47.53 -813 14 362 | -47.62 -827 12 363 | -47.7 -819 14 364 | -47.79 -817 20 365 | -47.87 -793 11 366 | -47.95 -811 20 367 | -48.04 -816 10 368 | -48.12 -798 7 369 | -48.2 -781 12 370 | -48.28 -775 13 371 | -48.37 -775 27 372 | -48.45 -798 14 373 | -48.53 -792 31 374 | -48.62 -812 17 375 | -48.7 -800 28 376 | -48.79 -788 12 377 | -48.87 -774 21 378 | -48.95 -796 15 379 | -49.04 -756 23 380 | -49.12 -782 36 381 | -49.2 -758 36 382 | -49.28 -754 27 383 | -49.37 -746 34 384 | -49.45 -758 19 385 | -49.53 -777 21 386 | -49.62 -758 18 387 | -49.7 -774 15 388 | -49.79 -788 19 389 | -49.87 -765 28 390 | -49.95 -742 18 391 | -50.04 -745 26 392 | -50.12 -729 17 393 | -50.2 -714 16 394 | -50.28 -702 8 395 | -50.37 -711 17 396 | -50.45 -713 28 397 | -50.53 -722 21 398 | -50.62 -722 31 399 | -50.7 -714 15 400 | -50.79 -713 7 401 | -50.87 -706 12 402 | -50.95 -706 12 403 | -51.04 -692 19 404 | -51.12 -660 26 405 | -51.2 -659 17 406 | -51.28 -637 13 407 | -51.37 -651 30 408 | -51.45 -661 18 409 | -51.53 -692 14 410 | -51.62 -683 18 411 | -51.7 -686 10 412 | -51.79 -678 28 413 | -51.87 -676 15 414 | -51.95 -654 18 415 | -52.04 -645 23 416 | -52.12 -639 18 417 | -52.2 -625 27 418 | -52.28 -620 33 419 | -52.37 -614 24 420 | -52.45 -635 19 421 | -52.53 -644 11 422 | -52.62 -632 24 423 | -52.7 -638 23 424 | -52.79 -624 22 425 | -52.87 -623 30 426 | -52.95 -598 22 427 | -53.04 -603 34 428 | -53.12 -573 31 429 | -53.2 -582 28 430 | -53.28 -579 16 431 | -53.37 -582 38 432 | -53.45 -595 11 433 | -53.53 -604 27 434 | -53.62 -584 22 435 | -53.7 -600 17 436 | -53.79 -599 19 437 | -53.87 -571 13 438 | -53.95 -575 13 439 | -54.04 -575 36 440 | -54.12 -566 21 441 | -54.2 -569 31 442 | -54.28 -563 19 443 | -54.37 -554 19 444 | -54.45 -556 10 445 | -54.53 -555 22 446 | -54.62 -573 10 447 | -54.7 -566 13 448 | -54.79 -550 15 449 | -54.87 -548 25 450 | -54.95 -550 19 451 | -55.04 -533 20 452 | -55.12 -537 10 453 | -55.2 -522 16 454 | -55.28 -500 26 455 | -55.37 -504 27 456 | -55.45 -482 20 457 | -55.53 -522 20 458 | -55.62 -525 14 459 | -55.7 -529 21 460 | -55.79 -525 14 461 | -55.87 -510 18 462 | -55.95 -498 29 463 | -56.04 -491 11 464 | -56.12 -490 33 465 | -56.2 -476 22 466 | -56.28 -485 38 467 | -56.37 -495 29 468 | -56.45 -507 23 469 | -56.53 -497 7 470 | -56.62 -498 21 471 | -56.7 -504 14 472 | -56.79 -505 12 473 | -56.87 -507 17 474 | -56.95 -476 11 475 | -57.04 -452 16 476 | -57.12 -485 30 477 | -57.2 -461 32 478 | -57.28 -454 17 479 | -57.37 -458 14 480 | -57.45 -446 35 481 | -57.53 -480 13 482 | -57.62 -466 10 483 | -57.7 -463 15 484 | -57.79 -457 14 485 | -57.87 -445 12 486 | -57.95 -421 43 487 | -58.37 -389 38 488 | -58.45 -414 27 489 | -58.53 -463 27 490 | -58.62 -460 27 491 | -59.37 -382 28 492 | -59.45 -366 29 493 | -59.53 -453 49 494 | -59.62 -445 30 495 | -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/bacon/Curves/postbomb_NH2.14C: -------------------------------------------------------------------------------- 1 | -0.5 180 11 2 | -1.5 187 12 3 | -2.5 159 12 4 | -3.5 162 31 5 | -4.5 140 12 6 | -5.5 -40 34 7 | -6.5 -312 35 8 | -7.5 -550 48 9 | -8.5 -1085 200 10 | -9.5 -1693 32 11 | -10.5 -1634 64 12 | -11.5 -1604 20 13 | -12.5 -2376 100 14 | -13.2 -3293 37 15 | -13.28 -3531 98 16 | -13.37 -4124 121 17 | -13.45 -4439 148 18 | -13.53 -5093 209 19 | -13.62 -5318 318 20 | -13.7 -5136 352 21 | -13.79 -4583 320 22 | -13.87 -4627 386 23 | -13.95 -4852 90 24 | -14.04 -4611 107 25 | -14.12 -4427 38 26 | -14.2 -4366 108 27 | -14.28 -4646 174 28 | -14.37 -4612 72 29 | -14.45 -4969 55 30 | -14.53 -4954 118 31 | -14.62 -5050 100 32 | -14.7 -4794 238 33 | -14.79 -4756 62 34 | -14.87 -4597 159 35 | -14.95 -4616 34 36 | -15.04 -4566 58 37 | -15.12 -4527 35 38 | -15.2 -4459 117 39 | -15.28 -4489 111 40 | -15.37 -4509 134 41 | -15.45 -4523 127 42 | -15.53 -4537 138 43 | -15.62 -4421 57 44 | -15.7 -4236 192 45 | -15.79 -4377 116 46 | -15.87 -4400 184 47 | -15.95 -4171 141 48 | -16.04 -4116 43 49 | -16.12 -4093 77 50 | -16.2 -4153 83 51 | -16.28 -4176 120 52 | -16.37 -4116 132 53 | -16.45 -4131 130 54 | -16.53 -4248 120 55 | -16.62 -4185 71 56 | -16.7 -4064 65 57 | -16.79 -4031 84 58 | -16.87 -4017 69 59 | -16.95 -4061 89 60 | -17.04 -3790 213 61 | -17.12 -3994 59 62 | -17.2 -3926 41 63 | -17.28 -4041 36 64 | -17.37 -3877 162 65 | -17.45 -3879 115 66 | -17.53 -3787 50 67 | -17.62 -3976 59 68 | -17.7 -3762 65 69 | -17.79 -3762 55 70 | -17.87 -3840 68 71 | -17.95 -3791 34 72 | -18.04 -3689 100 73 | -18.12 -3747 50 74 | -18.2 -3686 66 75 | -18.28 -3573 51 76 | -18.37 -3661 56 77 | -18.45 -3470 47 78 | -18.53 -3605 61 79 | -18.62 -3793 60 80 | -18.79 -3595 56 81 | -18.87 -3512 62 82 | -18.95 -3327 127 83 | -19.04 -3565 56 84 | -19.12 -3605 71 85 | -19.2 -3642 41 86 | -19.28 -3506 57 87 | -19.37 -3666 51 88 | -19.45 -3532 52 89 | -19.53 -3538 46 90 | -19.62 -3523 46 91 | -19.7 -3339 58 92 | -19.79 -3569 51 93 | -19.87 -3543 52 94 | -19.95 -3517 36 95 | -20.12 -3118 60 96 | -20.2 -3323 58 97 | -20.28 -3491 67 98 | -20.37 -3569 82 99 | -20.45 -3376 58 100 | -20.53 -3397 63 101 | -20.62 -3200 48 102 | -20.79 -3440 47 103 | -20.87 -3291 48 104 | -21.04 -3248 64 105 | -21.12 -3183 86 106 | -21.28 -3158 65 107 | -21.37 -3305 74 108 | -21.45 -3313 48 109 | -21.53 -3047 60 110 | -21.62 -3243 48 111 | -21.7 -3318 64 112 | -21.87 -3222 80 113 | -21.95 -3265 80 114 | -22.04 -3333 101 115 | -22.12 -3253 48 116 | -22.2 -3221 80 117 | -22.28 -3118 87 118 | -22.37 -3167 49 119 | -22.45 -3200 48 120 | -22.53 -3080 49 121 | -22.62 -3107 49 122 | -22.7 -3118 49 123 | -22.79 -3168 65 124 | -22.87 -3151 54 125 | -22.95 -3113 49 126 | -23.04 -2924 90 127 | -23.12 -2950 39 128 | -23.2 -2919 81 129 | -23.28 -2918 74 130 | -23.37 -2851 145 131 | -23.45 -2994 45 132 | -23.53 -2895 117 133 | -23.62 -3014 151 134 | -23.7 -2990 131 135 | -23.79 -2941 19 136 | -23.87 -2945 31 137 | -23.95 -2725 27 138 | -24.04 -2852 62 139 | -24.12 -2784 79 140 | -24.2 -2830 51 141 | -24.28 -2816 51 142 | -24.37 -2832 39 143 | -24.45 -2850 39 144 | -24.53 -2813 51 145 | -24.62 -2875 50 146 | -24.7 -2732 108 147 | -24.79 -2775 84 148 | -24.87 -2706 149 149 | -24.95 -2570 120 150 | -25.04 -2580 125 151 | -25.12 -2590 118 152 | -25.2 -2519 96 153 | -25.28 -2593 87 154 | -25.37 -2597 109 155 | -25.45 -2692 46 156 | -25.53 -2745 68 157 | -25.62 -2624 86 158 | -25.7 -2687 63 159 | -25.79 -2682 80 160 | -25.87 -2549 27 161 | -25.95 -2570 28 162 | -26.04 -2492 38 163 | -26.12 -2488 37 164 | -26.2 -2377 138 165 | -26.28 -2387 43 166 | -26.37 -2401 15 167 | -26.45 -2445 75 168 | -26.53 -2479 30 169 | -26.62 -2415 50 170 | -26.7 -2430 31 171 | -26.79 -2346 60 172 | -26.87 -2416 26 173 | -26.95 -2314 92 174 | -27.04 -2329 53 175 | -27.12 -2313 61 176 | -27.2 -2342 37 177 | -27.28 -2320 26 178 | -27.37 -2328 48 179 | -27.45 -2346 53 180 | -27.53 -2377 66 181 | -27.62 -2338 26 182 | -27.7 -2334 55 183 | -27.79 -2309 43 184 | -27.87 -2278 46 185 | -27.95 -2209 15 186 | -28.04 -2230 49 187 | -28.12 -2267 36 188 | -28.2 -2263 30 189 | -28.28 -2273 18 190 | -28.37 -2271 29 191 | -28.45 -2334 29 192 | -28.53 -2295 61 193 | -28.62 -2275 108 194 | -28.7 -2238 85 195 | -28.79 -2222 78 196 | -28.87 -2238 56 197 | -28.95 -2221 29 198 | -29.04 -2163 16 199 | -29.12 -2130 37 200 | -29.2 -2104 46 201 | -29.28 -2103 55 202 | -29.37 -2092 72 203 | -29.45 -2074 54 204 | -29.53 -2055 66 205 | -29.62 -2131 27 206 | -29.7 -2070 60 207 | -29.79 -2062 45 208 | -29.87 -2049 51 209 | -29.95 -1959 65 210 | -30.04 -1952 35 211 | -30.12 -1926 61 212 | -30.2 -1872 79 213 | -30.28 -1916 62 214 | -30.37 -1911 58 215 | -30.45 -1950 42 216 | -30.53 -1990 32 217 | -30.62 -1938 29 218 | -30.7 -1943 78 219 | -30.79 -1918 65 220 | -30.87 -1872 35 221 | -30.95 -1843 48 222 | -31.04 -1827 52 223 | -31.12 -1897 52 224 | -31.2 -1813 33 225 | -31.28 -1810 31 226 | -31.37 -1843 49 227 | -31.45 -1905 47 228 | -31.53 -1881 68 229 | -31.62 -1855 52 230 | -31.7 -1850 43 231 | -31.79 -1913 25 232 | -31.87 -1785 26 233 | -31.95 -1854 81 234 | -32.04 -1802 12 235 | -32.12 -1775 17 236 | -32.2 -1749 39 237 | -32.28 -1749 52 238 | -32.37 -1776 42 239 | -32.45 -1755 42 240 | -32.53 -1735 59 241 | -32.62 -1764 30 242 | -32.7 -1749 17 243 | -32.79 -1749 41 244 | -32.87 -1709 51 245 | -32.95 -1705 32 246 | -33.04 -1671 63 247 | -33.12 -1660 20 248 | -33.2 -1707 19 249 | -33.28 -1673 34 250 | -33.37 -1657 47 251 | -33.45 -1714 39 252 | -33.53 -1702 39 253 | -33.62 -1707 34 254 | -33.7 -1693 28 255 | -33.79 -1669 36 256 | -33.87 -1607 39 257 | -33.95 -1604 60 258 | -34.04 -1640 80 259 | -34.12 -1578 86 260 | -34.2 -1542 47 261 | -34.28 -1556 26 262 | -34.37 -1564 42 263 | -34.45 -1593 9 264 | -34.53 -1576 43 265 | -34.62 -1578 41 266 | -34.7 -1591 32 267 | -34.79 -1581 11 268 | -34.87 -1553 40 269 | -34.95 -1607 140 270 | -35.04 -1496 70 271 | -35.12 -1479 59 272 | -35.2 -1518 66 273 | -35.28 -1503 33 274 | -35.37 -1512 32 275 | -35.45 -1533 19 276 | -35.53 -1552 38 277 | -35.62 -1549 19 278 | -35.7 -1542 42 279 | -35.79 -1458 41 280 | -35.87 -1406 95 281 | -35.95 -1453 56 282 | -36.04 -1472 40 283 | -36.12 -1463 71 284 | -36.2 -1451 39 285 | -36.28 -1402 86 286 | -36.37 -1425 42 287 | -36.45 -1418 39 288 | -36.53 -1432 23 289 | -36.62 -1446 17 290 | -36.7 -1441 43 291 | -36.79 -1434 28 292 | -36.87 -1410 23 293 | -36.95 -1373 24 294 | -37.04 -1384 24 295 | -37.12 -1380 74 296 | -37.2 -1330 51 297 | -37.28 -1360 59 298 | -37.37 -1389 38 299 | -37.45 -1390 32 300 | -37.53 -1408 25 301 | -37.62 -1409 22 302 | -37.7 -1404 18 303 | -37.79 -1359 18 304 | -37.87 -1345 31 305 | -37.95 -1328 64 306 | -38.04 -1349 12 307 | -38.12 -1300 16 308 | -38.2 -1322 14 309 | -38.28 -1282 18 310 | -38.37 -1292 31 311 | -38.45 -1315 17 312 | -38.53 -1323 39 313 | -38.62 -1334 39 314 | -38.7 -1299 32 315 | -38.79 -1309 26 316 | -38.87 -1239 34 317 | -38.95 -1269 29 318 | -39.04 -1294 10 319 | -39.12 -1276 25 320 | -39.2 -1250 12 321 | -39.28 -1225 23 322 | -39.37 -1253 28 323 | -39.45 -1254 14 324 | -39.53 -1233 54 325 | -39.62 -1258 29 326 | -39.7 -1246 12 327 | -39.79 -1242 34 328 | -39.87 -1217 34 329 | -39.95 -1196 43 330 | -40.04 -1207 25 331 | -40.12 -1196 23 332 | -40.2 -1175 17 333 | -40.28 -1149 17 334 | -40.37 -1144 25 335 | -40.45 -1183 24 336 | -40.53 -1180 36 337 | -40.62 -1156 35 338 | -40.7 -1180 28 339 | -40.79 -1183 28 340 | -40.87 -1137 62 341 | -40.95 -1102 41 342 | -41.04 -1101 14 343 | -41.12 -1093 26 344 | -41.2 -1076 37 345 | -41.28 -1086 25 346 | -41.37 -1086 25 347 | -41.45 -1112 31 348 | -41.53 -1102 23 349 | -41.62 -1118 35 350 | -41.7 -1130 36 351 | -41.79 -1071 27 352 | -41.87 -1081 20 353 | -41.95 -1092 36 354 | -42.04 -1063 27 355 | -42.12 -1025 39 356 | -42.2 -1048 56 357 | -42.28 -1054 34 358 | -42.37 -1056 36 359 | -42.45 -1065 19 360 | -42.53 -1057 12 361 | -42.62 -1069 23 362 | -42.7 -1066 16 363 | -42.79 -1050 18 364 | -42.87 -1055 15 365 | -42.95 -1027 25 366 | -43.04 -1027 25 367 | -43.12 -1012 28 368 | -43.2 -992 36 369 | -43.28 -988 9 370 | -43.37 -1015 22 371 | -43.45 -1004 9 372 | -43.53 -994 38 373 | -43.62 -987 9 374 | -43.7 -996 11 375 | -43.79 -988 13 376 | -43.87 -960 56 377 | -43.95 -961 35 378 | -44.04 -957 35 379 | -44.12 -921 12 380 | -44.2 -955 9 381 | -44.28 -921 26 382 | -44.37 -945 27 383 | -44.45 -955 37 384 | -44.53 -963 30 385 | -44.62 -941 11 386 | -44.7 -961 14 387 | -44.79 -938 34 388 | -44.87 -953 14 389 | -44.95 -926 34 390 | -45.04 -938 21 391 | -45.12 -918 9 392 | -45.2 -915 14 393 | -45.28 -893 29 394 | -45.37 -915 9 395 | -45.45 -900 7 396 | -45.53 -916 13 397 | -45.62 -899 39 398 | -45.7 -910 57 399 | -45.79 -904 39 400 | -45.87 -890 24 401 | -45.95 -887 35 402 | -46.04 -867 22 403 | -46.12 -843 40 404 | -46.2 -851 42 405 | -46.28 -834 12 406 | -46.37 -849 28 407 | -46.45 -860 25 408 | -46.53 -866 14 409 | -46.62 -849 25 410 | -46.7 -850 9 411 | -46.79 -854 17 412 | -46.87 -856 11 413 | -46.95 -836 10 414 | -47.04 -819 9 415 | -47.12 -825 21 416 | -47.2 -850 13 417 | -47.28 -798 31 418 | -47.37 -830 10 419 | -47.45 -819 14 420 | -47.53 -813 14 421 | -47.62 -827 12 422 | -47.7 -819 14 423 | -47.79 -817 20 424 | -47.87 -793 11 425 | -47.95 -811 20 426 | -48.04 -816 10 427 | -48.12 -798 7 428 | -48.2 -781 12 429 | -48.28 -775 13 430 | -48.37 -775 27 431 | -48.45 -798 14 432 | -48.53 -792 31 433 | -48.62 -812 17 434 | -48.7 -800 28 435 | -48.79 -788 12 436 | -48.87 -774 21 437 | -48.95 -796 15 438 | -49.04 -756 23 439 | -49.12 -782 36 440 | -49.2 -758 36 441 | -49.28 -754 27 442 | -49.37 -746 34 443 | -49.45 -758 19 444 | -49.53 -777 21 445 | -49.62 -758 18 446 | -49.7 -774 15 447 | -49.79 -788 19 448 | -49.87 -765 28 449 | -49.95 -742 18 450 | -50.04 -745 26 451 | -50.12 -729 17 452 | -50.2 -714 16 453 | -50.28 -702 8 454 | -50.37 -711 17 455 | -50.45 -713 28 456 | -50.53 -722 21 457 | -50.62 -722 31 458 | -50.7 -714 15 459 | -50.79 -713 7 460 | -50.87 -706 12 461 | -50.95 -706 12 462 | -51.04 -692 19 463 | -51.12 -660 26 464 | -51.2 -659 17 465 | -51.28 -637 13 466 | -51.37 -651 30 467 | -51.45 -661 18 468 | -51.53 -692 14 469 | -51.62 -683 18 470 | -51.7 -686 10 471 | -51.79 -678 28 472 | -51.87 -676 15 473 | -51.95 -654 18 474 | -52.04 -645 23 475 | -52.12 -639 18 476 | -52.2 -625 27 477 | -52.28 -620 33 478 | -52.37 -614 24 479 | -52.45 -635 19 480 | -52.53 -644 11 481 | -52.62 -632 24 482 | -52.7 -638 23 483 | -52.79 -624 22 484 | -52.87 -623 30 485 | -52.95 -598 22 486 | -53.04 -603 34 487 | -53.12 -573 31 488 | -53.2 -582 28 489 | -53.28 -579 16 490 | -53.37 -582 38 491 | -53.45 -595 11 492 | -53.53 -604 27 493 | -53.62 -584 22 494 | -53.7 -600 17 495 | -53.79 -599 19 496 | -53.87 -571 13 497 | -53.95 -575 13 498 | -54.04 -575 36 499 | -54.12 -566 21 500 | -54.2 -569 31 501 | -54.28 -563 19 502 | -54.37 -554 19 503 | -54.45 -556 10 504 | -54.53 -555 22 505 | -54.62 -573 10 506 | -54.7 -566 13 507 | -54.79 -550 15 508 | -54.87 -548 25 509 | -54.95 -550 19 510 | -55.04 -533 20 511 | -55.12 -537 10 512 | -55.2 -522 16 513 | -55.28 -500 26 514 | -55.37 -504 27 515 | -55.45 -482 20 516 | -55.53 -522 20 517 | -55.62 -525 14 518 | -55.7 -529 21 519 | -55.79 -525 14 520 | -55.87 -510 18 521 | -55.95 -498 29 522 | -56.04 -491 11 523 | -56.12 -490 33 524 | -56.2 -476 22 525 | -56.28 -485 38 526 | -56.37 -495 29 527 | -56.45 -507 23 528 | -56.53 -497 7 529 | -56.62 -498 21 530 | -56.7 -504 14 531 | -56.79 -505 12 532 | -56.87 -507 17 533 | -56.95 -476 11 534 | -57.04 -452 16 535 | -57.12 -485 30 536 | -57.2 -461 32 537 | -57.28 -454 17 538 | -57.37 -458 14 539 | -57.45 -446 35 540 | -57.53 -480 13 541 | -57.62 -466 10 542 | -57.7 -463 15 543 | -57.79 -457 14 544 | -57.87 -445 12 545 | -57.95 -421 43 546 | -58.37 -389 38 547 | -58.45 -414 27 548 | -58.53 -463 27 549 | -58.62 -460 27 550 | -59.37 -382 28 551 | -59.45 -366 29 552 | -59.53 -453 49 553 | -59.62 -445 30 554 | -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/bacon/Curves/postbomb_NH1.14C: -------------------------------------------------------------------------------- 1 | -0.5 209 14 2 | -1.5 206 14 3 | -2.5 207 13 4 | -3.5 193 15 5 | -4.5 181 21 6 | -5.5 -142 42 7 | -6.5 -200 59 8 | -7.5 -761 266 9 | -8.5 -1257 64 10 | -9.12 -1342 51 11 | -9.2 -1446 33 12 | -9.28 -1659 46 13 | -9.37 -1685 58 14 | -9.45 -1967 44 15 | -9.53 -1789 45 16 | -9.62 -1930 63 17 | -9.7 -1802 38 18 | -9.79 -1705 41 19 | -9.87 -1653 26 20 | -9.95 -1581 46 21 | -10.04 -1461 47 22 | -10.12 -1501 33 23 | -10.2 -1504 35 24 | -10.28 -1488 47 25 | -10.37 -1601 39 26 | -10.45 -1699 32 27 | -10.53 -1680 39 28 | -10.62 -1614 46 29 | -10.7 -1575 53 30 | -10.79 -1535 46 31 | -10.87 -1509 46 32 | -10.95 -1535 46 33 | -11.04 -1489 47 34 | -11.12 -1509 60 35 | -11.2 -1609 52 36 | -11.28 -1556 46 37 | -11.37 -1576 53 38 | -11.45 -1784 51 39 | -11.53 -1654 46 40 | -11.62 -1739 39 41 | -11.7 -1509 46 42 | -11.79 -1589 39 43 | -11.95 -1727 39 44 | -12.04 -1881 44 45 | -12.12 -2032 31 46 | -12.2 -2144 37 47 | -12.37 -2517 35 48 | -12.53 -2675 34 49 | -12.62 -2807 34 50 | -12.7 -2675 46 51 | -12.79 -2611 35 52 | -12.87 -2761 34 53 | -12.95 -2843 56 54 | -13.04 -2805 44 55 | -13.12 -3058 93 56 | -13.2 -3194 52 57 | -13.28 -3575 70 58 | -13.37 -4023 18 59 | -13.45 -4563 182 60 | -13.53 -5086 54 61 | -13.62 -5502 87 62 | -13.7 -5477 166 63 | -13.79 -4960 230 64 | -13.87 -4829 191 65 | -13.95 -4794 222 66 | -14.04 -4753 84 67 | -14.12 -4725 117 68 | -14.2 -4730 105 69 | -14.28 -4890 36 70 | -14.37 -5135 65 71 | -14.45 -5239 19 72 | -14.53 -5221 205 73 | -14.62 -5159 90 74 | -14.7 -5004 146 75 | -14.79 -4894 25 76 | -14.87 -4681 106 77 | -14.95 -4622 79 78 | -15.04 -4627 62 79 | -15.12 -4476 25 80 | -15.2 -4522 54 81 | -15.28 -4554 38 82 | -15.37 -4554 62 83 | -15.45 -4714 82 84 | -15.53 -4733 77 85 | -15.62 -4663 140 86 | -15.7 -4545 37 87 | -15.79 -4492 119 88 | -15.87 -4395 34 89 | -15.95 -4292 35 90 | -16.04 -4266 24 91 | -16.12 -4229 29 92 | -16.2 -4224 43 93 | -16.28 -4232 93 94 | -16.37 -4270 70 95 | -16.45 -4361 40 96 | -16.53 -4360 37 97 | -16.62 -4331 31 98 | -16.7 -4304 73 99 | -16.79 -4140 111 100 | -16.87 -4025 115 101 | -16.95 -4084 19 102 | -17.04 -4019 96 103 | -17.12 -4039 108 104 | -17.2 -4000 61 105 | -17.28 -4001 58 106 | -17.37 -4021 23 107 | -17.45 -4053 63 108 | -17.53 -4023 105 109 | -17.62 -3970 82 110 | -17.7 -3889 129 111 | -17.79 -3916 65 112 | -17.87 -3830 28 113 | -17.95 -3746 38 114 | -18.04 -3756 36 115 | -18.12 -3674 38 116 | -18.2 -3659 33 117 | -18.28 -3710 80 118 | -18.37 -3687 133 119 | -18.45 -3667 26 120 | -18.53 -3742 89 121 | -18.62 -3711 228 122 | -18.7 -3657 120 123 | -18.79 -3586 119 124 | -18.87 -3527 63 125 | -18.95 -3566 53 126 | -19.04 -3658 148 127 | -19.12 -3487 101 128 | -19.2 -3487 36 129 | -19.28 -3557 179 130 | -19.37 -3579 27 131 | -19.45 -3581 27 132 | -19.53 -3567 89 133 | -19.62 -3542 165 134 | -19.7 -3485 65 135 | -19.79 -3621 128 136 | -19.87 -3551 33 137 | -19.95 -3463 42 138 | -20.04 -3519 32 139 | -20.12 -3521 58 140 | -20.2 -3391 29 141 | -20.28 -3424 29 142 | -20.37 -3438 108 143 | -20.45 -3513 53 144 | -20.53 -3486 31 145 | -20.62 -3540 196 146 | -20.7 -3479 90 147 | -20.79 -3465 116 148 | -20.87 -3347 34 149 | -20.95 -3369 43 150 | -21.04 -3282 89 151 | -21.12 -3216 32 152 | -21.2 -3144 33 153 | -21.28 -3313 41 154 | -21.37 -3436 123 155 | -21.45 -3431 157 156 | -21.53 -3310 179 157 | -21.62 -3413 57 158 | -21.7 -3261 113 159 | -21.79 -3354 125 160 | -21.87 -3156 58 161 | -21.95 -3246 74 162 | -22.04 -3305 60 163 | -22.12 -3130 26 164 | -22.2 -3174 30 165 | -22.28 -3173 107 166 | -22.37 -3146 33 167 | -22.45 -3171 21 168 | -22.53 -3147 35 169 | -22.62 -3046 63 170 | -22.7 -3124 65 171 | -22.79 -3061 21 172 | -22.87 -3146 49 173 | -22.95 -3092 65 174 | -23.04 -2924 90 175 | -23.12 -2950 39 176 | -23.2 -2919 81 177 | -23.28 -2918 74 178 | -23.37 -2851 145 179 | -23.45 -2994 45 180 | -23.53 -2895 117 181 | -23.62 -3014 151 182 | -23.7 -2990 131 183 | -23.79 -2941 19 184 | -23.87 -2945 31 185 | -23.95 -2725 27 186 | -24.04 -2852 62 187 | -24.12 -2784 79 188 | -24.2 -2830 51 189 | -24.28 -2816 51 190 | -24.37 -2832 39 191 | -24.45 -2850 39 192 | -24.53 -2813 51 193 | -24.62 -2875 50 194 | -24.7 -2732 108 195 | -24.79 -2775 84 196 | -24.87 -2706 149 197 | -24.95 -2570 120 198 | -25.04 -2580 125 199 | -25.12 -2590 118 200 | -25.2 -2519 96 201 | -25.28 -2593 87 202 | -25.37 -2597 109 203 | -25.45 -2692 46 204 | -25.53 -2745 68 205 | -25.62 -2624 86 206 | -25.7 -2687 63 207 | -25.79 -2682 80 208 | -25.87 -2549 27 209 | -25.95 -2570 28 210 | -26.04 -2492 38 211 | -26.12 -2488 37 212 | -26.2 -2377 138 213 | -26.28 -2387 43 214 | -26.37 -2401 15 215 | -26.45 -2445 75 216 | -26.53 -2479 30 217 | -26.62 -2415 50 218 | -26.7 -2430 31 219 | -26.79 -2346 60 220 | -26.87 -2416 26 221 | -26.95 -2314 92 222 | -27.04 -2329 53 223 | -27.12 -2313 61 224 | -27.2 -2342 37 225 | -27.28 -2320 26 226 | -27.37 -2328 48 227 | -27.45 -2346 53 228 | -27.53 -2377 66 229 | -27.62 -2338 26 230 | -27.7 -2334 55 231 | -27.79 -2309 43 232 | -27.87 -2278 46 233 | -27.95 -2209 15 234 | -28.04 -2230 49 235 | -28.12 -2267 36 236 | -28.2 -2263 30 237 | -28.28 -2273 18 238 | -28.37 -2271 29 239 | -28.45 -2334 29 240 | -28.53 -2295 61 241 | -28.62 -2275 108 242 | -28.7 -2238 85 243 | -28.79 -2222 78 244 | -28.87 -2238 56 245 | -28.95 -2221 29 246 | -29.04 -2163 16 247 | -29.12 -2130 37 248 | -29.2 -2104 46 249 | -29.28 -2103 55 250 | -29.37 -2092 72 251 | -29.45 -2074 54 252 | -29.53 -2055 66 253 | -29.62 -2131 27 254 | -29.7 -2070 60 255 | -29.79 -2062 45 256 | -29.87 -2049 51 257 | -29.95 -1959 65 258 | -30.04 -1952 35 259 | -30.12 -1926 61 260 | -30.2 -1872 79 261 | -30.28 -1916 62 262 | -30.37 -1911 58 263 | -30.45 -1950 42 264 | -30.53 -1990 32 265 | -30.62 -1938 29 266 | -30.7 -1943 78 267 | -30.79 -1918 65 268 | -30.87 -1872 35 269 | -30.95 -1843 48 270 | -31.04 -1827 52 271 | -31.12 -1897 52 272 | -31.2 -1813 33 273 | -31.28 -1810 31 274 | -31.37 -1843 49 275 | -31.45 -1905 47 276 | -31.53 -1881 68 277 | -31.62 -1855 52 278 | -31.7 -1850 43 279 | -31.79 -1913 25 280 | -31.87 -1785 26 281 | -31.95 -1854 81 282 | -32.04 -1802 12 283 | -32.12 -1775 17 284 | -32.2 -1749 39 285 | -32.28 -1749 52 286 | -32.37 -1776 42 287 | -32.45 -1755 42 288 | -32.53 -1735 59 289 | -32.62 -1764 30 290 | -32.7 -1749 17 291 | -32.79 -1749 41 292 | -32.87 -1709 51 293 | -32.95 -1705 32 294 | -33.04 -1671 63 295 | -33.12 -1660 20 296 | -33.2 -1707 19 297 | -33.28 -1673 34 298 | -33.37 -1657 47 299 | -33.45 -1714 39 300 | -33.53 -1702 39 301 | -33.62 -1707 34 302 | -33.7 -1693 28 303 | -33.79 -1669 36 304 | -33.87 -1607 39 305 | -33.95 -1604 60 306 | -34.04 -1640 80 307 | -34.12 -1578 86 308 | -34.2 -1542 47 309 | -34.28 -1556 26 310 | -34.37 -1564 42 311 | -34.45 -1593 9 312 | -34.53 -1576 43 313 | -34.62 -1578 41 314 | -34.7 -1591 32 315 | -34.79 -1581 11 316 | -34.87 -1553 40 317 | -34.95 -1607 140 318 | -35.04 -1496 70 319 | -35.12 -1479 59 320 | -35.2 -1518 66 321 | -35.28 -1503 33 322 | -35.37 -1512 32 323 | -35.45 -1533 19 324 | -35.53 -1552 38 325 | -35.62 -1549 19 326 | -35.7 -1542 42 327 | -35.79 -1458 41 328 | -35.87 -1406 95 329 | -35.95 -1453 56 330 | -36.04 -1472 40 331 | -36.12 -1463 71 332 | -36.2 -1451 39 333 | -36.28 -1402 86 334 | -36.37 -1425 42 335 | -36.45 -1418 39 336 | -36.53 -1432 23 337 | -36.62 -1446 17 338 | -36.7 -1441 43 339 | -36.79 -1434 28 340 | -36.87 -1410 23 341 | -36.95 -1373 24 342 | -37.04 -1384 24 343 | -37.12 -1380 74 344 | -37.2 -1330 51 345 | -37.28 -1360 59 346 | -37.37 -1389 38 347 | -37.45 -1390 32 348 | -37.53 -1408 25 349 | -37.62 -1409 22 350 | -37.7 -1404 18 351 | -37.79 -1359 18 352 | -37.87 -1345 31 353 | -37.95 -1328 64 354 | -38.04 -1349 12 355 | -38.12 -1300 16 356 | -38.2 -1322 14 357 | -38.28 -1282 18 358 | -38.37 -1292 31 359 | -38.45 -1315 17 360 | -38.53 -1323 39 361 | -38.62 -1334 39 362 | -38.7 -1299 32 363 | -38.79 -1309 26 364 | -38.87 -1239 34 365 | -38.95 -1269 29 366 | -39.04 -1294 10 367 | -39.12 -1276 25 368 | -39.2 -1250 12 369 | -39.28 -1225 23 370 | -39.37 -1253 28 371 | -39.45 -1254 14 372 | -39.53 -1233 54 373 | -39.62 -1258 29 374 | -39.7 -1246 12 375 | -39.79 -1242 34 376 | -39.87 -1217 34 377 | -39.95 -1196 43 378 | -40.04 -1207 25 379 | -40.12 -1196 23 380 | -40.2 -1175 17 381 | -40.28 -1149 17 382 | -40.37 -1144 25 383 | -40.45 -1183 24 384 | -40.53 -1180 36 385 | -40.62 -1156 35 386 | -40.7 -1180 28 387 | -40.79 -1183 28 388 | -40.87 -1137 62 389 | -40.95 -1102 41 390 | -41.04 -1101 14 391 | -41.12 -1093 26 392 | -41.2 -1076 37 393 | -41.28 -1086 25 394 | -41.37 -1086 25 395 | -41.45 -1112 31 396 | -41.53 -1102 23 397 | -41.62 -1118 35 398 | -41.7 -1130 36 399 | -41.79 -1071 27 400 | -41.87 -1081 20 401 | -41.95 -1092 36 402 | -42.04 -1063 27 403 | -42.12 -1025 39 404 | -42.2 -1048 56 405 | -42.28 -1054 34 406 | -42.37 -1056 36 407 | -42.45 -1065 19 408 | -42.53 -1057 12 409 | -42.62 -1069 23 410 | -42.7 -1066 16 411 | -42.79 -1050 18 412 | -42.87 -1055 15 413 | -42.95 -1027 25 414 | -43.04 -1027 25 415 | -43.12 -1012 28 416 | -43.2 -992 36 417 | -43.28 -988 9 418 | -43.37 -1015 22 419 | -43.45 -1004 9 420 | -43.53 -994 38 421 | -43.62 -987 9 422 | -43.7 -996 11 423 | -43.79 -988 13 424 | -43.87 -960 56 425 | -43.95 -961 35 426 | -44.04 -957 35 427 | -44.12 -921 12 428 | -44.2 -955 9 429 | -44.28 -921 26 430 | -44.37 -945 27 431 | -44.45 -955 37 432 | -44.53 -963 30 433 | -44.62 -941 11 434 | -44.7 -961 14 435 | -44.79 -938 34 436 | -44.87 -953 14 437 | -44.95 -926 34 438 | -45.04 -938 21 439 | -45.12 -918 9 440 | -45.2 -915 14 441 | -45.28 -893 29 442 | -45.37 -915 9 443 | -45.45 -900 7 444 | -45.53 -916 13 445 | -45.62 -899 39 446 | -45.7 -910 57 447 | -45.79 -904 39 448 | -45.87 -890 24 449 | -45.95 -887 35 450 | -46.04 -867 22 451 | -46.12 -843 40 452 | -46.2 -851 42 453 | -46.28 -834 12 454 | -46.37 -849 28 455 | -46.45 -860 25 456 | -46.53 -866 14 457 | -46.62 -849 25 458 | -46.7 -850 9 459 | -46.79 -854 17 460 | -46.87 -856 11 461 | -46.95 -836 10 462 | -47.04 -819 9 463 | -47.12 -825 21 464 | -47.2 -850 13 465 | -47.28 -798 31 466 | -47.37 -830 10 467 | -47.45 -819 14 468 | -47.53 -813 14 469 | -47.62 -827 12 470 | -47.7 -819 14 471 | -47.79 -817 20 472 | -47.87 -793 11 473 | -47.95 -811 20 474 | -48.04 -816 10 475 | -48.12 -798 7 476 | -48.2 -781 12 477 | -48.28 -775 13 478 | -48.37 -775 27 479 | -48.45 -798 14 480 | -48.53 -792 31 481 | -48.62 -812 17 482 | -48.7 -800 28 483 | -48.79 -788 12 484 | -48.87 -774 21 485 | -48.95 -796 15 486 | -49.04 -756 23 487 | -49.12 -782 36 488 | -49.2 -758 36 489 | -49.28 -754 27 490 | -49.37 -746 34 491 | -49.45 -758 19 492 | -49.53 -777 21 493 | -49.62 -758 18 494 | -49.7 -774 15 495 | -49.79 -788 19 496 | -49.87 -765 28 497 | -49.95 -742 18 498 | -50.04 -745 26 499 | -50.12 -729 17 500 | -50.2 -714 16 501 | -50.28 -702 8 502 | -50.37 -711 17 503 | -50.45 -713 28 504 | -50.53 -722 21 505 | -50.62 -722 31 506 | -50.7 -714 15 507 | -50.79 -713 7 508 | -50.87 -706 12 509 | -50.95 -706 12 510 | -51.04 -692 19 511 | -51.12 -660 26 512 | -51.2 -659 17 513 | -51.28 -637 13 514 | -51.37 -651 30 515 | -51.45 -661 18 516 | -51.53 -692 14 517 | -51.62 -683 18 518 | -51.7 -686 10 519 | -51.79 -678 28 520 | -51.87 -676 15 521 | -51.95 -654 18 522 | -52.04 -645 23 523 | -52.12 -639 18 524 | -52.2 -625 27 525 | -52.28 -620 33 526 | -52.37 -614 24 527 | -52.45 -635 19 528 | -52.53 -644 11 529 | -52.62 -632 24 530 | -52.7 -638 23 531 | -52.79 -624 22 532 | -52.87 -623 30 533 | -52.95 -598 22 534 | -53.04 -603 34 535 | -53.12 -573 31 536 | -53.2 -582 28 537 | -53.28 -579 16 538 | -53.37 -582 38 539 | -53.45 -595 11 540 | -53.53 -604 27 541 | -53.62 -584 22 542 | -53.7 -600 17 543 | -53.79 -599 19 544 | -53.87 -571 13 545 | -53.95 -575 13 546 | -54.04 -575 36 547 | -54.12 -566 21 548 | -54.2 -569 31 549 | -54.28 -563 19 550 | -54.37 -554 19 551 | -54.45 -556 10 552 | -54.53 -555 22 553 | -54.62 -573 10 554 | -54.7 -566 13 555 | -54.79 -550 15 556 | -54.87 -548 25 557 | -54.95 -550 19 558 | -55.04 -533 20 559 | -55.12 -537 10 560 | -55.2 -522 16 561 | -55.28 -500 26 562 | -55.37 -504 27 563 | -55.45 -482 20 564 | -55.53 -522 20 565 | -55.62 -525 14 566 | -55.7 -529 21 567 | -55.79 -525 14 568 | -55.87 -510 18 569 | -55.95 -498 29 570 | -56.04 -491 11 571 | -56.12 -490 33 572 | -56.2 -476 22 573 | -56.28 -485 38 574 | -56.37 -495 29 575 | -56.45 -507 23 576 | -56.53 -497 7 577 | -56.62 -498 21 578 | -56.7 -504 14 579 | -56.79 -505 12 580 | -56.87 -507 17 581 | -56.95 -476 11 582 | -57.04 -452 16 583 | -57.12 -485 30 584 | -57.2 -461 32 585 | -57.28 -454 17 586 | -57.37 -458 14 587 | -57.45 -446 35 588 | -57.53 -480 13 589 | -57.62 -466 10 590 | -57.7 -463 15 591 | -57.79 -457 14 592 | -57.87 -445 12 593 | -57.95 -421 43 594 | -58.37 -389 38 595 | -58.45 -414 27 596 | -58.53 -463 27 597 | -58.62 -460 27 598 | -59.37 -382 28 599 | -59.45 -366 29 600 | -59.53 -453 49 601 | -59.62 -445 30 602 | -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/bacon/Matrix.h: -------------------------------------------------------------------------------- 1 | /* Original simple matrix class taken from http://www.algarcia.org/nummeth/Cpp/Matrix.h */ 2 | 3 | #ifndef MATRIX_H 4 | #define MATRIX_H 5 | 6 | #include // Defines the assert function. 7 | //#define assert(x) {} //to avoid bound checking 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | #define BUFF_SIZE 4096 17 | 18 | class Matrix { 19 | 20 | public: 21 | 22 | // Default Constructor. Creates a 1 by 1 matrix; sets value to zero. 23 | Matrix () { 24 | ma = gsl_matrix_alloc( 1, 1);// Allocate memory 25 | ve.owner = 0; 26 | ve.block = ma->block; 27 | set(0.0); // Set value of data_[0] to 0.0 28 | 29 | header = NULL; 30 | } 31 | 32 | // Regular Constructor. Creates an nR by nC matrix; sets values to zero. 33 | // If number of columns is not specified, it is set to 1. 34 | Matrix(int nR, int nC = 1, char *head=NULL) { 35 | assert(nR > 0 && nC > 0); // Check that nC and nR both > 0. 36 | ma = gsl_matrix_alloc( nR, nC);// Allocate memory 37 | ve.owner = 0; 38 | ve.block = ma->block; 39 | set(0.0); // Set values of data_[] to 0.0 40 | 41 | if (head != NULL) 42 | header = strdup(head); 43 | else 44 | header = NULL; 45 | } 46 | 47 | 48 | //copy constructor 49 | Matrix(Matrix &mat) { 50 | printf("Matrix::Matrix 2 ...\n"); 51 | ma = gsl_matrix_alloc( mat.nRow(), mat.nCol());// Allocate memory 52 | ve.owner = 0; 53 | ve.block = ma->block; 54 | copy(mat); 55 | 56 | if (mat.Header() != NULL) 57 | header = strdup(mat.Header()); 58 | else 59 | header = NULL; 60 | 61 | } 62 | 63 | //Identity (preferably square) matrix 64 | void Iden() { 65 | //assert(nRow() == nCol()); // Check that square matrix. 66 | set(0.0); // Set values of data_[] to 0.0 67 | for (int i=0; idata[ (ma->tda)*i + i] = 1.0; 69 | } 70 | 71 | 72 | 73 | // Destructor. Called when a Matrix object goes out of scope or deleted. 74 | ~Matrix() { 75 | //printf("Matrix::~Matrix\n"); 76 | if (ma != NULL) 77 | gsl_matrix_free(ma); // Release allocated memory 78 | if (header != NULL) { 79 | free(header); 80 | } 81 | } 82 | 83 | 84 | 85 | // Assignment operator function. 86 | // Overloads the equal sign operator to work with 87 | // Matrix objects. 88 | Matrix& operator=(const Matrix& mat) { 89 | if( this == &mat ) return *this; // If two sides equal, do nothing. 90 | this->copy(mat); // Copy right hand side to l.h.s. 91 | return *this; 92 | } 93 | 94 | // += operator function. 95 | // Overloads the += sign operator to work with 96 | // Matrix objects. 97 | Matrix& operator+=(const Matrix& mat) { 98 | gsl_matrix_add( this->ma, mat.ma); 99 | return *this; 100 | } 101 | 102 | // -= operator function. 103 | // Overloads the -= sign operator to work with 104 | // Matrix objects. 105 | Matrix& operator-=(const Matrix& mat) { 106 | gsl_matrix_sub( this->ma, mat.ma); 107 | return *this; 108 | } 109 | 110 | // *= operator function. 111 | // Overloads the *= sign operator to work with 112 | // Matrix objects. 113 | Matrix& operator*=(const double a) { 114 | gsl_matrix_scale( this->ma, a); 115 | return *this; 116 | } 117 | 118 | 119 | 120 | 121 | 122 | // Set function. Sets all elements of a matrix to a given value. 123 | void set(double value) { 124 | gsl_matrix_set_all( ma, value); 125 | } 126 | 127 | /*// Set function. Sets all elements of a matrix to a given value. 128 | void eval(double value, double (*fct)(double x)) { 129 | to be done 130 | }*/ 131 | 132 | 133 | //info 134 | // Simple "get" functions. Return number of rows or columns. 135 | int nRow() const { return ma->size1; } 136 | int nCol() const { return ma->size2; } 137 | 138 | //min and max 139 | double Max() { gsl_matrix_max(ma); } 140 | double Min() { gsl_matrix_min(ma); } 141 | 142 | 143 | // Parenthesis operator function. 144 | // Allows access to values of Matrix via (i,j) pair. 145 | // Example: a(1,1) = 2*b(2,3); 146 | // If column is unspecified, take as 1. 147 | double& operator() (int i, int j = 0) { 148 | assert(i >= 0 && i < ma->size1); // Bounds checking for rows 149 | assert(j >= 0 && j < ma->size2); // Bounds checking for columns 150 | return ma->data[ (ma->tda)*i + j]; // Access appropriate value 151 | } 152 | 153 | // Parenthesis operator function (const version). 154 | const double& operator() (int i, int j = 0) const{ 155 | assert(i >= 0 && i < ma->size1); // Bounds checking for rows 156 | assert(j >= 0 && j < ma->size2); // Bounds checking for columns 157 | return ma->data[(ma->tda)*i + j]; // Access appropriate value 158 | } 159 | 160 | // Allows access to values of Matrix via ele(i,j) pair. 161 | // If column is unspecified, take as 1. 162 | double ele(int i, int j = 0) { 163 | assert(i >= 0 && i < ma->size1); // Bounds checking for rows 164 | assert(j >= 0 && j < ma->size2); // Bounds checking for columns 165 | return ma->data[ (ma->tda)*i + j]; // Access appropriate value 166 | } 167 | 168 | 169 | 170 | 171 | //i/o 172 | //Print function 173 | void print( FILE *F, char *name=NULL, int fw=11, int pres=4, char *sep=" ", int rownums=0, int colnums=0) 174 | { 175 | if (name == NULL) 176 | if (header == NULL) 177 | fprintf( F, "\n"); 178 | else 179 | fprintf( F, "%s\n", header); 180 | else 181 | fprintf( F, "%s", name); 182 | for (int i=0; isize1; i++) 183 | { 184 | if ((i == 0) && (colnums)) { 185 | fprintf( F, "%*s%s", fw, "", sep); 186 | for (int j=0; jsize2; j++) 187 | fprintf( F, "%*d%s", fw, j, sep); 188 | fprintf(F, "\n"); 189 | } 190 | for (int j=0; jsize2; j++) { 191 | if ((j == 0) && (rownums)) 192 | fprintf( F, "%3d%s", i, sep); 193 | fprintf( F, "%*.*g%s", fw, pres, ele(i,j), sep); 194 | } 195 | fprintf( F, "\n"); 196 | } 197 | } 198 | void print(char *name=NULL) { print( stdout, name, 11, 4, " ", 0, 0); } 199 | void printnums(char *name=NULL) { print( stdout, name, 11, 4, " ", 1, 1); } 200 | 201 | void fileprint(char *fnam) { 202 | FILE *F; 203 | 204 | if ((F = fopen( fnam, "w+")) == NULL) 205 | { 206 | printf( "Could not open file %s for writing\n", fnam); 207 | 208 | assert(F == NULL); 209 | } 210 | else 211 | { 212 | print( F, NULL, 11, 4, " "); 213 | 214 | fclose(F); 215 | } 216 | } 217 | 218 | void printrow(int i) { 219 | assert(i < nRow()); 220 | 221 | for (int j=0; jsize2; j++) { 222 | printf( "%*.*g%s", 11, 4, ele(i,j), " "); 223 | } 224 | printf( "\n"); 225 | } 226 | 227 | int filescan(char *fnam, int file_header=0) { 228 | FILE *F; 229 | 230 | if ((F = fopen( fnam, "r")) == NULL) 231 | { 232 | printf( "File %s not found\n", fnam); 233 | 234 | return 0; 235 | } 236 | else 237 | { 238 | if (file_header == 1) { 239 | header = (char *) malloc((size_t) BUFF_SIZE); 240 | 241 | header = fgets( header, (size_t) BUFF_SIZE, F); 242 | header[strlen(header)-1] = '\0'; //remove the \n 243 | } 244 | 245 | gsl_matrix_fscanf( F, ma); 246 | 247 | fclose(F); 248 | return 1; 249 | } 250 | } 251 | 252 | /*********************** Views *********************/ 253 | //Get the gsl matrix 254 | gsl_matrix *Ma() { return ma; } 255 | 256 | 257 | //Column gsl Vector 258 | gsl_vector *AsColVec(int Col) { 259 | assert(Col >= 0 && Col < ma->size2); // Bounds checking for columns 260 | ve.size = ma->size1; 261 | ve.stride = ma->tda; 262 | ve.data = ma->data + Col; 263 | 264 | return &ve; 265 | } 266 | //First column is the defalut 267 | gsl_vector *Ve() { 268 | ve.size = ma->size1; 269 | ve.stride = ma->tda; 270 | ve.data = ma->data; 271 | 272 | return &ve; 273 | } 274 | 275 | 276 | //Row Vector 277 | gsl_vector *AsRowVec(int Row, int ChopOff=0) { 278 | assert(Row >= 0 && Row < ma->size1); // Bounds checking for rows 279 | ve.size = ma->size2-ChopOff; 280 | ve.stride = 1; 281 | ve.data = ma->data + (ma->tda)*Row; 282 | 283 | return &ve; 284 | } 285 | 286 | 287 | 288 | // Copy function. 289 | // Copies values from one Matrix object to another. 290 | void Copy(const Matrix *mat) { 291 | 292 | assert((nRow() == mat->nRow()) && (nCol() == mat->nCol())); 293 | gsl_matrix_memcpy( ma, mat->ma); 294 | } 295 | 296 | // Copy function. 297 | // Copies values from one Matrix object to another. 298 | void copy(const Matrix& mat) { 299 | gsl_matrix_memcpy( ma, mat.ma); 300 | } 301 | 302 | 303 | const char *Header() { return header; } 304 | 305 | //********************************************************************* 306 | protected: 307 | 308 | // Matrix data. 309 | gsl_matrix *ma; 310 | gsl_vector ve; 311 | 312 | char *header; 313 | 314 | 315 | }; // Class Matrix 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | class SubMatrix : public Matrix { 325 | 326 | private: 327 | gsl_matrix_view view; 328 | Matrix *Parent; 329 | 330 | public: 331 | SubMatrix(Matrix &mat, size_t k1, size_t k2, size_t n1, size_t n2) { 332 | view = gsl_matrix_submatrix ( mat.Ma(), k1, k2, n1, n2); 333 | ma = &view.matrix; 334 | Parent = &mat; 335 | if (mat.Header() != NULL) 336 | header = strdup(mat.Header()); 337 | else 338 | header = NULL; 339 | } 340 | 341 | SubMatrix( Matrix& mat, size_t n1, size_t n2) { 342 | view = gsl_matrix_submatrix ( mat.Ma(), (size_t) 0, (size_t) 0, n1, n2); 343 | ma = &view.matrix; 344 | Parent = &mat; 345 | if (mat.Header() != NULL) 346 | header = strdup(mat.Header()); 347 | else 348 | header = NULL; 349 | } 350 | 351 | SubMatrix() { 352 | //delay the opening of this submatrix 353 | ma = NULL; 354 | Parent = NULL; 355 | header = NULL; 356 | } 357 | 358 | ~SubMatrix() { 359 | ma = NULL; //we avoid the base class call to free with this 360 | if (header != NULL) { 361 | free(header); 362 | header=NULL; 363 | } 364 | 365 | } 366 | 367 | void Set(Matrix *mat, size_t k1, size_t k2, size_t n1, size_t n2) { 368 | view = gsl_matrix_submatrix ( mat->Ma(), k1, k2, n1, n2); 369 | ma = &view.matrix; 370 | Parent = mat; 371 | if (mat->Header() == NULL) 372 | header = NULL; 373 | else 374 | header = strdup(mat->Header()); 375 | } 376 | 377 | const char *SetHeader(char *head) { 378 | if (header != NULL) 379 | free(header); 380 | header == NULL; 381 | if (head != NULL) 382 | header = strdup(head); 383 | return header; 384 | } 385 | 386 | 387 | // Assignment operator function. 388 | // Overloads the equal sign operator to work with 389 | // Matrix objects. 390 | SubMatrix& operator=(const SubMatrix& mat) { 391 | if( this == &mat ) return *this; // If two sides equal, do nothing. 392 | this->copy(mat); // Copy right hand side to l.h.s. 393 | return *this; 394 | } 395 | 396 | // += operator function. 397 | // Overloads the += sign operator to work with 398 | // Matrix objects. 399 | SubMatrix& operator+=(const SubMatrix& mat) { 400 | gsl_matrix_add( this->ma, mat.ma); 401 | return *this; 402 | } 403 | 404 | // -= operator function. 405 | // Overloads the -= sign operator to work with 406 | // Matrix objects. 407 | SubMatrix& operator-=(const SubMatrix& mat) { 408 | gsl_matrix_sub( this->ma, mat.ma); 409 | return *this; 410 | } 411 | 412 | // *= operator function. 413 | // Overloads the *= sign operator to work with 414 | // Matrix objects. 415 | SubMatrix& operator*=(const double a) { 416 | gsl_matrix_scale( this->ma, a); 417 | return *this; 418 | } 419 | 420 | 421 | 422 | void Set( Matrix *mat, size_t n1, size_t n2) { 423 | view = gsl_matrix_submatrix ( mat->Ma(), (size_t) 0, (size_t) 0, n1, n2); 424 | ma = &view.matrix; 425 | Parent = mat; 426 | } 427 | 428 | 429 | void ReSize(size_t k1, size_t k2, size_t n1, size_t n2) { 430 | view = gsl_matrix_submatrix( Parent->Ma(), k1, k2, n1, n2); 431 | ma = &view.matrix; 432 | } 433 | 434 | void ReSize(size_t n1, size_t n2) { 435 | view = gsl_matrix_submatrix ( Parent->Ma(), (size_t) 0, (size_t) 0, n1, n2); 436 | ma = &view.matrix; 437 | } 438 | 439 | }; 440 | 441 | 442 | 443 | /*Auxiliary functions*/ 444 | //C = A^trA B^trB 445 | int MatMul(Matrix &C, int trA, Matrix &A, int trB, Matrix &B); 446 | int MatMul(Matrix &C, Matrix &A, Matrix &B); 447 | double CuadForm(Matrix &A, Matrix &b); 448 | int MatMulSym(Matrix &C, Matrix &A, Matrix &B); 449 | //inverse of real (symetric) positive defined matrix 450 | //as a by product we may obtain the square root of the determinat of A 451 | int InvRPD(Matrix &R, Matrix &A, double *LogDetSqrt=NULL, Matrix *ExternChol=NULL); 452 | //I have seen problems with this when dest and src are rows or cls of the same matrix 453 | int VecCopy(gsl_vector * dest, const gsl_vector * src); 454 | 455 | 456 | 457 | #endif 458 | 459 | -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/bacon/Curves/postbomb_SH1-2.14C: -------------------------------------------------------------------------------- 1 | -0.45 199 14 2 | -1.45 198 14 3 | -3 220 27 4 | -3.45 203 21 5 | -4 166 25 6 | -4.12 241 41 7 | -4.28 241 41 8 | -4.95 139 62 9 | -5.12 77 62 10 | -5.28 6 61 11 | -5.37 78 63 12 | -5.45 27 47 13 | -5.7 90 32 14 | -5.95 -6 43 15 | -6.12 -50 31 16 | -6.2 -86 40 17 | -6.45 -305 37 18 | -6.7 -87 38 19 | -6.79 -133 26 20 | -7.04 -179 26 21 | -7.28 -277 102 22 | -7.37 -339 286 23 | -7.53 -355 21 24 | -7.62 -410 30 25 | -7.79 -371 39 26 | -7.87 -452 39 27 | -8.04 -626 37 28 | -8.12 -476 38 29 | -8.2 -559 25 30 | -8.28 -550 31 31 | -8.37 -556 20 32 | -8.53 -635 28 33 | -8.62 -610 28 34 | -8.7 -730 26 35 | -8.79 -897 33 36 | -8.87 -898 34 37 | -8.95 -848 27 38 | -9.04 -898 54 39 | -9.12 -1000 79 40 | -9.2 -963 33 41 | -9.28 -1042 27 42 | -9.45 -1011 27 43 | -9.53 -1136 20 44 | -9.62 -1074 32 45 | -9.7 -1342 28 46 | -9.79 -1234 31 47 | -9.87 -1289 25 48 | -9.95 -1377 58 49 | -10.04 -1388 40 50 | -10.12 -1421 54 51 | -10.2 -1347 54 52 | -10.28 -1375 46 53 | -10.45 -1259 34 54 | -10.53 -1343 79 55 | -10.7 -1449 35 56 | -10.79 -1455 47 57 | -10.87 -1430 75 58 | -10.95 -1433 30 59 | -11.04 -1446 21 60 | -11.12 -1467 31 61 | -11.2 -1476 43 62 | -11.28 -1455 35 63 | -11.37 -1453 30 64 | -11.45 -1340 47 65 | -11.53 -1455 27 66 | -11.62 -1509 32 67 | -11.7 -1347 34 68 | -11.79 -1360 34 69 | -11.87 -1471 159 70 | -11.95 -1497 91 71 | -12.04 -1525 79 72 | -12.12 -1454 69 73 | -12.2 -1540 40 74 | -12.28 -1622 73 75 | -12.37 -1405 64 76 | -12.53 -1733 34 77 | -12.7 -1784 117 78 | -12.79 -2002 56 79 | -12.87 -1896 101 80 | -12.95 -1863 68 81 | -13.04 -1917 88 82 | -13.2 -1261 19 83 | -13.28 -2014 17 84 | -13.37 -2195 23 85 | -13.45 -2346 36 86 | -13.53 -2439 183 87 | -13.62 -2457 25 88 | -13.7 -2780 40 89 | -13.79 -2965 39 90 | -13.87 -2570 24 91 | -13.95 -3058 258 92 | -14.04 -3089 172 93 | -14.2 -3230 224 94 | -14.28 -3439 141 95 | -14.37 -3389 133 96 | -14.45 -3514 16 97 | -14.53 -3583 114 98 | -14.62 -3626 20 99 | -14.7 -3869 105 100 | -14.79 -3377 298 101 | -14.87 -3915 16 102 | -14.95 -3960 99 103 | -15.04 -4095 80 104 | -15.12 -3993 33 105 | -15.2 -3907 142 106 | -15.28 -3981 56 107 | -15.37 -3881 48 108 | -15.45 -4009 76 109 | -15.53 -4141 133 110 | -15.62 -3928 76 111 | -15.7 -4009 57 112 | -15.79 -4093 39 113 | -15.87 -3981 79 114 | -15.95 -3968 16 115 | -16.04 -4059 108 116 | -16.12 -3999 41 117 | -16.2 -3993 39 118 | -16.28 -3942 19 119 | -16.37 -3920 45 120 | -16.45 -3943 102 121 | -16.53 -3877 44 122 | -16.62 -3914 139 123 | -16.7 -3918 39 124 | -16.79 -3914 105 125 | -16.87 -3857 46 126 | -16.95 -3927 47 127 | -17.04 -3872 15 128 | -17.12 -3892 75 129 | -17.2 -3832 25 130 | -17.28 -3831 23 131 | -17.37 -3810 39 132 | -17.45 -3800 82 133 | -17.53 -3706 61 134 | -17.62 -3751 31 135 | -17.7 -3837 55 136 | -17.79 -3703 36 137 | -17.87 -3734 57 138 | -17.95 -3665 53 139 | -18.04 -3623 115 140 | -18.12 -3670 34 141 | -18.2 -3633 33 142 | -18.28 -3639 124 143 | -18.37 -3590 17 144 | -18.45 -3568 27 145 | -18.53 -3529 33 146 | -18.62 -3508 50 147 | -18.7 -3488 52 148 | -18.79 -3505 69 149 | -18.87 -3531 67 150 | -18.95 -3501 55 151 | -19.04 -3524 53 152 | -19.12 -3499 41 153 | -19.2 -3536 24 154 | -19.28 -3505 26 155 | -19.37 -3455 12 156 | -19.45 -3406 21 157 | -19.53 -3435 18 158 | -19.62 -3397 20 159 | -19.7 -3470 64 160 | -19.79 -3450 29 161 | -19.87 -3416 52 162 | -19.95 -3291 106 163 | -20.04 -3341 54 164 | -20.12 -3494 36 165 | -20.2 -3421 69 166 | -20.28 -3417 75 167 | -20.37 -3394 56 168 | -20.45 -3372 56 169 | -20.53 -3307 40 170 | -20.62 -3277 55 171 | -20.7 -3289 75 172 | -20.79 -3311 55 173 | -20.87 -3269 77 174 | -20.95 -3308 73 175 | -21.04 -3285 45 176 | -21.12 -3265 25 177 | -21.2 -3302 26 178 | -21.28 -3280 26 179 | -21.37 -3283 55 180 | -21.45 -3264 43 181 | -21.53 -3218 43 182 | -21.62 -3186 17 183 | -21.7 -3224 42 184 | -21.79 -3247 63 185 | -21.87 -3215 50 186 | -21.95 -3192 36 187 | -22.04 -3216 20 188 | -22.12 -3235 19 189 | -22.2 -3222 53 190 | -22.28 -3119 39 191 | -22.37 -3132 28 192 | -22.45 -3090 56 193 | -22.53 -3112 29 194 | -22.62 -3136 46 195 | -22.7 -3029 61 196 | -22.79 -3073 50 197 | -22.87 -3108 53 198 | -22.95 -2989 24 199 | -23.04 -3061 34 200 | -23.12 -3021 36 201 | -23.2 -2980 30 202 | -23.28 -2981 57 203 | -23.37 -2953 40 204 | -23.45 -2912 20 205 | -23.53 -2933 41 206 | -23.62 -2948 86 207 | -23.7 -2868 71 208 | -23.79 -2856 54 209 | -23.87 -2856 84 210 | -23.95 -2861 128 211 | -24.04 -2809 59 212 | -24.12 -2809 112 213 | -24.2 -2803 26 214 | -24.28 -2787 44 215 | -24.37 -2745 85 216 | -24.45 -2665 145 217 | -24.53 -2703 33 218 | -24.62 -2702 115 219 | -24.7 -2731 23 220 | -24.79 -2788 76 221 | -24.87 -2734 14 222 | -24.95 -2702 32 223 | -25.04 -2716 35 224 | -25.12 -2669 72 225 | -25.2 -2698 30 226 | -25.28 -2686 41 227 | -25.37 -2641 30 228 | -25.45 -2674 53 229 | -25.53 -2575 36 230 | -25.62 -2569 85 231 | -25.7 -2520 42 232 | -25.79 -2596 88 233 | -25.87 -2524 21 234 | -25.95 -2541 53 235 | -26.04 -2555 25 236 | -26.12 -2541 32 237 | -26.2 -2532 68 238 | -26.28 -2468 65 239 | -26.37 -2473 35 240 | -26.45 -2469 35 241 | -26.53 -2462 48 242 | -26.62 -2400 14 243 | -26.7 -2395 30 244 | -26.79 -2355 52 245 | -26.87 -2392 54 246 | -26.95 -2356 41 247 | -27.04 -2319 80 248 | -27.12 -2376 42 249 | -27.2 -2364 19 250 | -27.28 -2407 20 251 | -27.37 -2349 22 252 | -27.45 -2313 63 253 | -27.53 -2314 35 254 | -27.62 -2284 18 255 | -27.7 -2257 49 256 | -27.79 -2310 40 257 | -27.87 -2319 47 258 | -27.95 -2337 56 259 | -28.04 -2279 66 260 | -28.12 -2340 75 261 | -28.2 -2276 25 262 | -28.28 -2256 40 263 | -28.37 -2203 35 264 | -28.45 -2205 20 265 | -28.53 -2294 36 266 | -28.62 -2208 47 267 | -28.7 -2238 64 268 | -28.79 -2273 40 269 | -28.87 -2203 77 270 | -29.04 -2200 18 271 | -29.12 -2136 43 272 | -29.2 -2166 37 273 | -29.28 -2156 20 274 | -29.37 -2122 25 275 | -29.45 -2086 19 276 | -29.53 -2149 56 277 | -29.62 -2037 24 278 | -29.7 -2122 50 279 | -29.79 -2051 55 280 | -29.87 -2151 21 281 | -29.95 -2006 50 282 | -30.04 -2069 43 283 | -30.12 -2041 43 284 | -30.2 -2062 21 285 | -30.28 -2000 19 286 | -30.37 -2011 18 287 | -30.45 -1924 38 288 | -30.53 -1999 61 289 | -30.62 -1973 20 290 | -30.7 -1996 18 291 | -30.79 -2015 28 292 | -30.87 -2005 81 293 | -30.95 -1969 78 294 | -31.04 -1933 22 295 | -31.12 -1930 84 296 | -31.2 -1935 38 297 | -31.28 -1940 41 298 | -31.37 -1868 38 299 | -31.45 -1883 58 300 | -31.53 -1855 38 301 | -31.62 -1884 21 302 | -31.7 -1878 25 303 | -31.79 -1867 18 304 | -31.87 -1881 61 305 | -31.95 -1867 34 306 | -32.04 -1875 38 307 | -32.12 -1778 45 308 | -32.2 -2027 44 309 | -32.28 -1779 45 310 | -32.37 -1771 58 311 | -32.45 -1787 74 312 | -32.53 -1798 46 313 | -32.62 -1740 45 314 | -32.7 -1779 33 315 | -32.79 -1773 32 316 | -32.87 -1747 45 317 | -32.95 -1733 20 318 | -33.04 -1725 21 319 | -33.12 -1678 24 320 | -33.2 -1721 21 321 | -33.28 -1793 38 322 | -33.37 -1696 39 323 | -33.45 -1713 43 324 | -33.53 -1610 39 325 | -33.62 -1709 45 326 | -33.7 -1702 39 327 | -33.79 -1654 37 328 | -33.87 -1709 45 329 | -33.95 -1604 39 330 | -34.04 -1639 77 331 | -34.12 -1684 31 332 | -34.2 -1683 58 333 | -34.28 -1584 33 334 | -34.37 -1593 22 335 | -34.45 -1591 39 336 | -34.53 -1584 20 337 | -34.62 -1707 95 338 | -34.7 -1564 34 339 | -34.79 -1542 16 340 | -34.87 -1559 46 341 | -34.95 -1614 12 342 | -35.04 -1578 46 343 | -35.12 -1559 44 344 | -35.2 -1572 47 345 | -35.28 -1522 15 346 | -35.37 -1523 34 347 | -35.45 -1432 40 348 | -35.53 -1507 62 349 | -35.62 -1511 56 350 | -35.7 -1518 42 351 | -35.79 -1497 31 352 | -35.87 -1539 28 353 | -35.95 -1529 27 354 | -36.04 -1499 25 355 | -36.12 -1483 39 356 | -36.2 -1487 25 357 | -36.28 -1467 31 358 | -36.37 -1440 38 359 | -36.45 -1477 22 360 | -36.53 -1445 28 361 | -36.62 -1434 17 362 | -36.7 -1479 17 363 | -36.79 -1479 24 364 | -36.87 -1423 18 365 | -36.95 -1442 27 366 | -37.04 -1421 15 367 | -37.12 -1407 15 368 | -37.2 -1387 19 369 | -37.28 -1379 14 370 | -37.37 -1347 31 371 | -37.45 -1250 118 372 | -37.53 -1339 14 373 | -37.62 -1336 33 374 | -37.7 -1359 16 375 | -37.79 -1366 14 376 | -37.87 -1399 20 377 | -37.95 -1385 12 378 | -38.12 -1441 20 379 | -38.2 -1342 14 380 | -38.28 -1343 16 381 | -38.37 -1243 34 382 | -38.45 -1230 41 383 | -38.53 -1206 145 384 | -38.62 -1302 23 385 | -38.7 -1303 27 386 | -38.79 -1307 53 387 | -38.87 -1341 30 388 | -38.95 -1304 22 389 | -39.04 -1298 91 390 | -39.12 -1296 23 391 | -39.2 -1216 41 392 | -39.28 -1286 41 393 | -39.37 -1245 21 394 | -39.45 -1241 32 395 | -39.53 -1192 49 396 | -39.62 -1273 68 397 | -39.7 -1198 22 398 | -39.79 -1201 31 399 | -39.87 -1243 28 400 | -39.95 -1268 31 401 | -40.04 -1195 21 402 | -40.12 -1230 81 403 | -40.2 -1220 44 404 | -40.28 -1221 39 405 | -40.37 -1113 42 406 | -40.45 -1148 85 407 | -40.53 -1185 74 408 | -40.62 -1149 87 409 | -40.7 -1209 100 410 | -40.79 -1186 23 411 | -40.87 -1157 75 412 | -40.95 -1203 53 413 | -41.04 -1159 71 414 | -41.12 -1149 83 415 | -41.2 -1193 109 416 | -41.28 -1111 37 417 | -41.37 -1114 82 418 | -41.45 -1149 98 419 | -41.53 -1154 119 420 | -41.62 -1168 81 421 | -41.7 -1212 16 422 | -41.79 -1222 70 423 | -41.87 -1110 58 424 | -41.95 -1169 22 425 | -42.04 -1107 64 426 | -42.12 -1196 35 427 | -42.2 -1100 35 428 | -42.28 -1236 69 429 | -42.37 -1232 107 430 | -42.45 -1087 42 431 | -42.53 -1139 142 432 | -42.62 -1108 37 433 | -42.7 -1080 42 434 | -42.79 -1132 17 435 | -42.87 -1158 42 436 | -42.95 -1118 52 437 | -43.04 -1136 22 438 | -43.12 -1069 92 439 | -43.2 -1069 22 440 | -43.28 -1014 68 441 | -43.37 -1040 45 442 | -43.45 -975 48 443 | -43.53 -1003 18 444 | -43.62 -1033 63 445 | -43.7 -1036 33 446 | -43.79 -996 42 447 | -43.87 -1109 42 448 | -43.95 -999 28 449 | -44.04 -977 13 450 | -44.12 -971 50 451 | -44.2 -970 32 452 | -44.28 -1008 17 453 | -44.37 -976 16 454 | -44.45 -957 60 455 | -44.53 -955 21 456 | -44.62 -939 12 457 | -44.7 -955 20 458 | -44.79 -955 25 459 | -44.87 -964 33 460 | -44.95 -980 32 461 | -45.04 -970 33 462 | -45.12 -955 19 463 | -45.2 -936 16 464 | -45.28 -941 12 465 | -45.37 -930 25 466 | -45.45 -916 49 467 | -45.53 -913 13 468 | -45.62 -910 13 469 | -45.7 -920 16 470 | -45.79 -902 13 471 | -45.87 -896 14 472 | -45.95 -922 46 473 | -46.04 -920 26 474 | -46.12 -920 16 475 | -46.2 -911 10 476 | -46.28 -923 11 477 | -46.37 -900 15 478 | -46.45 -895 14 479 | -46.53 -890 11 480 | -46.62 -887 17 481 | -46.7 -871 42 482 | -46.79 -900 31 483 | -46.87 -872 19 484 | -46.95 -853 12 485 | -47.04 -845 48 486 | -47.12 -857 19 487 | -47.2 -854 24 488 | -47.28 -855 22 489 | -47.37 -891 17 490 | -47.45 -863 22 491 | -47.53 -885 22 492 | -47.62 -814 29 493 | -47.7 -863 32 494 | -47.79 -840 12 495 | -47.87 -856 16 496 | -47.95 -873 17 497 | -48.04 -852 19 498 | -48.12 -841 14 499 | -48.2 -819 22 500 | -48.28 -842 22 501 | -48.37 -798 15 502 | -48.45 -827 22 503 | -48.53 -807 21 504 | -48.62 -825 22 505 | -48.7 -813 16 506 | -48.79 -793 13 507 | -48.87 -784 9 508 | -48.95 -791 10 509 | -49.04 -760 10 510 | -49.12 -791 11 511 | -49.2 -793 9 512 | -49.28 -761 12 513 | -49.37 -779 20 514 | -49.45 -798 46 515 | -49.53 -786 8 516 | -49.62 -752 34 517 | -49.7 -749 16 518 | -49.79 -742 31 519 | -49.87 -763 9 520 | -49.95 -840 59 521 | -50.04 -763 8 522 | -50.12 -766 10 523 | -50.2 -764 23 524 | -50.28 -739 15 525 | -50.37 -723 50 526 | -50.45 -702 44 527 | -50.53 -709 15 528 | -50.62 -699 13 529 | -50.7 -739 20 530 | -50.79 -735 23 531 | -50.87 -734 35 532 | -50.95 -721 34 533 | -51.04 -744 24 534 | -51.12 -725 14 535 | -51.2 -697 25 536 | -51.28 -722 21 537 | -51.37 -723 9 538 | -51.45 -697 13 539 | -51.53 -727 12 540 | -51.62 -683 13 541 | -51.7 -689 29 542 | -51.79 -678 25 543 | -51.87 -687 23 544 | -51.95 -692 21 545 | -52.04 -671 25 546 | -52.12 -668 26 547 | -52.2 -692 10 548 | -52.28 -699 29 549 | -52.37 -697 15 550 | -52.45 -652 11 551 | -52.53 -666 11 552 | -52.62 -661 19 553 | -52.7 -644 24 554 | -52.79 -653 10 555 | -52.87 -665 10 556 | -52.95 -659 26 557 | -53.04 -700 13 558 | -53.12 -653 27 559 | -53.2 -652 35 560 | -53.28 -655 27 561 | -53.37 -666 44 562 | -53.45 -617 31 563 | -53.53 -646 36 564 | -53.62 -632 16 565 | -53.7 -602 37 566 | -53.79 -609 25 567 | -53.87 -619 32 568 | -53.95 -634 9 569 | -54.04 -593 43 570 | -54.12 -615 14 571 | -54.2 -610 8 572 | -54.28 -612 31 573 | -54.37 -601 7 574 | -54.45 -589 31 575 | -54.53 -579 29 576 | -54.62 -582 29 577 | -54.7 -579 28 578 | -54.79 -562 49 579 | -54.87 -581 31 580 | -54.95 -564 24 581 | -55.04 -582 8 582 | -55.12 -571 16 583 | -55.2 -568 18 584 | -55.28 -579 57 585 | -55.37 -566 34 586 | -55.45 -547 25 587 | -55.53 -551 24 588 | -55.62 -558 21 589 | -55.7 -552 25 590 | -55.79 -562 8 591 | -55.87 -544 24 592 | -55.95 -535 27 593 | -56.04 -547 13 594 | -56.12 -559 20 595 | -56.2 -544 6 596 | -56.28 -535 7 597 | -56.37 -510 26 598 | -56.45 -525 13 599 | -56.53 -525 26 600 | -56.62 -521 11 601 | -56.7 -519 11 602 | -56.79 -525 6 603 | -56.87 -522 27 604 | -56.95 -512 29 605 | -57.04 -503 29 606 | -57.12 -474 28 607 | -57.2 -494 35 608 | -57.28 -530 20 609 | -57.37 -505 21 610 | -57.45 -510 35 611 | -57.53 -482 16 612 | -57.62 -494 18 613 | -57.7 -495 20 614 | -57.79 -504 27 615 | -57.87 -491 25 616 | -57.95 -487 31 617 | -58.04 -480 8 618 | -58.12 -494 10 619 | -58.2 -495 8 620 | -58.28 -467 20 621 | -58.37 -476 15 622 | -58.45 -455 9 623 | -58.53 -458 11 624 | -58.62 -473 8 625 | -58.7 -467 16 626 | -58.79 -443 16 627 | -58.87 -467 14 628 | -58.95 -464 11 629 | -59.04 -461 11 630 | -59.12 -456 14 631 | -59.2 -465 10 632 | -59.28 -449 13 633 | -59.37 -446 12 634 | -59.45 -466 9 635 | -59.53 -454 12 636 | -59.7 -446 13 637 | -59.79 -468 13 638 | -59.87 -464 8 639 | -59.95 -464 9 640 | -60.28 -449 9 641 | -60.37 -449 9 642 | -60.45 -431 10 643 | -60.53 -455 17 644 | -60.7 -448 9 645 | -60.79 -433 12 646 | -60.87 -451 9 647 | -61.04 -413 9 648 | -61.12 -400 9 649 | -61.2 -383 9 650 | -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/bacon/baconwrap.pyx: -------------------------------------------------------------------------------- 1 | import os 2 | import datetime 3 | import shutil 4 | import contextlib 5 | import tempfile 6 | import numpy as np 7 | import pandas as pd 8 | from bacon cimport notmain 9 | from libc.stdlib cimport malloc, free 10 | from .Curves import here as curvespath 11 | 12 | 13 | @contextlib.contextmanager 14 | def try_chdir(path): 15 | """Use in `with as`, returning to CWD afterwards""" 16 | curdir = os.getcwd() 17 | try: 18 | os.chdir(path) 19 | yield 20 | finally: 21 | os.chdir(curdir) 22 | 23 | 24 | def run_baconmcmc(ssize=2000, **kwargs): 25 | """Run bacon MCMC, given parameters. 26 | 27 | Parameters 28 | ---------- 29 | ssize : int 30 | ??? # TODO(brews): I have no idea what this actually does. 31 | **kwargs : 32 | Bacon MCMC run parameters passed to `write_baconin()`. 33 | 34 | Returns 35 | ------- 36 | Output from bacon MCMC. 37 | """ 38 | cwd = os.getcwd() 39 | infile_str = 'intobacon.txt' 40 | outfile_str = 'outofbacon.bacon' 41 | curves_dir = os.path.basename(curvespath) 42 | with tempfile.TemporaryDirectory() as tmpdir: 43 | write_baconin(os.path.join(tmpdir, infile_str), **kwargs) 44 | shutil.copytree(curvespath, os.path.join(tmpdir, curves_dir)) 45 | with try_chdir(tmpdir): 46 | _baconmain(infile_str, outfile_str, ssize) 47 | out = read_baconout(outfile_str) 48 | return out 49 | 50 | 51 | def run_baconmcmcfiles(inpath, outpath, ssize=2000): 52 | """Run bacon MCMC using bacon file at inpath and write results to outpath""" 53 | cwd = os.getcwd() 54 | inpath_fl = os.path.basename(inpath) 55 | outpath_fl = os.path.basename(outpath) 56 | curves_dir = os.path.basename(curvespath) 57 | with tempfile.TemporaryDirectory() as tmpdir: 58 | shutil.copytree(curvespath, os.path.join(tmpdir, curves_dir)) 59 | shutil.copy2(inpath, tmpdir) 60 | with try_chdir(tmpdir): 61 | _baconmain(inpath_fl, outpath_fl, ssize) 62 | shutil.copy2(os.path.join(tmpdir, outpath_fl), outpath) 63 | print('Done.') 64 | 65 | 66 | def read_baconout(path): 67 | """Read output file from bacon MCMC 68 | 69 | Parameters 70 | ---------- 71 | path : str 72 | Path of file output from bacon MCMC. 73 | 74 | Returns 75 | ------- 76 | Dictionary with four members. 'theta' (or 'theta0') array (i) of calendar age of sedimentation core head for i MCMC 77 | iterations retained. 'x', a 2d array (j, i) of sediment accumulation rates for each fixed-length segment (j) down 78 | the sediment core of each MCMC iteration member (i). 'w', array (i) of memory or coherence of accumulation rates 79 | along sediment core for each MCMC iteration member. 'objective' (i.e. 'Us'), an array (i) of objective or energy 80 | function values used in the twalk MCMC. 81 | """ 82 | d = pd.read_csv(path, delim_whitespace=True, header=None) 83 | # TODO(brews): Function cannot handle hiatus 84 | out = {'theta': d.iloc[:, 0].values, # `theta0` or often just `theta`, array (i) of Age of sedimentation core head. 85 | 'x': d.iloc[:, 1:-2].values.T, # `x`, 2d array (i, j) of sediment accumulation rates for each segment (i) down the sediment core of each MCMC iteration (j). 86 | 'w': d.iloc[:, -2].values, # `w`, array (i) of memory or coherence of accumulation rates along sediment core. 87 | 'objective': d.iloc[:, -1].values} # `Us`, array (i) of objective or energy function used in the twalk MCMC. 88 | return out 89 | 90 | 91 | def _baconin_str(*, core_labid, core_age, core_error, core_depth, depth_min, depth_max, cc, d_r, d_std, k, th01, th02, 92 | mem_strength, mem_mean, acc_shape, acc_mean, t_a=None, t_b=None, cc1='IntCal13', cc2='Marine13', 93 | cc3='SHCal13', cc4='ConstCal', minyr=-1000, maxyr=1e6, normal=False, postbomb=0): 94 | """Make list of strings to write to .bacon file 95 | 96 | Parameters 97 | ---------- 98 | core_labid : n-length iterable of strs 99 | Laboratory ID for each core sample. 100 | core_age : n-length iterable of floats 101 | Carbon-14 age of each core sample. 102 | core_error : n-length iterable of floats 103 | Carbon-14 age error (standard deviation) for each core sample. # TODO(brews): Clarify what this means. 104 | core_depth : n-length iterable of floats 105 | Depth (cm) at which each core sample was taken. 106 | depth_min : float 107 | Minimum core depth (cm) to be considered. If outside the range of core_depth, will be extrapolated. 108 | depth_max : float 109 | Maximum core depth (cm) to be considered. If outside the range of core_depth, will be extrapolated. 110 | cc : list of ints 111 | Int indicating which calibration curve to use for each core sample (i.e. 'cc1', 'cc2', ... 'cc4'). If list 112 | contains single value, this value is used for all core samples. 113 | cc1 : str, optional 114 | String indicating calibration curve option. Must be one of 'IntCal13', 'Marine13', 'SHCal13', 'ConstCal'. 115 | Default is 'IntCal13'. 116 | cc2 : str, optional 117 | String indicating calibration curve option. Must be one of 'IntCal13', 'Marine13', 'SHCal13', 'ConstCal'. 118 | Default is 'Marine13' 119 | cc3 : str, optional 120 | String indicating calibration curve option. Must be one of 'IntCal13', 'Marine13', 'SHCal13', 'ConstCal'. 121 | Default is 'SHCal13'. 122 | cc4 : str, optional 123 | String indicating calibration curve option. Must be one of 'IntCal13', 'Marine13', 'SHCal13', 'ConstCal'. 124 | Default is 'ConstCal'. 125 | d_r : n-length iterable of floats 126 | Delta carbon reservoir (delta R) values for each core sample. If single value is given, it will be used for all 127 | core samples. 128 | d_std : n-length iterable of floats 129 | Delta carbon reservoir (delta R) standard deviation for each core sample. If single value is given, it will be 130 | used for all core samples. 131 | t_a : n-length iterable of floats 132 | Parameter 'a' used in t-walk MCMC. If single value is given, it will be used for all core samples. Must be one 133 | less than 't_b'. Default is 3. 134 | t_b : n-length iterable of floats 135 | Parameter 'b' used in t-walk MCMC. If single value is given, it will be used for all core samples. Must be one 136 | greater than 't_a'. Default is 4. 137 | k : int 138 | Number of fixed-length segments to divide core into for MCMC. 139 | minyr : int, optional 140 | Lowest year considered in MCMC. # TODO(brews): See line 368 of Bacon.R. Note how this is calculated. 141 | maxyr : int, optional 142 | Highest year considered in MCMC. # TODO(brews): See line 370 of Bacon.R. Note how this is calculated. 143 | th01 : int 144 | Initial ballpark guess for top-most fixed segment age. # TODO(brews): Check on this @ ln 474 of Bacon.R 145 | th02 : int 146 | Another Initial ballpark guess for fixed segment age. # TODO(sbm): Check on this @ ln 474 of Bacon.R 147 | acc_mean : float 148 | Mean sediment accumulation rate (cm/yr). 149 | acc_shape : float 150 | Sediment accumulation rate distribution shape. 151 | mem_strength: float 152 | Mean sediment accumulation rate strength from one fixed-length segment to the next. # TODO(brews): Find more details on this. 153 | mem_mean: float 154 | Mean sediment accumulation rate memory from one fixed-length segment to the next. Must be between 1 and 0. 155 | normal: bool, optional 156 | Whether to use a normal for radiocarbon age. Default is 'False', using Student's t based distribution. 157 | postbomb: int, optional 158 | Integer indicating which post-bomb curve to use for radiocarbon calibration. `0` is no curve. `1` is 159 | 'postbomb_NH1.14C'. `2` is 'postbomb_NH2.14C'. `3` is 'postbomb_NH3.14C'. `4` is 'postbomb_SH1-2.14C'. 160 | `5` is 'postbomb_SH3.14C'. 161 | 162 | Returns 163 | ------- 164 | List of strings for each line of a text file to be read into the bacon MCMC. 165 | 166 | See .write.Bacon.file @ Bacon.R ln 385-480 167 | """ 168 | # import snakebacon as snek 169 | # c = snek.read_corefile('/home/sbm/Desktop/dtda sandbox/bacon/LinBacon_2.2/Cores/MSB2K/MSB2K.csv') 170 | # Test with: 171 | # write_baconin('testout.txt', core_labid = c.labid, core_age = c.age, core_error = c.error, core_depth = c.depth, depth_min = 1.5, depth_max = 99.5, cc=[1], cc1='IntCal13', cc2='Marine13', cc3='SHCal13', cc4 = 'ConstCal', d_r = [0], d_std = [0], t_a=[3], t_b=[4], k= 20, minyr=-1000, maxyr = 1e6, th01=4147, th02=4145, acc_mean = 20, acc_shape = 1.5, mem_strength = 4, mem_mean = 0.7) 172 | # TODO(brews): Function cannot handle hiatus. 173 | core_labid = np.array(core_labid, dtype=' max(core_depth): 190 | core_labid = np.append(np.array(core_labid), 'NA') 191 | core_age = np.append(np.array(core_age), [np.max(core_age)]) 192 | core_error = np.append(np.array(core_error), np.max([1e4, np.max(100 * core_error)])) 193 | core_depth = np.append(np.array(core_depth), [depth_max]) 194 | cc = np.append(np.array(cc), [0]) 195 | d_r = np.append(np.array(d_r), [0]) 196 | d_std = np.append(np.array(d_std), [0]) 197 | 198 | # Non-14C values do not have C-reservoir adjustments. 199 | nonc14mask = cc == 0 200 | d_r[nonc14mask] = 0 201 | d_std[nonc14mask] = 0 202 | 203 | if t_a is None: 204 | t_a = [3] 205 | if t_b is None: 206 | t_b = [4] 207 | if len(t_a) == 1: 208 | t_a = np.repeat(t_a, len(core_depth)) 209 | if len(t_b) == 1: 210 | t_b = np.repeat(t_b, len(core_depth)) 211 | 212 | outlines = list() 213 | outlines.append('## Ran on {0}\n\n'.format(datetime.datetime.today().strftime('%c'))) 214 | outlines.append('Cal 0 : ConstCal;\n') 215 | outlines.append('Cal 1 : {0}, {1};\n'.format(cc1, postbomb)) 216 | outlines.append('Cal 2 : {0};\n'.format(cc2)) # TODO(brews): This is very weird @ ln 400:406. 217 | outlines.append('Cal 3 : {0}, {1};\n'.format(cc3, postbomb)) 218 | # TODO(brews): Find out if this last bit is a way to specify a calibration curve directory. ln 409 219 | # outlines.append('Cal 4 : {0}, {1};'.format(cc3, postbomb)) 220 | # Something with os.path.sep on windows, see Bacon.R 406:409 221 | outlines.append('\n## id. yr std depth d.R d.STD t.a t.b cc\n') 222 | str_template = 'Det {count} : {id} , {age}, {error}, {depth}, {r}, {std}, {a}, {b}, {cc};\n' 223 | for i, ln_depth in enumerate(core_depth): 224 | # ln_cc = # Bacon.R @ ln 448. 225 | outlines.append(str_template.format(count=i, id=core_labid[i], 226 | age=core_age[i], error=core_error[i], depth=ln_depth, r=d_r[i], 227 | std=d_std[i], a=t_a[i], b=t_b[i], cc=cc[i])) 228 | # TODO(brews): if for hiatus @ Bacon.R ln 451:469 229 | wrapup_header = '\n##\t\t K MinYr MaxYr th0 th0p w.a w.b alpha beta dmin dmax\n' 230 | outlines.append(wrapup_header) 231 | dist_opt = 'FixT' 232 | if normal: 233 | dist_opt = 'FixNor' 234 | wrapup_body = 'Bacon 0: {dist_opt}, {k}, {minyr}, {maxyr}, {th0}, {th0p}, {w_a}, {w_b}, {alpha}, {beta}, {dmin}, {dmax};\n' 235 | outlines.append(wrapup_body.format(dist_opt=dist_opt, k=k, minyr=minyr, maxyr=maxyr, 236 | th0=th01, th0p=th02, 237 | w_a=mem_strength * mem_mean, w_b=mem_strength * (1 - mem_mean), 238 | alpha=acc_shape, beta=acc_shape / acc_mean, 239 | dmin=depth_min, dmax=depth_max)) 240 | return outlines 241 | 242 | 243 | def write_baconin(path, **kwargs): 244 | """Write .bacon file to be read into bacon MCMC 245 | """ 246 | outlines = _baconin_str(**kwargs) 247 | with open(path, 'w') as fl: 248 | fl.writelines(outlines) 249 | 250 | 251 | def _baconmain(str infile, str outfile, int ssize): 252 | """Run bacon MCMC on input file, and put output into outfile 253 | 254 | The underlying C/C++ from Bacon assumes there is a directory, 'Curve' in runtime CWD that holds special format 255 | calibration curve. 256 | 257 | Parameters 258 | ---------- 259 | infile : str 260 | Path of existing bacon-format file to be input into MCMC. 261 | outfile : str 262 | Path of file where bacon MCMC results are dumped. 263 | ssize : int 264 | Sample size of input data. 265 | 266 | Returns 267 | ------- 268 | int relating to burn-in and sub-sample thinning parameters. See bacon.cpp lines 41-44 and 156. 269 | """ 270 | cdef char **outgoing_argv 271 | cdef bytes binfile 272 | cdef bytes boutfile 273 | cdef bytes bssize 274 | cdef char* cinfile 275 | cdef char* coutfile 276 | cdef char* cssize 277 | cdef int argcount = 4 278 | outgoing_argv = malloc(argcount * sizeof(char*)) 279 | try: 280 | binfile = infile.encode('utf8') 281 | cinfile = binfile 282 | 283 | boutfile = outfile.encode('utf8') 284 | coutfile = boutfile 285 | 286 | bssize = str(ssize).encode('utf8') 287 | cssize = bssize 288 | 289 | outgoing_argv[1] = cinfile 290 | outgoing_argv[2] = coutfile 291 | outgoing_argv[3] = cssize 292 | return notmain(argcount, outgoing_argv) 293 | finally: 294 | free(outgoing_argv) 295 | 296 | 297 | # _baconmain('MSB2K_20.bacon', 'out.bacon', 2000) -------------------------------------------------------------------------------- /snakebacon/mcmcbackends/bacon/bacon.h: -------------------------------------------------------------------------------- 1 | /* 2 | ********* 3 | 4 | Andres christen, May 2009. 5 | 6 | Bacon 7 | 8 | BaconFix to be used with large K, number of sections 9 | 10 | BaconMov with moving borders, to be used with small K (<10) 11 | * 12 | */ 13 | 14 | 15 | 16 | #ifndef BACON_H 17 | #define BACON_H 18 | 19 | //This is my traditional farewell, may be changed to something more "serious" 20 | #define FAREWELL "Eso es to...eso es to...eso es to...eso es toooodo amigos!\n" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "cal.h" 28 | #include "ranfun.h" 29 | #include "Matrix.h" 30 | #include "twalk.h" // twalk simulator class 31 | 32 | 33 | #define CHARBUFFER 8000 34 | 35 | 36 | class Bacon : public obj_fcn { 37 | 38 | public: 39 | Bacon(int dim) : obj_fcn(dim) { /*nothing, template class*/} 40 | 41 | void show_descrip() const { printf("Bacon:\n"); } 42 | 43 | virtual double *Getx0() = 0; 44 | 45 | virtual double *Getxp0() = 0; 46 | 47 | virtual double Getc0() = 0; 48 | 49 | virtual double GetcK() = 0; 50 | 51 | virtual void ShowDescrip() = 0; 52 | 53 | virtual void PrintNumWarnings() = 0; 54 | 55 | }; 56 | 57 | 58 | //Fixed number of sections 59 | class BaconFix : public Bacon { 60 | protected: 61 | 62 | //Object that holds all determinations 63 | Dets *dets; 64 | 65 | int m, K; //m number of dets, K number of sections 66 | int H; //number of hiatuses 67 | double *h; //location of the hiatuses 68 | 69 | int useT; //=1 to use the t model, =0 to use the noermal model 70 | 71 | double w, w0, wp0; 72 | 73 | double *x0, *xp0, *theta; 74 | 75 | double MinYr, MaxYr; 76 | 77 | //Based depth and increment between depths 78 | double c0, Dc; 79 | 80 | virtual double c(int i) { return c0 + i * Dc; } 81 | 82 | double U, Uprior, Uli; 83 | 84 | void AccPars(int prime) { /*fprintf( F, "%f %f %f\n", Uprior, Uli, U);*/ } 85 | 86 | double *alpha, *beta; //prior pars for the acc gamma prior in each inter hiatus section 87 | double prioracU(int i, const double al) { return (1.0 - alpha[i]) * log(al) + beta[i] * al; } 88 | 89 | double a, b; //a priori pars for the w beta prior 90 | double priorwU(const double w) { 91 | double ds = 1.0, logw = log(w); 92 | return (ds / Dc) * (1.0 - a) * logw + (1.0 - b) * log(1.0 - exp((ds / Dc) * logw)); 93 | } 94 | //here ds = 1.0 (cm), it could be changed to a parameter 95 | 96 | 97 | double *ha, *hb; //a priori pars for the gamma prior on hiatus jumps in each inter hiatus 98 | double priorHU(int i, const double x) { return (1.0 - ha[i]) * log(x) + hb[i] * Dc * x; } 99 | 100 | int WarnBeyondLimits; 101 | 102 | //Sets the thetas and verifies correct limits 103 | int SetThetas(double *x) { 104 | double S = x[0]; //th0 105 | int rt = 1; 106 | 107 | theta[0] = x[0]; 108 | if (fcmp(theta[0], MinYr) == -1) {// < MinYr 109 | WarnBeyondLimits++; 110 | //beyond established limits 111 | rt = 0; 112 | } 113 | for (int k = 1; k < K; k++) { 114 | S += x[k] * (c(k) - c(k - 1)); //For fixed c's, Dc = c(k)-c(k-1) 115 | theta[k] = S; 116 | } 117 | //Last theta 118 | theta[K] = theta[K - 1] + x[K] * (c(K) - c(K - 1)); 119 | if (fcmp(theta[K], MaxYr) == 1) 120 | WarnBeyondLimits++; 121 | //beyond established limits 122 | 123 | return rt; 124 | } 125 | 126 | 127 | public: 128 | BaconFix(Dets *detsdets, int KK, int HH, double **hiatus_pars, double aa, double bb, 129 | double MMinYr, double MMaxYr, double th0, double thp0, double cc0, double cm, int uuseT, 130 | unsigned long int seed, int more_pars = 0) 131 | : Bacon((KK + 1) + 1 + more_pars) { 132 | 133 | 134 | //Use the student t model, 1, or the traditional normal model, 0 135 | useT = uuseT; 136 | 137 | dets = detsdets; 138 | 139 | m = dets->Size(); 140 | //Minimum and maximum years 141 | MinYr = MMinYr; 142 | MaxYr = MMaxYr; 143 | 144 | WarnBeyondLimits = 0; 145 | 146 | K = KK; // Number of sections 147 | H = HH; // Number of hiatuses 148 | // reg. w 149 | 150 | a = aa; 151 | b = bb; 152 | 153 | //hiatus_pars is a pointer to 5 arrays of doubles of size H+1 154 | //containing: 155 | h = hiatus_pars[0]; 156 | 157 | alpha = hiatus_pars[1]; 158 | beta = hiatus_pars[2]; 159 | 160 | ha = hiatus_pars[3]; 161 | hb = hiatus_pars[4]; 162 | 163 | 164 | //Open memory for the two points in the parameter space 165 | //x[0] is theta[0], then x[1] ... x[K], and x[K+1]=w 166 | x0 = new double[get_dim()]; 167 | xp0 = new double[get_dim()]; 168 | 169 | //These will hold the cal. years at each node 170 | //The translation from x's to thetas's is done in method insupport 171 | theta = new double[K + 1]; 172 | 173 | //Set the sections, locations for the c's 174 | c0 = cc0; 175 | Dc = (cm - c0) / (double) K; 176 | 177 | 178 | 179 | //Verify the ordering in the h's 180 | //The h's must be an array of size H+1!!! although there are only H hiatuses 181 | for (int k = 0; k < H; k++) { 182 | if (fcmp(h[k], ((k == 0) ? c(K) : h[k - 1]) - Dc) != -1) { //we need only one per section 183 | printf("Bacon: ERROR: The hiatuses are not in descending order and/or less than %f\n", c(K)); 184 | 185 | exit(0); //h[k] not in the correct order ... we need to have h[H-1] < ... < h[0] < c(K) 186 | } 187 | } 188 | if (H > 0) 189 | if (fcmp(h[H - 1], c0) == -1) { 190 | printf("Bacon: ERROR: The last hiatus location is not greater than %f\n", c0); 191 | 192 | exit(0); //we need to have c0 < h[H-1] 193 | } 194 | h[H] = c0 - 2 * Dc; //fix h[H] lower than the low limit for depths 195 | 196 | 197 | //Initial values for x0 198 | x0[0] = th0; 199 | xp0[0] = thp0; 200 | 201 | Seed(seed); //Set the Seed for random number generation 202 | 203 | //and for w, from its prior 204 | x0[K + 1] = BetaSim(a, b); 205 | xp0[K + 1] = BetaSim(a, b); 206 | w0 = x0[K + 1]; 207 | wp0 = xp0[K + 1]; //short names for the initial values 208 | 209 | //******************* NB ************************ 210 | //the prior is scale=1/beta[0] ... however, to avoid models growing out of bounds 211 | //we prefer higher accumulation rates: scale=mult/beta[0] 212 | double mult = 1.0; 213 | 214 | //initial values for the acc. rates 215 | x0[K] = GammaSim(alpha[H], 1.0 / beta[H]); 216 | xp0[K] = GammaSim(alpha[H], 1.0 / beta[H]); 217 | if (H == 0) { //with no hiatus 218 | for (int k = K - 1; k > 0; k--) { 219 | x0[k] = w0 * x0[k + 1] + (1.0 - w0) * GammaSim(alpha[0], mult / beta[0]); 220 | xp0[k] = wp0 * xp0[k + 1] + (1.0 - wp0) * GammaSim(alpha[0], mult / beta[0]); 221 | 222 | } 223 | } else {//initial values for the acc. rates, with hiatus 224 | 225 | //we go backwards until we find the hiatus 226 | int l = 0; 227 | for (int k = K - 1; k > 0; k--) { 228 | if ((fcmp(c(k - 1), h[l]) == -1) && (fcmp(h[l], c(k)) != 1)) { //forgets 229 | x0[k] = GammaSim(ha[l], 1.0 / (hb[l] * Dc)); 230 | //printf("Hiatus %d: %f %f %f\n", l, ha[l], hb[l], x0[k]); 231 | l++; //jump to next hiatus, but max one hiatus in each section. 232 | } else //continue with memory 233 | x0[k] = w0 * x0[k + 1] + (1.0 - w0) * GammaSim(alpha[l], mult / beta[l]); 234 | } 235 | 236 | l = 0; //do it again 237 | for (int k = K - 1; k > 0; k--) { 238 | if ((fcmp(c(k - 1), h[l]) == -1) && (fcmp(h[l], c(k)) != 1)) { //forgets 239 | xp0[k] = GammaSim(ha[l], 1.0 / (hb[l] * Dc)); 240 | //printf("Hiatus %d: %f %f %f\n", l, ha[l], hb[l], xp0[k]); 241 | l++; //jump to next hiatus, but max one hiatus in each section. 242 | } else //continue with the memory 243 | xp0[k] = wp0 * xp0[k + 1] + (1.0 - wp0) * GammaSim(alpha[l], mult / beta[l]); 244 | } 245 | 246 | } 247 | 248 | 249 | } 250 | 251 | 252 | //x[0] is theta[0], then x[1] ... x[K], x[K+1]=w 253 | int insupport(double *x) { 254 | 255 | //printf("insupport, "); 256 | //for (int i=0; i 0; k--) { 284 | //printf("B: %d %f %f\n", k, x[k], (x[k]-w*x[k+1])/(1.0-w)); 285 | if ((fcmp(c(k - 1), h[l]) == -1) && (fcmp(h[l], c(k)) != 1)) { //forgets 286 | if (fcmp(x[k], 0.0) != 1) //we only require x[k] greater than 0 287 | return 0; 288 | l++; //jump to next hiatus, but max one hiatus in each section. 289 | } else if (fcmp((x[k] - w * x[k + 1]) / (1.0 - w), 0.0) != 1) { //e_k <= 0 290 | return 0; 291 | } 292 | } 293 | 294 | } 295 | 296 | 297 | //Set the thetas and return 298 | int rt = SetThetas(x); 299 | 300 | //printf("%d\n", rt); 301 | 302 | return rt; 303 | } 304 | 305 | 306 | //we assume the correct thetas are in theta 307 | //G is only called right after insupport 308 | virtual double G(const double d, const double *x) { 309 | 310 | int i = (int) floor((d - c0) / Dc); 311 | 312 | return theta[i] + x[i + 1] * (d - c(i)); 313 | 314 | } 315 | 316 | //This is a polymorphic version of the above age-depth model 317 | //where only the theta at the nearest node is returned. 318 | //we assume the correct thetas are in theta!!!! 319 | virtual double G(const double d) { 320 | 321 | int i = (int) floor((d - c0) / Dc); 322 | 323 | return theta[i] + (d - c(i)) * (theta[i + 1] - theta[i]) / Dc; 324 | 325 | } 326 | 327 | 328 | ~BaconFix() { 329 | delete x0; 330 | delete xp0; 331 | delete theta; 332 | delete dets; 333 | } 334 | 335 | 336 | double Getc0() { return c(0); } 337 | 338 | double GetcK() { return c(K); } 339 | 340 | virtual void ShowDescrip() { 341 | printf("BaconFixed: Bacon jumps model with fixed c's.\n"); 342 | printf(" K= %d, H= %d, dim= %d, Seed= %ld, Dc=%f, c(0)= %f, c(K)= %f\n", 343 | K, H, get_dim(), GetSeed(), Dc, c(0), c(K)); 344 | } 345 | 346 | void PrintNumWarnings() { 347 | if (WarnBeyondLimits != 0) { 348 | printf("bacon: %d WarnBeyondLimits warnings:\n", WarnBeyondLimits); 349 | printf("bacon: WARNING: calibration attempted beyond MinYr= %f or MaxYr= %f\n", MinYr, MaxYr); 350 | } 351 | } 352 | 353 | double *Getx0() { return x0; } 354 | 355 | double *Getxp0() { return xp0; } 356 | 357 | virtual double eval(double *x, int prime) { 358 | 359 | Uprior = 0.0; 360 | Uli = 0.0; 361 | 362 | //printf(" Init=%f", U); 363 | 364 | //assuming insupport is called right before eval 365 | 366 | 367 | if (useT) { //uses t model 368 | for (int j = 0; j < (m - 1); j++) { 369 | 370 | Uli += dets->Ut(j, G(dets->d(j), x)); //likelihood 371 | 372 | //printf("%d %f %f %f\n", j, dets->d(j), G( dets->d(j), x), Uli); 373 | } 374 | Uli += dets->Ut(m - 1, G(dets->d(m - 1), x)); 375 | } else { //uses standard normal model 376 | for (int j = 0; j < (m - 1); j++) { 377 | 378 | Uli += dets->U(j, G(dets->d(j), x)); //likelihood 379 | 380 | //printf("%d %f %f %f\n", j, dets->d(j), G( dets->d(j), x), Uli); 381 | } 382 | Uli += dets->U(m - 1, G(dets->d(m - 1), x)); 383 | } 384 | 385 | //printf(" Uli=%f", Uli); 386 | 387 | Uprior += priorwU(w); //prior for w 388 | 389 | //printf(" priorw=%f", Uprior); 390 | 391 | 392 | //Set the prior for all accumulation rates 393 | Uprior += prioracU(0, x[K]); //prior for alpha_K 394 | if (H == 0) { 395 | //printf("A: %d %f %d\n", 0, x[0], K); 396 | for (int k = 1; k < K; k++) { 397 | Uprior += prioracU(0, (x[k] - w * x[k + 1]) / (1.0 - w)); //prior for e_k 398 | //printf("%f %f\n", (x[k]-w*x[k+1])/(1.0-w), U); 399 | } 400 | } else { 401 | 402 | //we go backwards until we find the hiatus 403 | int l = 0; 404 | 405 | for (int k = K - 1; k > 0; k--) { 406 | if ((fcmp(c(k - 1), h[l]) == -1) && (fcmp(h[l], c(k)) != 1)) { //forgets 407 | Uprior += priorHU(l, x[k]); //prior for the hiatus jump in hiatus l 408 | l++; //jump to next hiatus, but max one hiatuas in each section. 409 | } else 410 | Uprior += prioracU(l, (x[k] - w * x[k + 1]) / (1.0 - w)); //prior for e_k in section l 411 | } 412 | 413 | } 414 | 415 | //printf(" Uprior=%f, U=%f\n", Uprior, Uprior+Uli); 416 | /*if (!prime) { 417 | for (int i=0; i