{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# IODE and larray\n", "\n", "IODE offers many ways to interact with larray Array objects. \n", "\n", "Lets start with necessary imports and loading the sample data:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import larray as la\n", "\n", "from iode import (SAMPLE_DATA_DIR, comments, equations, identities, lists, scalars, \n", " tables, variables, Sample, NA)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Loading C:\\soft\\miniconda3\\envs\\py312\\Lib\\site-packages\\iode\\tests\\data/fun.cmt\n", "317 objects loaded\n", "Loading C:\\soft\\miniconda3\\envs\\py312\\Lib\\site-packages\\iode\\tests\\data/fun.eqs\n", "274 objects loaded\n", "Loading C:\\soft\\miniconda3\\envs\\py312\\Lib\\site-packages\\iode\\tests\\data/fun.idt\n", "48 objects loaded\n", "Loading C:\\soft\\miniconda3\\envs\\py312\\Lib\\site-packages\\iode\\tests\\data/fun.lst\n", "17 objects loaded\n", "Loading C:\\soft\\miniconda3\\envs\\py312\\Lib\\site-packages\\iode\\tests\\data/fun.scl\n", "161 objects loaded\n", "Loading C:\\soft\\miniconda3\\envs\\py312\\Lib\\site-packages\\iode\\tests\\data/fun.tbl\n", "46 objects loaded\n", "Loading C:\\soft\\miniconda3\\envs\\py312\\Lib\\site-packages\\iode\\tests\\data/fun.var\n", "394 objects loaded\n" ] }, { "data": { "text/plain": [ "(317, 274, 48, 17, 161, 46, 394)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# ---- load equations, identities, scalars and variables ----\n", "# Note: test binary and ASCII 'fun' files are located in the 'SAMPLE_DATA_DIR' \n", "# directory of the 'iode' package\n", "comments.load(f\"{SAMPLE_DATA_DIR}/fun.cmt\")\n", "equations.load(f\"{SAMPLE_DATA_DIR}/fun.eqs\")\n", "identities.load(f\"{SAMPLE_DATA_DIR}/fun.idt\")\n", "lists.load(f\"{SAMPLE_DATA_DIR}/fun.lst\")\n", "scalars.load(f\"{SAMPLE_DATA_DIR}/fun.scl\")\n", "tables.load(f\"{SAMPLE_DATA_DIR}/fun.tbl\")\n", "variables.load(f\"{SAMPLE_DATA_DIR}/fun.var\")\n", "\n", "# ---- print the number of objects present in the above workspaces ----\n", "len(comments), len(equations), len(identities), len(lists), len(scalars), len(tables), len(variables)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Add one variable:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Workspace: Variables\n", "nb variables: 1\n", "filename: c:\\soft\\miniconda3\\envs\\py312\\Lib\\site-packages\\iode\\tests\\data\\fun.var\n", "description: Modèle fun - Simulation 1 \n", "sample: 1960Y1:2015Y1\n", "mode: LEVEL\n", "\n", "name\t1960Y1\t1961Y1\t1962Y1\t1963Y1\t1964Y1\t1965Y1\t...\t2009Y1\t2010Y1\t2011Y1\t2012Y1\t2013Y1\t2014Y1\t2015Y1\n", "A4 \t na\t 1.00\t 2.00\t 3.00\t 4.00\t 5.00\t...\t 49.00\t 50.00\t 51.00\t 52.00\t 53.00\t 54.00\t na" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = list(range(variables.nb_periods))\n", "data[0] = NA\n", "data[-1] = np.nan\n", "time_axis = la.Axis(name=\"time\", labels=variables.periods_as_str)\n", "array = la.Array(data, axes=time_axis)\n", "\n", "variables[\"A4\"] = array\n", "variables[\"A4\"] " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Update one variable." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Update all values of a variable:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Workspace: Variables\n", "nb variables: 1\n", "filename: c:\\soft\\miniconda3\\envs\\py312\\Lib\\site-packages\\iode\\tests\\data\\fun.var\n", "description: Modèle fun - Simulation 1 \n", "sample: 1960Y1:2015Y1\n", "mode: LEVEL\n", "\n", "name\t1960Y1\t1961Y1\t1962Y1\t1963Y1\t1964Y1\t1965Y1\t...\t2009Y1\t2010Y1\t2011Y1\t2012Y1\t2013Y1\t2014Y1\t2015Y1\n", "AOUC\t na\t 1.00\t 2.00\t 3.00\t 4.00\t 5.00\t...\t 49.00\t 50.00\t 51.00\t 52.00\t 53.00\t 54.00\t na" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = list(range(variables.nb_periods))\n", "data[0] = NA\n", "data[-1] = np.nan\n", "time_axis = la.Axis(name=\"time\", labels=variables.periods_as_str)\n", "array = la.Array(data, axes=time_axis)\n", "\n", "variables[\"AOUC\"] = array\n", "variables[\"AOUC\"]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set the values for range of (contiguous) periods:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Workspace: Variables\n", "nb variables: 1\n", "filename: c:\\soft\\miniconda3\\envs\\py312\\Lib\\site-packages\\iode\\tests\\data\\fun.var\n", "description: Modèle fun - Simulation 1 \n", "sample: 1991Y1:1995Y1\n", "mode: LEVEL\n", "\n", "name\t1991Y1\t1992Y1\t1993Y1\t1994Y1\t1995Y1\n", "AOUC\t 1.00\t na\t 3.00\t na\t 5.00" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# variable[t:t+x] = la.Array(var_names, t:t+x)\n", "data = [1.0, NA, 3.0, np.nan, 5.0]\n", "periods = [\"1991Y1\", \"1992Y1\", \"1993Y1\", \"1994Y1\", \"1995Y1\"]\n", "time_axis = la.Axis(name=\"time\", labels=periods)\n", "array = la.Array(data, axes=time_axis)\n", "\n", "variables[\"AOUC\", \"1991Y1:1995Y1\"] = array\n", "variables[\"AOUC\", \"1991Y1:1995Y1\"]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Update multiple variables at once" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "names\\time 1991Y1 1992Y1 1993Y1 1994Y1 1995Y1\n", " ACAF 28.89 31.9 36.66 42.13 9.92\n", " ACAG nan -39.96 -42.88 -16.33 -41.16\n", " AOUC 1.023 nan 1.046 nan 1.064" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# using a larray Array\n", "data = [[28.89, 31.90, 36.66, 42.13, 9.92],\n", " [np.nan, -39.96, -42.88, -16.33, -41.16],\n", " [1.023, np.nan, 1.046, np.nan, 1.064]]\n", "periods = [\"1991Y1\", \"1992Y1\", \"1993Y1\", \"1994Y1\", \"1995Y1\"]\n", "\n", "names_axis = la.Axis(name=\"names\", labels=[\"ACAF\", \"ACAG\", \"AOUC\"])\n", "time_axis = la.Axis(name=\"time\", labels=periods)\n", "array = la.Array(data, axes=[names_axis, time_axis])\n", "array" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Workspace: Variables\n", "nb variables: 3\n", "filename: c:\\soft\\miniconda3\\envs\\py312\\Lib\\site-packages\\iode\\tests\\data\\fun.var\n", "description: Modèle fun - Simulation 1 \n", "sample: 1991Y1:1995Y1\n", "mode: LEVEL\n", "\n", "name\t1991Y1\t1992Y1\t1993Y1\t1994Y1\t1995Y1\n", "ACAF\t 28.89\t 31.90\t 36.66\t 42.13\t 9.92\n", "ACAG\t na\t-39.96\t-42.88\t-16.33\t-41.16\n", "AOUC\t 1.02\t na\t 1.05\t na\t 1.06" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "variables[\"ACAF, ACAG, AOUC\", \"1991Y1:1995Y1\"] = array\n", "variables[\"ACAF, ACAG, AOUC\", \"1991Y1:1995Y1\"]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Arithmetic Operations On Variables With larray Array objects\n", "\n", "IODE variables can be used in arithmetic operations with larray Array objects.\n", "\n", "Let's first reload the variables database to start from a clean state. \n", "Then we will select a subset of variables for the examples below:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Loading C:\\soft\\miniconda3\\envs\\py312\\Lib\\site-packages\\iode\\tests\\data/fun.var\n", "394 objects loaded\n" ] }, { "data": { "text/plain": [ "Workspace: Variables\n", "nb variables: 5\n", "filename: c:\\soft\\miniconda3\\envs\\py312\\Lib\\site-packages\\iode\\tests\\data\\fun.var\n", "description: Modèle fun - Simulation 1 \n", "sample: 1991Y1:1995Y1\n", "mode: LEVEL\n", "\n", " name\t1991Y1\t1992Y1\t1993Y1\t1994Y1\t1995Y1\n", "ACAF \t 26.24\t 30.16\t 34.66\t 8.16\t-13.13\n", "ACAG \t-30.93\t-40.29\t-43.16\t-16.03\t-41.85\n", "AOUC \t 1.02\t 1.03\t 1.03\t 1.05\t 1.05\n", "AOUC_\t 0.96\t 0.97\t 0.98\t 0.99\t 1.00\n", "AQC \t 1.06\t 1.11\t 1.15\t 1.16\t 1.16" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# reload variables to start from a clean state\n", "variables.load(f\"{SAMPLE_DATA_DIR}/fun.var\")\n", "\n", "# select a subset of variables for the examples below\n", "vars_subset = variables[\"A*\", \"1991Y1:1995Y1\"]\n", "vars_subset" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "time 1991Y1 1992Y1 1993Y1 1994Y1 1995Y1\n", " 2.0 3.0 4.0 5.0 6.0" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = [2.0, 3.0, 4.0, 5.0, 6.0]\n", "time_axis = la.Axis(name=\"time\", labels=vars_subset.periods_as_str)\n", "array = la.Array(data, axes=time_axis)\n", "array" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Workspace: Variables\n", "nb variables: 1\n", "filename: c:\\soft\\miniconda3\\envs\\py312\\Lib\\site-packages\\iode\\tests\\data\\fun.var\n", "description: Modèle fun - Simulation 1 \n", "sample: 1991Y1:1995Y1\n", "mode: LEVEL\n", "\n", "name\t1991Y1\t1992Y1\t1993Y1\t1994Y1\t1995Y1\n", "ACAF\t 24.24\t 27.16\t 30.66\t 3.16\t-19.13" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# subtract the values of an larray Array object\n", "# from the values of a single variable \n", "updated_ACAF = vars_subset[\"ACAF\"] - array\n", "updated_ACAF" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "names\\time 1995Y1\n", " ACAF 2.0\n", " ACAG 3.0\n", " AOUC 4.0\n", " AOUC_ 5.0\n", " AQC 6.0" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = [[2.0], [3.0], [4.0], [5.0], [6.0]]\n", "names_axis = la.Axis(name=\"names\", labels=vars_subset.names)\n", "time_axis = la.Axis(name=\"time\", labels=[\"1995Y1\"])\n", "array = la.Array(data, axes=[names_axis, time_axis])\n", "array" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Workspace: Variables\n", "nb variables: 5\n", "filename: c:\\soft\\miniconda3\\envs\\py312\\Lib\\site-packages\\iode\\tests\\data\\fun.var\n", "description: Modèle fun - Simulation 1 \n", "sample: 1995Y1:1995Y1\n", "mode: LEVEL\n", "\n", " name\t1995Y1\n", "ACAF \t-15.13\n", "ACAG \t-44.85\n", "AOUC \t -2.95\n", "AOUC_\t -4.00\n", "AQC \t -4.84" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# subtract the values of an larray Array object from the values \n", "# of a subset corresponding to a single period\n", "vars_subset_1995Y1 = vars_subset[:, \"1995Y1\"] - array\n", "vars_subset_1995Y1" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "names\\time 1991Y1 1992Y1 1993Y1 1994Y1 1995Y1\n", " ACAF 1.0 2.0 3.0 4.0 5.0\n", " ACAG 6.0 7.0 8.0 9.0 10.0\n", " AOUC 11.0 12.0 13.0 14.0 15.0\n", " AOUC_ 16.0 17.0 18.0 19.0 20.0\n", " AQC 21.0 22.0 23.0 24.0 25.0" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# define the larray Array object to be used in the example below\n", "data = np.array([[1.0, 2.0, 3.0, 4.0, 5.0],\n", " [6.0, 7.0, 8.0, 9.0, 10.0],\n", " [11.0, 12.0, 13.0, 14.0, 15.0],\n", " [16.0, 17.0, 18.0, 19.0, 20.0],\n", " [21.0, 22.0, 23.0, 24.0, 25.0]])\n", "names_axis = la.Axis(name=\"names\", labels=vars_subset.names)\n", "time_axis = la.Axis(name=\"time\", labels=vars_subset.periods_as_str)\n", "array = la.Array(data, axes=[names_axis, time_axis])\n", "array" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Workspace: Variables\n", "nb variables: 5\n", "filename: c:\\soft\\miniconda3\\envs\\py312\\Lib\\site-packages\\iode\\tests\\data\\fun.var\n", "description: Modèle fun - Simulation 1 \n", "sample: 1991Y1:1995Y1\n", "mode: LEVEL\n", "\n", " name\t1991Y1\t1992Y1\t1993Y1\t1994Y1\t1995Y1\n", "ACAF \t 25.24\t 28.16\t 31.66\t 4.16\t-18.13\n", "ACAG \t-36.93\t-47.29\t-51.16\t-25.03\t-51.85\n", "AOUC \t -9.98\t-10.97\t-11.97\t-12.95\t-13.95\n", "AOUC_\t-15.04\t-16.03\t-17.02\t-18.01\t-19.00\n", "AQC \t-19.94\t-20.89\t-21.85\t-22.84\t-23.84" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# subtract the values of na larray Array object \n", "# from the values of a subset of variables \n", "new_vars_subset = vars_subset - array\n", "new_vars_subset" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Import/Export the Variables workspace from/to LArray Array\n", "\n", "To import / export the content of the `variables` workspaces from/to a LArray Array object, use the [from_array()](../_generated/iode.Variables.from_array.rst#iode.Variables.from_array) and [to_array()](../_generated/iode.Variables.to_array.rst#iode.Variables.to_array) methods:" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Variables as LArray Array:\n", "394 x 56\n", " names [394]: 'ACAF' 'ACAG' 'AOUC' ... 'ZKFO' 'ZX' 'ZZF_'\n", " time [56]: '1960Y1' '1961Y1' '1962Y1' ... '2013Y1' '2014Y1' '2015Y1'\n", "dtype: float64\n", "memory used: 172.38 Kb\n" ] } ], "source": [ "# ---- to LArray Array ----\n", "# See Variables.to_array\n", "\n", "arr_vars = variables.to_array()\n", "print(f\"Variables as LArray Array:\\n{arr_vars.info}\")\n", "\n", "# ---- from LArray array ----\n", "# See Variables.from_array\n", "\n", "variables.from_array(arr_vars)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It possible to export a subset of the IODE databases:" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Workspace: Variables\n", "nb variables: 33\n", "filename: c:\\soft\\miniconda3\\envs\\py312\\Lib\\site-packages\\iode\\tests\\data\\fun.var\n", "description: Modèle fun - Simulation 1 \n", "sample: 2000Y1:2010Y1\n", "mode: LEVEL\n", "\n", " name\t 2000Y1\t 2001Y1\t 2002Y1\t 2003Y1\t 2004Y1\t 2005Y1\t 2006Y1\t 2007Y1\t 2008Y1 \t 2009Y1 \t 2010Y1 \n", "ACAF \t 10.05\t 2.87\t -0.93\t -6.09\t -14.58\t -26.54\t -28.99\t -33.38\t -38.41\t -37.46\t -37.83\n", "ACAG \t -41.53\t 18.94\t 19.98\t 21.02\t 22.07\t 23.11\t 24.13\t 25.16\t 26.19\t 27.23\t 28.25\n", "AOUC \t 1.12\t 1.14\t 1.16\t 1.17\t 1.17\t 1.18\t 1.20\t 1.22\t 1.26\t 1.29\t 1.31\n", "AOUC_\t 1.10\t 1.14\t 1.15\t 1.16\t 1.15\t 1.16\t 1.19\t 1.20\t 1.21\t 1.23\t 1.25\n", "AQC \t 1.34\t 1.38\t 1.41\t 1.42\t 1.40\t 1.40\t 1.40\t 1.41\t 1.43\t 1.45\t 1.46\n", "... \t ...\t ...\t ...\t ...\t ...\t ...\t ...\t ...\t ...\t ...\t ...\n", "WCF_ \t3716.45\t3863.90\t3999.57\t4147.95\t4242.58\t4320.97\t4463.72\t4665.91\t 4916.65\t 5042.74\t 5170.60\n", "WIND_\t1000.14\t1035.22\t1070.93\t1102.91\t1115.33\t1124.07\t1144.27\t1178.12\t 1231.49\t 1268.86\t 1301.03\n", "WNF_ \t2334.76\t2427.49\t2512.87\t2606.28\t2665.82\t2715.11\t2804.93\t2932.23\t 3089.99\t 3169.32\t 3249.75\n", "YDH_ \t7276.61\t7635.91\t7958.39\t8331.07\t8653.40\t8950.54\t9299.54\t9685.61\t10228.84\t10630.74\t10995.83\n", "ZZF_ \t 0.69\t 0.69\t 0.69\t 0.69\t 0.69\t 0.69\t 0.69\t 0.69\t 0.69\t 0.69\t 0.69" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# export a subset of the IODE Variables database as a LArray Array\n", "vars_subset = variables[\"A*;*_\", \"2000Y1:2010Y1\"]\n", "vars_subset" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(33, 11)" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "array = vars_subset.to_array()\n", "array.shape" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "names\\time 2000Y1 ... 2010Y1\n", " ACAF 10.046610792200543 ... -37.82742883229439\n", " ACAG -41.53478656734795 ... 28.253928978210485\n", " AOUC 1.1162376230972206 ... 1.3071099004906368\n", " AOUC_ 1.10195719812178 ... 1.2501643331956398\n", " AQC 1.3386028553645442 ... 1.4628683697450802\n", " GAP_ 4.510095736743436 ... 3.376524129115177\n", " GOSH_ 1957.0895201725107 ... 2834.234071582971\n", " PAF_ 1.1974908430779156 ... 1.343502315992764\n", " PC_ 1.2347266809771256 ... 1.4948195858546014\n", " PFI_ 1.073515977227475 ... 1.2922777989010075\n", " PROIHP_ 1.1054128 ... 0.95035726\n", " QAFF_ 5748.518880218095 ... 6973.598752540967\n", " QAF_ 4785.221048752499 ... 5936.55814807025\n", " QAI_ 963.2971444232843 ... 1036.991862780098\n", " QAT_ 7184.569798738995 ... 8726.21701183414\n", " QBBPPOT_ 7655.481802392836 ... 9605.212225913185\n", " QC_ 4855.41327831261 ... 5889.766110465185\n", " QQMAB_ 5180.218215045446 ... 6936.181730632514\n", " QS_ -35.212024420768714 ... -35.212024420768714\n", " TFPFHP_ 0.993773299183911 ... 1.0977439739214365\n", " VAFF_ 6883.859391184664 ... 9369.040711615937\n", " VAF_ 5730.319881574676 ... 7975.839742305225\n", " VAI_ 1153.535694715543 ... 1393.1903508914916\n", " VAT_ 8880.730664031325 ... 12525.5814075134\n", " VC_ 5995.108321903193 ... 8804.137738026035\n", " VS_ 16.860422365860263 ... 10.939949669199798\n", " WBF_ 2693.7277691578774 ... 3747.687848793519\n", " WBU_ 5074.19063621057 ... 7283.594651285259\n", " WCF_ 3716.4475089520292 ... 5170.600010384268\n", " WIND_ 1000.1445769794319 ... 1301.025126372868\n", " WNF_ 2334.7636275081923 ... 3249.7517024908175\n", " YDH_ 7276.607740221424 ... 10995.831392939246\n", " ZZF_ 0.68840039 ... 0.68840039" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "array" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For the `variables` workspace, the [to_array()](../_generated/iode.Variables.to_array.rst#iode.Variables.to_array) method have additional arguments. For instance, the `periods_as_type` argument allows to export the periods as a specific type. The `periods_as_type` argument can be one of the following: `str`, `int` or `float`. The default value is `str`:" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "names\\years 2000 ... 2010\n", " ACAF 10.046610792200543 ... -37.82742883229439\n", " ACAG -41.53478656734795 ... 28.253928978210485\n", " AOUC 1.1162376230972206 ... 1.3071099004906368\n", " AOUC_ 1.10195719812178 ... 1.2501643331956398\n", " AQC 1.3386028553645442 ... 1.4628683697450802\n", " GAP_ 4.510095736743436 ... 3.376524129115177\n", " GOSH_ 1957.0895201725107 ... 2834.234071582971\n", " PAF_ 1.1974908430779156 ... 1.343502315992764\n", " PC_ 1.2347266809771256 ... 1.4948195858546014\n", " PFI_ 1.073515977227475 ... 1.2922777989010075\n", " PROIHP_ 1.1054128 ... 0.95035726\n", " QAFF_ 5748.518880218095 ... 6973.598752540967\n", " QAF_ 4785.221048752499 ... 5936.55814807025\n", " QAI_ 963.2971444232843 ... 1036.991862780098\n", " QAT_ 7184.569798738995 ... 8726.21701183414\n", " QBBPPOT_ 7655.481802392836 ... 9605.212225913185\n", " QC_ 4855.41327831261 ... 5889.766110465185\n", " QQMAB_ 5180.218215045446 ... 6936.181730632514\n", " QS_ -35.212024420768714 ... -35.212024420768714\n", " TFPFHP_ 0.993773299183911 ... 1.0977439739214365\n", " VAFF_ 6883.859391184664 ... 9369.040711615937\n", " VAF_ 5730.319881574676 ... 7975.839742305225\n", " VAI_ 1153.535694715543 ... 1393.1903508914916\n", " VAT_ 8880.730664031325 ... 12525.5814075134\n", " VC_ 5995.108321903193 ... 8804.137738026035\n", " VS_ 16.860422365860263 ... 10.939949669199798\n", " WBF_ 2693.7277691578774 ... 3747.687848793519\n", " WBU_ 5074.19063621057 ... 7283.594651285259\n", " WCF_ 3716.4475089520292 ... 5170.600010384268\n", " WIND_ 1000.1445769794319 ... 1301.025126372868\n", " WNF_ 2334.7636275081923 ... 3249.7517024908175\n", " YDH_ 7276.607740221424 ... 10995.831392939246\n", " ZZF_ 0.68840039 ... 0.68840039" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "array = vars_subset.to_array(time_axis_name=\"years\", periods_as_type=int)\n", "array" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It is also possible to import a subset of the IODE databases:" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "names\\time 1990Y1 1991Y1 1992Y1 1993Y1 1994Y1 1995Y1\n", " ACAF 0.0 1.0 2.0 3.0 4.0 5.0\n", " ACAG 6.0 7.0 8.0 9.0 10.0 11.0\n", " AOUC 12.0 13.0 14.0 15.0 16.0 17.0\n", " AOUC_ 18.0 19.0 20.0 21.0 22.0 23.0\n", " AQC 24.0 25.0 26.0 27.0 28.0 29.0\n", " AX 30.0 31.0 32.0 33.0 34.0 35.0" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# existing variables\n", "names = variables.get_names(\"A*\")\n", "# new variables\n", "names += [\"AX\"]\n", "periods = [\"1990Y1\", \"1991Y1\", \"1992Y1\", \"1993Y1\", \"1994Y1\", \"1995Y1\"]\n", "data = [[0.0, 1.0, 2.0, 3.0, 4.0, 5.0], \n", " [6.0, 7.0, 8.0, 9.0, 10.0, 11.0], \n", " [12.0, 13.0, 14.0, 15.0, 16.0, 17.0], \n", " [18.0, 19.0, 20.0, 21.0, 22.0, 23.0],\n", " [24.0, 25.0, 26.0, 27.0, 28.0, 29.0], \n", " [30.0, 31.0, 32.0, 33.0, 34.0, 35.0]]\n", "names_axis = la.Axis(name=\"names\", labels=names)\n", "time_axis = la.Axis(name=\"time\", labels=periods)\n", "array = la.Array(data, axes=[names_axis, time_axis])\n", "array" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Workspace: Variables\n", "nb variables: 10\n", "filename: c:\\soft\\miniconda3\\envs\\py312\\Lib\\site-packages\\iode\\tests\\data\\fun.var\n", "description: Modèle fun - Simulation 1 \n", "sample: 1988Y1:1997Y1\n", "mode: LEVEL\n", "\n", " name\t1988Y1\t1989Y1\t1990Y1\t1991Y1\t1992Y1\t1993Y1\t1994Y1\t1995Y1\t1996Y1\t1997Y1\n", "ACAF \t 25.35\t 17.17\t 0.00\t 1.00\t 2.00\t 3.00\t 4.00\t 5.00\t 32.17\t 39.94\n", "ACAG \t-37.24\t-25.99\t 6.00\t 7.00\t 8.00\t 9.00\t 10.00\t 11.00\t-40.24\t-32.93\n", "AOUC \t 0.95\t 0.98\t 12.00\t 13.00\t 14.00\t 15.00\t 16.00\t 17.00\t 1.05\t 1.08\n", "AOUC_\t 0.88\t 0.91\t 18.00\t 19.00\t 20.00\t 21.00\t 22.00\t 23.00\t 1.00\t 1.03\n", "AQC \t 0.93\t 0.94\t 24.00\t 25.00\t 26.00\t 27.00\t 28.00\t 29.00\t 1.16\t 1.20\n", "AX \t na\t na\t 30.00\t 31.00\t 32.00\t 33.00\t 34.00\t 35.00\t na\t na\n", "BENEF\t281.77\t345.16\t284.18\t197.60\t194.04\t197.24\t231.75\t286.67\t340.56\t348.32\n", "BQY \t-20.18\t-11.33\t-34.10\t -1.26\t-13.75\t 52.16\t 66.63\t 91.09\t104.68\t113.52\n", "BRUGP\t 44.67\t 45.09\t 0.00\t 49.77\t 52.58\t 51.70\t 52.06\t 52.20\t 52.70\t 52.85\n", "BVY \t-18.70\t-10.99\t-34.10\t -1.30\t-14.70\t 58.10\t 75.90\t105.50\t123.20\t135.62" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# note that the new variable 'AX' has been added with NA values \n", "# for the periods present in the Variables sample but not in the Array\n", "variables.from_array(array)\n", "variables[\"A*;B*\", \"1988Y1:1997Y1\"]" ] } ], "metadata": { "kernelspec": { "display_name": "py312", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.9" } }, "nbformat": 4, "nbformat_minor": 2 }