bug fix for crop_stokes.write_to and background subtraction

This commit is contained in:
2024-03-12 17:06:28 +01:00
parent 10c35b10fc
commit 762b857720
4 changed files with 7 additions and 14 deletions

View File

@@ -240,7 +240,7 @@ def bkg_fit(data, error, mask, headers, subtract_error=True, display=False, save
# Substract background
if subtract_error > 0:
n_data_array[i][mask] = n_data_array[i][mask] - bkg
n_data_array[i][np.logical_and(mask, n_data_array[i] <= 0.01*bkg)] = 0.01*bkg
n_data_array[i][np.logical_and(mask, n_data_array[i] <= 1e-3*bkg)] = 1e-3*bkg
std_bkg[i] = image[np.abs(image-bkg)/bkg < 1.].std()
background[i] = bkg
@@ -327,10 +327,6 @@ def bkg_hist(data, error, mask, headers, sub_type=None, subtract_error=True, dis
histograms.append(hist)
binning.append(np.exp(bin_centers(bin_edges)))
# Take the background as the count-rate with the maximum number of pixels
# hist_max = binning[-1][np.argmax(hist)]
# bkg = np.sqrt(np.sum(image[np.abs(image-hist_max)/hist_max<0.5]**2)/image[np.abs(image-hist_max)/hist_max<0.5].size)
# Fit a gaussian to the log-intensity histogram
bins_stdev = binning[-1][hist > hist.max()/2.]
stdev = bins_stdev[-1]-bins_stdev[0]
@@ -346,7 +342,7 @@ def bkg_hist(data, error, mask, headers, sub_type=None, subtract_error=True, dis
# Substract background
if subtract_error > 0:
n_data_array[i][mask] = n_data_array[i][mask] - bkg
n_data_array[i][np.logical_and(mask, n_data_array[i] < 0.)] = 0.
n_data_array[i][np.logical_and(mask, n_data_array[i] <= 1e-3*bkg)] = 1e-3*bkg
std_bkg[i] = image[np.abs(image-bkg)/bkg < 1.].std()
background[i] = bkg
@@ -443,7 +439,7 @@ def bkg_mini(data, error, mask, headers, sub_shape=(15, 15), subtract_error=True
# Substract background
if subtract_error > 0.:
n_data_array[i][mask] = n_data_array[i][mask] - bkg
n_data_array[i][np.logical_and(mask, n_data_array[i] <= 0.01*bkg)] = 0.01*bkg
n_data_array[i][np.logical_and(mask, n_data_array[i] <= 1e-3*bkg)] = 1e-3*bkg
std_bkg[i] = image[np.abs(image-bkg)/bkg < 1.].std()
background[i] = bkg

View File

@@ -1438,9 +1438,6 @@ class crop_Stokes(crop_map):
def data_mask(self):
return self.hdul_crop[-1].data.astype(int)
def write_to(self, filename):
save_Stokes(self.hdul_crop['I_stokes'], self.hdul_crop['Q_stokes'], self.hdul_crop['U_stokes'], self.hdul_crop['IQU_cov_matrix'], self.hdul_crop['Pol_deg'], self.hdul_crop['Pol_deg_debiased'], self.hdul_crop['Pol_deg_err'], self.hdul_crop['Pol_deg_err_Poisson_noise'], self.hdul_crop['Pol_ang'], self.hdul_crop['Pol_ang_err'], self.hdul_crop['Pol_ang_err_Poisson_noise'], [hdu.header for hdu in self.hdul_crop], self.hdul_crop['data_mask'], filename, data_folder="", return_hdul=False)
class image_lasso_selector(object):
def __init__(self, img, fig=None, ax=None):

View File

@@ -164,7 +164,7 @@ def bin_ndarray(ndarray, new_shape, operation='sum'):
[342 350 358 366 374]]
"""
if not operation.lower() in ['sum', 'mean', 'average', 'avg']:
if operation.lower() not in ['sum', 'mean', 'average', 'avg']:
raise ValueError("Operation not supported.")
if ndarray.ndim != len(new_shape):
raise ValueError("Shape mismatch: {} -> {}".format(ndarray.shape,