-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtxt_gen.py
94 lines (63 loc) · 3.1 KB
/
txt_gen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
from astropy.io import fits
import random as rn
import pandas as pd
import sys,os
class MockLightCurve(object):
def __init__(self,filepath=None):
assert (filepath is not None), "No file name is specified."
self.filepath = filepath
try:
self.data = fits.open(self.filepath)
except IOError:
print("Error: file {0} could not be found".format(filepath))
exit()
data = fits.open(self.filepath)
self.z = data[0].header['Z']
self.L = data[0].header['L']
self.lagCIV = data[0].header['AGNLAGC']
self.lagMgII = data[0].header['AGNLAGM']
self.lagHbeta = data[0].header['AGNLAGH']
self.r_mag = data[0].header['RAPPMAG']
self.mBH = data[0].header['MBH']
self.underlyinglcs = data[1].data
self.ucDim = np.shape(self.underlyinglcs)
self.cadence = data[2].data
self.cad1Dim = np.shape(self.cadence)
def txt_gen(stats, phys_stats, lag_fracs, num_reals):
name = int(phys_stats[0])
mean_err_cont = stats[1]
std_err_cont = stats[3]
mean_err_line = stats[2]
std_err_line = stats[4]
for i in range(len(lag_fracs)):
dir_fits ='Data/'+ str(name)+'/'+str(lag_fracs[i])+'/'
dir_txt = dir_fits+'txt/'
if not os.path.exists(dir_txt):
os.makedirs(dir_txt)
mock = MockLightCurve(dir_fits+str(name)+'_'+str(lag_fracs[i])+'_sim.fits')
for k in range(num_reals):
#read in continuum flux from one
mjd1 = np.arange(0,5000) #mock1.measuredCont[:, 0, 0]
flux1 = mock.underlyinglcs[ 0,:, k]
#read in line flux from the other
mjd2 = np.arange(0,5000) #mock1.measuredCont[:, 0, 0]
flux2 = mock.underlyinglcs[1,:,k]
cadence_cont = mock.cadence[0,:]
cadence_line = mock.cadence[1,:]
cadence_cont[4000:5000] = 0
out_cont = open(dir_txt+str(name)+'_'+str(k)+'_'+str(lag_fracs[i])+'_cont.txt','w')
out_line = open(dir_txt+str(name)+'_'+str(k)+'_'+str(lag_fracs[i])+'_line.txt','w')
for n in range(len(cadence_cont)):
line_err = np.random.normal(mean_err_line,std_err_line)
cont_err = np.random.normal(mean_err_cont,std_err_cont)
line_shift = np.mean(flux2)*mean_err_line*np.random.normal(0,0.3)
cont_shift = np.mean(flux1)*mean_err_cont*np.random.normal(0,0.3)
if cadence_cont[n] == 1:
out_cont.write(str(mjd1[n])+ '\t' + str(flux1[n]+cont_shift) +'\t' + str(flux1[n]*(cont_err))+'\n')
if cadence_line[n] ==1:
out_line.write(str(mjd2[n])+ '\t' + str((flux2[n]+line_shift)) +'\t' + str(flux2[n]*(line_err))+'\n')
out_cont.close()
out_line.close()