Change some error handling for better smoothing
This commit is contained in:
@@ -17,11 +17,11 @@ import lib.plots as proj_plots #Functions for plotting data
|
||||
def main():
|
||||
##### User inputs
|
||||
## Input and output locations
|
||||
globals()['data_folder'] = "../data/NGC1068_x274020/"
|
||||
infiles = ['x274020at.c0f.fits','x274020bt.c0f.fits','x274020ct.c0f.fits',
|
||||
'x274020dt.c0f.fits','x274020et.c0f.fits','x274020ft.c0f.fits',
|
||||
'x274020gt.c0f.fits','x274020ht.c0f.fits','x274020it.c0f.fits']
|
||||
globals()['plots_folder'] = "../plots/NGC1068_x274020/"
|
||||
# globals()['data_folder'] = "../data/NGC1068_x274020/"
|
||||
# infiles = ['x274020at.c0f.fits','x274020bt.c0f.fits','x274020ct.c0f.fits',
|
||||
# 'x274020dt.c0f.fits','x274020et.c0f.fits','x274020ft.c0f.fits',
|
||||
# 'x274020gt.c0f.fits','x274020ht.c0f.fits','x274020it.c0f.fits']
|
||||
# globals()['plots_folder'] = "../plots/NGC1068_x274020/"
|
||||
|
||||
# globals()['data_folder'] = "../data/NGC1068_x14w010/"
|
||||
# infiles = ['x14w0101t_c0f.fits','x14w0102t_c0f.fits','x14w0103t_c0f.fits',
|
||||
@@ -44,13 +44,13 @@ def main():
|
||||
# infiles = ['x3mc0101m_c0f.fits','x3mc0102m_c0f.fits','x3mc0103m_c0f.fits']
|
||||
# globals()['plots_folder'] = "../plots/3C109_x3mc010/"
|
||||
|
||||
# globals()['data_folder'] = "../data/MKN463_x2rp030/"
|
||||
# infiles = ['x2rp0201t_c0f.fits', 'x2rp0202t_c0f.fits', 'x2rp0203t_c0f.fits',
|
||||
# 'x2rp0204t_c0f.fits', 'x2rp0205t_c0f.fits', 'x2rp0206t_c0f.fits',
|
||||
# 'x2rp0207t_c0f.fits', 'x2rp0301t_c0f.fits', 'x2rp0302t_c0f.fits',
|
||||
# 'x2rp0303t_c0f.fits', 'x2rp0304t_c0f.fits', 'x2rp0305t_c0f.fits',
|
||||
# 'x2rp0306t_c0f.fits', 'x2rp0307t_c0f.fits']
|
||||
# globals()['plots_folder'] = "../plots/MKN463_x2rp030/"
|
||||
globals()['data_folder'] = "../data/MKN463_x2rp030/"
|
||||
infiles = ['x2rp0201t_c0f.fits', 'x2rp0202t_c0f.fits', 'x2rp0203t_c0f.fits',
|
||||
'x2rp0204t_c0f.fits', 'x2rp0205t_c0f.fits', 'x2rp0206t_c0f.fits',
|
||||
'x2rp0207t_c0f.fits', 'x2rp0301t_c0f.fits', 'x2rp0302t_c0f.fits',
|
||||
'x2rp0303t_c0f.fits', 'x2rp0304t_c0f.fits', 'x2rp0305t_c0f.fits',
|
||||
'x2rp0306t_c0f.fits', 'x2rp0307t_c0f.fits']
|
||||
globals()['plots_folder'] = "../plots/MKN463_x2rp030/"
|
||||
|
||||
# globals()['data_folder'] = "../data/PG1630+377_x39510/"
|
||||
# infiles = ['x3990201m_c0f.fits', 'x3990205m_c0f.fits', 'x3995101r_c0f.fits',
|
||||
@@ -108,10 +108,10 @@ def main():
|
||||
rotate_stokes = True #rotation to North convention can give erroneous results
|
||||
rotate_data = False #rotation to North convention can give erroneous results
|
||||
# Polarization map output
|
||||
figname = 'NGC1068_FOC' #target/intrument name
|
||||
figname = 'MKN463_FOC' #target/intrument name
|
||||
figtype = '_combine_FWHM020_rot' #additionnal informations
|
||||
SNRp_cut = 20 #P measurments with SNR>3
|
||||
SNRi_cut = 130 #I measurments with SNR>30, which implies an uncertainty in P of 4.7%.
|
||||
SNRp_cut = 3 #P measurments with SNR>3
|
||||
SNRi_cut = 30 #I measurments with SNR>30, which implies an uncertainty in P of 4.7%.
|
||||
step_vec = 1 #plot all vectors in the array. if step_vec = 2, then every other vector will be plotted
|
||||
|
||||
##### Pipeline start
|
||||
|
||||
@@ -800,7 +800,7 @@ def smooth_data(data_array, error_array, data_mask, headers, FWHM=1.,
|
||||
raise ValueError("Not all images in array have same pixel size")
|
||||
FWHM /= pxsize[0].min()
|
||||
|
||||
#Define gaussian stdev
|
||||
# Define gaussian stdev
|
||||
stdev = FWHM/(2.*np.sqrt(2.*np.log(2)))
|
||||
fmax = np.finfo(np.float64).max
|
||||
|
||||
@@ -821,15 +821,16 @@ def smooth_data(data_array, error_array, data_mask, headers, FWHM=1.,
|
||||
dist_rc = np.where(data_mask, fmax, np.sqrt((r-xx)**2+(c-yy)**2))
|
||||
g_rc = np.array([np.exp(-0.5*(dist_rc/stdev)**2),]*len(data_array))
|
||||
# Apply weighted combination
|
||||
if data_mask[r,c]:
|
||||
smoothed[r,c] = 0.
|
||||
error[r,c] = 1.
|
||||
else:
|
||||
smoothed[r,c] = np.sum(data_array*weight*g_rc)/np.sum(weight*g_rc)
|
||||
error[r,c] = np.sqrt(np.sum(weight*g_rc**2))/np.sum(weight*g_rc)
|
||||
smoothed[r,c] = (1.-data_mask[r,c])*np.sum(data_array*weight*g_rc)/np.sum(weight*g_rc)
|
||||
error[r,c] = np.sqrt(np.sum(weight*g_rc**2))/np.sum(weight*g_rc)
|
||||
|
||||
# Nan handling
|
||||
error[np.isnan(smoothed)] = 0.
|
||||
smoothed[np.isnan(smoothed)] = 0.
|
||||
error[np.isnan(error)] = 0.
|
||||
|
||||
elif smoothing.lower() in ['gauss','gaussian']:
|
||||
#Convolution with gaussian function
|
||||
# Convolution with gaussian function
|
||||
smoothed = np.zeros(data_array.shape)
|
||||
error = np.zeros(error_array.shape)
|
||||
for i,image in enumerate(data_array):
|
||||
@@ -838,12 +839,13 @@ def smooth_data(data_array, error_array, data_mask, headers, FWHM=1.,
|
||||
for c in range(image.shape[1]):
|
||||
dist_rc = np.where(data_mask, fmax, np.sqrt((r-xx)**2+(c-yy)**2))
|
||||
g_rc = np.exp(-0.5*(dist_rc/stdev)**2)/(2.*np.pi*stdev**2)
|
||||
if data_mask[r,c]:
|
||||
smoothed[r,c] = 0.
|
||||
error[r,c] = 1.
|
||||
else:
|
||||
smoothed[r,c] = np.sum(data_array*weight*g_rc)/np.sum(weight*g_rc)
|
||||
error[r,c] = np.sqrt(np.sum(weight*g_rc**2))/np.sum(weight*g_rc)
|
||||
smoothed[i][r,c] = (1.-data_mask[r,c])*np.sum(data_array*weight*g_rc)/np.sum(weight*g_rc)
|
||||
error[i][r,c] = np.sqrt(np.sum(weight*g_rc**2))/np.sum(weight*g_rc)
|
||||
|
||||
# Nan handling
|
||||
error[i][np.isnan(smoothed)] = 0.
|
||||
smoothed[i][np.isnan(smoothed)] = 0.
|
||||
error[i][np.isnan(error)] = 0.
|
||||
|
||||
else:
|
||||
raise ValueError("{} is not a valid smoothing option".format(smoothing))
|
||||
|
||||
Reference in New Issue
Block a user