File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 88from typing import Any , Union
99
1010import numpy as np
11+ import xarray as xr
1112
1213AlternativeValueType = Union [str , int , float , tuple [str ]]
1314
@@ -151,6 +152,22 @@ def __iter__(self):
151152 if a .weight > 0 :
152153 yield Realization (self .name , a .value , a .weight , a .params )
153154
155+ def to_xarray (self , dim_name : str , name : str = "" ) -> xr .DataArray :
156+ """
157+ Convert the node to a numpy array.
158+
159+ Returns
160+ -------
161+ xr.DataArray
162+ A dataarray of the alternative values.
163+ """
164+ return xr .DataArray (
165+ np .array ([a .weight for a in self .alts ]),
166+ dims = (dim_name ,),
167+ coords = {dim_name : [a .value for a in self .alts ]},
168+ name = name ,
169+ )
170+
154171 @property
155172 def options (self ):
156173 """
You can’t perform that action at this time.
0 commit comments