.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_gallery/plot_barnes_filter.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_gallery_plot_barnes_filter.py: 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. .. seealso:: - Maddox, R. A. (1980). An Objective Technique for Separating Macroscale and Mesoscale Features in Meteorological Data. Monthly Weather Review, 108(8), 1108-1121. https://journals.ametsoc.org/view/journals/mwre/108/8/1520-0493_1980_108_1108_aotfsm_2_0_co_2.xml - https://github.com/LinOuyang/pybarnes Before proceeding with all the steps, first import some necessary libraries and packages .. GENERATED FROM PYTHON SOURCE LINES 17-20 .. code-block:: Python import matplotlib.pyplot as plt import easyclimate as ecl .. GENERATED FROM PYTHON SOURCE LINES 21-22 Open tuturial dataset .. GENERATED FROM PYTHON SOURCE LINES 22-25 .. code-block:: Python hgt_data = ecl.open_tutorial_dataset("hgt_2022_day5").hgt.sel(level = 500) hgt_data .. raw:: html
<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]


.. GENERATED FROM PYTHON SOURCE LINES 26-27 Filter dataset using :py:func:`easyclimate.filter.calc_barnes_lowpass ` .. GENERATED FROM PYTHON SOURCE LINES 27-30 .. code-block:: Python hgt_data1 = ecl.filter.calc_barnes_lowpass(hgt_data) hgt_data1 .. rst-class:: sphx-glr-script-out .. code-block:: none Caculating the first revision... Caculating the second revision... .. raw:: html
<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


.. GENERATED FROM PYTHON SOURCE LINES 31-32 Draw results and differences. .. GENERATED FROM PYTHON SOURCE LINES 32-55 .. code-block:: Python 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") .. image-sg:: /auto_gallery/images/sphx_glr_plot_barnes_filter_001.png :alt: Raw data, Filtered data, Mesoscale fluctuations :srcset: /auto_gallery/images/sphx_glr_plot_barnes_filter_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(0.5, 1.0, 'Mesoscale fluctuations') .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.899 seconds) .. _sphx_glr_download_auto_gallery_plot_barnes_filter.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_barnes_filter.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_barnes_filter.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_barnes_filter.zip `