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
NestedSamplesorMCMCSamples. Check their docstrings for more information.
- Returns:
anesthetic.samples.NestedSamplesoranesthetic.samples.MCMCSamplesdepending 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>.*.txtand<root>.updated.yaml.
- Returns:
- anesthetic.read.cobaya.read_paramnames(root)[source]
Read header of
<root>.1.txtto 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.csv module
Read and write CSV files for anesthetic.
- anesthetic.read.csv.read_csv(filename, *args, **kwargs)[source]
Read a CSV file into a
anesthetic.samples.Samplesobject.
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.read.getdist.read_paramnames(root)[source]
Read
<root>.paramnamesin 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
Object to retrieve from file. Raises KeyError if not found.
- 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.
This method writes a pandas DataFrame or Series into an HDF5 file using either the fixed or table format. The table format allows additional operations like incremental appends and queries but may have performance trade-offs. The fixed format provides faster read/write operations but does not support appends or queries.
- Parameters:
- keystr
Key of object to store in file.
- value{Series, DataFrame}
Value of object to store in file.
- 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.
- complibdefault None
This parameter is currently not accepted.
- complevelint, 0-9, default None
Specifies a compression level for data. A value of 0 or None disables compression.
- min_itemsizeint, dict, or None
Dict of columns that specify minimum str sizes.
- nan_repstr
Str to use as str nan representation.
- 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.
- errorsstr, default ‘strict’
The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.
- 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.
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.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.datand<root>phys_live.pointsin the old format, and<root>dead-birth.txtand<root>phys_live-birth.txtin the new format.
anesthetic.read.nestedfit module
Read NestedSamples from Nested_Fit chains.
anesthetic.read.polychord module
Read NestedSamples from PolyChord chains.
anesthetic.read.ultranest module
Read NestedSamples from UltraNest results.