{ "cells": [ { "cell_type": "markdown", "id": "dffd70cd-400c-4634-afb7-2afdf7f23209", "metadata": {}, "source": [ "# Flatten daily or monthly ERA5 files and select only glaciated gridpoints \n", "\n", "--> currently from 1940-01 to 2025-10, but only applied the flattening until end of 2024\n", "\n", "\n", "In `/home/www/lschuster/example_ipynb/flatten_glacier_gridpoint_tests_2025_6_new_isimip3b.ipynb`, we check if the flattening approach works as it should. \n", "\n", "- todo:\n", " - create a workflow that directly checks how much got downloaded and appends the missing months ...? (eventually even starts a script to download the missing files until now) \n", " - check if the files can be easily incorporated into existing OGGM methods/functions ... " ] }, { "cell_type": "code", "execution_count": 7, "id": "83acffa7-6af9-402e-92df-a24ccd179136", "metadata": {}, "outputs": [], "source": [ "import xarray as xr\n", "import numpy as np\n", "import pandas as pd\n", "from oggm import utils\n", "\n", "import sys\n", "import matplotlib.pyplot as plt\n", "import os\n", "import glob\n" ] }, { "cell_type": "code", "execution_count": 12, "id": "5299a1f3-1437-47bc-bdda-871264d1f807", "metadata": {}, "outputs": [], "source": [ "resolution = 'Monthly' # Choose here Monthly ... \n", "y0 = 1940\n", "y1 = 2024 #2024" ] }, { "cell_type": "code", "execution_count": 13, "id": "01468527-fe7e-48f0-a8ef-9e0353c3e506", "metadata": {}, "outputs": [], "source": [ "path = '/home/www/oggm/climate/wip/era5_both/'" ] }, { "cell_type": "code", "execution_count": 22, "id": "66111ca4-786c-4c61-8d32-da60c4de7831", "metadata": {}, "outputs": [ { "ename": "ValueError", "evalue": "These variables cannot be found in this dataset: ['tp']", "output_type": "error", "traceback": [ "\u001b[31m---------------------------------------------------------------------------\u001b[39m", "\u001b[31mValueError\u001b[39m Traceback (most recent call last)", "\u001b[32m/tmp/ipykernel_2455618/230978556.py\u001b[39m in \u001b[36m?\u001b[39m\u001b[34m()\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m dsifs = dsifs.drop_vars(var)\n\u001b[32m 2\u001b[39m dsifs = dsifs.drop_vars([\u001b[33m'number'\u001b[39m,\u001b[33m'expver'\u001b[39m]) \u001b[38;5;66;03m# valid_time\u001b[39;00m\n", "\u001b[32m~/mambaforge/envs/oggm_env_2025/lib/python3.11/site-packages/xarray/core/dataset.py\u001b[39m in \u001b[36m?\u001b[39m\u001b[34m(self, names, errors)\u001b[39m\n\u001b[32m 5873\u001b[39m names_set = {names}\n\u001b[32m 5874\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m 5875\u001b[39m names_set = set(names)\n\u001b[32m 5876\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m errors == \u001b[33m\"raise\"\u001b[39m:\n\u001b[32m-> \u001b[39m\u001b[32m5877\u001b[39m self._assert_all_in_dataset(names_set)\n\u001b[32m 5878\u001b[39m \n\u001b[32m 5879\u001b[39m \u001b[38;5;66;03m# GH6505\u001b[39;00m\n\u001b[32m 5880\u001b[39m other_names = set()\n", "\u001b[32m~/mambaforge/envs/oggm_env_2025/lib/python3.11/site-packages/xarray/core/dataset.py\u001b[39m in \u001b[36m?\u001b[39m\u001b[34m(self, names, virtual_okay)\u001b[39m\n\u001b[32m 5737\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m virtual_okay:\n\u001b[32m 5738\u001b[39m bad_names -= self.virtual_variables\n\u001b[32m 5739\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m bad_names:\n\u001b[32m 5740\u001b[39m ordered_bad_names = [name \u001b[38;5;28;01mfor\u001b[39;00m name \u001b[38;5;28;01min\u001b[39;00m names \u001b[38;5;28;01mif\u001b[39;00m name \u001b[38;5;28;01min\u001b[39;00m bad_names]\n\u001b[32m-> \u001b[39m\u001b[32m5741\u001b[39m raise ValueError(\n\u001b[32m 5742\u001b[39m \u001b[33mf\"These variables cannot be found in this dataset: {ordered_bad_names}\"\u001b[39m\n\u001b[32m 5743\u001b[39m )\n", "\u001b[31mValueError\u001b[39m: These variables cannot be found in this dataset: ['tp']" ] } ], "source": [ " dsifs = dsifs.drop_vars(var)\n", " dsifs = dsifs.drop_vars(['number','expver']) # valid_time" ] }, { "cell_type": "code", "execution_count": 21, "id": "115ef3c4-2b7e-4755-9c56-ce2633a8718d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset> Size: 271kB\n",
"Dimensions: (time: 1, points: 11293)\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 8B 1940-01-01T06:00:00\n",
" number int64 8B 0\n",
" expver (time) <U4 16B '0001'\n",
" valid_time datetime64[ns] 8B 2020-01-01\n",
" latitude (points) float64 90kB 83.5 83.5 83.5 ... -78.25 -78.25 -78.25\n",
" longitude (points) float64 90kB 321.0 321.2 321.5 ... 166.5 166.8 167.2\n",
"Dimensions without coordinates: points\n",
"Data variables:\n",
" tp (time, points) float32 45kB 0.000679 0.0006809 ... 0.0001221\n",
" ASurf (points, time) float32 45kB 132.6 175.3 217.9 ... 161.1 120.0\n",
"Attributes:\n",
" Conventions: CF-1.7\n",
" institution: European Centre for Medium-Range Weather Forecasts\n",
" history: 2025-11-03T16:33 GRIB to CDM+CF via cfgrib-0.9.15.0/ecCodes...<xarray.Dataset> Size: 226kB\n",
"Dimensions: (points: 11293)\n",
"Coordinates:\n",
" time datetime64[ns] 8B 1940-01-01T06:00:00\n",
" latitude (points) float64 90kB 83.5 83.5 83.5 ... -78.25 -78.25 -78.25\n",
" longitude (points) float64 90kB 321.0 321.2 321.5 ... 166.5 166.8 167.2\n",
"Dimensions without coordinates: points\n",
"Data variables:\n",
" ASurf (points) float32 45kB 132.6 175.3 217.9 ... 181.9 161.1 120.0\n",
"Attributes:\n",
" Conventions: CF-1.7\n",
" institution: European Centre for Medium-Range Weather Forecasts\n",
" history: 2025-11-03T16:33 GRIB to CDM+CF via cfgrib-0.9.15.0/ecCodes...\n",
" version: 2025.11"
],
"text/plain": [
"