@@ -420,25 +420,28 @@ def RobustWeights(y,z,I,h,wstr):
420420
421421"""
422422
423-
424423# Initial Guess with weighted/missing data
425- def InitialGuess (y ,I ):
424+ def InitialGuess (y , I ):
426425 ny = y .shape [0 ]
427- #% -- nearest neighbor interpolation (in case of missing values)
426+ #-- nearest neighbor interpolation (in case of missing values)
428427 if np .any (np .logical_not (I )):
429- z = np .zeros_like (y )
428+ z = np .zeros_like (y )
430429 for i in range (ny ):
431- _ ,L = scipy .ndimage .distance_transform_edt (np .logical_not (I ), return_indices = True )
430+ _ , L = scipy .ndimage .distance_transform_edt (np .logical_not (I ), return_indices = True )
432431 z [i ] = y [i ]
433- #z[i][np.logical_not(I)] = y[i][*L[:,np.logical_not(I)]]; #Use np take
434- z [i ][np .logical_not (I )] = np .take (y [i ], L [:, np .logical_not (I )])
432+
433+ # Fix: Flatten the indices to handle multidimensional arrays properly
434+ mask = np .logical_not (I )
435+ indices = tuple (L [j , mask ] for j in range (L .shape [0 ]))
436+ z [i ][mask ] = y [i ][indices ]
435437 else :
436438 z = y
437439
438440 #-- coarse fast smoothing using one-tenth**d of the DCT coefficients
439- z = scipy .fft .dctn (z , axes = np .arange (1 , len (z .shape )))
440- indices = np .indices (z .shape ) / np .array (z .shape ).reshape (([- 1 ] + [1 for _ in range (z .ndim )])) #Normalised indices between 0 and 1
441- maxIndex = np .max (indices , axis = 0 )
442- z [maxIndex > .1 ] = 0 # np.power(.1, 1/z.ndim) so that it has constant
443- z = scipy .fft .idctn (z , axes = np .arange (1 , len (z .shape )))
441+ z = scipy .fft .dctn (z , axes = np .arange (1 , len (z .shape )))
442+ indices = np .indices (z .shape ) / np .array (z .shape ).reshape (([- 1 ] + [1 for _ in range (z .ndim )]))
443+ maxIndex = np .max (indices , axis = 0 )
444+ z [maxIndex > .1 ] = 0
445+ z = scipy .fft .idctn (z , axes = np .arange (1 , len (z .shape )))
444446 return z
447+
0 commit comments