Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_lensing(self):
lensed,unlensed = get_lens_result(1.,400,np.float64)
lensed0 = enmap.read_map(DATA_PREFIX+"MM_lensed_%s.fits" % lens_version)
unlensed0 = enmap.read_map(DATA_PREFIX+"MM_unlensed_%s.fits" % lens_version)
y,x = lensed0.posmap()
assert np.all(np.isclose(lensed,lensed0))
assert np.all(np.isclose(unlensed,unlensed0))
assert wcsutils.equal(lensed.wcs,lensed0.wcs)
assert wcsutils.equal(unlensed.wcs,unlensed0.wcs)
assert wcsutils.equal(unlensed.wcs,lensed.wcs)
geos = get_geometries(config['geometries'])
lmax = config['lmax'] ; lmax_pad = config['lmax_pad']
spectra = get_spectra(config['spectra'],lmax,lmax_pad)
seed = config['seed']
results = {}
for g in geos.keys():
results[g] = {}
for s in spectra.keys():
results[g][s] = {}
imap = generate_map(geos[g][0][-2:],geos[g][1],spectra[s],lmax,seed)
# Do write and read test
filename = "temporary_map.fits"
enmap.write_map(filename,imap)
imap_in = enmap.read_map(filename)
check_equality(imap,imap_in)
for e in config['extracts']:
print("Doing test for extract ",e['name']," with geometry ", \
g," and spectrum ",s,"...")
if e['type']=='slice':
box = np.deg2rad(np.array(e['box_deg']))
cutout = enmap.read_map(filename,box=box)
cutout_internal = imap.submap(box=box)
elif e['type']=='postage':
dec_deg,ra_deg = e['center_deg']
width_arcmin = e['width_arcmin']
res_arcmin = e['res_arcmin']
file_proxy = enmap.read_map(filename,delayed=True)
coords = np.array([dec_deg,ra_deg]) * utils.degree
cutout = reproject.thumbnails(file_proxy,coords,
r=width_arcmin/2.*utils.arcmin,
def test_lensing(self):
lensed,unlensed = get_lens_result(1.,400,np.float64)
lensed0 = enmap.read_map(DATA_PREFIX+"MM_lensed_%s.fits" % lens_version)
unlensed0 = enmap.read_map(DATA_PREFIX+"MM_unlensed_%s.fits" % lens_version)
y,x = lensed0.posmap()
assert np.all(np.isclose(lensed,lensed0))
assert np.all(np.isclose(unlensed,unlensed0))
assert wcsutils.equal(lensed.wcs,lensed0.wcs)
assert wcsutils.equal(unlensed.wcs,unlensed0.wcs)
assert wcsutils.equal(unlensed.wcs,lensed.wcs)
def test_offset(self):
obs_pos,grad,raw_pos = get_offset_result(1.)
obs_pos0 = enmap.read_map(DATA_PREFIX+"MM_offset_obs_pos_%s.fits" % lens_version)
grad0 = enmap.read_map(DATA_PREFIX+"MM_offset_grad_%s.fits" % lens_version)
raw_pos0 = enmap.read_map(DATA_PREFIX+"MM_offset_raw_pos_%s.fits" % lens_version)
assert np.all(np.isclose(obs_pos,obs_pos0))
assert np.all(np.isclose(raw_pos,raw_pos0))
assert np.all(np.isclose(grad,grad0))
assert wcsutils.equal(grad.wcs,grad0.wcs)
assert wcsutils.equal(obs_pos.wcs,obs_pos0.wcs)
assert wcsutils.equal(raw_pos.wcs,raw_pos0.wcs)
def test_offset(self):
obs_pos,grad,raw_pos = get_offset_result(1.)
obs_pos0 = enmap.read_map(DATA_PREFIX+"MM_offset_obs_pos_%s.fits" % lens_version)
grad0 = enmap.read_map(DATA_PREFIX+"MM_offset_grad_%s.fits" % lens_version)
raw_pos0 = enmap.read_map(DATA_PREFIX+"MM_offset_raw_pos_%s.fits" % lens_version)
assert np.all(np.isclose(obs_pos,obs_pos0))
assert np.all(np.isclose(raw_pos,raw_pos0))
assert np.all(np.isclose(grad,grad0))
assert wcsutils.equal(grad.wcs,grad0.wcs)
assert wcsutils.equal(obs_pos.wcs,obs_pos0.wcs)
assert wcsutils.equal(raw_pos.wcs,raw_pos0.wcs)
results[g] = {}
for s in spectra.keys():
results[g][s] = {}
imap = generate_map(geos[g][0][-2:],geos[g][1],spectra[s],lmax,seed)
# Do write and read test
filename = "temporary_map.fits"
enmap.write_map(filename,imap)
imap_in = enmap.read_map(filename)
check_equality(imap,imap_in)
for e in config['extracts']:
print("Doing test for extract ",e['name']," with geometry ", \
g," and spectrum ",s,"...")
if e['type']=='slice':
box = np.deg2rad(np.array(e['box_deg']))
cutout = enmap.read_map(filename,box=box)
cutout_internal = imap.submap(box=box)
elif e['type']=='postage':
dec_deg,ra_deg = e['center_deg']
width_arcmin = e['width_arcmin']
res_arcmin = e['res_arcmin']
file_proxy = enmap.read_map(filename,delayed=True)
coords = np.array([dec_deg,ra_deg]) * utils.degree
cutout = reproject.thumbnails(file_proxy,coords,
r=width_arcmin/2.*utils.arcmin,
res=res_arcmin*utils.arcmin,
proj='tan')
cutout_internal = reproject.thumbnails(imap,coords,
r = width_arcmin/2.*utils.arcmin,
res=res_arcmin*utils.arcmin,
proj='tan')
check_equality(cutout,cutout_internal)
def get_map(ifile, args, return_info=False, name=None):
"""Read the specified map, and massage it according to the options
in args. Relevant ones are sub, autocrop, slice, op, downgrade, scale,
mask. Retuns with shape [:,ny,nx], where any extra dimensions have been
flattened into a single one."""
# TODO: this should be reorganized so that slicing can happen earlier.
# Currently the whole file needs to be read.
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
if isinstance(ifile, basestring):
toks = ifile.split(":")
ifile, slice = toks[0], ":".join(toks[1:])
m0 = enmap.read_map(ifile, hdu=args.hdu)
if name is None: name = ifile
else:
m0 = ifile
slice = ""
if name is None: name = ".fits"
# This fills in a dummy, plain wcs if one does not exist
m0 = enmap.enmap(m0, copy=False)
if args.fix_wcs:
m0.wcs = wcsutils.fix_wcs(m0.wcs)
# Save the original map, so we can compare its wcs later
m = m0
# Submap slicing currently has wrapping issues
if args.sub is not None:
default = [[-90,-180],[90,180]]
sub = np.array([[(default[j][i] if q == '' else float(q))*np.pi/180 for j,q in enumerate(w.split(":"))]for i,w in enumerate(args.sub.split(","))]).T
m = m.submap(sub)
imaps = inmap
rots = []
stamps = []
for imap in imaps:
if isinstance(imap,basestring):
ishape,iwcs = enmap.read_map_geometry(imap)
else:
ishape,iwcs = imap.shape,imap.wcs
mapres = np.min(np.abs(enmap.extent(ishape,iwcs))/ishape[-2:])
# cut out a stamp assuming CAR ; TODO: generalize?
stamp = cutout(imap, width=npad*mapres+np.deg2rad(width_arcmin / 60.) /
np.cos(dec), ra=ra, dec=dec,
return_slice=isinstance(imap,basestring))
if isinstance(imap,basestring):
stamp = enmap.read_map(imap, sel=stamp)
if stamp is None:
return (None,None) if return_cutout else None
if stamp.ndim==2: stamp = stamp[None,:]
ncomp = stamp.shape[0]
assert ncomp==1 or ncomp==3, \
"Only leading dimensions of 1 (intensity) or 3 (I,Q,U) are supported."
sshape, swcs = stamp.shape, stamp.wcs
if proj == 'car' or proj == 'cea':
tshape, twcs = rect_geometry(width=width, res=res, proj=proj)
elif proj == 'gnomonic':
tshape, twcs = gnomonic_pole_geometry(width, res)
rpix = get_rotated_pixels(sshape, swcs, tshape, twcs, inverse=False,
pos_target=None, center_target=(0., 0.),
center_source=(dec, ra))
rot = enmap.enmap(rotate_map(stamp, pix_target=rpix[:2], **kwargs), twcs)
if ncomp==3 and rotate_pol: