result output changed

This commit is contained in:
Andrey Mukhin 2023-06-22 16:20:08 +03:00
parent a58a1f612e
commit fd708d8170

View File

@ -278,7 +278,7 @@ class Observation:
correction_poiss = np.random.poisson(corr*array, corr.shape) correction_poiss = np.random.poisson(corr*array, corr.shape)
return array + correction_poiss return array + correction_poiss
def wavdecomp(self, mode='gauss', thresh=False, occ_coeff=False): def wavdecomp(self, mode='gauss', thresh=0, occ_coeff=False):
""" """
Performs a wavelet decomposition of image. Performs a wavelet decomposition of image.
""" """
@ -338,11 +338,11 @@ class Observation:
current_dir = os.path.dirname(__file__) current_dir = os.path.dirname(__file__)
pixpos = Table(fits.getdata(os.path.join(current_dir, 'pixpos', f'nu{self.det}pixpos20100101v007.fits'), i+1)) pixpos = Table(fits.getdata(os.path.join(current_dir, 'pixpos', f'nu{self.det}pixpos20100101v007.fits'), i+1))
pixpos = pixpos[pixpos['REF_DET1X'] != -1] pixpos = pixpos[pixpos['REF_DET1X'] != -1]
ref_condition = np.zeros(len(pixpos['REF_DET1X']), dtype=bool) ref_condition = np.zeros(len(pixpos['REF_DET1X']), dtype=bool)
for idx, (x, y) in enumerate(zip(pixpos['REF_DET1X'], pixpos['REF_DET1Y'])): for idx, (x, y) in enumerate(zip(pixpos['REF_DET1X'], pixpos['REF_DET1Y'])):
ref_condition[idx] = np.logical_and(np.equal(x, x_region), np.equal(y, y_region)).any() ref_condition[idx] = np.logical_and(np.equal(x, x_region), np.equal(y, y_region)).any()
positions = np.array((pixpos['RAWX'][ref_condition], pixpos['RAWY'][ref_condition])) positions = np.array((pixpos['RAWX'][ref_condition], pixpos['RAWY'][ref_condition]))
if sum(ref_condition) != 0: if sum(ref_condition) != 0:
positions = np.unique(positions, axis=1) positions = np.unique(positions, axis=1)
@ -392,7 +392,6 @@ def process(obs_path, thresh):
Arguments: path to the file of interest and threshold, Arguments: path to the file of interest and threshold,
e.g. process('D:\\Data\\obs_cl.evt', (3, 2)) e.g. process('D:\\Data\\obs_cl.evt', (3, 2))
""" """
bin_num = 6
table = { table = {
'obs_id': [], 'detector': [], 'ra': [], 'dec': [], 'obs_id': [], 'detector': [], 'ra': [], 'dec': [],
@ -407,17 +406,18 @@ def process(obs_path, thresh):
dec=obs.dec*u.deg, dec=obs.dec*u.deg,
frame='fk5').transform_to('galactic') frame='fk5').transform_to('galactic')
lon, lat = sky_coord.l.value, sky_coord.b.value lon, lat = sky_coord.l.value, sky_coord.b.value
rem_signal, rem_area, poiss_comp, rms = np.zeros((4, 2**bin_num)) useful_bin_num = 6
rem_signal, rem_area, poiss_comp, rms = np.zeros((4, 2**useful_bin_num))
region = np.zeros(obs.data.shape, dtype=bool) region = np.zeros(obs.data.shape, dtype=bool)
region_raw = -1 region_raw = -1
rem_region = np.logical_and(region, np.logical_not(obs.data.mask)) rem_region = np.logical_and(region, np.logical_not(obs.data.mask))
masked_obs = np.ma.masked_array(obs.data, mask=region) masked_obs = np.ma.masked_array(obs.data, mask=region)
good_lvl = np.zeros(bin_num, dtype=bool) good_lvl = np.zeros(useful_bin_num, dtype=bool)
if obs.exposure > 1000: if obs.exposure > 1000:
wav_obs = obs.wavdecomp('atrous', thresh, occ_coeff=True) wav_obs = obs.wavdecomp('atrous', thresh, occ_coeff=True)
wav_sum = wav_obs[2:-1].sum(0) wav_sum = wav_obs[2:-1].sum(0)
occ_coeff = obs.get_coeff() occ_coeff = obs.get_coeff()
binary_arr = binary_array(bin_num) binary_arr = binary_array(useful_bin_num)
good_idx = len(binary_arr) - 1 good_idx = len(binary_arr) - 1
for idx, lvl in enumerate(binary_arr): for idx, lvl in enumerate(binary_arr):
@ -456,7 +456,7 @@ def process(obs_path, thresh):
obs.dec, obs.dec,
lon, lon,
lat, lat,
obs.time_start, obs.time_start,
obs.exposure, obs.exposure,
masked_obs.mean()/obs.exposure, # count rate masked_obs.mean()/obs.exposure, # count rate
1 - rem_region.sum()/np.logical_not(obs.data.mask).sum(), # rem_area 1 - rem_region.sum()/np.logical_not(obs.data.mask).sum(), # rem_area
@ -482,7 +482,7 @@ def process(obs_path, thresh):
] ]
for key, value in zip(table.keys(), to_table): for key, value in zip(table.keys(), to_table):
table[key] = [value] table[key] = value
return table, region.astype(int), region_raw, wav_sum return table, region.astype(int), region_raw, wav_sum
except TypeError: except TypeError:
return obs_path, -1, -1, -1 return obs_path, -1, -1, -1
@ -603,14 +603,14 @@ def process_folder(input_folder=None, start_new_file=None, fits_folder=None,
num += 1 num += 1
continue continue
obs_name = str(result['obs_id'][0])+result['detector'][0] obs_name = str(result['obs_id'])+result['detector']
if result['exposure'][0] < 1000: if result['exposure'] < 1000:
print(f'{num:>3} {obs_name} is skipped. Exposure < 1000') print(f'{num:>3} {obs_name} is skipped. Exposure < 1000')
DataFrame(result).to_csv(os.path.join(fits_folder, 'overview_skipped.csv'), mode='a', header=False) DataFrame(result, index=[0]).to_csv(os.path.join(fits_folder, 'overview_skipped.csv'), mode='a', header=False)
num += 1 num += 1
continue continue
DataFrame(result).to_csv(os.path.join(fits_folder, 'overview.csv'), mode='a', header=False) DataFrame(result, index=[0]).to_csv(os.path.join(fits_folder, 'overview.csv'), mode='a', header=False)
save_region(region, os.path.join(region_folder, f'{obs_name}_region.fits'), overwrite=True) save_region(region, os.path.join(region_folder, f'{obs_name}_region.fits'), overwrite=True)
region_raw.writeto(os.path.join(region_raw_folder, f'{obs_name}_reg_raw.fits'), overwrite=True) region_raw.writeto(os.path.join(region_raw_folder, f'{obs_name}_reg_raw.fits'), overwrite=True)
fits.writeto(os.path.join(wav_sum_folder, f'{obs_name}_wav_sum.fits'), wav_sum, overwrite=True) fits.writeto(os.path.join(wav_sum_folder, f'{obs_name}_wav_sum.fits'), wav_sum, overwrite=True)