{ "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": [ "
<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...
array([0.0000e+00, 2.5000e-01, 5.0000e-01, ..., 3.5925e+02, 3.5950e+02,\n", " 3.5975e+02], dtype=float32)
array([ 90. , 89.75, 89.5 , ..., -89.5 , -89.75, -90. ], dtype=float32)
array(['2021-01-01T00:00:00.000000000', '2021-01-01T01:00:00.000000000',\n", " '2021-01-01T02:00:00.000000000', ..., '2021-01-31T21:00:00.000000000',\n", " '2021-01-31T22:00:00.000000000', '2021-01-31T23:00:00.000000000'],\n", " dtype='datetime64[ns]')
[772450560 values with dtype=float32]