{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "title",
   "metadata": {},
   "source": [
    "# GLORIA parser walkthrough\n",
    "\n",
    "This notebook is the practical guide for parsing GLORIA monetary SUT releases in MARIO."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "covers",
   "metadata": {},
   "source": [
    "## What this notebook covers\n",
    "\n",
    "- where the GLORIA release material comes from;\n",
    "- how the local GLORIA release should be laid out on disk;\n",
    "- when to pass the release root, the `part_I` folder, or the `GLORIA_MRIOs_*` directory directly;\n",
    "- how `valuation=`, `regions=`, and `satellites=` change the parse;\n",
    "- why `dtype` and `cache` matter for large GLORIA runs."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "sources",
   "metadata": {},
   "source": [
    "## Relevant source pages\n",
    "\n",
    "- GLORIA overview: [IELab GLORIA overview](https://ielab.info/resources/gloria/about)\n",
    "- release notes and supporting material: [IELab GLORIA supporting documents](https://ielab.info/resources/gloria/supportingdocs)\n",
    "\n",
    "MARIO does not download GLORIA automatically. The expected workflow is to obtain the release locally and then point the parser to the release root, to the `part_I` economic-account folder, or directly to the `GLORIA_MRIOs_*` directory."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "entry-point",
   "metadata": {},
   "source": [
    "## Main entry point\n",
    "\n",
    "For normal user workflows, the public entry point is:\n",
    "\n",
    "- `mario.parse_gloria(...)`\n",
    "\n",
    "The current backend supports monetary `SUT` parsing only."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "key-arguments",
   "metadata": {},
   "source": [
    "## Key arguments\n",
    "\n",
    "The key public arguments are:\n",
    "\n",
    "- `path`: GLORIA release root, the Google Drive `part_I` economic-account folder, or directly the `GLORIA_MRIOs_*` directory;\n",
    "- `table`: currently only `\"SUT\"` is supported;\n",
    "- `valuation`: choose one markup branch such as `basic`, `trade`, `transport`, `taxes`, or `subsidies`;\n",
    "- `year`: used when the selected root contains more than one GLORIA year;\n",
    "- `regions`: optional subset of GLORIA region acronyms;\n",
    "- `satellites`: optional satellite group or row selector;\n",
    "- `dtype`: numeric storage type, with `float32` as the practical default;\n",
    "- `cache`: `True` or one explicit path to persist the parsed result."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "local-layout",
   "metadata": {},
   "source": [
    "## Local layout expectation\n",
    "\n",
    "The parser supports two local layouts.\n",
    "\n",
    "Compact layout:\n",
    "\n",
    "- one `GLORIA_MRIOs_*` directory with raw `T`, `Y`, and `V` csv files;\n",
    "- the matching `GLORIA_ReadMe_*.xlsx` workbook next to that dataset;\n",
    "- optionally, one matching `GLORIA_SatelliteAccounts_*` directory.\n",
    "\n",
    "Google Drive layout:\n",
    "\n",
    "- one `GLORIA_MRIO_Loop*_part_I_MRIOdatabase` folder containing the economic-account dataset;\n",
    "- one `GLORIA_MRIO_Loop*_part_III_satelliteaccounts` folder containing satellite accounts;\n",
    "- the matching `GLORIA_ReadMe_*.xlsx` workbook under the same release root.\n",
    "\n",
    "You can point MARIO to the release root, the `part_I` folder, or directly to one `GLORIA_MRIOs_*` directory."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "import-mario",
   "metadata": {},
   "outputs": [],
   "source": [
    "import mario"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "parse-basic",
   "metadata": {},
   "source": [
    "## Parse one GLORIA SUT\n",
    "\n",
    "Use this when you want the default `basic` valuation and the full region set."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "parse-basic-code",
   "metadata": {},
   "outputs": [],
   "source": [
    "db = mario.parse_gloria(\n",
    "    path=\"/path/to/GLORIA\",\n",
    "    year=2023,\n",
    ")\n",
    "\n",
    "db"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "satellites",
   "metadata": {},
   "source": [
    "## Restrict the satellite payload\n",
    "\n",
    "You can keep all satellites, one full row label, or one group name from the GLORIA ReadMe."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "satellites-code",
   "metadata": {},
   "outputs": [],
   "source": [
    "db = mario.parse_gloria(\n",
    "    path=\"/path/to/GLORIA\",\n",
    "    satellites=\"Emissions\",\n",
    "    year = 2023,\n",
    ")\n",
    "\n",
    "db"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "warnings",
   "metadata": {},
   "source": [
    "## Practical warnings\n",
    "\n",
    "- `GLORIA` is currently `SUT`-only in MARIO.\n",
    "- Full-region parses can be memory-intensive; `regions=`, `dtype=\"float32\"`, and `cache=True` are usually sensible defaults.\n",
    "- If the local release does not include a complete satellite-account directory, MARIO falls back to empty extensions."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "mario",
   "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.13.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
