Commit ae096b86 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

factor out common code

parent c05d366b
Pipeline #12579 passed with stage
in 5 minutes and 18 seconds
......@@ -29,27 +29,33 @@ class GLMollweide(Heatmap):
idx -= target - left < right - target
return idx
def _mollview(self, x, nlat, nlon, xsize=800):
@staticmethod
def _mollweidehelper(xsize):
xsize = int(xsize)
ysize = int(xsize/2)
res = np.full(shape=(ysize,xsize), fill_value=np.nan, dtype=np.float64)
xc = (xsize-1)*0.5
yc = (ysize-1)*0.5
i, j = np.meshgrid(np.arange(xsize), np.arange(ysize))
u = 2*(i-xc)/(xc/1.02)
v = (j-yc)/(yc/1.02)
u, v = np.meshgrid(np.arange(xsize), np.arange(ysize))
u = 2*(u-xc)/(xc/1.02)
v = (v-yc)/(yc/1.02)
mask = np.where((u*u*0.25 + v*v) <= 1.)
t1 = v[mask]
theta = 0.5*np.pi-(
np.arcsin(2/np.pi*(np.arcsin(t1) + t1*np.sqrt((1.-t1)*(1+t1)))))
phi = -0.5*np.pi*u[mask]/np.maximum(np.sqrt((1-t1)*(1+t1)), 1e-6)
phi = np.where(phi<0, phi+2*np.pi, phi)
return res, mask, theta, phi
def _mollview(self, x, nlat, nlon, xsize=800):
res, mask, theta, phi = self._mollweidehelper(xsize)
x = np.reshape(x, (nlat,nlon))
ra = np.linspace(0, 2*np.pi, nlon+1)
dec = pyHealpix.GL_thetas(nlat)
ilat = self._find_closest(dec, theta)
ilon = self._find_closest(ra, phi+np.pi)
ilon = self._find_closest(ra, phi)
ilon=np.where(ilon==nlon,0,ilon)
res[mask]=x[ilat,ilon]
return res
......@@ -19,21 +19,28 @@ class HPMollweide(Heatmap):
data = self._mollview(data)
super(HPMollweide, self).__init__(data, color_map, webgl, smoothing)
def _mollview(self, x, xsize=800):
@staticmethod
def _mollweidehelper(xsize):
xsize = int(xsize)
ysize = int(xsize/2)
res = np.full(shape=(ysize,xsize), fill_value=np.nan, dtype=np.float64)
xc = (xsize-1)*0.5
yc = (ysize-1)*0.5
i, j = np.meshgrid(np.arange(xsize), np.arange(ysize))
u = 2*(i-xc)/(xc/1.02)
v = (j-yc)/(yc/1.02)
u, v = np.meshgrid(np.arange(xsize), np.arange(ysize))
u = 2*(u-xc)/(xc/1.02)
v = (v-yc)/(yc/1.02)
mask = np.where((u*u*0.25 + v*v) <= 1.)
t1 = v[mask]
theta = 0.5*np.pi-(
np.arcsin(2/np.pi*(np.arcsin(t1) + t1*np.sqrt((1.-t1)*(1+t1)))))
phi = -0.5*np.pi*u[mask]/np.maximum(np.sqrt((1-t1)*(1+t1)), 1e-6)
phi = np.where(phi<0, phi+2*np.pi, phi)
return res, mask, theta, phi
def _mollview(self, x, xsize=800):
res, mask, theta, phi = self._mollweidehelper(xsize)
ptg = np.empty((phi.size, 2), dtype=np.float64)
ptg[:, 0] = theta
ptg[:, 1] = phi
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment