Skip to content

Instantly share code, notes, and snippets.

@fmaussion
Created December 8, 2019 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fmaussion/16c1119d8658cf4af9d3218dd5b1adf4 to your computer and use it in GitHub Desktop.
Save fmaussion/16c1119d8658cf4af9d3218dd5b1adf4 to your computer and use it in GitHub Desktop.
Download ERA5 at 0.75° resolution - Climate lecture
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import xarray as xr\n",
"import cdsapi"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"c = cdsapi.Client()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"grid = [0.75, 0.75]\n",
"area = [90, -180+0.75/2, -90, 180]\n",
"year = ['{}'.format(y) for y in range(1979, 2019)]\n",
"month = ['{:02d}'.format(m) for m in range(1, 13)]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"dl_dir = '/home/mowglie/disk/Data/Gridded/ERA5_Lectures/'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Invariant"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"c.retrieve(\n",
" 'reanalysis-era5-single-levels',\n",
" {\n",
" 'product_type':'reanalysis',\n",
" 'format':'netcdf',\n",
" 'variable':[\n",
" 'land_sea_mask','model_bathymetry','orography'\n",
" ],\n",
" 'grid': grid,\n",
" 'area': area,\n",
" 'year':'1979',\n",
" 'month':'01',\n",
" 'day':'01',\n",
" 'time':'00:00'\n",
" },\n",
" dl_dir + 'ERA5_LowRes_Invariant.nc')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Temp and precip "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"c.retrieve(\n",
" 'reanalysis-era5-single-levels-monthly-means',\n",
" {\n",
" 'format':'netcdf',\n",
" 'product_type':'monthly_averaged_reanalysis',\n",
" 'variable':[\n",
" 'total_precipitation'\n",
" ],\n",
" 'grid': grid,\n",
" 'area': area,\n",
" 'year': year,\n",
" 'month': month,\n",
" 'time':'00:00'\n",
" },\n",
" dl_dir + 'ERA5_LowRes_Monthly_tp.nc')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"c.retrieve(\n",
" 'reanalysis-era5-single-levels-monthly-means',\n",
" {\n",
" 'format':'netcdf',\n",
" 'product_type':'monthly_averaged_reanalysis',\n",
" 'variable':[\n",
" '2m_temperature'\n",
" ],\n",
" 'grid': grid,\n",
" 'area': area,\n",
" 'year': year,\n",
" 'month': month,\n",
" 'time':'00:00'\n",
" },\n",
" dl_dir + 'ERA5_LowRes_Monthly_t2m.nc')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Wind and SLP at surface "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"c.retrieve(\n",
" 'reanalysis-era5-single-levels-monthly-means',\n",
" {\n",
" 'format':'netcdf',\n",
" 'product_type':'monthly_averaged_reanalysis',\n",
" 'variable':[\n",
" '10m_u_component_of_wind','10m_v_component_of_wind','mean_sea_level_pressure'\n",
" ],\n",
" 'grid': grid,\n",
" 'area': area,\n",
" 'year': year,\n",
" 'month': month,\n",
" 'time':'00:00'\n",
" },\n",
" dl_dir + 'ERA5_LowRes_Monthly_uvslp.nc')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"c.retrieve(\n",
" 'reanalysis-era5-pressure-levels-monthly-means',\n",
" {\n",
" 'format':'netcdf',\n",
" 'product_type':'monthly_averaged_reanalysis',\n",
" 'variable':[\n",
" 'geopotential','relative_humidity','specific_humidity',\n",
" 'temperature','u_component_of_wind','v_component_of_wind',\n",
" 'vertical_velocity'\n",
" ],\n",
" 'pressure_level':[\n",
" '10','50','100',\n",
" '200','300','400',\n",
" '500','600','650',\n",
" '700','750','800',\n",
" '850','900','950',\n",
" '1000'\n",
" ],\n",
" 'grid': grid,\n",
" 'area': area,\n",
" 'year': year,\n",
" 'month': month,\n",
" 'time':'00:00'\n",
" },\n",
" dl_dir + 'ERA5_LowRes_Monthly_4D_all.nc')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## SST"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2019-12-08 21:49:08,199 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/reanalysis-era5-single-levels-monthly-means\n",
"2019-12-08 21:49:08,649 INFO Request is queued\n",
"2019-12-08 21:49:09,729 INFO Request is running\n",
"2019-12-08 21:55:27,722 INFO Request is completed\n",
"2019-12-08 21:55:27,723 INFO Downloading http://136.156.132.210/cache-compute-0005/cache/data6/adaptor.mars.internal-1575838148.850594-27250-25-2aa173b8-df24-4101-8315-43c83ee425a2.nc to /home/mowglie/disk/Data/Gridded/ERA5_Lectures/ERA5_LowRes_Monthly_sst.nc (105.9M)\n",
"2019-12-08 21:55:39,951 INFO Download rate 8.7M/s\n"
]
},
{
"data": {
"text/plain": [
"Result(content_length=111058664,content_type=application/x-netcdf,location=http://136.156.132.210/cache-compute-0005/cache/data6/adaptor.mars.internal-1575838148.850594-27250-25-2aa173b8-df24-4101-8315-43c83ee425a2.nc)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c.retrieve(\n",
" 'reanalysis-era5-single-levels-monthly-means',\n",
" {\n",
" 'format':'netcdf',\n",
" 'product_type':'monthly_averaged_reanalysis',\n",
" 'variable':[\n",
" 'sea_surface_temperature',\n",
" ],\n",
" 'grid': grid,\n",
" 'area': area,\n",
" 'year': year,\n",
" 'month': month,\n",
" 'time':'00:00'\n",
" },\n",
" dl_dir + 'ERA5_LowRes_Monthly_sst.nc')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Sea-ice"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2019-12-08 21:55:44,402 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/reanalysis-era5-single-levels-monthly-means\n",
"2019-12-08 21:55:44,615 INFO Request is queued\n",
"2019-12-08 21:55:45,686 INFO Request is running\n",
"2019-12-08 22:02:03,647 INFO Request is completed\n",
"2019-12-08 22:02:03,648 INFO Downloading http://136.156.133.46/cache-compute-0015/cache/data3/adaptor.mars.internal-1575838544.7205305-22511-35-33da27bd-7142-4f1a-9acf-c8189948af77.nc to /home/mowglie/disk/Data/Gridded/ERA5_Lectures/ERA5_LowRes_Monthly_seaice.nc (105.9M)\n",
"2019-12-08 22:02:20,305 INFO Download rate 6.4M/s\n"
]
},
{
"data": {
"text/plain": [
"Result(content_length=111058724,content_type=application/x-netcdf,location=http://136.156.133.46/cache-compute-0015/cache/data3/adaptor.mars.internal-1575838544.7205305-22511-35-33da27bd-7142-4f1a-9acf-c8189948af77.nc)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c.retrieve(\n",
" 'reanalysis-era5-single-levels-monthly-means',\n",
" {\n",
" 'format':'netcdf',\n",
" 'product_type':'monthly_averaged_reanalysis',\n",
" 'variable':[\n",
" 'sea_ice_cover',\n",
" ],\n",
" 'grid': grid,\n",
" 'area': area,\n",
" 'year': year,\n",
" 'month': month,\n",
" 'time':'00:00'\n",
" },\n",
" dl_dir + 'ERA5_LowRes_Monthly_seaice.nc')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Cloud stuff "
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2019-12-08 22:04:58,822 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/reanalysis-era5-single-levels-monthly-means\n",
"2019-12-08 22:04:59,223 INFO Request is queued\n",
"2019-12-08 22:05:00,291 INFO Request is running\n",
"2019-12-08 22:15:22,975 INFO Request is completed\n",
"2019-12-08 22:15:22,976 INFO Downloading http://136.156.132.105/cache-compute-0000/cache/data8/adaptor.mars.internal-1575839099.7297738-21632-31-ec29620c-e09d-4736-adbb-6fc1cb49aac5.nc to /home/mowglie/disk/Data/Gridded/ERA5_Lectures/ERA5_LowRes_Monthly_clouds.nc (635.5M)\n",
"2019-12-08 22:16:46,851 INFO Download rate 7.6M/s\n"
]
},
{
"data": {
"text/plain": [
"Result(content_length=666323944,content_type=application/x-netcdf,location=http://136.156.132.105/cache-compute-0000/cache/data8/adaptor.mars.internal-1575839099.7297738-21632-31-ec29620c-e09d-4736-adbb-6fc1cb49aac5.nc)"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c.retrieve(\n",
" 'reanalysis-era5-single-levels-monthly-means',\n",
" {\n",
" 'format':'netcdf',\n",
" 'product_type':'monthly_averaged_reanalysis',\n",
" 'variable': [\n",
" 'high_cloud_cover', 'low_cloud_cover', 'medium_cloud_cover',\n",
" 'total_cloud_cover', 'total_column_cloud_ice_water', 'total_column_cloud_liquid_water',\n",
" ],\n",
" 'grid': grid,\n",
" 'area': area,\n",
" 'year': year,\n",
" 'month': month,\n",
" 'time':'00:00'\n",
" },\n",
" dl_dir + 'ERA5_LowRes_Monthly_clouds.nc')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## E, ET "
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2019-12-08 22:16:46,866 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/reanalysis-era5-single-levels-monthly-means\n",
"2019-12-08 22:16:47,557 INFO Request is queued\n",
"2019-12-08 22:16:48,617 INFO Request is running\n",
"2019-12-08 22:25:07,070 INFO Request is completed\n",
"2019-12-08 22:25:07,071 INFO Downloading http://136.156.132.236/cache-compute-0007/cache/data3/adaptor.mars.internal-1575839807.7100542-22963-1-e74be815-9eba-4800-acfe-9a29d69d1f05.nc to /home/mowglie/disk/Data/Gridded/ERA5_Lectures/ERA5_LowRes_Monthly_evap.nc (211.8M)\n",
"2019-12-08 22:25:33,569 INFO Download rate 8M/s\n"
]
},
{
"data": {
"text/plain": [
"Result(content_length=222111788,content_type=application/x-netcdf,location=http://136.156.132.236/cache-compute-0007/cache/data3/adaptor.mars.internal-1575839807.7100542-22963-1-e74be815-9eba-4800-acfe-9a29d69d1f05.nc)"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c.retrieve(\n",
" 'reanalysis-era5-single-levels-monthly-means',\n",
" {\n",
" 'format':'netcdf',\n",
" 'product_type':'monthly_averaged_reanalysis',\n",
" 'variable': [\n",
" 'evaporation', 'potential_evaporation',\n",
" ],\n",
" 'grid': grid,\n",
" 'area': area,\n",
" 'year': year,\n",
" 'month': month,\n",
" 'time':'00:00'\n",
" },\n",
" dl_dir + 'ERA5_LowRes_Monthly_evap.nc')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Water vapor transport "
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2019-12-08 22:25:33,583 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/reanalysis-era5-single-levels-monthly-means\n",
"2019-12-08 22:25:33,745 INFO Request is queued\n",
"2019-12-08 22:25:34,822 INFO Request is running\n",
"2019-12-08 22:31:52,860 INFO Request is completed\n",
"2019-12-08 22:31:52,862 INFO Downloading http://136.156.133.36/cache-compute-0010/cache/data0/adaptor.mars.internal-1575840333.8052623-14565-33-fb945033-9873-452c-8068-77b36f654789.nc to /home/mowglie/disk/Data/Gridded/ERA5_Lectures/ERA5_LowRes_Monthly_wvtransport.nc (211.8M)\n",
"2019-12-08 22:32:17,254 INFO Download rate 8.7M/s\n"
]
},
{
"data": {
"text/plain": [
"Result(content_length=222111788,content_type=application/x-netcdf,location=http://136.156.133.36/cache-compute-0010/cache/data0/adaptor.mars.internal-1575840333.8052623-14565-33-fb945033-9873-452c-8068-77b36f654789.nc)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c.retrieve(\n",
" 'reanalysis-era5-single-levels-monthly-means',\n",
" {\n",
" 'format':'netcdf',\n",
" 'product_type':'monthly_averaged_reanalysis',\n",
" 'variable': [\n",
" 'vertical_integral_of_eastward_water_vapour_flux', 'vertical_integral_of_northward_water_vapour_flux',\n",
" ],\n",
" 'grid': grid,\n",
" 'area': area,\n",
" 'year': year,\n",
" 'month': month,\n",
" 'time':'00:00'\n",
" },\n",
" dl_dir + 'ERA5_LowRes_Monthly_wvtransport.nc')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Energy budget "
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2019-12-08 22:32:17,263 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/reanalysis-era5-single-levels-monthly-means\n",
"2019-12-08 22:32:17,444 INFO Request is queued\n",
"2019-12-08 22:32:18,515 INFO Request is running\n",
"2019-12-08 22:46:37,818 INFO Request is completed\n",
"2019-12-08 22:46:37,820 INFO Downloading http://136.156.133.36/cache-compute-0010/cache/data1/adaptor.mars.internal-1575840737.548193-15848-35-7d61605b-182c-41cd-b640-26567c44cf73.nc to /home/mowglie/disk/Data/Gridded/ERA5_Lectures/ERA5_LowRes_Monthly_eb.nc (953.2M)\n",
"2019-12-08 22:48:28,997 INFO Download rate 8.6M/s\n"
]
},
{
"data": {
"text/plain": [
"Result(content_length=999483536,content_type=application/x-netcdf,location=http://136.156.133.36/cache-compute-0010/cache/data1/adaptor.mars.internal-1575840737.548193-15848-35-7d61605b-182c-41cd-b640-26567c44cf73.nc)"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c.retrieve(\n",
" 'reanalysis-era5-single-levels-monthly-means',\n",
" {\n",
" 'format':'netcdf',\n",
" 'product_type':'monthly_averaged_reanalysis',\n",
" 'variable': [\n",
" 'surface_latent_heat_flux', 'surface_sensible_heat_flux',\n",
" 'surface_net_solar_radiation', 'surface_net_thermal_radiation',\n",
" 'surface_solar_radiation_downwards', 'surface_thermal_radiation_downwards',\n",
" 'toa_incident_solar_radiation', 'top_net_solar_radiation', 'top_net_thermal_radiation',\n",
" ],\n",
" 'grid': grid,\n",
" 'area': area,\n",
" 'year': year,\n",
" 'month': month,\n",
" 'time':'00:00'\n",
" },\n",
" dl_dir + 'ERA5_LowRes_Monthly_eb.nc')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"hide_input": false,
"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.5.2"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
"autoclose": false,
"autocomplete": true,
"bibliofile": "biblio.bib",
"cite_by": "apalike",
"current_citInitial": 1,
"eqLabelWithNumbers": true,
"eqNumInitial": 1,
"hotkeys": {
"equation": "Ctrl-E",
"itemize": "Ctrl-I"
},
"labels_anchors": false,
"latex_user_defs": false,
"report_style_numbering": false,
"user_envs_cfg": false
},
"nbTranslate": {
"displayLangs": [
"*"
],
"hotkey": "alt-t",
"langInMainMenu": true,
"sourceLang": "en",
"targetLang": "fr",
"useGoogleTranslate": true
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": false,
"sideBar": true,
"skip_h1_title": true,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment