generated from erosita/uds
referee
This commit is contained in:
125
scripts/03_scox1_spec.py
Executable file
125
scripts/03_scox1_spec.py
Executable file
@@ -0,0 +1,125 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
__author__ = "Roman Krivonos"
|
||||
__copyright__ = "Space Research Institute (IKI)"
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from astropy.io import fits
|
||||
from astropy.table import Table, Column
|
||||
from astropy import units as u
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import math, sys, os
|
||||
import pickle
|
||||
|
||||
from sklearn.linear_model import LinearRegression
|
||||
from sklearn.linear_model import HuberRegressor
|
||||
from sklearn.linear_model import RANSACRegressor
|
||||
from sklearn.linear_model import TheilSenRegressor
|
||||
from sklearn.model_selection import cross_val_score
|
||||
from sklearn.model_selection import RepeatedKFold
|
||||
|
||||
#from statsmodels.robust.scale import huber
|
||||
from astropy.stats import sigma_clip
|
||||
from astropy.stats import sigma_clipped_stats
|
||||
|
||||
from scipy.stats import norm
|
||||
from scipy.stats import describe
|
||||
from scipy.stats import sem
|
||||
import subprocess
|
||||
|
||||
from numpy import absolute
|
||||
from numpy import arange
|
||||
|
||||
from ridge.utils import *
|
||||
from ridge.config import *
|
||||
|
||||
inkey="ALL"
|
||||
|
||||
skey="SCOX1"
|
||||
|
||||
|
||||
plotme=False
|
||||
|
||||
|
||||
ebands0={'B01':[0.0,0.0],
|
||||
'B02':[0.0,0.0],
|
||||
'B03':[0.0,0.0],
|
||||
'B04':[0.0,0.0],
|
||||
'B05':[0.0,0.0],
|
||||
'B06':[0.0,0.0],
|
||||
'B07':[0.0,0.0],
|
||||
'B08':[0.0,0.0],
|
||||
'B09':[0.0,0.0],
|
||||
'B10':[0.0,0.0],
|
||||
'B11':[0.0,0.0],
|
||||
'B12':[0.0,0.0],
|
||||
'B13':[0.0,0.0],
|
||||
'B14':[0.0,0.0],
|
||||
'B15':[0.0,0.0],
|
||||
'B16':[0.0,0.0],
|
||||
'B17':[0.0,0.0],
|
||||
'B18':[0.0,0.0],
|
||||
'B19':[0.0,0.0],
|
||||
'B20':[0.0,0.0],
|
||||
'B21':[0.0,0.0],
|
||||
}
|
||||
|
||||
"""
|
||||
ebands0={'A01':[0.0,0.0],
|
||||
'A02':[0.0,0.0],
|
||||
'A03':[0.0,0.0],
|
||||
}
|
||||
"""
|
||||
|
||||
mcrab=u.def_unit('mCrab')
|
||||
ctss=u.def_unit('cts/s')
|
||||
u.add_enabled_units([mcrab,ctss])
|
||||
|
||||
if not os.path.exists(specdir):
|
||||
os.makedirs(specdir)
|
||||
|
||||
fitsdir = "{}fits/".format(specdir)
|
||||
if not os.path.exists(fitsdir):
|
||||
os.makedirs(fitsdir)
|
||||
|
||||
for enkey in ebands0.keys():
|
||||
|
||||
fn="detcnts.{}.{}.resid.fits".format(enkey,inkey)
|
||||
dat = Table.read(proddir+fn, unit_parse_strict='silent')
|
||||
df = dat.to_pandas()
|
||||
|
||||
#crab_sep_max=2.0
|
||||
query = 'PHASE > {} & PHASE < {} & SCO_SEP < {}'.format(phmin,phmax,crab_sep_max)
|
||||
df = df.query(query)
|
||||
print("{}: {} N={}".format(enkey, query, df.shape[0]))
|
||||
|
||||
t = Table.from_pandas(df)
|
||||
t.write("{}fits/SCOX1.{}.fits".format(specdir,enkey),overwrite=True)
|
||||
|
||||
if not (df.shape[0]>0):
|
||||
print("continue")
|
||||
continue
|
||||
|
||||
sg_mean,sg_sem,skew_val,skew_err = get_spec_src(df, sigma=3, grxe_err_cut=grxe_err_cut, enkey=enkey, plotme=True, gaussfit=True)
|
||||
ebands0[enkey]=[sg_mean,sg_sem]
|
||||
|
||||
|
||||
|
||||
|
||||
fspec="{}{}.spec".format(specdir,skey)
|
||||
with open(fspec, 'w') as fp:
|
||||
for enkey in ebands0.keys():
|
||||
flux=ebands0[enkey][0]
|
||||
err=ebands0[enkey][1]
|
||||
print("[DATA] {}: {} {:.6f} {:.6f}".format(skey,enkey,flux,err))
|
||||
fp.write("0 {} {:.6f} {:.6f} 0.0\n".format(bands[enkey],flux,err))
|
||||
subprocess.run(["perl", "do_pha_igr_v3_mCrab.pl", fspec])
|
||||
|
||||
|
||||
try:
|
||||
for remfile in ["cols","cols1","cols2","header",]:
|
||||
os.remove(remfile)
|
||||
except OSError:
|
||||
pass
|
Reference in New Issue
Block a user