GLAMERDOC++
Gravitational Lensing Code Library
Public Member Functions | Public Attributes | List of all members
Grid Struct Reference

Structure to contain both source and image trees. More...

#include <grid_maintenance.h>

Collaboration diagram for Grid:
Collaboration graph
[legend]

Public Member Functions

 Grid (LensHndl lens, unsigned long N1d, const double center[2], double range)
 Constructor for initializing square grid. More...
 
 Grid (LensHndl lens, unsigned long Nx, const PosType center[2], PosType rangeX, PosType rangeY)
 Constructor for initializing rectangular grid. More...
 
 ~Grid ()
 Destructor for a Grid. Frees all memory.
 
Grid ReInitialize (LensHndl lens)
 Returns a new grid that has not been refined but has the same intial image grid, but calculated with a new lens.
 
void zoom (LensHndl lens, double *center, double scale, Branch *top=NULL)
 Test if point is in a region of uniform magnification using the kappa and gamma calculated from the rayshooter. More...
 
double RefreshSurfaceBrightnesses (SourceHndl source)
 Reshoot the rays with the same image postions. More...
 
double AddSurfaceBrightnesses (SourceHndl source)
 Recalculate surface brightness just like Grid::RefreshSurfaceBrightness but the new source is added to any sources that were already there.
More...
 
double mark_closest_point_source_images (Point_2d y_source, PosType r_source_max, PosType luminosity, bool verbose=false)
 This function finds all the images for a circular source of radius r_source, then finds the points within each image that are closest to the center and then markes each surface brightness. Only one pixel per image gets flux. More...
 
void find_point_source_images (Point_2d y_source, PosType r_source, PosType z_source, std::vector< RAY > &images, bool verbose=false)
 This function finds all the images for a circular source of radius r_source, then finds the points within each image that are closest to the center of the source. Only one pixel per image gets flux. Points are not marked. More...
 
double ClearSurfaceBrightnesses ()
 Reset the surface brightness and in_image flag in every point on image and source planes to zero (false)
 
double refine_on_surfacebrightness (Lens &lens, Source &source)
 
unsigned long getNumberOfPoints () const
 Returns number of points on image plane. More...
 
PosType EinsteinArea () const
 area of region with negative magnification
 
int getInitNgrid ()
 return initial number of grid points in each direction
 
int getNgrid_block ()
 return number of cells in each dimension into which each cell is divided when a refinement is made
 
double getInitRange ()
 return initial range of gridded region
 
Point_2d getInitCenter ()
 
PointRefineLeaf (LensHndl lens, Point *point)
 Fundamental function used to divide a leaf in the tree into nine subcells. More...
 
PointRefineLeaves (LensHndl lens, std::vector< Point * > &points)
 Same as RefineLeaf() but multiple points can be passed. The rays are shot all together so that more parallelization can be achieved in the rayshooting.
 
void ClearAllMarks ()
 Rest all in_image markers to False.
 
void writeFits (const double center[], size_t Npixels, double resolution, LensingVariable lensvar, std::string filename)
 Outputs a fits image of a lensing variable of choice. More...
 
void writeFits (const double center[], size_t Nx, size_t Ny, double resolution, LensingVariable lensvar, std::string filename)
 Outputs a fits image of a lensing variable of choice. More...
 
void writeFits (double strech, LensingVariable lensvar, std::string filename)
 make a fits image of whole grid region More...
 
void writePixelFits (size_t Nx, LensingVariable lensvar, std::string filename)
 Make a fits map that is automatically centered on the grid and has approximately the same range as the grid. Nx can be used to change the resolution. Nx = grid.getInitNgrid() will give the initial grid resolution. More...
 
void writeFitsVector (const double center[], size_t Npixels, double resolution, LensingVariable lensvar, std::string filename)
 Outputs a fits file for making plots of vector fields. More...
 
PixelMap writePixelMap (const double center[], size_t Npixels, double resolution, LensingVariable lensvar)
 Outputs a PixelMap of the lensing quantities of a fixed grid. More...
 
PixelMap writePixelMap (const double center[], size_t Nx, size_t Ny, double resolution, LensingVariable lensvar)
 Outputs a PixelMap of the lensing quantities of a fixed grid. More...
 
PixelMap writePixelMap (LensingVariable lensvar)
 With the initial boundaries and resolution, ie no refinement. More...
 
void MapSurfaceBrightness (PixelMap &map)
 make image of surface brightness
 
PixelMap MapSurfaceBrightness (double resolution)
 make a map of the whole gridded area with given resolution
 
PixelMap writePixelMapUniform (const PosType center[], size_t Nx, size_t Ny, LensingVariable lensvar)
 Make a Pixel map of the without distribution the pixels. More...
 
void writePixelMapUniform (PixelMap &map, LensingVariable lensvar)
 
void writeFitsUniform (const PosType center[], size_t Nx, size_t Ny, LensingVariable lensvar, std::string filename)
 Output a fits map of the without distribution the pixels. More...
 
void find_images (PosType *y_source, PosType r_source, int &Nimages, std::vector< ImageInfo > &imageinfo, unsigned long &Nimagepoints)
 Finds images for a given source position and size. It seporates images of different pairities. More...
 
void map_images (Lens *lens, Source *source, int *Nimages, std::vector< ImageInfo > &imageinfo, PosType xmax, PosType xmin, PosType initial_size, ExitCriterion criterion, bool FindCenter, bool divide_images)
 Find images and refine them based on their surface brightness distribution. More...
 
 Grid (Grid &&grid)
 
Grid operator= (Grid &grid)=delete
 
 Grid (Grid &grid)=delete
 
Gridoperator= (Grid &&grid)
 
PosType magnification (double sblimit=-1.0e12) const
 flux weighted local magnification that does not take multiple imaging into effect
 
PosType UnlensedFlux (double sblimit=-1.0e12) const
 
PosType LensedFlux (double sblimit=-1.0e12) const
 
Point_2d centroid () const
 centroid of flux
 

Public Attributes

TreeHndl i_tree
 tree on image plane
 
TreeHndl s_tree
 tree on source plane
 

Detailed Description

Structure to contain both source and image trees.

Constructor & Destructor Documentation

◆ Grid() [1/2]

Grid::Grid ( LensHndl  lens,
unsigned long  N1d,
const double  center[2],
double  range 
)

Constructor for initializing square grid.

Note: Deflection solver must be specified before creating a Grid.

Parameters
lenslens model for initializing grid
N1dInitial number of grid points in each dimension.
centerCenter of grid (usually in radian units)
rangeFull width of grid in whatever units will be used.

◆ Grid() [2/2]

Grid::Grid ( LensHndl  lens,
unsigned long  Nx,
const PosType  center[2],
PosType  rangeX,
PosType  rangeY 
)

Constructor for initializing rectangular grid.

Cells of grid will always be square with initial resolution rangeX/(Nx-1). The Y range may not be exactly rangeY, but will be the nearest value that is a whole number of cells.

Note: Deflection solver must be specified before creating a Grid.

Parameters
lenslens model for initializing grid
NxInitial number of grid points in X dimension.
centerCenter of grid.
rangeXFull width of grid in x direction in whatever units will be used.
rangeYFull width of grid in y direction in whatever units will be used.

Member Function Documentation

◆ AddSurfaceBrightnesses()

PosType Grid::AddSurfaceBrightnesses ( SourceHndl  source)

Recalculate surface brightness just like Grid::RefreshSurfaceBrightness but the new source is added to any sources that were already there.

returns the total flux from new source

◆ find_images()

void Grid::find_images ( PosType *  y_source,
PosType  r_source,
int &  Nimages,
std::vector< ImageInfo > &  imageinfo,
unsigned long &  Nimagepoints 
)

Finds images for a given source position and size. It seporates images of different pairities.

No grid refinement is done. If the images is not initially found no nearest neighbor points are returned.

image points are put into imageinfo[].imagekist imageinfo[].points and imageinfo[].Npoints are not changed

side-effects : Will make in_image = true for all image points if splitparities == 0

< >

◆ find_point_source_images()

void Grid::find_point_source_images ( Point_2d  y_source,
PosType  r_source,
PosType  z_source,
std::vector< RAY > &  images,
bool  verbose = false 
)

This function finds all the images for a circular source of radius r_source, then finds the points within each image that are closest to the center of the source. Only one pixel per image gets flux. Points are not marked.

Parameters
y_sourceangular position of source,
r_sourcepoints outside this radius on the source plane will not be considered as in the image
z_sourceredhsift of source
imagesreturned image rays

◆ getNumberOfPoints()

unsigned long Grid::getNumberOfPoints ( ) const

Returns number of points on image plane.

Finding

◆ map_images()

void Grid::map_images ( Lens lens,
Source source,
int *  Nimages,
std::vector< ImageInfo > &  imageinfo,
PosType  xmax,
PosType  xmin,
PosType  initial_size,
ExitCriterion  criterion,
bool  FindCenter,
bool  divide_images 
)

Find images and refine them based on their surface brightness distribution.

Finding Uses ImageFinding::find_images_kist() to initially find and refine images and then uses a surface brightness based criterion to refine the most important parts of the lens.

map_images is intended for mapping images of sources more complicated than simple circles.

No Grid refinement is done.

◆ mark_closest_point_source_images()

double Grid::mark_closest_point_source_images ( Point_2d  y_source,
PosType  r_source_max,
PosType  luminosity,
bool  verbose = false 
)

This function finds all the images for a circular source of radius r_source, then finds the points within each image that are closest to the center and then markes each surface brightness. Only one pixel per image gets flux.

Parameters
y_sourceangular position of source,
r_source_maxpoints outside this radius on the source plane will not be considered as in the image

◆ RefineLeaf()

Point * Grid::RefineLeaf ( LensHndl  lens,
Point point 
)

Fundamental function used to divide a leaf in the tree into nine subcells.

Source and image points are created, linked, shot and added to the trees. The leaf pointers of the points including the input are assigned.

If some of the of the points are outside the original grid they will not be added in which case THERE WILL BE LESS THEN Ngrid*Ngrid-1 points added. The true number will be result->head or, if no points are added, result = NULL.

Returns a pointer to the list of image points that have been added. This array can then be used for calculating the surface brightness or marking them as in the image.

i_tree current is left in one of the new subcells.

◆ RefreshSurfaceBrightnesses()

PosType Grid::RefreshSurfaceBrightnesses ( SourceHndl  source)

Reshoot the rays with the same image postions.

Finding The source positions and source tree are updated to the current lens model. The advantage over Grid::ReInitializeGrid() is that the image plane refinements are preserved.

void Grid::ReShoot(LensHndl lens){

PosType range,center[2];

range = i_tree->getTop()->boundary_p2[0] - i_tree->getTop()->boundary_p1[0]; center[0] = (i_tree->getTop()->boundary_p2[0] + i_tree->getTop()->boundary_p1[0])/2; center[1] = (i_tree->getTop()->boundary_p2[1] + i_tree->getTop()->boundary_p1[1])/2;

Grid newgrid(lens,Ngrid_init,center,rangeX,rangeY);

         Grid(LensHndl lens ,unsigned long Nx ,const PosType center[2] ,PosType rangeX ,PosType rangeY);

Point *i_points,*s_points;

unsigned long i;

clear source tree delete s_tree; s_points = NewPointArray(i_tree->pointlist.size()); s_points = point_factory(i_tree->pointlist.size());

build new initial grid PointList::iterator i_tree_pointlist_it; i_tree_pointlist_it.current = i_tree->pointlist.Top(); size_t k; for(i=0,k=0;i<i_tree->pointlist.size();++i){ i_points = *i_tree_pointlist_it; if(i_points->head > 0){

link source and image points for(size_t j=0;j<i_points->head;++j,++k){ i_points[j].image = &s_points[k]; s_points[k].image = &i_points[j]; s_points[k].id = i_points[j].id; s_points[k].gridsize = i_points[j].gridsize; };

{ reshoot the rays std::lock_guard<std::mutex> hold(grid_mutex); lens->rayshooterInternal(i_points->head,i_points); } }

–i_tree_pointlist_it; }

s_tree = new TreeStruct(s_points,s_points->head,1,(i_tree->getTop()->boundary_p2[0] - i_tree->getTop()->boundary_p1[0])/10 ); return; }

Recalculate surface brightness at every point without changing the positions of the grid or any lens properties.

Whatever is in the image is replaced with the one input source. Recalculate the surface brightness at all points on the grid. This is useful when changing the source model while preserving changes in the grid. Both i_tree and s_tree are both changed although only s_tree shows up here.

returns total flux

◆ writeFits() [1/3]

void Grid::writeFits ( const double  center[],
size_t  Npixels,
double  resolution,
LensingVariable  lensvar,
std::string  filename 
)

Outputs a fits image of a lensing variable of choice.

Parameters
centercenter of image
Npixelsnumber of pixels in image in on dimension
resolutionresolution of image in radians
lensvarwhich quantity is to be displayed
filenamefile name for image -- .kappa.fits, .gamma1.fits, etc will be appended

◆ writeFits() [2/3]

void Grid::writeFits ( const double  center[],
size_t  Nx,
size_t  Ny,
double  resolution,
LensingVariable  lensvar,
std::string  filename 
)

Outputs a fits image of a lensing variable of choice.

Parameters
centercenter of image
Nxnumber of pixels in image in x dimension
Nynumber of pixels in image in y dimension
resolutionresolution of image in radians
lensvarwhich quantity is to be displayed
filenamefile name for image -- .kappa.fits, .gamma1.fits, etc will be appended

◆ writeFits() [3/3]

void Grid::writeFits ( double  strech,
LensingVariable  lensvar,
std::string  filename 
)

make a fits image of whole grid region

Parameters
strechresolution relative to the initial resolution
lensvarwhich quantity is to be displayed
filenamefile name for image -- .kappa.fits, .gamma1.fits, etc will be appended

◆ writeFitsUniform()

void Grid::writeFitsUniform ( const PosType  center[],
size_t  Nx,
size_t  Ny,
LensingVariable  lensvar,
std::string  filename 
)

Output a fits map of the without distribution the pixels.

This will be faster than Grid::writePixelMap() and Grid::writeFits(). But it puts each grid pixel in one pixelmap pixel and if there are two grid pixels in one pixelmap pixel it uses one at random. This is meant for uniform maps to make equal sized PixelMaps.

Parameters
centercenter of image
Nxnumber of pixels in image in on dimension
Nynumber of pixels in image in on dimension
lensvarwhich quantity is to be displayed
filenamefile name for image -- .kappa.fits, .gamma1.fits, etc will be appended

◆ writeFitsVector()

void Grid::writeFitsVector ( const double  center[],
size_t  Npixels,
double  resolution,
LensingVariable  lensvar,
std::string  filename 
)

Outputs a fits file for making plots of vector fields.

Parameters
centercenter of image
Npixelsnumber of pixels in image in on dimension
resolutionresolution of image in radians
lensvarwhich quantity is to be displayed
filenamefile name for image -- .kappa.fits, .gamma1.fits, etc will be appended

◆ writePixelFits()

void Grid::writePixelFits ( size_t  Nx,
LensingVariable  lensvar,
std::string  filename 
)

Make a fits map that is automatically centered on the grid and has approximately the same range as the grid. Nx can be used to change the resolution. Nx = grid.getInitNgrid() will give the initial grid resolution.

Parameters
Nxnumber of pixels in image in x dimension
lensvarwhich quantity is to be displayed
filenamefile name for image -- .kappa.fits, .gamma1.fits, etc will be appended

◆ writePixelMap() [1/3]

PixelMap Grid::writePixelMap ( const double  center[],
size_t  Npixels,
double  resolution,
LensingVariable  lensvar 
)

Outputs a PixelMap of the lensing quantities of a fixed grid.

Parameters
centercenter of image
Npixelsnumber of pixels in image in on dimension
resolutionresolution of image in radians
lensvarwhich quantity is to be displayed

◆ writePixelMap() [2/3]

PixelMap Grid::writePixelMap ( const double  center[],
size_t  Nx,
size_t  Ny,
double  resolution,
LensingVariable  lensvar 
)

Outputs a PixelMap of the lensing quantities of a fixed grid.

Parameters
centercenter of image
Nxnumber of pixels in image in on dimension
Nynumber of pixels in image in on dimension
resolutionresolution of image in radians
lensvarwhich quantity is to be displayed

◆ writePixelMap() [3/3]

PixelMap Grid::writePixelMap ( LensingVariable  lensvar)

With the initial boundaries and resolution, ie no refinement.

Outputs a PixelMap of the lensing quantities of a fixed grid.

Parameters
lensvarwhich quantity is to be displayed

◆ writePixelMapUniform() [1/2]

PixelMap Grid::writePixelMapUniform ( const PosType  center[],
size_t  Nx,
size_t  Ny,
LensingVariable  lensvar 
)

Make a Pixel map of the without distribution the pixels.

This will be faster than Grid::writePixelMap() and Grid::writeFits(). But it puts each grid pixel in one pixelmap pixel and if there are two grid pixels in one pixelmap pixel it uses one at random. This is meant for uniform maps to make equal sized PixelMaps.

Parameters
centercenter of image
Nxnumber of pixels in image in on dimension
Nynumber of pixels in image in on dimension
lensvarwhich quantity is to be displayed

◆ writePixelMapUniform() [2/2]

void Grid::writePixelMapUniform ( PixelMap map,
LensingVariable  lensvar 
)
Parameters
lensvarwhich quantity is to be displayed

◆ zoom()

void Grid::zoom ( LensHndl  lens,
double *  center,
double  scale,
Branch top = NULL 
)

Test if point is in a region of uniform magnification using the kappa and gamma calculated from the rayshooter.

An estimate of the magnification matrix is returned if it returns true. Otherwise the magnification matrix is unspecified.

Magnification matrix elements are considered equal if their difference is smaller than maglimit which is set in the Grid constructor.

quickly refines the grid down to a specific scale at a given point

top is an optional argument that allows for the zooming to start part way down the tree. Default is to start at the root. If the point is not within top or the root nothing is done. The point will not necessarily be in the center of the smallest branch.

Parameters
centercenter of point where grid is refined
scalethe smallest grid size to which the grid is refined
topwhere on the tree to start, if NULL it will start at the root

The documentation for this struct was generated from the following files: