Beispiel #1
0
def test_smooth_coeval():
    '''
	With this, smooth_coeval_gauss, smooth_coeval_tophat, gauss_kernel and tophat_kernel
	are also tested.
	'''
    smt = t2c.smooth_coeval(data, 9, box_size_mpc=90)
    assert smt[4, 4, 4] < 1
Beispiel #2
0
    def _smt_xH(self, xH_box, idx):
        assert idx == self.astro_par[0,idx]
        z = self.astro_par[1, idx]

        smt_xn = t2c.smooth_coeval(xH_box, z, box_size_mpc=self.user_par['HII_DIM'], max_baseline=2.0, ratio=1.0, nu_axis=2)
        mask_xn = smt_xn>0.5

        return mask_xn.astype(int)
Beispiel #3
0
    def _lc_noise_smt_dT(self, lc1, idx):
        assert idx == self.astro_par[0,idx]
        z = self.astro_par[1, idx]

        noise_lc = t2c.noise_lightcone(ncells=lc.brightness_temp.shape[0], zs=lc.lightcone_redshifts, obs_time=self.tobs, save_uvmap=self.uvfile, boxsize=self.user_par['BOX_LEN'])

        # calculate uv-coverage 
        if(self.zipf):
            with zipfile.ZipFile(self.path_uvcov) as myzip: 
                with myzip.open('uv_coverage_%d/uvmap_z%.3f.npy' %(self.user_par['HII_DIM'], z)) as myfile1: 
                    uv = np.load(myfile1)
                with myzip.open('uv_coverage_%d/Nantmap_z%.3f.npy' %(self.user_par['HII_DIM'], z)) as myfile2: 
                    Nant = np.load(myfile2)
        else:
            file_uv = '%suvmap_z%.3f.npy' %(self.path_uvcov, z)
            file_Nant = '%sNantmap_z%.3f.npy' %(self.path_uvcov, z)

            if(os.path.exists(file_uv) and os.path.exists(file_Nant)):
                    uv = np.load(file_uv)
                    Nant = np.load(file_Nant)
            else:
                #SKA-Low 2016 configuration
                uv, Nant = t2c.get_uv_daily_observation(self.user_par['HII_DIM'], z, filename=None,
                                                        total_int_time=6.0, int_time=10.0,
                                                        boxsize=self.user_par['BOX_LEN'],
                                                        declination=-30.0, verbose=False)
                np.save(file_uv, uv)
                np.save(file_Nant, Nant)

        # calculate Noise cube
        random.seed(datetime.now())
        noise_cube = t2c.noise_cube_coeval(self.user_par['HII_DIM'], z, depth_mhz=None,
                                        obs_time=self.tobs, filename=None, boxsize=self.user_par['BOX_LEN'],
                                        total_int_time=6.0, int_time=10.0, declination=-30.0, 
                                        uv_map=uv, N_ant=Nant, fft_wrap=False, verbose=False)

        dT3 = t2c.smooth_coeval(dT1+noise_cube, z, 
                                box_size_mpc=self.user_par['HII_DIM'],
                                max_baseline=2.0, ratio=1.0, nu_axis=2)

        return dT3
Beispiel #4
0
                                           depth_mhz=None,
                                           obs_time=t,
                                           filename=None,
                                           boxsize=params['BOX_LEN'],
                                           total_int_time=6.0,
                                           int_time=10.0,
                                           declination=-30.0,
                                           uv_map=uv,
                                           N_ant=Nant,
                                           verbose=True,
                                           fft_wrap=False)
        dT1 = t2c.subtract_mean_signal(dT, los_axis=2)
        dT2 = dT1 + noise_cube
        dT3 = t2c.smooth_coeval(dT2,
                                z,
                                box_size_mpc=params['HII_DIM'],
                                max_baseline=2.0,
                                ratio=1.0,
                                nu_axis=2)
        smt_xn = t2c.smooth_coeval(xH,
                                   z,
                                   box_size_mpc=params['HII_DIM'],
                                   max_baseline=2.0,
                                   ratio=1.0,
                                   nu_axis=2)
        mask_xn = smt_xn > 0.5

        # calculate error and prediction
        X_tta = SegUnet21cmPredict(unet=model, x=dT3, TTA=False)
        X_seg = np.round(np.mean(X_tta, axis=0))

        # calculate MCC score
Beispiel #5
0
import tools21cm as t2c

### Setting the simulation environment
t2c.set_sim_constants(244)

### Reading files
xfrac_filename = '/disk/dawn-1/garrelt/Reionization/C2Ray_WMAP7/244Mpc/244Mpc_f2_0_250/results/xfrac3d_6.418.bin'
dens_filename = '/disk/dawn-1/sgiri/simulations/244Mpc/coarser_densities/nc250/6.418n_all.dat'

xfrac = t2c.read_c2ray_files(xfrac_filename,
                             file_type='xfrac')  # Ionization fraction file
neut = 1 - xfrac  # Neutral fraction file

dens = t2c.read_c2ray_files(dens_filename, file_type='dens')  # Density file

### Redshift from filename.....It can be manually given also
z = float(xfrac_filename.split('_')[-1].split('.b')[0])

### Making 21-cm coeval cube
dt = t2c.calc_dt(xfrac, dens, z)

### Smoothing neutral field to SKA resolution
smt_dt = t2c.smooth_coeval(dt, z)

### Generating the binary field from 21-cm signal using KMeans
bin_xf_sim = t2c.threshold_kmeans_3cluster(dt, upper_lim=True, n_jobs=5)
bin_nf_sim = 1. - bin_xf_sim  # The neutral binary field at Sim-Res

bin_xf_smt = t2c.threshold_kmeans_3cluster(smt_dt, upper_lim=True, n_jobs=5)
bin_nf_smt = 1. - bin_xf_smt  # The neutral binary field at Sim-Res
Beispiel #6
0
### Setting the simulation environment
t2c.set_sim_constants(244)

### Reading files
xfrac_filename = '/disk/dawn-1/garrelt/Reionization/C2Ray_WMAP7/244Mpc/244Mpc_f2_0_250/results/xfrac3d_6.450.bin'

xfrac = t2c.read_c2ray_files(xfrac_filename,
                             file_type='xfrac')  # Ionization fraction file
neut = 1 - xfrac  # Neutral fraction file

### Redshift from filename.....It can be manually given also
z = float(xfrac_filename.split('_')[-1].split('.b')[0])

### Smoothing neutral field to SKA resolution
smt_neut = t2c.smooth_coeval(neut, z)

### Generating the binary fields
xth = 0.5  # The fixed threshold to identify the regions of interest
bin_neut = neut > xth
bin_smt = smt_neut > xth

### Looking at the slices
fig, axes = plt.subplots(nrows=2, ncols=2)
fig.subplots_adjust(left=0.07,
                    bottom=0.06,
                    right=0.90,
                    top=0.96,
                    wspace=0.01,
                    hspace=0.15)
im00 = axes[0, 0].imshow(neut[:, :, 125], vmin=0, vmax=1)