def test_make_map(self): params = Struct(map_maker="seek.mapmaking.healpy_mapper", nside=2, variance=False) npix = hp.nside2npix(params.nside) ind = 1 theta, phi = hp.pix2ang(params.nside, ind) dec = np.pi * .5 - theta ra = phi times = np.array([[0, 0, 0, ra, dec], [0, 0, 0, ra, dec]]) rfi_mask = np.array([[False, False]], dtype=bool) tod_vx = np.ma.array([[1., 2.]], mask=rfi_mask) tod_vy = np.ma.array([[2., 4.]], mask=rfi_mask) frequencies = np.array([1420.40575177]) ctx = Struct(params=params, frequencies=frequencies, times=times, tod_vx=tod_vx, tod_vy=tod_vy, coords=Coords(times[:, -2], times[:, -1], None, None, None)) plugin = make_maps.Plugin(ctx) plugin() assert len(ctx.map_idxs) == 3 assert ctx.maps[0] == tod_vx.sum() assert ctx.maps[1] == tod_vy.sum() assert ctx.counts[0] == tod_vx.shape[1] assert ctx.counts[1] == tod_vy.shape[1]
def __call__(self): if self.ctx.tod_vx.shape[0] > 0: date = self.ctx.strategy_start coord_path = self.ctx.coords_paths[format_date(date)] coords = np.genfromtxt(coord_path, delimiter = ',', names = True) time_axis = self.ctx.time_axis azs = np.radians(np.interp(time_axis, coords['Time'], coords['AzAntenna'])) els = np.radians(np.interp(time_axis, coords['Time'], coords['ElAntenna'])) obs = sphere.get_observer(self.ctx.params) strategy = convert_coords(date, time_axis, azs, els,obs) self.ctx.coords = Coords(strategy[:, 0], strategy[:, 1], azs, els, time_axis) else: self.ctx.coords = Coords([], [], [], [], [])
def test_sun_masking(self): tod = np.ma.array(np.random.uniform(size=(10,100)), mask=False) coords = Coords([4.14857973] * tod.shape[1], [-0.51101287] * tod.shape[1], [0.0] * tod.shape[1], [0.0] * tod.shape[1], [0.0] * tod.shape[1]) ctx = Struct(params=self.params, tod_vx = tod, tod_vy = tod, coords = coords, strategy_start=datetime(2014, 11, 25, 11, 00, 00)) plugin = mask_objects.Plugin(ctx) plugin.mask_objects() assert np.any(tod.mask == True)
def test_no_moon_sun_masking(self): tod = np.ma.array(np.random.uniform(size=(10,100)), mask=False) times = np.zeros((tod.shape[1], 5)) ctx = Struct(params=self.params, tod_vx = tod, tod_vy = tod, coords = Coords(times[:,0], times[:,1], times[:,1]*0.0, times[:,1]*0.0, times[:,1]*0.0), strategy_start=datetime(2015, 01, 01, 00, 00, 00)) plugin = mask_objects.Plugin(ctx) plugin.mask_objects() assert np.all(tod.mask == False)
def test_moon_masking(self): tod = np.ma.array(np.random.uniform(size=(10, 100)), mask=False) ras = np.linspace(1.5, 2.5, tod.shape[1]) decs = [0.26] * tod.shape[1] times = np.linspace(0, 4, tod.shape[1]) coords = Coords(ras, decs, None, None, times) ctx = Struct(params=self.params, tod_vx=tod, tod_vy=tod, coords=coords, strategy_start=datetime(2015, 12, 26, 00, 00, 00)) plugin = mask_objects.Plugin(ctx) plugin.mask_objects() assert np.any(tod.mask == True)
def __call__(self): filename = os.path.basename(self.ctx.file_paths[0]) filepath = os.path.join(self.ctx.params.post_processing_prefix, filename) if self.ctx.params.verbose: print(filepath) self.ctx.strategy_start = load_data.get_observation_start_from_hdf5( filepath) with h5py.File(filepath, "r") as fp: tod = np.ma.array(fp["data"].value, mask=fp["mask"].value) self.ctx.tod_vx = tod self.ctx.tod_vy = tod.copy() self.ctx.frequencies = fp["frequencies"].value self.ctx.time_axis = fp["time"].value self.ctx.coords = Coords(fp["ra"].value, fp["dec"].value, None, None, self.ctx.time_axis) self.ctx.ref_channel = fp["ref_channel"].value
def test_bkg_removal_smooth(self): tod = np.ones((5, 9)) * np.arange(9) mask = np.zeros((5, 9)) mask[:, 0] = 1 mask[:, -1] = 1 mask = mask.astype('bool') ctx = Struct(params=Struct(background_model="smooth", struct_size_0=1, struct_size_1=1, nside=1), tod_vx=np.ma.array(tod, mask=mask), tod_vy=np.ma.array(tod, mask=mask), time_axis=np.arange(9), coords=Coords(np.zeros(9), np.zeros(9), None, None, None), simulation_mask=np.zeros(9, dtype=np.bool)) plugin = background_removal.Plugin(ctx) plugin() assert np.all(ctx.tod_vx.sum(axis=1) == 0) assert np.all(ctx.tod_vy.sum(axis=1) == 0)
def test_get_map(self): params = Struct(nside=2, variance=False) npix = hp.nside2npix(params.nside) ind = 1 theta, phi = hp.pix2ang(params.nside, ind) dec = np.pi * .5 - theta ra = phi times = np.array([[0,0,0,ra,dec],[0,0,0,ra,dec]]) rfi_mask = np.array([[False, False]], dtype = bool) tod_vx = np.ma.array([[1., 2.]], mask=rfi_mask) tod_vy = np.ma.array([[2., 4.]], mask=rfi_mask) frequencies = np.array([1420.40575177]) ctx = Struct(params = params, frequencies = frequencies, times = times, tod_vx = tod_vx, tod_vy = tod_vy, coords = Coords(times[:,-2], times[:,-1], None, None, None) ) maps, z, counts = healpy_mapper.get_map(ctx) t = np.zeros((1, 2, npix)) t[0, 0, 1] = 3. t[0, 1, 1] = 6. assert np.allclose(maps, t) t[0, 0, 1] = 2 t[0, 1, 1] = 2 assert np.allclose(counts, t) assert np.isclose(z, 0) ctx.params.variance = True maps, z, counts = healpy_mapper.get_map(ctx) t[0, 0, 1] = .5 t[0, 1, 1] = 2. assert np.allclose(maps, t)