Comparing two datasets with different resolutions using regriddingΒΆ

In this recipe, we will regrid two different datasets with different resolutions. An example use case could be one where the observational dataset with a higher resolution needs to be regridded to that of the model dataset so that they can be compared with each other.

  1. Import cf-python:

import cf
  1. Read the field constructs:

obs = cf.read("~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc", chunks=None)
print(obs)
[<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>]
model = cf.read(
    "~/recipes/tas_Amon_HadGEM3-GC3-1_hist-1p0_r3i1p1f2_gn_185001-201412.nc"
)
print(model)
[<CF Field: air_temperature(time(1980), latitude(144), longitude(192)) K>]
  1. Select observation and model temperature fields by identity and index respectively, and look at their contents:

obs_temp = obs.select_field("long_name=near-surface temperature")
print(obs_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
Field: air_temperature (ncvar%tas)
----------------------------------
Data            : air_temperature(time(1980), latitude(144), longitude(192)) K
Cell methods    : time(1980): mean (interval: 1 hour)
Dimension coords: time(1980) = [1850-01-16 00:00:00, ..., 2014-12-16 00:00:00] 360_day
                : latitude(144) = [-89.375, ..., 89.375] degrees_north
                : longitude(192) = [0.9375, ..., 359.0625] degrees_east
                : height(1) = [1.5] m
Coord references: grid_mapping_name:latitude_longitude
  1. Regrid observational data to that of the model data and create a new low resolution observational data using bilinear interpolation:

Field: long_name=near-surface temperature (ncvar%tmp)
-----------------------------------------------------
Data            : long_name=near-surface temperature(long_name=time(1452), latitude(144), longitude(192)) degrees Celsius
Dimension coords: long_name=time(1452) = [1901-01-16 00:00:00, ..., 2021-12-16 00:00:00] gregorian
                : latitude(144) = [-89.375, ..., 89.375] degrees_north
                : longitude(192) = [0.9375, ..., 359.0625] degrees_east
Coord references: grid_mapping_name:latitude_longitude

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

Gallery generated by Sphinx-Gallery