Skip to content

Commit 4b5eb8f

Browse files
committed
Updated pyshtools wrapper to fit latest API. Added SH windowing.
1 parent afe493b commit 4b5eb8f

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

tools3d/spharm.py

+23-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import numpy as np
44
from scipy.special import sph_harm
5-
from pyshtools.shtools import SHExpandDH, MakeGridDH
5+
from pyshtools import shtools
66

77
from envmap import EnvironmentMap
88

@@ -37,7 +37,7 @@ def __init__(self, input_, copy_=True, max_l=None, norm=4):
3737

3838
self.coeffs = []
3939
for i in range(self.spatial.data.shape[2]):
40-
self.coeffs.append(SHExpandDH(self.spatial.data[:,:,i], norm=norm, sampling=2, lmax_calc=max_l))
40+
self.coeffs.append(shtools.SHExpandDH(self.spatial.data[:,:,i], norm=norm, sampling=2, lmax_calc=max_l))
4141

4242
def reconstruct(self, height=None, max_l=None, clamp_negative=True):
4343
"""
@@ -47,14 +47,34 @@ def reconstruct(self, height=None, max_l=None, clamp_negative=True):
4747

4848
retval = []
4949
for i in range(len(self.coeffs)):
50-
retval.append(MakeGridDH(self.coeffs[i], norm=self.norm, sampling=2, lmax=height, lmax_calc=max_l))
50+
retval.append(shtools.MakeGridDH(self.coeffs[i], norm=self.norm, sampling=2, lmax=height, lmax_calc=max_l))
5151

5252
retval = np.asarray(retval).transpose((1,2,0))
5353

5454
if clamp_negative:
5555
retval = np.maximum(retval, 0)
5656

5757
return retval
58+
59+
def window(self, function="sinc"):
60+
"""
61+
Applies a windowing function to the coefficients to reduce ringing artifacts.
62+
See https://www.ppsloan.org/publication/StupidSH36.pdf
63+
"""
64+
deg = self.coeffs[0].shape[2]
65+
x = np.linspace(0, 1, deg + 1)[:-1]
66+
67+
if function == "sinc":
68+
kernel = np.sinc(x)
69+
else:
70+
raise NotImplementedError(f"Windowing function {function} is not implemented.")
71+
72+
for c in range(len(self.coeffs)):
73+
for l in range(self.coeffs[c].shape[2]):
74+
self.coeffs[c][0,l,:] *= kernel # real
75+
self.coeffs[c][1,l,:] *= kernel # imag
76+
77+
return self
5878

5979

6080
if __name__ == '__main__':

0 commit comments

Comments
 (0)