<jupyter_start><jupyter_text>Examples for IGM $f(N)$ constraints (v1.1)<jupyter_code>%matplotlib inline
# imports
try:
    import seaborn as sns; sns.set_style("white")
except:
    pass

import time
import imp

import bokeh
from bokeh.io import output_notebook, show, hplot, output_file
from bokeh.plotting import figure
from bokeh.models import Range1d

output_notebook()

from pyigm.fN.fnmodel import FNModel
from pyigm.fN.constraints import FNConstraint

from pyigm.fN import tau_eff as teff

pyigm_path = imp.find_module('pyigm')[1]<jupyter_output>/Users/xavier/anaconda/lib/python2.7/site-packages/matplotlib/__init__.py:872: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
  warnings.warn(self.msg_depr % (key, alt_key))<jupyter_text>Load  Vanilla constraints<jupyter_code>fn_file = pyigm_path+'/data/fN/fn_constraints_z2.5_vanilla.fits'
k13r13_file = pyigm_path+'/data/fN/fn_constraints_K13R13_vanilla.fits'
n12_file = pyigm_path+'/data/fN/fn_constraints_N12_vanilla.fits'
#reload(fNc)
all_fN_cs = FNConstraint.from_fitsfile([fn_file,k13r13_file, n12_file])
len(all_fN_cs)<jupyter_output><empty_output><jupyter_text>Remove K02<jupyter_code>fN_cs = [fN_c for fN_c in all_fN_cs if ((fN_c.ref != 'K02') & (fN_c.ref != 'PW09'))]
fN_dtype = [fc.fN_dtype for fc in fN_cs]
fN_cs<jupyter_output><empty_output><jupyter_text>Plot $f(N)$  $f(N)$ Model<jupyter_code>fN_model = FNModel.default_model()<jupyter_output>Using P14 spline values to generate a default model
Loading: /Users/xavier/local/Python/pyigm/pyigm/data/fN/fN_spline_z24.fits.gz<jupyter_text>Data dict<jupyter_code>data_dict = dict(Nbin=[], fN=[], ref=[], pcolor=[], zeval=[])
clrs = ['blue', 'green', 'red', 'purple']
cnt=0
for fN_c in fN_cs: 
    if fN_c.fN_dtype == 'fN':
        # Length
        ip = range(fN_c.data['NPT'])
        val = np.where(fN_c.data['FN'][ip] > -90)[0]
        npt = len(val)
        # Add in
        if npt > 0:
            ipv = np.array(ip)[val]
            data_dict['Nbin'] += list(np.median(fN_c.data['BINS'][:,ipv],0))
            #xerror = [ fN_c.data['BINS'][1,ipv]-xval, xval-fN_c.data['BINS'][0,ipv] ]
            #yerror = [ fN_c.data['SIG_FN'][1,ipv], fN_c.data['SIG_FN'][0,ipv] ] # Inverted!
            data_dict['fN'] += list(fN_c.data['FN'][ipv])
            data_dict['ref'] += [fN_c.ref]*npt
            data_dict['pcolor'] += [clrs[cnt]]*npt
            data_dict['zeval'] += [fN_c.zeval]*npt
            cnt += 1
plot_source = bokeh.models.ColumnDataSource(data_dict)
if fN_model is not None: 
    xplt = 12.01 + 0.01*np.arange(1100)
    line_dict = dict(xplt=xplt,
                     yplt=fN_model.evaluate(xplt, 2.4).flatten(),
                     ref=['P14']*1100, zeval=[fN_model.zpivot]*1100)
    model_source = bokeh.models.ColumnDataSource(line_dict)
p = bokeh.plotting.figure(tools="reset, hover, tap, resize, wheel_zoom, pan",
                          title="f(N)",
                          x_axis_label="log N_HI",
                          y_axis_label="log f(N)")
#
if fN_model is not None:
    p.line("xplt", "yplt", source=model_source, color='black', line_width=2, legend='P14')
# plot our data
data = p.scatter("Nbin", "fN", 
          source=plot_source, 
          color="pcolor", 
          size=8, legend='data')
# print useful data when you hover
hover = p.select(bokeh.models.HoverTool)
hover.tooltips = {"Ref"    : "@ref",
                  "redshift" : "@zeval"}
#
show(p)<jupyter_output><empty_output><jupyter_text>Plot other constraints<jupyter_code>con_dict = dict(xval=[], value=[], error=[], ftype=[], pcolor=[], ref=[], zeval=[])<jupyter_output><empty_output><jupyter_text>$\tau_{\rm eff}$<jupyter_code>itau = fN_dtype.index('teff') # Passes back the first one
fN_cs[itau].data['TEFF']
itau = fN_dtype.index('teff')     
con_dict['value'] += [float(fN_cs[itau].data['TEFF'])]
D_A = 1. - np.exp(-1. * con_dict['value'][0])
SIGDA_LIMIT = 0.1  # Allows for systemtics and b-value uncertainty
con_dict['error'] += [np.max([fN_cs[itau].data['SIG_TEFF'], (SIGDA_LIMIT*con_dict['value'][0])])]
con_dict['pcolor'] += ['blue']
con_dict['ref'] += [fN_cs[itau].ref]
con_dict['zeval'] += [fN_cs[itau].zeval]
con_dict['xval'] += [1]
con_dict['ftype'] += ['tau_eff']<jupyter_output><empty_output><jupyter_text>$\ell(X)$<jupyter_code>iLLS = fN_dtype.index('LLS') # Passes back the first one
con_dict['value'] += [fN_cs[iLLS].data['LX']]
con_dict['error'] += [fN_cs[iLLS].data['SIG_LX']]
con_dict['pcolor'] += ['green']
con_dict['ref'] += [fN_cs[iLLS].ref]
con_dict['zeval'] += [fN_cs[iLLS].zeval]
con_dict['xval'] += [2]
con_dict['ftype'] += ['l(X)']<jupyter_output><empty_output><jupyter_text>$\lambda_{\rm mfp}$<jupyter_code>iMFP = fN_dtype.index('MFP') 
con_dict['value'] += [fN_cs[iMFP].data['MFP']/500]
con_dict['error'] += [fN_cs[iMFP].data['SIG_MFP']/500]
con_dict['pcolor'] += ['red']
con_dict['ref'] += [fN_cs[iMFP].ref]
con_dict['zeval'] += [fN_cs[iMFP].zeval]
con_dict['xval'] += [3]
con_dict['ftype'] += ['MFP/(500 Mpc)']<jupyter_output><empty_output><jupyter_text>Model<jupyter_code>x_model = [1,2,3]
y_model = [None]*3
# teff
y_model[0] = teff.lyman_ew(1215.6701*(1+fN_cs[itau].zeval), 
                           fN_cs[itau].zeval+0.1, fN_model, 
                           NHI_MIN=fN_cs[itau].data['NHI_MNX'][0],
                           NHI_MAX=fN_cs[itau].data['NHI_MNX'][1])
# l(X)
y_model[1] = fN_model.calculate_lox(fN_cs[iLLS].zeval, 
                                    17.19+np.log10(fN_cs[iLLS].data['TAU_LIM']), NHI_max=22.)
# MFP
y_model[2] = fN_model.mfp(fN_cs[iMFP].zeval).value / 500.
x_model, y_model<jupyter_output><empty_output><jupyter_text>Plot<jupyter_code>con_source = bokeh.models.ColumnDataSource(con_dict)
p = bokeh.plotting.figure(tools="reset, hover, tap, resize, wheel_zoom, pan",
                          title="Integral Constraints",
                          y_axis_label="Value")
# Constraints
p.scatter("xval", "value", source=con_source, color="pcolor", size=7)
err_xs = []
err_ys = []
for x, y, yerr in zip(con_dict['xval'], con_dict['value'], con_dict['error']):
    err_xs.append((x, x))
    err_ys.append((y - yerr, y + yerr))
p.multi_line(err_xs, err_ys, color='gray', line_width=2)
#
p.text(con_dict['xval'], [0.]*3, con_dict['ftype'], text_color=con_dict['pcolor'],
      text_align="center")
# Model
p.square(x_model, y_model, color='black', fill_color=None, size=10, line_width=2, legend='Model')
# Hover
hover = p.select(bokeh.models.HoverTool)
hover.tooltips = {"Ref"    : "@ref",
                  "Type"   : "@ftype", 
                  "Value"  : "@value", 
                  "Error"  : "@error", 
                  "redshift" : "@zeval"}
# style
p.xgrid.grid_line_color = None
p.ygrid.grid_line_color = None
p.xaxis.major_label_text_color = None
p.set(x_range=Range1d(0.5,3.5), y_range=Range1d(0.,0.6))
p.legend.orientation = "top_left"
#
show(p)<jupyter_output>/Users/xavier/anaconda/lib/python2.7/site-packages/bokeh/core/properties.py:714: BokehDeprecationWarning: bokeh.models.annotations.orientation was deprecated in Bokeh 0.11; please use Legend.location instead
  super(HasProps, self).__setattr__(name, value)
{'fraction_non_alphanumeric': 0.178357272346953, 'fraction_numerical': 0.0209175847162181, 'mean_word_length': 4.193338160753077, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '547389', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 3063, 'n_tokens_neox': 2956, 'n_words': 425, 'path': 'docs/examples/fNConstraint_examples.ipynb', 'repo_name': 'pyigm/pyigm', 'size': '7171'}