First steps

This commit is contained in:
2023-02-15 17:14:46 +03:00
parent 88a8bf5877
commit d3565aa9ba
10 changed files with 185 additions and 18 deletions

View File

@@ -7,6 +7,7 @@ from astropy.wcs import WCS
from astropy.io.fits import update
from astropy.io.fits import getdata
import glob
from fitsio import FITS
from astropy.table import QTable, Table, Column
from astropy import units as u
@@ -19,8 +20,7 @@ from astropy.coordinates import Angle, Latitude, Longitude # Angles
import statistics
import shutil
def printme():
print("hellow world FFF ASAA")
def create_folder(folder):
if not (os.path.exists(folder)):
@@ -30,14 +30,83 @@ def remove_file(filename):
if(os.path.isfile(filename)==True):
os.remove(filename)
def do_evtool_esass(events,outfile):
cmd=["evtool",
"eventfiles=\'{}\'".format((" ").join(events)),
"outfile=%s" %(outfile),
def do_evtool_esass(events=None,outfile=None,evlist=None,gti=None):
eventfiles=None
if(events):
eventfiles="eventfiles=\'{}\'".format((" ").join(events))
if(evlist):
eventfiles="eventfiles=@{}".format(evlist)
if not (eventfiles):
print("ERROR: Event files not provided")
gti="gti=\'{}\'".format(gti) if(gti) else ''
cmd=["evtool",
eventfiles,
gti,
"outfile={}".format(outfile),
"image=yes",
"flag=0x2000",
"pattern=15"
]
# run the command
print((" ").join(cmd))
os.system((" ").join(cmd))
print((" ").join(cmd))
os.system((" ").join(cmd))
def set_bit(value, bit):
return value | (1<<bit)
def clear_bit(value, bit):
return value & ~(1<<bit)
def do_badpix_tm6(filename):
""" special corrrection for TM6 camera, needed for two CalPV-UDS observations, which shows high background at RAWX>250 """
nraw=384
skip_after=250
nskip=(nraw - skip_after)
nrows0=nraw*nskip
fout=filename.replace(".fits", "_badpix.fits")
shutil.copyfile(filename, fout)
hdul = fits.open(fout)
#hdul.info()
tstart=hdul[1].header['TSTART']
tstop=hdul[1].header['TSTOP']
nrows=hdul[1].header['NAXIS2']
f = FITS(fout,'rw')
data = f['EVENTS'].read()
#print(data.dtype)
for row in range(nrows):
if (data['RAWX'][row] >= skip_after):
data['FLAG'][row]=set_bit(data['FLAG'][row],13)
#hdr = fits[0].read_header()
f[1].write(data)
f[1].write_comment("Changed by Roman Krivonos")
f[1].write_history("All RAWx>=250 marked as BAD 0x2000")
data_badpix = f['BADPIX6'].read()
data4 = np.zeros(nrows0,dtype=data_badpix.dtype)
n=0
for i in range(skip_after,nraw):
for j in range(nraw):
data4['RAWX'][n]=i
data4['RAWY'][n]=j
data4['TIMEMIN'][n]=tstart
data4['TIMEMAX'][n]=tstop
data4['BADFLAG'][n]=3
data4['TYPE'][n]=3
data4['PHAMAX'][n]=12000
data4['PHAMIN'][n]=0
n=n+1
f[4].append(data4)
f.close()