Skip to content

Commit

Permalink
Merge pull request #327 from martinit18/nested_fit
Browse files Browse the repository at this point in the history
compatibility with nested_fit output files
  • Loading branch information
martinit18 committed Aug 12, 2023
2 parents dc15c5b + 9f4b9e5 commit 337b07a
Show file tree
Hide file tree
Showing 12 changed files with 51,450 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
anesthetic: nested sampling post-processing
===========================================
:Authors: Will Handley and Lukas Hergt
:Version: 2.1.5
:Version: 2.2.0
:Homepage: https://github.com/handley-lab/anesthetic
:Documentation: http://anesthetic.readthedocs.io/

Expand Down
2 changes: 1 addition & 1 deletion anesthetic/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.1.5'
__version__ = '2.2.0'
4 changes: 3 additions & 1 deletion anesthetic/read/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from anesthetic.read.cobaya import read_cobaya
from anesthetic.read.multinest import read_multinest
from anesthetic.read.ultranest import read_ultranest
from anesthetic.read.nestedfit import read_nestedfit


def read_chains(root, *args, **kwargs):
Expand All @@ -14,6 +15,7 @@ def read_chains(root, *args, **kwargs):
* `PolyChord <https://github.com/PolyChord/PolyChordLite>`_,
* `MultiNest <https://github.com/farhanferoz/MultiNest>`_,
* `UltraNest <https://github.com/JohannesBuchner/UltraNest>`_,
* `Nested_fit <https://github.com/martinit18/Nested_Fit>`_,
* `CosmoMC <https://github.com/cmbant/CosmoMC>`_,
* `Cobaya <https://github.com/CobayaSampler/cobaya>`_,
* or anything `GetDist <https://github.com/cmbant/getdist>`_
Expand Down Expand Up @@ -49,7 +51,7 @@ def read_chains(root, *args, **kwargs):
errors = []
readers = [
read_polychord, read_multinest, read_cobaya,
read_ultranest, read_getdist
read_ultranest, read_nestedfit, read_getdist
]
for read in readers:
try:
Expand Down
35 changes: 35 additions & 0 deletions anesthetic/read/nestedfit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Read NestedSamples from Nested_Fit chains."""
import os
import numpy as np
from anesthetic.read.getdist import read_paramnames
from anesthetic.samples import NestedSamples


def read_nestedfit(root, *args, **kwargs):
"""Read Nested_Fit chain files.
Parameters
----------
root : str
root specify the directory only, no specific roots,
The files read files are ``nf_output_points.txt``
and ``nf_output_diag.txt``.
"""
dead_file = os.path.join(root, 'nf_output_points.txt')
birth_file = os.path.join(root, 'nf_output_diag.dat')
data_dead = np.loadtxt(dead_file)
data_birth = np.loadtxt(birth_file)
weight, logL, data = np.split(data_dead, [1, 2], axis=1)
logL_birth = data_birth[:, 0]
root_getdist = os.path.join(root, 'nf_output_points')
columns, labels = read_paramnames(root_getdist)
# No specific labeling is implemented in nested_fit
labels = columns
columns = kwargs.pop('columns', columns)
labels = kwargs.pop('labels', labels)
kwargs['label'] = kwargs.get('label', os.path.basename(root))

return NestedSamples(data=data, columns=columns,
logL=logL, logL_birth=logL_birth,
labels=labels, *args, **kwargs)
13 changes: 11 additions & 2 deletions docs/source/reading_writing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ Reading and writing

.. _reading chains:

Reading chain files from PolyChord, MultiNest, UltraNest, CosmoMC, or Cobaya
============================================================================
Reading chain files from PolyChord, MultiNest, UltraNest, NestedFit, CosmoMC, or Cobaya
=======================================================================================

If you have finished nested sampling or MCMC runs from one of:

* `PolyChord <https://polychord.io>`_: https://github.com/PolyChord/PolyChordLite
* MultiNest: https://github.com/farhanferoz/MultiNest
* `UltraNest <https://johannesbuchner.github.io/UltraNest/index.html>`_: https://github.com/JohannesBuchner/UltraNest
* NestedFit: https://github.com/martinit18/nested_fit
* `CosmoMC <https://cosmologist.info/cosmomc/readme.html>`_: https://github.com/cmbant/CosmoMC
* `Cobaya <https://cobaya.readthedocs.io>`_: https://github.com/CobayaSampler/cobaya

Expand All @@ -38,6 +39,14 @@ out the examples listed here.
from anesthetic import read_chains
samples = read_chains("anesthetic/tests/example_data/un")

* NestedFit samples, which will be an instance of the
:class:`anesthetic.samples.NestedSamples` class:

::
from anesthetic import read_chains
samples = read_chains("anesthetic/tests/example_data/nf")

* Cobaya samples, which will be an instance of the
:class:`anesthetic.samples.MCMCSamples` class:

Expand Down

0 comments on commit 337b07a

Please sign in to comment.