Ejemplo n.º 1
0
def easy_baseline(x, y, result=''):
    if (result != ''):
        if (os.path.exists(result) == False):
            os.mkdir(result)
    else:
        result = os.getcwd()
    dir_d = os.path.join(result, 'in_xy.txt')
    data_d = [x, y]
    zhf.printdatatofile(dir_d, data_d)
    x = np.array(x, np.double)
    y = np.array(y, np.double)
    os.system(
        'Rscript  /home/laojin/software/idl_my_lib/zbbidl/baseline_r_2015.r ' +
        dir_d + ' ' + result + '>>/dev/null')
    if (os.path.exists(os.path.join(result, 'back.txt'))):
        back = np.array(zhf.readcol(os.path.join(result, 'back.txt'))[0])
        net = y - back
        x = decimal_for_array(x, 20)
        y = decimal_for_array(y, 20)
        net = decimal_for_array(net, 20)
        back = decimal_for_array(back, 20)
        zhf.printdatatofile(os.path.join(result, 'xout.txt'), [x])
        zhf.printdatatofile(os.path.join(result, 'net.txt'), [net])
        zhf.printdatatofile(os.path.join(result, 'back.txt'), [back])
        zhf.printdatatofile(os.path.join(result, 'summary_t_obs_net_back.txt'),
                            [x, y, net, back])
        return x, y, net, back
    else:
        print('failed!!')
        print('I can not do the following!!')
        return False
Ejemplo n.º 2
0
def r_baseline(x, y, result='', lamb=1, hwi=30, it=20, int=200):
    if (result != ''):
        if (os.path.exists(result) == False):
            os.mkdir(result)
    else:
        result = os.getcwd()
    dir_d = os.path.join(result, 'in_xy.txt')
    data_d = [x, y]
    zhf.printdatatofile(dir_d, data_d)
    x = np.array(x, np.double)
    y = np.array(y, np.double)
    os.system('Rscript  /home/laojin/my_work/my_r/zzh_baseline_r.r ' + dir_d +
              ' ' + result + ' ' + str(lamb) + ' ' + str(hwi) + ' ' + str(it) +
              ' ' + str(int) + '>>/dev/null')
    if (os.path.exists(os.path.join(result, 'back.txt'))):
        back = np.array(zhf.readcol(os.path.join(result, 'back.txt'))[0])
        net = y - back
        x = decimal_for_array(x, 20)
        y = decimal_for_array(y, 20)
        net = decimal_for_array(net, 20)
        back = decimal_for_array(back, 20)
        zhf.printdatatofile(os.path.join(result, 'xout.txt'), [x])
        zhf.printdatatofile(os.path.join(result, 'net.txt'), [net])
        zhf.printdatatofile(os.path.join(result, 'back.txt'), [back])
        zhf.printdatatofile(os.path.join(result, 'summary_t_obs_net_back.txt'),
                            [x, y, net, back])
        return x, y, net, back
    else:
        print('failed!!')
        print('I can not do the following!!')
        return False
Ejemplo n.º 3
0
from zjh_make_phaI import *
import zzh_py3_file as zhf
import os
from zjh_xspec_fit_kernel import xspec_fit_kernel
import matplotlib.pyplot as plt

data_topdir = '/home/laojin/trigdata/2017/'
result_topdir = '/home/laojin/results/results_GBM/2017/'

namelist = zhf.readcol(
    '/home/laojin/results/results_GBM/Y_all_sample_name.txt')[0]

yearnamelist = []

for i in namelist:
    if i[:4] == 'bn17':
        yearnamelist.append(i)

print('year name list:\n', yearnamelist)

for bnname in yearnamelist:
    file_1_link = result_topdir + bnname + '/good_NaI_detectors.txt'
    file_2_link = result_topdir + bnname + '/good_BGO_detectors.txt'
    file_3_link = result_topdir + bnname + '/0_pulse_edges.txt'
    save_all = result_topdir + 'A_spectrum_1/'
    save_all2 = result_topdir + 'A_spectrum_2/'
    if (os.path.exists(save_all) == False):
        os.makedirs(save_all)
    if (os.path.exists(save_all2) == False):
        os.makedirs(save_all2)
Ejemplo n.º 4
0
import numpy as np
import matplotlib.pyplot as plt
from astropy.io import fits
import zzh_py3_file as zhf
import os
from Calculate_duration import Plot
from Calculate_duration import get_txx
topdir = '/home/laojin/trigdata/2017/'

bn,ni = zhf.readcol('./samples.txt')

indexbn = np.argsort(bn)

samples = np.array([bn,ni]).T
samples = samples[indexbn]
savetop = './results/'

if os.path.exists(savetop) == False:
	os.makedirs(savetop)


time_start = -100
time_stop = 400
ch_top = 91
ch_buttum = 7
binsize = 0.064
for index,value in enumerate(samples):
	print('&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&')
	print(value)
	filedir = topdir+value[0]+'/'
	filename = zhf.findfile(filedir,'glg_tte_'+value[1]+'_'+value[0]+'*')[0]
Ejemplo n.º 5
0
	elif(name in sample_2):
		table.write(l+1,2*h+1,'2')
	elif(name in sample_3):
		table.write(l+1,2*h+1,'3')
	elif(name in sample_x):
		table.write(l+1,2*h+1,'x')
	else:
		table.write(l+1,2*h+1,'0')

file.save(topdir +'sample_all.xls')
'''
topdir = '/home/laojin/results/results_GBM/background/'
file_1 = 'b_sample.txt'
file_2 = 'b_sample2.txt'

sample_1, detector_1 = zhf.readcol(topdir + file_1)
sample_2, detector_2 = zhf.readcol(topdir + file_2)

sample = sample_1 + sample_2
detector = detector_1 + detector_2
table.write(0, 0, 'trigger name')
table.write(0, 1, 'detector')
table.write(0, 2, 'trigger name')
table.write(0, 3, 'detector')
table.write(0, 4, 'trigger name')
table.write(0, 5, 'detector')
for index, name in enumerate(sample):
    l = int(index / 3)
    h = index % 3
    table.write(l + 1, 2 * h, name)
    table.write(l + 1, 2 * h + 1, detector[index])
Ejemplo n.º 6
0
import zzh_py3_file as zhf
from zjh_fermi_daily_geometry import Fermi_daily_geometry
import numpy as np

timelist = zhf.readcol('/home/laojin/shiyan/result_time.txt')

posistion = []

for i in timelist[0]:
	print(i)
	qsj,pos,sc = Fermi_daily_geometry(i).find_right_list()
	if(sc[1]>180):
		sc[1] = sc[1]-360
	posistion.append(sc)
posistion = np.array(posistion).T
der = posistion[0]
ra = posistion[1]

#index = np.argsort(ra)
#ra = ra[index]
#der = der[index]

zhf.printdatatofile('/home/laojin/shiyan/SAA_point.txt',[ra,der])







import numpy as np
import matplotlib.pyplot as plt
import zzh_py3_file as zhf
import os
from glob import glob

namelist = zhf.readcol(
    '/home/laojin/results/results_GBM/Y_all_sample_name.txt')[0]
data_topdir = '/home/laojin/results/results_GBM/2017/'

savetop = '/home/laojin/results/spectrum_all/'

if (os.path.exists(savetop) == False):
    os.makedirs(savetop)

yearnamelist = []

for i in namelist:
    if i[:4] == 'bn17':
        yearnamelist.append(i)

print('year name list:\n', yearnamelist)

Epec = []
Epec_err = []
Flux = []
Flux_err = []

for bnname in yearnamelist:

    spectrum_dir = data_topdir + bnname + '/spectrum/'
Ejemplo n.º 8
0
import numpy as np
import matplotlib.pyplot as plt
import os
import zzh_py3_file as zhf

datadir = './data/lightcurve1.txt'

savedir = './results/'

if os.path.exists(savedir) == False:
    os.makedirs(savedir)
print('xxx')
t, v = zhf.readcol(datadir)
da = np.array([t, v]).T
#t,v = np.loadtxt(datadir,delimiter=' ')
print('xxx')

np.savetxt('./data/lightcurve1.txt', da, fmt='%0.4f')
plt.plot(t, v, color='k')
plt.savefig(savedir + 'lightcurve.png')
plt.close()