iode.Variables.to_array
- Variables.to_array(self, vars_axis_name: str = 'names', time_axis_name: str = 'time', sample_as_floats: bool = False) Array
Creates an Array from the current IODE Variables database.
- Parameters:
- vars_axis_name: str, optional
Name of the axis representing the Variables names. Defaults to ‘names’.
- time_axis_name: str, optional
Name of the axis representing the periods. Defaults to ‘time’.
- sample_as_floats: bool, optional
Whether or not to convert periods as float values. Defaults to False (periods are exported as string values).
Warning
IODE and LArray don’t use the same constant to represent NaN values. When exporting IODE variables as a LArray Array, the IODE NaN values (\(NA\)) are converted to LArray NaN values (\(nan\)).
Examples
>>> from iode import SAMPLE_DATA_DIR >>> from iode import variables >>> variables.load(f"{SAMPLE_DATA_DIR}/fun.var") >>> len(variables) 394 >>> variables.sample '1960Y1:2015Y1' >>> variables.nb_periods 56
>>> # Export the IODE Variables database as an (larray) Array object >>> array = variables.to_array() >>> array.shape (394, 56) >>> array.axes.info 394 x 56 names [394]: 'ACAF' 'ACAG' 'AOUC' ... 'ZKFO' 'ZX' 'ZZF_' time [56]: '1960Y1' '1961Y1' '1962Y1' ... '2013Y1' '2014Y1' '2015Y1' >>> variables["AOUC"] [nan, 0.24783191606766575, ..., 1.4237139558484628, 1.4608626117037322] >>> array["AOUC"] time 1960Y1 ... 2014Y1 2015Y1 nan ... 1.4237139558484628 1.4608626117037322 >>> variables["ZKFO"] [1.0, 1.0, ..., 1.0159901, 1.0159901] >>> array["ZKFO"] time 1960Y1 1961Y1 1962Y1 ... 2012Y1 2013Y1 2014Y1 2015Y1 1.0 1.0 1.0 ... 1.0159901 1.0159901 1.0159901 1.0159901
>>> # Export a subset of the IODE Variables database as an (larray) Array object >>> array = variables["A*;*_"].to_array() >>> array.shape (33, 56) >>> array.axes.info 33 x 56 names [33]: 'ACAF' 'ACAG' 'AOUC' ... 'WNF_' 'YDH_' 'ZZF_' time [56]: '1960Y1' '1961Y1' '1962Y1' ... '2013Y1' '2014Y1' '2015Y1' >>> variables["AOUC"] [nan, 0.24783191606766575, ..., 1.4237139558484628, 1.4608626117037322] >>> array["AOUC"] time 1960Y1 ... 2014Y1 2015Y1 nan ... 1.4237139558484628 1.4608626117037322 >>> variables["ZZF_"] [0.68840039, 0.68840039, ..., 0.68840039, 0.68840039] >>> array["ZZF_"] time 1960Y1 1961Y1 ... 2013Y1 2014Y1 2015Y1 0.68840039 0.68840039 ... 0.68840039 0.68840039 0.68840039