def main(): zd = 0.5 lens = lenses.PlummerLens(D(zd), { "mass": 1e14*MASS_SUN, "width": 5*ANGLE_ARCSEC }) li = plotutil.LensInfo(lens, size=15*ANGLE_ARCSEC, zd=zd) iws = inversion.InversionWorkSpace(zd, 20*ANGLE_ARCSEC) num = 5 print(f"Creating {num} sources") while num > 0: zs = np.random.uniform(zd, 6) beta = np.random.uniform(-1*ANGLE_ARCSEC, 1*ANGLE_ARCSEC, size=(2,)) li.setSourceRedshift(zs) ip = li.getImagePlane() thetas = ip.traceBeta(beta) if len(thetas) > 1: num -= 1 print(f"Found image, {num} to go") img = images.ImagesData(len(thetas)) for i in range(len(thetas)): img.addPoint(i, thetas[i]) iws.addImageDataToList(img, zs, "pointimages") print("Fitness info") print("------------") print(iws.calculateFitness(None)) print("") imperfectLens = lenses.CompositeLens(D(zd), [ { "lens": lens, "factor": 0.999, "x": 0, "y": 0, "angle": 0 } ]) for l, info in [ (lens, "True lens"), (imperfectLens, "Imperfect lens") ]: s = f"Using: {info}" print(s) print("-" * len(s)) print("Using lens itself:") print(iws.calculateFitness(l)) print("") print("Using backprojected images:") bpImages = iws.backProject(l) print(iws.calculateFitness(bpImages)) print("")
import random print("RNG State:") print(random.getstate()) V = lambda x, y: np.array([x, y], dtype=np.double) renderers.setDefaultLensPlaneRenderer( "threads") # threads, mpi, opencl, None or a Renderer object renderers.setDefaultMassRenderer( "threads") # threads, mpi, None, or a Renderer object inversion.setDefaultInverter("threads") # threads, mpi or an Inverter object plotutil.setDefaultAngularUnit(ANGLE_ARCSEC) z_lens = 0.45 iws = inversion.InversionWorkSpace(z_lens, 150 * ANGLE_ARCSEC, cosmology=Cosmology(0.7, 1.0, 0, 0)) iws.addImageDataToList(images.ImagesData.load("images1pointgroups.imgdata"), 2.5, "extendedimages") iws.addImageDataToList(images.ImagesData.load("null1.imgdata"), 2.5, "extendednullgrid") iws.addImageDataToList(images.ImagesData.load("images2.imgdata"), 1.5, "extendedimages") iws.addImageDataToList(images.ImagesData.load("null2.imgdata"), 1.5, "extendednullgrid") # For a quick test to see if all code executes # iws.setDefaultInversionArguments(maximumGenerations = 10) iws.setUniformGrid(15)
import random print("RNG State:") print(random.getstate()) V = lambda x, y: np.array([x, y], dtype=np.double) renderers.setDefaultLensPlaneRenderer( "threads") # threads, mpi, opencl, None or a Renderer object renderers.setDefaultMassRenderer( "threads") # threads, mpi, None, or a Renderer object inversion.setDefaultInverter("threads") # threads, mpi or an Inverter object plotutil.setDefaultAngularUnit(ANGLE_ARCSEC) z_lens = 0.7 iws = inversion.InversionWorkSpace(z_lens, 60 * ANGLE_ARCSEC, cosmology=Cosmology(0.7, 0.3, 0, 0.7)) iws.addImageDataToList(images.ImagesData.load("images_00.imgdata"), 2.74714, "extendedimages") iws.addImageDataToList(images.ImagesData.load("images_01.imgdata"), 3.07785, "extendedimages") iws.addImageDataToList(images.ImagesData.load("images_02.imgdata"), 2.85271, "extendedimages") iws.addImageDataToList(images.ImagesData.load("images_03_td.imgdata"), 3.32098, "extendedimages") #iws.addImageDataToList(images.ImagesData.load("images_03_td.imgdata"), 3.32098, "extendedimages", { "timedelay": False }) iws.addImageDataToList(images.ImagesData.load("images_04.imgdata"), 3.1543, "extendedimages")
19.30124747 -16.9427861 -0.4142903709 -6.376420558 -15.50428292 -1.884038019 -60.06804983 14.08154015 37.96515147 68.83852853 -64.12416086 -82.79545034 3.2336 36.2571622 13.72493334 39.32244461 15.59162438 """ z_lens = 0.4 for useWeights in [False, True]: iws = inversion.InversionWorkSpace(z_lens, 250 * ANGLE_ARCSEC, cosmology=Cosmology(0.7, 0.27, 0, 0.73)) imgList = images.readInputImagesFile(pointData, True) for i in imgList: iws.addImageDataToList(i["imgdata"], i["z"], "pointimages") iws.setUniformGrid(15) if showPlots: plotutil.plotSubdivisionGrid(iws.getGrid()) plt.show() lens1, fitness1, fitdesc = iws.invert(popSize, maximumGenerations=maxGen, rescaleBasisFunctions=useWeights, basisFunctionType=basisFunctionType)
renderers.setDefaultLensPlaneRenderer( "threads") # threads, mpi, opencl, None or a Renderer object renderers.setDefaultMassRenderer( "threads") # threads, mpi, None, or a Renderer object inversion.setDefaultInverter("threads") # threads, mpi or an Inverter object z_lens = 0.4 cosm = cosmology.Cosmology(0.7, 0.27, 0, 0.73) cosmology.setDefaultCosmology(cosm) weakSize = 30 * ANGLE_ARCMIN weakSubDiv = 48 weakThreshold = 0.1 # Threshold for |1-kappa| sheetType = "nosheet" # or "genome" iws = inversion.InversionWorkSpace( z_lens, weakSize) # Now using weakSize for the default grid size iws.addImageDataToList(images.ImagesData.load("ellipt_48x48_exact_z1.imgdata"), 1, "sheardata", {"threshold": weakThreshold}) iws.addImageDataToList(images.ImagesData.load("ellipt_48x48_exact_z2.imgdata"), 2, "sheardata", {"threshold": weakThreshold}) iws.addImageDataToList(images.ImagesData.load("ellipt_48x48_exact_z4.imgdata"), 4, "sheardata", {"threshold": weakThreshold}) iws.setDefaultInversionArguments( sheetSearch=sheetType ) # add maximumGenerations = 2 to test if script works iws.setUniformGrid(weakSubDiv) # We don't have SL info to estimate a mass scale, so we'll specify one. This # will be used to set the masses of the basis functions for each grid cell.
"threads") # threads, mpi, opencl, None or a Renderer object renderers.setDefaultMassRenderer( "threads") # threads, mpi, None, or a Renderer object inversion.setDefaultInverter("threads") # threads, mpi or an Inverter object z_lens = 0.4 cosm = cosmology.Cosmology(0.7, 0.27, 0, 0.73) cosmology.setDefaultCosmology(cosm) strongSize = 200 * ANGLE_ARCSEC weakSize = 30 * ANGLE_ARCMIN weakSubDiv = 48 weakThreshold = 0.1 # Threshold for |1-kappa| sheetType = "nosheet" # or "genome" iws = inversion.InversionWorkSpace(z_lens, strongSize) # Add the SL data # Note: not using null space for i in images.readInputImagesFile("images.txt", True): iws.addImageDataToList(i["imgdata"], i["z"], "pointimages") iws.addImageDataToList(images.ImagesData.load("ellipt_48x48_exact_z1.imgdata"), 1, "sheardata", {"threshold": weakThreshold}) iws.addImageDataToList(images.ImagesData.load("ellipt_48x48_exact_z2.imgdata"), 2, "sheardata", {"threshold": weakThreshold}) iws.addImageDataToList(images.ImagesData.load("ellipt_48x48_exact_z4.imgdata"), 4, "sheardata", {"threshold": weakThreshold}) iws.setDefaultInversionArguments( sheetSearch=sheetType