@@ -66,16 +66,22 @@ def loadMCSamples(file_root, ini=None, jobItem=None, no_cache=False, settings={}
66
66
if settings and dist_settings : raise ValueError ('Use settings or dist_settings' )
67
67
if dist_settings : settings = dist_settings
68
68
files = chainFiles (file_root )
69
+ if not files : # try new Cobaya format
70
+ files = chainFiles (file_root , separator = '.' )
69
71
path , name = os .path .split (file_root )
70
72
path = getdist .cache_dir or path
71
73
if not os .path .exists (path ): os .mkdir (path )
72
74
cachefile = os .path .join (path , name ) + '.py_mcsamples'
73
75
samples = MCSamples (file_root , jobItem = jobItem , ini = ini , settings = settings )
74
76
if os .path .isfile (file_root + '.paramnames' ):
75
77
allfiles = files + [file_root + '.ranges' , file_root + '.paramnames' , file_root + '.properties.ini' ]
76
- else : # new format (txt+yaml)
77
- mid = "" if file_root .endswith ("/" ) else "__"
78
- allfiles = files + [file_root + mid + ending for ending in ['input.yaml' , 'full.yaml' ]]
78
+ else : # Cobaya
79
+ folder = os .path .dirname (file_root )
80
+ prefix = os .path .basename (file_root )
81
+ allfiles = files + [
82
+ os .path .join (folder , f ) for f in os .listdir (folder ) if (
83
+ f .startswith (prefix ) and
84
+ any ([f .lower ().endswith (end ) for end in ['updated.yaml' , 'full.yaml' ]]))]
79
85
if not no_cache and os .path .exists (cachefile ) and lastModified (allfiles ) < os .path .getmtime (cachefile ):
80
86
try :
81
87
with open (cachefile , 'rb' ) as inp :
@@ -95,12 +101,18 @@ def loadMCSamples(file_root, ini=None, jobItem=None, no_cache=False, settings={}
95
101
return samples
96
102
97
103
98
- def loadCobayaSamples (info , collections , name_tag = None ,
99
- ignore_rows = 0 , ini = None , settings = {}):
104
+ def loadCobayaSamples (* args , ** kwargs ):
105
+ logging .warning ("'loadCobayaSamples' will be deprecated in the future. "
106
+ "Use 'MCSamplesFromCobaya' instead." )
107
+ return MCSamplesFromCobaya (* args , ** kwargs )
108
+
109
+
110
+ def MCSamplesFromCobaya (info , collections , name_tag = None ,
111
+ ignore_rows = 0 , ini = None , settings = {}):
100
112
"""
101
- Loads a set of samples from Cobaya's output.
113
+ Creates a set of samples from Cobaya's output.
102
114
Parameter names, ranges and labels are taken from the "info" dictionary
103
- (always use the "full", updated one generated by `cobaya.run`).
115
+ (always use the "updated" one generated by `cobaya.run`).
104
116
105
117
For a description of the various analysis settings and default values see
106
118
`analysis_defaults.ini <http://getdist.readthedocs.org/en/latest/analysis_settings.html>`_.
@@ -114,6 +126,10 @@ def loadCobayaSamples(info, collections, name_tag=None,
114
126
:param settings: dictionary of analysis settings to override defaults
115
127
:return: The :class:`MCSamples` instance
116
128
"""
129
+ from getdist .cobaya_interface import _p_label , _p_renames , _weight , _minuslogpost
130
+ from getdist .cobaya_interface import get_info_params , get_range , is_derived_param
131
+ from getdist .cobaya_interface import get_sampler_type , _post
132
+
117
133
if not hasattr (info , "keys" ):
118
134
raise TypeError ("Cannot regonise arguments. Are you sure you are calling "
119
135
"with (info, collections, ...) in that order?" )
@@ -127,9 +143,6 @@ def loadCobayaSamples(info, collections, name_tag=None,
127
143
"The second argument does not appear to be a (list of) samples `Collection`." )
128
144
if not all ([list (c .data ) == columns for c in collections [1 :]]):
129
145
raise ValueError ("The given collections don't have the same columns." )
130
- from getdist .yaml_format_tools import _p_label , _p_renames , _weight , _minuslogpost
131
- from getdist .yaml_format_tools import get_info_params , get_range , is_derived_param
132
- from getdist .yaml_format_tools import get_sampler_type , _post
133
146
# Check consistency with info
134
147
info_params = get_info_params (info )
135
148
# ####################################################################################
@@ -139,8 +152,8 @@ def loadCobayaSamples(info, collections, name_tag=None,
139
152
thin = info .get (_post , {}).get ("thin" , 1 )
140
153
# Maybe warn if trying to ignore rows twice?
141
154
if ignore_rows != 0 and skip != 0 :
142
- logging .warn ("You are asking for rows to be ignored (%r), but some (%r) were "
143
- "already ignored in the original chain." , ignore_rows , skip )
155
+ logging .warning ("You are asking for rows to be ignored (%r), but some (%r) were "
156
+ "already ignored in the original chain." , ignore_rows , skip )
144
157
# Should we warn about thin too?
145
158
# Most importantly: do we want to save somewhere the fact that we have *already*
146
159
# thinned/skipped?
@@ -182,7 +195,8 @@ class MCSamples(Chains):
182
195
"""
183
196
The main high-level class for a collection of parameter samples.
184
197
185
- Derives from :class:`.chains.Chains`, adding high-level functions including Kernel Density estimates, parameter ranges and custom settings.
198
+ Derives from :class:`.chains.Chains`, adding high-level functions including
199
+ Kernel Density estimates, parameter ranges and custom settings.
186
200
"""
187
201
188
202
def __init__ (self , root = None , jobItem = None , ini = None , settings = None , ranges = None ,
@@ -2083,10 +2097,15 @@ def _setLikeStats(self):
2083
2097
2084
2098
def _readRanges (self ):
2085
2099
if self .root :
2100
+ from getdist .cobaya_interface import _separator_files
2086
2101
ranges_file_classic = self .root + '.ranges'
2087
- ranges_file_new = (
2088
- self .root + ('' if self .root .endswith ('/' ) else '__' ) + 'full.yaml' )
2089
- for ranges_file in [ranges_file_classic , ranges_file_new ]:
2102
+ ranges_file_cobaya_old = (
2103
+ self .root + ('' if self .root .endswith ((os .sep , "/" )) else '__' ) + 'full.yaml' )
2104
+ ranges_file_cobaya = (
2105
+ self .root + (
2106
+ '' if self .root .endswith ((os .sep , "/" )) else _separator_files ) + 'updated.yaml' )
2107
+ for ranges_file in [
2108
+ ranges_file_classic , ranges_file_cobaya_old , ranges_file_cobaya ]:
2090
2109
if os .path .isfile (ranges_file ):
2091
2110
self .ranges = ParamBounds (ranges_file )
2092
2111
return
@@ -2553,9 +2572,9 @@ def GetChainRootFiles(rootdir):
2553
2572
"""
2554
2573
pattern = os .path .join (rootdir , '*.paramnames' )
2555
2574
files = [os .path .splitext (f )[0 ] for f in glob .glob (pattern )]
2556
- ending = 'full.yaml'
2557
- pattern = os .path .join (rootdir , "*" + ending )
2558
- files += [f [:- len (ending )].rstrip ("_" ) for f in glob .glob (pattern )]
2575
+ for ending in [ 'full.yaml' , 'updated.yaml' ]:
2576
+ pattern = os .path .join (rootdir , "*" + ending )
2577
+ files += [f [:- len (ending )].rstrip ("_. " ) for f in glob .glob (pattern )]
2559
2578
files .sort ()
2560
2579
return files
2561
2580
0 commit comments