2
2
3
3
import numpy as np
4
4
from scipy .special import sph_harm
5
- from pyshtools . shtools import SHExpandDH , MakeGridDH
5
+ from pyshtools import shtools
6
6
7
7
from envmap import EnvironmentMap
8
8
@@ -37,7 +37,7 @@ def __init__(self, input_, copy_=True, max_l=None, norm=4):
37
37
38
38
self .coeffs = []
39
39
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 ))
41
41
42
42
def reconstruct (self , height = None , max_l = None , clamp_negative = True ):
43
43
"""
@@ -47,14 +47,34 @@ def reconstruct(self, height=None, max_l=None, clamp_negative=True):
47
47
48
48
retval = []
49
49
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 ))
51
51
52
52
retval = np .asarray (retval ).transpose ((1 ,2 ,0 ))
53
53
54
54
if clamp_negative :
55
55
retval = np .maximum (retval , 0 )
56
56
57
57
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
58
78
59
79
60
80
if __name__ == '__main__' :
0 commit comments