简体   繁体   English

在python中的Modis NETCDF中绘制平滑Savgol过滤器

[英]Plot Smoothing Savgol filter in Modis NETCDF in python

Is it possible to insert the savgol filter in a NETCDF file in MODIS and plot the smoothing spatially in python?是否可以在 MODIS 的 NETCDF 文件中插入 savgol 过滤器并在 python 中绘制空间平滑?

Here is my sample code这是我的示例代码

import matplotlib.pyplot as plt
import xarray as xr
import pandas as pd
import numpy as np

# open Netcdf file
ds = xr.open_dataset('MOD16A2.006_500m_aid20001.nc')

# show information in xarray dataset
ds

<xarray.Dataset>
Dimensions:     (lat: 2567, lon: 2739, time: 45)
Coordinates:
  * time        (time) object 2001-01-01 00:00:00 ... 2001-12-27 00:00:00
  * lat         (lat) float64 -7.348 -7.352 -7.356 ... -18.03 -18.04 -18.04
  * lon         (lon) float64 -61.64 -61.63 -61.63 ... -50.24 -50.23 -50.23
Data variables:
    crs         int8 ...
    ET_500m     (time, lat, lon) float32 ...
    ET_QC_500m  (time, lat, lon) float32 ...
Attributes:
    title:        MOD16A2.006 for aid0001
    Conventions:  CF-1.6
    institution:  Land Processes Distributed Active Archive Center (LP DAAC)
    source:       AppEEARS v2.36
    references:   See README.txt
    history:      See README.txt

# Get Variables
lat = ds.lat
lon = ds.lon
time = ds.time
data = ds.ET_500m[0,:,:] 
units = ds.ET_500m[:,:,:].units


# Plot image
data.plot.imshow(cmap='viridis_r', figsize=(10,8))

Due to the noise that the amount of clouds causes in the pixel quality, I need to apply a spatial smoothing method to improve the quality of data derived from MODIS由于云量对像素质量造成的噪声影响,我需要应用空间平滑方法来提高从 MODIS 导出的数据质量

I think the savgol filter fits the situation, but I don't know how to use it spatially.我认为 savgol 过滤器适合这种情况,但我不知道如何在空间上使用它。 I may have another method of smoothing, but I don't know.我可能有另一种平滑的方法,但我不知道。

Yes it is possible, please provide a working code example next time.是的,有可能,请下次提供一个有效的代码示例。 I would suggest using netCDF4 or xarray in python, getting the data, and using the 2d Savgol filter as found in the following documentation:我建议在 python 中使用 netCDF4 或 xarray,获取数据,并使用以下文档中的 2d Savgol 过滤器:

https://scipy.github.io/old-wiki/pages/Cookbook/SavitzkyGolay https://scipy.github.io/old-wiki/pages/Cookbook/SavitzkyGolay

This will perform the smoothing, then export the data in the netCDF file and you should be good to go.这将执行平滑,然后导出 netCDF 文件中的数据,您应该一切顺利。

Also, you can use xarray in conjunction with cartopy for plotting the data as well:此外,您还可以将 xarray 与 cartopy 结合使用来绘制数据:

http://xarray.pydata.org/en/stable/plotting.html http://xarray.pydata.org/en/stable/plotting.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM