Commit af670df4 authored by Wilfried Mercier's avatar Wilfried Mercier
Browse files

correction of a bug in remove_nanvar function from Benoit

parent 0214c6ae
......@@ -380,16 +380,20 @@ def remove_nanvar(var):
"""
cnan = np.isnan(var)
nanmap = cnan.prod(axis=0)
indnan = np.where(nanmap == 1)
indnum = np.where(nanmap == 0)
qvar = var[:, indnum[0], indnum[1]].reshape(var.shape[0], np.size(indnum[0]))
medianvar = np.median(qvar, axis=1)
cnan = np.isnan(var) # True where there are NaN
#nanmap = cnan.prod(axis=0) # 0 if there is at least one value
#indnan = np.where(nanmap == 1)
#indnum = np.where(nanmap == 0)
ncnan = np.logical_not(cnan) # True where there are values
nanmap = ncnan.prod(axis=0) # 0 if there is at least one NaN
indnan = np.where(nanmap == 0) # indicates the pixels where there is at least one NaN
indnum = np.where(nanmap == 1) # indicates the pixels where there are no NaN
qvar = var[:, indnum[0], indnum[1]].reshape(var.shape[0], np.size(indnum[0])) # spectra with no NaN
medianvar = np.median(qvar, axis=1) # median variance spectrum
if np.size(indnan[0]) == 0:
logger.info('Variance cube contains NaN and has been corrected')
for ind in range(np.size(indnan[0])):
var[:, indnan[0][ind], indnan[1][ind]] = medianvar
var[:, indnan[0][ind], indnan[1][ind]] = medianvar # If there is one NaN, the whole variance spectrum is replaced by the median variance spectrum
return var
......@@ -416,13 +420,15 @@ def clipcube(cube, hdr, xy=3, sclip=3, npass=10):
im = cube[z, :]
count = 0
ok = False
while count < npass | ok:
#while count < npass | ok:
while (count < npass) & (not(ok)):
count += 1
im1 = ndimage.median_filter(im, xy)
diff = im - im1
bad = np.abs(diff) > (sclip * np.std(diff))
im[bad] = im1[bad]
if np.size(bad) == 0:
#if np.size(bad) == 0:
if np.sum(bad) == 0:
ok = True
cube1[z, :] = im
hdr.append(('XYCLIP', xy, 'Size of the clipping box'))
......
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