@@ -43,7 +43,8 @@ def __init__(self, *args, **kwargs):
43
43
def read_idata (
44
44
self , mdl : BasePYMCModel = None , fn : str = "" , ** kwargs
45
45
) -> az .InferenceData :
46
- """Read InferenceData using mdl.mdl_id_fn + txtadd, or from fn"""
46
+ """Read InferenceData appropriate to a built model using
47
+ mdl.mdl_id_fn + txtadd, or from fn"""
47
48
txtadd = kwargs .pop ("txtadd" , None )
48
49
if mdl is not None :
49
50
fn = "_" .join (filter (None , ["idata" , mdl .mdl_id_fn , txtadd ]))
@@ -52,14 +53,22 @@ def read_idata(
52
53
_log .info (f"Read model idata from { str (fqn .resolve ())} " )
53
54
return idata
54
55
55
- def write_idata (self , mdl : BasePYMCModel , fn : str = "" , ** kwargs ) -> Path :
56
- """Accept BasePYMCModel object write to InferenceData using
57
- mdl.mdl_id_fn + txtadd"""
56
+ def write_idata (
57
+ self , mdl : BasePYMCModel , idata : az .InferenceData = None , fn : str = "" , ** kwargs
58
+ ) -> Path :
59
+ """Accept BasePYMCModel object with attached in-sample idata, and write
60
+ to netcdf file with name mdl.mdl_id_fn + txtadd. Optionally use this to
61
+ write out-of-sample InferenceData passed as idata kwarg. Can implicitly
62
+ use mdl.mdl_id_fn in either case"""
58
63
txtadd = kwargs .pop ("txtadd" , None )
59
64
if fn == "" :
60
65
fn = "_" .join (filter (None , ["idata" , mdl .mdl_id_fn , txtadd ]))
61
66
fqn = self .get_path_write (Path (self .snl .clean (fn )).with_suffix (".netcdf" ))
62
- mdl .idata .to_netcdf (str (fqn .resolve ()))
67
+
68
+ if idata is not None :
69
+ idata .to_netcdf (str (fqn .resolve ()))
70
+ else :
71
+ mdl .idata .to_netcdf (str (fqn .resolve ()))
63
72
_log .info (f"Written to { str (fqn .resolve ())} " )
64
73
return fqn
65
74
0 commit comments