77# for interpolation
88from scipy import interpolate
99
10- # for resampling technology
11- #from lintsampler import LintSampler
12- #import lintsampler
10+ # check if lintsampler is available
11+ try :
12+ import lintsampler
13+ HAS_LINTSAMPLER = True
14+ except ImportError :
15+ HAS_LINTSAMPLER = False
16+
17+ # check if flex is available
18+ try :
19+ import flex
20+ HAS_FLEX = True
21+ except ImportError :
22+ HAS_FLEX = False
1323
14- # if you leave LaguerreAmplitudes in a different file
15- from FLEXbase import LaguerreAmplitudes
1624
1725
1826
@@ -205,6 +213,9 @@ def generate_image(self,rmax,nbins,noiselevel=-1.0):
205213
206214 def make_expansion (self ,mmax ,nmax ,rscl ,xmax = 10000. ,noisy = False ):
207215
216+ if not HAS_FLEX :
217+ raise ImportError ("flex is not available. Please install flex to use this method." )
218+
208219 try :
209220 snapshot = self .img
210221 except :
@@ -230,24 +241,29 @@ def make_expansion(self,mmax,nmax,rscl,xmax=10000.,noisy=False):
230241 #phi[gvals] = np.nan
231242 snapshotflat [gvals ] = np .nan
232243
233- laguerre = LaguerreAmplitudes (rscl ,mmax ,nmax ,rval ,phi ,snapshotflat )
244+ laguerre = flex . FLEX (rscl ,mmax ,nmax ,rval ,phi ,mass = snapshotflat )
234245
235246 return laguerre
236247
237248 def make_particle_expansion (self ,mmax ,nmax ,rscl ,xmax = 10000. ,noisy = False ):
238249
239- # no guards here yet, please add one!
250+ if not HAS_FLEX :
251+ raise ImportError ("flex is not available. Please install flex to use this method." )
240252
241253 rval = np .sqrt (self .x ** 2 + self .y ** 2 )
242254 phi = np .arctan2 (self .y ,self .x )
243255 mass = (self .M / self .N )* np .ones (rval .size ) # this assumes equal weights; the sqrt avoids double counting
244256
245257 # this assumes equal weights
246- laguerre = LaguerreAmplitudes (rscl ,mmax ,nmax ,rval ,phi ,mass = mass )
258+ laguerre = flex . FLEX (rscl ,mmax ,nmax ,rval ,phi ,mass = mass )
247259
248260 return laguerre
249261
250262 def resample_expansion (self ,E ):
263+
264+ if not HAS_LINTSAMPLER :
265+ raise ImportError ("lintsampler is not available. Please install lintsampler to use this method." )
266+
251267 def rndmpdf (X ): return np .random .uniform ()
252268 g = lintsampler .DensityGrid ((self .x_centers ,self .x_centers ), rndmpdf )
253269
@@ -256,7 +272,7 @@ def rndmpdf(X): return np.random.uniform()
256272
257273 g .masses = g ._calculate_faverages () * g ._calculate_volumes ()
258274 g ._total_mass = np .sum (g .masses )
259- pos = LintSampler (g ).sample (self .N )
275+ pos = lintsampler . LintSampler (g ).sample (self .N )
260276 return pos
261277
262278 def compute_a1 (self ,E ):
0 commit comments