ERA5¶
ERA5 products can be downloaded from https://cds.climate.copernicus.eu/#!/home by using the download method of the corresponding product object. For this example we will have a look at the surface temperature of the ERA5 product on single levels at monthly resolution.
Download data
[1]:
from datetime import datetime
from pansat.products.reanalysis.era5 import ERA5Product
t_0 = datetime(2005, 3, 1, 0)
t_1 = datetime(2005, 11, 1, 0)
# create product instance
global_srfc_temps = ERA5Product('monthly','surface', ['2m_temperature'])
[2]:
files = global_srfc_temps.download(t_0, t_1)
Please enter your pansat user password:
········
The variable files now contains the downloaded files. Now we can open the data of a given file by calling the ERA5Product.open() method. This will return an xarray dataset object, which is easy to handle.
[6]:
temp_data = global_srfc_temps.open(filename = files[0])
# display xarray dataset object with its dimensions, coordinates, variables and attributes:
display(temp_data)
<xarray.Dataset>
Dimensions: (latitude: 721, longitude: 1440, time: 1)
Coordinates:
* longitude (longitude) float32 0.0 0.25 0.5 0.75 ... 359.25 359.5 359.75
* latitude (latitude) float32 90.0 89.75 89.5 89.25 ... -89.5 -89.75 -90.0
* time (time) datetime64[ns] 2020-03-01
Data variables:
t2m (time, latitude, longitude) float32 ...
Attributes:
Conventions: CF-1.6
history: 2020-11-15 19:16:38 GMT by grib_to_netcdf-2.16.0: /opt/ecmw...xarray.Dataset
- latitude: 721
- longitude: 1440
- time: 1
- longitude(longitude)float320.0 0.25 0.5 ... 359.5 359.75
- units :
- degrees_east
- long_name :
- longitude
array([0.0000e+00, 2.5000e-01, 5.0000e-01, ..., 3.5925e+02, 3.5950e+02, 3.5975e+02], dtype=float32) - latitude(latitude)float3290.0 89.75 89.5 ... -89.75 -90.0
- units :
- degrees_north
- long_name :
- latitude
array([ 90. , 89.75, 89.5 , ..., -89.5 , -89.75, -90. ], dtype=float32)
- time(time)datetime64[ns]2020-03-01
- long_name :
- time
array(['2020-03-01T00:00:00.000000000'], dtype='datetime64[ns]')
- t2m(time, latitude, longitude)float32...
- units :
- K
- long_name :
- 2 metre temperature
[1038240 values with dtype=float32]
- Conventions :
- CF-1.6
- history :
- 2020-11-15 19:16:38 GMT by grib_to_netcdf-2.16.0: /opt/ecmwf/eccodes/bin/grib_to_netcdf -o /cache/data1/adaptor.mars.internal-1605467798.042555-2625-29-c1f2bd98-67eb-4d84-8c06-47a490014d9d.nc /cache/tmp/c1f2bd98-67eb-4d84-8c06-47a490014d9d-adaptor.mars.internal-1605467798.0430672-2625-12-tmp.grib
Plot data
[12]:
# using xarrays inbuild plot function
temp_data.t2m[0].plot.pcolormesh()
[12]:
<matplotlib.collections.QuadMesh at 0x7f2d2c0c2630>
[14]:
# get data points
temps = temp_data.t2m[0]
lons = temp_data.longitude
lats = temp_data.latitude
[15]:
# customize your own plot
%matplotlib inline
import matplotlib.pyplot as plt
plt.figure(figsize=(12, 6))
fontsize= 15
plt.pcolormesh(lons, lats, temps, shading = 'auto', cmap = 'coolwarm')
plt.colorbar(label="Surface air temperature [K]", extend = 'both')
plt.xticks(lons[::100])
plt.yticks(lats[::100])
plt.xlabel('Lon $^\circ$E', fontsize= fontsize)
plt.ylabel('Lat $^\circ$N', fontsize= fontsize);
Subset domain
You may want to subset the dataset, in order to extract a specific region of the globe:
[20]:
t_0 = datetime(1999, 8, 1, 0)
t_1 = datetime(1999, 9, 1, 0)
# create product instance
arctic_srfc_temps = ERA5Product('monthly','surface', ['mean_sea_level_pressure'], [60,90,-179, 180])
# download
files = arctic_srfc_temps.download(t_0, t_1)
2020-11-02 17:35:57,047 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/reanalysis-era5-single-levels-monthly-means
Creating file: url: https://cds.climate.copernicus.eu/api/v2
key: 63394:602acfdf-3bd4-43d5-9e0e-50fe7dc26ed2
2020-11-02 17:35:57,259 INFO Request is queued
2020-11-02 17:35:58,300 INFO Request is running
2020-11-02 17:35:59,838 INFO Request is completed
2020-11-02 17:35:59,839 INFO Downloading http://136.156.133.46/cache-compute-0015/cache/data6/adaptor.mars.internal-1604334957.4891286-29913-14-4c48fdbb-57ed-4a46-b2e1-8b4ce0432126.nc to ERA5/reanalysis-era5-single-levels-monthly-means/reanalysis-era5-single-levels-monthly-means_199908_mean_sea_level_pressure90--179-60-180.nc (346.8K)
2020-11-02 17:36:00,047 INFO Download rate 1.6M/s
file downloaded and saved as ERA5/reanalysis-era5-single-levels-monthly-means/reanalysis-era5-single-levels-monthly-means_199908_mean_sea_level_pressure90--179-60-180.nc
[10]:
arctic_data
[10]:
<xarray.Dataset>
Dimensions: (latitude: 121, longitude: 1437, time: 1)
Coordinates:
* longitude (longitude) float32 -179.0 -178.75 -178.5 ... 179.5 179.75 180.0
* latitude (latitude) float32 90.0 89.75 89.5 89.25 ... 60.5 60.25 60.0
* time (time) datetime64[ns] 1999-08-01
Data variables:
asn (time, latitude, longitude) float32 ...
Attributes:
Conventions: CF-1.6
history: 2020-11-02 16:31:18 GMT by grib_to_netcdf-2.16.0: /opt/ecmw...xarray.Dataset
- latitude: 121
- longitude: 1437
- time: 1
- longitude(longitude)float32-179.0 -178.75 ... 179.75 180.0
- units :
- degrees_east
- long_name :
- longitude
array([-179. , -178.75, -178.5 , ..., 179.5 , 179.75, 180. ], dtype=float32) - latitude(latitude)float3290.0 89.75 89.5 ... 60.5 60.25 60.0
- units :
- degrees_north
- long_name :
- latitude
array([90. , 89.75, 89.5 , 89.25, 89. , 88.75, 88.5 , 88.25, 88. , 87.75, 87.5 , 87.25, 87. , 86.75, 86.5 , 86.25, 86. , 85.75, 85.5 , 85.25, 85. , 84.75, 84.5 , 84.25, 84. , 83.75, 83.5 , 83.25, 83. , 82.75, 82.5 , 82.25, 82. , 81.75, 81.5 , 81.25, 81. , 80.75, 80.5 , 80.25, 80. , 79.75, 79.5 , 79.25, 79. , 78.75, 78.5 , 78.25, 78. , 77.75, 77.5 , 77.25, 77. , 76.75, 76.5 , 76.25, 76. , 75.75, 75.5 , 75.25, 75. , 74.75, 74.5 , 74.25, 74. , 73.75, 73.5 , 73.25, 73. , 72.75, 72.5 , 72.25, 72. , 71.75, 71.5 , 71.25, 71. , 70.75, 70.5 , 70.25, 70. , 69.75, 69.5 , 69.25, 69. , 68.75, 68.5 , 68.25, 68. , 67.75, 67.5 , 67.25, 67. , 66.75, 66.5 , 66.25, 66. , 65.75, 65.5 , 65.25, 65. , 64.75, 64.5 , 64.25, 64. , 63.75, 63.5 , 63.25, 63. , 62.75, 62.5 , 62.25, 62. , 61.75, 61.5 , 61.25, 61. , 60.75, 60.5 , 60.25, 60. ], dtype=float32) - time(time)datetime64[ns]1999-08-01
- long_name :
- time
array(['1999-08-01T00:00:00.000000000'], dtype='datetime64[ns]')
- asn(time, latitude, longitude)float32...
- units :
- (0 - 1)
- long_name :
- Snow albedo
[173877 values with dtype=float32]
- Conventions :
- CF-1.6
- history :
- 2020-11-02 16:31:18 GMT by grib_to_netcdf-2.16.0: /opt/ecmwf/eccodes/bin/grib_to_netcdf -S param -o /cache/data0/adaptor.mars.internal-1604334676.3084235-3553-16-fc6ae340-8d24-440b-a66f-e04e2bd123fb.nc /cache/tmp/fc6ae340-8d24-440b-a66f-e04e2bd123fb-adaptor.mars.internal-1604334676.3090165-3553-6-tmp.grib
[26]:
# open file
arctic_data = arctic_srfc_temps.open(filename = files[0])
# get data points as numpy arrays
arctic_pressure = arctic_data.msl[0].values
lons = arctic_data.longitude.values
lats = arctic_data.latitude.values
plt.figure(figsize= (20, 6))
fontsize= 15
plt.pcolormesh(lons, lats, arctic_pressure/100, shading = 'auto', cmap = 'magma')
plt.colorbar(label="Mean sea level pressure [hPa]", extend = 'both')
plt.xticks(lons[::100])
plt.yticks(lats[::20])
plt.xlabel('Lon $^\circ$E', fontsize= fontsize)
plt.ylabel('Lat $^\circ$N', fontsize= fontsize);