{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Met Éireann Reanalysis - create input data for ModVege" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import glob\n", "import os\n", "from datetime import datetime, timezone\n", "import cartopy.crs as ccrs\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "import xarray as xr\n", "import climag.climag as cplt\n", "from climag import climag_plot" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# directory of processed MÉRA netCDF files\n", "DATA_DIR = os.path.join(\"/run/media/nms/MyPassport\", \"MERA\", \"netcdf_day\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# list of netCDF variable files\n", "var_list = [\n", " \"11_105_2_0\", # 2 m temperature\n", " \"61_105_0_4\", # total precipitation\n", " \"117_105_0_4\", # global irradiance\n", " \"PET\", # evapotranspiration\n", "]" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# dictionary to store Xarray datasets\n", "ds = {}" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "for var in var_list:\n", " ds[var] = xr.open_mfdataset(\n", " glob.glob(os.path.join(DATA_DIR, f\"MERA_{var}_day.nc\")),\n", " chunks=\"auto\",\n", " decode_coords=\"all\",\n", " )" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "# obtain CRS info\n", "data_crs = ds[\"11_105_2_0\"].rio.crs" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "CRS.from_wkt('PROJCS[\"undefined\",GEOGCS[\"undefined\",DATUM[\"undefined\",SPHEROID[\"undefined\",6367470,0]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433]],PROJECTION[\"Lambert_Conformal_Conic_1SP\"],PARAMETER[\"latitude_of_origin\",53.5],PARAMETER[\"central_meridian\",5],PARAMETER[\"scale_factor\",1],PARAMETER[\"false_easting\",1481641.67696368],PARAMETER[\"false_northing\",537326.063885016],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH]]')" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data_crs" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "# drop the height dimension from the datasets\n", "for v in var_list[:-1]:\n", " ds[v] = ds[v].isel(height=0)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## View datasets" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n",
"Dimensions: (x: 158, y: 166, time: 9131)\n",
"Coordinates:\n",
" * x (x) float64 4.15e+05 4.175e+05 ... 8.05e+05 8.075e+05\n",
" * y (y) float64 4.075e+05 4.1e+05 ... 8.175e+05 8.2e+05\n",
" height float64 2.0\n",
" Lambert_Conformal int64 ...\n",
" * time (time) datetime64[ns] 1981-01-01 ... 2005-12-31\n",
" spatial_ref int64 ...\n",
"Data variables:\n",
" t (time, y, x) float32 dask.array<chunksize=(4871, 85, 81), meta=np.ndarray>\n",
"Attributes:\n",
" CDI: Climate Data Interface version 2.0.5 (https://mpimet.mpg.de...\n",
" Conventions: CF-1.6\n",
" history: Wed Mar 22 19:51:04 2023: cdo -s -f nc4c -shifttime,-3hour ...\n",
" CDO: Climate Data Operators version 2.0.5 (https://mpimet.mpg.de...<xarray.Dataset>\n",
"Dimensions: (x: 158, y: 166, time: 9131)\n",
"Coordinates:\n",
" * x (x) float64 4.15e+05 4.175e+05 ... 8.05e+05 8.075e+05\n",
" * y (y) float64 4.075e+05 4.1e+05 ... 8.175e+05 8.2e+05\n",
" height float64 0.0\n",
" Lambert_Conformal int64 ...\n",
" * time (time) datetime64[ns] 1981-01-01 ... 2005-12-31\n",
" spatial_ref int64 ...\n",
"Data variables:\n",
" tp (time, y, x) float32 dask.array<chunksize=(4871, 85, 81), meta=np.ndarray>\n",
"Attributes:\n",
" CDI: Climate Data Interface version 2.0.5 (https://mpimet.mpg.de...\n",
" Conventions: CF-1.6\n",
" history: Wed Mar 22 16:41:24 2023: cdo -s -f nc4c -shifttime,-3hour ...\n",
" CDO: Climate Data Operators version 2.0.5 (https://mpimet.mpg.de...<xarray.Dataset>\n",
"Dimensions: (x: 158, y: 166, time: 9131)\n",
"Coordinates:\n",
" * x (x) float64 4.15e+05 4.175e+05 ... 8.05e+05 8.075e+05\n",
" * y (y) float64 4.075e+05 4.1e+05 ... 8.175e+05 8.2e+05\n",
" height float64 0.0\n",
" Lambert_Conformal int64 ...\n",
" * time (time) datetime64[ns] 1981-01-01 ... 2005-12-31\n",
" spatial_ref int64 ...\n",
"Data variables:\n",
" grad (time, y, x) float32 dask.array<chunksize=(4871, 85, 81), meta=np.ndarray>\n",
"Attributes:\n",
" CDI: Climate Data Interface version 2.0.5 (https://mpimet.mpg.de...\n",
" Conventions: CF-1.6\n",
" history: Wed Mar 22 21:11:40 2023: cdo -s -f nc4c -shifttime,-3hour ...\n",
" CDO: Climate Data Operators version 2.0.5 (https://mpimet.mpg.de...<xarray.Dataset>\n",
"Dimensions: (x: 158, y: 166, time: 9131)\n",
"Coordinates:\n",
" * x (x) float64 4.15e+05 4.175e+05 ... 8.05e+05 8.075e+05\n",
" * y (y) float64 4.075e+05 4.1e+05 ... 8.175e+05 8.2e+05\n",
" height float64 ...\n",
" Lambert_Conformal int64 ...\n",
" * time (time) datetime64[ns] 1981-01-01 ... 2005-12-31\n",
" spatial_ref int64 ...\n",
"Data variables:\n",
" PET (time, y, x) float32 dask.array<chunksize=(4756, 86, 82), meta=np.ndarray>\n",
"Attributes:\n",
" CDI: Climate Data Interface version 2.0.5 (https://mpimet.mpg.de...\n",
" Conventions: CF-1.6\n",
" CDO: Climate Data Operators version 2.0.5 (https://mpimet.mpg.de...<xarray.Dataset>\n",
"Dimensions: (x: 158, y: 166, time: 9131)\n",
"Coordinates:\n",
" * x (x) float64 4.15e+05 4.175e+05 ... 8.05e+05 8.075e+05\n",
" * y (y) float64 4.075e+05 4.1e+05 ... 8.175e+05 8.2e+05\n",
" height float64 0.0\n",
" Lambert_Conformal int64 ...\n",
" * time (time) datetime64[ns] 1981-01-01 ... 2005-12-31\n",
" spatial_ref int64 0\n",
"Data variables:\n",
" PAR (time, y, x) float32 dask.array<chunksize=(4871, 85, 81), meta=np.ndarray>\n",
" PET (time, y, x) float32 dask.array<chunksize=(4756, 86, 82), meta=np.ndarray>\n",
" T (time, y, x) float32 dask.array<chunksize=(4871, 85, 81), meta=np.ndarray>\n",
" PP (time, y, x) float32 dask.array<chunksize=(4871, 85, 81), meta=np.ndarray>\n",
"Attributes:\n",
" CDI: Climate Data Interface version 2.0.5 (https://mpimet.mpg.de...\n",
" Conventions: CF-1.6\n",
" CDO: Climate Data Operators version 2.0.5 (https://mpimet.mpg.de...\n",
" dataset: IE_MERA_FC3hr_3_day<xarray.Dataset>\n",
"Dimensions: (x: 158, y: 166, time: 366)\n",
"Coordinates:\n",
" * x (x) float64 4.15e+05 4.175e+05 ... 8.05e+05 8.075e+05\n",
" * y (y) float64 4.075e+05 4.1e+05 ... 8.175e+05 8.2e+05\n",
" height float64 0.0\n",
" Lambert_Conformal int64 ...\n",
" * time (time) datetime64[ns] 1980-01-01 ... 1980-12-31\n",
" spatial_ref int64 0\n",
"Data variables:\n",
" PAR (time, y, x) float32 dask.array<chunksize=(366, 85, 81), meta=np.ndarray>\n",
" PET (time, y, x) float32 dask.array<chunksize=(366, 86, 82), meta=np.ndarray>\n",
" T (time, y, x) float32 dask.array<chunksize=(366, 85, 81), meta=np.ndarray>\n",
" PP (time, y, x) float32 dask.array<chunksize=(366, 85, 81), meta=np.ndarray>\n",
"Attributes:\n",
" CDI: Climate Data Interface version 2.0.5 (https://mpimet.mpg.de...\n",
" Conventions: CF-1.6\n",
" CDO: Climate Data Operators version 2.0.5 (https://mpimet.mpg.de...\n",
" dataset: IE_MERA_FC3hr_3_day<xarray.Dataset>\n",
"Dimensions: (x: 158, y: 166, time: 1096)\n",
"Coordinates:\n",
" * x (x) float64 4.15e+05 4.175e+05 ... 8.05e+05 8.075e+05\n",
" * y (y) float64 4.075e+05 4.1e+05 ... 8.175e+05 8.2e+05\n",
" height float64 0.0\n",
" Lambert_Conformal int64 0\n",
" * time (time) datetime64[ns] 1980-01-01 ... 1982-12-31\n",
" spatial_ref int64 0\n",
"Data variables:\n",
" PAR (time, y, x) float32 dask.array<chunksize=(366, 85, 81), meta=np.ndarray>\n",
" PET (time, y, x) float32 dask.array<chunksize=(366, 86, 82), meta=np.ndarray>\n",
" T (time, y, x) float32 dask.array<chunksize=(366, 85, 81), meta=np.ndarray>\n",
" PP (time, y, x) float32 dask.array<chunksize=(366, 85, 81), meta=np.ndarray>\n",
"Attributes:\n",
" CDI: Climate Data Interface version 2.0.5 (https://mpimet.mpg.de...\n",
" Conventions: CF-1.6\n",
" CDO: Climate Data Operators version 2.0.5 (https://mpimet.mpg.de...\n",
" dataset: IE_MERA_FC3hr_3_day<xarray.Dataset>\n",
"Dimensions: (x: 158, y: 166, time: 9497)\n",
"Coordinates:\n",
" * x (x) float64 4.15e+05 4.175e+05 ... 8.05e+05 8.075e+05\n",
" * y (y) float64 4.075e+05 4.1e+05 ... 8.175e+05 8.2e+05\n",
" height float64 0.0\n",
" Lambert_Conformal int64 0\n",
" * time (time) datetime64[ns] 1980-01-01 ... 2005-12-31\n",
" spatial_ref int64 0\n",
"Data variables:\n",
" PAR (time, y, x) float32 dask.array<chunksize=(366, 85, 81), meta=np.ndarray>\n",
" PET (time, y, x) float32 dask.array<chunksize=(366, 86, 82), meta=np.ndarray>\n",
" T (time, y, x) float32 dask.array<chunksize=(366, 85, 81), meta=np.ndarray>\n",
" PP (time, y, x) float32 dask.array<chunksize=(366, 85, 81), meta=np.ndarray>\n",
"Attributes:\n",
" CDI: Climate Data Interface version 2.0.5 (https://mpimet.mpg.de...\n",
" Conventions: CF-1.6\n",
" CDO: Climate Data Operators version 2.0.5 (https://mpimet.mpg.de...\n",
" dataset: IE_MERA_FC3hr_3_day