Commit e552e581 authored by Fabian Wachsmann's avatar Fabian Wachsmann
Browse files

Delete Test_ERA5_Download_later_add_to_summer_day_use_case.ipynb

parent 9dcc2e7f
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Download Era-5 Data\n",
"\n",
"Test to download era-5 data. If it's working it will later be added to the \"use-case_count_summer_days.ipynb\" notebook as additional (external) data source"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import xarray as xr\n",
"import hvplot.xarray\n",
"import cdsapi\n",
"import cartopy.crs as ccrs\n",
"import numpy as np\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"c = cdsapi.Client()\n",
"\n",
"c.retrieve(\n",
" 'reanalysis-era5-single-levels',\n",
" {\n",
" 'variable': '2m_temperature',\n",
" 'product_type': 'reanalysis',\n",
" 'year': '2018',\n",
" 'month':[\n",
" '01',\n",
" ],\n",
" 'day':[\n",
" '01','02','03',\n",
" '04','05','06',\n",
" '07','08','09',\n",
" '10','11','12',\n",
" '13','14','15',\n",
" '16','17','18',\n",
" '19','20','21',\n",
" '22','23','24',\n",
" '25','26','27',\n",
" '28','29','30',\n",
" '31'\n",
" ],\n",
" 'time':[\n",
" '00:00','01:00','02:00',\n",
" '03:00','04:00','05:00',\n",
" '06:00','07:00','08:00',\n",
" '09:00','10:00','11:00',\n",
" '12:00','13:00','14:00',\n",
" '15:00','16:00','17:00',\n",
" '18:00','19:00','20:00',\n",
" '21:00','22:00','23:00'\n",
" ],\n",
" \"format\": \"grib\",\n",
" }, \"download.grib\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t_xr = xr.open_dataset(\"download.grib\", engine='cfgrib')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t_xr"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t_xr.hvplot.quadmesh(\n",
" 'longitude', 'latitude', 't2m', projection=ccrs.Orthographic(-45, -20),\n",
" global_extent=True, frame_height=540, cmap='viridis',\n",
" coastline=True\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Try 2m max](https://apps.ecmwf.int/codes/grib/param-db?id=51)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Find closest Coordinate Index"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Find nearest model coordinate\n",
"location_latitude = -40.\n",
"location_longitude = -20.\n",
"\n",
"# First, find the index of the grid point nearest a specific lat/lon.\n",
"abslat = np.abs(t_xr[\"latitude\"] - location_latitude)\n",
"abslon = np.abs(t_xr[\"longitude\"] - location_longitude)\n",
"c = np.maximum(abslon, abslat)\n",
"\n",
"([xloc], [yloc]) = np.where(c == np.min(c))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Select"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t_xr = t_xr -273.15"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t_xr['time'].values"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t_pd = pd.Series(t_xr.values, index=t_xr['time'].values)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"tasmax_s = t_pd.resample('D').max()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"tasmax_s"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# resampling the data with the min and max methods. 'MS' stands for month start.\n",
"#monthly_max = c.cube.resample(test_df, freq='MS', how='max')\n",
"#monthly_min = c.cube.resample(test_df, freq='MS', how='min')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "test_env",
"language": "python",
"name": "test_env"
},
"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.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment