This commit is contained in:
Roman Krivonos
2024-07-07 16:07:39 +03:00
parent 2552bdb552
commit d7ddc5dc43
31 changed files with 13798 additions and 56949 deletions

View File

@@ -26,10 +26,10 @@ from numpy import arange
from ridge.utils import *
from ridge.config import *
plotme=False
plotme=True
enkey = sys.argv[1]
outkey = sys.argv[2]
#outkey = "ALL"
#outkey = sys.argv[2]
outkey = "ALL"
fn="detcnts.{}.fits".format(enkey)
@@ -83,8 +83,11 @@ base0=[]
c0=[]
texp0=[]
d = fits.getdata(datadir+fn)
df = pd.DataFrame(np.array(d).byteswap().newbyteorder())
#d = fits.getdata(datadir+fn)
#df = pd.DataFrame(np.array(d).byteswap().newbyteorder())
with fits.open(datadir+fn) as data:
df = pd.DataFrame(data[1].data)
# BKG
if(outkey == 'BKG'):
@@ -100,7 +103,7 @@ if(outkey=='ALL'):
for i, row in df.iterrows():
orbit=row['REV']
obsid=row['OBSID'].decode("UTF-8")
obsid=row['OBSID']#.decode("UTF-8")
if not (orbit > revmin and orbit < revmax):
print("Skip orbit",orbit,row['OBSID'])
@@ -170,7 +173,6 @@ for r in range(rev_min,rev_max):
ind = np.nonzero(orbits == r)
if not (len(resid_arr[ind])>10):
continue
#print(r,np.mean(resid_arr[ind]), len(resid_arr[ind]))
distr_val.append(np.mean(resid_arr[ind]))
distr_rev.append(r)
@@ -183,13 +185,14 @@ filtered_data = sigma_clip(dval, sigma=sigma, maxiters=10, return_bounds=True)
filtered_arr=filtered_data[0]
filtered_min=filtered_data[1]
filtered_max=filtered_data[2]
print("Sigma clipping: min {:.2e} max {:.2e}".format(filtered_min,filtered_max))
print("length orig: {} taken: {} filtered: {}".format(len(dval),len(dval[filtered_arr.mask==False]),len(dval[filtered_arr.mask==True])))
sg_mean, sg_med, sg_std = sigma_clipped_stats(distr_val, sigma=sigma, maxiters=10)
sg_sem = sem(dval[filtered_arr.mask==False])
print("Sigma clipping: mean {:.2f} med {:.2f} std {:.2f} ".format(sg_mean, sg_med, sg_std))
print("Sigma clipping: mean {:.2e} med {:.2e} std {:.2e} ".format(sg_mean, sg_med, sg_std))
print(len(drev[filtered_arr.mask==True]))
@@ -208,7 +211,7 @@ if(plotme):
with open(proddir+fn.replace(".fits",".ignored_rev.resid.pkl"), 'wb') as fp:
pickle.dump(drev[filtered_arr.mask==True], fp, protocol=pickle.HIGHEST_PROTOCOL)
print("Removed REVs:",ignored_rev)
print("Removed REVs:",drev[filtered_arr.mask==True])
indices = sorted(
@@ -256,3 +259,22 @@ with fits.open(proddir+fout, mode='update') as hdus:
coldefs = fits.ColDefs([
fits.Column(name='REV', format='J', unit='', array=drev),
fits.Column(name='RESID', format='D', unit='cts/s', array=dval),
fits.Column(name='MASK', format='L', unit='', array=filtered_arr.mask),
])
fout = fn.replace(".fits",".{}.resid_by_rev.fits".format(outkey))
hdu = fits.BinTableHDU.from_columns(coldefs, name='GRXE')
hdu.header['MISSION'] = ('INTEGRAL', '')
hdu.header['TELESCOP'] = (outkey, '')
hdu.header['INSTITUT'] = ('IKI', 'Affiliation')
hdu.header['AUTHOR'] = ('Roman Krivonos', 'Responsible person')
hdu.header['EMAIL'] = ('krivonos@cosmos.ru', 'E-mail')
#hdu.add_checksum()
print(hdu.columns)
hdu.writeto(proddir+fout, overwrite=True)
with fits.open(proddir+fout, mode='update') as hdus:
hdus[1].add_checksum()