简体   繁体   中英

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?

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

I think the savgol filter fits the situation, but I don't know how to use it spatially. 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:

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.

Also, you can use xarray in conjunction with cartopy for plotting the data as well:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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