forked from marcoviero/simstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.py
37 lines (30 loc) · 1.03 KB
/
bootstrap.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
# Standard modules
import pdb
import os.path
import sys
import six
import shutil
import time
import logging
import importlib
import numpy as np
import pandas as pd
import astropy.units as u
from astropy.wcs import WCS
class Bootstrap:
def __init__(self,tbl):
self.table = tbl[['ID','sfg','ra','dec','z_peak','z_err','LMASS','LMASS_ERR']]
def perturb_catalog(self, perturb_z = False, draw_z = False):
'''
Default is a simple bootstrap with replacement.
If perturb_z is True, then the redshifts (z_peak) are perturbed by random normal with sigma z_err
If draw_z is True, then the redshifts are drawn from the redshift PDF (output by EAZY) of each object (TODO!)
'''
pseudo_cat = self.table.copy()
ngals = len(pseudo_cat)
if perturb_z == True:
pseudo_z = self.table['z_peak'] + self.table['z_err']*np.random.randn(len(self.table['z_err']))
pseudo_cat['z_peak'] = pseudo_z
#Simple Bootstrap. Sample draws from pseudo_cat with replacement.
self.pseudo_cat = pseudo_cat.sample(ngals,replace=True)
#pdb.set_trace()