In [50]:
# imports
from scipy import interpolate
from specdb.specdb import IgmSpec
from pyigm.surveys.dlasurvey import DLASurvey
from pyigm.fN import dla as pyi_fd
from pyigm.fN.fnmodel import FNModel
#from xastropy.xutils import xdebug as xdb
sys.path.append(os.path.abspath("../../src"))
import training_set as tset
In [43]:
rstate = np.random.RandomState(1234)
In [3]:
igmsp = IgmSpec()
In [2]:
reload(tset)
slines, sdict = tset.grab_sightlines()
In [8]:
i3 = np.argmin(np.abs(slines['ZEM']-3.))
s3 = slines[i3]
spec3l, meta = igmsp.spec_from_coord((s3['RA'], s3['DEC']), isurvey=['SDSS_DR7'])
spec3 = spec3l[0]
In [11]:
spec3.wvmin.value/1215.67 - 1.
Out[11]:
In [48]:
zlya = spec3.wavelength.value/1215.67 - 1
dz = np.roll(zlya,-1)-zlya
dz[-1] = dz[-2]
dz
Out[48]:
In [49]:
### Cut on zem and 920A rest-frame
gdz = (zlya < s3['ZEM']) & (spec3.wavelength > 910.*u.AA*(1+s3['ZEM']))
In [25]:
reload(pyi_fd)
lz = pyi_fd.lX(zlya[gdz], extrap=True, calc_lz=True)
lz
Out[25]:
In [37]:
cum_lz = np.cumsum(lz*dz[gdz])
tot_lz = cum_lz[-1]
tot_lz
#xdb.xplot(cum_lz)
Out[37]:
In [39]:
ndla = np.random.poisson(tot_lz, 20)
ndla
Out[39]:
In [41]:
fzdla = interpolate.interp1d(cum_lz/tot_lz, zlya[gdz],bounds_error=False,fill_value=np.min(zlya[gdz]))#
In [46]:
randz = rstate.random_sample(100)
In [47]:
zdla = fzdla(randz)
zdla
Out[47]:
In [54]:
fN_model = FNModel.default_model()
In [57]:
lX, cum_lX, lX_NHI = fN_model.calculate_lox(fN_model.zpivot,
20.3,NHI_max=22.5, cumul=True)
xdb.xplot(lX_NHI, cum_lX)
In [58]:
fNHI = interpolate.interp1d(cum_lX/cum_lX[-1], lX_NHI,bounds_error=False,fill_value=lX_NHI[0])#
In [59]:
randNHI = rstate.random_sample(100)
In [60]:
dla_NHI = fNHI(randNHI)
dla_NHI
Out[60]:
In [63]:
rstate.rand?
In [1]:
from linetools.spectra import io as lsio
spec = lsio.readspec('/Users/xavier/Dropbox/MachineLearning/DLAs/training_20456_5000.hdf5')
In [2]:
spec.select = 2
spec.plot(xspec=True)
In [4]:
hdrlist = spec.meta['headers']
In [13]:
meta2 = hdrlist[1]
meta2['zem']
Out[13]:
In [8]:
import h5py
import json
In [7]:
hdf = h5py.File('/Users/xavier/Dropbox/MachineLearning/DLAs/training_20456_5000.hdf5','r')
In [9]:
meta = json.loads(hdf['meta'].value)
In [11]:
meta['headers'][2]
Out[11]:
In [ ]: