{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "793820df-21e9-4a37-b3fb-8ec520da02ff", "metadata": {}, "outputs": [], "source": [ "import cdsapi\n", "\n", "c = cdsapi.Client()" ] }, { "cell_type": "code", "execution_count": 2, "id": "8cfa6fdc-b0a9-485b-972d-6c9fb4c7a1c9", "metadata": {}, "outputs": [], "source": [ "grid = [0.75, 0.75]\n", "area = [90, -180+0.75/2, -90, 180]" ] }, { "cell_type": "code", "execution_count": null, "id": "8df80e83-904b-4be2-8260-8c243ab63913", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2002 01\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2022-05-08 12:27:55,665 INFO Welcome to the CDS\n", "2022-05-08 12:27:55,665 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/reanalysis-era5-single-levels\n", "2022-05-08 12:27:55,980 INFO Request is queued\n" ] } ], "source": [ "for yr in range(2002, 2021):\n", " yr_str = f'{yr}'\n", " for mon in range(1, 13):\n", " mon_str = f'{mon:02d}'\n", " print(yr_str, mon_str)\n", " c.retrieve(\n", " 'reanalysis-era5-single-levels',\n", " {\n", " 'product_type': 'reanalysis',\n", " 'format': 'netcdf',\n", " 'variable': [\n", " 'total_precipitation',\n", " ],\n", " # 'grid': grid,\n", " # 'area': area,\n", " 'year': yr_str,\n", " 'month': mon_str,\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", " },\n", " f'HiRes_Hourly_Surf/ERA5_HiRes_Hourly_tp_{yr_str}_{mon_str}.nc')" ] }, { "cell_type": "code", "execution_count": 2, "id": "a3481c55-8f48-492a-b11c-9e018b20445a", "metadata": {}, "outputs": [], "source": [ "import xarray as xr" ] }, { "cell_type": "code", "execution_count": 11, "id": "55b8aee5-0a0f-4687-af70-7ddb99c854f7", "metadata": {}, "outputs": [], "source": [ "for i in range(1, 13):\n", " with xr.open_dataset(f'ERA5_HiRes_Hourly_Surf_2021_{i:02d}.nc') as ds:\n", " ds[['tp']].to_netcdf(f'ERA5_HiRes_Hourly_tp_2021_{i:02d}.nc')" ] }, { "cell_type": "code", "execution_count": 3, "id": "fc6870b8-24ec-49ee-b980-bf300a2b07da", "metadata": {}, "outputs": [], "source": [ "ds = xr.open_dataset('HiRes_Hourly_Surf/ERA5_HiRes_Hourly_tp_2021_01.nc')" ] }, { "cell_type": "code", "execution_count": 4, "id": "dfd929f5-79fb-43e3-87e7-91830c3124ca", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
<xarray.Dataset>\n",
       "Dimensions:    (latitude: 721, longitude: 1440, time: 744)\n",
       "Coordinates:\n",
       "  * longitude  (longitude) float32 0.0 0.25 0.5 0.75 ... 359.0 359.2 359.5 359.8\n",
       "  * latitude   (latitude) float32 90.0 89.75 89.5 89.25 ... -89.5 -89.75 -90.0\n",
       "  * time       (time) datetime64[ns] 2021-01-01 ... 2021-01-31T23:00:00\n",
       "Data variables:\n",
       "    tp         (time, latitude, longitude) float32 ...\n",
       "Attributes:\n",
       "    Conventions:  CF-1.6\n",
       "    history:      2022-04-24 20:23:58 GMT by grib_to_netcdf-2.24.3: /opt/ecmw...
" ], "text/plain": [ "\n", "Dimensions: (latitude: 721, longitude: 1440, time: 744)\n", "Coordinates:\n", " * longitude (longitude) float32 0.0 0.25 0.5 0.75 ... 359.0 359.2 359.5 359.8\n", " * latitude (latitude) float32 90.0 89.75 89.5 89.25 ... -89.5 -89.75 -90.0\n", " * time (time) datetime64[ns] 2021-01-01 ... 2021-01-31T23:00:00\n", "Data variables:\n", " tp (time, latitude, longitude) float32 ...\n", "Attributes:\n", " Conventions: CF-1.6\n", " history: 2022-04-24 20:23:58 GMT by grib_to_netcdf-2.24.3: /opt/ecmw..." ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds" ] }, { "cell_type": "code", "execution_count": null, "id": "4c8829b7-95f3-4791-b59c-11be65c1e858", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "2af359ee-d12b-4c0d-b2a4-a59650c017ee", "metadata": {}, "source": [ "## HiRes test " ] }, { "cell_type": "code", "execution_count": 2, "id": "0878aa14-43a8-419f-b216-9aeac0fee9f1", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2022-04-24 14:32:30,227 INFO Welcome to the CDS\n", "2022-04-24 14:32:30,228 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/reanalysis-era5-single-levels\n", "2022-04-24 14:32:30,276 INFO Request is queued\n", "2022-04-24 14:32:31,317 INFO Request is running\n", "2022-04-24 14:44:49,668 INFO Request is completed\n", "2022-04-24 14:44:49,669 INFO Downloading https://download-0006-clone.copernicus-climate.eu/cache-compute-0006/cache/data2/adaptor.mars.internal-1650803761.3115456-8385-1-3bfef9e1-692d-404c-a18f-692e6af3da04.nc to ERA5_HiRes_Hourly_Energy_2021_01.nc (5.8G)\n", "2022-04-24 14:52:45,901 INFO Download rate 12.4M/s \n" ] }, { "data": { "text/plain": [ "Result(content_length=6179618028,content_type=application/x-netcdf,location=https://download-0006-clone.copernicus-climate.eu/cache-compute-0006/cache/data2/adaptor.mars.internal-1650803761.3115456-8385-1-3bfef9e1-692d-404c-a18f-692e6af3da04.nc)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c.retrieve(\n", " 'reanalysis-era5-single-levels',\n", " {\n", " 'product_type': 'reanalysis',\n", " 'format': 'netcdf',\n", " 'variable': [\n", " 'vertical_integral_of_northward_geopotential_flux', \n", " 'vertical_integral_of_northward_heat_flux', \n", " 'vertical_integral_of_northward_kinetic_energy_flux',\n", " 'vertical_integral_of_northward_total_energy_flux',\n", " ],\n", " 'year': '2021',\n", " 'month': '01',\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", " },\n", " 'ERA5_HiRes_Hourly_Energy_2021_01.nc')" ] }, { "cell_type": "code", "execution_count": null, "id": "347d6154-b63e-4b15-8830-a9ffa26b09d8", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.8.8" } }, "nbformat": 4, "nbformat_minor": 5 }