Barnes Filter

Barnes Filter#

Barnes filter is a commonly used spatial filtering method that mainly uses two constants g and c to calculate Gaussian weights, and performs spatial interpolation for each grid point, thus becoming a low-pass filter that filters out high-frequency fluctuations. When using two different schemes of constant g and c schemes, both retain low-frequency fluctuations of different scales. The difference between the filtering results of the two methods can result in mesoscale fluctuations.

See also

Before proceeding with all the steps, first import some necessary libraries and packages

import matplotlib.pyplot as plt
import easyclimate as ecl

Open tuturial dataset

hgt_data = ecl.open_tutorial_dataset("hgt_2022_day5").hgt.sel(level = 500)
hgt_data
<xarray.DataArray 'hgt' (time: 5, lat: 73, lon: 144)> Size: 210kB
[52560 values with dtype=float32]
Coordinates:
  * time     (time) datetime64[ns] 40B 2022-01-01 2022-01-02 ... 2022-01-05
  * lon      (lon) float32 576B 0.0 2.5 5.0 7.5 10.0 ... 350.0 352.5 355.0 357.5
  * lat      (lat) float32 292B 90.0 87.5 85.0 82.5 ... -82.5 -85.0 -87.5 -90.0
    level    float32 4B 500.0
Attributes:
    long_name:     mean Daily Geopotential height
    units:         m
    precision:     0
    GRIB_id:       7
    GRIB_name:     HGT
    var_desc:      Geopotential height
    level_desc:    Pressure Levels
    statistic:     Mean
    parent_stat:   Individual Obs
    dataset:       NCEP Reanalysis Daily Averages
    actual_range:  [ -574.  32254.5]


Filter dataset using easyclimate.filter.calc_barnes_lowpass

Caculating the first revision...
Caculating the second revision...
<xarray.DataArray 'hgt' (time: 5, lat: 73, lon: 144)> Size: 210kB
array([[[5222.2305, 5222.2305, 5222.2305, ..., 5235.0347, 5235.0347,
         5235.0347],
        [5200.5723, 5200.46  , 5200.3447, ..., 5190.972 , 5190.9414,
         5190.9106],
        [5174.9907, 5174.7886, 5174.5845, ..., 5154.6816, 5154.685 ,
         5154.689 ],
        ...,
        [5163.059 , 5163.5312, 5164.0054, ..., 5146.0386, 5146.181 ,
         5146.3237],
        [5128.2397, 5128.4556, 5128.676 , ..., 5115.2935, 5115.3325,
         5115.3745],
        [5097.883 , 5097.883 , 5097.883 , ..., 5083.253 , 5083.253 ,
         5083.253 ]],

       [[5263.8013, 5263.8013, 5263.8013, ..., 5278.7783, 5278.7783,
         5278.7783],
        [5236.4766, 5236.32  , 5236.162 , ..., 5232.6475, 5232.6074,
         5232.565 ],
        [5204.6294, 5204.3345, 5204.038 , ..., 5188.53  , 5188.4946,
         5188.4585],
...
        [5179.0986, 5179.465 , 5179.837 , ..., 5163.406 , 5163.4946,
         5163.586 ],
        [5156.721 , 5156.8345, 5156.951 , ..., 5147.816 , 5147.8306,
         5147.8438],
        [5143.429 , 5143.429 , 5143.429 , ..., 5145.254 , 5145.254 ,
         5145.254 ]],

       [[5000.3213, 5000.3213, 5000.3213, ..., 5003.492 , 5003.492 ,
         5003.492 ],
        [4997.3667, 4997.3325, 4997.2964, ..., 5001.8037, 5001.801 ,
         5001.796 ],
        [4997.3843, 4997.326 , 4997.266 , ..., 5004.7764, 5004.7524,
         5004.729 ],
        ...,
        [5169.53  , 5169.918 , 5170.312 , ..., 5169.401 , 5169.48  ,
         5169.563 ],
        [5137.6997, 5137.84  , 5137.9795, ..., 5134.1953, 5134.2217,
         5134.251 ],
        [5116.9644, 5116.9644, 5116.9644, ..., 5113.9883, 5113.9883,
         5113.9883]]], shape=(5, 73, 144), dtype=float32)
Coordinates:
  * time     (time) datetime64[ns] 40B 2022-01-01 2022-01-02 ... 2022-01-05
  * lon      (lon) float32 576B 0.0 2.5 5.0 7.5 10.0 ... 350.0 352.5 355.0 357.5
  * lat      (lat) float32 292B 90.0 87.5 85.0 82.5 ... -82.5 -85.0 -87.5 -90.0
    level    float32 4B 500.0


Draw results and differences.

fig, ax = plt.subplots(3,1, figsize = (5, 15))

axi = ax[0]
hgt_data.isel(time = 0).plot.contourf(
    ax = axi, levels = 21,
    cbar_kwargs={"location": "right", "aspect": 30},
)
axi.set_title("Raw data")

axi = ax[1]
hgt_data1.isel(time = 0).plot.contourf(
    ax = axi, levels = 21,
    cbar_kwargs={"location": "right", "aspect": 30},
)
axi.set_title("Filtered data")

axi = ax[2]
draw_dta = hgt_data.isel(time = 0) - hgt_data1.isel(time = 0)
draw_dta.plot.contourf(
    ax = axi, levels = 21,
    cbar_kwargs={"location": "right", "aspect": 30},
)
axi.set_title("Mesoscale fluctuations")
Raw data, Filtered data, Mesoscale fluctuations
Text(0.5, 1.0, 'Mesoscale fluctuations')

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