In [1]:
%matplotlib nbagg
import numpy as np
import netCDF4
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import scipy.ndimage as ndimage
import glob

# open data files
dataf = sorted(glob.glob("../data/uvi_2018111[7-9]*l3b_*.nc"))   # all images during 2018-11-17 -- 19
nf = len(dataf)   # number of files
print("number of images = ", nf)

# extract information from the first file
nc = netCDF4.Dataset(dataf[0], 'r')
rad = nc.variables["radiance"][0, :, :]    # radiance
inang = nc.variables["inangle"][0, :, :]   # incidence angle
nx = rad.shape[1]   # number of longitudinal grids
ny = rad.shape[0]   # number of latitudinal grids
lon = nc.variables["longitude"][:]   # longitude
lat = nc.variables["latitude"][:]    # latitude
nc.close()

# plot the first image
plt.figure(figsize=(10, 5))
plt.title("original image")
plt.pcolormesh(lon, lat, rad, shading='auto', cmap="gray", vmin=0, vmax=4e7)
plt.show()

# high-pass filter
sigma = 20   # e-folding half width in pixels for gaussian smoothing

model = np.cos(np.pi/180.*inang)
model = np.where(model > 0., model, 0.)
corrected_rad = rad/model
smoothed_rad = ndimage.gaussian_filter(corrected_rad, [sigma, sigma])
highpass_rad = corrected_rad - smoothed_rad
plt.figure(figsize=(10, 5))
plt.title("high-pass filtered image")
plt.pcolormesh(lon, lat, highpass_rad, shading='auto', cmap="gray", vmin=-1e6, vmax=1e6)
plt.show()
number of images =  35
C:\ProgramData\Anaconda3\lib\site-packages\numpy\ma\core.py:1158: RuntimeWarning: overflow encountered in true_divide
  result = self.f(da, db, *args, **kwargs)
In [2]:
# animation
sigma = 20   # e-folding half width in pixels for gaussian smoothing

# create a fig object
fig = plt.figure(figsize=(10, 5))

# prepare a list for successive images
ims = []

# prepare variables for processed images
model = np.zeros([ny, nx])
corrected_rad = np.zeros([ny, nx])
smoothed_rad = np.zeros([ny, nx])
highpass_rad = np.zeros([ny, nx])

for i in range(0, nf):  # read all images
    print(i, end=" ")

    # read data
    nc = netCDF4.Dataset(dataf[i], 'r')
    rad = nc.variables["radiance"][0, :, :]   # radiance
    inang = nc.variables["inangle"][0, :, :]   # incidence angle
    nc.close()

    # high-pass filtering
    model = np.cos(np.pi/180.*inang)
    model = np.where(model > 0., model, 0.)
    corrected_rad = rad/model
    smoothed_rad = ndimage.gaussian_filter(corrected_rad, [sigma, sigma])
    highpass_rad = corrected_rad - smoothed_rad

    # append the image to the list
    ims.append([plt.pcolormesh(lon, lat, highpass_rad, shading='auto', cmap="gray", vmin=-1e6, vmax=1e6)])

# create an animation
ani = animation.ArtistAnimation(fig, ims, interval=100, repeat_delay=500)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34