def padproj(sptmap, padding=(4000, 4000), squaremap=True, proj0=True): sptmap = np.pad(np.asarray(sptmap), padding, mode='constant') if squaremap == True: sptmap = sptmap[:, int((sptmap.shape[1] / 2) - (sptmap.shape[0] / 2)):int((sptmap.shape[1] / 2) + (sptmap.shape[0] / 2))] sptmap = maps.FlatSkyMap( sptmap.copy(order='C'), 0.25 * core.G3Units.arcmin, weighted=False, proj=maps.MapProjection.Proj5, alpha_center=0 * core.G3Units.deg, delta_center=-57.5 * core.G3Units.deg, coord_ref=maps.MapCoordReference.Equatorial, units=core.G3TimestreamUnits.Tcmb, pol_type=maps.MapPolType.T, ) if proj0 == True: MapProj0 = map_3g.Clone(False) MapProj0.proj = maps.MapProjection.Proj0 maps.reproj_map(map_3g, MapProj0, interp=True) sptmap = MapProj0 return sptmap
good_wafers = [] for wafer in args.wafers_to_include: if wafer not in [None, '']: good_wafers.append(wafer.capitalize()) # Suppress warnings about timestream missing from scan frame if args.split_left_right: core.set_log_level(core.G3LogLevel.LOG_ERROR, 'MapBinner') # ----------------------------------------------------------------------------- # Generate map stubs for use later in pipeline. # ----------------------------------------------------------------------------- map_params = maps.FlatSkyMap( x_len = x_len, y_len = y_len, res = res, proj = proj, alpha_center = ra, delta_center = dec, pol_type = maps.MapPolType.T, coord_ref = maps.MapCoordReference.Equatorial) # Set up an empty map for point source filtering if args.mask_point_sources and args.point_source_file not in [None, '']: ps_params = maps.FlatSkyMap( x_len = x_len, y_len = y_len, res = res, proj = proj, alpha_center = ra, delta_center = dec, pol_type = maps.MapPolType.T, coord_ref = maps.MapCoordReference.Equatorial) # Fill map with the point source mask sources.source_utils.make_point_source_map( ps_params, args.point_source_file) ps_map_id = 'PointSourceMask'
def healpix_to_flatsky( map_in, nest=False, map_stub=None, rebin=1, interp=False, **kwargs ): """ Re-pixelize a map from Healpix to one of the flat sky projections. Parameters: ----------- map_in: numpy array or HealpixSkyMap The array containing the input healpix map to reproject. nest[False]: bool Ordering of the healpix map, if the input is a numpy array. Ring ordering is assumed by default. map_stub[None]: FlatSkyMap Stub output map object to be used to construct the output map. If not supplied, one will be constructed using the remaining keyword arguments. rebin[1]: int If supplied and >1, account for sub-pixel structure by integrating over a sub-grid on each pixel of the given dimension. This avoids aliasing of power at angular scales beyond the map resolution. interp[false]: bool If True, use bilinear interpolation to extract values from the input map. Otherwise, the nearest-neighbor value is used. All additional keyword arguments are passed to FlatSkyMap to construct the output map object. Required if `map_stub` is not supplied, otherwise ignored. Returns: -------- output_map: FlatSkyMap The reprojected map """ # Construct the output map if map_stub is None: if isinstance(map_in, maps.HealpixSkyMap): kwargs.setdefault("coord_ref", map_in.coord_ref) kwargs.setdefault("pol_type", map_in.pol_type) kwargs.setdefault("pol_conv", map_in.pol_conv) map_out = maps.FlatSkyMap(**kwargs) else: if not isinstance(map_stub, maps.FlatSkyMap): raise TypeError("Output stub must be a FlatSkyMap") map_out = map_stub.Clone(False) # Populate output map pixels with interpolation and rebinning if not isinstance(map_in, maps.HealpixSkyMap): map_in = maps.HealpixSkyMap( map_in, nested=nest, coord_ref=map_out.coord_ref, weighted=map_out.weighted, units=map_out.units, pol_type=map_out.pol_type, pol_conv=map_out.pol_conv, ) maps.reproj_map(map_in, map_out, rebin=rebin, interp=interp) return map_out
def healpix_to_flatsky(map_in, nest=False, map_stub=None, rebin=1, interp=False, **kwargs): """ Re-pixelize a map from Healpix to one of the flat sky projections. Parameters: ----------- map_in: numpy array or HealpixSkyMap The array containing the input healpix map to reproject. nest[False]: bool Ordering of the healpix map, if the input is a numpy array. Ring ordering is assumed by default. map_stub[None]: FlatSkyMap Stub output map object to be used to construct the output map. If not supplied, one will be constructed using the remaining keyword arguments. rebin[1]: int If supplied and >1, subdivide the output pixel by n x n with each sub-pixel taking on the input map values at pixel center (with interp or nearest neighbor). The output pixel takes on the average of the sub-pixel values. In the case that the input map has higher resolution than the output map (and that the input map is not low-pass filtered to remove information above the Nyquist freq. of the output map pixel), this reduces aliasing compared with direct sampling. But there would still be aliased power from the input map from freq above the ouput map pixel's Nyquist. interp[false]: bool If True, use bilinear interpolation to extract values from the input map. Otherwise, the nearest-neighbor value is used. All additional keyword arguments are passed to FlatSkyMap to construct the output map object. Required if `map_stub` is not supplied, otherwise ignored. Maps can be rotated between Equatorial and Galactic coordinates, and/or change polarization convention between COSMO and IAU, by setting the appropriate attributes of the input and output maps. Note that if the input map is a numpy array representation of a healpix map, the coordinate system and polarization convention are assumed to be that of the output map. Conversely, attributes not defined in the output map are assumed to be that of the input map. Returns: -------- output_map: FlatSkyMap The reprojected map """ # Construct the output map if map_stub is None: if len(kwargs) == 0: raise ValueError( "Need to provide either a stub map or map parameters (projection, center, etc.)" ) if isinstance(map_in, maps.HealpixSkyMap): kwargs.setdefault("coord_ref", map_in.coord_ref) kwargs.setdefault("pol_type", map_in.pol_type) kwargs.setdefault("pol_conv", map_in.pol_conv) map_out = maps.FlatSkyMap(**kwargs) else: if not isinstance(map_stub, maps.FlatSkyMap): raise TypeError("Output stub must be a FlatSkyMap") map_out = map_stub.clone(False) # Populate output map pixels with interpolation and rebinning if not isinstance(map_in, maps.HealpixSkyMap): map_in = maps.HealpixSkyMap( map_in, nested=nest, coord_ref=map_out.coord_ref, weighted=map_out.weighted, units=map_out.units, pol_type=map_out.pol_type, pol_conv=map_out.pol_conv, ) maps.reproj_map(map_in, map_out, rebin=rebin, interp=interp) return map_out
arr = np.arange(dim * dim).reshape(dim, dim) res = core.G3Units.arcmin deg = core.G3Units.deg a0 = 20 * deg d0 = -50 * deg x0 = 120 y0 = 180 verbose = False error = '' fm0 = maps.FlatSkyMap(dim, dim, res, proj=maps.MapProjection.ProjZEA, alpha_center=a0, delta_center=d0, x_center=x0, y_center=y0) print('Checking projections for dim {}'.format(dim)) if verbose: print('-' * 80) for p in [0, 1, 2, 3, 4, 5, 6, 7, 9]: if verbose: print('Checking Proj{}'.format(p)) proj = getattr(maps.MapProjection, 'Proj{}'.format(p)) fm1 = maps.FlatSkyMap(arr, res, proj=proj,
from spt3g import core, maps import numpy as np pipe = core.G3Pipeline() m = maps.FlatSkyMap(300, 300, core.G3Units.arcmin, proj=maps.MapProjection.ProjZEA) pipe.Add(core.G3InfiniteSource, type=core.G3FrameType.Observation, n=1) pipe.Add(maps.InjectMapStub, map_id="test_map", map_stub=m, polarized=False, weighted=True) def RandomMap(frame): if frame.type != core.G3FrameType.Map: return tmap = frame.pop("T") tmap[:] = np.random.randn(*m.shape) frame["T"] = tmap wmap = frame.pop("Wunpol") wmap.TT[:] = 10 * np.ones(m.shape) frame["Wunpol"] = wmap