I made use of numpy.gradient to calculate the gradient map of a scalar-field map. I guess I have not known numpy.gradient very well so that I might produce an incorrect gradient map. I post my code and the resulting map below:
from astropy.io import fits
import matplotlib.pyplot as plt
import numpy as np
subhdu = fits.open('test_subim.fits')[0]
subhdu = subhdu.data
fig = plt.figure(1, figsize = (30,30))
ax = fig.add_axes([0.1,0.7,0.5,0.2])
xr = np.arange(0, subhdu.shape[1], 1)
yr = np.arange(0, subhdu.shape[0], 1)
xx, yy = np.meshgrid(xr,yr)
dx, dy = np.gradient(subhdu.astype('float'))
im = ax.imshow(subhdu,origin='lower',cmap='bwr')
ax.quiver(xx,yy,dx,dy,scale=5,angles="uv",headwidth = 5)
fig.colorbar(im,pad=0)
ax.xaxis.set_ticks([])
ax.yaxis.set_ticks([])

I am confused with two things about my resulting map:
- Why the gradients in the masked area do not point toward as the green arrows;
- Why the edges of the map do not have the gradient calculation?
I would appreciate if anyone can help me figure out my confusions. If you want to play with my data 'test_subim.fits', please visit my google drive. Before playing it, you must install the package astropy probably through the following command, pip install astropy.
Thank you very much again in advance for anyone who can help me out.
