Plotting global mean temperatures spatiallyΒΆ

In this recipe, we will plot the global mean temperature spatially.

  1. Import cf-python and cf-plot:

import cfplot as cfp

import cf
  1. Read the field constructs:

f = cf.read("~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc")
print(f)
[<CF Field: ncvar%stn(long_name=time(1452), long_name=latitude(360), long_name=longitude(720))>,
 <CF Field: long_name=near-surface temperature(long_name=time(1452), long_name=latitude(360), long_name=longitude(720)) degrees Celsius>]
  1. Select near surface temperature by index and look at its contents:

temp = f[1]
print(temp)
Field: long_name=near-surface temperature (ncvar%tmp)
-----------------------------------------------------
Data            : long_name=near-surface temperature(long_name=time(1452), long_name=latitude(360), long_name=longitude(720)) degrees Celsius
Dimension coords: long_name=time(1452) = [1901-01-16 00:00:00, ..., 2021-12-16 00:00:00] gregorian
                : long_name=latitude(360) = [-89.75, ..., 89.75] degrees_north
                : long_name=longitude(720) = [-179.75, ..., 179.75] degrees_east
  1. Average the monthly mean surface temperature values by the time axis using the collapse method:

global_avg = temp.collapse("mean", axes="long_name=time")
  1. Plot the global mean surface temperatures:

cfp.con(global_avg, lines=False, title="Global mean surface temperature")
plot 3 recipe
/home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/cartopy/crs.py:228: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  if len(multi_line_string) > 1:
/home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/cartopy/crs.py:239: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  line_strings = list(multi_line_string)
/home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/cartopy/crs.py:239: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  line_strings = list(multi_line_string)
/home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/cartopy/crs.py:280: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  for line in multi_line_string:
/home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/cartopy/crs.py:347: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  if len(p_mline) > 0:
/home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/cartopy/crs.py:385: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  line_strings.extend(multi_line_string)
/home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/cartopy/crs.py:385: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  line_strings.extend(multi_line_string)

Total running time of the script: ( 0 minutes 36.820 seconds)

Gallery generated by Sphinx-Gallery