anesthetic.read package

Module for reading samples from file.

anesthetic.read.chain module

Read MCMCSamples or NestedSamples from any chains.

anesthetic.read.chain.read_chains(root, *args, **kwargs)[source]

Auto-detect chain type and read from file.

anesthetic supports chains from:

Note that in order to optimally read chains from Cobaya you need to have GetDist installed.

Parameters:
rootstr, pathlib.Path

root name for reading files

*args, **kwargs:

Passed onto NestedSamples or MCMCSamples. Check their docstrings for more information.

Returns:
anesthetic.samples.NestedSamples or
anesthetic.samples.MCMCSamples depending on auto-detection

anesthetic.read.cobaya module

Read MCMCSamples from Cobaya chains.

anesthetic.read.cobaya.read_cobaya(root, *args, **kwargs)[source]

Read Cobaya yaml files.

Note that in order to optimally read chains from Cobaya you need to have GetDist installed.

Parameters:
rootstr

root name for reading files in Cobaya format, i.e. the files <root>.*.txt and <root>.updated.yaml.

Returns:
anesthetic.samples.MCMCSamples
anesthetic.read.cobaya.read_paramnames(root)[source]

Read header of <root>.1.txt to infer the paramnames.

This is the data file of the first chain. It should have as many columns as there are parameters (sampled and derived) plus an additional two corresponding to the weights (first column) and the log-posterior (second column). The first line should start with a # and should list the parameter names corresponding to the columns. These will be used as handles in the pandas array.

anesthetic.read.getdist module

Read MCMCSamples from GetDist chains.

anesthetic.read.getdist.read_getdist(root, *args, **kwargs)[source]

Read <root>_1.txt in GetDist format.

Returns:
anesthetic.samples.MCMCSamples
anesthetic.read.getdist.read_paramnames(root)[source]

Read <root>.paramnames in GetDist format.

This file should contain one or two columns. The first column indicates a reference name for the sample, used as labels in the pandas array. The second optional column should include the equivalent axis label, possibly in tex, with the understanding that it will be surrounded by dollar signs, for example

<root>.paramnames:

a1     a_1
a2     a_2
omega  \omega

anesthetic.read.hdf module

Anesthetic overwrites for pandas hdf functionality.

class anesthetic.read.hdf.HDFStore(path, mode='a', complevel=None, complib=None, fletcher32=False, **kwargs)[source]
anesthetic_types = {'MCMCSamples': <class 'anesthetic.samples.MCMCSamples'>, 'NestedSamples': <class 'anesthetic.samples.NestedSamples'>, 'Samples': <class 'anesthetic.samples.Samples'>}
get(key, *args, **kwargs)[source]

Retrieve pandas object stored in file.

Parameters:
keystr
Returns:
object

Same type as object stored in file.

Examples

>>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
>>> store = pd.HDFStore("store.h5", 'w')  
>>> store.put('data', df)  
>>> store.get('data')  
>>> store.close()  
put(key, value, *args, **kwargs)[source]

Store object in HDFStore.

Parameters:
keystr
value{Series, DataFrame}
format‘fixed(f)|table(t)’, default is ‘fixed’

Format to use when storing object in HDFStore. Value can be one of:

'fixed'

Fixed format. Fast writing/reading. Not-appendable, nor searchable.

'table'

Table format. Write as a PyTables Table structure which may perform worse but allow more flexible operations like searching / selecting subsets of the data.

indexbool, default True

Write DataFrame index as a column.

appendbool, default False

This will force Table format, append the input data to the existing.

data_columnslist of columns or True, default None

List of columns to create as data columns, or True to use all columns. See here.

encodingstr, default None

Provide an encoding for strings.

track_timesbool, default True

Parameter is propagated to ‘create_table’ method of ‘PyTables’. If set to False it enables to have the same h5 files (same hashes) independent on creation time.

dropnabool, default False, optional

Remove missing values.

Examples

>>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
>>> store = pd.HDFStore("store.h5", 'w')  
>>> store.put('data', df)  
select(key, *args, **kwargs)[source]

Retrieve pandas object stored in file, optionally based on where criteria.

Warning

Pandas uses PyTables for reading and writing HDF5 files, which allows serializing object-dtype data with pickle when using the “fixed” format. Loading pickled data received from untrusted sources can be unsafe.

See: https://docs.python.org/3/library/pickle.html for more.

Parameters:
keystr

Object being retrieved from file.

wherelist or None

List of Term (or convertible) objects, optional.

startint or None

Row number to start selection.

stopint, default None

Row number to stop selection.

columnslist or None

A list of columns that if not None, will limit the return columns.

iteratorbool or False

Returns an iterator.

chunksizeint or None

Number or rows to include in iteration, return an iterator.

auto_closebool or False

Should automatically close the store when finished.

Returns:
object

Retrieved object from file.

Examples

>>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
>>> store = pd.HDFStore("store.h5", 'w')  
>>> store.put('data', df)  
>>> store.get('data')  
>>> print(store.keys())  
['/data1', '/data2']
>>> store.select('/data1')  
   A  B
0  1  2
1  3  4
>>> store.select('/data1', where='columns == A')  
   A
0  1
1  3
>>> store.close()  
anesthetic.read.hdf.read_hdf(path_or_buf, *args, **kwargs)[source]

Read from the store, close it if we opened it.

Retrieve pandas object stored in file, optionally based on where criteria.

Warning

Pandas uses PyTables for reading and writing HDF5 files, which allows serializing object-dtype data with pickle when using the “fixed” format. Loading pickled data received from untrusted sources can be unsafe.

See: https://docs.python.org/3/library/pickle.html for more.

Parameters:
path_or_bufstr, path object, pandas.HDFStore

Any valid string path is acceptable. Only supports the local file system, remote URLs and file-like objects are not supported.

If you want to pass in a path object, pandas accepts any os.PathLike.

Alternatively, pandas accepts an open pandas.HDFStore object.

keyobject, optional

The group identifier in the store. Can be omitted if the HDF file contains a single pandas object.

mode{‘r’, ‘r+’, ‘a’}, default ‘r’

Mode to use when opening the file. Ignored if path_or_buf is a pandas.HDFStore. Default is ‘r’.

errorsstr, default ‘strict’

Specifies how encoding and decoding errors are to be handled. See the errors argument for open for a full list of options.

wherelist, optional

A list of Term (or convertible) objects.

startint, optional

Row number to start selection.

stopint, optional

Row number to stop selection.

columnslist, optional

A list of columns names to return.

iteratorbool, optional

Return an iterator object.

chunksizeint, optional

Number of rows to include in an iteration when using an iterator.

**kwargs

Additional keyword arguments passed to HDFStore.

Returns:
object

The selected object. Return type depends on the object stored.

See also

pandas.DataFrame.to_hdf

Write a HDF file from a pandas.DataFrame.

HDFStore

Low-level access to HDF files.

Examples

>>> df = pd.pandas.DataFrame([[1, 1.0, 'a']], columns=['x', 'y', 'z'])  
>>> df.to_hdf('./store.h5', 'data')  
>>> reread = pd.anesthetic.read_hdf('./store.h5')  
anesthetic.read.hdf.to_hdf(path_or_buf, key, value, mode='a', complevel=None, complib=None, *args, **kwargs)[source]

store this object, close it if we opened it

anesthetic.read.multinest module

Read NestedSamples from MultiNest chains.

anesthetic.read.multinest.read_multinest(root, *args, **kwargs)[source]

Read MultiNest chain files.

Parameters:
rootstr

root name for reading files in MultiNest format, i.e. the files <root>ev.dat and <root>phys_live.points in the old format, and <root>dead-birth.txt and <root>phys_live-birth.txt in the new format.

anesthetic.read.nestedfit module

Read NestedSamples from Nested_Fit chains.

anesthetic.read.nestedfit.read_nestedfit(root, *args, **kwargs)[source]

Read Nested_Fit chain files.

Parameters:
rootstr

root specify the directory only, no specific roots, The files read files are nf_output_points.txt and nf_output_diag.txt.

anesthetic.read.polychord module

Read NestedSamples from PolyChord chains.

anesthetic.read.polychord.read_polychord(root, *args, **kwargs)[source]

Read PolyChord chain files.

Parameters:
rootstr

root name for reading files in PolyChord format, i.e. the files <root>_dead-birth.txt and <root>_phys_live-birth.txt.

anesthetic.read.ultranest module

Read NestedSamples from UltraNest results.

anesthetic.read.ultranest.read_ultranest(root, *args, **kwargs)[source]

Read UltraNest files.

Parameters:
rootstr

root name for reading files in UltraNest format, i.e. the files <root>/info/results.json and <root>/results/points.hdf5.