{ "cells": [ { "cell_type": "markdown", "id": "24ece7af-9e94-433d-8fec-6170c7bad246", "metadata": {}, "source": [ "- script removes unwanted variables that don't need to be stored\n", "- So far, I have run it for 'gfdl-esm4' (except for RGI region 03)\n", "- need to repeat it for the other gcms\n", "\n" ] }, { "cell_type": "markdown", "id": "635f0612-335e-4b5e-9f90-2c9e96c98afc", "metadata": {}, "source": [ "['gfdl-esm4', 'ipsl-cm6a-lr', 'mpi-esm1-2-hr', 'mri-esm2-0',\n", " 'ukesm1-0-ll']" ] }, { "cell_type": "code", "execution_count": 4, "id": "588dad5b-98ee-4020-8051-bf71f86185d3", "metadata": {}, "outputs": [], "source": [ "import xarray as xr\n", "import numpy as np\n", "import os\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "ddd3ddcf-5f43-403d-a847-75c90dc0c422", "metadata": {}, "outputs": [], "source": [ "rgi_regs = []\n", "for rgi_reg in np.arange(1,20,1):\n", " if rgi_reg < 10:\n", " rgi_reg = '0'+str(rgi_reg)\n", " else:\n", " rgi_reg = str(rgi_reg)\n", " rgi_regs.append(rgi_reg)\n", " \n" ] }, { "cell_type": "code", "execution_count": 4, "id": "ccfa0306-499f-4869-8859-850358453a88", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['17', '18', '19']" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rgi_regs[16:]" ] }, { "cell_type": "markdown", "id": "5f567e00-feb1-4600-ad57-e98c0e0724bb", "metadata": {}, "source": [ "- > just need to load that code once again ... when all RGI regions are finished:" ] }, { "cell_type": "code", "execution_count": 5, "id": "adb260e7-21e7-4b12-9e17-a63a60294152", "metadata": {}, "outputs": [], "source": [ "for rgi in rgi_regs:\n", " fpath = f'/home/www/lschuster/runs_glacierMIP3_oggm_v16/output/RGI{rgi}/'\n", " files = os.listdir(path=fpath)\n", " files_old = files.copy()\n", "\n", " for f in files: \n", " if 'x_' not in f and '.nc' in f:\n", " with xr.open_dataset(fpath+f) as ds:\n", " try:\n", " ds = ds.drop_vars('volume_m3_min_h')\n", " ds = ds.drop_vars('area_m2_min_h')\n", "\n", " ds.to_netcdf(fpath+'x_'+f)\n", " # remove the old files\n", " #for f in files_old:\n", " except:\n", " # here we did already remove the stuff\n", " os.rename(fpath+f, fpath+'x_'+f)\n", " try:\n", " os.remove(fpath+f)\n", " except:\n", " pass\n", "\n", " # rename the new smaller files the same as the old files\n", " files_new = os.listdir(path=fpath)\n", " for ff in files_new:\n", " if 'x_' in ff:\n", " os.rename(fpath+ff, fpath+ff[2:])\n", "\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "b7150d52-3aa3-46d0-a151-d4c62c12779c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'06'" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rgi" ] }, { "cell_type": "code", "execution_count": null, "id": "38a46ecc-f7d3-44f0-8492-d990a8fbc0ba", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.12" } }, "nbformat": 4, "nbformat_minor": 5 }