iode.Variables.from_array

Variables.from_array(self, array: Array, time_axis_name: str = 'time', sep: str = '_')

Copies the Array array into the IODE Variables database.

If the passed array has more than two dimensions, the non-time axes are grouped (with ‘sep’ as separator) to form the Variables names.

Parameters:
array: Array

Input Array object.

time_axis_name: str, optional

Name of the time axis in array. Assumed to be ‘time’ by default.

sep: str, optional

If the ‘array’ as more than two axes, the separator ‘sep’ is used to group labels of the non-time axes.

Warning

IODE and LArray don’t use the same constant to represent NaN values. When loading a LArray Array into the Variables database, the LArray NaN values (\(nan\)) are converted to IODE NaN values (\(NA\)).

Examples

>>> from iode import variables
>>> import larray as la
>>> import numpy as np
>>> variables.clear()
>>> len(variables)
0
>>> regions_axis = la.Axis("region=VLA,WAL,BXL")
>>> code_axis = la.Axis("code=00..02")
>>> periods_axis = la.Axis("time=1960Y1..1970Y1")
>>> array = la.ndtest((regions_axis, code_axis, periods_axis), dtype=float)
>>> array
region  code\time  1960Y1  1961Y1  1962Y1  ...  1968Y1  1969Y1  1970Y1
   VLA         00     0.0     1.0     2.0  ...     8.0     9.0    10.0
   VLA         01    11.0    12.0    13.0  ...    19.0    20.0    21.0
   VLA         02    22.0    23.0    24.0  ...    30.0    31.0    32.0
   WAL         00    33.0    34.0    35.0  ...    41.0    42.0    43.0
   WAL         01    44.0    45.0    46.0  ...    52.0    53.0    54.0
   WAL         02    55.0    56.0    57.0  ...    63.0    64.0    65.0
   BXL         00    66.0    67.0    68.0  ...    74.0    75.0    76.0
   BXL         01    77.0    78.0    79.0  ...    85.0    86.0    87.0
   BXL         02    88.0    89.0    90.0  ...    96.0    97.0    98.0
>>> # load the IODE Variables from the Array object
>>> variables.from_array(array)
>>> len(variables)
9
>>> variables.names
['BXL_00', 'BXL_01', 'BXL_02', 'VLA_00', 'VLA_01', 'VLA_02', 'WAL_00', 'WAL_01', 'WAL_02']
>>> variables.sample
'1960Y1:1970Y1'
>>> variables["VLA_00"]
[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
>>> variables["BXL_02"]
[88.0, 89.0, 90.0, 91.0, 92.0, 93.0, 94.0, 95.0, 96.0, 97.0, 98.0]