{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Create MERA time series for comparison with measurements" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "import geopandas as gpd\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "import xarray as xr\n", "from rasterstats import zonal_stats\n", "import climag.climag as cplt" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Model results" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "ds = xr.open_mfdataset(\n", " os.path.join(\n", " \"data\", \"ModVege\", \"MERA\", \"modvege_IE_MERA_FC3hr_3_day_*.nc\"\n", " ),\n", " decode_coords=\"all\",\n", " chunks=\"auto\",\n", ")" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "# limit to MERA time series\n", "ds = ds.sel(time=slice(\"1981-01-01\", \"2019-08-31\"))" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "# keep only growth\n", "ds = ds.drop_vars([i for i in ds.data_vars if i != \"gro\"])" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "# # resample - yearly average\n", "# ds_ = cplt.weighted_average(data=ds, averages=\"year\")" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "# resample - weekly average\n", "ds_ = ds.resample(time=\"W-MON\").mean()" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [], "source": [ "for var in ds_.data_vars:\n", " ds_[var].attrs = ds[var].attrs" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n",
"Dimensions: (x: 158, y: 166, time: 2018)\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] 1981-01-05 ... 2019-09-02\n",
" spatial_ref int64 0\n",
"Data variables:\n",
" gro (time, y, x) float32 dask.array<chunksize=(1, 166, 158), meta=np.ndarray>\n",
"Attributes:\n",
" creation_date: 2023-03-25 20:11:18.719312+00:00\n",
" contact: nstreethran@ucc.ie\n",
" frequency: day\n",
" references: https://github.com/ClimAg\n",
" input_dataset: IE_MERA_FC3hr_3_day| \n", " | COUNTY | \n", "mean | \n", "time | \n", "
|---|---|---|---|
| 0 | \n", "DONEGAL | \n", "0.143106 | \n", "1981-01-05 | \n", "
| 1 | \n", "LIMERICK | \n", "0.367039 | \n", "1981-01-05 | \n", "
| 2 | \n", "KILDARE | \n", "0.196928 | \n", "1981-01-05 | \n", "
| 3 | \n", "WATERFORD | \n", "0.529810 | \n", "1981-01-05 | \n", "
| 4 | \n", "DUBLIN | \n", "0.320577 | \n", "1981-01-05 | \n", "
| \n", " | COUNTY | \n", "mean | \n", "time | \n", "
|---|---|---|---|
| 0 | \n", "DONEGAL | \n", "0.175074 | \n", "1981-01-05 | \n", "
| 1 | \n", "LIMERICK | \n", "0.376006 | \n", "1981-01-05 | \n", "
| 2 | \n", "KILDARE | \n", "0.197097 | \n", "1981-01-05 | \n", "
| 3 | \n", "WATERFORD | \n", "0.549799 | \n", "1981-01-05 | \n", "
| 4 | \n", "DUBLIN | \n", "0.226976 | \n", "1981-01-05 | \n", "