Commit 1964b3e4 authored by bepinat's avatar bepinat

Nan in variance cube corrected

parent 1c3f7f74
......@@ -124,6 +124,7 @@ def readconfig(filename, config):
if conf.has_key('OII'):
conf['OII3729'] = conf['OII3726'] = conf.pop('OII')
if conf['SPSF'] == None: conf['SPSF'] = 0.
if conf['COMMW'] == None: conf['COMMW'] = False
# XXX or give an error message but in that case, must test that the keywords have correct values
return conf
......@@ -242,6 +243,32 @@ def cutcube(cube, hdr, conf):
hdr['CRPIX1'] -= conf['ZMIN']
return cubecut, hdr
def remove_nanvar(var):
"""This function removes nan in variance cube if any and replaces them by median variance (spectrally)
var: array
input variance cube
corrected variance
cnan = np.isnan(var)
nanmap =
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)
if np.size(indnan[0]) == 0:
print('Variance cube contains NaN and has been corrected')
for ind in range(np.size(indnan[0])):
var[:, indnan[0][ind], indnan[1][ind]] = medianvar
return var
def clipcube(cube, hdr, xy=3, sclip=3, npass=10):
"""This function performs a sigma clipping on the cube
......@@ -872,6 +899,8 @@ def camel(filename, plot=False, debug=False, free_ratio=False, multi_ext=False,
if var != None:
print("Cutting variance")
var, varhdr = cutcube(var, varhdr, conf)
if var.ndim == 3:
var = remove_nanvar(var)
varhdr = writedata(var, varhdr, conf['OUTPUT']+'_var_cut.fits')
#Clipping the cube
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment