e


In [ ]:


In [1]:
def detection_efficiency(x, y):
    return 1 / (1 + np.exp((x**2 / np.sqrt(y) - 1) / 0.1))

In [2]:
x, y = np.linspace(1, 2, 101), np.linspace(1, 10, 103)
X, Y = np.meshgrid(x, y, indexing="ij")
pl.pcolor(X, Y, detection_efficiency(X, Y), cmap="gray")
pl.xlim(min(x), max(x))
pl.ylim(min(y), max(y))
pl.colorbar();


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-2-d47d88d25d00> in <module>()
----> 1 x, y = np.linspace(1, 2, 101), np.linspace(1, 10, 103)
      2 X, Y = np.meshgrid(x, y, indexing="ij")
      3 pl.pcolor(X, Y, detection_efficiency(X, Y), cmap="gray")
      4 pl.xlim(min(x), max(x))
      5 pl.ylim(min(y), max(y))

NameError: name 'np' is not defined

In [3]:
bin_edges = np.linspace(min(y), max(y), 11)
int_comp = np.empty(len(bin_edges) - 1)
x0 = np.random.uniform(min(x), max(x), 50000)
for i in range(len(int_comp)):
    y0 = np.random.uniform(bin_edges[i], bin_edges[i + 1], len(x0))
    int_comp[i] = np.mean(detection_efficiency(x0, y0))


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-3-cb834c6cb598> in <module>()
----> 1 bin_edges = np.linspace(min(y), max(y), 11)
      2 int_comp = np.empty(len(bin_edges) - 1)
      3 x0 = np.random.uniform(min(x), max(x), 50000)
      4 for i in range(len(int_comp)):
      5     y0 = np.random.uniform(bin_edges[i], bin_edges[i + 1], len(x0))

NameError: name 'np' is not defined

In [4]:
def plot_histogram(bin_edges, bin_heights, reluncert=None, **kwargs):
    x = np.array(list(zip(bin_edges[:-1], bin_edges[1:]))).flatten()
    y = np.array(list(zip(bin_heights, bin_heights))).flatten()
    pl.plot(x, y, **kwargs)
    if reluncert is not None:
        pl.errorbar(0.5 * (bin_edges[:-1] + bin_edges[1:]), bin_heights,
                    yerr=bin_heights * reluncert, fmt="+", capsize=0,
                    color=kwargs.get("color", "k"))

In [5]:
plot_histogram(bin_edges, int_comp, color="k")
pl.ylim(0, 1);


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-5-60ef8bd77522> in <module>()
----> 1 plot_histogram(bin_edges, int_comp, color="k")
      2 pl.ylim(0, 1);

NameError: name 'bin_edges' is not defined

In [6]:
true_samp = np.random.multivariate_normal([1.5, 6], [[1.0, 0.0], [0.0, 4.0]], size=5000)
true_samp = true_samp[(min(x) < true_samp[:, 0]) * (true_samp[:, 0] < max(x))
                      * (min(y) < true_samp[:, 1]) * (true_samp[:, 1] < max(y))]

m = np.random.rand(len(true_samp)) < detection_efficiency(true_samp[:, 0], true_samp[:, 1])
obs_samp = true_samp[m]
obs_det = detection_efficiency(obs_samp[:, 0], obs_samp[:, 1])


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-6-79f270d29f1b> in <module>()
----> 1 true_samp = np.random.multivariate_normal([1.5, 6], [[1.0, 0.0], [0.0, 4.0]], size=5000)
      2 true_samp = true_samp[(min(x) < true_samp[:, 0]) * (true_samp[:, 0] < max(x))
      3                       * (min(y) < true_samp[:, 1]) * (true_samp[:, 1] < max(y))]
      4 
      5 m = np.random.rand(len(true_samp)) < detection_efficiency(true_samp[:, 0], true_samp[:, 1])

NameError: name 'np' is not defined

In [7]:
pl.pcolor(X, Y, detection_efficiency(X, Y), cmap="gray")
pl.plot(true_samp[~m, 0], true_samp[~m, 1], ".r", ms=3)
pl.plot(obs_samp[:, 0], obs_samp[:, 1], ".b", ms=3)
pl.xlim(min(x), max(x))
pl.ylim(min(y), max(y));


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-7-98fa072364a8> in <module>()
----> 1 pl.pcolor(X, Y, detection_efficiency(X, Y), cmap="gray")
      2 pl.plot(true_samp[~m, 0], true_samp[~m, 1], ".r", ms=3)
      3 pl.plot(obs_samp[:, 0], obs_samp[:, 1], ".b", ms=3)
      4 pl.xlim(min(x), max(x))
      5 pl.ylim(min(y), max(y));

NameError: name 'pl' is not defined

In [8]:
bin_areas = np.diff(bin_edges)
pl.hist(true_samp[:, 1], bin_edges, color="k", histtype="step", lw=3, alpha=0.2)

n0, _ = np.histogram(obs_samp[:, 1], bin_edges)
n1, _ = np.histogram(obs_samp[:, 1], bin_edges, weights=1.0 / obs_det)

plot_histogram(bin_edges, n0 / int_comp, 1 / np.sqrt(n0), color="k", ls="--")
plot_histogram(bin_edges, n1, 1 / np.sqrt(n0), color="k", ls=":")


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-8-a5bf51d340da> in <module>()
----> 1 bin_areas = np.diff(bin_edges)
      2 pl.hist(true_samp[:, 1], bin_edges, color="k", histtype="step", lw=3, alpha=0.2)
      3 
      4 n0, _ = np.histogram(obs_samp[:, 1], bin_edges)
      5 n1, _ = np.histogram(obs_samp[:, 1], bin_edges, weights=1.0 / obs_det)

NameError: name 'np' is not defined

In [ ]: